From c32e80286f0e0e1679454062563bc57b530d38e4 Mon Sep 17 00:00:00 2001 From: punkrockguy318 Date: Sat, 27 Feb 2010 20:05:42 +0000 Subject: [PATCH] SDL: hotkey config system revamped. shouldn't be too difficult to write a GUI for defining hotkeys in the near future --- src/drivers/sdl/config.cpp | 61 ++++++++------ src/drivers/sdl/config.h | 41 ++++++++++ src/drivers/sdl/input.cpp | 161 ++++++++++--------------------------- 3 files changed, 120 insertions(+), 143 deletions(-) diff --git a/src/drivers/sdl/config.cpp b/src/drivers/sdl/config.cpp index c6107efc..b9aeeb93 100644 --- a/src/drivers/sdl/config.cpp +++ b/src/drivers/sdl/config.cpp @@ -32,18 +32,17 @@ int LoadCPalette(const std::string &file) { - printf("Loading custom palette from file...\n"); uint8 tmpp[192]; FILE *fp; if(!(fp = FCEUD_UTF8fopen(file.c_str(), "rb"))) { printf(" Error loading custom palette from file: %s\n", file.c_str()); - return -1; + return 0; } fread(tmpp, 1, 192, fp); FCEUI_SetPaletteArray(tmpp); fclose(fp); - return 0; + return 1; } /** @@ -294,35 +293,49 @@ InitConfig() DefaultFamilyKeyBoard[j]); } - // Hotkeys - prefix = "SDL.Hotkeys."; - config->addOption(prefix + "CheatMenu", SDLK_F1); - config->addOption(prefix + "BindState", SDLK_F2); - #ifdef _S9XLUA_H - config->addOption(prefix + "LoadLua", SDLK_F3); - #endif - config->addOption(prefix + "RenderBG", SDLK_F4); - config->addOption(prefix + "SaveState", SDLK_F5); - config->addOption(prefix + "FrameAdvanceLagSkip", SDLK_LEFTBRACKET); - config->addOption(prefix + "LoadState", SDLK_F7); - config->addOption(prefix + "LagCounterDisplay", SDLK_RIGHTBRACKET); - config->addOption(prefix + "MovieToggleFrameDisplay", SDLK_F9); - config->addOption(prefix + "SubtitleDisplay", SDLK_F10); - config->addOption(prefix + "Reset", SDLK_F11); - config->addOption(prefix + "Screenshot", SDLK_F12); + const int Hotkeys[HK_MAX] = { + SDLK_F1, // cheat menu + SDLK_F2, // bind state + SDLK_F3, // load lua + SDLK_F4, // toggleBG + SDLK_F5, // save state + SDLK_F6, // fds select + SDLK_F7, // load state + SDLK_F8, // fds eject + SDLK_F9, // toggle frame display + SDLK_F10, // toggle subtitle + SDLK_F11, // reset + SDLK_F12, // screenshot + SDLK_PAUSE, // pause + SDLK_MINUS, // speed++ + SDLK_EQUALS, // speed-- + SDLK_BACKSLASH, //frame advnace + SDLK_TAB, // turbo + SDLK_i, // toggle input display + SDLK_o, // toggle movie RW + SDLK_p, // toggle mute capture + 0, // quit + SDLK_DELETE, // frame advance lag skip + SDLK_ESCAPE, // lag counter display + SDLK_0, SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, + SDLK_6, SDLK_7, SDLK_8, SDLK_9}; + + prefix = "SDL.Hotkeys."; + for(int i=0; i < HK_MAX; i++) + config->addOption(prefix + HotkeyStrings[i], Hotkeys[i]); + + /* config->addOption(prefix + "Pause", SDLK_PAUSE); config->addOption(prefix + "DecreaseSpeed", SDLK_MINUS); config->addOption(prefix + "IncreaseSpeed", SDLK_EQUALS); config->addOption(prefix + "FrameAdvance", SDLK_BACKSLASH); - config->addOption(prefix + "FastForward", SDLK_BACKQUOTE); + config->addOption(prefix + "FastForward", SDLK_TAB); config->addOption(prefix + "InputDisplay", SDLK_i); config->addOption(prefix + "MovieToggleReadWrite", SDLK_q); #ifdef CREATE_AVI config->addOption(prefix + "MuteCapture", SDLK_DELETE); #endif config->addOption(prefix + "Quit", SDLK_ESCAPE); - config->addOption(prefix + "FDSSelect", SDLK_F6); - config->addOption(prefix + "FDSEject", SDLK_F8); //config->addOption(prefix + "Power", 0); @@ -339,7 +352,7 @@ InitConfig() config->addOption(prefix + "SelectState8", SDLK_8); config->addOption(prefix + "SelectState9", SDLK_9); - + */ // All mouse devices config->addOption("SDL.OekaKids.0.DeviceType", "Mouse"); @@ -353,7 +366,7 @@ InitConfig() config->addOption("SDL.Zapper.0.DeviceType", "Mouse"); config->addOption("SDL.Zapper.0.DeviceNum", 0); - + return config; } diff --git a/src/drivers/sdl/config.h b/src/drivers/sdl/config.h index 63f485b9..6511fa25 100644 --- a/src/drivers/sdl/config.h +++ b/src/drivers/sdl/config.h @@ -7,4 +7,45 @@ Config *InitConfig(void); void UpdateEMUCore(Config *); int LoadCPalette(const std::string &file); + +// hotkey definitions +const int HK_MAX = 33; + +enum HOTKEY { HK_CHEAT_MENU, HK_BIND_STATE, HK_LOAD_LUA, HK_TOGGLE_BG, + HK_SAVE_STATE, HK_FDS_SELECT, HK_LOAD_STATE, HK_FDS_EJECT , + HK_TOGGLE_FRAME_DISPLAY, HK_TOGGLE_SUBTITLE, HK_RESET, HK_SCREENSHOT, + HK_PAUSE, HK_DECREASE_SPEED, HK_INCREASE_SPEED, HK_FRAME_ADVANCE, HK_TURBO, + HK_TOGGLE_INPUT_DISPLAY, HK_MOVIE_TOGGLE_RW, HK_MUTE_CAPTURE, HK_QUIT, HK_FA_LAG_SKIP, HK_LAG_COUNTER_DISPLAY, + HK_SELECT_STATE_0, HK_SELECT_STATE_1, HK_SELECT_STATE_2, HK_SELECT_STATE_3, + HK_SELECT_STATE_4, HK_SELECT_STATE_5, HK_SELECT_STATE_6, HK_SELECT_STATE_7, + HK_SELECT_STATE_8, HK_SELECT_STATE_9}; +static const char* HotkeyStrings[HK_MAX] = { + "CheatMenu", + "BindState", + "LoadLua", + "ToggleBG", + "SaveState", + "FDSSelect", + "FDSEject", + "LoadState", + + "MovieToggleFrameDisplay", + "SubtitleDisplay", + "Reset", + "Screenshot", + "Pause", + "DecreaseSpeed", + "IncreaseSpeed", + "FrameAdvance", + "Turbo", + "ToggleInputDisplay", + "ToggleMovieRW", + "MuteCapture", + "Quit", + "FrameAdvanceLagSkip", + "LagCounterDisplay", + "SelectState0", "SelectState1", "SelectState2", "SelectState3", + "SelectState4", "SelectState5", "SelectState6", "SelectState7", + "SelectState8", "SelectState9" }; + #endif diff --git a/src/drivers/sdl/input.cpp b/src/drivers/sdl/input.cpp index a25e8b94..6b8d3eb4 100644 --- a/src/drivers/sdl/input.cpp +++ b/src/drivers/sdl/input.cpp @@ -162,97 +162,19 @@ _keyonly(int a) static int g_fkbEnabled = 0; -// key definitions -int cheatMenuKey; -#ifdef _S9XLUA_H -int loadLuaKey; -#endif -int renderBgKey; -int saveStateKey; -int loadStateKey; -int resetKey; -int screenshotKey; -int pauseKey; -int decreaseSpeedKey; -int increaseSpeedKey; -int frameAdvanceKey; -int ffKey; -int powerKey; -int bindStateKey; -int frameAdvanceLagSkipKey; -int quitKey; -int stateKey[10]; -int movieToggleFrameDisplayKey; -int lagCounterDisplayKey; -int SubtitleDisplayKey; -int InputDisplayKey; -int movieToggleReadWriteKey; -#ifdef CREATE_AVI -int MuteCaptureKey; -#endif -int fdsSelectDiskKey; -int fdsEjectKey; - // this function loads the sdl hotkeys from the config file into the // global scope. this elimates the need for accessing the config file + +int Hotkeys[HK_MAX] = {0}; + // on every cycle of keyboardinput() void setHotKeys() { - g_config->getOption("SDL.Hotkeys.CheatMenu", &cheatMenuKey); - #ifdef _S9XLUA_H - g_config->getOption("SDL.Hotkeys.LoadLua", &loadLuaKey); - #endif - g_config->getOption("SDL.Hotkeys.RenderBG", &renderBgKey); - g_config->getOption("SDL.Hotkeys.SaveState", &saveStateKey); - g_config->getOption("SDL.Hotkeys.LoadState", &loadStateKey); - g_config->getOption("SDL.Hotkeys.Reset", &resetKey); - g_config->getOption("SDL.Hotkeys.Screenshot", &screenshotKey); - g_config->getOption("SDL.Hotkeys.Pause", &pauseKey); - g_config->getOption("SDL.Hotkeys.IncreaseSpeed", &increaseSpeedKey); - g_config->getOption("SDL.Hotkeys.DecreaseSpeed", &decreaseSpeedKey); - g_config->getOption("SDL.Hotkeys.FrameAdvance", &frameAdvanceKey); - g_config->getOption("SDL.Hotkeys.FastForward", &ffKey); - g_config->getOption("SDL.Hotkeys.Power", &powerKey); - g_config->getOption("SDL.Hotkeys.Pause", &bindStateKey); - g_config->getOption("SDL.Hotkeys.FrameAdvanceLagSkip", &frameAdvanceLagSkipKey); - g_config->getOption("SDL.Hotkeys.Quit", &quitKey); - g_config->getOption("SDL.Hotkeys.SelectState0", &stateKey[0]); - g_config->getOption("SDL.Hotkeys.SelectState1", &stateKey[1]); - g_config->getOption("SDL.Hotkeys.SelectState2", &stateKey[2]); - g_config->getOption("SDL.Hotkeys.SelectState3", &stateKey[3]); - g_config->getOption("SDL.Hotkeys.SelectState4", &stateKey[4]); - g_config->getOption("SDL.Hotkeys.SelectState5", &stateKey[5]); - g_config->getOption("SDL.Hotkeys.SelectState6", &stateKey[6]); - g_config->getOption("SDL.Hotkeys.SelectState7", &stateKey[7]); - g_config->getOption("SDL.Hotkeys.SelectState8", &stateKey[8]); - g_config->getOption("SDL.Hotkeys.SelectState9", &stateKey[9]); - g_config->getOption("SDL.Hotkeys.LagCounterDisplay", &lagCounterDisplayKey); - g_config->getOption("SDL.Hotkeys.MovieToggleFrameDisplay", &movieToggleFrameDisplayKey); - g_config->getOption("SDL.Hotkeys.SubtitleDisplay", &SubtitleDisplayKey); - g_config->getOption("SDL.Hotkeys.InputDisplay", &InputDisplayKey); - g_config->getOption("SDL.Hotkeys.MovieToggleReadWrite", &movieToggleReadWriteKey); - #ifdef CREATE_AVI - g_config->getOption("SDL.Hotkeys.MuteCapture", &MuteCaptureKey); - #endif - g_config->getOption("SDL.Hotkeys.FDSSelect", &fdsSelectDiskKey); - g_config->getOption("SDL.Hotkeys.FDSEject", &fdsEjectKey); - /* - config->addOption(prefix + "FrameAdvance", SDLK_BACKSLASH); - config->addOption(prefix + "Power", 0); - config->addOption(prefix + "BindState", SDLK_F2); - config->addOption(prefix + "FrameAdvanceLagSkip", SDLK_F6); - config->addOption(prefix + "LagCounterDisplay", SDLK_F8); - config->addOption(prefix + "SelectState0", SDLK_0); - config->addOption(prefix + "SelectState1", SDLK_1); - config->addOption(prefix + "SelectState2", SDLK_2); - config->addOption(prefix + "SelectState3", SDLK_3); - config->addOption(prefix + "SelectState4", SDLK_4); - config->addOption(prefix + "SelectState5", SDLK_5); - config->addOption(prefix + "SelectState6", SDLK_6); - config->addOption(prefix + "SelectState7", SDLK_7); - config->addOption(prefix + "SelectState8", SDLK_8); - config->addOption(prefix + "SelectState9", SDLK_9); - */ + std::string prefix = "SDL.Hotkeys."; + for(int i=0; igetOption(prefix + HotkeyStrings[i], &Hotkeys[i]); + } return; } @@ -508,7 +430,7 @@ KeyboardCommands() is_alt = 0; - if(_keyonly(renderBgKey)) { + if(_keyonly(Hotkeys[HK_TOGGLE_BG])) { if(is_shift) { FCEUI_SetRenderPlanes(true, false); } else { @@ -548,26 +470,26 @@ KeyboardCommands() // Famicom disk-system games if(gametype==GIT_FDS) { - if(_keyonly(fdsSelectDiskKey)) { + if(_keyonly(Hotkeys[HK_FDS_SELECT])) { FCEUI_FDSSelect(); } - if(_keyonly(fdsEjectKey)) { + if(_keyonly(Hotkeys[HK_FDS_EJECT])) { FCEUI_FDSInsert(); } } - if(_keyonly(screenshotKey)) { + if(_keyonly(Hotkeys[HK_SCREENSHOT])) { FCEUI_SaveSnapshot(); } // if not NES Sound Format if(gametype != GIT_NSF) { - if(_keyonly(cheatMenuKey)) { + if(_keyonly(Hotkeys[HK_CHEAT_MENU])) { DoCheatSeq(); } // f5 (default) save key, hold shift to save movie - if(_keyonly(saveStateKey)) { + if(_keyonly(Hotkeys[HK_SAVE_STATE])) { if(is_shift) { movie_fname = const_cast(FCEU_MakeFName(FCEUMKF_MOVIE, 0, 0).c_str()); FCEUI_printf("Recording movie to %s\n", movie_fname); @@ -578,7 +500,7 @@ KeyboardCommands() } // f7 to load state, Shift-f7 to load movie - if(_keyonly(loadStateKey)) { + if(_keyonly(Hotkeys[HK_LOAD_STATE])) { if(is_shift) { FCEUI_StopMovie(); std::string fname; @@ -602,47 +524,47 @@ KeyboardCommands() } - if(_keyonly(decreaseSpeedKey)) { + if(_keyonly(Hotkeys[HK_DECREASE_SPEED])) { DecreaseEmulationSpeed(); } - if(_keyonly(increaseSpeedKey)) { + if(_keyonly(Hotkeys[HK_INCREASE_SPEED])) { IncreaseEmulationSpeed(); } - if(_keyonly(movieToggleFrameDisplayKey)) { + if(_keyonly(Hotkeys[HK_TOGGLE_FRAME_DISPLAY])) { FCEUI_MovieToggleFrameDisplay(); } - if(_keyonly(InputDisplayKey)) { + if(_keyonly(Hotkeys[HK_TOGGLE_INPUT_DISPLAY])) { FCEUI_ToggleInputDisplay(); extern int input_display; g_config->setOption("SDL.InputDisplay", input_display); } - if(_keyonly(movieToggleReadWriteKey)) { + if(_keyonly(Hotkeys[HK_MOVIE_TOGGLE_RW])) { FCEUI_SetMovieToggleReadOnly(!FCEUI_GetMovieToggleReadOnly()); } #ifdef CREATE_AVI - if(_keyonly(MuteCaptureKey)) { + if(_keyonly(Hotkeys[HK_MUTE_CAPTURE])) { extern int mutecapture; mutecapture ^= 1; } #endif - if(_keyonly(pauseKey)) { + if(_keyonly(Hotkeys[HK_PAUSE])) { FCEUI_ToggleEmulationPause(); } // Toggle throttling NoWaiting &= ~1; - if(g_keyState[ffKey]) { + if(g_keyState[Hotkeys[HK_TURBO]]) { NoWaiting |= 1; } static bool frameAdvancing = false; - if(g_keyState[frameAdvanceKey]) + if(g_keyState[Hotkeys[HK_FRAME_ADVANCE]]) { if(frameAdvancing == false) { @@ -659,18 +581,18 @@ KeyboardCommands() } } - if(_keyonly(resetKey)) { + if(_keyonly(Hotkeys[HK_RESET])) { FCEUI_ResetNES(); } - if(_keyonly(powerKey)) { - FCEUI_PowerNES(); - } + //if(_keyonly(Hotkeys[HK_POWER])) { + // FCEUI_PowerNES(); + //} - if(_keyonly(quitKey)) { + if(_keyonly(Hotkeys[HK_QUIT])) { CloseGame(); } #ifdef _S9XLUA_H - if(_keyonly(loadLuaKey)) { + if(_keyonly(Hotkeys[HK_LOAD_LUA])) { std::string fname; fname = GetFilename("Open LUA script...", false, "Lua scripts|*.lua"); if(fname != "") @@ -679,26 +601,26 @@ KeyboardCommands() #endif for(int i=0; i<10; i++) - if(_keyonly(stateKey[i])) + if(_keyonly(Hotkeys[HK_SELECT_STATE_0 + i])) FCEUI_SelectState(i, 1); - if(_keyonly(bindStateKey)) { + if(_keyonly(Hotkeys[HK_BIND_STATE])) { bindSavestate ^= 1; FCEUI_DispMessage("Savestate binding to movie %sabled.", bindSavestate ? "en" : "dis"); } - if(_keyonly(frameAdvanceLagSkipKey)) { + if(_keyonly(Hotkeys[HK_FA_LAG_SKIP])) { frameAdvanceLagSkip ^= 1; FCEUI_DispMessage("Skipping lag in Frame Advance %sabled.", frameAdvanceLagSkip ? "en" : "dis"); } - if(_keyonly(lagCounterDisplayKey)) { + if(_keyonly(Hotkeys[HK_LAG_COUNTER_DISPLAY])) { lagCounterDisplay ^= 1; } - if (_keyonly(SubtitleDisplayKey)) { + if (_keyonly(Hotkeys[HK_TOGGLE_SUBTITLE])) { extern int movieSubtitles; movieSubtitles ^= 1; FCEUI_DispMessage("Movie subtitles o%s.", @@ -736,12 +658,13 @@ KeyboardCommands() - #if SDL_VERSION_ATLEAST(1,3,0) - // TODO: clean this shit up and make it work for 1.3 - #else - if(KEY(KP_MINUS) || KEY(MINUS)) FCEUI_NTSCDEC(); - if(KEY(KP_PLUS) || KEY(EQUAL)) FCEUI_NTSCINC(); - #endif + if (_keyonly(Hotkeys[HK_DECREASE_SPEED])) + FCEUI_NTSCDEC(); + if (_keyonly(Hotkeys[HK_INCREASE_SPEED])) + FCEUI_NTSCINC(); + + + if((InputType[2] == SIFC_BWORLD) || (cspec == SIS_DATACH)) { if(keyonly(F8)) {