From efe821252ce39db3701ad4581d432e2bddb2c9e4 Mon Sep 17 00:00:00 2001 From: teuf <> Date: Sat, 21 Apr 2001 22:31:07 +0000 Subject: [PATCH] hpsolo's fix for the joystick code and support for a third axis --- zsnes/src/linux/sdllink.c | 43 ++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/zsnes/src/linux/sdllink.c b/zsnes/src/linux/sdllink.c index d4ad4b80..b6ed9c74 100644 --- a/zsnes/src/linux/sdllink.c +++ b/zsnes/src/linux/sdllink.c @@ -212,6 +212,7 @@ void LinuxExit(void); int Main_Proc(void) { + int j; // TODO: Main event loop SDL_Event event; Uint8 JoyButton; @@ -257,26 +258,20 @@ int Main_Proc(void) case SDL_JOYAXISMOTION: CurrentJoy = event.jaxis.which; - if( event.jaxis.axis == 0) { - if (event.jaxis.value < -16384) { - pressed[0x100 + CurrentJoy*32 + 1] = 1; - } else if (event.jaxis.value > 16384) { - pressed[0x100 + CurrentJoy*32 + 0] = 1; - } else { - pressed[0x100 + CurrentJoy*32 + 1] = 0; - pressed[0x100 + CurrentJoy*32 + 0] = 0; + for (j=0; j<3; j++) { + if (event.jaxis.axis == j) { + if (event.jaxis.value < -16384) { + pressed[0x100 + CurrentJoy*32 + 2*j + 1] = 1; + pressed[0x100 + CurrentJoy*32 + 2*j + 0] = 0; + } else if (event.jaxis.value > 16384) { + pressed[0x100 + CurrentJoy*32 + 2*j + 0] = 1; + pressed[0x100 + CurrentJoy*32 + 2*j + 1] = 0; + } else { + pressed[0x100 + CurrentJoy*32 + 2*j + 0] = 0; + pressed[0x100 + CurrentJoy*32 + 2*j + 1] = 0; + } } - } - if( event.jaxis.axis == 1) { - if (event.jaxis.value < -16384) { - pressed[0x100 + CurrentJoy*32 + 3] = 1; - } else if (event.jaxis.value > 16384) { - pressed[0x100 + CurrentJoy*32 + 2] = 1; - } else { - pressed[0x100 + CurrentJoy*32 + 3] = 0; - pressed[0x100 + CurrentJoy*32 + 2] = 0; - } - } + } break; case SDL_JOYBUTTONDOWN: @@ -858,12 +853,18 @@ BOOL InitJoystickInput(void) // before initialising SDL_INIT_JOYSTICK then // this call can be replaced with SDL_InitSubSystem if (!SDL_NumJoysticks()) { - SDL_QuitSubSystem(SDL_INIT_JOYSTICK); + printf ("ZSNES could not find any joysticks.\n"); + SDL_QuitSubSystem(SDL_INIT_JOYSTICK); return FALSE; } SDL_JoystickEventState(SDL_ENABLE); - for (i=0; i