From ec924bafeb82b3271b671311b5797ae7a54aa4c7 Mon Sep 17 00:00:00 2001 From: "simon.kagstrom" Date: Sun, 7 Mar 2010 09:26:54 +0000 Subject: [PATCH] Fix joystick handling for multiple joysticks (well, partly at least) --- Src/C64.h | 2 +- Src/C64_SDL.h | 1 + Src/Display.cpp | 29 +++++++++++++++++++++-------- Src/Prefs.cpp | 2 +- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Src/C64.h b/Src/C64.h index 42b697c..6c32ca8 100644 --- a/Src/C64.h +++ b/Src/C64.h @@ -164,7 +164,7 @@ private: uint8 poll_joystick(int port); uint8 poll_joystick_axes(int port, bool *has_event); uint8 poll_joystick_hats(int port, bool *has_event); - uint8 poll_joystick_buttons(int port, bool *has_event); + uint8 poll_joystick_buttons(int port, uint8 *table, bool *has_event); void thread_func(void); bool thread_running; // Emulation thread is running diff --git a/Src/C64_SDL.h b/Src/C64_SDL.h index 350c2a9..9b82c84 100644 --- a/Src/C64_SDL.h +++ b/Src/C64_SDL.h @@ -247,6 +247,7 @@ void C64::VBlank(bool draw_frame) if (ThePrefs.JoystickSwap) joy_port_1 = 1; + SDL_JoystickUpdate(); // Poll joysticks j1 = poll_joystick(!joy_port_1); j2 = poll_joystick(joy_port_1); diff --git a/Src/Display.cpp b/Src/Display.cpp index 5a4835e..06fdec4 100644 --- a/Src/Display.cpp +++ b/Src/Display.cpp @@ -884,7 +884,7 @@ uint8 C64::poll_joystick_hats(int port, bool *has_event) return out; } -uint8 C64::poll_joystick_buttons(int port, bool *has_event) +uint8 C64::poll_joystick_buttons(int port, uint8 *table, bool *has_event) { SDL_Joystick *js = joy[port]; uint8 out = 0xff; @@ -901,12 +901,10 @@ uint8 C64::poll_joystick_buttons(int port, bool *has_event) Gui::gui->pushJoystickEvent(ev); *has_event = true; } - if (kc == JOY_NONE) continue; - TheDisplay->UpdateKeyMatrix(kc, !cur, - TheCIA1->KeyMatrix, TheCIA1->RevMatrix, &out); + table[kc] = cur ? 2 : 1; } return out; @@ -919,20 +917,35 @@ uint8 C64::poll_joystick(int port) { bool has_event = false; uint8 out = 0xff; - - if (port == 0 && (joy[0] || joy[1])) - SDL_JoystickUpdate(); + static uint8 last_table_ports[2][0xff]; + static uint8 table_ports[2][0xff]; + uint8 *last_table = last_table_ports[port]; + uint8 *table = table_ports[port]; if (!joy[port]) return out; + memset(table, 0, 0xff); + out &= this->poll_joystick_axes(port, &has_event); out &= this->poll_joystick_hats(port, &has_event); - out &= this->poll_joystick_buttons(port, &has_event); + out &= this->poll_joystick_buttons(port, table, &has_event); if (!has_event) Gui::gui->pushJoystickEvent(EVENT_NONE); + /* Handle keyboard codes */ + for (int i = 0; i < 0x51; i++) + { + if (table[i] == 0 || table[i] == last_table[i]) + continue; + + TheDisplay->UpdateKeyMatrix(i, table[i] == 1, + TheCIA1->KeyMatrix, TheCIA1->RevMatrix, &out); + } + + memcpy(last_table, table, sizeof(table)); + return out; } diff --git a/Src/Prefs.cpp b/Src/Prefs.cpp index 09706bc..a0a81d1 100644 --- a/Src/Prefs.cpp +++ b/Src/Prefs.cpp @@ -158,6 +158,7 @@ void Prefs::SetupJoystickDefaults() this->JoystickButtons[7] = 0x50; this->JoystickButtons[9] = 0x50; this->JoystickButtons[10] = 0x50; + this->MenuJoystickButtons[3] = KEY_SELECT; this->MenuJoystickButtons[7] = KEY_SELECT; this->MenuJoystickButtons[9] = KEY_SELECT; @@ -204,7 +205,6 @@ void Prefs::SetupJoystickDefaults() /* Saitek P380 */ else if (strcmp(name, "Jess Tech Dual Analog Pad") == 0) { - printf("Found joystikk\n"); /* Pad */ this->JoystickHats[0] = HAT_PLAIN; this->MenuJoystickHats[0] = HAT_PLAIN;