How to query WIZ keys?

Started by deetee, October 28, 2010, 09:34:30 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

deetee

Hi all!

I'm trying to run my Hello-World-program on my WIZ - but I was trapped in an endless loop.
What did I do wrong with querying the WIZ-keys (took libs from the galaxian-game)?

import "mod_text"
import "mod_key"
#include "jkeys.lib"

global
string s="Hello World";
end

process main()
begin
write_string(0,320/2,200/2,4,&s);

repeat
  frame;
until(key(_ESC) OR jkeys_state[_JKEY_A])

end


Thanks in advance
deetee

EugeneP

jkeys_state will not refresh itself by magic. look carefully in jkeys.lib

deetee

Thanks for your patience with a newbie.

Sorry - but I didn't get it yet.

Does it mean I have to query jkeys_state in the loop?
How? - I saw (in the galaxian-game) some functions like signal or jkeys_controller?

Regards
deetee

handsource-dyko

The WIZ uses joystick functions as a far as I know.
I'm currently working again on malvado2010, and I have reworked the controls,
to support the WIZ. I've not used jkeys.lib, but studied it to figure out how input
is handled on the WIZ. For my understanding it is mapped as joystick device 0.

Unfortunately I have no wiz to test it out.



EugeneP

Wiz buttons in Bennu are mapped as Joystick #0 buttons.

jkeys.lib helps you to read joystick state.

You need to call jkeys_controller() before repeat to make your code work.

This is "right" answer to your question.

deetee

Sorry to be annoying.
Calling jkeys_controller(); before repeat didn't work. Even on the PC the ESC-key didn't work any more.

My code is:

import "mod_text"
import "mod_key"
#include "jkeys.lib"

global
string s="Hello World";
end

process main()
begin
write_string(0,320/2,200/2,4,&s);

jkeys_controller();

repeat
  frame;
until(jkeys_state[_JKEY_A])

end


Putting jkey_controller() in the repeat loop doesn't help as well.

I saw in jkeys.lib that the function jkeys_controller works with "joy_getbutton(0,_JKEY_A);" - is there a possibility to use this function directly (without jkey.lib)?

Regards
deetee

EugeneP

#6
Yes, of course you may use it directly.

If galaxian works and your code works not then you probably run into some issue or bug.
Please, specify your Wiz firmware version, Bennu release you're using and attach files you're trying to get working ( jkey.lib, your .prg and your .gpe )

EugeneP

OHHHH! SILLY ME :)  :-[

[code language="bennu"]import "mod_text"
import "mod_key"
#include "jkeys.lib"

global
string s="Hello World";
end

process main()
begin
write_string(0,320/2,200/2,4,&s);

jkeys_controller();

repeat
  frame;
until(jkeys_state[_JKEY_A])
let_me_alone(); // <------------ !!!!!!!!!!!!!!!!!!!!!!!
end[/code]

deetee

Wow - it's working (even the ESC-key on the PC) - thanks, that you didn't let_me_alone  :)

I hope to go much faster on after resolving the WIZ-key- and WIZ-touchscreen-query.
deetee

handsource-dyko

Remember that _JKEY_A and others are constants.
They represent a button number. You can make your own
input abstraction lib if you like.


deetee

Ah - yes.

I saw that jkeys.lib is based on

joy_getbutton(0,_JKEY_A);

where 0 is the joystick device number and _JKEY_A is 12 (const).

What I didn't know/find is what "|=" means in:
jkeys_state[_JKEY_A] |= joy_getbutton(0, _JKEY_A);

Regards
deetee

EugeneP

Quote from: deetee on October 29, 2010, 11:08:57 AM
Ah - yes.

I saw that jkeys.lib is based on

joy_getbutton(0,_JKEY_A);

where 0 is the joystick device number and _JKEY_A is 12 (const).

What I didn't know/find is what "|=" means in:
jkeys_state[_JKEY_A] |= joy_getbutton(0, _JKEY_A);

Regards
deetee

Start from reading Bennu Wiki.

Operators of type "+="  are sort forms. "A=A+B" is equivalent of "A+=B". It's common in many programming languages.

P.S.
...and if your next question will be "What does operator | do?" then you will be sent to goole for "basics of computer science" :)

handsource-dyko

Quote from: deetee on October 29, 2010, 11:08:57 AM
Ah - yes.

I saw that jkeys.lib is based on

joy_getbutton(0,_JKEY_A);

where 0 is the joystick device number and _JKEY_A is 12 (const).

What I didn't know/find is what "|=" means in:
jkeys_state[_JKEY_A] |= joy_getbutton(0, _JKEY_A);

Regards
deetee


"|=" is the so called bitwise OR assignment if I'm not mistaking (had to look this for this on wikipedia).
I never use that kind of C language ways to express operands, I prefer to keywords
like NOT and OR and AND instead of those symbols, just because I get confused into thinking bitwise maybe
different from standard operators.

You see these operands like "|" and  "&&" a lot in examples, but I never use them.

Here's a list: http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B


EugeneP

handsource-dyko,
Please do not mix bitwise operators ("&", "|", "~"), and logical operators ("&&", "||", "!") !

AND is the same as &&, but & is WAY other thing.

deetee obviously needs to read some good tutorial on basics of programming. Learning such things from forums is... errrrr... suboptimal.

handsource-dyko

Quote from: EugeneP on October 29, 2010, 11:34:26 AM
handsource-dyko,
Please do not mix bitwise operators ("&", "|", "~"), and logical operators ("&&", "||", "!") !

AND is the same as &&, but & is WAY other thing.

deetee obviously needs to read some good tutorial on basics of programming. Learning such things from forums is... errrrr... suboptimal.

I sort of knew it, but I was never really sure. Maybe it's because I'm not used to use operators in a C-style way. It's some
habbit I inherited from DIV gamesstudio, wich preferred the pascal style of expressing things. Although I do like == and =
better their the Pascal equivalents = and :=. Now that always bugs me with free Pascal, I guess the C-style is more common.

Actually, DIV/Fenix/Bennu are kinda like C but with the readabilty of Pascal.