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;
60 void joystick_init(void)
65 void joystick_exec(void)
67 // extern bool useJoystick;
68 uint8 * keystate = SDL_GetKeyState(NULL);
70 memset(joypad_0_buttons, 0, 21);
71 memset(joypad_1_buttons, 0, 21);
72 gpu_start_log = 0; // Only log while key down!
74 effect_start2 = effect_start3 = effect_start4 = effect_start5 = effect_start6 = 0;
76 iLeft = iRight = false;
78 if ((keystate[SDLK_LALT] || keystate[SDLK_RALT]) & keystate[SDLK_RETURN])
81 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
82 // vjs.p1KeyBindings[0] = sdlemu_getval_int("p1k_up", SDLK_UP);
84 if (keystate[vjs.p1KeyBindings[0]])
85 joypad_0_buttons[BUTTON_U] = 0x01;
86 if (keystate[vjs.p1KeyBindings[1]])
87 joypad_0_buttons[BUTTON_D] = 0x01;
88 if (keystate[vjs.p1KeyBindings[2]])
89 joypad_0_buttons[BUTTON_L] = 0x01;
90 if (keystate[vjs.p1KeyBindings[3]])
91 joypad_0_buttons[BUTTON_R] = 0x01;
92 // The buttons are labelled C,B,A on the controller (going from left to right)
93 if (keystate[vjs.p1KeyBindings[4]])
94 joypad_0_buttons[BUTTON_C] = 0x01;
95 if (keystate[vjs.p1KeyBindings[5]])
96 joypad_0_buttons[BUTTON_B] = 0x01;
97 if (keystate[vjs.p1KeyBindings[6]])
98 joypad_0_buttons[BUTTON_A] = 0x01;
99 //I may yet move these to O and P...
100 if (keystate[vjs.p1KeyBindings[7]])
101 joypad_0_buttons[BUTTON_OPTION] = 0x01;
102 if (keystate[vjs.p1KeyBindings[8]])
103 joypad_0_buttons[BUTTON_PAUSE] = 0x01;
105 if (keystate[vjs.p1KeyBindings[9]])
106 joypad_0_buttons[BUTTON_0] = 0x01;
107 if (keystate[vjs.p1KeyBindings[10]])
108 joypad_0_buttons[BUTTON_1] = 0x01;
109 if (keystate[vjs.p1KeyBindings[11]])
110 joypad_0_buttons[BUTTON_2] = 0x01;
111 if (keystate[vjs.p1KeyBindings[12]])
112 joypad_0_buttons[BUTTON_3] = 0x01;
113 if (keystate[vjs.p1KeyBindings[13]])
114 joypad_0_buttons[BUTTON_4] = 0x01;
115 if (keystate[vjs.p1KeyBindings[14]])
116 joypad_0_buttons[BUTTON_5] = 0x01;
117 if (keystate[vjs.p1KeyBindings[15]])
118 joypad_0_buttons[BUTTON_6] = 0x01;
119 if (keystate[vjs.p1KeyBindings[16]])
120 joypad_0_buttons[BUTTON_7] = 0x01;
121 if (keystate[vjs.p1KeyBindings[17]])
122 joypad_0_buttons[BUTTON_8] = 0x01;
123 if (keystate[vjs.p1KeyBindings[18]])
124 joypad_0_buttons[BUTTON_9] = 0x01;
125 if (keystate[vjs.p1KeyBindings[19]])
126 joypad_0_buttons[BUTTON_s] = 0x01;
127 if (keystate[vjs.p1KeyBindings[20]])
128 joypad_0_buttons[BUTTON_d] = 0x01;
130 if (keystate[SDLK_ESCAPE])
133 if (keystate[SDLK_TAB])
136 showGUI = !showGUI, GUIKeyHeld = true;
141 if (keystate[SDLK_q])
143 if (keystate[SDLK_w])
145 // if (keystate[SDLK_u]) jaguar_long_write(0xf1c384,jaguar_long_read(0xf1c384)+1);
146 if (keystate[SDLK_d])
148 if (keystate[SDLK_l])
150 if (keystate[SDLK_o])
152 if (keystate[SDLK_b])
155 if (keystate[SDLK_1])
157 if (keystate[SDLK_2])
159 if (keystate[SDLK_3])
161 if (keystate[SDLK_4])
163 if (keystate[SDLK_5])
165 if (keystate[SDLK_6])
168 if (keystate[SDLK_i])
169 interactiveMode = true;
171 if (keystate[SDLK_8] && interactiveMode)
174 objectPtr--, keyHeld1 = true;
179 if (keystate[SDLK_0] && interactiveMode)
182 objectPtr++, keyHeld2 = true;
187 if (keystate[SDLK_9] && interactiveMode)
190 iToggle = !iToggle, keyHeld3 = true;
195 if (keystate[SDLK_e])
197 if (keystate[SDLK_r])
198 WriteLog("\n--------> MARK!\n\n");
199 if (keystate[SDLK_t])
203 // Joystick support [nwagenaar]
207 extern SDL_Joystick * joystick;
208 int16 x = SDL_JoystickGetAxis(joystick, 0),
209 y = SDL_JoystickGetAxis(joystick, 1);
212 joypad_0_buttons[BUTTON_R] = 0x01;
214 joypad_0_buttons[BUTTON_L] = 0x01;
216 joypad_0_buttons[BUTTON_D] = 0x01;
218 joypad_0_buttons[BUTTON_U] = 0x01;
220 if (SDL_JoystickGetButton(joystick, 0) == SDL_PRESSED)
221 joypad_0_buttons[BUTTON_A] = 0x01;
222 if (SDL_JoystickGetButton(joystick, 1) == SDL_PRESSED)
223 joypad_0_buttons[BUTTON_B] = 0x01;
224 if (SDL_JoystickGetButton(joystick, 2) == SDL_PRESSED)
225 joypad_0_buttons[BUTTON_C] = 0x01;
228 // Needed to ensure that the events queue is empty [nwagenaar]
232 void joystick_reset(void)
234 memset(joystick_ram, 0x00, 4);
235 memset(joypad_0_buttons, 0, 21);
236 memset(joypad_1_buttons, 0, 21);
239 void joystick_done(void)
243 uint8 joystick_byte_read(uint32 offset)
245 // extern bool hardwareTypeNTSC;
251 int pad0Index = joystick_ram[1] & 0x0F;
252 int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
254 // This is bad--we're assuming that a bit is set in the last case. Might not be so!
255 if (!(pad0Index & 0x01))
257 else if (!(pad0Index & 0x02))
259 else if (!(pad0Index & 0x04))
264 if (!(pad1Index & 0x01))
266 else if (!(pad1Index & 0x02))
268 else if (!(pad1Index & 0x04))
273 if (joypad_0_buttons[(pad0Index << 2) + 0]) data |= 0x01;
274 if (joypad_0_buttons[(pad0Index << 2) + 1]) data |= 0x02;
275 if (joypad_0_buttons[(pad0Index << 2) + 2]) data |= 0x04;
276 if (joypad_0_buttons[(pad0Index << 2) + 3]) data |= 0x08;
277 if (joypad_1_buttons[(pad1Index << 2) + 0]) data |= 0x10;
278 if (joypad_1_buttons[(pad1Index << 2) + 1]) data |= 0x20;
279 if (joypad_1_buttons[(pad1Index << 2) + 2]) data |= 0x40;
280 if (joypad_1_buttons[(pad1Index << 2) + 3]) data |= 0x80;
284 else if (offset == 3)
286 uint8 data = 0x2F | (vjs.hardwareTypeNTSC ? 0x10 : 0x00);
287 int pad0Index = joystick_ram[1] & 0x0F;
288 //unused int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
290 if (!(pad0Index & 0x01))
292 if (joypad_0_buttons[BUTTON_PAUSE])
294 if (joypad_0_buttons[BUTTON_A])
297 else if (!(pad0Index & 0x02))
299 if (joypad_0_buttons[BUTTON_B])
302 else if (!(pad0Index & 0x04))
304 if (joypad_0_buttons[BUTTON_C])
309 if (joypad_0_buttons[BUTTON_OPTION])
315 return joystick_ram[offset];
318 uint16 joystick_word_read(uint32 offset)
320 return ((uint16)joystick_byte_read((offset+0)&0x03) << 8) | joystick_byte_read((offset+1)&0x03);
323 void joystick_byte_write(uint32 offset, uint8 data)
325 joystick_ram[offset&0x03] = data;
328 void joystick_word_write(uint32 offset, uint16 data)
331 joystick_ram[offset+0] = (data >> 8) & 0xFF;
332 joystick_ram[offset+1] = data & 0xFF;