5 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)
6 // Cleanups/fixes by James L. Hammons
40 #define BUTTON_OPTION 19
41 #define BUTTON_PAUSE 20
45 static uint8 joystick_ram[4];
46 static uint8 joypad_0_buttons[21];
47 static uint8 joypad_1_buttons[21];
48 //extern bool finished;
49 ////extern bool showGUI;
50 bool GUIKeyHeld = false;
51 extern int start_logging;
52 int gpu_start_log = 0;
54 int blit_start_log = 0;
56 int effect_start2 = 0, effect_start3 = 0, effect_start4 = 0, effect_start5 = 0, effect_start6 = 0;
57 bool interactiveMode = false;
58 bool iLeft, iRight, iToggle = false;
59 bool keyHeld1 = false, keyHeld2 = false, keyHeld3 = false;
61 bool startMemLog = false;
62 extern bool doDSPDis, doGPUDis;
64 bool blitterSingleStep = false;
68 void JoystickInit(void)
73 void JoystickExec(void)
75 uint8 * keystate = SDL_GetKeyState(NULL);
77 memset(joypad_0_buttons, 0, 21);
78 memset(joypad_1_buttons, 0, 21);
79 gpu_start_log = 0; // Only log while key down!
81 effect_start2 = effect_start3 = effect_start4 = effect_start5 = effect_start6 = 0;
83 iLeft = iRight = false;
85 if ((keystate[SDLK_LALT] || keystate[SDLK_RALT]) & keystate[SDLK_RETURN])
88 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
89 // vjs.p1KeyBindings[0] = sdlemu_getval_int("p1k_up", SDLK_UP);
91 if (keystate[vjs.p1KeyBindings[0]])
92 joypad_0_buttons[BUTTON_U] = 0x01;
93 if (keystate[vjs.p1KeyBindings[1]])
94 joypad_0_buttons[BUTTON_D] = 0x01;
95 if (keystate[vjs.p1KeyBindings[2]])
96 joypad_0_buttons[BUTTON_L] = 0x01;
97 if (keystate[vjs.p1KeyBindings[3]])
98 joypad_0_buttons[BUTTON_R] = 0x01;
99 // The buttons are labelled C,B,A on the controller (going from left to right)
100 if (keystate[vjs.p1KeyBindings[4]])
101 joypad_0_buttons[BUTTON_C] = 0x01;
102 if (keystate[vjs.p1KeyBindings[5]])
103 joypad_0_buttons[BUTTON_B] = 0x01;
104 if (keystate[vjs.p1KeyBindings[6]])
105 joypad_0_buttons[BUTTON_A] = 0x01;
106 //I may yet move these to O and P...
107 if (keystate[vjs.p1KeyBindings[7]])
108 joypad_0_buttons[BUTTON_OPTION] = 0x01;
109 if (keystate[vjs.p1KeyBindings[8]])
110 joypad_0_buttons[BUTTON_PAUSE] = 0x01;
112 if (keystate[vjs.p1KeyBindings[9]])
113 joypad_0_buttons[BUTTON_0] = 0x01;
114 if (keystate[vjs.p1KeyBindings[10]])
115 joypad_0_buttons[BUTTON_1] = 0x01;
116 if (keystate[vjs.p1KeyBindings[11]])
117 joypad_0_buttons[BUTTON_2] = 0x01;
118 if (keystate[vjs.p1KeyBindings[12]])
119 joypad_0_buttons[BUTTON_3] = 0x01;
120 if (keystate[vjs.p1KeyBindings[13]])
121 joypad_0_buttons[BUTTON_4] = 0x01;
122 if (keystate[vjs.p1KeyBindings[14]])
123 joypad_0_buttons[BUTTON_5] = 0x01;
124 if (keystate[vjs.p1KeyBindings[15]])
125 joypad_0_buttons[BUTTON_6] = 0x01;
126 if (keystate[vjs.p1KeyBindings[16]])
127 joypad_0_buttons[BUTTON_7] = 0x01;
128 if (keystate[vjs.p1KeyBindings[17]])
129 joypad_0_buttons[BUTTON_8] = 0x01;
130 if (keystate[vjs.p1KeyBindings[18]])
131 joypad_0_buttons[BUTTON_9] = 0x01;
132 if (keystate[vjs.p1KeyBindings[19]])
133 joypad_0_buttons[BUTTON_s] = 0x01;
134 if (keystate[vjs.p1KeyBindings[20]])
135 joypad_0_buttons[BUTTON_d] = 0x01;
137 extern bool debounceRunKey;
138 if (keystate[SDLK_ESCAPE])
144 debounceRunKey = false;
146 if (keystate[SDLK_TAB])
149 showGUI = !showGUI, GUIKeyHeld = true;
154 if (keystate[SDLK_q])
156 if (keystate[SDLK_w])
158 // if (keystate[SDLK_u]) jaguar_long_write(0xf1c384,jaguar_long_read(0xf1c384)+1);
159 if (keystate[SDLK_d])
161 if (keystate[SDLK_l])
163 if (keystate[SDLK_o])
165 if (keystate[SDLK_b])
168 if (keystate[SDLK_1])
170 if (keystate[SDLK_2])
172 if (keystate[SDLK_3])
174 if (keystate[SDLK_4])
176 if (keystate[SDLK_5])
178 if (keystate[SDLK_6])
181 if (keystate[SDLK_i])
182 interactiveMode = true;
184 if (keystate[SDLK_8] && interactiveMode)
187 objectPtr--, keyHeld1 = true;
192 if (keystate[SDLK_0] && interactiveMode)
195 objectPtr++, keyHeld2 = true;
200 if (keystate[SDLK_9] && interactiveMode)
203 iToggle = !iToggle, keyHeld3 = true;
208 if (keystate[SDLK_e])
210 if (keystate[SDLK_r])
211 WriteLog("\n--------> MARK!\n\n");
212 if (keystate[SDLK_t])
214 if (keystate[SDLK_y])
217 // BLITTER single step
218 if (keystate[SDLK_F5])
219 blitterSingleStep = true;
221 if (keystate[SDLK_F6])
232 // Joystick support [nwagenaar]
236 extern SDL_Joystick * joystick;
237 int16 x = SDL_JoystickGetAxis(joystick, 0),
238 y = SDL_JoystickGetAxis(joystick, 1);
241 joypad_0_buttons[BUTTON_R] = 0x01;
243 joypad_0_buttons[BUTTON_L] = 0x01;
245 joypad_0_buttons[BUTTON_D] = 0x01;
247 joypad_0_buttons[BUTTON_U] = 0x01;
249 if (SDL_JoystickGetButton(joystick, 0) == SDL_PRESSED)
250 joypad_0_buttons[BUTTON_A] = 0x01;
251 if (SDL_JoystickGetButton(joystick, 1) == SDL_PRESSED)
252 joypad_0_buttons[BUTTON_B] = 0x01;
253 if (SDL_JoystickGetButton(joystick, 2) == SDL_PRESSED)
254 joypad_0_buttons[BUTTON_C] = 0x01;
257 // Needed to ensure that the events queue is empty [nwagenaar]
261 void JoystickReset(void)
263 memset(joystick_ram, 0x00, 4);
264 memset(joypad_0_buttons, 0, 21);
265 memset(joypad_1_buttons, 0, 21);
268 void JoystickDone(void)
272 uint8 JoystickReadByte(uint32 offset)
274 #warning "No bounds checking done in JoystickReadByte!"
275 // extern bool hardwareTypeNTSC;
281 int pad0Index = joystick_ram[1] & 0x0F;
282 int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
284 // This is bad--we're assuming that a bit is set in the last case. Might not be so!
285 // NOTE: values $7, B, D, & E are only legal ones for pad 0, (rows 3 to 0, in both cases)
286 // $E, D, B, & 7 are only legal ones for pad 1
287 // So the following code is WRONG!
289 if (!(pad0Index & 0x01))
291 else if (!(pad0Index & 0x02))
293 else if (!(pad0Index & 0x04))
298 if (!(pad1Index & 0x01))
300 else if (!(pad1Index & 0x02))
302 else if (!(pad1Index & 0x04))
307 if (joypad_0_buttons[(pad0Index << 2) + 0]) data |= 0x01;
308 if (joypad_0_buttons[(pad0Index << 2) + 1]) data |= 0x02;
309 if (joypad_0_buttons[(pad0Index << 2) + 2]) data |= 0x04;
310 if (joypad_0_buttons[(pad0Index << 2) + 3]) data |= 0x08;
311 if (joypad_1_buttons[(pad1Index << 2) + 0]) data |= 0x10;
312 if (joypad_1_buttons[(pad1Index << 2) + 1]) data |= 0x20;
313 if (joypad_1_buttons[(pad1Index << 2) + 2]) data |= 0x40;
314 if (joypad_1_buttons[(pad1Index << 2) + 3]) data |= 0x80;
318 else if (offset == 3)
320 // Hardware ID returns NTSC/PAL identification bit here
321 uint8 data = 0x2F | (vjs.hardwareTypeNTSC ? 0x10 : 0x00);
322 int pad0Index = joystick_ram[1] & 0x0F;
323 //unused int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
326 if (!(pad0Index & 0x01))
328 if (joypad_0_buttons[BUTTON_PAUSE])
330 if (joypad_0_buttons[BUTTON_A])
333 else if (!(pad0Index & 0x02))
335 if (joypad_0_buttons[BUTTON_B])
338 else if (!(pad0Index & 0x04))
340 if (joypad_0_buttons[BUTTON_C])
345 if (joypad_0_buttons[BUTTON_OPTION])
352 return joystick_ram[offset];
355 uint16 JoystickReadWord(uint32 offset)
357 return ((uint16)JoystickReadByte((offset + 0) & 0x03) << 8) | JoystickReadByte((offset + 1) & 0x03);
360 void JoystickWriteByte(uint32 offset, uint8 data)
362 joystick_ram[offset & 0x03] = data;
365 void JoystickWriteWord(uint32 offset, uint16 data)
367 #warning "No bounds checking done for JoystickWriteWord!"
369 joystick_ram[offset + 0] = (data >> 8) & 0xFF;
370 joystick_ram[offset + 1] = data & 0xFF;