From 10abe43c0c9b0e32aa5919c7dd83ec587c32bee0 Mon Sep 17 00:00:00 2001 From: rainwarrior Date: Sat, 23 Apr 2016 04:58:30 +0000 Subject: [PATCH] Support for SNES mouse, added "Subor" to description of existing mouse --- trunk/attic/cmake-stuff/cmake/fceux.cmake | 1 + trunk/src/drivers/win/input.cpp | 4 + trunk/src/git.h | 8 +- trunk/src/input.cpp | 4 + trunk/src/input/snesmouse.cpp | 116 ++++++++++++++++++++++ trunk/vc/vc10_fceux.vcxproj | 1 + trunk/vc/vc10_fceux.vcxproj.filters | 3 + 7 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 trunk/src/input/snesmouse.cpp diff --git a/trunk/attic/cmake-stuff/cmake/fceux.cmake b/trunk/attic/cmake-stuff/cmake/fceux.cmake index 6d1a5191..3332183f 100644 --- a/trunk/attic/cmake-stuff/cmake/fceux.cmake +++ b/trunk/attic/cmake-stuff/cmake/fceux.cmake @@ -142,6 +142,7 @@ set(SRC_CORE ${CMAKE_SOURCE_DIR}/src/input/hypershot.cpp ${CMAKE_SOURCE_DIR}/src/input/mahjong.cpp ${CMAKE_SOURCE_DIR}/src/input/mouse.cpp + ${CMAKE_SOURCE_DIR}/src/input/snesmouse.cpp ${CMAKE_SOURCE_DIR}/src/input/oekakids.cpp ${CMAKE_SOURCE_DIR}/src/input/powerpad.cpp ${CMAKE_SOURCE_DIR}/src/input/quiz.cpp diff --git a/trunk/src/drivers/win/input.cpp b/trunk/src/drivers/win/input.cpp index d899db1e..93106d37 100644 --- a/trunk/src/drivers/win/input.cpp +++ b/trunk/src/drivers/win/input.cpp @@ -432,6 +432,7 @@ void FCEUD_UpdateInput() UpdateGamepad(true); break; case SI_MOUSE: mouse=true; break; + case SI_SNES_MOUSE: mouse=true; break; case SI_ARKANOID: mouse=true; break; case SI_ZAPPER: mouse=true; break; case SI_POWERPADA: @@ -519,6 +520,9 @@ void InitInputPorts(bool fourscore) case SI_MOUSE: InputDPtr=MouseData; break; + case SI_SNES_MOUSE: + InputDPtr=MouseData; + break; case SI_SNES: InputDPtr=snespad_return; break; diff --git a/trunk/src/git.h b/trunk/src/git.h index 82956e08..67accc14 100644 --- a/trunk/src/git.h +++ b/trunk/src/git.h @@ -37,8 +37,9 @@ enum ESI SI_ARKANOID = 5, SI_MOUSE = 6, SI_SNES = 7, + SI_SNES_MOUSE = 8, - SI_COUNT = SI_SNES + SI_COUNT = SI_SNES_MOUSE }; inline const char* ESI_Name(ESI esi) @@ -51,8 +52,9 @@ inline const char* ESI_Name(ESI esi) "Power Pad A", "Power Pad B", "Arkanoid Paddle", - "Mouse", - "SNES Pad" + "Subor Mouse", + "SNES Pad", + "SNES Mouse" }; if(esi >= SI_NONE && esi <= SI_COUNT) diff --git a/trunk/src/input.cpp b/trunk/src/input.cpp index 7dce2492..a5318fd9 100644 --- a/trunk/src/input.cpp +++ b/trunk/src/input.cpp @@ -63,6 +63,7 @@ extern INPUTC *FCEU_InitPowerpadA(int w); extern INPUTC *FCEU_InitPowerpadB(int w); extern INPUTC *FCEU_InitArkanoid(int w); extern INPUTC *FCEU_InitMouse(int w); +extern INPUTC *FCEU_InitSNESMouse(int w); extern INPUTCFC *FCEU_InitArkanoidFC(void); extern INPUTCFC *FCEU_InitSpaceShadow(void); @@ -474,6 +475,9 @@ static void SetInputStuff(int port) case SI_MOUSE: joyports[port].driver=FCEU_InitMouse(port); break; + case SI_SNES_MOUSE: + joyports[port].driver=FCEU_InitSNESMouse(port); + break; case SI_NONE: joyports[port].driver=&DummyJPort; break; diff --git a/trunk/src/input/snesmouse.cpp b/trunk/src/input/snesmouse.cpp new file mode 100644 index 00000000..4d13781e --- /dev/null +++ b/trunk/src/input/snesmouse.cpp @@ -0,0 +1,116 @@ +/* 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 +#include "share.h" + +typedef struct { + bool strobe; + uint32 latch; // latched data (read when strobe goes high to low) + uint32 sensitivity; // reading while strobe is high cycles sensitivity 0,1,2 + int32 mx, my; // current screen location + int32 lmx, lmy; // last latched location + uint32 mb; // current buttons +} SNES_MOUSE; + +static SNES_MOUSE SNESMouse; + +static uint8 ReadSNESMouse(int w) +{ + if (SNESMouse.strobe) + { + SNESMouse.sensitivity += 1; + if (SNESMouse.sensitivity > 2) SNESMouse.sensitivity = 0; + } + + uint8 result = (SNESMouse.latch & 0x80000000) >> 31; + SNESMouse.latch = (SNESMouse.latch << 1); + + return result; +} + +static void WriteSNESMouse(uint8 v) +{ + bool strobing = v & 1; + + if (SNESMouse.strobe && !strobing) + { + int dx = SNESMouse.mx - SNESMouse.lmx; + int dy = SNESMouse.my - SNESMouse.lmy; + + SNESMouse.lmx = SNESMouse.mx; + SNESMouse.lmy = SNESMouse.my; + + // convert to sign and magnitude + bool sx = (dx < 0); + bool sy = (dy < 0); + if (dx < 0) dx = -dx; + if (dy < 0) dy = -dy; + + // apply sensitivity + dx += dx >> (2 - SNESMouse.sensitivity); + dx += dx >> (2 - SNESMouse.sensitivity); + + // clamp + if (dx > 127) dx = 127; + if (dy > 127) dy = 127; + + //FCEU_printf("SNES Mouse: %1d %3d, %1d %3d %1d x%1d\n",sx,dx,sy,dy,SNESMouse.mb,SNESMouse.sensitivity); + + uint8 byte0 = 0x00; + uint8 byte1 = + 0x1 | // signature + ((SNESMouse.sensitivity & 3) << 4) | // sensitivity + ((SNESMouse.mb & 3) << 6); // buttons + uint8 byte2 = uint8(dy) | (sy ? 0x80 : 0x00); + uint8 byte3 = uint8(dx) | (sx ? 0x80 : 0x00); + + SNESMouse.latch = (byte0 << 24) | (byte1 << 16) | (byte2 << 8) | (byte3 << 0); + } + + SNESMouse.strobe = strobing; +} + +static void UpdateSNESMouse(int w, void *data, int arg) +{ + uint32 *ptr=(uint32*)data; + SNESMouse.mx = ptr[0]; // screen position + SNESMouse.my = ptr[1]; + SNESMouse.mb = ptr[2] & 3; // bit 0 = left button, bit 1 = right button +} + +static INPUTC SNES_MOUSEC = +{ + ReadSNESMouse, // Read + WriteSNESMouse, // Write + 0, // Strobe (handled by Write) + UpdateSNESMouse, // Update + 0, // SLHook + 0, // Draw + 0, // Log + 0, // Load +}; + +INPUTC *FCEU_InitSNESMouse(int w) +{ + memset(&SNESMouse,0,sizeof(SNESMouse)); + return(&SNES_MOUSEC); +} diff --git a/trunk/vc/vc10_fceux.vcxproj b/trunk/vc/vc10_fceux.vcxproj index d22d7594..fa5d97ae 100644 --- a/trunk/vc/vc10_fceux.vcxproj +++ b/trunk/vc/vc10_fceux.vcxproj @@ -540,6 +540,7 @@ + diff --git a/trunk/vc/vc10_fceux.vcxproj.filters b/trunk/vc/vc10_fceux.vcxproj.filters index 3f5187f0..fbc592e5 100644 --- a/trunk/vc/vc10_fceux.vcxproj.filters +++ b/trunk/vc/vc10_fceux.vcxproj.filters @@ -520,6 +520,9 @@ input + + input + input