From 691c9b2e1da2c72425131a43047b76bf35122553 Mon Sep 17 00:00:00 2001 From: stephena Date: Tue, 23 Feb 2010 14:49:12 +0000 Subject: [PATCH] Added support for the Sega Genesis gamepad controller. This controller uses the directional pad and button 'B' as a normal joystick, but can also use button 'C' as a second 2600 button (with the logic reversed). git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1950 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- src/debugger/DiStella.cxx | 2 +- src/emucore/Console.cxx | 9 +++ src/emucore/Control.cxx | 3 + src/emucore/Control.hxx | 2 +- src/emucore/Genesis.cxx | 70 +++++++++++++++++++ src/emucore/Genesis.hxx | 65 +++++++++++++++++ src/emucore/module.mk | 1 + src/gui/GameInfoDialog.cxx | 1 + .../stella_intel.xcodeproj/project.pbxproj | 8 +++ 9 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 src/emucore/Genesis.cxx create mode 100644 src/emucore/Genesis.hxx diff --git a/src/debugger/DiStella.cxx b/src/debugger/DiStella.cxx index 888686029..c589a4ca7 100644 --- a/src/debugger/DiStella.cxx +++ b/src/debugger/DiStella.cxx @@ -8,7 +8,7 @@ // SS SS tt ee ll ll aa aa // SSSS ttt eeeee llll llll aaaaa // -// Copyright (c) 1995-2010 by Bradford W. Mott and the Stella team +// Copyright (c) 1995-2010 wby Bradford W. Mott and the Stella team // // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx index f29e18ede..2ff2f2843 100644 --- a/src/emucore/Console.cxx +++ b/src/emucore/Console.cxx @@ -32,6 +32,7 @@ #include "Joystick.hxx" #include "Keyboard.hxx" #include "KidVid.hxx" +#include "Genesis.hxx" #include "M6502.hxx" #include "M6532.hxx" #include "Paddles.hxx" @@ -621,6 +622,10 @@ void Console::setControllers(const string& rommd5) myControllers[leftPort] = new TrackBall(Controller::Left, *myEvent, *mySystem, Controller::AmigaMouse); } + else if(left == "GENESIS") + { + myControllers[leftPort] = new Genesis(Controller::Left, *myEvent, *mySystem); + } else { myControllers[leftPort] = new Joystick(Controller::Left, *myEvent, *mySystem); @@ -677,6 +682,10 @@ void Console::setControllers(const string& rommd5) { myControllers[rightPort] = new KidVid(Controller::Right, *myEvent, *mySystem, rommd5); } + else if(right == "GENESIS") + { + myControllers[rightPort] = new Genesis(Controller::Right, *myEvent, *mySystem); + } else { myControllers[rightPort] = new Joystick(Controller::Right, *myEvent, *mySystem); diff --git a/src/emucore/Control.cxx b/src/emucore/Control.cxx index 9575f90f6..a4a41dc1a 100644 --- a/src/emucore/Control.cxx +++ b/src/emucore/Control.cxx @@ -73,6 +73,9 @@ Controller::Controller(Jack jack, const Event& event, const System& system, case KidVid: myName = "KidVid"; break; + case Genesis: + myName = "Genesis"; + break; } } diff --git a/src/emucore/Control.hxx b/src/emucore/Control.hxx index 5fce0719d..9fa092369 100644 --- a/src/emucore/Control.hxx +++ b/src/emucore/Control.hxx @@ -82,7 +82,7 @@ class Controller : public Serializable { BoosterGrip, Driving, Keyboard, Paddles, Joystick, TrackBall22, TrackBall80, AmigaMouse, AtariVox, SaveKey, - KidVid + KidVid, Genesis }; public: diff --git a/src/emucore/Genesis.cxx b/src/emucore/Genesis.cxx new file mode 100644 index 000000000..e6b9915be --- /dev/null +++ b/src/emucore/Genesis.cxx @@ -0,0 +1,70 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2010 by Bradford W. Mott and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +// +// $Id: Genesis.cxx 1921 2010-01-10 03:23:32Z stephena $ +//============================================================================ + +#include "Event.hxx" +#include "Genesis.hxx" + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Genesis::Genesis(Jack jack, const Event& event, const System& system) + : Controller(jack, event, system, Controller::Genesis) +{ + if(myJack == Left) + { + myUpEvent = Event::JoystickZeroUp; + myDownEvent = Event::JoystickZeroDown; + myLeftEvent = Event::JoystickZeroLeft; + myRightEvent = Event::JoystickZeroRight; + myFire1Event = Event::JoystickZeroFire1; + myFire2Event = Event::JoystickZeroFire2; + } + else + { + myUpEvent = Event::JoystickOneUp; + myDownEvent = Event::JoystickOneDown; + myLeftEvent = Event::JoystickOneLeft; + myRightEvent = Event::JoystickOneRight; + myFire1Event = Event::JoystickOneFire1; + myFire2Event = Event::JoystickOneFire2; + } + + // Analog pin 9 is not connected to this controller at all + // Analog pin 5 corresponds to button 'C' on the gamepad + myAnalogPinValue[Five] = myAnalogPinValue[Nine] = maximumResistance; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Genesis::~Genesis() +{ +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Genesis::update() +{ + // Digital events (from keyboard or joystick hats & buttons) + myDigitalPinState[One] = (myEvent.get(myUpEvent) == 0); + myDigitalPinState[Two] = (myEvent.get(myDownEvent) == 0); + myDigitalPinState[Three] = (myEvent.get(myLeftEvent) == 0); + myDigitalPinState[Four] = (myEvent.get(myRightEvent) == 0); + myDigitalPinState[Six] = (myEvent.get(myFire1Event) == 0); + + // The Genesis has one more button (C) that can be read by the 2600 + // However, it seems to work opposite to the BoosterGrip controller, + // in that the logic is inverted + myAnalogPinValue[Five] = (myEvent.get(myFire2Event) == 0) ? + minimumResistance : maximumResistance; +} diff --git a/src/emucore/Genesis.hxx b/src/emucore/Genesis.hxx new file mode 100644 index 000000000..623fd0f01 --- /dev/null +++ b/src/emucore/Genesis.hxx @@ -0,0 +1,65 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2010 by Bradford W. Mott and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +// +// $Id: Booster.hxx 1921 2010-01-10 03:23:32Z stephena $ +//============================================================================ + +#ifndef GENESIS_HXX +#define GENESIS_HXX + +#include "bspf.hxx" +#include "Control.hxx" +#include "Event.hxx" + +/** + The standard Sega Genesis controller works with the 2600 console for + joystick directions and some of the buttons. Button 'B' corresponds to + the normal fire button (joy0fire), while button 'C' is read through + INPT1 (analog pin 5), which is normally mapped to the BoosterGrip trigger. + + @author Stephen Anthony +*/ +class Genesis : public Controller +{ + public: + /** + Create a new Genesis gamepad plugged into the specified jack + + @param jack The jack the controller is plugged into + @param event The event object to use for events + @param system The system using this controller + */ + Genesis(Jack jack, const Event& event, const System& system); + + /** + Destructor + */ + virtual ~Genesis(); + + public: + /** + Update the entire digital and analog pin state according to the + events currently set. + */ + virtual void update(); + + private: + // Pre-compute the events we care about based on given port + // This will eliminate test for left or right port in update() + Event::Type myUpEvent, myDownEvent, myLeftEvent, myRightEvent, + myFire1Event, myFire2Event; +}; + +#endif diff --git a/src/emucore/module.mk b/src/emucore/module.mk index fcf53997c..01ab96649 100644 --- a/src/emucore/module.mk +++ b/src/emucore/module.mk @@ -38,6 +38,7 @@ MODULE_OBJS := \ src/emucore/EventHandler.o \ src/emucore/FrameBuffer.o \ src/emucore/FSNode.o \ + src/emucore/Genesis.o \ src/emucore/Joystick.o \ src/emucore/Keyboard.o \ src/emucore/KidVid.o \ diff --git a/src/gui/GameInfoDialog.cxx b/src/gui/GameInfoDialog.cxx index dc974a0b2..ef36f34ae 100644 --- a/src/gui/GameInfoDialog.cxx +++ b/src/gui/GameInfoDialog.cxx @@ -230,6 +230,7 @@ GameInfoDialog::GameInfoDialog( ctrls.push_back("AmigaMouse", "AMIGAMOUSE" ); ctrls.push_back("AtariVox", "ATARIVOX" ); ctrls.push_back("SaveKey", "SAVEKEY" ); + ctrls.push_back("Sega Genesis", "GENESIS" ); //FIXME ctrls.push_back("KidVid", "KIDVID" ); myP0Controller = new PopUpWidget(myTab, font, xpos+lwidth, ypos, pwidth, lineHeight, ctrls, "", 0, 0); diff --git a/src/macosx/stella_intel.xcodeproj/project.pbxproj b/src/macosx/stella_intel.xcodeproj/project.pbxproj index cf406f285..2749eb326 100644 --- a/src/macosx/stella_intel.xcodeproj/project.pbxproj +++ b/src/macosx/stella_intel.xcodeproj/project.pbxproj @@ -308,6 +308,8 @@ DCC527DB10B9DA6A005E1287 /* bspf.hxx in Headers */ = {isa = PBXBuildFile; fileRef = DCC527D810B9DA6A005E1287 /* bspf.hxx */; }; DCC527DC10B9DA6A005E1287 /* Snapshot.cxx in Sources */ = {isa = PBXBuildFile; fileRef = DCC527D910B9DA6A005E1287 /* Snapshot.cxx */; }; DCC527DD10B9DA6A005E1287 /* Snapshot.hxx in Headers */ = {isa = PBXBuildFile; fileRef = DCC527DA10B9DA6A005E1287 /* Snapshot.hxx */; }; + DCD3F7C511340AAF00DBA3AE /* Genesis.cxx in Sources */ = {isa = PBXBuildFile; fileRef = DCD3F7C311340AAF00DBA3AE /* Genesis.cxx */; }; + DCD3F7C611340AAF00DBA3AE /* Genesis.hxx in Headers */ = {isa = PBXBuildFile; fileRef = DCD3F7C411340AAF00DBA3AE /* Genesis.hxx */; }; DCD56D380B247D920092F9F8 /* Cart4A50.cxx in Sources */ = {isa = PBXBuildFile; fileRef = DCD56D360B247D920092F9F8 /* Cart4A50.cxx */; }; DCD56D390B247D920092F9F8 /* Cart4A50.hxx in Headers */ = {isa = PBXBuildFile; fileRef = DCD56D370B247D920092F9F8 /* Cart4A50.hxx */; }; DCD56D3C0B247DB40092F9F8 /* RectList.cxx in Sources */ = {isa = PBXBuildFile; fileRef = DCD56D3A0B247DB40092F9F8 /* RectList.cxx */; }; @@ -687,6 +689,8 @@ DCC527D810B9DA6A005E1287 /* bspf.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = bspf.hxx; path = ../common/bspf.hxx; sourceTree = SOURCE_ROOT; }; DCC527D910B9DA6A005E1287 /* Snapshot.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Snapshot.cxx; path = ../common/Snapshot.cxx; sourceTree = SOURCE_ROOT; }; DCC527DA10B9DA6A005E1287 /* Snapshot.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Snapshot.hxx; path = ../common/Snapshot.hxx; sourceTree = SOURCE_ROOT; }; + DCD3F7C311340AAF00DBA3AE /* Genesis.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Genesis.cxx; path = ../emucore/Genesis.cxx; sourceTree = SOURCE_ROOT; }; + DCD3F7C411340AAF00DBA3AE /* Genesis.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Genesis.hxx; path = ../emucore/Genesis.hxx; sourceTree = SOURCE_ROOT; }; DCD56D360B247D920092F9F8 /* Cart4A50.cxx */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = Cart4A50.cxx; path = ../emucore/Cart4A50.cxx; sourceTree = SOURCE_ROOT; }; DCD56D370B247D920092F9F8 /* Cart4A50.hxx */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; name = Cart4A50.hxx; path = ../emucore/Cart4A50.hxx; sourceTree = SOURCE_ROOT; }; DCD56D3A0B247DB40092F9F8 /* RectList.cxx */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = RectList.cxx; path = ../common/RectList.cxx; sourceTree = SOURCE_ROOT; }; @@ -917,6 +921,8 @@ 2D6050CC0898776500C6DE89 /* emucore */ = { isa = PBXGroup; children = ( + DCD3F7C311340AAF00DBA3AE /* Genesis.cxx */, + DCD3F7C411340AAF00DBA3AE /* Genesis.hxx */, DCC527C810B9DA19005E1287 /* Device.cxx */, DCC527C910B9DA19005E1287 /* Device.hxx */, DCC527CA10B9DA19005E1287 /* M6502.cxx */, @@ -1369,6 +1375,7 @@ DCC527DD10B9DA6A005E1287 /* Snapshot.hxx in Headers */, DC6B2BA511037FF200F199A7 /* CartDebug.hxx in Headers */, DC6B2BA711037FF200F199A7 /* DiStella.hxx in Headers */, + DCD3F7C611340AAF00DBA3AE /* Genesis.hxx in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1605,6 +1612,7 @@ DCC527DC10B9DA6A005E1287 /* Snapshot.cxx in Sources */, DC6B2BA411037FF200F199A7 /* CartDebug.cxx in Sources */, DC6B2BA611037FF200F199A7 /* DiStella.cxx in Sources */, + DCD3F7C511340AAF00DBA3AE /* Genesis.cxx in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };