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 ;-)
47 #define BUTTON_OPTION 19
48 #define BUTTON_PAUSE 20
52 static uint8 joystick_ram[4];
53 static uint8 joypad_0_buttons[21];
54 static uint8 joypad_1_buttons[21];
58 //extern bool finished;
59 ////extern bool showGUI;
60 bool GUIKeyHeld = false;
61 extern int start_logging;
62 int gpu_start_log = 0;
64 int blit_start_log = 0;
66 int effect_start2 = 0, effect_start3 = 0, effect_start4 = 0, effect_start5 = 0, effect_start6 = 0;
67 bool interactiveMode = false;
68 bool iLeft, iRight, iToggle = false;
69 bool keyHeld1 = false, keyHeld2 = false, keyHeld3 = false;
71 bool startMemLog = false;
72 extern bool doDSPDis, doGPUDis;
74 bool blitterSingleStep = false;
78 void JoystickInit(void)
83 void JoystickExec(void)
85 uint8 * keystate = SDL_GetKeyState(NULL);
87 memset(joypad_0_buttons, 0, 21);
88 memset(joypad_1_buttons, 0, 21);
89 gpu_start_log = 0; // Only log while key down!
91 effect_start2 = effect_start3 = effect_start4 = effect_start5 = effect_start6 = 0;
93 iLeft = iRight = false;
95 if ((keystate[SDLK_LALT] || keystate[SDLK_RALT]) & keystate[SDLK_RETURN])
98 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
99 // vjs.p1KeyBindings[0] = sdlemu_getval_int("p1k_up", SDLK_UP);
102 if (keystate[vjs.p1KeyBindings[0]])
103 joypad_0_buttons[BUTTON_U] = 0x01;
104 if (keystate[vjs.p1KeyBindings[1]])
105 joypad_0_buttons[BUTTON_D] = 0x01;
106 if (keystate[vjs.p1KeyBindings[2]])
107 joypad_0_buttons[BUTTON_L] = 0x01;
108 if (keystate[vjs.p1KeyBindings[3]])
109 joypad_0_buttons[BUTTON_R] = 0x01;
110 // The buttons are labelled C,B,A on the controller (going from left to right)
111 if (keystate[vjs.p1KeyBindings[4]])
112 joypad_0_buttons[BUTTON_C] = 0x01;
113 if (keystate[vjs.p1KeyBindings[5]])
114 joypad_0_buttons[BUTTON_B] = 0x01;
115 if (keystate[vjs.p1KeyBindings[6]])
116 joypad_0_buttons[BUTTON_A] = 0x01;
119 joypad_0_buttons[BUTTON_U] = 0x01;
121 joypad_0_buttons[BUTTON_D] = 0x01;
123 joypad_0_buttons[BUTTON_L] = 0x01;
125 joypad_0_buttons[BUTTON_R] = 0x01;
126 // The buttons are labelled C,B,A on the controller (going from left to right)
128 joypad_0_buttons[BUTTON_C] = 0x01;
130 joypad_0_buttons[BUTTON_B] = 0x01;
132 joypad_0_buttons[BUTTON_A] = 0x01;
134 //I may yet move these to O and P...
135 if (keystate[vjs.p1KeyBindings[7]])
136 joypad_0_buttons[BUTTON_OPTION] = 0x01;
137 if (keystate[vjs.p1KeyBindings[8]])
138 joypad_0_buttons[BUTTON_PAUSE] = 0x01;
140 if (keystate[vjs.p1KeyBindings[9]])
141 joypad_0_buttons[BUTTON_0] = 0x01;
142 if (keystate[vjs.p1KeyBindings[10]])
143 joypad_0_buttons[BUTTON_1] = 0x01;
144 if (keystate[vjs.p1KeyBindings[11]])
145 joypad_0_buttons[BUTTON_2] = 0x01;
146 if (keystate[vjs.p1KeyBindings[12]])
147 joypad_0_buttons[BUTTON_3] = 0x01;
148 if (keystate[vjs.p1KeyBindings[13]])
149 joypad_0_buttons[BUTTON_4] = 0x01;
150 if (keystate[vjs.p1KeyBindings[14]])
151 joypad_0_buttons[BUTTON_5] = 0x01;
152 if (keystate[vjs.p1KeyBindings[15]])
153 joypad_0_buttons[BUTTON_6] = 0x01;
154 if (keystate[vjs.p1KeyBindings[16]])
155 joypad_0_buttons[BUTTON_7] = 0x01;
156 if (keystate[vjs.p1KeyBindings[17]])
157 joypad_0_buttons[BUTTON_8] = 0x01;
158 if (keystate[vjs.p1KeyBindings[18]])
159 joypad_0_buttons[BUTTON_9] = 0x01;
160 if (keystate[vjs.p1KeyBindings[19]])
161 joypad_0_buttons[BUTTON_s] = 0x01;
162 if (keystate[vjs.p1KeyBindings[20]])
163 joypad_0_buttons[BUTTON_d] = 0x01;
165 #warning "!!! FIX !!! (debounceRunKey)"
166 // extern bool debounceRunKey;
168 if (keystate[SDLK_ESCAPE])
171 #warning "!!! FIX !!! (finished = true)"
175 debounceRunKey = false;
177 if (keystate[SDLK_TAB])
180 #warning "!!! FIX !!! (showGUI = !showGUI, ...)"
181 ;// showGUI = !showGUI, GUIKeyHeld = true;
186 if (keystate[SDLK_q])
188 if (keystate[SDLK_w])
190 // if (keystate[SDLK_u]) jaguar_long_write(0xf1c384,jaguar_long_read(0xf1c384)+1);
191 if (keystate[SDLK_d])
193 if (keystate[SDLK_l])
195 if (keystate[SDLK_o])
197 if (keystate[SDLK_b])
200 if (keystate[SDLK_1])
202 if (keystate[SDLK_2])
204 if (keystate[SDLK_3])
206 if (keystate[SDLK_4])
208 if (keystate[SDLK_5])
210 if (keystate[SDLK_6])
213 if (keystate[SDLK_i])
214 interactiveMode = true;
216 if (keystate[SDLK_8] && interactiveMode)
219 objectPtr--, keyHeld1 = true;
224 if (keystate[SDLK_0] && interactiveMode)
227 objectPtr++, keyHeld2 = true;
232 if (keystate[SDLK_9] && interactiveMode)
235 iToggle = !iToggle, keyHeld3 = true;
240 if (keystate[SDLK_e])
242 if (keystate[SDLK_r])
243 WriteLog("\n--------> MARK!\n\n");
244 if (keystate[SDLK_t])
246 if (keystate[SDLK_y])
249 // BLITTER single step
250 if (keystate[SDLK_F5])
251 blitterSingleStep = true;
253 if (keystate[SDLK_F6])
264 // Joystick support [nwagenaar]
268 extern SDL_Joystick * joystick1;
269 int16 x = SDL_JoystickGetAxis(joystick1, 0),
270 y = SDL_JoystickGetAxis(joystick1, 1);
273 joypad_0_buttons[BUTTON_R] = 0x01;
275 joypad_0_buttons[BUTTON_L] = 0x01;
277 joypad_0_buttons[BUTTON_D] = 0x01;
279 joypad_0_buttons[BUTTON_U] = 0x01;
281 if (SDL_JoystickGetButton(joystick1, 0) == SDL_PRESSED)
282 joypad_0_buttons[BUTTON_A] = 0x01;
283 if (SDL_JoystickGetButton(joystick1, 1) == SDL_PRESSED)
284 joypad_0_buttons[BUTTON_B] = 0x01;
285 if (SDL_JoystickGetButton(joystick1, 2) == SDL_PRESSED)
286 joypad_0_buttons[BUTTON_C] = 0x01;
289 // Needed to ensure that the events queue is empty [nwagenaar]
293 void JoystickReset(void)
295 memset(joystick_ram, 0x00, 4);
296 memset(joypad_0_buttons, 0, 21);
297 memset(joypad_1_buttons, 0, 21);
300 void JoystickDone(void)
304 uint8 JoystickReadByte(uint32 offset)
306 #warning "No bounds checking done in JoystickReadByte!"
307 // extern bool hardwareTypeNTSC;
313 int pad0Index = joystick_ram[1] & 0x0F;
314 int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
316 // This is bad--we're assuming that a bit is set in the last case. Might not be so!
317 // NOTE: values $7, B, D, & E are only legal ones for pad 0, (rows 3 to 0, in both cases)
318 // $E, D, B, & 7 are only legal ones for pad 1
319 // So the following code is WRONG!
321 if (!(pad0Index & 0x01))
323 else if (!(pad0Index & 0x02))
325 else if (!(pad0Index & 0x04))
330 if (!(pad1Index & 0x01))
332 else if (!(pad1Index & 0x02))
334 else if (!(pad1Index & 0x04))
339 if (joypad_0_buttons[(pad0Index << 2) + 0]) data |= 0x01;
340 if (joypad_0_buttons[(pad0Index << 2) + 1]) data |= 0x02;
341 if (joypad_0_buttons[(pad0Index << 2) + 2]) data |= 0x04;
342 if (joypad_0_buttons[(pad0Index << 2) + 3]) data |= 0x08;
343 if (joypad_1_buttons[(pad1Index << 2) + 0]) data |= 0x10;
344 if (joypad_1_buttons[(pad1Index << 2) + 1]) data |= 0x20;
345 if (joypad_1_buttons[(pad1Index << 2) + 2]) data |= 0x40;
346 if (joypad_1_buttons[(pad1Index << 2) + 3]) data |= 0x80;
350 else if (offset == 3)
352 // Hardware ID returns NTSC/PAL identification bit here
353 uint8 data = 0x2F | (vjs.hardwareTypeNTSC ? 0x10 : 0x00);
354 int pad0Index = joystick_ram[1] & 0x0F;
355 //unused int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
358 if (!(pad0Index & 0x01))
360 if (joypad_0_buttons[BUTTON_PAUSE])
362 if (joypad_0_buttons[BUTTON_A])
365 else if (!(pad0Index & 0x02))
367 if (joypad_0_buttons[BUTTON_B])
370 else if (!(pad0Index & 0x04))
372 if (joypad_0_buttons[BUTTON_C])
377 if (joypad_0_buttons[BUTTON_OPTION])
384 return joystick_ram[offset];
387 uint16 JoystickReadWord(uint32 offset)
389 return ((uint16)JoystickReadByte((offset + 0) & 0x03) << 8) | JoystickReadByte((offset + 1) & 0x03);
392 void JoystickWriteByte(uint32 offset, uint8 data)
394 joystick_ram[offset & 0x03] = data;
397 void JoystickWriteWord(uint32 offset, uint16 data)
399 #warning "No bounds checking done for JoystickWriteWord!"
401 joystick_ram[offset + 0] = (data >> 8) & 0xFF;
402 joystick_ram[offset + 1] = data & 0xFF;