+++ /dev/null
-\r
-#include "app.h"\r
-#include <commdlg.h>\r
-\r
-struct Input Inp;\r
-\r
-// --------------------- XBox Input -----------------------------\r
-#ifdef _XBOX\r
-static HANDLE GamePad=NULL;\r
-static XINPUT_STATE Pad;\r
-\r
-static int DeadZone(short *paxis)\r
-{\r
- int zone=0x2000;\r
- int a=*paxis;\r
-\r
- if (a<-zone) a+=zone;\r
- else if (a> zone) a-=zone; else a=0;\r
-\r
- *paxis=(short)a;\r
- return 0;\r
-}\r
-\r
-static int DeviceRead()\r
-{\r
- int but=0,a=0;\r
-\r
- memset(Inp.axis, 0,sizeof(Inp.axis));\r
- memset(Inp.button,0,sizeof(Inp.button));\r
-\r
- if (GamePad==NULL) GamePad=XInputOpen(XDEVICE_TYPE_GAMEPAD,0,XDEVICE_NO_SLOT,NULL);\r
- if (GamePad==NULL) return 1;\r
-\r
- // Read XBox joypad:\r
- XInputGetState(GamePad,&Pad);\r
-\r
- // Get analog axes:\r
- Inp.axis[0]=Pad.Gamepad.sThumbLX;\r
- Inp.axis[1]=Pad.Gamepad.sThumbLY;\r
- Inp.axis[2]=Pad.Gamepad.sThumbRX;\r
- Inp.axis[3]=Pad.Gamepad.sThumbRY;\r
-\r
- for (a=0;a<4;a++) DeadZone(Inp.axis+a);\r
-\r
- // Get digital buttons:\r
- but=Pad.Gamepad.wButtons;\r
- for (a=0;a<8;a++)\r
- {\r
- if (but&(1<<a)) Inp.button[a]=0xff;\r
- }\r
-\r
- // Get analog buttons:\r
- memcpy(Inp.button+8, Pad.Gamepad.bAnalogButtons, 8);\r
-\r
- return 0;\r
-}\r
-\r
-#endif\r
-\r
-// --------------------- Windows Input -----------------------------\r
-\r
-#ifndef _XBOX\r
-\r
-static int DeviceRead()\r
-{\r
- int push=0x6000;\r
- int axis[]={0,0,0,0};\r
- int i=0;\r
-\r
- memset(Inp.axis, 0,sizeof(Inp.axis));\r
- memset(Inp.button,0,sizeof(Inp.button));\r
-\r
- if (GetForegroundWindow()!=FrameWnd) return 1;\r
-\r
- if (GetAsyncKeyState(VK_LEFT )) axis[0]-=push;\r
- if (GetAsyncKeyState(VK_RIGHT)) axis[0]+=push;\r
- if (GetAsyncKeyState(VK_DOWN )) axis[1]-=push;\r
- if (GetAsyncKeyState(VK_UP )) axis[1]+=push;\r
- for (i=0;i<4;i++) Inp.axis[i]=(short)axis[i];\r
-\r
- if (GetAsyncKeyState(VK_RETURN)) Inp.button[4]=0xff; // Start\r
- //if (GetAsyncKeyState(VK_ESCAPE)) Inp.button[7]=0xff; // Right thumb\r
-\r
- if (GetAsyncKeyState('Z')) Inp.button[10]=0xff;\r
- if (GetAsyncKeyState('X')) Inp.button[ 8]=0xff;\r
- if (GetAsyncKeyState('C')) Inp.button[ 9]=0xff;\r
-\r
- if (GetAsyncKeyState('A')) Inp.button[13]=0xff;\r
- if (GetAsyncKeyState('S')) Inp.button[12]=0xff;\r
- if (GetAsyncKeyState('D')) Inp.button[11]=0xff;\r
- if (GetAsyncKeyState('F')) Inp.button[14]=0xff;\r
-\r
- static int sblobked = 0;\r
- if (!sblobked && GetAsyncKeyState(VK_TAB)) {\r
- PicoReset();\r
- sblobked = 1;\r
- }\r
- else if (!sblobked && GetAsyncKeyState(VK_ESCAPE))\r
- {\r
- PostMessage(FrameWnd, WM_COMMAND, 0x20000 | 1000, 0);\r
- sblobked = 1;\r
- }\r
- else\r
- sblobked = GetAsyncKeyState(VK_TAB) | GetAsyncKeyState(VK_ESCAPE);\r
- \r
- return 0;\r
-}\r
-\r
-#endif\r
-\r
-int InputInit()\r
-{\r
- memset(&Inp,0,sizeof(Inp));\r
-#ifdef _XBOX\r
- memset(&Pad,0,sizeof(Pad));\r
- XInitDevices(0,NULL);\r
-#endif\r
- return 0;\r
-}\r
-\r
-void InputExit()\r
-{\r
-#ifdef _XBOX\r
- if (GamePad) XInputClose(GamePad);\r
- GamePad=NULL;\r
-#endif\r
-}\r
-\r
-int InputUpdate()\r
-{\r
- int i=0;\r
- int push=0x2000;\r
-\r
- DeviceRead(); // Read XBox or PC device \r
-\r
- // Use left analog for left digital too:\r
- if (Inp.axis[1]>= push) Inp.button[0]|=0xff; // Up\r
- if (Inp.axis[1]<=-push) Inp.button[1]|=0xff; // Down\r
- if (Inp.axis[0]<=-push) Inp.button[2]|=0xff; // Left\r
- if (Inp.axis[0]>= push) Inp.button[3]|=0xff; // Right\r
-\r
- // Update debounce/time held information:\r
- for (i=0;i<sizeof(Inp.held);i++)\r
- {\r
- if (Inp.held[i]==0)\r
- {\r
- if (Inp.button[i]>30) Inp.held[i]=1; // Just pressed\r
- }\r
- else\r
- {\r
- // Is the button still being held down?\r
- Inp.held[i]++;\r
- if (Inp.held[i]>=0x80) Inp.held[i]&=0xbf; // (Keep looping around)\r
-\r
- if (Inp.button[i]<25) Inp.held[i]=0; // No\r
- }\r
- }\r
-\r
- // Work out some key repeat values:\r
- for (i=0;i<sizeof(Inp.repeat);i++)\r
- {\r
- char rep=0;\r
- int held=Inp.held[i];\r
-\r
- if (held==1) rep=1;\r
- if (held>=0x20 && (held&1)) rep=1;\r
-\r
- Inp.repeat[i]=rep;\r
- }\r
-\r
- return 0;\r
-}\r
-\r
-// Set Lightgun calibration values:\r
-int InputLightCal(int cx,int cy,int ux,int uy)\r
-{\r
-#ifdef _XBOX\r
- XINPUT_LIGHTGUN_CALIBRATION_OFFSETS cal;\r
-\r
- memset(&cal,0,sizeof(cal));\r
-\r
- cal.wCenterX =(WORD)cx;\r
- cal.wCenterY =(WORD)cy;\r
- cal.wUpperLeftX=(WORD)ux;\r
- cal.wUpperLeftY=(WORD)uy;\r
- XInputSetLightgunCalibration(GamePad,&cal);\r
-\r
-#endif\r
-\r
- (void)(cx+cy+ux+uy);\r
-\r
- return 0;\r
-}\r