Separated the various trakball-compatible controllers into their

own class, preparing for further work on issue #70.

The 3 classes are now named more appropriately, as mentioned in
issue #70.
This commit is contained in:
Stephen Anthony 2017-02-11 21:07:42 -03:30
parent c80f72b367
commit 52d3bd9df3
14 changed files with 545 additions and 146 deletions

125
src/emucore/AmigaMouse.cxx Normal file
View File

@ -0,0 +1,125 @@
//============================================================================
//
// 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-2017 by Bradford W. Mott, Stephen Anthony
// 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.
//============================================================================
#include "Event.hxx"
#include "System.hxx"
#include "TIA.hxx"
#include "AmigaMouse.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AmigaMouse::AmigaMouse(Jack jack, const Event& event, const System& system)
: Controller(jack, event, system, Controller::AmigaMouse),
myHCounter(0),
myVCounter(0),
myMouseEnabled(false)
{
// This code in ::read() is set up to always return IOPortA values in
// the lower 4 bits data value
// As such, the jack type (left or right) isn't necessary here
myTrakBallCountH = myTrakBallCountV = 0;
myTrakBallLinesH = myTrakBallLinesV = 1;
myTrakBallLeft = myTrakBallDown = myScanCountV = myScanCountH =
myCountV = myCountH = 0;
// Analog pins are never used by the trakball controller
myAnalogPinValue[Five] = myAnalogPinValue[Nine] = maximumResistance;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt8 AmigaMouse::read()
{
int scanline = mySystem.tia().scanlines();
if(myScanCountV > scanline) myScanCountV = 0;
if(myScanCountH > scanline) myScanCountH = 0;
while((myScanCountV + myTrakBallLinesV) < scanline)
{
if(myTrakBallCountV)
{
if(myTrakBallDown) myCountV--;
else myCountV++;
myTrakBallCountV--;
}
myScanCountV += myTrakBallLinesV;
}
while((myScanCountH + myTrakBallLinesH) < scanline)
{
if(myTrakBallCountH)
{
if(myTrakBallLeft) myCountH--;
else myCountH++;
myTrakBallCountH--;
}
myScanCountH += myTrakBallLinesH;
}
myCountV &= 0x03;
myCountH &= 0x03;
static constexpr uInt32 ourTableH[4] = { 0x00, 0x10, 0x50, 0x40 };
static constexpr uInt32 ourTableV[4] = { 0x00, 0x80, 0xa0, 0x20 };
uInt8 IOPortA = ourTableV[myCountV] | ourTableH[myCountH];
myDigitalPinState[One] = IOPortA & 0x10;
myDigitalPinState[Two] = IOPortA & 0x20;
myDigitalPinState[Three] = IOPortA & 0x40;
myDigitalPinState[Four] = IOPortA & 0x80;
return (IOPortA >> 4);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void AmigaMouse::update()
{
if(!myMouseEnabled)
return;
// Get the current mouse position
myHCounter = myEvent.get(Event::MouseAxisXValue);
myVCounter = myEvent.get(Event::MouseAxisYValue);
if(myVCounter < 0) myTrakBallLeft = 1;
else myTrakBallLeft = 0;
if(myHCounter < 0) myTrakBallDown = 0;
else myTrakBallDown = 1;
myTrakBallCountH = abs(myVCounter >> 1);
myTrakBallCountV = abs(myHCounter >> 1);
myTrakBallLinesH = 200 /*LinesInFrame*/ / (myTrakBallCountH + 1);
if(myTrakBallLinesH == 0) myTrakBallLinesH = 1;
myTrakBallLinesV = 200 /*LinesInFrame*/ / (myTrakBallCountV + 1);
if(myTrakBallLinesV == 0) myTrakBallLinesV = 1;
// Get mouse button state
myDigitalPinState[Six] = (myEvent.get(Event::MouseButtonLeftValue) == 0) &&
(myEvent.get(Event::MouseButtonRightValue) == 0);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool AmigaMouse::setMouseControl(
Controller::Type xtype, int xid, Controller::Type ytype, int yid)
{
// Currently, the various trakball controllers take full control of the
// mouse, and use both mouse buttons for the single fire button
// As well, there's no separate setting for x and y axis, so any
// combination of Controller and id is valid
myMouseEnabled = (xtype == myType || ytype == myType) &&
(xid != -1 || yid != -1);
return true;
}

View File

@ -15,39 +15,31 @@
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================
#ifndef TRACKBALL_HXX
#define TRACKBALL_HXX
#ifndef AMIGAMOUSE_HXX
#define AMIGAMOUSE_HXX
#include "bspf.hxx"
#include "Control.hxx"
#include "Event.hxx"
/**
The various trackball-like controllers supported by the Atari 2600.
They're all placed in one class, since other than a few minor
differences, they work almost exactly the same. This code was
heavily borrowed from z26.
The supported controllers include:
TrackBall22: Atari 2600 CX-22 Trakball
TrackBall80: Atari ST CX-80 Trakball
AmigaMouse: Amiga Mouse
Trakball-like controller emulating the original Amiga mouse.
This code was heavily borrowed from z26.
@author Stephen Anthony & z26 team
*/
class TrackBall : public Controller
class AmigaMouse : public Controller
{
public:
/**
Create a new TrackBall controller plugged into the specified jack
Create a new Amiga Mouse controller 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
@param type The type of trackball controller
*/
TrackBall(Jack jack, const Event& event, const System& system, Type type);
virtual ~TrackBall() = default;
AmigaMouse(Jack jack, const Event& event, const System& system);
virtual ~AmigaMouse() = default;
public:
using Controller::read;
@ -106,25 +98,13 @@ class TrackBall : public Controller
// Whether to use the mouse to emulate this controller
int myMouseEnabled;
// CX-22
static const uInt32 ourTrakBallTableTB_H[2][2];
static const uInt32 ourTrakBallTableTB_V[2][2];
// ST mouse / CX-80
static const uInt32 ourTrakBallTableST_H[4];
static const uInt32 ourTrakBallTableST_V[4];
// Amiga mouse
static const uInt32 ourTrakBallTableAM_H[4];
static const uInt32 ourTrakBallTableAM_V[4];
private:
// Following constructors and assignment operators not supported
TrackBall() = delete;
TrackBall(const TrackBall&) = delete;
TrackBall(TrackBall&&) = delete;
TrackBall& operator=(const TrackBall&) = delete;
TrackBall& operator=(TrackBall&&) = delete;
AmigaMouse() = delete;
AmigaMouse(const AmigaMouse&) = delete;
AmigaMouse(AmigaMouse&&) = delete;
AmigaMouse& operator=(const AmigaMouse&) = delete;
AmigaMouse& operator=(AmigaMouse&&) = delete;
};
#endif

125
src/emucore/AtariMouse.cxx Normal file
View File

@ -0,0 +1,125 @@
//============================================================================
//
// 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-2017 by Bradford W. Mott, Stephen Anthony
// 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.
//============================================================================
#include "Event.hxx"
#include "System.hxx"
#include "TIA.hxx"
#include "AtariMouse.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AtariMouse::AtariMouse(Jack jack, const Event& event, const System& system)
: Controller(jack, event, system, Controller::AtariMouse),
myHCounter(0),
myVCounter(0),
myMouseEnabled(false)
{
// This code in ::read() is set up to always return IOPortA values in
// the lower 4 bits data value
// As such, the jack type (left or right) isn't necessary here
myTrakBallCountH = myTrakBallCountV = 0;
myTrakBallLinesH = myTrakBallLinesV = 1;
myTrakBallLeft = myTrakBallDown = myScanCountV = myScanCountH =
myCountV = myCountH = 0;
// Analog pins are never used by the Atari ST mouse controller
myAnalogPinValue[Five] = myAnalogPinValue[Nine] = maximumResistance;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt8 AtariMouse::read()
{
int scanline = mySystem.tia().scanlines();
if(myScanCountV > scanline) myScanCountV = 0;
if(myScanCountH > scanline) myScanCountH = 0;
while((myScanCountV + myTrakBallLinesV) < scanline)
{
if(myTrakBallCountV)
{
if(myTrakBallDown) myCountV--;
else myCountV++;
myTrakBallCountV--;
}
myScanCountV += myTrakBallLinesV;
}
while((myScanCountH + myTrakBallLinesH) < scanline)
{
if(myTrakBallCountH)
{
if(myTrakBallLeft) myCountH--;
else myCountH++;
myTrakBallCountH--;
}
myScanCountH += myTrakBallLinesH;
}
myCountV &= 0x03;
myCountH &= 0x03;
static constexpr uInt32 ourTableH[4] = { 0x00, 0x80, 0xc0, 0x40 };
static constexpr uInt32 ourTableV[4] = { 0x00, 0x10, 0x30, 0x20 };
uInt8 IOPortA = ourTableV[myCountV] | ourTableH[myCountH];
myDigitalPinState[One] = IOPortA & 0x10;
myDigitalPinState[Two] = IOPortA & 0x20;
myDigitalPinState[Three] = IOPortA & 0x40;
myDigitalPinState[Four] = IOPortA & 0x80;
return (IOPortA >> 4);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void AtariMouse::update()
{
if(!myMouseEnabled)
return;
// Get the current mouse position
myHCounter = myEvent.get(Event::MouseAxisXValue);
myVCounter = myEvent.get(Event::MouseAxisYValue);
if(myVCounter < 0) myTrakBallLeft = 1;
else myTrakBallLeft = 0;
if(myHCounter < 0) myTrakBallDown = 0;
else myTrakBallDown = 1;
myTrakBallCountH = abs(myVCounter >> 1);
myTrakBallCountV = abs(myHCounter >> 1);
myTrakBallLinesH = 200 /*LinesInFrame*/ / (myTrakBallCountH + 1);
if(myTrakBallLinesH == 0) myTrakBallLinesH = 1;
myTrakBallLinesV = 200 /*LinesInFrame*/ / (myTrakBallCountV + 1);
if(myTrakBallLinesV == 0) myTrakBallLinesV = 1;
// Get mouse button state
myDigitalPinState[Six] = (myEvent.get(Event::MouseButtonLeftValue) == 0) &&
(myEvent.get(Event::MouseButtonRightValue) == 0);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool AtariMouse::setMouseControl(
Controller::Type xtype, int xid, Controller::Type ytype, int yid)
{
// Currently, the various trakball controllers take full control of the
// mouse, and use both mouse buttons for the single fire button
// As well, there's no separate setting for x and y axis, so any
// combination of Controller and id is valid
myMouseEnabled = (xtype == myType || ytype == myType) &&
(xid != -1 || yid != -1);
return true;
}

110
src/emucore/AtariMouse.hxx Normal file
View File

@ -0,0 +1,110 @@
//============================================================================
//
// 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-2017 by Bradford W. Mott, Stephen Anthony
// 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.
//============================================================================
#ifndef ATARIMOUSE_HXX
#define ATARIMOUSE_HXX
#include "bspf.hxx"
#include "Control.hxx"
#include "Event.hxx"
/**
Trakball-like controller emulating the Atari ST mouse.
This code was heavily borrowed from z26.
@author Stephen Anthony & z26 team
*/
class AtariMouse : public Controller
{
public:
/**
Create a new AtariMouse controller 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
*/
AtariMouse(Jack jack, const Event& event, const System& system);
virtual ~AtariMouse() = default;
public:
using Controller::read;
/**
Read the entire state of all digital pins for this controller.
Note that this method must use the lower 4 bits, and zero the upper bits.
@return The state of all digital pins
*/
uInt8 read() override;
/**
Update the entire digital and analog pin state according to the
events currently set.
*/
void update() override;
/**
Determines how this controller will treat values received from the
X/Y axis and left/right buttons of the mouse. Since not all controllers
use the mouse the same way (or at all), it's up to the specific class to
decide how to use this data.
In the current implementation, the left button is tied to the X axis,
and the right one tied to the Y axis.
@param xtype The controller to use for x-axis data
@param xid The controller ID to use for x-axis data (-1 for no id)
@param ytype The controller to use for y-axis data
@param yid The controller ID to use for y-axis data (-1 for no id)
@return Whether the controller supports using the mouse
*/
bool setMouseControl(Controller::Type xtype, int xid,
Controller::Type ytype, int yid) override;
private:
// Counter to iterate through the gray codes
int myHCounter, myVCounter;
// How many new horizontal and vertical values this frame
int myTrakBallCountH, myTrakBallCountV;
// How many lines to wait before sending new horz and vert val
int myTrakBallLinesH, myTrakBallLinesV;
// Was TrakBall moved left or moved right instead
int myTrakBallLeft;
// Was TrakBall moved down or moved up instead
int myTrakBallDown;
int myScanCountH, myScanCountV, myCountH, myCountV;
// Whether to use the mouse to emulate this controller
int myMouseEnabled;
private:
// Following constructors and assignment operators not supported
AtariMouse() = delete;
AtariMouse(const AtariMouse&) = delete;
AtariMouse(AtariMouse&&) = delete;
AtariMouse& operator=(const AtariMouse&) = delete;
AtariMouse& operator=(AtariMouse&&) = delete;
};
#endif

View File

@ -46,7 +46,9 @@
#include "Sound.hxx"
#include "Switches.hxx"
#include "System.hxx"
#include "TrackBall.hxx"
#include "AmigaMouse.hxx"
#include "AtariMouse.hxx"
#include "TrakBall.hxx"
#include "FrameBuffer.hxx"
#include "OSystem.hxx"
#include "Menu.hxx"
@ -641,20 +643,17 @@ void Console::setControllers(const string& rommd5)
leftC = make_ptr<Paddles>(Controller::Left, myEvent, *mySystem,
swapPaddles, swapAxis, swapDir);
}
else if(left == "TRACKBALL22")
{
leftC = make_ptr<TrackBall>(Controller::Left, myEvent, *mySystem,
Controller::TrackBall22);
}
else if(left == "TRACKBALL80")
{
leftC = make_ptr<TrackBall>(Controller::Left, myEvent, *mySystem,
Controller::TrackBall80);
}
else if(left == "AMIGAMOUSE")
{
leftC = make_ptr<TrackBall>(Controller::Left, myEvent, *mySystem,
Controller::AmigaMouse);
leftC = make_ptr<AmigaMouse>(Controller::Left, myEvent, *mySystem);
}
else if(left == "ATARIMOUSE")
{
leftC = make_ptr<AtariMouse>(Controller::Left, myEvent, *mySystem);
}
else if(left == "TRAKBALL")
{
leftC = make_ptr<TrakBall>(Controller::Left, myEvent, *mySystem);
}
else if(left == "GENESIS")
{
@ -694,20 +693,17 @@ void Console::setControllers(const string& rommd5)
rightC = make_ptr<Paddles>(Controller::Right, myEvent, *mySystem,
swapPaddles, swapAxis, swapDir);
}
else if(right == "TRACKBALL22")
else if(left == "AMIGAMOUSE")
{
rightC = make_ptr<TrackBall>(Controller::Left, myEvent, *mySystem,
Controller::TrackBall22);
rightC = make_ptr<AmigaMouse>(Controller::Left, myEvent, *mySystem);
}
else if(right == "TRACKBALL80")
else if(left == "ATARIMOUSE")
{
rightC = make_ptr<TrackBall>(Controller::Left, myEvent, *mySystem,
Controller::TrackBall80);
rightC = make_ptr<AtariMouse>(Controller::Left, myEvent, *mySystem);
}
else if(right == "AMIGAMOUSE")
else if(left == "TRAKBALL")
{
rightC = make_ptr<TrackBall>(Controller::Left, myEvent, *mySystem,
Controller::AmigaMouse);
rightC = make_ptr<TrakBall>(Controller::Left, myEvent, *mySystem);
}
else if(right == "ATARIVOX")
{

View File

@ -54,15 +54,15 @@ Controller::Controller(Jack jack, const Event& event, const System& system,
case Keyboard:
myName = "Keyboard";
break;
case TrackBall22:
myName = "TrackBall22";
break;
case TrackBall80:
myName = "TrackBall80";
break;
case AmigaMouse:
myName = "AmigaMouse";
break;
case AtariMouse:
myName = "AtariMouse";
break;
case TrakBall:
myName = "TrakBall";
break;
case AtariVox:
myName = "AtariVox";
break;

View File

@ -88,7 +88,7 @@ class Controller : public Serializable
enum Type
{
BoosterGrip, Driving, Keyboard, Paddles, Joystick,
TrackBall22, TrackBall80, AmigaMouse, AtariVox, SaveKey,
AmigaMouse, AtariMouse, TrakBall, AtariVox, SaveKey,
KidVid, Genesis, MindLink, CompuMate
};

View File

@ -472,7 +472,7 @@ static const char* DefProps[DEF_PROPS_SIZE][21] = {
{ "2327456f86d7e0deda94758c518d05b3", "Digitel", "", "Mr. Postman (Digitel)", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" },
{ "2351d26d0bfdee3095bec9c05cbcf7b0", "", "", "Warring Worms (19-01-2002) (Billy Eno)", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" },
{ "235436ab0832370e73677c9c6f0c8b06", "", "", "Beast Invaders (Double Shot) (Hack)", "Hack of Space Invaders", "Hack", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" },
{ "2365e1534d67f94d8670394ab99150ce", "Thomas Jentzsch", "", "Missile Command (CX-80 Trackball) (2002) (TJ)", "Uses CX-80 Trackball Controller", "Homebrew", "", "", "", "", "", "", "TRACKBALL80", "", "", "", "", "", "", "YES", "" },
{ "2365e1534d67f94d8670394ab99150ce", "Thomas Jentzsch", "", "Missile Command (Atari Mouse) (2002) (TJ)", "Uses Atari ST Mouse Controller", "Homebrew", "", "", "", "", "", "", "ATARIMOUSE", "", "", "", "", "", "", "YES", "" },
{ "23d445ea19a18fb78d5035878d9fb649", "CBS Electronics, Sylvia Day, Henry Will IV", "4L1818, 4L1819, 4L1820, 4L1821", "Mouse Trap (1982) (CBS Electronics) (PAL)", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "YES", "" },
{ "23e4ca038aba11982e1694559f3be10f", "", "", "Big Dig (V3) (20-10-2002) (CT)", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" },
{ "23fad5a125bcd4463701c8ad8a0043a9", "CCE", "C-840", "Stone Age (1983) (CCE)", "Uses the Joystick Controllers (swapped)", "", "", "", "A", "A", "", "YES", "", "", "", "", "", "", "220", "YES", "" },
@ -1844,7 +1844,7 @@ static const char* DefProps[DEF_PROPS_SIZE][21] = {
{ "8bbfd951c89cc09c148bfabdefa08bec", "UA Limited", "", "Pleiades (1983) (UA Limited) (Prototype)", "", "Prototype", "", "", "", "", "", "", "", "", "", "", "", "32", "", "YES", "" },
{ "8bc0d2052b4f259e7a50a7c771b45241", "Xonox - K-Tel Software, Anthony R. Henderson", "99007, 6240", "Tomarc the Barbarian (1983) (Xonox) [a]", "AKA Thundarr the Barbarian", "", "", "", "", "", "", "", "", "", "", "", "", "24", "", "", "" },
{ "8bd8f65377023bdb7c5fcf46ddda5d31", "Activision, Bob Whitehead", "AG-019", "Sky Jinks (1982) (Activision) (4K)", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" },
{ "8bebac614571135933116045204f0f00", "Thomas Jentzsch", "", "Missile Command (CX-22 Trackball) (2002) (TJ) (PAL)", "Uses CX-22 Trackball Controller", "Homebrew", "", "", "", "", "", "", "TRACKBALL22", "", "", "", "", "", "", "YES", "" },
{ "8bebac614571135933116045204f0f00", "Thomas Jentzsch", "", "Missile Command (CX22 Trakball) (2002) (TJ) (PAL)", "Uses CX22 Trakball Controller", "Homebrew", "", "", "", "", "", "", "TRAKBALL", "", "", "", "", "", "", "YES", "" },
{ "8c103a79b007a2fd5af602334937b4e1", "Thomas Jentzsch", "", "Laser Base (Thomas Jentzsch)", "NTSC Conversion", "Homebrew", "", "", "", "", "", "", "", "", "", "", "", "", "240", "", "" },
{ "8c136e97c0a4af66da4a249561ed17db", "", "", "Poker Squares (V0.27) (2001) (B. Watson)", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" },
{ "8c2fa33048f055f38358d51eefe417db", "Home Vision - Gem International Corp.", "VCS83137", "Teddy Apple (1983) (Home Vision) (PAL)", "AKA Open Sesame", "", "", "", "", "", "", "", "", "", "", "", "", "42", "", "YES", "" },
@ -1855,7 +1855,7 @@ static const char* DefProps[DEF_PROPS_SIZE][21] = {
{ "8c941fa32c7718a10061d8c328909577", "Digivision", "", "River Raid (Digivision)", "", "", "", "", "", "", "", "", "", "", "", "", "", "33", "", "", "" },
{ "8ccaa442d26b09139685f5b22bf189c4", "Retroactive", "", "Qb (V1.01) (NTSC) (2001) (Retroactive)", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "YES", "" },
{ "8cd26dcf249456fe4aeb8db42d49df74", "Atari", "CX26139", "Crossbow (1987) (Atari)", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" },
{ "8ce9126066f2ddd5173e9f1f9ce1494e", "Thomas Jentzsch", "", "Missile Command (CX-22 Trackball) (2002) (TJ)", "Uses CX-22 Trackball Controller", "Homebrew", "", "", "", "", "", "", "TRACKBALL22", "", "", "", "", "", "", "YES", "" },
{ "8ce9126066f2ddd5173e9f1f9ce1494e", "Thomas Jentzsch", "", "Missile Command (CX22 Trakball) (2002) (TJ)", "Uses CX22 Trakball Controller", "Homebrew", "", "", "", "", "", "", "TRAKBALL", "", "", "", "", "", "", "YES", "" },
{ "8cf0d333bbe85b9549b1e6b1e2390b8d", "Atari, Brad Stewart", "CX2649, CX2649P", "Asteroids (1981) (Atari) (PAL)", "", "Common", "", "", "", "", "", "", "", "", "", "", "", "", "", "YES", "" },
{ "8d00a38f4c8f8800f1c237215ac243fc", "", "", "3-D Corridor (Green) (30-03-2003) (AD)", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" },
{ "8d1e2a6d2885966e6d86717180938f87", "Thomas Jentzsch", "", "Missile Command (Amiga Mouse) (2002) (TJ)", "Uses Amiga Mouse Controller", "Homebrew", "", "", "", "", "", "", "AMIGAMOUSE", "", "", "", "", "", "", "YES", "" },
@ -1969,7 +1969,7 @@ static const char* DefProps[DEF_PROPS_SIZE][21] = {
{ "969b968383d9f0e9d8ffd1056bcaef49", "Atari, Larry Kaplan", "CX2628, CX2628P", "Bowling (1979) (Atari) (PAL)", "", "Common", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" },
{ "96bcb3d97ce4ff7586326d183ac338a2", "", "", "Revenge of the Apes (Hack) [h2]", "Hack of Planet of the Apes", "Hack", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" },
{ "96e798995af6ed9d8601166d4350f276", "20th Century Fox Video Games - Videa, David Ross", "11029", "Meltdown (1983) (20th Century Fox) (Prototype)", "", "Prototype", "", "", "", "", "", "", "", "", "", "", "", "", "", "YES", "" },
{ "96eccc2277043508a6c481ea432d7dd9", "Thomas Jentzsch", "", "Missile Command (CX-80 Trackball) (2002) (TJ) (PAL)", "Uses CX-80 Trackball Controller", "Homebrew", "", "", "", "", "", "", "TRACKBALL80", "", "", "", "", "", "", "YES", "" },
{ "96eccc2277043508a6c481ea432d7dd9", "Thomas Jentzsch", "", "Missile Command (Atari Mouse) (2002) (TJ) (PAL)", "Uses Atari ST Mouse Controller", "Homebrew", "", "", "", "", "", "", "ATARIMOUSE", "", "", "", "", "", "", "YES", "" },
{ "96f806fc62005205d851e758d050dfca", "", "", "Push (V0.05) (2001) (AD)", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" },
{ "97184b263722748757cfdc41107ca5c0", "Parker Brothers", "PB5820", "Mr. Do!'s Castle (1984) (Parker Bros)", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "YES", "" },
{ "9718b85ac5a55cbc7348963c63ffa35a", "Robby", "", "Demon Attack (Robby)", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" },

View File

@ -1878,9 +1878,9 @@ bool EventHandler::controllerIsAnalog(Controller::Jack jack) const
{
case Controller::Paddles:
case Controller::Driving:
case Controller::TrackBall22:
case Controller::TrackBall80:
case Controller::AmigaMouse:
case Controller::AtariMouse:
case Controller::TrakBall:
case Controller::MindLink:
return true;
default:

View File

@ -20,12 +20,11 @@
#include "Event.hxx"
#include "System.hxx"
#include "TIA.hxx"
#include "TrackBall.hxx"
#include "TrakBall.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TrackBall::TrackBall(Jack jack, const Event& event, const System& system,
Type type)
: Controller(jack, event, system, type),
TrakBall::TrakBall(Jack jack, const Event& event, const System& system)
: Controller(jack, event, system, Controller::TrakBall),
myHCounter(0),
myVCounter(0),
myMouseEnabled(false)
@ -40,12 +39,12 @@ TrackBall::TrackBall(Jack jack, const Event& event, const System& system,
myTrakBallLeft = myTrakBallDown = myScanCountV = myScanCountH =
myCountV = myCountH = 0;
// Analog pins are never used by the trackball controller
// Analog pins are never used by the trakball controller
myAnalogPinValue[Five] = myAnalogPinValue[Nine] = maximumResistance;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt8 TrackBall::read()
uInt8 TrakBall::read()
{
int scanline = mySystem.tia().scanlines();
@ -76,27 +75,10 @@ uInt8 TrackBall::read()
myCountV &= 0x03;
myCountH &= 0x03;
uInt8 IOPortA = 0x00;
switch(myType)
{
case Controller::TrackBall80:
IOPortA = IOPortA
| ourTrakBallTableST_V[myCountV]
| ourTrakBallTableST_H[myCountH];
break;
case Controller::TrackBall22:
IOPortA = IOPortA
| ourTrakBallTableTB_V[myCountV & 0x01][myTrakBallDown]
| ourTrakBallTableTB_H[myCountH & 0x01][myTrakBallLeft];
break;
case Controller::AmigaMouse:
IOPortA = IOPortA
| ourTrakBallTableAM_V[myCountV]
| ourTrakBallTableAM_H[myCountH];
break;
default:
break;
}
static constexpr uInt32 ourTableH[2][2] = {{ 0x40, 0x00 }, { 0xc0, 0x80 }};
static constexpr uInt32 ourTableV[2][2] = {{ 0x00, 0x10 }, { 0x20, 0x30 }};
uInt8 IOPortA = ourTableV[myCountV & 0x01][myTrakBallDown] |
ourTableH[myCountH & 0x01][myTrakBallLeft];
myDigitalPinState[One] = IOPortA & 0x10;
myDigitalPinState[Two] = IOPortA & 0x20;
@ -107,7 +89,7 @@ uInt8 TrackBall::read()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void TrackBall::update()
void TrakBall::update()
{
if(!myMouseEnabled)
return;
@ -133,10 +115,10 @@ void TrackBall::update()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool TrackBall::setMouseControl(
bool TrakBall::setMouseControl(
Controller::Type xtype, int xid, Controller::Type ytype, int yid)
{
// Currently, the various trackball controllers take full control of the
// Currently, the various trakball controllers take full control of the
// mouse, and use both mouse buttons for the single fire button
// As well, there's no separate setting for x and y axis, so any
// combination of Controller and id is valid
@ -144,33 +126,3 @@ bool TrackBall::setMouseControl(
(xid != -1 || yid != -1);
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const uInt32 TrackBall::ourTrakBallTableTB_H[2][2] = {
{ 0x40, 0x00 }, { 0xc0, 0x80 }
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const uInt32 TrackBall::ourTrakBallTableTB_V[2][2] = {
{ 0x00, 0x10 }, { 0x20, 0x30 }
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const uInt32 TrackBall::ourTrakBallTableST_H[4] = {
0x00, 0x80, 0xc0, 0x40
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const uInt32 TrackBall::ourTrakBallTableST_V[4] = {
0x00, 0x10, 0x30, 0x20
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const uInt32 TrackBall::ourTrakBallTableAM_H[4] = {
0x00, 0x10, 0x50, 0x40
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const uInt32 TrackBall::ourTrakBallTableAM_V[4] = {
0x00, 0x80, 0xa0, 0x20
};

109
src/emucore/TrakBall.hxx Normal file
View File

@ -0,0 +1,109 @@
//============================================================================
//
// 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-2017 by Bradford W. Mott, Stephen Anthony
// 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.
//============================================================================
#ifndef CX_TRAKBALL_HXX
#define CX_TRAKBALL_HXX
#include "bspf.hxx"
#include "Control.hxx"
#include "Event.hxx"
/**
CS22/CX80 trakball controller. This code was heavily borrowed from z26.
@author Stephen Anthony & z26 team
*/
class TrakBall : public Controller
{
public:
/**
Create a new TrakBall controller 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
*/
TrakBall(Jack jack, const Event& event, const System& system);
virtual ~TrakBall() = default;
public:
using Controller::read;
/**
Read the entire state of all digital pins for this controller.
Note that this method must use the lower 4 bits, and zero the upper bits.
@return The state of all digital pins
*/
uInt8 read() override;
/**
Update the entire digital and analog pin state according to the
events currently set.
*/
void update() override;
/**
Determines how this controller will treat values received from the
X/Y axis and left/right buttons of the mouse. Since not all controllers
use the mouse the same way (or at all), it's up to the specific class to
decide how to use this data.
In the current implementation, the left button is tied to the X axis,
and the right one tied to the Y axis.
@param xtype The controller to use for x-axis data
@param xid The controller ID to use for x-axis data (-1 for no id)
@param ytype The controller to use for y-axis data
@param yid The controller ID to use for y-axis data (-1 for no id)
@return Whether the controller supports using the mouse
*/
bool setMouseControl(Controller::Type xtype, int xid,
Controller::Type ytype, int yid) override;
private:
// Counter to iterate through the gray codes
int myHCounter, myVCounter;
// How many new horizontal and vertical values this frame
int myTrakBallCountH, myTrakBallCountV;
// How many lines to wait before sending new horz and vert val
int myTrakBallLinesH, myTrakBallLinesV;
// Was TrakBall moved left or moved right instead
int myTrakBallLeft;
// Was TrakBall moved down or moved up instead
int myTrakBallDown;
int myScanCountH, myScanCountV, myCountH, myCountV;
// Whether to use the mouse to emulate this controller
int myMouseEnabled;
private:
// Following constructors and assignment operators not supported
TrakBall() = delete;
TrakBall(const TrakBall&) = delete;
TrakBall(TrakBall&&) = delete;
TrakBall& operator=(const TrakBall&) = delete;
TrakBall& operator=(TrakBall&&) = delete;
};
#endif

View File

@ -74,11 +74,13 @@ MODULE_OBJS := \
src/emucore/System.o \
src/emucore/TIASnd.o \
src/emucore/TIASurface.o \
src/emucore/TrackBall.o \
src/emucore/AmigaMouse.o \
src/emucore/AtariMouse.o \
src/emucore/TrakBall.o \
src/emucore/Thumbulator.o
MODULE_DIRS += \
src/emucore
# Include common rules
# Include common rules
include $(srcdir)/common.rules

View File

@ -2719,10 +2719,10 @@
"Cartridge.MD5" "2365e1534d67f94d8670394ab99150ce"
"Cartridge.Manufacturer" "Thomas Jentzsch"
"Cartridge.Name" "Missile Command (CX-80 Trackball) (2002) (TJ)"
"Cartridge.Note" "Uses CX-80 Trackball Controller"
"Cartridge.Name" "Missile Command (Atari Mouse) (2002) (TJ)"
"Cartridge.Note" "Uses Atari ST Mouse Controller"
"Cartridge.Rarity" "Homebrew"
"Controller.Left" "TRACKBALL80"
"Controller.Left" "ATARIMOUSE"
"Display.Phosphor" "YES"
""
@ -11188,10 +11188,10 @@
"Cartridge.MD5" "8bebac614571135933116045204f0f00"
"Cartridge.Manufacturer" "Thomas Jentzsch"
"Cartridge.Name" "Missile Command (CX-22 Trackball) (2002) (TJ) (PAL)"
"Cartridge.Note" "Uses CX-22 Trackball Controller"
"Cartridge.Name" "Missile Command (CX22 Trakball) (2002) (TJ) (PAL)"
"Cartridge.Note" "Uses CX22 Trakball Controller"
"Cartridge.Rarity" "Homebrew"
"Controller.Left" "TRACKBALL22"
"Controller.Left" "TRAKBALL"
"Display.Phosphor" "YES"
""
@ -11261,10 +11261,10 @@
"Cartridge.MD5" "8ce9126066f2ddd5173e9f1f9ce1494e"
"Cartridge.Manufacturer" "Thomas Jentzsch"
"Cartridge.Name" "Missile Command (CX-22 Trackball) (2002) (TJ)"
"Cartridge.Note" "Uses CX-22 Trackball Controller"
"Cartridge.Name" "Missile Command (CX22 Trakball) (2002) (TJ)"
"Cartridge.Note" "Uses CX22 Trakball Controller"
"Cartridge.Rarity" "Homebrew"
"Controller.Left" "TRACKBALL22"
"Controller.Left" "TRAKBALL"
"Display.Phosphor" "YES"
""
@ -11952,10 +11952,10 @@
"Cartridge.MD5" "96eccc2277043508a6c481ea432d7dd9"
"Cartridge.Manufacturer" "Thomas Jentzsch"
"Cartridge.Name" "Missile Command (CX-80 Trackball) (2002) (TJ) (PAL)"
"Cartridge.Note" "Uses CX-80 Trackball Controller"
"Cartridge.Name" "Missile Command (Atari Mouse) (2002) (TJ) (PAL)"
"Cartridge.Note" "Uses Atari ST Mouse Controller"
"Cartridge.Rarity" "Homebrew"
"Controller.Left" "TRACKBALL80"
"Controller.Left" "ATARIMOUSE"
"Display.Phosphor" "YES"
""

View File

@ -178,7 +178,7 @@ GameInfoDialog::GameInfoDialog(
xpos = 10; ypos = vBorder;
lwidth = font.getStringWidth("P0 Controller: ");
pwidth = font.getStringWidth("CX-22 Trakball");
pwidth = font.getStringWidth("CX22 Trakball");
new StaticTextWidget(myTab, font, xpos, ypos+1, lwidth, fontHeight,
"P0 Controller:", kTextAlignLeft);
ctrls.clear();
@ -190,9 +190,9 @@ GameInfoDialog::GameInfoDialog(
VarList::push_back(ctrls, "BoosterGrip", "BOOSTERGRIP" );
VarList::push_back(ctrls, "Driving", "DRIVING" );
VarList::push_back(ctrls, "Keyboard", "KEYBOARD" );
VarList::push_back(ctrls, "CX-22 Trakball", "TRACKBALL22" );
VarList::push_back(ctrls, "CX-80 Mouse", "TRACKBALL80" );
VarList::push_back(ctrls, "AmigaMouse", "AMIGAMOUSE" );
VarList::push_back(ctrls, "AtariMouse", "ATARIMOUSE" );
VarList::push_back(ctrls, "CX22 Trakball", "TRAKBALL" );
VarList::push_back(ctrls, "AtariVox", "ATARIVOX" );
VarList::push_back(ctrls, "SaveKey", "SAVEKEY" );
VarList::push_back(ctrls, "Sega Genesis", "GENESIS" );
@ -216,7 +216,7 @@ GameInfoDialog::GameInfoDialog(
wid.push_back(myLeftPort);
xpos = 10; ypos += lineHeight + 5;
pwidth = font.getStringWidth("CX-22 Trakball");
pwidth = font.getStringWidth("CX22 Trakball");
new StaticTextWidget(myTab, font, xpos, ypos+1, lwidth, fontHeight,
"P1 Controller:", kTextAlignLeft);
myP1Controller = new PopUpWidget(myTab, font, xpos+lwidth, ypos,