5 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)
6 // Cleanups/fixes by James L. Hammons
33 #define BUTTON_OPTION 19
34 #define BUTTON_PAUSE 20
36 // Private function prototypes
38 void main_screen_switch(void);
42 static uint8 joystick_ram[4];
43 static uint8 joypad_0_buttons[21];
44 static uint8 joypad_1_buttons[21];
47 bool GUIKeyHeld = false;
48 extern int start_logging;
49 int gpu_start_log = 0;
51 int blit_start_log = 0;
53 int effect_start2 = 0, effect_start3 = 0, effect_start4 = 0, effect_start5 = 0, effect_start6 = 0;
54 bool interactiveMode = false;
55 bool iLeft, iRight, iToggle = false;
56 bool keyHeld1 = false, keyHeld2 = false, keyHeld3 = false;
58 bool startMemLog = false;
61 void main_screen_switch(void)
63 extern SDL_Surface * mainSurface;
64 extern Uint32 mainSurfaceFlags;
65 extern bool fullscreen;
67 fullscreen = !fullscreen;
68 mainSurfaceFlags &= ~SDL_FULLSCREEN;
70 mainSurfaceFlags |= SDL_FULLSCREEN;
72 mainSurface = SDL_SetVideoMode(tom_width, tom_height, 16, mainSurfaceFlags);
74 if (mainSurface == NULL)
76 WriteLog("Joystick: SDL is unable to set the video mode: %s\n", SDL_GetError());
80 SDL_WM_SetCaption("Virtual Jaguar", "Virtual Jaguar");
83 void joystick_init(void)
88 void joystick_exec(void)
90 extern SDL_Joystick * joystick;
91 extern bool useJoystick;
92 uint8 * keystate = SDL_GetKeyState(NULL);
94 memset(joypad_0_buttons, 0, 21);
95 memset(joypad_1_buttons, 0, 21);
96 gpu_start_log = 0; // Only log while key down!
98 effect_start2 = effect_start3 = effect_start4 = effect_start5 = effect_start6 = 0;
100 iLeft = iRight = false;
102 if ((keystate[SDLK_LALT] || keystate[SDLK_RALT]) & keystate[SDLK_RETURN])
103 main_screen_switch();
105 /* Added/Changed by SDLEMU (http://sdlemu.ngemu.com) */
107 if (keystate[SDLK_UP]) joypad_0_buttons[BUTTON_U] = 0x01;
108 if (keystate[SDLK_DOWN]) joypad_0_buttons[BUTTON_D] = 0x01;
109 if (keystate[SDLK_LEFT]) joypad_0_buttons[BUTTON_L] = 0x01;
110 if (keystate[SDLK_RIGHT]) joypad_0_buttons[BUTTON_R] = 0x01;
111 // The buttons are labelled C,B,A on the controller (going from left to right)
112 if (keystate[SDLK_z]) joypad_0_buttons[BUTTON_C] = 0x01;
113 if (keystate[SDLK_x]) joypad_0_buttons[BUTTON_B] = 0x01;
114 if (keystate[SDLK_c]) joypad_0_buttons[BUTTON_A] = 0x01;
115 //I may yet move these to O and P...
116 if (keystate[SDLK_QUOTE]) joypad_0_buttons[BUTTON_OPTION] = 0x01;
117 if (keystate[SDLK_RETURN]) joypad_0_buttons[BUTTON_PAUSE] = 0x01;
119 if (keystate[SDLK_TAB])
122 showGUI = !showGUI, GUIKeyHeld = true;
127 if (keystate[SDLK_q])
129 if (keystate[SDLK_w])
131 // if (keystate[SDLK_u]) jaguar_long_write(0xf1c384,jaguar_long_read(0xf1c384)+1);
132 if (keystate[SDLK_d])
134 if (keystate[SDLK_l])
136 if (keystate[SDLK_o])
138 if (keystate[SDLK_b])
141 if (keystate[SDLK_1])
143 if (keystate[SDLK_2])
145 if (keystate[SDLK_3])
147 if (keystate[SDLK_4])
149 if (keystate[SDLK_5])
151 if (keystate[SDLK_6])
154 if (keystate[SDLK_i])
155 interactiveMode = true;
157 if (keystate[SDLK_8] && interactiveMode)
160 objectPtr--, keyHeld1 = true;
165 if (keystate[SDLK_0] && interactiveMode)
168 objectPtr++, keyHeld2 = true;
173 if (keystate[SDLK_9] && interactiveMode)
176 iToggle = !iToggle, keyHeld3 = true;
181 if (keystate[SDLK_e])
183 if (keystate[SDLK_r])
184 WriteLog("\n--------> MARK!\n\n");
186 if (keystate[SDLK_KP0]) joypad_0_buttons[BUTTON_0] = 0x01;
187 if (keystate[SDLK_KP1]) joypad_0_buttons[BUTTON_1] = 0x01;
188 if (keystate[SDLK_KP2]) joypad_0_buttons[BUTTON_2] = 0x01;
189 if (keystate[SDLK_KP3]) joypad_0_buttons[BUTTON_3] = 0x01;
190 if (keystate[SDLK_KP4]) joypad_0_buttons[BUTTON_4] = 0x01;
191 if (keystate[SDLK_KP5]) joypad_0_buttons[BUTTON_5] = 0x01;
192 if (keystate[SDLK_KP6]) joypad_0_buttons[BUTTON_6] = 0x01;
193 if (keystate[SDLK_KP7]) joypad_0_buttons[BUTTON_7] = 0x01;
194 if (keystate[SDLK_KP8]) joypad_0_buttons[BUTTON_8] = 0x01;
195 if (keystate[SDLK_KP9]) joypad_0_buttons[BUTTON_9] = 0x01;
197 if (keystate[SDLK_ESCAPE])
200 /* Added/Changed by SDLEMU (http://sdlemu.ngemu.com */
201 /* Joystick support */
205 int16 x = SDL_JoystickGetAxis(joystick, 0),
206 y = SDL_JoystickGetAxis(joystick, 1);
209 joypad_0_buttons[BUTTON_R] = 0x01;
211 joypad_0_buttons[BUTTON_L] = 0x01;
213 joypad_0_buttons[BUTTON_D] = 0x01;
215 joypad_0_buttons[BUTTON_U] = 0x01;
217 if (SDL_JoystickGetButton(joystick, 0) == SDL_PRESSED)
218 joypad_0_buttons[BUTTON_A] = 0x01;
219 if (SDL_JoystickGetButton(joystick, 1) == SDL_PRESSED)
220 joypad_0_buttons[BUTTON_B] = 0x01;
221 if (SDL_JoystickGetButton(joystick, 2) == SDL_PRESSED)
222 joypad_0_buttons[BUTTON_C] = 0x01;
225 /* ADDED by SDLEMU (http://sdlemu.ngemu.com */
226 /* Needed to make sure that the events queue is empty */
230 void joystick_reset(void)
232 memset(joystick_ram, 0x00, 4);
233 memset(joypad_0_buttons, 0, 21);
234 memset(joypad_1_buttons, 0, 21);
237 void joystick_done(void)
241 uint8 joystick_byte_read(uint32 offset)
243 extern bool hardwareTypeNTSC;
249 int pad0Index = joystick_ram[1] & 0x0F;
250 int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
252 // This is bad--we're assuming that a bit is set in the last case. Might not be so!
253 if (!(pad0Index & 0x01))
255 else if (!(pad0Index & 0x02))
257 else if (!(pad0Index & 0x04))
262 if (!(pad1Index & 0x01))
264 else if (!(pad1Index & 0x02))
266 else if (!(pad1Index & 0x04))
271 if (joypad_0_buttons[(pad0Index << 2) + 0]) data |= 0x01;
272 if (joypad_0_buttons[(pad0Index << 2) + 1]) data |= 0x02;
273 if (joypad_0_buttons[(pad0Index << 2) + 2]) data |= 0x04;
274 if (joypad_0_buttons[(pad0Index << 2) + 3]) data |= 0x08;
275 if (joypad_1_buttons[(pad1Index << 2) + 0]) data |= 0x10;
276 if (joypad_1_buttons[(pad1Index << 2) + 1]) data |= 0x20;
277 if (joypad_1_buttons[(pad1Index << 2) + 2]) data |= 0x40;
278 if (joypad_1_buttons[(pad1Index << 2) + 3]) data |= 0x80;
282 else if (offset == 3)
284 uint8 data = 0x2F | (hardwareTypeNTSC ? 0x10 : 0x00);
285 int pad0Index = joystick_ram[1] & 0x0F;
286 //unused int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
288 if (!(pad0Index & 0x01))
290 if (joypad_0_buttons[BUTTON_PAUSE])
292 if (joypad_0_buttons[BUTTON_A])
295 else if (!(pad0Index & 0x02))
297 if (joypad_0_buttons[BUTTON_B])
300 else if (!(pad0Index & 0x04))
302 if (joypad_0_buttons[BUTTON_C])
307 if (joypad_0_buttons[BUTTON_OPTION])
313 return joystick_ram[offset];
316 uint16 joystick_word_read(uint32 offset)
318 return ((uint16)joystick_byte_read((offset+0)&0x03) << 8) | joystick_byte_read((offset+1)&0x03);
321 void joystick_byte_write(uint32 offset, uint8 data)
323 joystick_ram[offset&0x03] = data;
326 void joystick_word_write(uint32 offset, uint16 data)
329 joystick_ram[offset+0] = (data >> 8) & 0xFF;
330 joystick_ram[offset+1] = data & 0xFF;