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 extern bool debounceRunKey;
131 if (keystate[SDLK_ESCAPE])
137 debounceRunKey = false;
139 if (keystate[SDLK_TAB])
142 showGUI = !showGUI, GUIKeyHeld = true;
147 if (keystate[SDLK_q])
149 if (keystate[SDLK_w])
151 // if (keystate[SDLK_u]) jaguar_long_write(0xf1c384,jaguar_long_read(0xf1c384)+1);
152 if (keystate[SDLK_d])
154 if (keystate[SDLK_l])
156 if (keystate[SDLK_o])
158 if (keystate[SDLK_b])
161 if (keystate[SDLK_1])
163 if (keystate[SDLK_2])
165 if (keystate[SDLK_3])
167 if (keystate[SDLK_4])
169 if (keystate[SDLK_5])
171 if (keystate[SDLK_6])
174 if (keystate[SDLK_i])
175 interactiveMode = true;
177 if (keystate[SDLK_8] && interactiveMode)
180 objectPtr--, keyHeld1 = true;
185 if (keystate[SDLK_0] && interactiveMode)
188 objectPtr++, keyHeld2 = true;
193 if (keystate[SDLK_9] && interactiveMode)
196 iToggle = !iToggle, keyHeld3 = true;
201 if (keystate[SDLK_e])
203 if (keystate[SDLK_r])
204 WriteLog("\n--------> MARK!\n\n");
205 if (keystate[SDLK_t])
209 // Joystick support [nwagenaar]
213 extern SDL_Joystick * joystick;
214 int16 x = SDL_JoystickGetAxis(joystick, 0),
215 y = SDL_JoystickGetAxis(joystick, 1);
218 joypad_0_buttons[BUTTON_R] = 0x01;
220 joypad_0_buttons[BUTTON_L] = 0x01;
222 joypad_0_buttons[BUTTON_D] = 0x01;
224 joypad_0_buttons[BUTTON_U] = 0x01;
226 if (SDL_JoystickGetButton(joystick, 0) == SDL_PRESSED)
227 joypad_0_buttons[BUTTON_A] = 0x01;
228 if (SDL_JoystickGetButton(joystick, 1) == SDL_PRESSED)
229 joypad_0_buttons[BUTTON_B] = 0x01;
230 if (SDL_JoystickGetButton(joystick, 2) == SDL_PRESSED)
231 joypad_0_buttons[BUTTON_C] = 0x01;
234 // Needed to ensure that the events queue is empty [nwagenaar]
238 void joystick_reset(void)
240 memset(joystick_ram, 0x00, 4);
241 memset(joypad_0_buttons, 0, 21);
242 memset(joypad_1_buttons, 0, 21);
245 void joystick_done(void)
249 uint8 joystick_byte_read(uint32 offset)
251 // extern bool hardwareTypeNTSC;
257 int pad0Index = joystick_ram[1] & 0x0F;
258 int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
260 // This is bad--we're assuming that a bit is set in the last case. Might not be so!
261 if (!(pad0Index & 0x01))
263 else if (!(pad0Index & 0x02))
265 else if (!(pad0Index & 0x04))
270 if (!(pad1Index & 0x01))
272 else if (!(pad1Index & 0x02))
274 else if (!(pad1Index & 0x04))
279 if (joypad_0_buttons[(pad0Index << 2) + 0]) data |= 0x01;
280 if (joypad_0_buttons[(pad0Index << 2) + 1]) data |= 0x02;
281 if (joypad_0_buttons[(pad0Index << 2) + 2]) data |= 0x04;
282 if (joypad_0_buttons[(pad0Index << 2) + 3]) data |= 0x08;
283 if (joypad_1_buttons[(pad1Index << 2) + 0]) data |= 0x10;
284 if (joypad_1_buttons[(pad1Index << 2) + 1]) data |= 0x20;
285 if (joypad_1_buttons[(pad1Index << 2) + 2]) data |= 0x40;
286 if (joypad_1_buttons[(pad1Index << 2) + 3]) data |= 0x80;
290 else if (offset == 3)
292 uint8 data = 0x2F | (vjs.hardwareTypeNTSC ? 0x10 : 0x00);
293 int pad0Index = joystick_ram[1] & 0x0F;
294 //unused int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
296 if (!(pad0Index & 0x01))
298 if (joypad_0_buttons[BUTTON_PAUSE])
300 if (joypad_0_buttons[BUTTON_A])
303 else if (!(pad0Index & 0x02))
305 if (joypad_0_buttons[BUTTON_B])
308 else if (!(pad0Index & 0x04))
310 if (joypad_0_buttons[BUTTON_C])
315 if (joypad_0_buttons[BUTTON_OPTION])
321 return joystick_ram[offset];
324 uint16 joystick_word_read(uint32 offset)
326 return ((uint16)joystick_byte_read((offset+0)&0x03) << 8) | joystick_byte_read((offset+1)&0x03);
329 void joystick_byte_write(uint32 offset, uint8 data)
331 joystick_ram[offset&0x03] = data;
334 void joystick_word_write(uint32 offset, uint16 data)
337 joystick_ram[offset+0] = (data >> 8) & 0xFF;
338 joystick_ram[offset+1] = data & 0xFF;