Author Topic: Porting Unofficial OhBoy to OpenDingux.  (Read 2184 times)

hi-ban (OP)

  • **
  • Posts: 821
Porting Unofficial OhBoy to OpenDingux.
« on: November 06, 2012, 09:13:17 pm »
Hi! I am porting my Unofficial Ohboy to Opendingux, It is finished, but i have a little programming problem:

In the native versions, i used the Power slider (SDLK_PAUSE) to access the menu. But in Opendingux, that button is used for changing the volume (Power+Up/Power+Down) so i can't use it in the Opendingux version.
Anyway, in Opendingux, SDLK_PAUSE seems to be mapped to the "Hold" position of the Power slider. Don't really know what is the mapping for the Power button...

Currently the menu is set to the "Hold" position of the Power slider, but it is no good choice. So i will have to map it to Select+Start. However, i don't know how to set a combination of keys.

Here is what is it now:

Code: [Select]
if(event.key.keysym.sym==SDLK_PAUSE){
dvolume = 0;
osd_persist = 0;
hw.pad = 0;
menu();
}

I want to call the menu when i press Select+Start (SDLK_ESCAPE and SDLK_RETURN). However, this does not work:

Code: [Select]
if((event.key.keysym.sym==SDLK_ESCAPE)&&(event.key.keysym.sym==SDLK_RETURN)){
dvolume = 0;
osd_persist = 0;
hw.pad = 0;
menu();
}

And this one calls the menu only when pressing Select (SDLK_ESCAPE):

Code: [Select]
if(event.key.keysym.sym==(SDLK_ESCAPE)&&(SDLK_RETURN)){
dvolume = 0;
osd_persist = 0;
hw.pad = 0;
menu();
}

I'm sure i'm doing something wrong... any help?

Shin-NiL

  • *
  • Posts: 375
    • Shin-NiL's Personal Web Page (Brazilian Portuguese)
Re: Porting Unofficial OhBoy to OpenDingux.
« Reply #1 on: November 06, 2012, 10:34:09 pm »
I think SDL_GetKeyState could help you. Take a look at the example on the help page

Code: [Select]
Uint8 *keystate = SDL_GetKeyState(NULL);
if ( keystate[SDLK_RETURN] ) printf("Return Key Pressed.\n");
if ( keystate[SDLK_RIGHT] && keystate[SDLK_UP] ) printf("Right and Up Keys Pressed.\n");

DiegoSLTS

  • *
  • Posts: 356
Re: Porting Unofficial OhBoy to OpenDingux.
« Reply #2 on: November 06, 2012, 10:55:19 pm »
Hi, for the button mapping you can take a look here. The Power slider is mapped to KEY_POWER on linux events or "SDLK_POWER" on SDL events. But you're right, it's better to avoid it because of the power daemon.

You can't use the SDL events to check for a combination of keys, every key pressed or released triggers an independant event. The event.key.keysym.sym returns the code of that key, but the AND of two key codes makes the code of another key.

You can do two things:

1 - Save all the events in variables for every key (set a boolean variable "buttonA" to true if the A was pressed, set it to false if it's released), and when you check for the input check those booleans instead of the event.

2 - What Shin-Nil said, use SDL_GetKeyState instead wich returns the state of all the keys at the same time, so you can check for any combination you want.

With the events you have the advantage of doing things only when you have to, with the SDL_GetKeyState you have to check the state periodically.

Anyway, I think that the Dingoo has enough buttons to map the Game Boy buttons AND emulator shortcuts without using combinations.
« Last Edit: November 06, 2012, 10:57:21 pm by DiegoSLTS »

hi-ban (OP)

  • **
  • Posts: 821
Re: Porting Unofficial OhBoy to OpenDingux.
« Reply #3 on: November 07, 2012, 03:14:57 am »
Thanks, SDL_GetKeyState worked.  :)
But for some reason, when going to the menu using buttons which are mapped to something else, after returning to the game they wont register the first keypress of each one.

Anyway, i've mapped the menu keys to L+R.