extra input methods
authorJavier S. Pedro <maemo@javispedro.com>
Mon, 17 Aug 2009 00:50:25 +0000 (02:50 +0200)
committerJavier S. Pedro <maemo@javispedro.com>
Mon, 17 Aug 2009 00:52:10 +0000 (02:52 +0200)
Added partial support for mouse and superscope input.

gui/drnoksnes_plugin.so [deleted file]
platform/config.cpp
platform/platform.h
platform/sdli.cpp

diff --git a/gui/drnoksnes_plugin.so b/gui/drnoksnes_plugin.so
deleted file mode 100755 (executable)
index 4803714..0000000
Binary files a/gui/drnoksnes_plugin.so and /dev/null differ
index 55d86d4..393eb98 100644 (file)
@@ -38,6 +38,10 @@ static const struct poptOption optionsTable[] = {
        "Turbo mode (do not try to sleep between frames)", 0 },
        { "conf", 'c', POPT_ARG_STRING, 0, 10,
        "Extra configuration file to load", "FILE" },
+       { "mouse", 'm', POPT_ARG_INT | POPT_ARGFLAG_OPTIONAL, 0, 11,
+       "Enable mouse on controller NUM", "NUM"},
+       { "superscope", 'e', POPT_ARG_NONE, 0, 12,
+       "Enable SuperScope", 0},
        { "scancode", '\0', POPT_ARG_INT, 0, 100,
        "Scancode to map", "CODE" },
        { "button", '\0', POPT_ARG_STRING, 0, 101,
@@ -148,8 +152,7 @@ static void loadDefaults()
        Settings.Mouse = FALSE;
        Settings.SuperScope = FALSE;
        Settings.MultiPlayer5 = FALSE;
-       //      Settings.ControllerOption = SNES_MULTIPLAYER5;
-       Settings.ControllerOption = 0;
+       Settings.ControllerOption = SNES_JOYPAD;
        
        Settings.ForceTransparency = FALSE;
        Settings.Transparency = FALSE;
@@ -162,12 +165,9 @@ static void loadDefaults()
        Settings.ApplyCheats = FALSE;
        Settings.TurboMode = FALSE;
        Settings.TurboSkipFrames = 15;
-       Settings.ThreadSound = FALSE;
-       Settings.SoundSync = FALSE;
+       //Settings.ThreadSound = FALSE;
+       //Settings.SoundSync = FALSE;
        //Settings.NoPatch = true;
-       
-    Settings.ApplyCheats = FALSE;
-    Settings.TurboMode = FALSE;
     
     Settings.ForcePAL = FALSE;
     Settings.ForceNTSC = FALSE;
@@ -250,6 +250,7 @@ static void parseArgs(poptContext optCon)
        unsigned char scancode = 0;
        
        while ((rc = poptGetNextOpt(optCon)) > 0) {
+               const char * val;
                switch (rc) {
                        case 1:
                                Config.enableAudio = false;
@@ -283,6 +284,21 @@ static void parseArgs(poptContext optCon)
                        case 10:
                                loadConfig(optCon, poptGetOptArg(optCon));
                                break;
+                       case 11:
+                               val = poptGetOptArg(optCon);
+                               Settings.Mouse = TRUE;
+                               if (!val || atoi(val) <= 1) {
+                                       // Enable mouse on first controller
+                                       Settings.ControllerOption = SNES_MOUSE_SWAPPED;
+                               } else {
+                                       // Enable mouse on second controller
+                                       Settings.ControllerOption = SNES_MOUSE;
+                               }
+                               break;
+                       case 12:
+                               Settings.SuperScope = TRUE;
+                               Settings.ControllerOption = SNES_SUPERSCOPE;
+                               break;
                        case 100:
                                scancode = atoi(poptGetOptArg(optCon));
                                break;
index e4b73b9..8584d7c 100644 (file)
@@ -12,8 +12,6 @@ extern struct config {
        bool fullscreen;
        bool xsp;
        bool enableAudio;
-       bool enableMouse;
-       bool enableSuperScope;
        unsigned short joypad1Mapping[256];
        unsigned char action[256];
        bool quitting;
index 2eea9fc..1d20b18 100644 (file)
@@ -7,6 +7,11 @@
 #define kPollEveryNFrames      3
 
 static uint32 joypads[2];
+static struct {
+       unsigned x;
+       unsigned y;
+       bool pressed;
+} mouse;
 
 static void processEvent(const SDL_Event& event)
 {
@@ -20,6 +25,24 @@ static void processEvent(const SDL_Event& event)
        case SDL_KEYUP:
                joypads[0] &= ~Config.joypad1Mapping[event.key.keysym.scancode];
                break;
+       case SDL_MOUSEBUTTONUP:
+       case SDL_MOUSEBUTTONDOWN:
+               mouse.x = event.button.x;
+               mouse.y = event.button.y;
+               if (Config.xsp) {
+                       mouse.x /= 2;
+                       mouse.y /= 2;
+               }
+               mouse.pressed = event.button.state == SDL_PRESSED;
+               break;
+       case SDL_MOUSEMOTION:
+               mouse.x = event.motion.x;
+               mouse.y = event.motion.y;
+               if (Config.xsp) {
+                       mouse.x /= 2;
+                       mouse.y /= 2;
+               }
+               break;
        case SDL_QUIT:
                Config.quitting = true;
                break;
@@ -31,26 +54,34 @@ uint32 S9xReadJoypad (int which)
        if (which < 0 || which > 2) {
                return 0;
        }
-       
+
        return joypads[which];
 }
 
-bool8 S9xReadMousePosition (int /* which1 */, int &/* x */, int & /* y */,
-                   uint32 & /* buttons */)
+bool8 S9xReadMousePosition(int which1, int& x, int& y, uint32& buttons)
 {
-       return FALSE;
+       if (which1 != 0) return FALSE;
+
+       x = mouse.x;
+       y = mouse.y;
+       buttons = mouse.pressed ? 1 : 0;
+
+       return TRUE;
 }
 
-bool8 S9xReadSuperScopePosition (int & /* x */, int & /* y */,
-                        uint32 & /* buttons */)
+bool8 S9xReadSuperScopePosition(int& x, int& y, uint32& buttons)
 {
-       return FALSE;
+       x = mouse.x;
+       y = mouse.y;
+       buttons = mouse.pressed ? 8 : 0;
+
+       return TRUE;
 }
 
 void S9xProcessEvents(bool8_32 block)
 {
        SDL_Event event;
-       
+
        if (block) {
                SDL_WaitEvent(&event);
                processEvent(event);
@@ -64,9 +95,28 @@ void S9xProcessEvents(bool8_32 block)
 
 void S9xInitInputDevices()
 {
-       joypads[0] = 0x80000000UL;
+       joypads[0] = 0;
        joypads[1] = 0;
-       
-       printf("Input: 1 joypad, hw keyboard input only\n");
+
+       switch (Settings.ControllerOption) {
+               case SNES_JOYPAD:
+                       joypads[0] = 0x80000000UL;
+                       printf("Input: 1 joypad, keyboard only\n");
+                       break;
+               case SNES_MOUSE:
+                       joypads[0] = 0x80000000UL;
+                       printf("Input: 1 joypad + mouse\n");
+                       break;
+               case SNES_MOUSE_SWAPPED:
+                       printf("Input: mouse\n");
+                       break;
+               case SNES_SUPERSCOPE:
+                       joypads[0] = 0x80000000UL;
+                       printf("Input: 1 joypad + superscope\n");
+                       break;
+               default:
+                       printf("Input: unknown\n");
+                       break;
+       }
 }