Permalink
Browse files

Improved gamepad support.

  • Loading branch information...
EndeavourAccuracy committed Dec 29, 2015
1 parent 62f3970 commit 01f9e7cca8af2ef44a17b55ef683328181d6b33f
Showing with 51 additions and 25 deletions.
  1. +2 −1 data.h
  2. +5 −5 seg000.c
  3. +44 −19 seg009.c
View
3 data.h
@@ -519,7 +519,8 @@ extern SDL_Window* window_;
extern SDL_Texture* sdl_texture_;
extern SDL_Joystick* sdl_controller_ INIT( = 0 );
extern int joy_states[3] INIT( = { 0, 0, 0 } );
extern int joy_state INIT( = { 0 } ); // hor
extern int gamepad_states[3] INIT( = { 0, 0, 0 } ); // hor, ver, shift
extern int screen_updates_suspended;
View
@@ -1031,19 +1031,19 @@ void __pascal far check_fall_flo() {
// seg000:1051
void __pascal far read_joyst_control() {
// stub
if (joy_states[0] == -1)
if ((gamepad_states[0] == -1) || (joy_state == -1))
control_x = -1;
if (joy_states[0] == 1)
if ((gamepad_states[0] == 1) || (joy_state == 1))
control_x = 1;
if (joy_states[1] == -1)
if (gamepad_states[1] == -1)
control_y = -1;
if (joy_states[1] == 1)
if (gamepad_states[1] == 1)
control_y = 1;
if (joy_states[2])
if (gamepad_states[2] == 1)
control_shift = -1;
}
View
@@ -2434,34 +2434,59 @@ void idle() {
case SDL_JOYAXISMOTION:
if (event.jaxis.axis == 0) {
if (event.jaxis.value < -30000)
joy_states[0] = -1; // left
if (event.jaxis.value < -8000)
joy_state = -1; // left
else if (event.jaxis.value > 30000)
joy_states[0] = 1; // right
else if (event.jaxis.value > 8000)
joy_state = 1; // right
else
joy_states[0] = 0;
joy_state = 0;
}
if (event.jaxis.axis == 1) {
if (event.jaxis.value < -30000)
joy_states[1] = -1; // up
else if (event.jaxis.value > 30000)
joy_states[1] = 1; // down
else
joy_states[1] = 0;
break;
case SDL_JOYHATMOTION:
switch (event.jhat.value)
{
case 2: gamepad_states[0] = 1; break; // right
case 3: gamepad_states[0] = 1; break; // right (and up)
case 6: gamepad_states[0] = 1; break; // right (and down)
case 8: gamepad_states[0] = -1; break; // left
case 9: gamepad_states[0] = -1; break; // left (and up)
case 12: gamepad_states[0] = -1; break; // left (and down)
default: gamepad_states[0] = 0; break;
}
break;
case SDL_JOYBUTTONDOWN:
joy_states[2] = 1;
switch (event.jbutton.button)
{
case 0: gamepad_states[1] = 1; break; /*** A (down) ***/
case 1: quit (0); break; /*** B (quit) ***/
case 2: gamepad_states[2] = 1; break; /*** X (shift) ***/
case 3: gamepad_states[1] = -1; break; /*** Y (up) ***/
case 4: break; /*** left shoulder ***/
case 5: break; /*** right shoulder ***/
case 6: break; /*** back ***/
case 7: break; /*** start ***/
case 8: break; /*** guide ***/
case 9: break; /*** left joystick ***/
case 10: break; /*** right joystick ***/
}
break;
case SDL_JOYBUTTONUP:
joy_states[2] = 0;
switch (event.jbutton.button)
{
case 0: gamepad_states[1] = 0; break; /*** A (down) ***/
case 1: break; /*** B ***/
case 2: gamepad_states[2] = 0; break; /*** X (shift) ***/
case 3: gamepad_states[1] = 0; break; /*** Y (up) ***/
case 4: break; /*** left shoulder ***/
case 5: break; /*** right shoulder ***/
case 6: break; /*** back ***/
case 7: break; /*** start ***/
case 8: break; /*** guide ***/
case 9: break; /*** left joystick ***/
case 10: break; /*** right joystick ***/
}
break;
case SDL_TEXTINPUT:
last_text_input = event.text.text[0]; // UTF-8 formatted char text input

0 comments on commit 01f9e7c

Please sign in to comment.