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];
47 extern int start_logging;
48 int gpu_start_log = 0;
50 int blit_start_log = 0;
52 bool interactiveMode = false;
53 bool iLeft, iRight, iToggle = false;
54 bool keyHeld1 = false, keyHeld2 = false, keyHeld3 = false;
58 void main_screen_switch(void)
60 extern SDL_Surface * mainSurface;
61 extern Uint32 mainSurfaceFlags;
62 extern bool fullscreen;
64 fullscreen = !fullscreen;
65 mainSurfaceFlags &= ~SDL_FULLSCREEN;
67 mainSurfaceFlags |= SDL_FULLSCREEN;
69 //???Should we do this???
70 // SDL_FreeSurface(mainSurface);
71 mainSurface = SDL_SetVideoMode(tom_width, tom_height, 16, mainSurfaceFlags);
73 if (mainSurface == NULL)
75 WriteLog("Joystick: SDL is unable to set the video mode: %s\n", SDL_GetError());
79 SDL_WM_SetCaption("Virtual Jaguar", "Virtual Jaguar");
81 console.option("fullscreen output");
83 console.option("windowed output");*/
86 // console.open("Virtual Jaguar", tom_width, tom_height, format);
89 void joystick_init(void)
94 void joystick_exec(void)
96 extern SDL_Joystick * joystick;
97 extern bool useJoystick;
98 uint8 * keystate = SDL_GetKeyState(NULL);
99 // extern Console console;
101 memset(joypad_0_buttons, 0, 21);
102 memset(joypad_1_buttons, 0, 21);
103 gpu_start_log = 0; // Only log while key down!
106 iLeft = iRight = false;
108 if ((keystate[SDLK_LALT] || keystate[SDLK_RALT]) & keystate[SDLK_RETURN])
109 main_screen_switch();
111 /* Added/Changed by SDLEMU (http://sdlemu.ngemu.com) */
113 if (keystate[SDLK_UP]) joypad_0_buttons[BUTTON_U] = 0x01;
114 if (keystate[SDLK_DOWN]) joypad_0_buttons[BUTTON_D] = 0x01;
115 if (keystate[SDLK_LEFT]) joypad_0_buttons[BUTTON_L] = 0x01;
116 if (keystate[SDLK_RIGHT]) joypad_0_buttons[BUTTON_R] = 0x01;
117 // The buttons are labelled C,B,A on the controller (going from left to right)
118 if (keystate[SDLK_z]) joypad_0_buttons[BUTTON_C] = 0x01;
119 if (keystate[SDLK_x]) joypad_0_buttons[BUTTON_B] = 0x01;
120 if (keystate[SDLK_c]) joypad_0_buttons[BUTTON_A] = 0x01;
121 if (keystate[SDLK_TAB]) joypad_0_buttons[BUTTON_OPTION] = 0x01;
122 if (keystate[SDLK_RETURN]) joypad_0_buttons[BUTTON_PAUSE] = 0x01;
123 if (keystate[SDLK_q])
125 if (keystate[SDLK_w])
127 // if (keystate[SDLK_u]) jaguar_long_write(0xf1c384,jaguar_long_read(0xf1c384)+1);
128 if (keystate[SDLK_d])
130 if (keystate[SDLK_l])
132 if (keystate[SDLK_o])
134 if (keystate[SDLK_b])
136 if (keystate[SDLK_1])
139 if (keystate[SDLK_i])
140 interactiveMode = true;
142 if (keystate[SDLK_8] && interactiveMode)
145 objectPtr--, keyHeld1 = true;
150 if (keystate[SDLK_0] && interactiveMode)
153 objectPtr++, keyHeld2 = true;
158 if (keystate[SDLK_9] && interactiveMode)
161 iToggle = !iToggle, keyHeld3 = true;
166 if (keystate[SDLK_KP0]) joypad_0_buttons[BUTTON_0] = 0x01;
167 if (keystate[SDLK_KP1]) joypad_0_buttons[BUTTON_1] = 0x01;
168 if (keystate[SDLK_KP2]) joypad_0_buttons[BUTTON_2] = 0x01;
169 if (keystate[SDLK_KP3]) joypad_0_buttons[BUTTON_3] = 0x01;
170 if (keystate[SDLK_KP4]) joypad_0_buttons[BUTTON_4] = 0x01;
171 if (keystate[SDLK_KP5]) joypad_0_buttons[BUTTON_5] = 0x01;
172 if (keystate[SDLK_KP6]) joypad_0_buttons[BUTTON_6] = 0x01;
173 if (keystate[SDLK_KP7]) joypad_0_buttons[BUTTON_7] = 0x01;
174 if (keystate[SDLK_KP8]) joypad_0_buttons[BUTTON_8] = 0x01;
175 if (keystate[SDLK_KP9]) joypad_0_buttons[BUTTON_9] = 0x01;
177 if (keystate[SDLK_ESCAPE])
180 /* Added/Changed by SDLEMU (http://sdlemu.ngemu.com */
181 /* Joystick support */
183 // if (console.JoyEnabled() == 1)
186 // int16 x = SDL_JoystickGetAxis(console.joystick, 0),
187 // y = SDL_JoystickGetAxis(console.joystick, 1);
188 int16 x = SDL_JoystickGetAxis(joystick, 0),
189 y = SDL_JoystickGetAxis(joystick, 1);
192 joypad_0_buttons[BUTTON_R] = 0x01;
194 joypad_0_buttons[BUTTON_L] = 0x01;
196 joypad_0_buttons[BUTTON_D] = 0x01;
198 joypad_0_buttons[BUTTON_U] = 0x01;
200 // if (SDL_JoystickGetButton(console.joystick, 0) == SDL_PRESSED)
201 if (SDL_JoystickGetButton(joystick, 0) == SDL_PRESSED)
202 joypad_0_buttons[BUTTON_A] = 0x01;
203 // if (SDL_JoystickGetButton(console.joystick, 1) == SDL_PRESSED)
204 if (SDL_JoystickGetButton(joystick, 1) == SDL_PRESSED)
205 joypad_0_buttons[BUTTON_B] = 0x01;
206 // if (SDL_JoystickGetButton(console.joystick, 2) == SDL_PRESSED)
207 if (SDL_JoystickGetButton(joystick, 2) == SDL_PRESSED)
208 joypad_0_buttons[BUTTON_C] = 0x01;
211 /* ADDED by SDLEMU (http://sdlemu.ngemu.com */
212 /* Needed to make sure that the events queue is empty */
216 void joystick_reset(void)
218 memset(joystick_ram, 0x00, 4);
219 memset(joypad_0_buttons, 0, 21);
220 memset(joypad_1_buttons, 0, 21);
223 void joystick_done(void)
227 void joystick_byte_write(uint32 offset, uint8 data)
229 joystick_ram[offset&0x03] = data;
232 void joystick_word_write(uint32 offset, uint16 data)
235 joystick_ram[offset+0] = (data >> 8) & 0xFF;
236 joystick_ram[offset+1] = data & 0xFF;
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
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 = ((1 << 5) | (1 << 4) | 0x0F);
283 uint8 data = 0x2F | (hardwareTypeNTSC ? 0x10 : 0x00);
284 int pad0Index = joystick_ram[1] & 0x0F;
285 //unused int pad1Index = (joystick_ram[1] >> 4) & 0x0F;
287 if (!(pad0Index & 0x01))
289 if (joypad_0_buttons[BUTTON_PAUSE])
291 if (joypad_0_buttons[BUTTON_A])
294 else if (!(pad0Index & 0x02))
296 if (joypad_0_buttons[BUTTON_B])
299 else if (!(pad0Index & 0x04))
301 if (joypad_0_buttons[BUTTON_C])
306 if (joypad_0_buttons[BUTTON_OPTION])
312 return joystick_ram[offset];
315 uint16 joystick_word_read(uint32 offset)
317 return ((uint16)joystick_byte_read((offset+0)&0x03) << 8) | joystick_byte_read((offset+1)&0x03);