From c64594959265e67f766446d374ad63bc34807169 Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Sat, 30 Sep 2017 11:14:13 +0800 Subject: [PATCH 1/3] Integrate standard pads(pads.c) into input.c --- src/input.c | 133 +++++++++++++++++++++++++++++++++++++++++---- src/input.h | 2 + src/input/pads.c | 138 ----------------------------------------------- 3 files changed, 126 insertions(+), 147 deletions(-) delete mode 100644 src/input/pads.c diff --git a/src/input.c b/src/input.c index b18d74f..9203359 100644 --- a/src/input.c +++ b/src/input.c @@ -18,24 +18,27 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + + /* merged pad.c 2017-9-30 */ + #include #include "fceu-types.h" #include "x6502.h" #include "fceu.h" +#include "state.h" + #include "input.h" #include "vsuni.h" #include "fds.h" -extern INPUTC *FCEU_InitJoyPad(int w); extern INPUTC *FCEU_InitZapper(int w); extern INPUTC *FCEU_InitMouse(int w); extern INPUTC *FCEU_InitPowerpadA(int w); extern INPUTC *FCEU_InitPowerpadB(int w); extern INPUTC *FCEU_InitArkanoid(int w); -extern INPUTCFC *FCEU_InitFami4(void); extern INPUTCFC *FCEU_InitArkanoidFC(void); extern INPUTCFC *FCEU_InitSpaceShadow(void); extern INPUTCFC *FCEU_InitFKB(void); @@ -50,19 +53,23 @@ extern INPUTCFC *FCEU_InitOekaKids(void); extern INPUTCFC *FCEU_InitTopRider(void); extern INPUTCFC *FCEU_InitBarcodeWorld(void); +static uint8 joy_readbit[2]; +static uint8 joy[4] = { 0, 0, 0, 0 }; +static uint8 LastStrobe; + extern uint8 coinon; -static void *InputDataPtr[2]; -uint8 LastStrobe; - +static int FSDisable = 0; /* Set to 1 if NES-style four-player adapter is disabled. */ static int JPAttrib[2] = { 0, 0 }; static int JPType[2] = { 0, 0 }; -static INPUTC DummyJPort = { 0, 0, 0, 0, 0 }; -static INPUTC *JPorts[2] = { &DummyJPort, &DummyJPort }; +static void *InputDataPtr[2]; static int JPAttribFC = 0; static int JPTypeFC = 0; static void *InputDataPtrFC; + +static INPUTC DummyJPort = { 0, 0, 0, 0, 0 }; +static INPUTC *JPorts[2] = { &DummyJPort, &DummyJPort }; static INPUTCFC *FCExp = 0; void (*InputScanlineHook)(uint8 *bg, uint8 *spr, uint32 linets, int final); @@ -110,6 +117,7 @@ static DECLFW(B4016) void FCEU_DrawInput(uint8 *buf) { int x; + for (x = 0; x < 2; x++) if (JPorts[x]->Draw) JPorts[x]->Draw(x, buf, JPAttrib[x]); @@ -118,6 +126,96 @@ void FCEU_DrawInput(uint8 *buf) FCExp->Draw(buf, JPAttribFC); } +/**********************************************************************/ +/* This function is a quick hack to get the NSF player to use emulated gamepad + input. +*/ +uint8 FCEU_GetJoyJoy(void) { + return(joy[0] | joy[1] | joy[2] | joy[3]); +} + +/* 4-player support for famicom expansion */ +static uint8 F4ReadBit[2]; + +static void StrobeFami4(void) { + F4ReadBit[0] = F4ReadBit[1] = 0; +} + +static uint8 FP_FASTAPASS(2) ReadFami4(int w, uint8 ret) { + ret &= 1; + ret |= ((joy[2 + w] >> (F4ReadBit[w])) & 1) << 1; + if (F4ReadBit[w] >= 8) ret |= 2; + else F4ReadBit[w]++; + return(ret); +} + +/* VS. Unisystem inputs */ +static uint8 FP_FASTAPASS(1) ReadGPVS(int w) { + uint8 ret = 0; + if (joy_readbit[w] >= 8) + ret = 1; + else { + ret = ((joy[w] >> (joy_readbit[w])) & 1); + #ifdef FCEUDEF_DEBUGGER + if (!fceuindbg) + #endif + joy_readbit[w]++; + } + return ret; +} + +/* standard gamepad inputs */ +static uint8 FP_FASTAPASS(1) ReadGP(int w) { + uint8 ret; + if (joy_readbit[w] >= 8) + ret = ((joy[2 + w] >> (joy_readbit[w] & 7)) & 1); + else + ret = ((joy[w] >> (joy_readbit[w])) & 1); + if (joy_readbit[w] >= 16) ret = 0; + if (FSDisable) { + if (joy_readbit[w] >= 8) + ret |= 1; + } else { + if (joy_readbit[w] == 19 - w) + ret |= 1; + } + #ifdef FCEUDEF_DEBUGGER + if (!fceuindbg) + #endif + joy_readbit[w]++; + return ret; +} + +static void FP_FASTAPASS(3) UpdateGP(int w, void *data, int arg) { + uint32 *ptr = (uint32*)data; + if (!w) { + joy[0] = *(uint32*)ptr; + joy[2] = *(uint32*)ptr >> 16; + } else { + joy[1] = *(uint32*)ptr >> 8; + joy[3] = *(uint32*)ptr >> 24; + } +#ifdef NETWORK + if (FCEUnetplay) NetplayUpdate(joy); +#endif + FCEUMOV_AddJoy(joy); +#ifdef __LIBRETRO__ +#else + if (GameInfo->type == GIT_VSUNI) /* moved to libretro.c */ + FCEU_VSUniSwap(&joy[0], &joy[1]); +#endif +} + +static void FP_FASTAPASS(1) StrobeGP(int w) { + joy_readbit[w] = 0; +} + +static INPUTC GPC = { ReadGP, 0, StrobeGP, UpdateGP, 0, 0 }; +static INPUTC GPCVS = { ReadGPVS, 0, StrobeGP, UpdateGP, 0, 0 }; +static INPUTCFC FAMI4C = { ReadFami4, 0, StrobeFami4, 0, 0, 0 }; + +/**********************************************************************/ + void FCEU_UpdateInput(void) { int x; @@ -189,7 +287,10 @@ static void FASTAPASS(1) SetInputStuff(int x) JPorts[x] = &DummyJPort; break; case SI_GAMEPAD: - JPorts[x] = FCEU_InitJoyPad(x); + if (GameInfo->type == GIT_VSUNI) + JPorts[x] = &GPCVS; + else + JPorts[x] = &GPC; break; case SI_ARKANOID: JPorts[x] = FCEU_InitArkanoid(x); @@ -227,7 +328,8 @@ static void SetInputStuffFC(void) FCExp = FCEU_InitOekaKids(); break; case SIFC_4PLAYER: - FCExp = FCEU_InitFami4(); + FCExp = &FAMI4C; + memset(&F4ReadBit, 0, sizeof(F4ReadBit)); break; case SIFC_FKB: FCExp = FCEU_InitFKB(); @@ -265,6 +367,8 @@ static void SetInputStuffFC(void) void InitializeInput(void) { + memset(joy_readbit,0,sizeof(joy_readbit)); + memset(joy,0,sizeof(joy)); LastStrobe = 0; if (GameInfo && GameInfo->type == GIT_VSUNI) @@ -298,6 +402,17 @@ void FCEUI_SetInputFC(int type, void *ptr, int attrib) SetInputStuffFC(); } +void FCEUI_DisableFourScore(int s) { + FSDisable = s; +} + +SFORMAT FCEUCTRL_STATEINFO[] = { + { joy_readbit, 2, "JYRB" }, + { joy, 4, "JOYS" }, + { &LastStrobe, 1, "LSTS" }, + { 0 } +}; + void FCEU_DoSimpleCommand(int cmd) { switch (cmd) diff --git a/src/input.h b/src/input.h index 0dcaa06..82061bc 100644 --- a/src/input.h +++ b/src/input.h @@ -19,6 +19,8 @@ typedef struct { void FP_FASTAPASS(2) (*Draw)(uint8 *buf, int arg); } INPUTCFC; +void FCEUMOV_AddJoy(uint8 *js); + void FCEU_DrawInput(uint8 *buf); void FCEU_UpdateInput(void); void InitializeInput(void); diff --git a/src/input/pads.c b/src/input/pads.c deleted file mode 100644 index 875323c..0000000 --- a/src/input/pads.c +++ /dev/null @@ -1,138 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2002 Xodnizel - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include "share.h" -#include "../vsuni.h" - -static uint8 joy_readbit[2]; -static uint8 joy[4] = { 0, 0, 0, 0 }; - -static int FSDisable = 0; /* Set to 1 if NES-style four-player adapter is disabled. */ -void FCEUI_DisableFourScore(int s) { - FSDisable = s; -} - -extern uint8 LastStrobe; - -SFORMAT FCEUCTRL_STATEINFO[] = { - { joy_readbit, 2, "JYRB" }, - { joy, 4, "JOYS" }, - { &LastStrobe, 1, "LSTS" }, - { 0 } -}; - -/* This function is a quick hack to get the NSF player to use emulated gamepad - input. -*/ -uint8 FCEU_GetJoyJoy(void) { - return(joy[0] | joy[1] | joy[2] | joy[3]); -} - -static void FP_FASTAPASS(1) StrobeGP(int w) { - joy_readbit[w] = 0; -} - -static uint8 FP_FASTAPASS(1) ReadGPVS(int w) { - uint8 ret = 0; - if (joy_readbit[w] >= 8) - ret = 1; - else { - ret = ((joy[w] >> (joy_readbit[w])) & 1); - #ifdef FCEUDEF_DEBUGGER - if (!fceuindbg) - #endif - joy_readbit[w]++; - } - return ret; -} - -static uint8 FP_FASTAPASS(1) ReadGP(int w) { - uint8 ret; - if (joy_readbit[w] >= 8) - ret = ((joy[2 + w] >> (joy_readbit[w] & 7)) & 1); - else - ret = ((joy[w] >> (joy_readbit[w])) & 1); - if (joy_readbit[w] >= 16) ret = 0; - if (FSDisable) { - if (joy_readbit[w] >= 8) - ret |= 1; - } else { - if (joy_readbit[w] == 19 - w) - ret |= 1; - } - #ifdef FCEUDEF_DEBUGGER - if (!fceuindbg) - #endif - joy_readbit[w]++; - return ret; -} - -static void FP_FASTAPASS(3) UpdateGP(int w, void *data, int arg) { - uint32 *ptr = (uint32*)data; - if (!w) { - joy[0] = *(uint32*)ptr; - joy[2] = *(uint32*)ptr >> 16; - } else { - joy[1] = *(uint32*)ptr >> 8; - joy[3] = *(uint32*)ptr >> 24; - } -#ifdef NETWORK - if (FCEUnetplay) NetplayUpdate(joy); -#endif - FCEUMOV_AddJoy(joy); -#ifdef __LIBRETRO__ -#else - if (GameInfo->type == GIT_VSUNI) /* moved to libretro.c */ - FCEU_VSUniSwap(&joy[0], &joy[1]); -#endif -} - -static INPUTC GPC = { ReadGP, 0, StrobeGP, UpdateGP, 0, 0 }; -static INPUTC GPCVS = { ReadGPVS, 0, StrobeGP, UpdateGP, 0, 0 }; - -INPUTC *FCEU_InitJoyPad(int w) { - joy_readbit[w] = 0; - joy[w] = 0; - joy[w + 2] = 0; - if (GameInfo->type == GIT_VSUNI) - return(&GPCVS); - else - return(&GPC); -} - -static uint8 F4ReadBit[2]; -static void StrobeFami4(void) { - F4ReadBit[0] = F4ReadBit[1] = 0; -} - -static uint8 FP_FASTAPASS(2) ReadFami4(int w, uint8 ret) { - ret &= 1; - ret |= ((joy[2 + w] >> (F4ReadBit[w])) & 1) << 1; - if (F4ReadBit[w] >= 8) ret |= 2; - else F4ReadBit[w]++; - return(ret); -} - -static INPUTCFC FAMI4C = { ReadFami4, 0, StrobeFami4, 0, 0, 0 }; -INPUTCFC *FCEU_InitFami4(int w) { - memset(&F4ReadBit, 0, sizeof(F4ReadBit)); - return(&FAMI4C); -} From c4c67b4b08940994fdfbcd081f7d62a6b6c239dc Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Sat, 30 Sep 2017 12:00:33 +0800 Subject: [PATCH 2/3] Proper fix for VS Unisystem input not working with some games. --- src/drivers/libretro/libretro.c | 3 --- src/input.c | 8 +++----- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index bc79651..d784522 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -1178,9 +1178,6 @@ static void FCEUD_UpdateInput(void) } } - if (GameInfo->type == GIT_VSUNI) - FCEU_VSUniSwap(&pad[0], &pad[1]); - JSReturn[0] = pad[0] | (pad[1] << 8) | (pad[2] << 16) | (pad[3] << 24); if (t[0] == RETRO_DEVICE_MOUSE || t[1] == RETRO_DEVICE_MOUSE) diff --git a/src/input.c b/src/input.c index 9203359..ca57ad5 100644 --- a/src/input.c +++ b/src/input.c @@ -199,11 +199,6 @@ static void FP_FASTAPASS(3) UpdateGP(int w, void *data, int arg) { if (FCEUnetplay) NetplayUpdate(joy); #endif FCEUMOV_AddJoy(joy); -#ifdef __LIBRETRO__ -#else - if (GameInfo->type == GIT_VSUNI) /* moved to libretro.c */ - FCEU_VSUniSwap(&joy[0], &joy[1]); -#endif } static void FP_FASTAPASS(1) StrobeGP(int w) { @@ -231,6 +226,9 @@ void FCEU_UpdateInput(void) if (GameInfo && GameInfo->type == GIT_VSUNI) if (coinon) coinon--; + + if (GameInfo->type == GIT_VSUNI) /* moved to libretro.c */ + FCEU_VSUniSwap(&joy[0], &joy[1]); } static DECLFR(VSUNIRead0) From e43a3374e118f5a15e8681c1d98f59d4844eff0d Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Sat, 30 Sep 2017 13:28:05 +0800 Subject: [PATCH 3/3] Update JSReturn --- src/drivers/libretro/libretro.c | 12 ++++++------ src/input.c | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index d784522..0c4e7d3 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -85,7 +85,7 @@ unsigned sndvolume = 150; static volatile int nofocus = 0; static int32_t *sound = 0; -static uint32_t JSReturn[4]; +static uint32_t JSReturn = 0; static uint32_t MouseData[3]; static uint32_t current_palette = 0; @@ -542,7 +542,7 @@ void retro_set_controller_port_device(unsigned port, unsigned device) { case RETRO_DEVICE_JOYPAD: t[port] = RETRO_DEVICE_JOYPAD; - FCEUI_SetInput(port, SI_GAMEPAD, &JSReturn[0], 0); + FCEUI_SetInput(port, SI_GAMEPAD, &JSReturn, 0); break; case RETRO_DEVICE_MOUSE: t[port] = RETRO_DEVICE_MOUSE; @@ -1178,7 +1178,7 @@ static void FCEUD_UpdateInput(void) } } - JSReturn[0] = pad[0] | (pad[1] << 8) | (pad[2] << 16) | (pad[3] << 24); + JSReturn = pad[0] | (pad[1] << 8) | (pad[2] << 16) | (pad[3] << 24); if (t[0] == RETRO_DEVICE_MOUSE || t[1] == RETRO_DEVICE_MOUSE) GetMouseData(&MouseData[0]); @@ -1737,8 +1737,8 @@ bool retro_load_game(const struct retro_game_info *game) return false; } - FCEUI_SetInput(0, SI_GAMEPAD, &JSReturn[0], 0); - FCEUI_SetInput(1, SI_GAMEPAD, &JSReturn[0], 0); + FCEUI_SetInput(0, SI_GAMEPAD, &JSReturn, 0); + FCEUI_SetInput(1, SI_GAMEPAD, &JSReturn, 0); external_palette_exist = ipalette; if (external_palette_exist) @@ -1769,7 +1769,7 @@ bool retro_load_game(const struct retro_game_info *game) { if (famicom_4p_db_list[i].crc == iNESGameCRC32) { - FCEUI_SetInputFC(SIFC_4PLAYER, &JSReturn[0], 0); + FCEUI_SetInputFC(SIFC_4PLAYER, &JSReturn, 0); break; } } diff --git a/src/input.c b/src/input.c index ca57ad5..ff01bd5 100644 --- a/src/input.c +++ b/src/input.c @@ -227,7 +227,7 @@ void FCEU_UpdateInput(void) if (GameInfo && GameInfo->type == GIT_VSUNI) if (coinon) coinon--; - if (GameInfo->type == GIT_VSUNI) /* moved to libretro.c */ + if (GameInfo->type == GIT_VSUNI) FCEU_VSUniSwap(&joy[0], &joy[1]); }