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 // extern bool useJoystick;
76 uint8 * keystate = SDL_GetKeyState(NULL);
78 memset(joypad_0_buttons, 0, 21);
79 memset(joypad_1_buttons, 0, 21);
80 gpu_start_log = 0; // Only log while key down!
82 effect_start2 = effect_start3 = effect_start4 = effect_start5 = effect_start6 = 0;
84 iLeft = iRight = false;
86 if ((keystate[SDLK_LALT] || keystate[SDLK_RALT]) & keystate[SDLK_RETURN])
89 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
90 // vjs.p1KeyBindings[0] = sdlemu_getval_int("p1k_up", SDLK_UP);
92 if (keystate[vjs.p1KeyBindings[0]])
93 joypad_0_buttons[BUTTON_U] = 0x01;
94 if (keystate[vjs.p1KeyBindings[1]])
95 joypad_0_buttons[BUTTON_D] = 0x01;
96 if (keystate[vjs.p1KeyBindings[2]])
97 joypad_0_buttons[BUTTON_L] = 0x01;
98 if (keystate[vjs.p1KeyBindings[3]])
99 joypad_0_buttons[BUTTON_R] = 0x01;
100 // The buttons are labelled C,B,A on the controller (going from left to right)
101 if (keystate[vjs.p1KeyBindings[4]])
102 joypad_0_buttons[BUTTON_C] = 0x01;
103 if (keystate[vjs.p1KeyBindings[5]])
104 joypad_0_buttons[BUTTON_B] = 0x01;
105 if (keystate[vjs.p1KeyBindings[6]])
106 joypad_0_buttons[BUTTON_A] = 0x01;
107 //I may yet move these to O and P...
108 if (keystate[vjs.p1KeyBindings[7]])
109 joypad_0_buttons[BUTTON_OPTION] = 0x01;
110 if (keystate[vjs.p1KeyBindings[8]])
111 joypad_0_buttons[BUTTON_PAUSE] = 0x01;
113 if (keystate[vjs.p1KeyBindings[9]])
114 joypad_0_buttons[BUTTON_0] = 0x01;
115 if (keystate[vjs.p1KeyBindings[10]])
116 joypad_0_buttons[BUTTON_1] = 0x01;
117 if (keystate[vjs.p1KeyBindings[11]])
118 joypad_0_buttons[BUTTON_2] = 0x01;
119 if (keystate[vjs.p1KeyBindings[12]])
120 joypad_0_buttons[BUTTON_3] = 0x01;
121 if (keystate[vjs.p1KeyBindings[13]])
122 joypad_0_buttons[BUTTON_4] = 0x01;
123 if (keystate[vjs.p1KeyBindings[14]])
124 joypad_0_buttons[BUTTON_5] = 0x01;
125 if (keystate[vjs.p1KeyBindings[15]])
126 joypad_0_buttons[BUTTON_6] = 0x01;
127 if (keystate[vjs.p1KeyBindings[16]])
128 joypad_0_buttons[BUTTON_7] = 0x01;
129 if (keystate[vjs.p1KeyBindings[17]])
130 joypad_0_buttons[BUTTON_8] = 0x01;
131 if (keystate[vjs.p1KeyBindings[18]])
132 joypad_0_buttons[BUTTON_9] = 0x01;
133 if (keystate[vjs.p1KeyBindings[19]])
134 joypad_0_buttons[BUTTON_s] = 0x01;
135 if (keystate[vjs.p1KeyBindings[20]])
136 joypad_0_buttons[BUTTON_d] = 0x01;
138 extern bool debounceRunKey;
139 if (keystate[SDLK_ESCAPE])
145 debounceRunKey = false;
147 if (keystate[SDLK_TAB])
150 showGUI = !showGUI, GUIKeyHeld = true;
155 if (keystate[SDLK_q])
157 if (keystate[SDLK_w])
159 // if (keystate[SDLK_u]) jaguar_long_write(0xf1c384,jaguar_long_read(0xf1c384)+1);
160 if (keystate[SDLK_d])
162 if (keystate[SDLK_l])
164 if (keystate[SDLK_o])
166 if (keystate[SDLK_b])
169 if (keystate[SDLK_1])
171 if (keystate[SDLK_2])
173 if (keystate[SDLK_3])
175 if (keystate[SDLK_4])
177 if (keystate[SDLK_5])
179 if (keystate[SDLK_6])
182 if (keystate[SDLK_i])
183 interactiveMode = true;
185 if (keystate[SDLK_8] && interactiveMode)
188 objectPtr--, keyHeld1 = true;
193 if (keystate[SDLK_0] && interactiveMode)
196 objectPtr++, keyHeld2 = true;
201 if (keystate[SDLK_9] && interactiveMode)
204 iToggle = !iToggle, keyHeld3 = true;
209 if (keystate[SDLK_e])
211 if (keystate[SDLK_r])
212 WriteLog("\n--------> MARK!\n\n");
213 if (keystate[SDLK_t])
215 if (keystate[SDLK_y])
218 // BLITTER single step
219 if (keystate[SDLK_F5])
220 blitterSingleStep = true;
222 if (keystate[SDLK_F6])
233 // Joystick support [nwagenaar]
237 extern SDL_Joystick * joystick;
238 int16 x = SDL_JoystickGetAxis(joystick, 0),
239 y = SDL_JoystickGetAxis(joystick, 1);
242 joypad_0_buttons[BUTTON_R] = 0x01;
244 joypad_0_buttons[BUTTON_L] = 0x01;
246 joypad_0_buttons[BUTTON_D] = 0x01;
248 joypad_0_buttons[BUTTON_U] = 0x01;
250 if (SDL_JoystickGetButton(joystick, 0) == SDL_PRESSED)
251 joypad_0_buttons[BUTTON_A] = 0x01;
252 if (SDL_JoystickGetButton(joystick, 1) == SDL_PRESSED)
253 joypad_0_buttons[BUTTON_B] = 0x01;
254 if (SDL_JoystickGetButton(joystick, 2) == SDL_PRESSED)
255 joypad_0_buttons[BUTTON_C] = 0x01;
258 // Needed to ensure that the events queue is empty [nwagenaar]
262 void JoystickReset(void)
264 memset(joystick_ram, 0x00, 4);
265 memset(joypad_0_buttons, 0, 21);
266 memset(joypad_1_buttons, 0, 21);
269 void JoystickDone(void)
273 uint8 JoystickReadByte(uint32 offset)
275 #warning No bounds checking done in JoystickReadByte!
276 // extern bool hardwareTypeNTSC;
282 int pad0Index = joystick_ram[1] & 0x0F;
283 int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
285 // This is bad--we're assuming that a bit is set in the last case. Might not be so!
286 if (!(pad0Index & 0x01))
288 else if (!(pad0Index & 0x02))
290 else if (!(pad0Index & 0x04))
295 if (!(pad1Index & 0x01))
297 else if (!(pad1Index & 0x02))
299 else if (!(pad1Index & 0x04))
304 if (joypad_0_buttons[(pad0Index << 2) + 0]) data |= 0x01;
305 if (joypad_0_buttons[(pad0Index << 2) + 1]) data |= 0x02;
306 if (joypad_0_buttons[(pad0Index << 2) + 2]) data |= 0x04;
307 if (joypad_0_buttons[(pad0Index << 2) + 3]) data |= 0x08;
308 if (joypad_1_buttons[(pad1Index << 2) + 0]) data |= 0x10;
309 if (joypad_1_buttons[(pad1Index << 2) + 1]) data |= 0x20;
310 if (joypad_1_buttons[(pad1Index << 2) + 2]) data |= 0x40;
311 if (joypad_1_buttons[(pad1Index << 2) + 3]) data |= 0x80;
315 else if (offset == 3)
317 // Hardware ID returns NTSC/PAL identification bit here
318 uint8 data = 0x2F | (vjs.hardwareTypeNTSC ? 0x10 : 0x00);
319 int pad0Index = joystick_ram[1] & 0x0F;
320 //unused int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
322 if (!(pad0Index & 0x01))
324 if (joypad_0_buttons[BUTTON_PAUSE])
326 if (joypad_0_buttons[BUTTON_A])
329 else if (!(pad0Index & 0x02))
331 if (joypad_0_buttons[BUTTON_B])
334 else if (!(pad0Index & 0x04))
336 if (joypad_0_buttons[BUTTON_C])
341 if (joypad_0_buttons[BUTTON_OPTION])
347 return joystick_ram[offset];
350 uint16 JoystickReadWord(uint32 offset)
352 return ((uint16)JoystickReadByte((offset + 0) & 0x03) << 8) | JoystickReadByte((offset + 1) & 0x03);
355 void JoystickWriteByte(uint32 offset, uint8 data)
357 joystick_ram[offset & 0x03] = data;
360 void JoystickWriteWord(uint32 offset, uint16 data)
362 #warning No bounds checking done for JoystickWriteWord!
364 joystick_ram[offset + 0] = (data >> 8) & 0xFF;
365 joystick_ram[offset + 1] = data & 0xFF;