2 #include "include/stdafx.h"
7 #include "include/SDLptc.h"
8 #include "include/jaguar.h"
10 void main_screen_switch(void);
34 #define BUTTON_OPTION 19
35 #define BUTTON_PAUSE 20
37 static uint8 joystick_ram[4];
38 static uint8 joypad_0_buttons[21];
39 static uint8 joypad_1_buttons[21];
40 extern uint8 finished;
41 extern int start_logging;
43 //////////////////////////////////////////////////////////////////////////////
45 //////////////////////////////////////////////////////////////////////////////
49 //////////////////////////////////////////////////////////////////////////////
50 void joystick_init(void)
54 //////////////////////////////////////////////////////////////////////////////
56 //////////////////////////////////////////////////////////////////////////////
60 //////////////////////////////////////////////////////////////////////////////
61 void joystick_exec(void)
64 uint8 *keystate = SDL_GetKeyState(NULL);
66 extern Console console;
68 memset(joypad_0_buttons,0,21);
69 memset(joypad_1_buttons,0,21);
71 if ((keystate[SDLK_LALT])&(keystate[SDLK_RETURN])) main_screen_switch();
73 /* Added/Changed by SDLEMU (http://sdlemu.ngemu.com) */
75 if (keystate[SDLK_UP]) joypad_0_buttons[BUTTON_U]=0x01;
76 if (keystate[SDLK_DOWN]) joypad_0_buttons[BUTTON_D]=0x01;
77 if (keystate[SDLK_LEFT]) joypad_0_buttons[BUTTON_L]=0x01;
78 if (keystate[SDLK_RIGHT]) joypad_0_buttons[BUTTON_R]=0x01;
79 if (keystate[SDLK_z]) joypad_0_buttons[BUTTON_A]=0x01;
80 if (keystate[SDLK_x]) joypad_0_buttons[BUTTON_B]=0x01;
81 if (keystate[SDLK_c]) joypad_0_buttons[BUTTON_C]=0x01;
82 if (keystate[SDLK_TAB]) joypad_0_buttons[BUTTON_OPTION]=0x01;
83 if (keystate[SDLK_RETURN]) joypad_0_buttons[BUTTON_PAUSE]=0x01;
84 if (keystate[SDLK_q]) start_logging=1;
85 if (keystate[SDLK_w]) gpu_reset_stats();
86 //f (keystate[SDLK_u]) jaguar_long_write(0xf1c384,jaguar_long_read(0xf1c384)+1);
88 if (keystate[SDLK_KP0]) joypad_0_buttons[BUTTON_0]=0x01;
89 if (keystate[SDLK_KP1]) joypad_0_buttons[BUTTON_1]=0x01;
90 if (keystate[SDLK_KP2]) joypad_0_buttons[BUTTON_2]=0x01;
91 if (keystate[SDLK_KP3]) joypad_0_buttons[BUTTON_3]=0x01;
92 if (keystate[SDLK_KP4]) joypad_0_buttons[BUTTON_4]=0x01;
93 if (keystate[SDLK_KP5]) joypad_0_buttons[BUTTON_5]=0x01;
94 if (keystate[SDLK_KP6]) joypad_0_buttons[BUTTON_6]=0x01;
95 if (keystate[SDLK_KP7]) joypad_0_buttons[BUTTON_7]=0x01;
96 if (keystate[SDLK_KP8]) joypad_0_buttons[BUTTON_8]=0x01;
97 if (keystate[SDLK_KP9]) joypad_0_buttons[BUTTON_9]=0x01;
99 if (keystate[SDLK_ESCAPE]) finished=1;
101 /* Added/Changed by SDLEMU (http://sdlemu.ngemu.com */
102 /* Joystick support */
104 if ( console.JoyEnabled() == 1 ) {
106 x = SDL_JoystickGetAxis(console.joystick, 0);
107 y = SDL_JoystickGetAxis(console.joystick, 1);
109 if ( x > 16384 ) joypad_0_buttons[BUTTON_R]=0x01;
110 if ( x < -16384 ) joypad_0_buttons[BUTTON_L]=0x01;
111 if ( y > 16384 ) joypad_0_buttons[BUTTON_D]=0x01;
112 if ( y < -16384 ) joypad_0_buttons[BUTTON_U]=0x01;
114 if (SDL_JoystickGetButton(console.joystick, 0) == SDL_PRESSED) joypad_0_buttons[BUTTON_A]=0x01;
115 if (SDL_JoystickGetButton(console.joystick, 1) == SDL_PRESSED) joypad_0_buttons[BUTTON_B]=0x01;
116 if (SDL_JoystickGetButton(console.joystick, 2) == SDL_PRESSED) joypad_0_buttons[BUTTON_C]=0x01;
120 /* ADDED by SDLEMU (http://sdlemu.ngemu.com */
121 /* Needed to make sure that the events queue is empty */
125 //////////////////////////////////////////////////////////////////////////////
127 //////////////////////////////////////////////////////////////////////////////
131 //////////////////////////////////////////////////////////////////////////////
132 void joystick_reset(void)
134 memset(joystick_ram,0x00,4);
135 memset(joypad_0_buttons,0,21);
136 memset(joypad_1_buttons,0,21);
138 //////////////////////////////////////////////////////////////////////////////
140 //////////////////////////////////////////////////////////////////////////////
144 //////////////////////////////////////////////////////////////////////////////
145 void joystick_done(void)
148 //////////////////////////////////////////////////////////////////////////////
150 //////////////////////////////////////////////////////////////////////////////
154 //////////////////////////////////////////////////////////////////////////////
155 void joystick_byte_write(uint32 offset, uint8 data)
157 joystick_ram[offset&0x03]=data;
159 //////////////////////////////////////////////////////////////////////////////
161 //////////////////////////////////////////////////////////////////////////////
165 //////////////////////////////////////////////////////////////////////////////
166 void joystick_word_write(uint32 offset, uint16 data)
169 joystick_ram[offset+0]=(data>>8)&0xff;
170 joystick_ram[offset+1]=data&0xff;
172 //////////////////////////////////////////////////////////////////////////////
174 //////////////////////////////////////////////////////////////////////////////
178 //////////////////////////////////////////////////////////////////////////////
179 uint8 joystick_byte_read(uint32 offset)
186 int pad0Index=joystick_ram[1]&0x0f;
187 int pad1Index=(joystick_ram[1]>>4)&0x0f;
189 if (!(pad0Index&0x01))
192 if (!(pad0Index&0x02))
195 if (!(pad0Index&0x04))
200 if (!(pad1Index&0x01))
203 if (!(pad1Index&0x02))
206 if (!(pad1Index&0x04))
211 if (joypad_0_buttons[(pad0Index<<2)+0]) data|=0x01;
212 if (joypad_0_buttons[(pad0Index<<2)+1]) data|=0x02;
213 if (joypad_0_buttons[(pad0Index<<2)+2]) data|=0x04;
214 if (joypad_0_buttons[(pad0Index<<2)+3]) data|=0x08;
215 if (joypad_1_buttons[(pad1Index<<2)+0]) data|=0x10;
216 if (joypad_1_buttons[(pad1Index<<2)+1]) data|=0x20;
217 if (joypad_1_buttons[(pad1Index<<2)+2]) data|=0x40;
218 if (joypad_1_buttons[(pad1Index<<2)+3]) data|=0x80;
224 uint8 data=((1<<5)|(1<<4)|0x0f) ;
225 int pad0Index=joystick_ram[1]&0x0f;
226 int pad1Index=(joystick_ram[1]>>4)&0x0f;
228 if (!(pad0Index&0x01))
230 if (joypad_0_buttons[BUTTON_PAUSE]) data^=0x01;
231 if (joypad_0_buttons[BUTTON_A]) data^=0x02;
234 if (!(pad0Index&0x02))
236 if (joypad_0_buttons[BUTTON_B]) data^=0x02;
239 if (!(pad0Index&0x04))
241 if (joypad_0_buttons[BUTTON_C]) data^=0x02;
245 if (joypad_0_buttons[BUTTON_OPTION]) data^=0x02;
249 return(joystick_ram[offset]);
251 //////////////////////////////////////////////////////////////////////////////
253 //////////////////////////////////////////////////////////////////////////////
257 //////////////////////////////////////////////////////////////////////////////
258 uint16 joystick_word_read(uint32 offset)
260 uint16 data=joystick_byte_read((offset+0)&0x03);
262 data|=joystick_byte_read((offset+1)&0x03);