--- hatari/src/gui-sdl/dlgJoystick.c 2019/04/01 07:12:47 1.1.1.3 +++ hatari/src/gui-sdl/dlgJoystick.c 2019/04/09 08:48:51 1.1.1.9 @@ -4,7 +4,7 @@ This file is distributed under the GNU Public License, version 2 or at your option any later version. Read the file gpl.txt for details. */ -char DlgJoystick_rcsid[] = "Hatari $Id: dlgJoystick.c,v 1.1.1.3 2019/04/01 07:12:47 root Exp $"; +const char DlgJoystick_fileid[] = "Hatari dlgJoystick.c : " __DATE__ " " __TIME__; #include "main.h" #include "configuration.h" @@ -53,7 +53,7 @@ static SGOBJ joydlg[] = { SGBUTTON, 0, 0, 1,3, 3,1, "\x04" }, /* Arrow left */ { SGBUTTON, 0, 0, 28,3, 3,1, "\x03" }, /* Arrow right */ - { SGBUTTON, 0, 0, 6,16, 20,1, "Back to main menu" }, + { SGBUTTON, SG_DEFAULT, 0, 6,16, 20,1, "Back to main menu" }, { -1, 0, 0, 0,0, 0,0, NULL } }; @@ -72,7 +72,7 @@ static SGOBJ joykeysdlg[] = }; -static char *sJoystickNames[6] = +static char *sJoystickNames[JOYSTICK_COUNT] = { "ST Joystick 0", "ST Joystick 1", @@ -84,9 +84,9 @@ static char *sJoystickNames[6] = /*-----------------------------------------------------------------------*/ -/* - Show dialogs for defining joystick keys and wait for a key press. -*/ +/** + * Show dialogs for defining joystick keys and wait for a key press. + */ static void DlgJoystick_DefineOneKey(char *pType, int *pKey) { SDL_Event sdlEvent; @@ -110,7 +110,7 @@ static void DlgJoystick_DefineOneKey(cha } else if (sdlEvent.type == SDL_QUIT) { - bQuitProgram = TRUE; + bQuitProgram = true; return; } } while (sdlEvent.type != SDL_KEYUP); @@ -119,25 +119,25 @@ static void DlgJoystick_DefineOneKey(cha /*-----------------------------------------------------------------------*/ -/* - Let the user define joystick keys. -*/ +/** + * Let the user define joystick keys. + */ static void DlgJoystick_DefineKeys(int nActJoy) { SDLGui_CenterDlg(joykeysdlg); - DlgJoystick_DefineOneKey("up", &DialogParams.Joysticks.Joy[nActJoy].nKeyCodeUp); - DlgJoystick_DefineOneKey("down", &DialogParams.Joysticks.Joy[nActJoy].nKeyCodeDown); - DlgJoystick_DefineOneKey("left", &DialogParams.Joysticks.Joy[nActJoy].nKeyCodeLeft); - DlgJoystick_DefineOneKey("right", &DialogParams.Joysticks.Joy[nActJoy].nKeyCodeRight); - DlgJoystick_DefineOneKey("fire", &DialogParams.Joysticks.Joy[nActJoy].nKeyCodeFire); + DlgJoystick_DefineOneKey("up", &ConfigureParams.Joysticks.Joy[nActJoy].nKeyCodeUp); + DlgJoystick_DefineOneKey("down", &ConfigureParams.Joysticks.Joy[nActJoy].nKeyCodeDown); + DlgJoystick_DefineOneKey("left", &ConfigureParams.Joysticks.Joy[nActJoy].nKeyCodeLeft); + DlgJoystick_DefineOneKey("right", &ConfigureParams.Joysticks.Joy[nActJoy].nKeyCodeRight); + DlgJoystick_DefineOneKey("fire", &ConfigureParams.Joysticks.Joy[nActJoy].nKeyCodeFire); } /*-----------------------------------------------------------------------*/ -/* - Adapt dialog using the values from the configration structure. -*/ +/** + * Adapt dialog using the values from the configration structure. + */ static void DlgJoystick_ReadValuesFromConf(int nActJoy, int nMaxId) { int i; @@ -147,24 +147,24 @@ static void DlgJoystick_ReadValuesFromCo { strcpy(sSdlStickName, "0: (none available)"); } - else if (DialogParams.Joysticks.Joy[nActJoy].nJoyId <= nMaxId) + else if (ConfigureParams.Joysticks.Joy[nActJoy].nJoyId <= nMaxId) { - snprintf(sSdlStickName, 20, "%i: %s", DialogParams.Joysticks.Joy[nActJoy].nJoyId, - SDL_JoystickName(DialogParams.Joysticks.Joy[nActJoy].nJoyId)); + snprintf(sSdlStickName, 20, "%i: %s", ConfigureParams.Joysticks.Joy[nActJoy].nJoyId, + SDL_JoystickName(ConfigureParams.Joysticks.Joy[nActJoy].nJoyId)); } else { snprintf(sSdlStickName, 20, "0: %s", SDL_JoystickName(0)); /* Unavailable joystick ID -> disable it if necessary*/ - if (DialogParams.Joysticks.Joy[nActJoy].nJoystickMode == JOYSTICK_REALSTICK) - DialogParams.Joysticks.Joy[nActJoy].nJoystickMode = JOYSTICK_DISABLED; + if (ConfigureParams.Joysticks.Joy[nActJoy].nJoystickMode == JOYSTICK_REALSTICK) + ConfigureParams.Joysticks.Joy[nActJoy].nJoystickMode = JOYSTICK_DISABLED; } for (i = DLGJOY_DISABLED; i <= DLGJOY_USEKEYS; i++) joydlg[i].state &= ~SG_SELECTED; - joydlg[DLGJOY_DISABLED + DialogParams.Joysticks.Joy[nActJoy].nJoystickMode].state |= SG_SELECTED; + joydlg[DLGJOY_DISABLED + ConfigureParams.Joysticks.Joy[nActJoy].nJoystickMode].state |= SG_SELECTED; - if (DialogParams.Joysticks.Joy[nActJoy].bEnableAutoFire) + if (ConfigureParams.Joysticks.Joy[nActJoy].bEnableAutoFire) joydlg[DLGJOY_AUTOFIRE].state |= SG_SELECTED; else joydlg[DLGJOY_AUTOFIRE].state &= ~SG_SELECTED; @@ -172,30 +172,30 @@ static void DlgJoystick_ReadValuesFromCo /*-----------------------------------------------------------------------*/ -/* - Read values from dialog and write them to the configuration structure. -*/ +/** + * Read values from dialog and write them to the configuration structure. + */ static void DlgJoystick_WriteValuesToConf(int nActJoy) { - int i; - for (i = DLGJOY_DISABLED; i <= DLGJOY_USEKEYS; i++) + JOYSTICKMODE jmi; + for (jmi = JOYSTICK_DISABLED; jmi <= JOYSTICK_KEYBOARD; jmi++) { - if (joydlg[i].state & SG_SELECTED) + if (joydlg[jmi + DLGJOY_DISABLED].state & SG_SELECTED) { - DialogParams.Joysticks.Joy[nActJoy].nJoystickMode = i - DLGJOY_DISABLED; + ConfigureParams.Joysticks.Joy[nActJoy].nJoystickMode = jmi; break; } } - DialogParams.Joysticks.Joy[nActJoy].bEnableAutoFire = (joydlg[DLGJOY_AUTOFIRE].state & SG_SELECTED); - DialogParams.Joysticks.Joy[nActJoy].nJoyId = joydlg[DLGJOY_SDLJOYNAME].txt[0] - '0'; + ConfigureParams.Joysticks.Joy[nActJoy].bEnableAutoFire = (joydlg[DLGJOY_AUTOFIRE].state & SG_SELECTED); + ConfigureParams.Joysticks.Joy[nActJoy].nJoyId = joydlg[DLGJOY_SDLJOYNAME].txt[0] - '0'; } /*-----------------------------------------------------------------------*/ -/* - Show and process the joystick dialog. -*/ +/** + * Show and process the joystick dialog. + */ void Dialog_JoyDlg(void) { int but; @@ -219,19 +219,19 @@ void Dialog_JoyDlg(void) switch (but) { case DLGJOY_PREVSDLJOY: // Select the previous SDL joystick - if (DialogParams.Joysticks.Joy[nActJoy].nJoyId > '0') + if (ConfigureParams.Joysticks.Joy[nActJoy].nJoyId > 0) { - DialogParams.Joysticks.Joy[nActJoy].nJoyId -= 1; - snprintf(sSdlStickName, 20, "%i: %s", DialogParams.Joysticks.Joy[nActJoy].nJoyId, - SDL_JoystickName(DialogParams.Joysticks.Joy[nActJoy].nJoyId)); + ConfigureParams.Joysticks.Joy[nActJoy].nJoyId -= 1; + snprintf(sSdlStickName, 20, "%i: %s", ConfigureParams.Joysticks.Joy[nActJoy].nJoyId, + SDL_JoystickName(ConfigureParams.Joysticks.Joy[nActJoy].nJoyId)); } break; case DLGJOY_NEXTSDLJOY: // Select the next SDL joystick - if (DialogParams.Joysticks.Joy[nActJoy].nJoyId < nMaxJoyId) + if (ConfigureParams.Joysticks.Joy[nActJoy].nJoyId < nMaxJoyId) { - DialogParams.Joysticks.Joy[nActJoy].nJoyId += 1; - snprintf(sSdlStickName, 20, "%i: %s", DialogParams.Joysticks.Joy[nActJoy].nJoyId, - SDL_JoystickName(DialogParams.Joysticks.Joy[nActJoy].nJoyId)); + ConfigureParams.Joysticks.Joy[nActJoy].nJoyId += 1; + snprintf(sSdlStickName, 20, "%i: %s", ConfigureParams.Joysticks.Joy[nActJoy].nJoyId, + SDL_JoystickName(ConfigureParams.Joysticks.Joy[nActJoy].nJoyId)); } break; case DLGJOY_DEFINEKEYS: // Define new keys for keyboard emulation @@ -257,7 +257,8 @@ void Dialog_JoyDlg(void) break; } } - while (but != DLGJOY_EXIT && but != SDLGUI_QUIT && !bQuitProgram ); + while (but != DLGJOY_EXIT && but != SDLGUI_QUIT + && but != SDLGUI_ERROR && !bQuitProgram); DlgJoystick_WriteValuesToConf(nActJoy); }