aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/NDS.cpp10
-rw-r--r--src/NDS.h2
-rw-r--r--src/libui_sdl/DlgInputConfig.cpp8
-rw-r--r--src/libui_sdl/main.cpp50
4 files changed, 61 insertions, 9 deletions
diff --git a/src/NDS.cpp b/src/NDS.cpp
index bee3a8d..3ebaf44 100644
--- a/src/NDS.cpp
+++ b/src/NDS.cpp
@@ -508,6 +508,16 @@ void ReleaseScreen()
}
+void SetKeyMask(u32 mask)
+{
+ u32 key_lo = mask & 0x3FF;
+ u32 key_hi = (mask >> 10) & 0x3;
+
+ KeyInput &= 0xFFFCFC00;
+ KeyInput |= key_lo | (key_hi << 16);
+}
+
+
void Halt()
{
printf("Halt()\n");
diff --git a/src/NDS.h b/src/NDS.h
index 0d77201..204c67d 100644
--- a/src/NDS.h
+++ b/src/NDS.h
@@ -117,6 +117,8 @@ void ReleaseKey(u32 key);
void TouchScreen(u16 x, u16 y);
void ReleaseScreen();
+void SetKeyMask(u32 mask);
+
void ScheduleEvent(u32 id, bool periodic, s32 delay, void (*func)(u32), u32 param);
void CancelEvent(u32 id);
diff --git a/src/libui_sdl/DlgInputConfig.cpp b/src/libui_sdl/DlgInputConfig.cpp
index a60a0f9..ccacb64 100644
--- a/src/libui_sdl/DlgInputConfig.cpp
+++ b/src/libui_sdl/DlgInputConfig.cpp
@@ -106,7 +106,13 @@ int OnAreaKeyEvent(uiAreaHandler* handler, uiArea* area, uiAreaKeyEvent* evt)
if (pollid < 0x100) return 0;
int id = pollid & 0xFF;
if (id > 12) return 0;
- if (evt->Scancode != 0x1) return 0; // ESC
+ if (evt->Scancode != 0x1) // ESC
+ {
+ if (evt->Scancode == 0xE) // backspace
+ joymap[id] = -1;
+ else
+ return 1;
+ }
char keyname[16];
JoyMappingName(joymap[id], keyname);
diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp
index df5076f..f27c7ed 100644
--- a/src/libui_sdl/main.cpp
+++ b/src/libui_sdl/main.cpp
@@ -57,6 +57,7 @@ u32 ScreenBuffer[256*384];
bool Touching = false;
+u32 KeyInputMask;
SDL_Joystick* Joystick;
@@ -95,6 +96,8 @@ int EmuThreadFunc(void* burp)
SDL_PauseAudioDevice(audio, 0);
}
+ KeyInputMask = 0xFFF;
+
// TODO: support more joysticks
if (SDL_NumJoysticks() > 0)
Joystick = SDL_JoystickOpen(0);
@@ -114,6 +117,39 @@ int EmuThreadFunc(void* burp)
{
EmuStatus = 1;
+ // poll input
+ u32 keymask = KeyInputMask;
+ u32 joymask = 0xFFF;
+ if (Joystick)
+ {
+ SDL_JoystickUpdate();
+
+ Uint32 hat = SDL_JoystickGetHat(Joystick, 0);
+ Sint16 axisX = SDL_JoystickGetAxis(Joystick, 0);
+ Sint16 axisY = SDL_JoystickGetAxis(Joystick, 1);
+
+ for (int i = 0; i < 12; i++)
+ {
+ int btnid = Config::JoyMapping[i];
+ if (btnid < 0) continue;
+
+ bool pressed;
+ if (btnid == 0x101) // up
+ pressed = (hat & SDL_HAT_UP) || (axisY <= -16384);
+ else if (btnid == 0x104) // down
+ pressed = (hat & SDL_HAT_DOWN) || (axisY >= 16384);
+ else if (btnid == 0x102) // right
+ pressed = (hat & SDL_HAT_RIGHT) || (axisX >= 16384);
+ else if (btnid == 0x108) // left
+ pressed = (hat & SDL_HAT_LEFT) || (axisX <= -16384);
+ else
+ pressed = SDL_JoystickGetButton(Joystick, btnid);
+
+ if (pressed) joymask &= ~(1<<i);
+ }
+ }
+ NDS::SetKeyMask(keymask & joymask);
+
// emulate
u32 nlines = NDS::RunFrame();
@@ -258,17 +294,15 @@ int OnAreaKeyEvent(uiAreaHandler* handler, uiArea* area, uiAreaKeyEvent* evt)
if (evt->Up)
{
- for (int i = 0; i < 10; i++)
- if (evt->Scancode == Config::KeyMapping[i]) NDS::ReleaseKey(i);
- if (evt->Scancode == Config::KeyMapping[10]) NDS::ReleaseKey(16);
- if (evt->Scancode == Config::KeyMapping[11]) NDS::ReleaseKey(17);
+ for (int i = 0; i < 12; i++)
+ if (evt->Scancode == Config::KeyMapping[i])
+ KeyInputMask |= (1<<i);
}
else if (!evt->Repeat)
{
- for (int i = 0; i < 10; i++)
- if (evt->Scancode == Config::KeyMapping[i]) NDS::PressKey(i);
- if (evt->Scancode == Config::KeyMapping[10]) NDS::PressKey(16);
- if (evt->Scancode == Config::KeyMapping[11]) NDS::PressKey(17);
+ for (int i = 0; i < 12; i++)
+ if (evt->Scancode == Config::KeyMapping[i])
+ KeyInputMask &= ~(1<<i);
}
return 1;