Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F126366
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
11 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/util/input/psp/joystick.cpp b/util/input/psp/joystick.cpp
index 58949739..95f11418 100644
--- a/util/input/psp/joystick.cpp
+++ b/util/input/psp/joystick.cpp
@@ -1,104 +1,305 @@
#ifdef MINPSPW
+// Assumes SDL
+#include <SDL.h>
+
#include "joystick.h"
+#include "util/debug.h"
void PSPJoystick::poll(){
events.clear();
- sceCtrlPeekBufferPositive(&joystick, 1);
+ sceCtrlPeekBufferPositive(&joystick, 1);
+ doKeys();
}
int PSPJoystick::getDeviceId() const {
- /* FIXME */
+ /* Only one available on psp, return that */
return 0;
}
JoystickInput PSPJoystick::readAll(){
- JoystickInput input;
- if(joystick.Buttons != 0){
- if(joystick.Buttons & PSP_CTRL_START){
- //input.button7 = true;
- } else if(joystick.Buttons & PSP_CTRL_SELECT){
- //input.button8 = true;
- } else if(joystick.Buttons & PSP_CTRL_SQUARE){
- input.button1 = true;
- } else if(joystick.Buttons & PSP_CTRL_CROSS){
- input.button2 = true;
- } else if(joystick.Buttons & PSP_CTRL_TRIANGLE){
- input.button3 = true;
- } else if(joystick.Buttons & PSP_CTRL_CIRCLE){
- input.button4 = true;
- } else if(joystick.Buttons & PSP_CTRL_RTRIGGER){
- } else if(joystick.Buttons & PSP_CTRL_LTRIGGER){
- } else if(joystick.Buttons & PSP_CTRL_LEFT){
- input.left = true;
- } else if(joystick.Buttons & PSP_CTRL_RIGHT){
- input.right = true;
- } else if(joystick.Buttons & PSP_CTRL_DOWN){
- input.down = true;
- } else if(joystick.Buttons & PSP_CTRL_UP){
- input.up = true;
- }
- }
-
- return input;
+ return buffer;
}
void PSPJoystick::pressButton(int button){
+ /* NOTE This can easily be done in doKeys instead of feeding it back into SDL to run this */
Event event = Invalid;
switch (button){
case 0: event = Button1; break;
case 1: event = Button2; break;
case 2: event = Button3; break;
case 3: event = Button4; break;
case 4: event = Quit; break;
}
events.push_back(event);
}
void PSPJoystick::releaseButton(int button){
}
void PSPJoystick::axisMotion(int axis, int motion){
if (axis == 0){
if (motion < 0){
events.push_back(Left);
} else if (motion > 0){
events.push_back(Right);
}
} else if (axis == 1){
if (motion < 0){
events.push_back(Up);
} else if (motion > 0){
events.push_back(Down);
}
}
}
-Joystick::Event PSPJoystick::getKey(int button){
- /*
- switch (key){
- case (joystick.Buttons & PSP_CTRL_SQUARE):
- return Button1; break;
- case (joystick.Buttons & PSP_CTRL_CROSS):
- return Button2; break;
- case (joystick.Buttons & PSP_CTRL_TRIANGLE):
- return Button3; break;
- case (joystick.Buttons & PSP_CTRL_CIRCLE):
- return Button4; break;
- default: break;
+void PSPJoystick::doKeys(){
+ if(joystick.Buttons != 0){
+
+ /*
+ if(!(buffer.button7) && (joystick.Buttons & PSP_CTRL_START)){
+
+ } else if((buffer.button7) && !(joystick.Buttons & PSP_CTRL_START)){
+
+ } */
+
+ if(!(buffer.quit) && (joystick.Buttons & PSP_CTRL_SELECT)){
+ buffer.quit = true;
+ // Create SDL joy button event
+ SDL_Event event;
+ // Default to 0
+ event.jbutton.which = 0;
+ event.jbutton.button = 4;
+ event.jbutton.type = SDL_JOYBUTTONDOWN;
+ event.jbutton.state = SDL_PRESSED;
+ SDL_PushEvent(&event);
+ } else if((buffer.quit) && !(joystick.Buttons & PSP_CTRL_SELECT)){
+ buffer.quit = false;
+ // Create SDL joy button event
+ SDL_Event event;
+ // Default to 0
+ event.jbutton.which = 0;
+ event.jbutton.button = 4;
+ event.jbutton.type = SDL_JOYBUTTONUP;
+ event.jbutton.state = SDL_RELEASED;
+ SDL_PushEvent(&event);
+ }
+
+ if(!(buffer.button1) && (joystick.Buttons & PSP_CTRL_SQUARE)){
+ buffer.button1 = true;
+ // Create SDL joy button event
+ SDL_Event event;
+ // Default to 0
+ event.jbutton.which = 0;
+ event.jbutton.button = 0;
+ event.jbutton.type = SDL_JOYBUTTONDOWN;
+ event.jbutton.state = SDL_PRESSED;
+ SDL_PushEvent(&event);
+ } else if((buffer.button1) && !(joystick.Buttons & PSP_CTRL_SQUARE)){
+ buffer.button1 = false;
+ // Create SDL joy button event
+ SDL_Event event;
+ // Default to 0
+ event.jbutton.which = 0;
+ event.jbutton.button = 0;
+ event.jbutton.type = SDL_JOYBUTTONUP;
+ event.jbutton.state = SDL_RELEASED;
+ SDL_PushEvent(&event);
+ }
+
+ if(!(buffer.button2) && (joystick.Buttons & PSP_CTRL_CROSS)){
+ buffer.button2 = true;
+ // Create SDL joy button event
+ SDL_Event event;
+ // Default to 0
+ event.jbutton.which = 0;
+ event.jbutton.button = 1;
+ event.jbutton.type = SDL_JOYBUTTONDOWN;
+ event.jbutton.state = SDL_PRESSED;
+ SDL_PushEvent(&event);
+ } else if((buffer.button2) && !(joystick.Buttons & PSP_CTRL_CROSS)){
+ buffer.button2 = false;
+ // Create SDL joy button event
+ SDL_Event event;
+ // Default to 0
+ event.jbutton.which = 0;
+ event.jbutton.button = 1;
+ event.jbutton.type = SDL_JOYBUTTONUP;
+ event.jbutton.state = SDL_RELEASED;
+ SDL_PushEvent(&event);
+ }
+
+ if(!(buffer.button3) && (joystick.Buttons & PSP_CTRL_TRIANGLE)){
+ buffer.button3 = true;
+ // Create SDL joy button event
+ SDL_Event event;
+ // Default to 0
+ event.jbutton.which = 0;
+ event.jbutton.button = 2;
+ event.jbutton.type = SDL_JOYBUTTONDOWN;
+ event.jbutton.state = SDL_PRESSED;
+ SDL_PushEvent(&event);
+ } else if((buffer.button3) && !(joystick.Buttons & PSP_CTRL_TRIANGLE)){
+ buffer.button3 = false;
+ // Create SDL joy button event
+ SDL_Event event;
+ // Default to 0
+ event.jbutton.which = 0;
+ event.jbutton.button = 2;
+ event.jbutton.type = SDL_JOYBUTTONUP;
+ event.jbutton.state = SDL_RELEASED;
+ SDL_PushEvent(&event);
+ }
+
+ if(!(buffer.button4) && (joystick.Buttons & PSP_CTRL_CIRCLE)){
+ buffer.button4 = true;
+ // Create SDL joy button event
+ SDL_Event event;
+ // Default to 0
+ event.jbutton.which = 0;
+ event.jbutton.button = 3;
+ event.jbutton.type = SDL_JOYBUTTONDOWN;
+ event.jbutton.state = SDL_PRESSED;
+ SDL_PushEvent(&event);
+ } else if((buffer.button4) && !(joystick.Buttons & PSP_CTRL_CIRCLE)){
+ buffer.button4 = false;
+ // Create SDL joy button event
+ SDL_Event event;
+ // Default to 0
+ event.jbutton.which = 0;
+ event.jbutton.button = 3;
+ event.jbutton.type = SDL_JOYBUTTONUP;
+ event.jbutton.state = SDL_RELEASED;
+ SDL_PushEvent(&event);
+ }
+ /*
+ if(!(buffer.button5) && (joystick.Buttons & PSP_CTRL_RTRIGGER)){
+ } else if((buffer.button5) && !(joystick.Buttons & PSP_CTRL_RTRIGGER)){
+ }
+
+ if(!(buffer.button6) && (joystick.Buttons & PSP_CTRL_LTRIGGER)){
+ } else if((buffer.button6) && !(joystick.Buttons & PSP_CTRL_LTRIGGER)){
+ }
+ */
+
+ if(!(buffer.left) && (joystick.Buttons & PSP_CTRL_LEFT)){
+ buffer.left = true;
+ events.push_back(Left);
+#if 0
+ // Create SDL joy button event
+ SDL_Event event;
+ // Default to 0
+ event.jaxis.which = 0;
+ event.jaxis.type = SDL_JOYAXISMOTION;
+ event.jaxis.axis = 0;
+ event.jaxis.value = -1;
+ SDL_PushEvent(&event);
+#endif
+ } else if((buffer.left) && !(joystick.Buttons & PSP_CTRL_LEFT)){
+ buffer.left = false;
+#if 0
+ // Create SDL joy button event
+ SDL_Event event;
+ // Default to 0
+ event.jaxis.which = 0;
+ event.jaxis.type = SDL_JOYAXISMOTION;
+ event.jaxis.axis = 0;
+ event.jaxis.value = 0;
+ SDL_PushEvent(&event);
+#endif
+ }
+
+ if(!(buffer.right) && (joystick.Buttons & PSP_CTRL_RIGHT)){
+ buffer.right = true;
+ events.push_back(Right);
+#if 0
+ // Create SDL joy button event
+ SDL_Event event;
+ // Default to 0
+ event.jaxis.which = 0;
+ event.jaxis.type = SDL_JOYAXISMOTION;
+ event.jaxis.axis = 0;
+ event.jaxis.value = 1;
+ SDL_PushEvent(&event);
+#endif
+ } else if((buffer.right) && !(joystick.Buttons & PSP_CTRL_RIGHT)){
+ buffer.right = false;
+#if 0
+ // Create SDL joy button event
+ SDL_Event event;
+ // Default to 0
+ event.jaxis.which = 0;
+ event.jaxis.type = SDL_JOYAXISMOTION;
+ event.jaxis.axis = 0;
+ event.jaxis.value = 0;
+ SDL_PushEvent(&event);
+#endif
+ }
+
+ if(!(buffer.down) && (joystick.Buttons & PSP_CTRL_DOWN)){
+ buffer.down = true;
+ events.push_back(Down);
+#if 0
+ // Create SDL joy button event
+ SDL_Event event;
+ // Default to 0
+ event.jaxis.which = 0;
+ event.jaxis.type = SDL_JOYAXISMOTION;
+ event.jaxis.axis = 1;
+ event.jaxis.value = -1;
+ SDL_PushEvent(&event);
+#endif
+ } else if((buffer.down) && !(joystick.Buttons & PSP_CTRL_DOWN)){
+ buffer.down = false;
+#if 0
+ // Create SDL joy button event
+ SDL_Event event;
+ // Default to 0
+ event.jaxis.which = 0;
+ event.jaxis.type = SDL_JOYAXISMOTION;
+ event.jaxis.axis = 1;
+ event.jaxis.value = 0;
+ SDL_PushEvent(&event);
+#endif
+ }
+
+ if(!(buffer.up) && (joystick.Buttons & PSP_CTRL_UP)){
+ buffer.up = true;
+ events.push_back(Up);
+#if 0
+ // Create SDL joy button event
+ SDL_Event event;
+ // Default to 0
+ event.jaxis.which = 0;
+ event.jaxis.type = SDL_JOYAXISMOTION;
+ event.jaxis.axis = 1;
+ event.jaxis.value = 1;
+ SDL_PushEvent(&event);
+#endif
+ } else if((buffer.up) && !(joystick.Buttons & PSP_CTRL_UP)){
+ buffer.up = false;
+#if 0
+ // Create SDL joy button event
+ SDL_Event event;
+ // Default to 0
+ event.jaxis.which = 0;
+ event.jaxis.type = SDL_JOYAXISMOTION;
+ event.jaxis.axis = 1;
+ event.jaxis.value = 0;
+ SDL_PushEvent(&event);
+#endif
+ }
+
}
-
- return Invalid;
- */
}
PSPJoystick::~PSPJoystick(){
// no cleanup required
}
PSPJoystick::PSPJoystick(){
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
}
#endif
diff --git a/util/input/psp/joystick.h b/util/input/psp/joystick.h
index b5e97566..49c62e4a 100644
--- a/util/input/psp/joystick.h
+++ b/util/input/psp/joystick.h
@@ -1,32 +1,34 @@
#ifndef _paintown_psp_joystick_h
#define _paintown_psp_joystick_h
#ifdef MINPSPW
#include "../joystick.h"
#include <pspctrl.h>
class PSPJoystick: public Joystick {
public:
virtual void poll();
virtual JoystickInput readAll();
virtual int getDeviceId() const;
virtual void pressButton(int button);
virtual void releaseButton(int button);
virtual void axisMotion(int axis, int motion);
virtual ~PSPJoystick();
friend class Joystick;
protected:
- Joystick::Event getKey(int button);
+ void doKeys();
+ JoystickInput buffer;
+
PSPJoystick();
// joystick
SceCtrlData joystick;
};
#endif
#endif
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Jun 11, 11:24 AM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
68735
Default Alt Text
(11 KB)
Attached To
Mode
R75 R-Tech1
Attached
Detach File
Event Timeline