diff --git a/Src/Display.cpp b/Src/Display.cpp index d37f4dd..0288239 100644 --- a/Src/Display.cpp +++ b/Src/Display.cpp @@ -586,12 +586,38 @@ void C64Display::TranslateKey(SDLKey key, bool key_up, uint8 *key_matrix, case SDLK_RSHIFT: c64_key = MATRIX(6,4); break; case SDLK_LALT: case SDLK_LMETA: c64_key = MATRIX(7,5); break; case SDLK_RALT: case SDLK_RMETA: c64_key = MATRIX(7,5); break; - - case SDLK_UP: c64_key = 0x01 | 0x40; break; - case SDLK_DOWN: c64_key = 0x02 | 0x40; break; - case SDLK_LEFT: c64_key = 0x04 | 0x40; break; - case SDLK_RIGHT: c64_key = 0x08 | 0x40; break; - + case SDLK_UP: + { + if (ThePrefs.CursorKeysForJoystick) + c64_key = 0x01 | 0x40; + else + c64_key = MATRIX(0,7) | 0x80; + break; + } + case SDLK_DOWN: + { + if (ThePrefs.CursorKeysForJoystick) + c64_key = 0x02 | 0x40; + else + c64_key = MATRIX(0,7); + break; + } + case SDLK_LEFT: + { + if (ThePrefs.CursorKeysForJoystick) + c64_key = 0x04 | 0x40; + else + c64_key = MATRIX(0,2) | 0x80; + break; + } + case SDLK_RIGHT: + { + if (ThePrefs.CursorKeysForJoystick) + c64_key = 0x08 | 0x40; + else + c64_key = MATRIX(0,2); + break; + } case SDLK_F1: c64_key = MATRIX(0,4); break; case SDLK_F2: c64_key = MATRIX(0,4) | 0x80; break; case SDLK_F3: c64_key = MATRIX(0,5); break; diff --git a/Src/Prefs.cpp b/Src/Prefs.cpp index 8cfbfd1..9a98224 100644 --- a/Src/Prefs.cpp +++ b/Src/Prefs.cpp @@ -118,6 +118,7 @@ Prefs::Prefs() snprintf(this->NetworkServer, 64, "play.c64-network.org"); this->NetworkPort = 46214; this->NetworkRegion = REGION_UNKNOWN; + this->CursorKeysForJoystick = true; strcpy(this->Theme, "default"); } @@ -319,6 +320,7 @@ bool Prefs::operator==(const Prefs &rhs) const && strcmp(this->NetworkName, rhs.NetworkName) == 0 && strcmp(this->Theme, rhs.Theme) == 0 && this->NetworkAvatar == rhs.NetworkAvatar + && this->CursorKeysForJoystick == rhs.CursorKeysForJoystick ); } @@ -504,6 +506,8 @@ void Prefs::Load(const char *filename) NetworkAvatar = atoi(value); else if (!strcmp(keyword, "Theme")) strcpy(Theme, value); + else if (!strcmp(keyword, "CursorKeysForJoystick")) + CursorKeysForJoystick = !strcmp(value, "TRUE"); } } fclose(file); @@ -616,6 +620,7 @@ bool Prefs::Save(const char *filename) maybe_write(file, NetworkPort != TheDefaultPrefs.NetworkPort, "NetworkPort = %d\n", NetworkPort); maybe_write(file, NetworkRegion != TheDefaultPrefs.NetworkRegion, "NetworkRegion = %d\n", NetworkRegion); maybe_write(file, strcmp(Theme, TheDefaultPrefs.Theme) != 0, "Theme = %s\n", Theme); + maybe_write(file, CursorKeysForJoystick != TheDefaultPrefs.CursorKeysForJoystick, "CursorKeysForJoystick = %s\n", CursorKeysForJoystick ? "TRUE" : "FALSE"); fclose(file); ThePrefsOnDisk = *this; return true; diff --git a/Src/Prefs.h b/Src/Prefs.h index 8747474..c1a618d 100644 --- a/Src/Prefs.h +++ b/Src/Prefs.h @@ -172,6 +172,8 @@ public: int NetworkKey; uint16 NetworkAvatar; char Theme[128]; + + bool CursorKeysForJoystick; }; diff --git a/Src/gui/main_menu.cpp b/Src/gui/main_menu.cpp index 5b39fee..f608e72 100644 --- a/Src/gui/main_menu.cpp +++ b/Src/gui/main_menu.cpp @@ -95,6 +95,13 @@ public: case 1: Gui::gui->pushView(Gui::gui->bkv); break; + case 2: + Gui::gui->np->CursorKeysForJoystick = !Gui::gui->np->CursorKeysForJoystick; + if (Gui::gui->np->CursorKeysForJoystick) + Gui::gui->status_bar->queueMessage("Cursor keys used as joystick"); + else + Gui::gui->status_bar->queueMessage("Cursor keys used as keyboard cursors"); + break; default: panic("Illegal selection\n"); } diff --git a/Src/gui/menu_messages.c b/Src/gui/menu_messages.c index 77fb423..c4a722d 100644 --- a/Src/gui/menu_messages.c +++ b/Src/gui/menu_messages.c @@ -133,7 +133,7 @@ const char *main_menu_messages[14] = { /*02*/ "States", /*03*/ "^|Load|Save|Delete", /*04*/ "Keyboard", - /*05*/ "^|Type|Bind", + /*05*/ "^|Type|Bind|Toggle crsr", /*06*/ " ", /*07*/ "Game info", /*08*/ "Networking", @@ -158,8 +158,10 @@ const char **main_menu_help[14] = { NULL, (const char*[]){ "Bind keyboard keys to the", - "joysticks, or type with", - "the virtual keyboard", + "joysticks, toggle cursor", + "key settings (joystick or", + "cursors) or type with the", + "virtual keyboard", NULL, }, NULL,