5 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)
6 // Cleanups/fixes by James L. Hammons
35 #define BUTTON_OPTION 19
36 #define BUTTON_PAUSE 20
40 static uint8 joystick_ram[4];
41 static uint8 joypad_0_buttons[21];
42 static uint8 joypad_1_buttons[21];
45 bool GUIKeyHeld = false;
46 extern int start_logging;
47 int gpu_start_log = 0;
49 int blit_start_log = 0;
51 int effect_start2 = 0, effect_start3 = 0, effect_start4 = 0, effect_start5 = 0, effect_start6 = 0;
52 bool interactiveMode = false;
53 bool iLeft, iRight, iToggle = false;
54 bool keyHeld1 = false, keyHeld2 = false, keyHeld3 = false;
56 bool startMemLog = false;
57 extern bool doDSPDis, doGPUDis;
59 bool blitterSingleStep = false;
63 void joystick_init(void)
68 void joystick_exec(void)
70 // extern bool useJoystick;
71 uint8 * keystate = SDL_GetKeyState(NULL);
73 memset(joypad_0_buttons, 0, 21);
74 memset(joypad_1_buttons, 0, 21);
75 gpu_start_log = 0; // Only log while key down!
77 effect_start2 = effect_start3 = effect_start4 = effect_start5 = effect_start6 = 0;
79 iLeft = iRight = false;
81 if ((keystate[SDLK_LALT] || keystate[SDLK_RALT]) & keystate[SDLK_RETURN])
84 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
85 // vjs.p1KeyBindings[0] = sdlemu_getval_int("p1k_up", SDLK_UP);
87 if (keystate[vjs.p1KeyBindings[0]])
88 joypad_0_buttons[BUTTON_U] = 0x01;
89 if (keystate[vjs.p1KeyBindings[1]])
90 joypad_0_buttons[BUTTON_D] = 0x01;
91 if (keystate[vjs.p1KeyBindings[2]])
92 joypad_0_buttons[BUTTON_L] = 0x01;
93 if (keystate[vjs.p1KeyBindings[3]])
94 joypad_0_buttons[BUTTON_R] = 0x01;
95 // The buttons are labelled C,B,A on the controller (going from left to right)
96 if (keystate[vjs.p1KeyBindings[4]])
97 joypad_0_buttons[BUTTON_C] = 0x01;
98 if (keystate[vjs.p1KeyBindings[5]])
99 joypad_0_buttons[BUTTON_B] = 0x01;
100 if (keystate[vjs.p1KeyBindings[6]])
101 joypad_0_buttons[BUTTON_A] = 0x01;
102 //I may yet move these to O and P...
103 if (keystate[vjs.p1KeyBindings[7]])
104 joypad_0_buttons[BUTTON_OPTION] = 0x01;
105 if (keystate[vjs.p1KeyBindings[8]])
106 joypad_0_buttons[BUTTON_PAUSE] = 0x01;
108 if (keystate[vjs.p1KeyBindings[9]])
109 joypad_0_buttons[BUTTON_0] = 0x01;
110 if (keystate[vjs.p1KeyBindings[10]])
111 joypad_0_buttons[BUTTON_1] = 0x01;
112 if (keystate[vjs.p1KeyBindings[11]])
113 joypad_0_buttons[BUTTON_2] = 0x01;
114 if (keystate[vjs.p1KeyBindings[12]])
115 joypad_0_buttons[BUTTON_3] = 0x01;
116 if (keystate[vjs.p1KeyBindings[13]])
117 joypad_0_buttons[BUTTON_4] = 0x01;
118 if (keystate[vjs.p1KeyBindings[14]])
119 joypad_0_buttons[BUTTON_5] = 0x01;
120 if (keystate[vjs.p1KeyBindings[15]])
121 joypad_0_buttons[BUTTON_6] = 0x01;
122 if (keystate[vjs.p1KeyBindings[16]])
123 joypad_0_buttons[BUTTON_7] = 0x01;
124 if (keystate[vjs.p1KeyBindings[17]])
125 joypad_0_buttons[BUTTON_8] = 0x01;
126 if (keystate[vjs.p1KeyBindings[18]])
127 joypad_0_buttons[BUTTON_9] = 0x01;
128 if (keystate[vjs.p1KeyBindings[19]])
129 joypad_0_buttons[BUTTON_s] = 0x01;
130 if (keystate[vjs.p1KeyBindings[20]])
131 joypad_0_buttons[BUTTON_d] = 0x01;
133 extern bool debounceRunKey;
134 if (keystate[SDLK_ESCAPE])
140 debounceRunKey = false;
142 if (keystate[SDLK_TAB])
145 showGUI = !showGUI, GUIKeyHeld = true;
150 if (keystate[SDLK_q])
152 if (keystate[SDLK_w])
154 // if (keystate[SDLK_u]) jaguar_long_write(0xf1c384,jaguar_long_read(0xf1c384)+1);
155 if (keystate[SDLK_d])
157 if (keystate[SDLK_l])
159 if (keystate[SDLK_o])
161 if (keystate[SDLK_b])
164 if (keystate[SDLK_1])
166 if (keystate[SDLK_2])
168 if (keystate[SDLK_3])
170 if (keystate[SDLK_4])
172 if (keystate[SDLK_5])
174 if (keystate[SDLK_6])
177 if (keystate[SDLK_i])
178 interactiveMode = true;
180 if (keystate[SDLK_8] && interactiveMode)
183 objectPtr--, keyHeld1 = true;
188 if (keystate[SDLK_0] && interactiveMode)
191 objectPtr++, keyHeld2 = true;
196 if (keystate[SDLK_9] && interactiveMode)
199 iToggle = !iToggle, keyHeld3 = true;
204 if (keystate[SDLK_e])
206 if (keystate[SDLK_r])
207 WriteLog("\n--------> MARK!\n\n");
208 if (keystate[SDLK_t])
210 if (keystate[SDLK_y])
213 // BLITTER single step
214 if (keystate[SDLK_F5])
215 blitterSingleStep = true;
217 if (keystate[SDLK_F6])
228 // Joystick support [nwagenaar]
232 extern SDL_Joystick * joystick;
233 int16 x = SDL_JoystickGetAxis(joystick, 0),
234 y = SDL_JoystickGetAxis(joystick, 1);
237 joypad_0_buttons[BUTTON_R] = 0x01;
239 joypad_0_buttons[BUTTON_L] = 0x01;
241 joypad_0_buttons[BUTTON_D] = 0x01;
243 joypad_0_buttons[BUTTON_U] = 0x01;
245 if (SDL_JoystickGetButton(joystick, 0) == SDL_PRESSED)
246 joypad_0_buttons[BUTTON_A] = 0x01;
247 if (SDL_JoystickGetButton(joystick, 1) == SDL_PRESSED)
248 joypad_0_buttons[BUTTON_B] = 0x01;
249 if (SDL_JoystickGetButton(joystick, 2) == SDL_PRESSED)
250 joypad_0_buttons[BUTTON_C] = 0x01;
253 // Needed to ensure that the events queue is empty [nwagenaar]
257 void joystick_reset(void)
259 memset(joystick_ram, 0x00, 4);
260 memset(joypad_0_buttons, 0, 21);
261 memset(joypad_1_buttons, 0, 21);
264 void joystick_done(void)
268 uint8 joystick_byte_read(uint32 offset)
270 // extern bool hardwareTypeNTSC;
276 int pad0Index = joystick_ram[1] & 0x0F;
277 int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
279 // This is bad--we're assuming that a bit is set in the last case. Might not be so!
280 if (!(pad0Index & 0x01))
282 else if (!(pad0Index & 0x02))
284 else if (!(pad0Index & 0x04))
289 if (!(pad1Index & 0x01))
291 else if (!(pad1Index & 0x02))
293 else if (!(pad1Index & 0x04))
298 if (joypad_0_buttons[(pad0Index << 2) + 0]) data |= 0x01;
299 if (joypad_0_buttons[(pad0Index << 2) + 1]) data |= 0x02;
300 if (joypad_0_buttons[(pad0Index << 2) + 2]) data |= 0x04;
301 if (joypad_0_buttons[(pad0Index << 2) + 3]) data |= 0x08;
302 if (joypad_1_buttons[(pad1Index << 2) + 0]) data |= 0x10;
303 if (joypad_1_buttons[(pad1Index << 2) + 1]) data |= 0x20;
304 if (joypad_1_buttons[(pad1Index << 2) + 2]) data |= 0x40;
305 if (joypad_1_buttons[(pad1Index << 2) + 3]) data |= 0x80;
309 else if (offset == 3)
311 uint8 data = 0x2F | (vjs.hardwareTypeNTSC ? 0x10 : 0x00);
312 int pad0Index = joystick_ram[1] & 0x0F;
313 //unused int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
315 if (!(pad0Index & 0x01))
317 if (joypad_0_buttons[BUTTON_PAUSE])
319 if (joypad_0_buttons[BUTTON_A])
322 else if (!(pad0Index & 0x02))
324 if (joypad_0_buttons[BUTTON_B])
327 else if (!(pad0Index & 0x04))
329 if (joypad_0_buttons[BUTTON_C])
334 if (joypad_0_buttons[BUTTON_OPTION])
340 return joystick_ram[offset];
343 uint16 joystick_word_read(uint32 offset)
345 return ((uint16)joystick_byte_read((offset+0)&0x03) << 8) | joystick_byte_read((offset+1)&0x03);
348 void joystick_byte_write(uint32 offset, uint8 data)
350 joystick_ram[offset&0x03] = data;
353 void joystick_word_write(uint32 offset, uint16 data)
356 joystick_ram[offset+0] = (data >> 8) & 0xFF;
357 joystick_ram[offset+1] = data & 0xFF;