My Fenix Questions: Delete_text, 320x240, Scan_code?


TrevorBradley

Active Member
Joined
Nov 6, 2007
Messages
732
OK, after a day tinkering around with fenix, I've coded a very nice program that helped me work out which key was which (not really documented. For the record it's:

LEFT_C_LEFT
RIGHT _C_RIGHT
UP _C_UP
DOWN _C_DOWN
A _CONTROL
B _ALT
Y _Z
X _X
VOL_DOWN _A
VOL_UP _S
SELECT _ENTER
START/HOME _SPACE
L _BACKSPACE
R _TAB

Here are my questions:

1) The global variable scan_code doesn't seem to do anything on GP2X Fenix, it always has a value of 0. I had to write a program to figure out what button was being pressed. It works fine on Fenix Windows.

2) The Fenix Development kit (multiple versions) appear to have a screen resolution of 320x200, yet the GP2X appears to have a 320x240 screen resolution. But if I code for things in that last 40 pixels, they don't show up. What am I doing wrong?

3) (as detailed in a previous post) delete_text() appears to bleed across processes, where one process is deleting the text of another, even though they have unique textIDs. Why?

Here's the rather nifty code I worked out today. I'm quite pleased with it actually for a first try:

CODE

Program FenixKeypadTest;
//This program demonstrates the use of the fenix key() function.
//It also allowed me to determine a list of GP2X keys.
// Feel free to use in any way
//Questions:
// Why does scan_code not work on the GP2X? (always gives 0)
// Why does delete_text delete text in other processes?
// Why does fenix seem to be able to use only 320x200 instead of 320x240?

Const
screen_width = 320;
screen_height = 240;
screen_depth = 8;
screen_fps = 60;
Begin

// make the movement a bit more smooth
set_fps(screen_fps,0);

//LEFT
button(_c_left, 40, 110);
//RIGHT
button(_c_right, 80, 110);
//UP
button(_c_up, 60, 90);
//DOWN
button(_c_down, 60, 130);

//A
button(_control, 240, 110);
//B
button(_alt, 280, 110);
//Y
button(_z, 260, 90);
//X
button(_x, 260, 130);

//VOL_DOWN
button(_a, 40, 170);
//VOL_UP
button(_s, 80, 170);
//SELECT
button(_enter, 280, 170);
//HOME
button(_space, 240, 170);

//L
button(_backspace, 60, 50);
//R
button(_tab, 260, 50);

myscancode();

Repeat
delete_text(ALL_TEXT);
frame;
Until(key(_enter)&&key(_space))

// kill all other remaining processes and exit
let_me_alone();
exit();

End

Process button(int mykey, int x, int y)
Private
int mytext;
Begin
graph = new_map(10,10,8);

Loop
if (key(mykey))
map_clear(0,graph,rgb(0,0,255));
mytext=write(0,x+10,y+2,0,""+mykey);
else
map_clear(0,graph,rgb(64,64,64));
end;
frame;
End

End

Process myscancode()
Private
int mytext2;
int i;
String msg;
Begin
Loop
msg="";
For(i=0;i<255;i++)
If (key(i))
msg = msg+" "+i;
End;
End;
write (0,160,10,4,"Fenix Keypad Test");
write (0,160,20,4,"Keys Pressed:");
write (0,160,30,4,msg);
write (0,160,195,4,"Press Select+Start to Quit");
frame;
End

End



(forgive the indentation, I switched between 3 different editors in the creation process.
 

TrevorBradley

Active Member
Joined
Nov 6, 2007
Messages
732
I have a habit of answering my own questions after writing them out:

#2: set_mode(320,240);
 

ruckage

Certified Guru
Joined
Oct 15, 2006
Messages
659
Hate to picky but the key assignments are actually documented in the readme file distributed with the runtime, could have saved yourself some time.
For the directions you just need _left, _right, _up and _down. No need to put the _c before them.

Not sure about scan_code global variable as I've not had any need for it yet but if it works in windows and not on 2x its possibly a bug.

From the readme:

QUOTE
Controls:
----------
This port admits two game modes: "native" mode and "emulated" mode.

In "native" mode, only useful for GP2X, you have to code the games using the control as it was
a 19 buttons joystick, with the same correspondece as SDL as you can see here:
http://wiki.gp2x.org/wiki/SDL_Joystick_mapping

In "emulated" mode the port recognizes several keys and emulates them using the own GP2X control
as you can see:
Cursors -> pad
ctrl -> A
alt -> B
return -> START
space -> SELECT
backspace -> L
tab -> R
x -> X
z -> Y
a -> VOL-
s -> VOL+
c -> CLICK
 

TrevorBradley

Active Member
Joined
Nov 6, 2007
Messages
732
I noticed the readme about 15 minutes after I posted this (in the beta 6 version on archive.gp2x.de). For some reason, querying all 256 possibilities for key gives _C_UP, etc for the arrow keys, even though _UP, _DOWN, etc work anyways
 
Top