5 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)
6 // Cleanups/fixes by James L. Hammons
34 #define BUTTON_OPTION 19
35 #define BUTTON_PAUSE 20
37 // Private function prototypes
39 //void main_screen_switch(void);
43 static uint8 joystick_ram[4];
44 static uint8 joypad_0_buttons[21];
45 static uint8 joypad_1_buttons[21];
48 bool GUIKeyHeld = false;
49 extern int start_logging;
50 int gpu_start_log = 0;
52 int blit_start_log = 0;
54 int effect_start2 = 0, effect_start3 = 0, effect_start4 = 0, effect_start5 = 0, effect_start6 = 0;
55 bool interactiveMode = false;
56 bool iLeft, iRight, iToggle = false;
57 bool keyHeld1 = false, keyHeld2 = false, keyHeld3 = false;
59 bool startMemLog = false;
62 void joystick_init(void)
67 void joystick_exec(void)
69 extern SDL_Joystick * joystick;
70 extern bool useJoystick;
71 uint8 * keystate = SDL_GetKeyState(NULL);
73 memset(joypad_0_buttons, 0, 21);
74 memset(joypad_1_buttons, 0, 21);
75 gpu_start_log = 0; // Only log while key down!
77 effect_start2 = effect_start3 = effect_start4 = effect_start5 = effect_start6 = 0;
79 iLeft = iRight = false;
81 if ((keystate[SDLK_LALT] || keystate[SDLK_RALT]) & keystate[SDLK_RETURN])
84 /* Added/Changed by SDLEMU (http://sdlemu.ngemu.com) */
86 if (keystate[SDLK_UP]) joypad_0_buttons[BUTTON_U] = 0x01;
87 if (keystate[SDLK_DOWN]) joypad_0_buttons[BUTTON_D] = 0x01;
88 if (keystate[SDLK_LEFT]) joypad_0_buttons[BUTTON_L] = 0x01;
89 if (keystate[SDLK_RIGHT]) joypad_0_buttons[BUTTON_R] = 0x01;
90 // The buttons are labelled C,B,A on the controller (going from left to right)
91 if (keystate[SDLK_z]) joypad_0_buttons[BUTTON_C] = 0x01;
92 if (keystate[SDLK_x]) joypad_0_buttons[BUTTON_B] = 0x01;
93 if (keystate[SDLK_c]) joypad_0_buttons[BUTTON_A] = 0x01;
94 //I may yet move these to O and P...
95 if (keystate[SDLK_QUOTE]) joypad_0_buttons[BUTTON_OPTION] = 0x01;
96 if (keystate[SDLK_RETURN]) joypad_0_buttons[BUTTON_PAUSE] = 0x01;
98 if (keystate[SDLK_TAB])
101 showGUI = !showGUI, GUIKeyHeld = true;
106 if (keystate[SDLK_q])
108 if (keystate[SDLK_w])
110 // if (keystate[SDLK_u]) jaguar_long_write(0xf1c384,jaguar_long_read(0xf1c384)+1);
111 if (keystate[SDLK_d])
113 if (keystate[SDLK_l])
115 if (keystate[SDLK_o])
117 if (keystate[SDLK_b])
120 if (keystate[SDLK_1])
122 if (keystate[SDLK_2])
124 if (keystate[SDLK_3])
126 if (keystate[SDLK_4])
128 if (keystate[SDLK_5])
130 if (keystate[SDLK_6])
133 if (keystate[SDLK_i])
134 interactiveMode = true;
136 if (keystate[SDLK_8] && interactiveMode)
139 objectPtr--, keyHeld1 = true;
144 if (keystate[SDLK_0] && interactiveMode)
147 objectPtr++, keyHeld2 = true;
152 if (keystate[SDLK_9] && interactiveMode)
155 iToggle = !iToggle, keyHeld3 = true;
160 if (keystate[SDLK_e])
162 if (keystate[SDLK_r])
163 WriteLog("\n--------> MARK!\n\n");
165 if (keystate[SDLK_KP0]) joypad_0_buttons[BUTTON_0] = 0x01;
166 if (keystate[SDLK_KP1]) joypad_0_buttons[BUTTON_1] = 0x01;
167 if (keystate[SDLK_KP2]) joypad_0_buttons[BUTTON_2] = 0x01;
168 if (keystate[SDLK_KP3]) joypad_0_buttons[BUTTON_3] = 0x01;
169 if (keystate[SDLK_KP4]) joypad_0_buttons[BUTTON_4] = 0x01;
170 if (keystate[SDLK_KP5]) joypad_0_buttons[BUTTON_5] = 0x01;
171 if (keystate[SDLK_KP6]) joypad_0_buttons[BUTTON_6] = 0x01;
172 if (keystate[SDLK_KP7]) joypad_0_buttons[BUTTON_7] = 0x01;
173 if (keystate[SDLK_KP8]) joypad_0_buttons[BUTTON_8] = 0x01;
174 if (keystate[SDLK_KP9]) joypad_0_buttons[BUTTON_9] = 0x01;
176 if (keystate[SDLK_ESCAPE])
179 /* Added/Changed by SDLEMU (http://sdlemu.ngemu.com */
180 /* Joystick support */
184 int16 x = SDL_JoystickGetAxis(joystick, 0),
185 y = SDL_JoystickGetAxis(joystick, 1);
188 joypad_0_buttons[BUTTON_R] = 0x01;
190 joypad_0_buttons[BUTTON_L] = 0x01;
192 joypad_0_buttons[BUTTON_D] = 0x01;
194 joypad_0_buttons[BUTTON_U] = 0x01;
196 if (SDL_JoystickGetButton(joystick, 0) == SDL_PRESSED)
197 joypad_0_buttons[BUTTON_A] = 0x01;
198 if (SDL_JoystickGetButton(joystick, 1) == SDL_PRESSED)
199 joypad_0_buttons[BUTTON_B] = 0x01;
200 if (SDL_JoystickGetButton(joystick, 2) == SDL_PRESSED)
201 joypad_0_buttons[BUTTON_C] = 0x01;
204 /* ADDED by SDLEMU (http://sdlemu.ngemu.com */
205 /* Needed to make sure that the events queue is empty */
209 void joystick_reset(void)
211 memset(joystick_ram, 0x00, 4);
212 memset(joypad_0_buttons, 0, 21);
213 memset(joypad_1_buttons, 0, 21);
216 void joystick_done(void)
220 uint8 joystick_byte_read(uint32 offset)
222 extern bool hardwareTypeNTSC;
228 int pad0Index = joystick_ram[1] & 0x0F;
229 int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
231 // This is bad--we're assuming that a bit is set in the last case. Might not be so!
232 if (!(pad0Index & 0x01))
234 else if (!(pad0Index & 0x02))
236 else if (!(pad0Index & 0x04))
241 if (!(pad1Index & 0x01))
243 else if (!(pad1Index & 0x02))
245 else if (!(pad1Index & 0x04))
250 if (joypad_0_buttons[(pad0Index << 2) + 0]) data |= 0x01;
251 if (joypad_0_buttons[(pad0Index << 2) + 1]) data |= 0x02;
252 if (joypad_0_buttons[(pad0Index << 2) + 2]) data |= 0x04;
253 if (joypad_0_buttons[(pad0Index << 2) + 3]) data |= 0x08;
254 if (joypad_1_buttons[(pad1Index << 2) + 0]) data |= 0x10;
255 if (joypad_1_buttons[(pad1Index << 2) + 1]) data |= 0x20;
256 if (joypad_1_buttons[(pad1Index << 2) + 2]) data |= 0x40;
257 if (joypad_1_buttons[(pad1Index << 2) + 3]) data |= 0x80;
261 else if (offset == 3)
263 uint8 data = 0x2F | (hardwareTypeNTSC ? 0x10 : 0x00);
264 int pad0Index = joystick_ram[1] & 0x0F;
265 //unused int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
267 if (!(pad0Index & 0x01))
269 if (joypad_0_buttons[BUTTON_PAUSE])
271 if (joypad_0_buttons[BUTTON_A])
274 else if (!(pad0Index & 0x02))
276 if (joypad_0_buttons[BUTTON_B])
279 else if (!(pad0Index & 0x04))
281 if (joypad_0_buttons[BUTTON_C])
286 if (joypad_0_buttons[BUTTON_OPTION])
292 return joystick_ram[offset];
295 uint16 joystick_word_read(uint32 offset)
297 return ((uint16)joystick_byte_read((offset+0)&0x03) << 8) | joystick_byte_read((offset+1)&0x03);
300 void joystick_byte_write(uint32 offset, uint8 data)
302 joystick_ram[offset&0x03] = data;
305 void joystick_word_write(uint32 offset, uint16 data)
308 joystick_ram[offset+0] = (data >> 8) & 0xFF;
309 joystick_ram[offset+1] = data & 0xFF;