5 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)
6 // Cleanups/fixes by James L. Hammons
7 // (C) 2010 Underground Software
9 // JLH = James L. Hammons <jlhamm@acm.org>
12 // --- ---------- -------------------------------------------------------------
13 // JLH 01/16/2010 Created this log ;-)
48 #define BUTTON_OPTION 19
49 #define BUTTON_PAUSE 20
54 static uint8 joystick_ram[4];
55 uint8 joypad_0_buttons[21];
56 uint8 joypad_1_buttons[21];
60 //extern bool finished;
61 ////extern bool showGUI;
62 bool GUIKeyHeld = false;
63 extern int start_logging;
64 int gpu_start_log = 0;
66 int blit_start_log = 0;
68 int effect_start2 = 0, effect_start3 = 0, effect_start4 = 0, effect_start5 = 0, effect_start6 = 0;
69 bool interactiveMode = false;
70 bool iLeft, iRight, iToggle = false;
71 bool keyHeld1 = false, keyHeld2 = false, keyHeld3 = false;
73 bool startMemLog = false;
74 extern bool doDSPDis, doGPUDis;
76 bool blitterSingleStep = false;
80 void JoystickInit(void)
85 void JoystickExec(void)
87 // uint8 * keystate = SDL_GetKeyState(NULL);
89 // memset(joypad_0_buttons, 0, 21);
90 // memset(joypad_1_buttons, 0, 21);
91 gpu_start_log = 0; // Only log while key down!
93 effect_start2 = effect_start3 = effect_start4 = effect_start5 = effect_start6 = 0;
95 iLeft = iRight = false;
98 if ((keystate[SDLK_LALT] || keystate[SDLK_RALT]) & keystate[SDLK_RETURN])
101 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
102 // vjs.p1KeyBindings[0] = sdlemu_getval_int("p1k_up", SDLK_UP);
105 if (keystate[vjs.p1KeyBindings[0]])
106 joypad_0_buttons[BUTTON_U] = 0x01;
107 if (keystate[vjs.p1KeyBindings[1]])
108 joypad_0_buttons[BUTTON_D] = 0x01;
109 if (keystate[vjs.p1KeyBindings[2]])
110 joypad_0_buttons[BUTTON_L] = 0x01;
111 if (keystate[vjs.p1KeyBindings[3]])
112 joypad_0_buttons[BUTTON_R] = 0x01;
113 // The buttons are labelled C,B,A on the controller (going from left to right)
114 if (keystate[vjs.p1KeyBindings[4]])
115 joypad_0_buttons[BUTTON_C] = 0x01;
116 if (keystate[vjs.p1KeyBindings[5]])
117 joypad_0_buttons[BUTTON_B] = 0x01;
118 if (keystate[vjs.p1KeyBindings[6]])
119 joypad_0_buttons[BUTTON_A] = 0x01;
120 //I may yet move these to O and P...
121 if (keystate[vjs.p1KeyBindings[7]])
122 joypad_0_buttons[BUTTON_OPTION] = 0x01;
123 if (keystate[vjs.p1KeyBindings[8]])
124 joypad_0_buttons[BUTTON_PAUSE] = 0x01;
126 if (keystate[vjs.p1KeyBindings[9]])
127 joypad_0_buttons[BUTTON_0] = 0x01;
128 if (keystate[vjs.p1KeyBindings[10]])
129 joypad_0_buttons[BUTTON_1] = 0x01;
130 if (keystate[vjs.p1KeyBindings[11]])
131 joypad_0_buttons[BUTTON_2] = 0x01;
132 if (keystate[vjs.p1KeyBindings[12]])
133 joypad_0_buttons[BUTTON_3] = 0x01;
134 if (keystate[vjs.p1KeyBindings[13]])
135 joypad_0_buttons[BUTTON_4] = 0x01;
136 if (keystate[vjs.p1KeyBindings[14]])
137 joypad_0_buttons[BUTTON_5] = 0x01;
138 if (keystate[vjs.p1KeyBindings[15]])
139 joypad_0_buttons[BUTTON_6] = 0x01;
140 if (keystate[vjs.p1KeyBindings[16]])
141 joypad_0_buttons[BUTTON_7] = 0x01;
142 if (keystate[vjs.p1KeyBindings[17]])
143 joypad_0_buttons[BUTTON_8] = 0x01;
144 if (keystate[vjs.p1KeyBindings[18]])
145 joypad_0_buttons[BUTTON_9] = 0x01;
146 if (keystate[vjs.p1KeyBindings[19]])
147 joypad_0_buttons[BUTTON_s] = 0x01;
148 if (keystate[vjs.p1KeyBindings[20]])
149 joypad_0_buttons[BUTTON_d] = 0x01;
152 joypad_0_buttons[BUTTON_U] = 0x01;
154 joypad_0_buttons[BUTTON_D] = 0x01;
156 joypad_0_buttons[BUTTON_L] = 0x01;
158 joypad_0_buttons[BUTTON_R] = 0x01;
159 // The buttons are labelled C,B,A on the controller (going from left to right)
161 joypad_0_buttons[BUTTON_C] = 0x01;
163 joypad_0_buttons[BUTTON_B] = 0x01;
165 joypad_0_buttons[BUTTON_A] = 0x01;
166 //I may yet move these to O and P...
168 joypad_0_buttons[BUTTON_OPTION] = 0x01;
170 joypad_0_buttons[BUTTON_PAUSE] = 0x01;
173 joypad_0_buttons[BUTTON_0] = 0x01;
175 joypad_0_buttons[BUTTON_1] = 0x01;
177 joypad_0_buttons[BUTTON_2] = 0x01;
179 joypad_0_buttons[BUTTON_3] = 0x01;
181 joypad_0_buttons[BUTTON_4] = 0x01;
183 joypad_0_buttons[BUTTON_5] = 0x01;
185 joypad_0_buttons[BUTTON_6] = 0x01;
187 joypad_0_buttons[BUTTON_7] = 0x01;
189 joypad_0_buttons[BUTTON_8] = 0x01;
191 joypad_0_buttons[BUTTON_9] = 0x01;
193 joypad_0_buttons[BUTTON_s] = 0x01;
195 joypad_0_buttons[BUTTON_d] = 0x01;
198 #warning "!!! FIX !!! (debounceRunKey)"
199 // extern bool debounceRunKey;
201 if (keystate[SDLK_ESCAPE])
204 #warning "!!! FIX !!! (finished = true)"
208 debounceRunKey = false;
210 if (keystate[SDLK_TAB])
213 #warning "!!! FIX !!! (showGUI = !showGUI, ...)"
214 ;// showGUI = !showGUI, GUIKeyHeld = true;
219 if (keystate[SDLK_q])
221 if (keystate[SDLK_w])
223 // if (keystate[SDLK_u]) jaguar_long_write(0xf1c384,jaguar_long_read(0xf1c384)+1);
224 if (keystate[SDLK_d])
226 if (keystate[SDLK_l])
228 if (keystate[SDLK_o])
230 if (keystate[SDLK_b])
233 if (keystate[SDLK_1])
235 if (keystate[SDLK_2])
237 if (keystate[SDLK_3])
239 if (keystate[SDLK_4])
241 if (keystate[SDLK_5])
243 if (keystate[SDLK_6])
246 if (keystate[SDLK_i])
247 interactiveMode = true;
249 if (keystate[SDLK_8] && interactiveMode)
252 objectPtr--, keyHeld1 = true;
257 if (keystate[SDLK_0] && interactiveMode)
260 objectPtr++, keyHeld2 = true;
265 if (keystate[SDLK_9] && interactiveMode)
268 iToggle = !iToggle, keyHeld3 = true;
273 if (keystate[SDLK_e])
275 if (keystate[SDLK_r])
276 WriteLog("\n--------> MARK!\n\n");
277 if (keystate[SDLK_t])
279 if (keystate[SDLK_y])
282 // BLITTER single step
283 if (keystate[SDLK_F5])
284 blitterSingleStep = true;
286 if (keystate[SDLK_F6])
297 // We need to ensure that illegal combinations are not possible.
298 // So, we do a simple minded way here...
299 // It would be better to check to see which one was pressed last
300 // and discard that one, but for now...
301 //This didn't work... Was still able to do bad combination.
302 //It's because the GUI is changing this *after* we fix it here.
304 if (joypad_0_buttons[BUTTON_R] && joypad_0_buttons[BUTTON_L])
305 joypad_0_buttons[BUTTON_L] = 0;
307 if (joypad_0_buttons[BUTTON_U] && joypad_0_buttons[BUTTON_D])
308 joypad_0_buttons[BUTTON_D] = 0;
311 // Joystick support [nwagenaar]
315 extern SDL_Joystick * joystick1;
316 int16 x = SDL_JoystickGetAxis(joystick1, 0),
317 y = SDL_JoystickGetAxis(joystick1, 1);
320 joypad_0_buttons[BUTTON_R] = 0x01;
322 joypad_0_buttons[BUTTON_L] = 0x01;
324 joypad_0_buttons[BUTTON_D] = 0x01;
326 joypad_0_buttons[BUTTON_U] = 0x01;
328 if (SDL_JoystickGetButton(joystick1, 0) == SDL_PRESSED)
329 joypad_0_buttons[BUTTON_A] = 0x01;
330 if (SDL_JoystickGetButton(joystick1, 1) == SDL_PRESSED)
331 joypad_0_buttons[BUTTON_B] = 0x01;
332 if (SDL_JoystickGetButton(joystick1, 2) == SDL_PRESSED)
333 joypad_0_buttons[BUTTON_C] = 0x01;
336 // Needed to ensure that the events queue is empty [nwagenaar]
340 void JoystickReset(void)
342 memset(joystick_ram, 0x00, 4);
343 memset(joypad_0_buttons, 0, 21);
344 memset(joypad_1_buttons, 0, 21);
347 void JoystickDone(void)
351 uint8 JoystickReadByte(uint32 offset)
353 #warning "No bounds checking done in JoystickReadByte!"
354 // extern bool hardwareTypeNTSC;
360 int pad0Index = joystick_ram[1] & 0x0F;
361 int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
363 // This is bad--we're assuming that a bit is set in the last case. Might not be so!
364 // NOTE: values $7, B, D, & E are only legal ones for pad 0, (rows 3 to 0, in both cases)
365 // $E, D, B, & 7 are only legal ones for pad 1
366 // So the following code is WRONG!
368 if (!(pad0Index & 0x01))
370 else if (!(pad0Index & 0x02))
372 else if (!(pad0Index & 0x04))
377 if (!(pad1Index & 0x01))
379 else if (!(pad1Index & 0x02))
381 else if (!(pad1Index & 0x04))
386 if (joypad_0_buttons[(pad0Index << 2) + 0]) data |= 0x01;
387 if (joypad_0_buttons[(pad0Index << 2) + 1]) data |= 0x02;
388 if (joypad_0_buttons[(pad0Index << 2) + 2]) data |= 0x04;
389 if (joypad_0_buttons[(pad0Index << 2) + 3]) data |= 0x08;
390 if (joypad_1_buttons[(pad1Index << 2) + 0]) data |= 0x10;
391 if (joypad_1_buttons[(pad1Index << 2) + 1]) data |= 0x20;
392 if (joypad_1_buttons[(pad1Index << 2) + 2]) data |= 0x40;
393 if (joypad_1_buttons[(pad1Index << 2) + 3]) data |= 0x80;
397 else if (offset == 3)
399 // Hardware ID returns NTSC/PAL identification bit here
400 uint8 data = 0x2F | (vjs.hardwareTypeNTSC ? 0x10 : 0x00);
401 int pad0Index = joystick_ram[1] & 0x0F;
402 //unused int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
405 if (!(pad0Index & 0x01))
407 if (joypad_0_buttons[BUTTON_PAUSE])
409 if (joypad_0_buttons[BUTTON_A])
412 else if (!(pad0Index & 0x02))
414 if (joypad_0_buttons[BUTTON_B])
417 else if (!(pad0Index & 0x04))
419 if (joypad_0_buttons[BUTTON_C])
424 if (joypad_0_buttons[BUTTON_OPTION])
431 return joystick_ram[offset];
434 uint16 JoystickReadWord(uint32 offset)
436 return ((uint16)JoystickReadByte((offset + 0) & 0x03) << 8) | JoystickReadByte((offset + 1) & 0x03);
439 void JoystickWriteByte(uint32 offset, uint8 data)
441 joystick_ram[offset & 0x03] = data;
444 void JoystickWriteWord(uint32 offset, uint16 data)
446 #warning "No bounds checking done for JoystickWriteWord!"
448 joystick_ram[offset + 0] = (data >> 8) & 0xFF;
449 joystick_ram[offset + 1] = data & 0xFF;