5 extern char *romname;
\r
6 extern unsigned char *rom_data;
\r
7 extern unsigned int rom_size;
\r
8 extern int fastForward;
\r
9 extern int frameStep;
\r
10 extern int emu_frame;
\r
14 // --------------------- XBox Input -----------------------------
\r
16 static HANDLE GamePad=NULL;
\r
17 static XINPUT_STATE Pad;
\r
19 static int DeadZone(short *paxis)
\r
24 if (a<-zone) a+=zone;
\r
25 else if (a> zone) a-=zone; else a=0;
\r
31 static int DeviceRead()
\r
35 memset(Inp.axis, 0,sizeof(Inp.axis));
\r
36 memset(Inp.button,0,sizeof(Inp.button));
\r
38 if (GamePad==NULL) GamePad=XInputOpen(XDEVICE_TYPE_GAMEPAD,0,XDEVICE_NO_SLOT,NULL);
\r
39 if (GamePad==NULL) return 1;
\r
41 // Read XBox joypad:
\r
42 XInputGetState(GamePad,&Pad);
\r
45 Inp.axis[0]=Pad.Gamepad.sThumbLX;
\r
46 Inp.axis[1]=Pad.Gamepad.sThumbLY;
\r
47 Inp.axis[2]=Pad.Gamepad.sThumbRX;
\r
48 Inp.axis[3]=Pad.Gamepad.sThumbRY;
\r
50 for (a=0;a<4;a++) DeadZone(Inp.axis+a);
\r
52 // Get digital buttons:
\r
53 but=Pad.Gamepad.wButtons;
\r
56 if (but&(1<<a)) Inp.button[a]=0xff;
\r
59 // Get analog buttons:
\r
60 memcpy(Inp.button+8, Pad.Gamepad.bAnalogButtons, 8);
\r
67 // --------------------- Windows Input -----------------------------
\r
71 static int DeviceRead()
\r
74 int axis[]={0,0,0,0};
\r
77 memset(Inp.axis, 0,sizeof(Inp.axis));
\r
78 memset(Inp.button,0,sizeof(Inp.button));
\r
80 if (GetForegroundWindow()!=FrameWnd) return 1;
\r
82 if (GetAsyncKeyState(VK_LEFT )) axis[0]-=push;
\r
83 if (GetAsyncKeyState(VK_RIGHT)) axis[0]+=push;
\r
84 if (GetAsyncKeyState(VK_DOWN )) axis[1]-=push;
\r
85 if (GetAsyncKeyState(VK_UP )) axis[1]+=push;
\r
86 for (i=0;i<4;i++) Inp.axis[i]=(short)axis[i];
\r
88 if (GetAsyncKeyState(VK_RETURN)) Inp.button[4]=0xff; // Start
\r
89 //if (GetAsyncKeyState(VK_ESCAPE)) Inp.button[7]=0xff; // Right thumb
\r
91 if (GetAsyncKeyState('Z')) Inp.button[10]=0xff;
\r
92 if (GetAsyncKeyState('X')) Inp.button[ 8]=0xff;
\r
93 if (GetAsyncKeyState('C')) Inp.button[ 9]=0xff;
\r
95 if (GetAsyncKeyState('A')) Inp.button[13]=0xff;
\r
96 if (GetAsyncKeyState('S')) Inp.button[12]=0xff;
\r
97 if (GetAsyncKeyState('D')) Inp.button[11]=0xff;
\r
98 if (GetAsyncKeyState('F')) Inp.button[14]=0xff;
\r
100 static int sblobked = 0;
\r
101 if(!sblobked && GetAsyncKeyState(VK_F6)) {
\r
103 romname[strlen(romname)-3] = 0;
\r
104 strcat(romname, "mds");
\r
105 PmovFile = fopen(romname, "wb");
\r
107 PmovState(5, PmovFile);
\r
112 else if(!sblobked && GetAsyncKeyState(VK_F9)) {
\r
114 romname[strlen(romname)-3] = 0;
\r
115 strcat(romname, "mds");
\r
116 PmovFile = fopen(romname, "rb");
\r
118 PmovState(6, PmovFile);
\r
123 else if(!sblobked && GetAsyncKeyState(VK_TAB)) {
\r
128 else if(!sblobked && GetAsyncKeyState(VK_ESCAPE)) {
\r
131 OPENFILENAME of; ZeroMemory(&of, sizeof(OPENFILENAME));
\r
132 of.lStructSize = sizeof(OPENFILENAME);
\r
133 of.lpstrFilter = "ROMs\0*.smd;*.bin;*.gen\0";
\r
134 of.lpstrFile = romname; romname[0] = 0;
\r
135 of.nMaxFile = MAX_PATH;
\r
136 of.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
\r
137 GetOpenFileName(&of);
\r
138 rom = fopen(romname, "rb");
\r
141 PicoCartLoad(rom, &rom_data, &rom_size);
\r
142 PicoCartInsert(rom_data, rom_size);
\r
146 else if(!sblobked && GetAsyncKeyState(VK_BACK)) {
\r
147 if(frameStep) frameStep=0;
\r
148 else fastForward^=1;
\r
151 else if(!sblobked && GetAsyncKeyState(VK_OEM_5)) {
\r
156 sblobked = GetAsyncKeyState(VK_F6) | GetAsyncKeyState(VK_F9) |
\r
157 GetAsyncKeyState(VK_TAB) | GetAsyncKeyState(VK_ESCAPE) |
\r
158 GetAsyncKeyState(VK_BACK) | GetAsyncKeyState(VK_OEM_5);
\r
167 memset(&Inp,0,sizeof(Inp));
\r
169 memset(&Pad,0,sizeof(Pad));
\r
170 XInitDevices(0,NULL);
\r
178 if (GamePad) XInputClose(GamePad);
\r
188 DeviceRead(); // Read XBox or PC device
\r
190 // Use left analog for left digital too:
\r
191 if (Inp.axis[1]>= push) Inp.button[0]|=0xff; // Up
\r
192 if (Inp.axis[1]<=-push) Inp.button[1]|=0xff; // Down
\r
193 if (Inp.axis[0]<=-push) Inp.button[2]|=0xff; // Left
\r
194 if (Inp.axis[0]>= push) Inp.button[3]|=0xff; // Right
\r
196 // Update debounce/time held information:
\r
197 for (i=0;i<sizeof(Inp.held);i++)
\r
199 if (Inp.held[i]==0)
\r
201 if (Inp.button[i]>30) Inp.held[i]=1; // Just pressed
\r
205 // Is the button still being held down?
\r
207 if (Inp.held[i]>=0x80) Inp.held[i]&=0xbf; // (Keep looping around)
\r
209 if (Inp.button[i]<25) Inp.held[i]=0; // No
\r
213 // Work out some key repeat values:
\r
214 for (i=0;i<sizeof(Inp.repeat);i++)
\r
217 int held=Inp.held[i];
\r
219 if (held==1) rep=1;
\r
220 if (held>=0x20 && (held&1)) rep=1;
\r
228 // Set Lightgun calibration values:
\r
229 int InputLightCal(int cx,int cy,int ux,int uy)
\r
232 XINPUT_LIGHTGUN_CALIBRATION_OFFSETS cal;
\r
234 memset(&cal,0,sizeof(cal));
\r
236 cal.wCenterX =(WORD)cx;
\r
237 cal.wCenterY =(WORD)cy;
\r
238 cal.wUpperLeftX=(WORD)ux;
\r
239 cal.wUpperLeftY=(WORD)uy;
\r
240 XInputSetLightgunCalibration(GamePad,&cal);
\r
244 (void)(cx+cy+ux+uy);
\r