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];
55 //extern bool finished;
56 ////extern bool showGUI;
57 bool GUIKeyHeld = false;
58 extern int start_logging;
59 int gpu_start_log = 0;
61 int blit_start_log = 0;
63 int effect_start2 = 0, effect_start3 = 0, effect_start4 = 0, effect_start5 = 0, effect_start6 = 0;
64 bool interactiveMode = false;
65 bool iLeft, iRight, iToggle = false;
66 bool keyHeld1 = false, keyHeld2 = false, keyHeld3 = false;
68 bool startMemLog = false;
69 extern bool doDSPDis, doGPUDis;
71 bool blitterSingleStep = false;
75 void JoystickInit(void)
80 void JoystickExec(void)
82 uint8 * keystate = SDL_GetKeyState(NULL);
84 memset(joypad_0_buttons, 0, 21);
85 memset(joypad_1_buttons, 0, 21);
86 gpu_start_log = 0; // Only log while key down!
88 effect_start2 = effect_start3 = effect_start4 = effect_start5 = effect_start6 = 0;
90 iLeft = iRight = false;
92 if ((keystate[SDLK_LALT] || keystate[SDLK_RALT]) & keystate[SDLK_RETURN])
95 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
96 // vjs.p1KeyBindings[0] = sdlemu_getval_int("p1k_up", SDLK_UP);
98 if (keystate[vjs.p1KeyBindings[0]])
99 joypad_0_buttons[BUTTON_U] = 0x01;
100 if (keystate[vjs.p1KeyBindings[1]])
101 joypad_0_buttons[BUTTON_D] = 0x01;
102 if (keystate[vjs.p1KeyBindings[2]])
103 joypad_0_buttons[BUTTON_L] = 0x01;
104 if (keystate[vjs.p1KeyBindings[3]])
105 joypad_0_buttons[BUTTON_R] = 0x01;
106 // The buttons are labelled C,B,A on the controller (going from left to right)
107 if (keystate[vjs.p1KeyBindings[4]])
108 joypad_0_buttons[BUTTON_C] = 0x01;
109 if (keystate[vjs.p1KeyBindings[5]])
110 joypad_0_buttons[BUTTON_B] = 0x01;
111 if (keystate[vjs.p1KeyBindings[6]])
112 joypad_0_buttons[BUTTON_A] = 0x01;
113 //I may yet move these to O and P...
114 if (keystate[vjs.p1KeyBindings[7]])
115 joypad_0_buttons[BUTTON_OPTION] = 0x01;
116 if (keystate[vjs.p1KeyBindings[8]])
117 joypad_0_buttons[BUTTON_PAUSE] = 0x01;
119 if (keystate[vjs.p1KeyBindings[9]])
120 joypad_0_buttons[BUTTON_0] = 0x01;
121 if (keystate[vjs.p1KeyBindings[10]])
122 joypad_0_buttons[BUTTON_1] = 0x01;
123 if (keystate[vjs.p1KeyBindings[11]])
124 joypad_0_buttons[BUTTON_2] = 0x01;
125 if (keystate[vjs.p1KeyBindings[12]])
126 joypad_0_buttons[BUTTON_3] = 0x01;
127 if (keystate[vjs.p1KeyBindings[13]])
128 joypad_0_buttons[BUTTON_4] = 0x01;
129 if (keystate[vjs.p1KeyBindings[14]])
130 joypad_0_buttons[BUTTON_5] = 0x01;
131 if (keystate[vjs.p1KeyBindings[15]])
132 joypad_0_buttons[BUTTON_6] = 0x01;
133 if (keystate[vjs.p1KeyBindings[16]])
134 joypad_0_buttons[BUTTON_7] = 0x01;
135 if (keystate[vjs.p1KeyBindings[17]])
136 joypad_0_buttons[BUTTON_8] = 0x01;
137 if (keystate[vjs.p1KeyBindings[18]])
138 joypad_0_buttons[BUTTON_9] = 0x01;
139 if (keystate[vjs.p1KeyBindings[19]])
140 joypad_0_buttons[BUTTON_s] = 0x01;
141 if (keystate[vjs.p1KeyBindings[20]])
142 joypad_0_buttons[BUTTON_d] = 0x01;
144 #warning "!!! FIX !!! (debounceRunKey)"
145 // extern bool debounceRunKey;
147 if (keystate[SDLK_ESCAPE])
150 #warning "!!! FIX !!! (finished = true)"
154 debounceRunKey = false;
156 if (keystate[SDLK_TAB])
159 #warning "!!! FIX !!! (showGUI = !showGUI, ...)"
160 ;// showGUI = !showGUI, GUIKeyHeld = true;
165 if (keystate[SDLK_q])
167 if (keystate[SDLK_w])
169 // if (keystate[SDLK_u]) jaguar_long_write(0xf1c384,jaguar_long_read(0xf1c384)+1);
170 if (keystate[SDLK_d])
172 if (keystate[SDLK_l])
174 if (keystate[SDLK_o])
176 if (keystate[SDLK_b])
179 if (keystate[SDLK_1])
181 if (keystate[SDLK_2])
183 if (keystate[SDLK_3])
185 if (keystate[SDLK_4])
187 if (keystate[SDLK_5])
189 if (keystate[SDLK_6])
192 if (keystate[SDLK_i])
193 interactiveMode = true;
195 if (keystate[SDLK_8] && interactiveMode)
198 objectPtr--, keyHeld1 = true;
203 if (keystate[SDLK_0] && interactiveMode)
206 objectPtr++, keyHeld2 = true;
211 if (keystate[SDLK_9] && interactiveMode)
214 iToggle = !iToggle, keyHeld3 = true;
219 if (keystate[SDLK_e])
221 if (keystate[SDLK_r])
222 WriteLog("\n--------> MARK!\n\n");
223 if (keystate[SDLK_t])
225 if (keystate[SDLK_y])
228 // BLITTER single step
229 if (keystate[SDLK_F5])
230 blitterSingleStep = true;
232 if (keystate[SDLK_F6])
243 // Joystick support [nwagenaar]
247 extern SDL_Joystick * joystick1;
248 int16 x = SDL_JoystickGetAxis(joystick1, 0),
249 y = SDL_JoystickGetAxis(joystick1, 1);
252 joypad_0_buttons[BUTTON_R] = 0x01;
254 joypad_0_buttons[BUTTON_L] = 0x01;
256 joypad_0_buttons[BUTTON_D] = 0x01;
258 joypad_0_buttons[BUTTON_U] = 0x01;
260 if (SDL_JoystickGetButton(joystick1, 0) == SDL_PRESSED)
261 joypad_0_buttons[BUTTON_A] = 0x01;
262 if (SDL_JoystickGetButton(joystick1, 1) == SDL_PRESSED)
263 joypad_0_buttons[BUTTON_B] = 0x01;
264 if (SDL_JoystickGetButton(joystick1, 2) == SDL_PRESSED)
265 joypad_0_buttons[BUTTON_C] = 0x01;
268 // Needed to ensure that the events queue is empty [nwagenaar]
272 void JoystickReset(void)
274 memset(joystick_ram, 0x00, 4);
275 memset(joypad_0_buttons, 0, 21);
276 memset(joypad_1_buttons, 0, 21);
279 void JoystickDone(void)
283 uint8 JoystickReadByte(uint32 offset)
285 #warning "No bounds checking done in JoystickReadByte!"
286 // extern bool hardwareTypeNTSC;
292 int pad0Index = joystick_ram[1] & 0x0F;
293 int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
295 // This is bad--we're assuming that a bit is set in the last case. Might not be so!
296 // NOTE: values $7, B, D, & E are only legal ones for pad 0, (rows 3 to 0, in both cases)
297 // $E, D, B, & 7 are only legal ones for pad 1
298 // So the following code is WRONG!
300 if (!(pad0Index & 0x01))
302 else if (!(pad0Index & 0x02))
304 else if (!(pad0Index & 0x04))
309 if (!(pad1Index & 0x01))
311 else if (!(pad1Index & 0x02))
313 else if (!(pad1Index & 0x04))
318 if (joypad_0_buttons[(pad0Index << 2) + 0]) data |= 0x01;
319 if (joypad_0_buttons[(pad0Index << 2) + 1]) data |= 0x02;
320 if (joypad_0_buttons[(pad0Index << 2) + 2]) data |= 0x04;
321 if (joypad_0_buttons[(pad0Index << 2) + 3]) data |= 0x08;
322 if (joypad_1_buttons[(pad1Index << 2) + 0]) data |= 0x10;
323 if (joypad_1_buttons[(pad1Index << 2) + 1]) data |= 0x20;
324 if (joypad_1_buttons[(pad1Index << 2) + 2]) data |= 0x40;
325 if (joypad_1_buttons[(pad1Index << 2) + 3]) data |= 0x80;
329 else if (offset == 3)
331 // Hardware ID returns NTSC/PAL identification bit here
332 uint8 data = 0x2F | (vjs.hardwareTypeNTSC ? 0x10 : 0x00);
333 int pad0Index = joystick_ram[1] & 0x0F;
334 //unused int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
337 if (!(pad0Index & 0x01))
339 if (joypad_0_buttons[BUTTON_PAUSE])
341 if (joypad_0_buttons[BUTTON_A])
344 else if (!(pad0Index & 0x02))
346 if (joypad_0_buttons[BUTTON_B])
349 else if (!(pad0Index & 0x04))
351 if (joypad_0_buttons[BUTTON_C])
356 if (joypad_0_buttons[BUTTON_OPTION])
363 return joystick_ram[offset];
366 uint16 JoystickReadWord(uint32 offset)
368 return ((uint16)JoystickReadByte((offset + 0) & 0x03) << 8) | JoystickReadByte((offset + 1) & 0x03);
371 void JoystickWriteByte(uint32 offset, uint8 data)
373 joystick_ram[offset & 0x03] = data;
376 void JoystickWriteWord(uint32 offset, uint16 data)
378 #warning "No bounds checking done for JoystickWriteWord!"
380 joystick_ram[offset + 0] = (data >> 8) & 0xFF;
381 joystick_ram[offset + 1] = data & 0xFF;