1 // Module for input
2 #include "burner.h"
3 
4 #define MAX_JOYSTICKS (1)
5 
6 static int nInitedSubsytems = 0;
7 static int* JoyPrevAxes = NULL;
8 static int nJoystickCount = 0;						// Number of joysticks connected to this machine
9 
10 static SceCtrlData myInput;
11 
PSPinpSetCooperativeLevel(bool bExclusive,bool)12 int PSPinpSetCooperativeLevel(bool bExclusive, bool /*bForeGround*/)
13 {
14 	return 0;
15 }
16 
PSPinpExit()17 int PSPinpExit()
18 {
19 	nJoystickCount = 0;
20 
21 	free(JoyPrevAxes);
22 	JoyPrevAxes = NULL;
23 
24 	return 0;
25 }
26 
PSPinpInit()27 int PSPinpInit()
28 {
29 	int nSize;
30 
31 	nSize = MAX_JOYSTICKS * 8 * sizeof(int);
32 	if ((JoyPrevAxes = (int*)malloc(nSize)) == NULL) {
33 		return 1;
34 	}
35 	memset(JoyPrevAxes, 0, nSize);
36 	// Set up the joysticks
37 	nJoystickCount = 1;
38 	return 0;
39 }
40 
41 static unsigned char bKeyboardRead = 0;
42 
43 static unsigned char bJoystickRead = 0;
44 
45 static unsigned char bMouseRead = 0;
46 static struct { unsigned char buttons; int xdelta; int ydelta; } PSPinpMouseState;
47 
48 // Call before checking for Input in a frame
PSPinpStart()49 int PSPinpStart()
50 {
51 	// Keyboard not read this frame
52 	bKeyboardRead = 0;
53 
54 	// No joysticks have been read for this frame
55 	bJoystickRead = 0;
56 
57 	// Mouse not read this frame
58 	bMouseRead = 0;
59 
60 	sceCtrlPeekBufferPositive( &myInput, 1 );
61 
62 	return 0;
63 }
64 
65 // Read one of the joysticks
ReadJoystick()66 static int ReadJoystick()
67 {
68 	if (bJoystickRead) {
69 		return 0;
70 	}
71 
72 	// All joysticks have been Read this frame
73 	bJoystickRead = 1;
74 
75 	return 0;
76 }
77 
78 // Read one joystick axis
PSPinpJoyAxis(int i,int nAxis)79 int PSPinpJoyAxis(int i, int nAxis)
80 {
81 	if (i < 0 || i >= nJoystickCount) {				// This joystick number isn't connected
82 		return 0;
83 	}
84 
85 	if (ReadJoystick() != 0) {						// There was an error polling the joystick
86 		return 0;
87 	}
88 
89 	return 0;
90 }
91 
92 // Read the keyboard
ReadKeyboard()93 static int ReadKeyboard()
94 {
95 	int numkeys;
96 
97 	if (bKeyboardRead) {							// already read this frame - ready to go
98 		return 0;
99 	}
100 
101 	// The keyboard has been successfully Read this frame
102 	bKeyboardRead = 1;
103 
104 	return 0;
105 }
106 
ReadMouse()107 static int ReadMouse()
108 {
109 	if (bMouseRead) {
110 		return 0;
111 	}
112 
113 	bMouseRead = 1;
114 
115 	return 0;
116 }
117 
118 // Read one mouse axis
PSPinpMouseAxis(int i,int nAxis)119 int PSPinpMouseAxis(int i, int nAxis)
120 {
121 	if (i < 0 || i >= 1) {									// Only the system mouse is supported by SDL
122 		return 0;
123 	}
124 
125 	return 0;
126 }
127 
128 // Check a subcode (the 40xx bit in 4001, 4102 etc) for a joystick input code
JoystickState(int i,int nSubCode)129 static int JoystickState(int i, int nSubCode)
130 {
131 	return 0;
132 }
133 
134 // Check a subcode (the 80xx bit in 8001, 8102 etc) for a mouse input code
CheckMouseState(unsigned int nSubCode)135 static int CheckMouseState(unsigned int nSubCode)
136 {
137 
138 	return 0;
139 }
140 
141 // Get the state (pressed = 1, not pressed = 0) of a particular input code
142 // look in inp_keys.h to see what keycodes need mapping, e.g. 9 is used for the
143 // diag mode in cps, I think. Better check on the win32 version :-)
PSPinpState(int nCode)144 int PSPinpState(int nCode)
145 {
146 	switch(nCode)
147 	{
148 	case 0x02: // start
149 		return ((myInput.Buttons & PSP_CTRL_START) ? 1 : 0);
150 		break;
151 	case 0x06: // coin
152 		return ((myInput.Buttons & PSP_CTRL_SELECT) ? 1 : 0);
153 		break;
154 	case 0x3c: //f2
155 		break;
156 	case 0x3D: //f3
157 		break;
158 	case 0x4000: // left
159 		return ((myInput.Buttons & PSP_CTRL_LEFT) ? 1 : 0);
160 		break;
161 	case 0x4001: // right
162 		return ((myInput.Buttons & PSP_CTRL_RIGHT) ? 1 : 0);
163 		break;
164 	case 0x4002: // up
165 		return ((myInput.Buttons & PSP_CTRL_UP) ? 1 : 0);
166 		break;
167 	case 0x4003: // down
168 		return ((myInput.Buttons & PSP_CTRL_DOWN) ? 1 : 0);
169 		break;
170 
171 	case 0x4080: //fire1
172 		return ((myInput.Buttons & PSP_CTRL_SQUARE) ? 1 : 0);
173 		break;
174 	case 0x4081: //fire 2
175 		return ((myInput.Buttons & PSP_CTRL_CROSS) ? 1 : 0);
176 		break;
177 	case 0x4082: // etc
178 		return ((myInput.Buttons & PSP_CTRL_CIRCLE) ? 1 : 0);
179 		break;
180 	case 0x4083:
181 		return ((myInput.Buttons & PSP_CTRL_TRIANGLE) ? 1 : 0);
182 		break;
183 	case 0x4084:
184 		return ((myInput.Buttons & PSP_CTRL_LTRIGGER) ? 1 : 0);
185 		break;
186 	case 0x4085:
187 		return ((myInput.Buttons & PSP_CTRL_RTRIGGER) ? 1 : 0);
188 		break;
189 	//fba can map 2 more buttons but I dont think the psp has that many and no games use that much that I know of
190 	default:
191 		return 0;
192 	}
193 	return 0;
194 }
195 
196 // This function finds which key is pressed, and returns its code
PSPinpFind(bool CreateBaseline)197 int PSPinpFind(bool CreateBaseline)
198 {
199 	int nRetVal = -1;										// assume nothing pressed
200 
201 	return nRetVal;
202 }
203 
PSPinpGetControlName(int nCode,TCHAR * pszDeviceName,TCHAR * pszControlName)204 int PSPinpGetControlName(int nCode, TCHAR* pszDeviceName, TCHAR* pszControlName)
205 {
206 	return 0;
207 }
208 
209 struct InputInOut InputInOutPSP = { PSPinpInit, PSPinpExit, PSPinpSetCooperativeLevel, PSPinpStart, PSPinpState, PSPinpJoyAxis, PSPinpMouseAxis, PSPinpFind, PSPinpGetControlName, NULL, _T("PSP input") };
210