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