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,
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;
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:
}
}
+/** 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;
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;
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()
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();