From 3171bddeaed934a89a1d30f6db1873edf6a8ac01 Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Sat, 16 Sep 2017 16:24:59 +0800 Subject: [PATCH] Zapper update --- src/drivers/libretro/libretro.c | 76 ++++++++++++++++----------------- 1 file changed, 37 insertions(+), 39 deletions(-) diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index 29fbf75..a1066a7 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -50,6 +50,7 @@ static bool use_par; int turbo_enabler; int turbo_delay; static int regionoverride = -1; +static int t[2] = {0.0}; /* emulator-specific variables */ @@ -535,14 +536,16 @@ void retro_set_controller_port_device(unsigned port, unsigned device) { if (port < 2) /* port #0 = player1/player3, port #1 = player2/player4 */ { - switch(device) - { - case RETRO_DEVICE_JOYPAD: - FCEUI_SetInput(port, SI_GAMEPAD, &JSReturn[0], 0); - break; - case RETRO_DEVICE_MOUSE: - FCEUI_SetInput(port, SI_ZAPPER, &MouseData[0], 1); - break; + switch(device) + { + case RETRO_DEVICE_JOYPAD: + t[port] = RETRO_DEVICE_JOYPAD; + FCEUI_SetInput(port, SI_GAMEPAD, &JSReturn[0], 0); + break; + case RETRO_DEVICE_MOUSE: + t[port] = RETRO_DEVICE_MOUSE; + FCEUI_SetInput(port, SI_ZAPPER, &MouseData[0], 1); + break; } } } @@ -570,7 +573,7 @@ void retro_set_environment(retro_environment_t cb) }; static const struct retro_controller_description pads[] = { - { "NES Gamepad", RETRO_DEVICE_JOYPAD }, + { "Gamepad", RETRO_DEVICE_JOYPAD }, { "Zapper", RETRO_DEVICE_MOUSE }, }; @@ -1020,47 +1023,41 @@ static void check_variables(bool startup) } } -static int mouse_x, mouse_y, mzx, mzy; +static int mzx = 0, mzy = 0, mzb = 0; + void GetMouseData(uint32_t *zapdata) { - static int right, bottom, adjx, adjy, offscreen, port; + int right, bottom, port, adjx, adjy; + +#ifdef PSP + adjx = adjy = use_overscan ? 8 : 0; +#else + adjx = overscan_h ? 8 : 0; + adjy = overscan_v ? 8 : 0; +#endif + port = (GameInfo->type == GIT_VSUNI) ? 0 : 1; right = 256; bottom = 240; - offscreen = 0; -#ifdef PSP - adjx = adjy = use_overscan ? 8:0; -#else - adjx = overscan_h ? 8:0; - adjy = overscan_v ? 8:0; -#endif - - if (GameInfo->input[0] != SI_ZAPPER && GameInfo->input[1] != SI_ZAPPER) - return; - - port = (GameInfo->type == GIT_VSUNI) ? 1 : 0; + mzb = 0; /* TODO: Add some sort of mouse sensitivity */ - mouse_x = input_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X); - mouse_y = input_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y); - - mzx += mouse_x; - mzy += mouse_y; + mzx += input_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X); + mzy += input_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y); /* Set crosshair within the limits of game's resolution */ - if (mzx > right - adjx + offscreen) - mzx = right - adjx + offscreen; - else if (mzx <= 1 + adjx) - mzx = 1 + adjx; + if (mzx > right - adjx) mzx = right - adjx; + else if (mzx < 1 + adjx) mzx = 1 + adjx; + if (mzy > bottom - adjy) mzy = bottom - adjy; + else if (mzy < 1 + adjy) mzy = 1 + adjy; - if (mzy > bottom - adjy + offscreen) - mzy = bottom - adjy + offscreen; - else if (mzy <= 1 + adjy) - mzy = 1 + adjy; + if (input_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT)) + mzb |= 0x1; + if (input_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT)) + mzb |= 0x2; zapdata[0] = mzx; zapdata[1] = mzy; - zapdata[2] = input_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT) ? 1 : 0 - | input_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT) ? 2 : 0; + zapdata[2] = mzb; } /* @@ -1154,7 +1151,8 @@ static void FCEUD_UpdateInput(void) JSReturn[0] = pad[0] | (pad[1] << 8) | (pad[2] << 16) | (pad[3] << 24); - GetMouseData(&MouseData[0]); + if (t[0] == RETRO_DEVICE_MOUSE || t[1] == RETRO_DEVICE_MOUSE) + GetMouseData(&MouseData[0]); if (input_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2)) FCEU_VSUniCoin(); /* Insert Coin VS System */