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;
59 void joystick_init(void)
64 void joystick_exec(void)
66 // extern bool useJoystick;
67 uint8 * keystate = SDL_GetKeyState(NULL);
69 memset(joypad_0_buttons, 0, 21);
70 memset(joypad_1_buttons, 0, 21);
71 gpu_start_log = 0; // Only log while key down!
73 effect_start2 = effect_start3 = effect_start4 = effect_start5 = effect_start6 = 0;
75 iLeft = iRight = false;
77 if ((keystate[SDLK_LALT] || keystate[SDLK_RALT]) & keystate[SDLK_RETURN])
80 // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
81 // vjs.p1KeyBindings[0] = sdlemu_getval_int("p1k_up", SDLK_UP);
83 if (keystate[vjs.p1KeyBindings[0]])
84 joypad_0_buttons[BUTTON_U] = 0x01;
85 if (keystate[vjs.p1KeyBindings[1]])
86 joypad_0_buttons[BUTTON_D] = 0x01;
87 if (keystate[vjs.p1KeyBindings[2]])
88 joypad_0_buttons[BUTTON_L] = 0x01;
89 if (keystate[vjs.p1KeyBindings[3]])
90 joypad_0_buttons[BUTTON_R] = 0x01;
91 // The buttons are labelled C,B,A on the controller (going from left to right)
92 if (keystate[vjs.p1KeyBindings[4]])
93 joypad_0_buttons[BUTTON_C] = 0x01;
94 if (keystate[vjs.p1KeyBindings[5]])
95 joypad_0_buttons[BUTTON_B] = 0x01;
96 if (keystate[vjs.p1KeyBindings[6]])
97 joypad_0_buttons[BUTTON_A] = 0x01;
98 //I may yet move these to O and P...
99 if (keystate[vjs.p1KeyBindings[7]])
100 joypad_0_buttons[BUTTON_OPTION] = 0x01;
101 if (keystate[vjs.p1KeyBindings[8]])
102 joypad_0_buttons[BUTTON_PAUSE] = 0x01;
104 if (keystate[vjs.p1KeyBindings[9]])
105 joypad_0_buttons[BUTTON_0] = 0x01;
106 if (keystate[vjs.p1KeyBindings[10]])
107 joypad_0_buttons[BUTTON_1] = 0x01;
108 if (keystate[vjs.p1KeyBindings[11]])
109 joypad_0_buttons[BUTTON_2] = 0x01;
110 if (keystate[vjs.p1KeyBindings[12]])
111 joypad_0_buttons[BUTTON_3] = 0x01;
112 if (keystate[vjs.p1KeyBindings[13]])
113 joypad_0_buttons[BUTTON_4] = 0x01;
114 if (keystate[vjs.p1KeyBindings[14]])
115 joypad_0_buttons[BUTTON_5] = 0x01;
116 if (keystate[vjs.p1KeyBindings[15]])
117 joypad_0_buttons[BUTTON_6] = 0x01;
118 if (keystate[vjs.p1KeyBindings[16]])
119 joypad_0_buttons[BUTTON_7] = 0x01;
120 if (keystate[vjs.p1KeyBindings[17]])
121 joypad_0_buttons[BUTTON_8] = 0x01;
122 if (keystate[vjs.p1KeyBindings[18]])
123 joypad_0_buttons[BUTTON_9] = 0x01;
124 if (keystate[vjs.p1KeyBindings[19]])
125 joypad_0_buttons[BUTTON_s] = 0x01;
126 if (keystate[vjs.p1KeyBindings[20]])
127 joypad_0_buttons[BUTTON_d] = 0x01;
129 if (keystate[SDLK_ESCAPE])
132 if (keystate[SDLK_TAB])
135 showGUI = !showGUI, GUIKeyHeld = true;
140 if (keystate[SDLK_q])
142 if (keystate[SDLK_w])
144 // if (keystate[SDLK_u]) jaguar_long_write(0xf1c384,jaguar_long_read(0xf1c384)+1);
145 if (keystate[SDLK_d])
147 if (keystate[SDLK_l])
149 if (keystate[SDLK_o])
151 if (keystate[SDLK_b])
154 if (keystate[SDLK_1])
156 if (keystate[SDLK_2])
158 if (keystate[SDLK_3])
160 if (keystate[SDLK_4])
162 if (keystate[SDLK_5])
164 if (keystate[SDLK_6])
167 if (keystate[SDLK_i])
168 interactiveMode = true;
170 if (keystate[SDLK_8] && interactiveMode)
173 objectPtr--, keyHeld1 = true;
178 if (keystate[SDLK_0] && interactiveMode)
181 objectPtr++, keyHeld2 = true;
186 if (keystate[SDLK_9] && interactiveMode)
189 iToggle = !iToggle, keyHeld3 = true;
194 if (keystate[SDLK_e])
196 if (keystate[SDLK_r])
197 WriteLog("\n--------> MARK!\n\n");
199 // Joystick support [nwagenaar]
203 extern SDL_Joystick * joystick;
204 int16 x = SDL_JoystickGetAxis(joystick, 0),
205 y = SDL_JoystickGetAxis(joystick, 1);
208 joypad_0_buttons[BUTTON_R] = 0x01;
210 joypad_0_buttons[BUTTON_L] = 0x01;
212 joypad_0_buttons[BUTTON_D] = 0x01;
214 joypad_0_buttons[BUTTON_U] = 0x01;
216 if (SDL_JoystickGetButton(joystick, 0) == SDL_PRESSED)
217 joypad_0_buttons[BUTTON_A] = 0x01;
218 if (SDL_JoystickGetButton(joystick, 1) == SDL_PRESSED)
219 joypad_0_buttons[BUTTON_B] = 0x01;
220 if (SDL_JoystickGetButton(joystick, 2) == SDL_PRESSED)
221 joypad_0_buttons[BUTTON_C] = 0x01;
224 // Needed to ensure that the events queue is empty [nwagenaar]
228 void joystick_reset(void)
230 memset(joystick_ram, 0x00, 4);
231 memset(joypad_0_buttons, 0, 21);
232 memset(joypad_1_buttons, 0, 21);
235 void joystick_done(void)
239 uint8 joystick_byte_read(uint32 offset)
241 // extern bool hardwareTypeNTSC;
247 int pad0Index = joystick_ram[1] & 0x0F;
248 int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
250 // This is bad--we're assuming that a bit is set in the last case. Might not be so!
251 if (!(pad0Index & 0x01))
253 else if (!(pad0Index & 0x02))
255 else if (!(pad0Index & 0x04))
260 if (!(pad1Index & 0x01))
262 else if (!(pad1Index & 0x02))
264 else if (!(pad1Index & 0x04))
269 if (joypad_0_buttons[(pad0Index << 2) + 0]) data |= 0x01;
270 if (joypad_0_buttons[(pad0Index << 2) + 1]) data |= 0x02;
271 if (joypad_0_buttons[(pad0Index << 2) + 2]) data |= 0x04;
272 if (joypad_0_buttons[(pad0Index << 2) + 3]) data |= 0x08;
273 if (joypad_1_buttons[(pad1Index << 2) + 0]) data |= 0x10;
274 if (joypad_1_buttons[(pad1Index << 2) + 1]) data |= 0x20;
275 if (joypad_1_buttons[(pad1Index << 2) + 2]) data |= 0x40;
276 if (joypad_1_buttons[(pad1Index << 2) + 3]) data |= 0x80;
280 else if (offset == 3)
282 uint8 data = 0x2F | (vjs.hardwareTypeNTSC ? 0x10 : 0x00);
283 int pad0Index = joystick_ram[1] & 0x0F;
284 //unused int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
286 if (!(pad0Index & 0x01))
288 if (joypad_0_buttons[BUTTON_PAUSE])
290 if (joypad_0_buttons[BUTTON_A])
293 else if (!(pad0Index & 0x02))
295 if (joypad_0_buttons[BUTTON_B])
298 else if (!(pad0Index & 0x04))
300 if (joypad_0_buttons[BUTTON_C])
305 if (joypad_0_buttons[BUTTON_OPTION])
311 return joystick_ram[offset];
314 uint16 joystick_word_read(uint32 offset)
316 return ((uint16)joystick_byte_read((offset+0)&0x03) << 8) | joystick_byte_read((offset+1)&0x03);
319 void joystick_byte_write(uint32 offset, uint8 data)
321 joystick_ram[offset&0x03] = data;
324 void joystick_word_write(uint32 offset, uint16 data)
327 joystick_ram[offset+0] = (data >> 8) & 0xFF;
328 joystick_ram[offset+1] = data & 0xFF;