adding actual player 2 support
authorJavier S. Pedro <maemo@javispedro.com>
Mon, 8 Feb 2010 16:55:09 +0000 (17:55 +0100)
committerJavier S. Pedro <maemo@javispedro.com>
Mon, 8 Feb 2010 16:55:09 +0000 (17:55 +0100)
platform/config.cpp
platform/osso.cpp
platform/sdli.cpp
platform/sdlv.cpp
platform/sdlvscalers.cpp

index 08f5347..869dc7d 100644 (file)
@@ -197,8 +197,8 @@ static void loadDefaults()
        Config.fullscreen = false;
        Config.scaler = 0;
        Config.hacksFile = 0;
-       Config.player1Enabled = false;
-       Config.player2Enabled = false;
+       Config.joypad1Enabled = false;
+       Config.joypad2Enabled = false;
        Config.touchscreenInput = false;
        Config.touchscreenShow = false;
 
index 6eb9d93..010c11d 100644 (file)
@@ -15,6 +15,19 @@ static GMainContext *mainContext;
 static GMainLoop *mainLoop;
 osso_context_t *ossoContext;
 
+// Older versions of glib don't have this.
+#ifndef g_warn_if_fail
+#define g_warn_if_fail(expr) \
+       if G_UNLIKELY(expr) { \
+               g_warning("Non critical assertion failed at %s:%d \"%s\"", \
+                       __FILE__, __LINE__, #expr); \
+       }
+#endif
+#if ! GLIB_CHECK_VERSION(2,14,0)
+#define g_timeout_add_seconds(interval, function, data) \
+       g_timeout_add((interval) * 1000, function, data)
+#endif
+
 static volatile enum {
        STARTUP_COMMAND_INVALID = -1,
        STARTUP_COMMAND_UNKNOWN = 0,
index e7dd266..82fefe1 100644 (file)
@@ -118,9 +118,10 @@ static void processMouse(unsigned int x, unsigned int y, int pressed = 0)
                        if (mouse.y > GUI.RenderH) mouse.y = GUI.RenderH;
                }
 
-               // Take care of scaling
-               mouse.x /= GUI.ScaleX;
-               mouse.y /= GUI.ScaleY;
+               // mouse.{x,y} are system coordinates.
+               // Scale them to emulated screen coordinates.
+               mouse.x = static_cast<unsigned int>(mouse.x / GUI.ScaleX);
+               mouse.y = static_cast<unsigned int>(mouse.y / GUI.ScaleY);
 
                if (pressed > 0)
                        mouse.pressed = true;
@@ -137,9 +138,11 @@ static void processEvent(const SDL_Event& event)
                        if (Config.action[event.key.keysym.scancode]) 
                                S9xDoAction(Config.action[event.key.keysym.scancode]);
                        joypads[0] |= Config.joypad1Mapping[event.key.keysym.scancode];
+                       joypads[1] |= Config.joypad2Mapping[event.key.keysym.scancode];
                        break;
                case SDL_KEYUP:
                        joypads[0] &= ~Config.joypad1Mapping[event.key.keysym.scancode];
+                       joypads[1] &= ~Config.joypad2Mapping[event.key.keysym.scancode];
                        break;
                case SDL_MOUSEBUTTONUP:
                case SDL_MOUSEBUTTONDOWN:
@@ -159,15 +162,30 @@ static void processEvent(const SDL_Event& event)
        }
 }
 
+/** This function is called to return a bit-wise mask of the state of one of the
+       five emulated SNES controllers.
+
+       @return 0 if you're not supporting controllers past a certain number or
+               return the mask representing the current state of the controller number
+               passed as a parameter or'ed with 0x80000000.
+*/
+
 uint32 S9xReadJoypad (int which)
 {
-       if (which < 0 || which > 2) {
+       if (which < 0 || which >= 2) {
+               // More joypads that we currently handle (could happen if bad conf)
                return 0;
        }
 
        return joypads[which];
 }
 
+/** Get the current position of the host pointing device, usually a mouse,
+       used to emulated the SNES mouse.
+
+       @param buttons The buttons return value is a bit-wise mask of the two SNES
+               mouse buttons, bit 0 for button 1 (left) and bit 1 for button 2 (right).
+*/
 bool8 S9xReadMousePosition(int which1, int& x, int& y, uint32& buttons)
 {
        if (which1 != 0) return FALSE;
@@ -188,6 +206,9 @@ bool8 S9xReadSuperScopePosition(int& x, int& y, uint32& buttons)
        return TRUE;
 }
 
+/** Get and process system/input events.
+       @param block true to block, false to poll until the queue is empty.
+*/
 void S9xProcessEvents(bool block)
 {
        SDL_Event event;
@@ -209,36 +230,38 @@ void S9xInitInputDevices()
        mouse.enabled = false;
        mouse.pressed = false;
 
-       switch (Settings.ControllerOption) {
-               case SNES_JOYPAD:
-                       joypads[0] = 0x80000000UL;
-                       printf("Input: 1 joypad, keyboard only\n");
-                       break;
-               case SNES_MOUSE:
-                       joypads[0] = 0x80000000UL;
-                       mouse.enabled = true;
-                       printf("Input: 1 joypad + mouse\n");
-                       break;
-               case SNES_MOUSE_SWAPPED:
-                       printf("Input: mouse\n");
-                       mouse.enabled = true;
-                       break;
-               case SNES_SUPERSCOPE:
-                       joypads[0] = 0x80000000UL;
-                       mouse.enabled = true;
-                       printf("Input: 1 joypad + superscope\n");
-                       break;
-               default:
-                       printf("Input: unknown\n");
-                       break;
+       if (Config.joypad1Enabled) {
+               joypads[0] = 0x80000000UL;
+       }
+       if (Config.joypad2Enabled) {
+               joypads[1] = 0x80000000UL;
        }
 
+       // Pretty print some information
+       printf("Input: ");
+       if (Config.joypad1Enabled) {
+               printf("Player 1 (joypad)");
+               if (Config.joypad2Enabled) {
+                       printf("+ player 2 (joypad)");
+               }
+       } else if (Config.joypad2Enabled) {
+               printf("Player 2 (joypad)");
+       } else {
+               printf("Nothing");
+       }
+       printf("\n");
+
+       // TODO Non-awful mouse support, Superscope
+
        S9xInputScreenChanged();
 }
 
 void S9xDeinitInputDevices()
 {
-
+       joypads[0] = 0;
+       joypads[1] = 0;
+       mouse.enabled = false;
+       mouse.pressed = false;
 }
 
 void S9xInputScreenChanged()
index 39f68fe..afe0187 100644 (file)
@@ -252,7 +252,18 @@ bool8_32 S9xInitUpdate ()
        return TRUE;
 }
 
-/** Called after rendering a frame. */
+/** Called once a complete SNES screen has been rendered into the GFX.Screen
+       memory buffer.
+
+       Now is your chance to copy the SNES rendered screen to the
+       host computer's screen memory. The problem is that you have to cope with
+       different sized SNES rendered screens. Width is always 256, unless you're
+       supporting SNES hi-res. screen modes (Settings.SupportHiRes is TRUE), in
+       which case it can be 256 or 512. The height parameter can be either 224 or
+       239 if you're only supporting SNES lo-res. screen modes, or 224, 239, 448 or
+       478 if hi-res. SNES screen modes are being supported.
+ */
+// TODO Above.
 bool8_32 S9xDeinitUpdate (int width, int height, bool8_32 sixteenBit)
 {
        scaler->finish();
index 5218ebd..a4aba0b 100644 (file)
@@ -6,6 +6,7 @@
 #include <SDL.h>
 
 #if CONF_XSP
+#      include <SDL_syswm.h>
 #      include <X11/extensions/Xsp.h>
 #endif
 #if CONF_HD