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
jkeys_state will not refresh itself by magic. look carefully in jkeys.lib
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
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.
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.
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
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 )
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]
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
Remember that _JKEY_A and others are constants.
They represent a button number. You can make your own
input abstraction lib if you like.
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
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 (http://wiki.bennugd.org/index.php?title=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" :)
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
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.
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.
Yes, when I first encountered Fenix I had strange feeling as if authors wanted to mix Pascal and C.
Hi all!
Actually I was a little bit lost - I should have seen for myself that it is some kind of bitwise-or-assignment. But the brain stops to work if you go to google first. :)
I would like to develop a text editor for my WIZ with touchscreen support - similar to keeEDIT for my N-Gage (see http://web.uta4you.at/shop/ (http://web.uta4you.at/shop/)). But starting with some "curiosities" of WIZ and bennu is hard.
Regards
deetee
Text editor in Bennu is quite a task!
The first question will be: How to store text file in memory?
PS
Nothing personal. I was in really bad mood that day.
I saw in the bennu-reference functions like Fopen, Fclose, Fputs and Fgets which seems to be C-like - and hopefully there is a function to allocate memory.
But first I have to do some key-, font- and touchscreen-experiments.
Regards
deetee
I would not not mind to have book reader and text editor purely written in Bennu, so I wish you good luck.
I like WIZWRITE.
I tried to convice ZX81 to add some touchscreen support, but he has no time to expand this good program. So I try it by myself (with bennu).
Where can I get "text editor" for the WIZ (or did you mean WIZWRITE from ZX81?) - I couldn't find it - Does it have (good) touchscreen support.
Regards
deetee
Writing a text editor in bennu...
Well it's possible, but not practical. You need to write textinput functions yourself, wich isn't hard, but you need to work a lot
with pointers. You can allocate memory yourself with bennu. Bennu provides most of the familiar C functions.
But, bennu has no proper gui lib. Yes thare are some of them around, but their either incomplete or provide limited functionality.
Maybe someone should port the sdl gui Agar to a bennu extension lib. It would be very usefull. So, any kind of controls have to be
written by yourself.
About the C/pascal mix, I personally like it a lot. I can look up any C book for general concepts, and they easily translate to bennu,
but in a nicer sort of way. Bennu/div took the good things from both languages, what I find good about it in contrast to C is that
it less cryptic since it uses Pascal style keywords. Yet I see some examples of programs written like C programs, and I find these less
readable.
Anyway, be carefull when you use someonelse's code, make sure that you undestand it before you use it. It's sometimes better to
rewrite it to your own taste/style that you are comfortable with. I do this a lot, especially for readabilty. Changing one or two character
identifiers to meaningfull names, adding more comments etc.
QuoteWell it's possible, but not practical.
Yes, I mean it, but yet writing such editor is possible. It would be quite a work of art.
Hi!
Finally I want to post some quick code which allows to play with keys and touchscreen on the WIZ or PC:
import "mod_text";
import "mod_key";
import "mod_joy";
import "mod_string";
import "mod_proc";
import "mod_mouse";
const
KEY_UP=0; KEY_UPLEFT= 1; KEY_LEFT=2; KEY_DOWNLEFT=3;
KEY_DOWN=4; KEY_DOWNRIGHT=5;
KEY_RIGHT=6; KEY_UPRIGHT=7;
KEY_MENU=8; KEY_SELECT=9; KEY_L=10; KEY_R=11;
KEY_A=12; KEY_B=13; KEY_X=14; KEY_Y=15;
KEY_VOLUP=16; KEY_VOLDOWN=17; KEY_CLICK=18;
KEY_LAST=19;
end
function byte key_query()
begin
if (joy_getbutton(0,KEY_UP)) return KEY_UP;
elseif(joy_getbutton(0,KEY_UPLEFT)) return KEY_UPLEFT;
elseif(joy_getbutton(0,KEY_LEFT)) return KEY_LEFT;
elseif(joy_getbutton(0,KEY_DOWNLEFT)) return KEY_DOWNLEFT;
elseif(joy_getbutton(0,KEY_DOWN)) return KEY_DOWN;
elseif(joy_getbutton(0,KEY_DOWNRIGHT)) return KEY_DOWNRIGHT;
elseif(joy_getbutton(0,KEY_RIGHT)) return KEY_RIGHT;
elseif(joy_getbutton(0,KEY_UPRIGHT)) return KEY_UPRIGHT;
elseif(joy_getbutton(0,KEY_MENU)) return KEY_MENU;
elseif(joy_getbutton(0,KEY_SELECT)) return KEY_SELECT;
elseif(joy_getbutton(0,KEY_L)) return KEY_L;
elseif(joy_getbutton(0,KEY_R)) return KEY_R;
elseif(joy_getbutton(0,KEY_A)) return KEY_A;
elseif(joy_getbutton(0,KEY_B)) return KEY_B;
elseif(joy_getbutton(0,KEY_X)) return KEY_X;
elseif(joy_getbutton(0,KEY_Y)) return KEY_Y;
elseif(joy_getbutton(0,KEY_VOLUP)) return KEY_VOLUP;
elseif(joy_getbutton(0,KEY_VOLDOWN)) return KEY_VOLDOWN;
elseif(joy_getbutton(0,KEY_CLICK)) return KEY_CLICK;
else return(0); end
end
process main()
private
int escape=0, was_clicked=0;
string str1="", str2="";
begin
repeat
str1="WIZ-Key:"+itoa(key_query())+" Character: "+chr(ascii)+" "+itoa(ascii);
write_string(0,320/2,200/2,4,&str1);
if((was_clicked==1) && (! mouse.left))
str2="x:"+itoa(mouse.x)+" y:"+itoa(mouse.y);
write_string(0,320/2,240/2,4,&str2);
end;
was_clicked = mouse.left;
if(key(_ESC) or joy_getbutton(0,KEY_MENU)) escape=1; end
frame;
until(escape);
let_me_alone();
end
As you could see I did the key query the direct way (with joy_getbutton() and without jkeys.lib).
In addition I inserted some touchscreen-code from this forum to test touchscreen-inputs.
Thank you for helping (so far)
Regards
deetee
Glad for you :)
I am not the person who have rights to say this, but: WELCOME! :) :) :)
----- edit:
After some playing with jkey a also wrote my own input abstraction.
Quote from: deetee on November 03, 2010, 01:03:20 PM
Hi!
Finally I want to post some quick code which allows to play with keys and touchscreen on the WIZ or PC:
import "mod_text";
import "mod_key";
import "mod_joy";
import "mod_string";
import "mod_proc";
import "mod_mouse";
const
KEY_UP=0; KEY_UPLEFT= 1; KEY_LEFT=2; KEY_DOWNLEFT=3;
KEY_DOWN=4; KEY_DOWNRIGHT=5;
KEY_RIGHT=6; KEY_UPRIGHT=7;
KEY_MENU=8; KEY_SELECT=9; KEY_L=10; KEY_R=11;
KEY_A=12; KEY_B=13; KEY_X=14; KEY_Y=15;
KEY_VOLUP=16; KEY_VOLDOWN=17; KEY_CLICK=18;
KEY_LAST=19;
end
function byte key_query()
begin
if (joy_getbutton(0,KEY_UP)) return KEY_UP;
elseif(joy_getbutton(0,KEY_UPLEFT)) return KEY_UPLEFT;
elseif(joy_getbutton(0,KEY_LEFT)) return KEY_LEFT;
elseif(joy_getbutton(0,KEY_DOWNLEFT)) return KEY_DOWNLEFT;
elseif(joy_getbutton(0,KEY_DOWN)) return KEY_DOWN;
elseif(joy_getbutton(0,KEY_DOWNRIGHT)) return KEY_DOWNRIGHT;
elseif(joy_getbutton(0,KEY_RIGHT)) return KEY_RIGHT;
elseif(joy_getbutton(0,KEY_UPRIGHT)) return KEY_UPRIGHT;
elseif(joy_getbutton(0,KEY_MENU)) return KEY_MENU;
elseif(joy_getbutton(0,KEY_SELECT)) return KEY_SELECT;
elseif(joy_getbutton(0,KEY_L)) return KEY_L;
elseif(joy_getbutton(0,KEY_R)) return KEY_R;
elseif(joy_getbutton(0,KEY_A)) return KEY_A;
elseif(joy_getbutton(0,KEY_B)) return KEY_B;
elseif(joy_getbutton(0,KEY_X)) return KEY_X;
elseif(joy_getbutton(0,KEY_Y)) return KEY_Y;
elseif(joy_getbutton(0,KEY_VOLUP)) return KEY_VOLUP;
elseif(joy_getbutton(0,KEY_VOLDOWN)) return KEY_VOLDOWN;
elseif(joy_getbutton(0,KEY_CLICK)) return KEY_CLICK;
else return(0); end
end
process main()
private
int escape=0, was_clicked=0;
string str1="", str2="";
begin
repeat
str1="WIZ-Key:"+itoa(key_query())+" Character: "+chr(ascii)+" "+itoa(ascii);
write_string(0,320/2,200/2,4,&str1);
if((was_clicked==1) && (! mouse.left))
str2="x:"+itoa(mouse.x)+" y:"+itoa(mouse.y);
write_string(0,320/2,240/2,4,&str2);
end;
was_clicked = mouse.left;
if(key(_ESC) or joy_getbutton(0,KEY_MENU)) escape=1; end
frame;
until(escape);
let_me_alone();
end
As you could see I did the key query the direct way (with joy_getbutton() and without jkeys.lib).
In addition I inserted some touchscreen-code from this forum to test touchscreen-inputs.
Thank you for helping (so far)
Regards
deetee
I don't suggest use this key_query function, if you press 2 keys at same time you only get 1 of they, for example, if you press A and B, you only get A.
use jkeys.lib.
Hello SplinterGU - cool to get an advice from the master himself.
You are right - querying for example a "MENU-SELECT-Reset" is not possible with my function. I will use some better (jkeys-like) solution if I am a little bit more familiar with bennu.
Regards
deetee
Just take your time. There are a lot of combinations to do a "key-input" method, so you must try and find a way you like.
Splinter and me discuss it a lot of times, and have it's own way to do this. Splinter uses his jkeys.lib, it's the easier way to noobs, but i prefer a key scanning and variable increment (or put it to "0" if not), so if this variable have "1", it's recently pressed, if more, more time has pressed, if "0", is not pressed.
Maybe you prefer to use jkeys.lib initially, but (personal opinion) try to search your own style.
Good luck with text editor, i really need one, but i don't have time to do it ;)
directly joy_button if you use it several times in your code is more expensive, for this point, I did jkey.lib on this way.