5 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)
6 // Cleanups by James L. Hammons
10 #include "include/stdafx.h"
18 void main_screen_switch(void);
41 #define BUTTON_OPTION 19
42 #define BUTTON_PAUSE 20
44 static uint8 joystick_ram[4];
45 static uint8 joypad_0_buttons[21];
46 static uint8 joypad_1_buttons[21];
47 extern uint8 finished;
48 extern int start_logging;
51 void joystick_init(void)
56 void joystick_exec(void)
58 uint8 * keystate = SDL_GetKeyState(NULL);
59 extern Console console;
61 memset(joypad_0_buttons, 0, 21);
62 memset(joypad_1_buttons, 0, 21);
64 if ((keystate[SDLK_LALT]) & (keystate[SDLK_RETURN]))
67 /* Added/Changed by SDLEMU (http://sdlemu.ngemu.com) */
69 if (keystate[SDLK_UP]) joypad_0_buttons[BUTTON_U] = 0x01;
70 if (keystate[SDLK_DOWN]) joypad_0_buttons[BUTTON_D] = 0x01;
71 if (keystate[SDLK_LEFT]) joypad_0_buttons[BUTTON_L] = 0x01;
72 if (keystate[SDLK_RIGHT]) joypad_0_buttons[BUTTON_R] = 0x01;
73 if (keystate[SDLK_z]) joypad_0_buttons[BUTTON_A] = 0x01;
74 if (keystate[SDLK_x]) joypad_0_buttons[BUTTON_B] = 0x01;
75 if (keystate[SDLK_c]) joypad_0_buttons[BUTTON_C] = 0x01;
76 if (keystate[SDLK_TAB]) joypad_0_buttons[BUTTON_OPTION] = 0x01;
77 if (keystate[SDLK_RETURN]) joypad_0_buttons[BUTTON_PAUSE] = 0x01;
82 // if (keystate[SDLK_u]) jaguar_long_write(0xf1c384,jaguar_long_read(0xf1c384)+1);
86 if (keystate[SDLK_KP0]) joypad_0_buttons[BUTTON_0] = 0x01;
87 if (keystate[SDLK_KP1]) joypad_0_buttons[BUTTON_1] = 0x01;
88 if (keystate[SDLK_KP2]) joypad_0_buttons[BUTTON_2] = 0x01;
89 if (keystate[SDLK_KP3]) joypad_0_buttons[BUTTON_3] = 0x01;
90 if (keystate[SDLK_KP4]) joypad_0_buttons[BUTTON_4] = 0x01;
91 if (keystate[SDLK_KP5]) joypad_0_buttons[BUTTON_5] = 0x01;
92 if (keystate[SDLK_KP6]) joypad_0_buttons[BUTTON_6] = 0x01;
93 if (keystate[SDLK_KP7]) joypad_0_buttons[BUTTON_7] = 0x01;
94 if (keystate[SDLK_KP8]) joypad_0_buttons[BUTTON_8] = 0x01;
95 if (keystate[SDLK_KP9]) joypad_0_buttons[BUTTON_9] = 0x01;
97 if (keystate[SDLK_ESCAPE])
100 /* Added/Changed by SDLEMU (http://sdlemu.ngemu.com */
101 /* Joystick support */
103 if (console.JoyEnabled() == 1)
105 int16 x = SDL_JoystickGetAxis(console.joystick, 0),
106 y = SDL_JoystickGetAxis(console.joystick, 1);
109 joypad_0_buttons[BUTTON_R] = 0x01;
111 joypad_0_buttons[BUTTON_L] = 0x01;
113 joypad_0_buttons[BUTTON_D] = 0x01;
115 joypad_0_buttons[BUTTON_U] = 0x01;
117 if (SDL_JoystickGetButton(console.joystick, 0) == SDL_PRESSED)
118 joypad_0_buttons[BUTTON_A] = 0x01;
119 if (SDL_JoystickGetButton(console.joystick, 1) == SDL_PRESSED)
120 joypad_0_buttons[BUTTON_B] = 0x01;
121 if (SDL_JoystickGetButton(console.joystick, 2) == SDL_PRESSED)
122 joypad_0_buttons[BUTTON_C] = 0x01;
125 /* ADDED by SDLEMU (http://sdlemu.ngemu.com */
126 /* Needed to make sure that the events queue is empty */
130 void joystick_reset(void)
132 memset(joystick_ram, 0x00, 4);
133 memset(joypad_0_buttons, 0, 21);
134 memset(joypad_1_buttons, 0, 21);
137 void joystick_done(void)
141 void joystick_byte_write(uint32 offset, uint8 data)
143 joystick_ram[offset&0x03] = data;
146 void joystick_word_write(uint32 offset, uint16 data)
149 joystick_ram[offset+0] = (data >> 8) & 0xFF;
150 joystick_ram[offset+1] = data & 0xFF;
153 uint8 joystick_byte_read(uint32 offset)
160 int pad0Index = joystick_ram[1] & 0x0F;
161 int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
163 if (!(pad0Index & 0x01))
165 else if (!(pad0Index & 0x02))
167 else if (!(pad0Index & 0x04))
172 if (!(pad1Index & 0x01))
174 else if (!(pad1Index & 0x02))
176 else if (!(pad1Index & 0x04))
181 if (joypad_0_buttons[(pad0Index << 2) + 0]) data |= 0x01;
182 if (joypad_0_buttons[(pad0Index << 2) + 1]) data |= 0x02;
183 if (joypad_0_buttons[(pad0Index << 2) + 2]) data |= 0x04;
184 if (joypad_0_buttons[(pad0Index << 2) + 3]) data |= 0x08;
185 if (joypad_1_buttons[(pad1Index << 2) + 0]) data |= 0x10;
186 if (joypad_1_buttons[(pad1Index << 2) + 1]) data |= 0x20;
187 if (joypad_1_buttons[(pad1Index << 2) + 2]) data |= 0x40;
188 if (joypad_1_buttons[(pad1Index << 2) + 3]) data |= 0x80;
192 else if (offset == 3)
194 uint8 data = ((1 << 5) | (1 << 4) | 0x0F);
195 int pad0Index = joystick_ram[1] & 0x0F;
196 //unused int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
198 if (!(pad0Index & 0x01))
200 if (joypad_0_buttons[BUTTON_PAUSE])
202 if (joypad_0_buttons[BUTTON_A])
205 else if (!(pad0Index & 0x02))
207 if (joypad_0_buttons[BUTTON_B])
210 else if (!(pad0Index & 0x04))
212 if (joypad_0_buttons[BUTTON_C])
217 if (joypad_0_buttons[BUTTON_OPTION])
223 return joystick_ram[offset];
226 uint16 joystick_word_read(uint32 offset)
228 return ((uint16)joystick_byte_read((offset+0)&0x03) << 8) | joystick_byte_read((offset+1)&0x03);