From 7b9f8c922898f7f0e1df1bc625a040c997a3b836 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Mon, 8 Feb 2010 17:55:09 +0100 Subject: [PATCH] adding actual player 2 support --- platform/config.cpp | 4 +-- platform/osso.cpp | 13 ++++++++ platform/sdli.cpp | 77 ++++++++++++++++++++++++++++++---------------- platform/sdlv.cpp | 13 +++++++- platform/sdlvscalers.cpp | 1 + 5 files changed, 78 insertions(+), 30 deletions(-) diff --git a/platform/config.cpp b/platform/config.cpp index 08f5347..869dc7d 100644 --- a/platform/config.cpp +++ b/platform/config.cpp @@ -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; diff --git a/platform/osso.cpp b/platform/osso.cpp index 6eb9d93..010c11d 100644 --- a/platform/osso.cpp +++ b/platform/osso.cpp @@ -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, diff --git a/platform/sdli.cpp b/platform/sdli.cpp index e7dd266..82fefe1 100644 --- a/platform/sdli.cpp +++ b/platform/sdli.cpp @@ -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(mouse.x / GUI.ScaleX); + mouse.y = static_cast(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() diff --git a/platform/sdlv.cpp b/platform/sdlv.cpp index 39f68fe..afe0187 100644 --- a/platform/sdlv.cpp +++ b/platform/sdlv.cpp @@ -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(); diff --git a/platform/sdlvscalers.cpp b/platform/sdlvscalers.cpp index 5218ebd..a4aba0b 100644 --- a/platform/sdlvscalers.cpp +++ b/platform/sdlvscalers.cpp @@ -6,6 +6,7 @@ #include #if CONF_XSP +# include # include #endif #if CONF_HD -- 1.7.9.5