Changing Esc Key
Moderator: ZSNES Mods
Changing Esc Key
Hi,
Could someone tell me how to change in the source the Esc key (which i remapped to exit the Emultor) for the Tab key which would allow me to bring the menu while playing ?
Thanks
Could someone tell me how to change in the source the Esc key (which i remapped to exit the Emultor) for the Tab key which would allow me to bring the menu while playing ?
Thanks
-
- ZSNES Developer
- Posts: 6747
- Joined: Tue Dec 28, 2004 6:47 am
-
- Rookie
- Posts: 12
- Joined: Sat Feb 12, 2005 3:48 pm
Getting to show/hide the gui using TAB in the sdl linux port was easy.
Just change the returned scancode from 0x0f to 0x01 in sdllink.c
After too much fiddling with guikeys.inc and gui.asm :
There're two macros to deal with pressed keys one for normal keys and the other for the ESC key (this one takes into account if we are showing the gui or not)
First macro:
Second macro:
Both in guikeys.inc
The first macro is expanded once per key with repeated parameters as in : GUIgetprkeys 90,90, GUIgetprkeys 96,96
But not always sometimes it's expanded with different paremeters appears as: GUIgetprkeys 1Ch,13
The second macro is only expanded once
1 is the scancode for ESC 27 is the scancode for p, wich is used for pause.
GUIescpress is 1 if we're currently showing the GUI otherwise is 0, defined in gui.asm.
Pressed (which is accessed in the macros) contains info of the pressed keys and is defined as:In execute.asm
Any dev or user if I got any detail wrong, please feel free to correct me.
Just change the returned scancode from 0x0f to 0x01 in sdllink.c
Code: Select all
unsigned int sdl_keysym_to_pc_scancode(int sym)
{
switch (sym)
{
case SDLK_ESCAPE: return 0x01;
*************
case SDLK_TAB: return 0x0f;
There're two macros to deal with pressed keys one for normal keys and the other for the ESC key (this one takes into account if we are showing the gui or not)
First macro:
Code: Select all
%macro GUIgetprkeys 2
cmp byte[pressed+%1],1
je %%okay
cmp byte[pressed+%1],2
jne %%nopr
cmp dword[GUIfirstkey],1
je %%nopr
cmp dword[GUIlastkey],%1
jne %%nopr
jmp %%skipnext
%%okay
mov dword[GUInextkeydelay],10
%%skipnext
mov dword[GUIlastkey],%1
mov byte[pressed+%1],2
cmp dword[GUIkeydelay],0
jne near .done
mov eax,[GUInextkeydelay]
mov [GUIkeydelay],eax
mov dword[GUInextkeydelay],2
mov eax,%2
jmp .done
%%nopr
%endmacro
Code: Select all
%macro GUIgetprkeysb 2
cmp byte[pressed+%1],1
jne %%nopr
cmp byte[GUIescpress],1
je %%nopr2
mov byte[pressed+%1],2
mov eax,%2
jmp .done
%%nopr
cmp byte[pressed+%1],0
jne %%nopr2
mov byte[GUIescpress],0
%%nopr2
%endmacro
The first macro is expanded once per key with repeated parameters as in : GUIgetprkeys 90,90, GUIgetprkeys 96,96
But not always sometimes it's expanded with different paremeters appears as: GUIgetprkeys 1Ch,13
The second macro is only expanded once
Code: Select all
GUIgetprkeysb 1,27
GUIescpress is 1 if we're currently showing the GUI otherwise is 0, defined in gui.asm.
Pressed (which is accessed in the macros) contains info of the pressed keys and is defined as:
Code: Select all
NEWSYM pressed, times 256+128+64 db 0
Any dev or user if I got any detail wrong, please feel free to correct me.
-
- Rookie
- Posts: 12
- Joined: Sat Feb 12, 2005 3:48 pm
If you change
to
You should be able to hide the hide the gui and continue running the game Pressing TAB.
1 is the scancode for ESC 15 is the scancode for TAB, in decimal.
As we're changing the common between ports asm source it should work on windows just fine.
I have yet to look for the other way around, while ingame show the gui.
Code: Select all
GUIgetprkeysb 1,27
Code: Select all
GUIgetprkeysb 15,27
1 is the scancode for ESC 15 is the scancode for TAB, in decimal.
As we're changing the common between ports asm source it should work on windows just fine.
I have yet to look for the other way around, while ingame show the gui.
-
- Rookie
- Posts: 12
- Joined: Sat Feb 12, 2005 3:48 pm
It turns out the code for going back to the gui wasn't in guikeys.inc but in execute.asm, silly me!
Just change in execute.asm
To
There're other places in which ESC is harcoded that I found while looking how to return to the gui, might be used for canceling some settings, exitting the file dialog,etc... who knows.
The thing is they appear as cmp byte[pressed+1] or test byte[pressed+1] you just have to change [pressed+1] to [pressed+15], although haven't tried it myself it might break anything else.
Just change in execute.asm
Code: Select all
.noincrframekey
test byte[pressed+1],01h
Code: Select all
.noincrframekey
test byte[pressed+15],01h
The thing is they appear as cmp byte[pressed+1] or test byte[pressed+1] you just have to change [pressed+1] to [pressed+15], although haven't tried it myself it might break anything else.
Thanks, it's a bit of an improvement : i can now pop up the gui, but it doesn't want to hide by repressing tab : in fact the gui diseapear an reappear almost immediatly...
If a change back the first mod (the one in guikeys.inc) to use esc again it seems to work the over way : i can popup the gui with tab and hide it with esc...?!?
If a change back the first mod (the one in guikeys.inc) to use esc again it seems to work the over way : i can popup the gui with tab and hide it with esc...?!?
-
- Rookie
- Posts: 12
- Joined: Sat Feb 12, 2005 3:48 pm
I compiled it for windows and you're right it works on linux but in windows it behaves as you said, I'm taking a deeper look right now.Namoi wrote:Thanks, it's a bit of an improvement : i can now pop up the gui, but it doesn't want to hide by repressing tab : in fact the gui diseapear an reappear almost immediatly...
If a change back the first mod (the one in guikeys.inc) to use esc again it seems to work the over way : i can popup the gui with tab and hide it with esc...?!?
-
- ZSNES Shake Shake Prinny
- Posts: 5632
- Joined: Wed Jul 28, 2004 4:15 pm
- Location: PAL50, dood !
The pressed array works like this:
pressed[keycode] == 00b // key isn't pressed
pressed[keycode] == 01b // key is pressed, do something
pressed[keycode] == 10b // key is held, depending what it is, do something or not
The issue with hardcoded values and tests is what you're confronted with.
If you modify which key is tested to go in/out of the GUI, you'll have to change all of them, and update the pressed array correspondingly to prevent effect from being overrepeated.
Typically code should do:
pressed[keycode] == 00b // key isn't pressed
pressed[keycode] == 01b // key is pressed, do something
pressed[keycode] == 10b // key is held, depending what it is, do something or not
The issue with hardcoded values and tests is what you're confronted with.
If you modify which key is tested to go in/out of the GUI, you'll have to change all of them, and update the pressed array correspondingly to prevent effect from being overrepeated.
Typically code should do:
Code: Select all
if (pressed[desired_keycode] & 1)
{
pressed[desired_keycode]++;
stuff_here();
}
皆黙って俺について来い!!
Pantheon: Gideon Zhi | CaitSith2 | Nach | kode54
Code: Select all
<jmr> bsnes has the most accurate wiki page but it takes forever to load (or something)
-
- Rookie
- Posts: 12
- Joined: Sat Feb 12, 2005 3:48 pm
The thing is the changes in the assembler source I made worked on linux, but not on windows and I couldn't figure out why. I haven't seen any other hardcoded ESC value but since its a 1 it's easy to be confused with anything else.grinvader wrote:The pressed array works like this:
pressed[keycode] == 00b // key isn't pressed
pressed[keycode] == 01b // key is pressed, do something
pressed[keycode] == 10b // key is held, depending what it is, do something or not
The issue with hardcoded values and tests is what you're confronted with.
If you modify which key is tested to go in/out of the GUI, you'll have to change all of them, and update the pressed array correspondingly to prevent effect from being overrepeated.
Typically code should do:Code: Select all
if (pressed[desired_keycode] & 1) { pressed[desired_keycode]++; stuff_here(); }
Anyway I found a crappy solution that will only work in the windows port, as I previously did with the linux sdl port, swap ESC and TAB when reading from the keyboard with dinput.
In winlink.cpp in the funcion void WinUpdateDevices()
change:
Code: Select all
void WinUpdateDevices()
{
int i,j;
unsigned char * keys;
unsigned char keys2[256];
for (i = 0; i<256; i++)
keys2[i] = 0;
keys = (unsigned char *)&pressed;
if (KeyboardInput&&InputEn==1)
{
KeyboardInput->GetDeviceState(256, keys2);
}
void WinUpdateDevices()
{
int i,j;
unsigned char * keys;
unsigned char keys2[256];
unsigned char tmp = 0;
for (i = 0; i<256; i++)
keys2 = 0;
keys = (unsigned char *)&pressed;
if (KeyboardInput&&InputEn==1)
{
KeyboardInput->GetDeviceState(256, keys2);
tmp = keys2[1];
keys2[1]= keys2[15] ;
keys2[15] = tmp;
}
Ha, it works indeed... Thanks.
But i understand why you call it a "crappy" way...Funny things is that i still can exit the emulator using the esc key if defined in the cfg file.
Anyway, it's just what i wanted but i still believe that an option should be added to the "misc. keys" menu for that purpose.
I will post a thread in the request forum for it if you think it won't hurt as i know by experience that these subjects could be a little "tense".
Thanks again
edit:
In fact, we must defined the KeyQuickExit value to 15 for it to work or pressing tab during gameplay will exit the emultator...
But i understand why you call it a "crappy" way...Funny things is that i still can exit the emulator using the esc key if defined in the cfg file.
Anyway, it's just what i wanted but i still believe that an option should be added to the "misc. keys" menu for that purpose.
I will post a thread in the request forum for it if you think it won't hurt as i know by experience that these subjects could be a little "tense".
Thanks again
edit:
In fact, we must defined the KeyQuickExit value to 15 for it to work or pressing tab during gameplay will exit the emultator...
-
- Rookie
- Posts: 12
- Joined: Sat Feb 12, 2005 3:48 pm
Note: This is all pure especulation I have no idea of what the current plans for ZSNES are.Namoi wrote:Ha, it works indeed... Thanks.
But i understand why you call it a "crappy" way...Funny things is that i still can exit the emulator using the esc key if defined in the cfg file.
Anyway, it's just what i wanted but i still believe that an option should be added to the "misc. keys" menu for that purpose.
I will post a thread in the request forum for it if you think it won't hurt as i know by experience that these subjects could be a little "tense".
Thanks again
edit:
In fact, we must defined the KeyQuickExit value to 15 for it to work or pressing tab during gameplay will exit the emultator...
Well it's up to the developers, key "configurability" seems a pretty basic and reasonable feature to me.
The sad thing is the state of the asm code (Hardcoded values and all ) a complete rewrite of the input code would make sense.
I remember some time ago reading in this very same forum about a considered/planned rewrite in C for some parts of the asm code but I can't recall exactly which parts were being considered or even if it was going to happen at all.
Anyway the developers have the last word as ZSNES is their child given to birth with pain during all this years and counting.