Skip to content
Merged
73 changes: 51 additions & 22 deletions datadir/WCONTROL.SRC
Original file line number Diff line number Diff line change
Expand Up @@ -190,26 +190,57 @@ Refresh()
WindowString(WHITE, 7.0, i+6, ":")
i++

binding8 = WindowMiniList(9.0, 9.0, 9, 17, binding8, option_string)
binding7 = WindowMiniList(9.0, 8.0, 9, 17, binding7, option_string)
binding6 = WindowMiniList(9.0, 7.0, 9, 17, binding6, option_string)
binding5 = WindowMiniList(9.0, 6.0, 9, 17, binding5, option_string)
binding4 = WindowMiniList(9.0, 5.0, 9, 17, binding4, option_string)
binding3 = WindowMiniList(9.0, 4.0, 9, 17, binding3, option_string)
binding2 = WindowMiniList(9.0, 3.0, 9, 17, binding2, option_string)
binding1 = WindowMiniList(9.0, 2.0, 9, 17, binding1, option_string)
binding0 = WindowMiniList(9.0, 1.0, 9, 17, binding0, option_string)

// Apply the joystick bindings...
SystemSet(SYS_PLAYERDEVICE, player, 0, (binding0>>8))
SystemSet(SYS_PLAYERDEVICE, player, 1, (binding1>>8))
SystemSet(SYS_PLAYERDEVICE, player, 2, (binding2>>8))
SystemSet(SYS_PLAYERDEVICE, player, 3, (binding3>>8))
SystemSet(SYS_PLAYERDEVICE, player, 4, (binding4>>8))
SystemSet(SYS_PLAYERDEVICE, player, 5, (binding5>>8))
SystemSet(SYS_PLAYERDEVICE, player, 6, (binding6>>8))
SystemSet(SYS_PLAYERDEVICE, player, 7, (binding7>>8))
SystemSet(SYS_PLAYERDEVICE, player, 8, (binding8>>8))

i = 0
while(i < 9)
if(WindowImage(9.0, i+1, 9.0, 1.0, NULL, NULL, 0) == 255)
SystemGet(SYS_LASTKEYPRESSED, 0, 0) // Clear out lastkey...
SystemSet(SYS_PLAYERDEVICE, player, i, 0)
i++
// Show current buttons
i = 0
while(i < 9)
current = SystemGet(SYS_PLAYERDEVICE, player, i)
StringClear(String(0))
if(current == 0)
lastkey = SystemGet(SYS_LASTKEYPRESSED, 0, 0)
if(lastkey != 0)
current = lastkey
SystemSet(SYS_PLAYERDEVICE, player, i, lastkey)
if(current)
if(current < 20)
StringAppend(String(0), "Btn", 16)
StringAppendNumber(String(0), current, 16)
if(current == 20)
StringAppend(String(0), "DPadU", 16)
if(current == 21)
StringAppend(String(0), "DPadD", 16)
if(current == 22)
StringAppend(String(0), "DPadL", 16)
if(current == 23)
StringAppend(String(0), "DPadR", 16)
if(current == 26)
StringAppend(String(0), "LTrigg", 16)
if(current == 29)
StringAppend(String(0), "RTrigg", 16)
if(current == 24)
StringAppend(String(0), "RJoyL", 16)
if(current == 25)
StringAppend(String(0), "RJoyU", 16)
if(current == 27)
StringAppend(String(0), "RJoyR", 16)
if(current == 28)
StringAppend(String(0), "RJoyD", 16)
else
StringAppend(String(0), "???", 16)
WindowString(White, 9.0, i+1, String(0))
i++
else
// Make sure we don't screw up the item number...
i = 0
while(i < 9)
WindowImage(9.0, i+1, 0.0, 0.0, NULL, NULL, 0)
i++



Expand Down Expand Up @@ -280,8 +311,6 @@ Refresh()
i++




// Input selection
joystick_count = SystemGet(SYS_NUMJOYSTICK, 0, 0)
if(joystick_count > 4)
Expand Down
101 changes: 97 additions & 4 deletions source/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ unsigned char key_shift[MAX_ASCII]; // Convert an SDLK_ to ASCII cap
unsigned short last_key_pressed = 0; // The sdlk value of the last key pressed...



#define MOUSE_TEXT_TIME 10 // Number of ticks mouse text should show after taking off of character...
#define MAX_MOUSE_BUTTON 4
#define BUTTON0 0
Expand Down Expand Up @@ -73,7 +72,7 @@ unsigned char mouse_camera_active = FALSE; //


#define MAX_JOYSTICK 8
#define MAX_JOYSTICK_BUTTON 16
#define MAX_JOYSTICK_BUTTON 30
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aaron liked to assign powers of 2, instead of arbitrarily chosen numbers. I have seen in the code there are no explicit dependencies on this fact, but wouldn't it be better to set it to 32? Just a question.

Copy link
Copy Markdown
Collaborator

@MiyanoOsu MiyanoOsu Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

30 button is enough for controller, set to 32 is not harm, just not necessary, the array to store button will expand 2 slot that doing nothing

int num_joystick;
void* joystick_structure[MAX_JOYSTICK]; // Used for closing the joysticks...
unsigned char joystick_button_pressed[MAX_JOYSTICK][MAX_JOYSTICK_BUTTON];
Expand Down Expand Up @@ -370,6 +369,8 @@ void input_setup(void)
}
}

input_setup_key_buffer();
input_setup_key_shift();

SDL_JoystickEventState(SDL_ENABLE);
num_joystick = SDL_NumJoysticks();
Expand Down Expand Up @@ -459,7 +460,8 @@ void input_read(void)
unsigned short i, j, num_keys;
SDL_Scancode key;
const unsigned char* key_state;
int temp;
int temp, dpad_offset = 20;
int trigger_offset = 24, trigger_threshold = 1600;



Expand Down Expand Up @@ -575,8 +577,43 @@ void input_read(void)
{
joystick_position_xy[event.jaxis.which][event.jaxis.axis] = (event.jaxis.value-JOY_TOLERANCE)/(32768.0f-JOY_TOLERANCE);
}
} else if (event.jaxis.axis == 2 || event.jaxis.axis == 5) {
// For listen trigger left and trigger right in controller
if(event.jaxis.value > trigger_threshold) {
if(!joystick_button_down[event.jaxis.which][event.jaxis.axis + trigger_offset]) {
joystick_button_pressed[event.jaxis.which][event.jaxis.axis + trigger_offset] = TRUE;
joystick_button_down[event.jaxis.which][event.jaxis.axis + trigger_offset] = TRUE;
last_key_pressed = event.jaxis.axis + trigger_offset;
}
} else {
if(joystick_button_down[event.jaxis.which][event.jaxis.axis + trigger_offset]) {
joystick_button_unpressed[event.jaxis.which][event.jaxis.axis + trigger_offset] = TRUE;
joystick_button_down[event.jaxis.which][event.jaxis.axis + trigger_offset] = FALSE;
}
}
} else if (event.jaxis.axis == 3 || event.jaxis.axis == 4) {
// For listen right joystick
if(event.jaxis.value < -JOY_TOLERANCE) {
if(!joystick_button_down[event.jaxis.which][event.jaxis.axis + trigger_offset - 3]) {
joystick_button_pressed[event.jaxis.which][event.jaxis.axis + trigger_offset - 3] = TRUE;
joystick_button_down[event.jaxis.which][event.jaxis.axis + trigger_offset - 3] = TRUE;
last_key_pressed = event.jaxis.axis + trigger_offset - 3;
} else if(joystick_button_down[event.jaxis.which][event.jaxis.axis + trigger_offset - 3]) {
joystick_button_unpressed[event.jaxis.which][event.jaxis.axis + trigger_offset - 3] = TRUE;
joystick_button_down[event.jaxis.which][event.jaxis.axis + trigger_offset - 3] = FALSE;
}
} else if(event.jaxis.value > JOY_TOLERANCE) {
if(!joystick_button_down[event.jaxis.which][event.jaxis.axis + trigger_offset]) {
joystick_button_pressed[event.jaxis.which][event.jaxis.axis + trigger_offset] = TRUE;
joystick_button_down[event.jaxis.which][event.jaxis.axis + trigger_offset] = TRUE;
last_key_pressed = event.jaxis.axis + trigger_offset;
} else if(joystick_button_down[event.jaxis.which][event.jaxis.axis + trigger_offset]) {
joystick_button_unpressed[event.jaxis.which][event.jaxis.axis + trigger_offset] = TRUE;
joystick_button_down[event.jaxis.which][event.jaxis.axis + trigger_offset] = FALSE;
}
}
}
}
}
break;
case SDL_JOYBUTTONUP:
if(event.jbutton.which < MAX_JOYSTICK)
Expand All @@ -595,6 +632,62 @@ void input_read(void)
{
joystick_button_pressed[event.jbutton.which][event.jbutton.button] = TRUE;
joystick_button_down[event.jbutton.which][event.jbutton.button] = TRUE;
last_key_pressed = event.jbutton.button + 1;
}
}
break;
case SDL_JOYHATMOTION:
if(event.jhat.which < MAX_JOYSTICK) {
if(event.jhat.value & SDL_HAT_UP) {
if(!joystick_button_down[event.jhat.which][dpad_offset + 0]) {
joystick_button_pressed[event.jhat.which][dpad_offset + 0] = TRUE;
joystick_button_down[event.jhat.which][dpad_offset + 0] = TRUE;
last_key_pressed = dpad_offset + 0;
}
} else {
if(joystick_button_down[event.jhat.which][dpad_offset + 0]) {
joystick_button_unpressed[event.jhat.which][dpad_offset + 0] = TRUE;
joystick_button_down[event.jhat.which][dpad_offset + 0] = FALSE;
}
}

if(event.jhat.value & SDL_HAT_DOWN) {
if(!joystick_button_down[event.jhat.which][dpad_offset + 1]) {
joystick_button_pressed[event.jhat.which][dpad_offset + 1] = TRUE;
joystick_button_down[event.jhat.which][dpad_offset + 1] = TRUE;
last_key_pressed = dpad_offset + 1;
}
} else {
if(joystick_button_down[event.jhat.which][dpad_offset + 1]) {
joystick_button_unpressed[event.jhat.which][dpad_offset + 1] = TRUE;
joystick_button_down[event.jhat.which][dpad_offset + 1] = FALSE;
}
}

if(event.jhat.value & SDL_HAT_LEFT) {
if(!joystick_button_down[event.jhat.which][dpad_offset + 2]) {
joystick_button_pressed[event.jhat.which][dpad_offset + 2] = TRUE;
joystick_button_down[event.jhat.which][dpad_offset + 2] = TRUE;
last_key_pressed = dpad_offset + 2;
}
} else {
if(joystick_button_down[event.jhat.which][dpad_offset + 2]) {
joystick_button_unpressed[event.jhat.which][dpad_offset + 2] = TRUE;
joystick_button_down[event.jhat.which][dpad_offset + 2] = FALSE;
}
}

if(event.jhat.value & SDL_HAT_RIGHT) {
if(!joystick_button_down[event.jhat.which][dpad_offset + 3]) {
joystick_button_pressed[event.jhat.which][dpad_offset + 3] = TRUE;
joystick_button_down[event.jhat.which][dpad_offset + 3] = TRUE;
last_key_pressed = dpad_offset + 3;
}
} else {
if(joystick_button_down[event.jhat.which][dpad_offset + 3]) {
joystick_button_unpressed[event.jhat.which][dpad_offset + 3] = TRUE;
joystick_button_down[event.jhat.which][dpad_offset + 3] = FALSE;
}
}
}
break;
Expand Down