5 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)
6 // Cleanups/fixes by James L. Hammons
10 //#include "include/stdafx.h"
11 //#include <mmsystem.h>
18 void main_screen_switch(void);
40 #define BUTTON_OPTION 19
41 #define BUTTON_PAUSE 20
43 static uint8 joystick_ram[4];
44 static uint8 joypad_0_buttons[21];
45 static uint8 joypad_1_buttons[21];
48 bool GUIKeyHeld = false;
49 extern int start_logging;
50 int gpu_start_log = 0;
52 int blit_start_log = 0;
54 bool interactiveMode = false;
55 bool iLeft, iRight, iToggle = false;
56 bool keyHeld1 = false, keyHeld2 = false, keyHeld3 = false;
60 void main_screen_switch(void)
62 extern SDL_Surface * mainSurface;
63 extern Uint32 mainSurfaceFlags;
64 extern bool fullscreen;
66 fullscreen = !fullscreen;
67 mainSurfaceFlags &= ~SDL_FULLSCREEN;
69 mainSurfaceFlags |= SDL_FULLSCREEN;
71 //???Should we do this???
72 // SDL_FreeSurface(mainSurface);
73 mainSurface = SDL_SetVideoMode(tom_width, tom_height, 16, mainSurfaceFlags);
75 if (mainSurface == NULL)
77 WriteLog("Joystick: SDL is unable to set the video mode: %s\n", SDL_GetError());
81 SDL_WM_SetCaption("Virtual Jaguar", "Virtual Jaguar");
83 console.option("fullscreen output");
85 console.option("windowed output");*/
88 // console.open("Virtual Jaguar", tom_width, tom_height, format);
91 void joystick_init(void)
96 void joystick_exec(void)
98 extern SDL_Joystick * joystick;
99 extern bool useJoystick;
100 uint8 * keystate = SDL_GetKeyState(NULL);
101 // extern Console console;
103 memset(joypad_0_buttons, 0, 21);
104 memset(joypad_1_buttons, 0, 21);
105 gpu_start_log = 0; // Only log while key down!
108 iLeft = iRight = false;
110 if ((keystate[SDLK_LALT] || keystate[SDLK_RALT]) & keystate[SDLK_RETURN])
111 main_screen_switch();
113 /* Added/Changed by SDLEMU (http://sdlemu.ngemu.com) */
115 if (keystate[SDLK_UP]) joypad_0_buttons[BUTTON_U] = 0x01;
116 if (keystate[SDLK_DOWN]) joypad_0_buttons[BUTTON_D] = 0x01;
117 if (keystate[SDLK_LEFT]) joypad_0_buttons[BUTTON_L] = 0x01;
118 if (keystate[SDLK_RIGHT]) joypad_0_buttons[BUTTON_R] = 0x01;
119 // The buttons are labelled C,B,A on the controller (going from left to right)
120 if (keystate[SDLK_z]) joypad_0_buttons[BUTTON_C] = 0x01;
121 if (keystate[SDLK_x]) joypad_0_buttons[BUTTON_B] = 0x01;
122 if (keystate[SDLK_c]) joypad_0_buttons[BUTTON_A] = 0x01;
123 //I may yet move these to O and P...
124 if (keystate[SDLK_QUOTE]) joypad_0_buttons[BUTTON_OPTION] = 0x01;
125 if (keystate[SDLK_RETURN]) joypad_0_buttons[BUTTON_PAUSE] = 0x01;
127 if (keystate[SDLK_TAB])
130 showGUI = !showGUI, GUIKeyHeld = true;
135 if (keystate[SDLK_q])
137 if (keystate[SDLK_w])
139 // if (keystate[SDLK_u]) jaguar_long_write(0xf1c384,jaguar_long_read(0xf1c384)+1);
140 if (keystate[SDLK_d])
142 if (keystate[SDLK_l])
144 if (keystate[SDLK_o])
146 if (keystate[SDLK_b])
148 if (keystate[SDLK_1])
151 if (keystate[SDLK_i])
152 interactiveMode = true;
154 if (keystate[SDLK_8] && interactiveMode)
157 objectPtr--, keyHeld1 = true;
162 if (keystate[SDLK_0] && interactiveMode)
165 objectPtr++, keyHeld2 = true;
170 if (keystate[SDLK_9] && interactiveMode)
173 iToggle = !iToggle, keyHeld3 = true;
178 if (keystate[SDLK_KP0]) joypad_0_buttons[BUTTON_0] = 0x01;
179 if (keystate[SDLK_KP1]) joypad_0_buttons[BUTTON_1] = 0x01;
180 if (keystate[SDLK_KP2]) joypad_0_buttons[BUTTON_2] = 0x01;
181 if (keystate[SDLK_KP3]) joypad_0_buttons[BUTTON_3] = 0x01;
182 if (keystate[SDLK_KP4]) joypad_0_buttons[BUTTON_4] = 0x01;
183 if (keystate[SDLK_KP5]) joypad_0_buttons[BUTTON_5] = 0x01;
184 if (keystate[SDLK_KP6]) joypad_0_buttons[BUTTON_6] = 0x01;
185 if (keystate[SDLK_KP7]) joypad_0_buttons[BUTTON_7] = 0x01;
186 if (keystate[SDLK_KP8]) joypad_0_buttons[BUTTON_8] = 0x01;
187 if (keystate[SDLK_KP9]) joypad_0_buttons[BUTTON_9] = 0x01;
189 if (keystate[SDLK_ESCAPE])
192 /* Added/Changed by SDLEMU (http://sdlemu.ngemu.com */
193 /* Joystick support */
195 // if (console.JoyEnabled() == 1)
198 // int16 x = SDL_JoystickGetAxis(console.joystick, 0),
199 // y = SDL_JoystickGetAxis(console.joystick, 1);
200 int16 x = SDL_JoystickGetAxis(joystick, 0),
201 y = SDL_JoystickGetAxis(joystick, 1);
204 joypad_0_buttons[BUTTON_R] = 0x01;
206 joypad_0_buttons[BUTTON_L] = 0x01;
208 joypad_0_buttons[BUTTON_D] = 0x01;
210 joypad_0_buttons[BUTTON_U] = 0x01;
212 // if (SDL_JoystickGetButton(console.joystick, 0) == SDL_PRESSED)
213 if (SDL_JoystickGetButton(joystick, 0) == SDL_PRESSED)
214 joypad_0_buttons[BUTTON_A] = 0x01;
215 // if (SDL_JoystickGetButton(console.joystick, 1) == SDL_PRESSED)
216 if (SDL_JoystickGetButton(joystick, 1) == SDL_PRESSED)
217 joypad_0_buttons[BUTTON_B] = 0x01;
218 // if (SDL_JoystickGetButton(console.joystick, 2) == SDL_PRESSED)
219 if (SDL_JoystickGetButton(joystick, 2) == SDL_PRESSED)
220 joypad_0_buttons[BUTTON_C] = 0x01;
223 /* ADDED by SDLEMU (http://sdlemu.ngemu.com */
224 /* Needed to make sure that the events queue is empty */
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 void joystick_byte_write(uint32 offset, uint8 data)
241 joystick_ram[offset&0x03] = data;
244 void joystick_word_write(uint32 offset, uint16 data)
247 joystick_ram[offset+0] = (data >> 8) & 0xFF;
248 joystick_ram[offset+1] = data & 0xFF;
251 uint8 joystick_byte_read(uint32 offset)
253 extern bool hardwareTypeNTSC;
259 int pad0Index = joystick_ram[1] & 0x0F;
260 int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
262 // This is bad--we're assuming that a bit is set in the last case
263 if (!(pad0Index & 0x01))
265 else if (!(pad0Index & 0x02))
267 else if (!(pad0Index & 0x04))
272 if (!(pad1Index & 0x01))
274 else if (!(pad1Index & 0x02))
276 else if (!(pad1Index & 0x04))
281 if (joypad_0_buttons[(pad0Index << 2) + 0]) data |= 0x01;
282 if (joypad_0_buttons[(pad0Index << 2) + 1]) data |= 0x02;
283 if (joypad_0_buttons[(pad0Index << 2) + 2]) data |= 0x04;
284 if (joypad_0_buttons[(pad0Index << 2) + 3]) data |= 0x08;
285 if (joypad_1_buttons[(pad1Index << 2) + 0]) data |= 0x10;
286 if (joypad_1_buttons[(pad1Index << 2) + 1]) data |= 0x20;
287 if (joypad_1_buttons[(pad1Index << 2) + 2]) data |= 0x40;
288 if (joypad_1_buttons[(pad1Index << 2) + 3]) data |= 0x80;
292 else if (offset == 3)
294 // uint8 data = ((1 << 5) | (1 << 4) | 0x0F);
295 uint8 data = 0x2F | (hardwareTypeNTSC ? 0x10 : 0x00);
296 int pad0Index = joystick_ram[1] & 0x0F;
297 //unused int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
299 if (!(pad0Index & 0x01))
301 if (joypad_0_buttons[BUTTON_PAUSE])
303 if (joypad_0_buttons[BUTTON_A])
306 else if (!(pad0Index & 0x02))
308 if (joypad_0_buttons[BUTTON_B])
311 else if (!(pad0Index & 0x04))
313 if (joypad_0_buttons[BUTTON_C])
318 if (joypad_0_buttons[BUTTON_OPTION])
324 return joystick_ram[offset];
327 uint16 joystick_word_read(uint32 offset)
329 return ((uint16)joystick_byte_read((offset+0)&0x03) << 8) | joystick_byte_read((offset+1)&0x03);