Changing Esc Key

Strictly for discussing ZSNES development and for submitting code. You can also join us on IRC at irc.libera.chat in #zsnes.
Please, no requests here.

Moderator: ZSNES Mods

Post Reply
Namoi
New Member
Posts: 9
Joined: Fri Dec 19, 2008 10:33 pm

Changing Esc Key

Post by Namoi »

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
Deathlike2
ZSNES Developer
ZSNES Developer
Posts: 6747
Joined: Tue Dec 28, 2004 6:47 am

Post by Deathlike2 »

Unfortunately, the Esc key is hardwired to many different functions of the emu. Changing that behavior will be very difficult.
Continuing [url=http://slickproductions.org/forum/index.php?board=13.0]FF4[/url] Research...
Namoi
New Member
Posts: 9
Joined: Fri Dec 19, 2008 10:33 pm

Post by Namoi »

Raaaahhhh !

Pity....
Namoi
New Member
Posts: 9
Joined: Fri Dec 19, 2008 10:33 pm

Post by Namoi »

Ok, maybe i wasn't totally clear : i don't want to remap the esc key totally but just to change the key used to call the menu... maybe this could be done ?

Hope, hope, hope....
whicker
Trooper
Posts: 479
Joined: Sat Nov 27, 2004 4:33 am

Post by whicker »

Namoi wrote:Ok, maybe i wasn't totally clear : i don't want to remap the esc key totally but just to change the key used to call the menu... maybe this could be done ?

Hope, hope, hope....
not without some programming and recompiling.
odditude
Official tech support dood
Posts: 2118
Joined: Wed Jan 25, 2006 7:57 am

Post by odditude »

whicker wrote:not without some programming and recompiling.
Namoi wrote:Could someone tell me how to change in the source the Esc key [...] ?
Why yes, my shift key *IS* broken.
wah_wah_69
Rookie
Posts: 12
Joined: Sat Feb 12, 2005 3:48 pm

Post by wah_wah_69 »

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

Code: Select all

unsigned int sdl_keysym_to_pc_scancode(int sym)
{
  switch (sym)
  {
    case SDLK_ESCAPE:       return 0x01;
    *************
    case SDLK_TAB:          return 0x0f;
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:

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
Second macro:

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
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

Code: Select all

GUIgetprkeysb 1,27
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:

Code: Select all

NEWSYM pressed, times 256+128+64 db 0 
In execute.asm

Any dev or user if I got any detail wrong, please feel free to correct me.
Namoi
New Member
Posts: 9
Joined: Fri Dec 19, 2008 10:33 pm

Post by Namoi »

I'm using the Win version, so it doesn't seem as "simple" as for the linux one...
Should i put this in the request section, or is someone able to tell me which lines i should change ? I Think i could compile the source by myself after...

Thanks,
wah_wah_69
Rookie
Posts: 12
Joined: Sat Feb 12, 2005 3:48 pm

Post by wah_wah_69 »

If you change

Code: Select all

GUIgetprkeysb 1,27
to

Code: Select all

GUIgetprkeysb 15,27
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.
Namoi
New Member
Posts: 9
Joined: Fri Dec 19, 2008 10:33 pm

Post by Namoi »

Thanks a lot, I'll try this and enjoy my first attempt at compiling the source...

Glup...
Namoi
New Member
Posts: 9
Joined: Fri Dec 19, 2008 10:33 pm

Post by Namoi »

I succeeded to compile the source using your mods but as you pointed it, it is not possible to pop up the gui but only to hide it... here i'm stuck. Any idea how to make it work both ways ?

Thanks
wah_wah_69
Rookie
Posts: 12
Joined: Sat Feb 12, 2005 3:48 pm

Post by wah_wah_69 »

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

Code: Select all

.noincrframekey
    test byte[pressed+1],01h 
To

Code: Select all

.noincrframekey
    test byte[pressed+15],01h 
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.
Namoi
New Member
Posts: 9
Joined: Fri Dec 19, 2008 10:33 pm

Post by Namoi »

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...?!?
wah_wah_69
Rookie
Posts: 12
Joined: Sat Feb 12, 2005 3:48 pm

Post by wah_wah_69 »

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...?!?
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
New Member
Posts: 9
Joined: Fri Dec 19, 2008 10:33 pm

Post by Namoi »

Thanks, i appreciate; i really would like it to work and i'm sorry not to be of a better help, but these matters are a little out of my scope.
grinvader
ZSNES Shake Shake Prinny
Posts: 5632
Joined: Wed Jul 28, 2004 4:15 pm
Location: PAL50, dood !

Post by grinvader »

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();
}
皆黙って俺について来い!!

Code: Select all

<jmr> bsnes has the most accurate wiki page but it takes forever to load (or something)
Pantheon: Gideon Zhi | CaitSith2 | Nach | kode54
wah_wah_69
Rookie
Posts: 12
Joined: Sat Feb 12, 2005 3:48 pm

Post by wah_wah_69 »

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();
}
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.

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);
   }
To


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;
}
Namoi
New Member
Posts: 9
Joined: Fri Dec 19, 2008 10:33 pm

Post by Namoi »

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...
wah_wah_69
Rookie
Posts: 12
Joined: Sat Feb 12, 2005 3:48 pm

Post by wah_wah_69 »

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...
Note: This is all pure especulation I have no idea of what the current plans for ZSNES are.

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.
Post Reply