A slight restructuring of the Controller classes, to fix CompuMate

support broken in rev 3034.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@3038 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2014-11-04 00:34:56 +00:00
parent 03f760cceb
commit a48c4fc6a8
12 changed files with 138 additions and 140 deletions

View File

@ -26,8 +26,8 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MouseControl::MouseControl(Console& console, const string& mode) MouseControl::MouseControl(Console& console, const string& mode)
: myProps(console.properties()), : myProps(console.properties()),
myLeftController(console.controller(Controller::Left)), myLeftController(console.leftController()),
myRightController(console.controller(Controller::Right)), myRightController(console.rightController()),
myCurrentModeNum(0) myCurrentModeNum(0)
{ {
if(BSPF_equalsIgnoreCase(mode, "none")) if(BSPF_equalsIgnoreCase(mode, "none"))

View File

@ -200,7 +200,8 @@ uInt8 RiotDebug::tim1024T(int newVal)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Controller& RiotDebug::controller(Controller::Jack jack) const Controller& RiotDebug::controller(Controller::Jack jack) const
{ {
return myConsole.controller(jack); return jack == Controller::Left ? myConsole.leftController() :
myConsole.rightController();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -150,7 +150,7 @@ CartridgeCMWidget::CartridgeCMWidget(
void CartridgeCMWidget::saveOldState() void CartridgeCMWidget::saveOldState()
{ {
myOldState.swcha = myCart.mySWCHA; myOldState.swcha = myCart.mySWCHA;
myOldState.column = myCart.myColumn; myOldState.column = myCart.column();
myOldState.internalram.clear(); myOldState.internalram.clear();
@ -180,7 +180,7 @@ void CartridgeCMWidget::loadConfig()
mySWCHA->setState(newbits, changed); mySWCHA->setState(newbits, changed);
// Column // Column
myColumn->setList(0, myCart.myColumn, myCart.myColumn != myOldState.column); myColumn->setList(0, myCart.column(), myCart.column() != myOldState.column);
// Various bits from SWCHA and INPTx // Various bits from SWCHA and INPTx
myIncrease->setState(swcha & 0x40); myIncrease->setState(swcha & 0x40);

View File

@ -19,6 +19,7 @@
#include <cstring> #include <cstring>
#include "CompuMate.hxx"
#include "System.hxx" #include "System.hxx"
#include "M6532.hxx" #include "M6532.hxx"
#include "CartCM.hxx" #include "CartCM.hxx"
@ -90,14 +91,21 @@ bool CartridgeCM::poke(uInt16 address, uInt8 value)
{ {
mySWCHA = value; mySWCHA = value;
bank(mySWCHA & 0x3); bank(mySWCHA & 0x3);
if(value & 0x20) myColumn = 0; uInt8& column = myCompuMate->myColumn;
if(value & 0x40) myColumn = (myColumn + 1) % 10; if(value & 0x20) column = 0;
if(value & 0x40) column = (column + 1) % 10;
} }
mySystem->m6532().poke(address, value); mySystem->m6532().poke(address, value);
} }
return myBankChanged; return myBankChanged;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt8 CartridgeCM::column() const
{
return myCompuMate->myColumn;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool CartridgeCM::bank(uInt16 bank) bool CartridgeCM::bank(uInt16 bank)
{ {
@ -196,7 +204,7 @@ bool CartridgeCM::save(Serializer& out) const
out.putString(name()); out.putString(name());
out.putShort(myCurrentBank); out.putShort(myCurrentBank);
out.putByte(mySWCHA); out.putByte(mySWCHA);
out.putByte(myColumn); out.putByte(myCompuMate->myColumn);
out.putByteArray(myRAM, 2048); out.putByteArray(myRAM, 2048);
} }
catch(...) catch(...)
@ -218,7 +226,7 @@ bool CartridgeCM::load(Serializer& in)
myCurrentBank = in.getShort(); myCurrentBank = in.getShort();
mySWCHA = in.getByte(); mySWCHA = in.getByte();
myColumn = in.getByte(); myCompuMate->myColumn = in.getByte();
in.getByteArray(myRAM, 2048); in.getByteArray(myRAM, 2048);
} }
catch(...) catch(...)

View File

@ -20,6 +20,7 @@
#ifndef CARTRIDGECM_HXX #ifndef CARTRIDGECM_HXX
#define CARTRIDGECM_HXX #define CARTRIDGECM_HXX
class CompuMate;
class System; class System;
#include "bspf.hxx" #include "bspf.hxx"
@ -226,13 +227,21 @@ class CartridgeCM : public Cartridge
bool poke(uInt16 address, uInt8 value); bool poke(uInt16 address, uInt8 value);
/** /**
Get the current keybord column Inform the cartridge about the parent CompuMate controller
*/
void setCompuMate(CompuMate* cmate) { myCompuMate = cmate; }
/**
Get the current keyboard column
@return The column referenced by SWCHA D6 and D5 @return The column referenced by SWCHA D6 and D5
*/ */
uInt8 column() const { return myColumn; } uInt8 column() const;
private: private:
// The CompuMate device which interacts with this cartridge
CompuMate* myCompuMate;
// Indicates which bank is currently active // Indicates which bank is currently active
uInt16 myCurrentBank; uInt16 myCurrentBank;
@ -244,9 +253,6 @@ class CartridgeCM : public Cartridge
// Current copy of SWCHA (controls ROM/RAM accesses) // Current copy of SWCHA (controls ROM/RAM accesses)
uInt8 mySWCHA; uInt8 mySWCHA;
// Column currently active
uInt8 myColumn;
}; };
#endif #endif

View File

@ -18,21 +18,20 @@
//============================================================================ //============================================================================
#include "Control.hxx" #include "Control.hxx"
#include "System.hxx"
#include "StellaKeys.hxx" #include "StellaKeys.hxx"
#include "CompuMate.hxx" #include "CompuMate.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CompuMate::CompuMate(CartridgeCM& cart, const Event& event, CompuMate::CompuMate(const Console& console, const Event& event,
const System& system) const System& system)
: myCart(cart), : myConsole(console),
myEvent(event), myEvent(event),
mySystem(system), myLeftController(nullptr),
myLeftController(0), myRightController(nullptr)
myRightController(0),
myCycleAtLastUpdate(0)
{ {
myLeftController = new CMControl(*this, Controller::Left, event, system); // These controller pointers will be retrieved by the Console, which will
// also take ownership of them
myLeftController = new CMControl(*this, Controller::Left, event, system);
myRightController = new CMControl(*this, Controller::Right, event, system); myRightController = new CMControl(*this, Controller::Right, event, system);
myLeftController->myAnalogPinValue[Controller::Nine] = Controller::maximumResistance; myLeftController->myAnalogPinValue[Controller::Nine] = Controller::maximumResistance;
@ -58,19 +57,9 @@ void CompuMate::enableKeyHandling(bool enable)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CompuMate::update() void CompuMate::update()
{ {
uInt32 cycle = mySystem.cycles();
// Only perform update once for both ports in the same cycle
if(myCycleAtLastUpdate != cycle)
{
myCycleAtLastUpdate = cycle;
return;
}
myCycleAtLastUpdate = cycle;
// Handle SWCHA changes - the following comes almost directly from z26 // Handle SWCHA changes - the following comes almost directly from z26
Controller& lp = *myLeftController; Controller& lp = myConsole.leftController();
Controller& rp = *myRightController; Controller& rp = myConsole.rightController();
lp.myAnalogPinValue[Controller::Nine] = Controller::maximumResistance; lp.myAnalogPinValue[Controller::Nine] = Controller::maximumResistance;
lp.myAnalogPinValue[Controller::Five] = Controller::minimumResistance; lp.myAnalogPinValue[Controller::Five] = Controller::minimumResistance;
@ -86,7 +75,8 @@ void CompuMate::update()
rp.myDigitalPinState[Controller::Three] = true; rp.myDigitalPinState[Controller::Three] = true;
rp.myDigitalPinState[Controller::Four] = true; rp.myDigitalPinState[Controller::Four] = true;
switch(myCart.column())
switch(myColumn)
{ {
case 0: case 0:
if (myKeyTable[KBDK_7]) lp.myDigitalPinState[Controller::Six] = false; if (myKeyTable[KBDK_7]) lp.myDigitalPinState[Controller::Six] = false;

View File

@ -42,17 +42,19 @@
*/ */
class CompuMate class CompuMate
{ {
friend class CartridgeCM;
public: public:
/** /**
Create a new CompuMate handler for both left and right ports. Create a new CompuMate handler for both left and right ports.
Note that this class creates CMControl controllers for both ports, Note that this class creates CMControl controllers for both ports,
but does not take responsibility for their deletion. but does not take responsibility for their deletion.
@param cart The CompuMate cartridge @param console The console that owns the controller
@param event The event object to use for events @param event The event object to use for events
@param system The system using this controller @param system The system using this controller
*/ */
CompuMate(CartridgeCM& cart, const Event& event, const System& system); CompuMate(const Console& console, const Event& event, const System& system);
/** /**
Destructor Destructor
@ -105,8 +107,7 @@ class CompuMate
CMControl(class CompuMate& handler, Controller::Jack jack, const Event& event, CMControl(class CompuMate& handler, Controller::Jack jack, const Event& event,
const System& system) const System& system)
: Controller(jack, event, system, Controller::CompuMate), : Controller(jack, event, system, Controller::CompuMate),
myHandler(handler) myHandler(handler) { }
{ }
/** /**
Destructor Destructor
@ -116,10 +117,12 @@ class CompuMate
public: public:
/** /**
Called after *all* digital pins have been written on Port A. Called after *all* digital pins have been written on Port A.
Only update on the left controller; the right controller will
happen at the same cycle and is redundant.
@param value The entire contents of the SWCHA register @param value The entire contents of the SWCHA register
*/ */
void controlWrite(uInt8) { myHandler.update(); } void controlWrite(uInt8) { if(myJack == Controller::Left) myHandler.update(); }
/** /**
Update the entire digital and analog pin state according to the Update the entire digital and analog pin state according to the
@ -133,23 +136,21 @@ class CompuMate
private: private:
// Cart, Event and System objects // Cart, Event and System objects
CartridgeCM& myCart; const Console& myConsole;
const Event& myEvent; const Event& myEvent;
const System& mySystem;
// Left and right controllers // Left and right controllers
CMControl *myLeftController, *myRightController; CMControl *myLeftController, *myRightController;
// Column currently active
uInt8 myColumn;
// The keyboard state array (tells us the current state of the keyboard) // The keyboard state array (tells us the current state of the keyboard)
const bool* myKeyTable; const bool* myKeyTable;
// Array of keyboard key states when in the debugger (the normal keyboard // Array of keyboard key states when in the debugger (the normal keyboard
// keys are ignored in such a case) // keys are ignored in such a case)
bool myInternalKeyTable[KBDK_LAST]; bool myInternalKeyTable[KBDK_LAST];
// System cycle at which the update() method is called
// Multiple calls at the same cycle should be ignored
uInt32 myCycleAtLastUpdate;
}; };
#endif #endif

View File

@ -93,8 +93,8 @@ Console::Console(OSystem& osystem, Cartridge* cart, const Properties& props)
// For now, we just add dummy joystick controllers, since autodetection // For now, we just add dummy joystick controllers, since autodetection
// runs the emulation for a while, and this may interfere with 'smart' // runs the emulation for a while, and this may interfere with 'smart'
// controllers such as the AVox and SaveKey // controllers such as the AVox and SaveKey
myControllers[0] = new Joystick(Controller::Left, myEvent, *mySystem); myLeftControl = make_ptr<Joystick>(Controller::Left, myEvent, *mySystem);
myControllers[1] = new Joystick(Controller::Right, myEvent, *mySystem); myRightControl = make_ptr<Joystick>(Controller::Right, myEvent, *mySystem);
// We can only initialize after all the devices/components have been created // We can only initialize after all the devices/components have been created
mySystem->initialize(); mySystem->initialize();
@ -156,8 +156,8 @@ Console::Console(OSystem& osystem, Cartridge* cart, const Properties& props)
// Finally, add remaining info about the console // Finally, add remaining info about the console
myConsoleInfo.CartName = myProperties.get(Cartridge_Name); myConsoleInfo.CartName = myProperties.get(Cartridge_Name);
myConsoleInfo.CartMD5 = myProperties.get(Cartridge_MD5); myConsoleInfo.CartMD5 = myProperties.get(Cartridge_MD5);
myConsoleInfo.Control0 = myControllers[0]->about(); myConsoleInfo.Control0 = myLeftControl->about();
myConsoleInfo.Control1 = myControllers[1]->about(); myConsoleInfo.Control1 = myRightControl->about();
myConsoleInfo.BankSwitch = myCart->about(); myConsoleInfo.BankSwitch = myCart->about();
myCart->setRomName(myConsoleInfo.CartName); myCart->setRomName(myConsoleInfo.CartName);
@ -167,8 +167,6 @@ Console::Console(OSystem& osystem, Cartridge* cart, const Properties& props)
Console::~Console() Console::~Console()
{ {
delete myCMHandler; delete myCMHandler;
delete myControllers[0];
delete myControllers[1];
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -181,7 +179,7 @@ bool Console::save(Serializer& out) const
return false; return false;
// Now save the console controllers and switches // Now save the console controllers and switches
if(!(myControllers[0]->save(out) && myControllers[1]->save(out) && if(!(myLeftControl->save(out) && myRightControl->save(out) &&
mySwitches->save(out))) mySwitches->save(out)))
return false; return false;
} }
@ -204,7 +202,7 @@ bool Console::load(Serializer& in)
return false; return false;
// Then load the console controllers and switches // Then load the console controllers and switches
if(!(myControllers[0]->load(in) && myControllers[1]->load(in) && if(!(myLeftControl->load(in) && myRightControl->load(in) &&
mySwitches->load(in))) mySwitches->load(in)))
return false; return false;
} }
@ -583,9 +581,6 @@ void Console::setTIAProperties()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Console::setControllers(const string& rommd5) void Console::setControllers(const string& rommd5)
{ {
delete myControllers[0];
delete myControllers[1];
// Setup the controllers based on properties // Setup the controllers based on properties
const string& left = myProperties.get(Controller_Left); const string& left = myProperties.get(Controller_Left);
const string& right = myProperties.get(Controller_Right); const string& right = myProperties.get(Controller_Right);
@ -595,22 +590,21 @@ void Console::setControllers(const string& rommd5)
if(left == "COMPUMATE" || right == "COMPUMATE") if(left == "COMPUMATE" || right == "COMPUMATE")
{ {
delete myCMHandler; delete myCMHandler;
myCMHandler = new CompuMate(*((CartridgeCM*)&myCart), myEvent, *mySystem); myCMHandler = new CompuMate(*this, myEvent, *mySystem);
myControllers[0] = myCMHandler->leftController();
myControllers[1] = myCMHandler->rightController(); // A somewhat ugly bit of code that casts to CartridgeCM to
// add the CompuMate, and then back again for the actual
// Cartridge
unique_ptr<CartridgeCM> cartcm(static_cast<CartridgeCM*>(myCart.release()));
cartcm->setCompuMate(myCMHandler);
myCart = std::move(cartcm);
myLeftControl = unique_ptr<Controller>(myCMHandler->leftController());
myRightControl = unique_ptr<Controller>(myCMHandler->rightController());
return; return;
} }
// Swap the ports if necessary unique_ptr<Controller> leftC, rightC;
int leftPort, rightPort;
if(myProperties.get(Console_SwapPorts) == "NO")
{
leftPort = 0; rightPort = 1;
}
else
{
leftPort = 1; rightPort = 0;
}
// Also check if we should swap the paddles plugged into a jack // Also check if we should swap the paddles plugged into a jack
bool swapPaddles = myProperties.get(Controller_SwapPaddles) == "YES"; bool swapPaddles = myProperties.get(Controller_SwapPaddles) == "YES";
@ -618,15 +612,15 @@ void Console::setControllers(const string& rommd5)
// Construct left controller // Construct left controller
if(left == "BOOSTERGRIP") if(left == "BOOSTERGRIP")
{ {
myControllers[leftPort] = new BoosterGrip(Controller::Left, myEvent, *mySystem); leftC = make_ptr<BoosterGrip>(Controller::Left, myEvent, *mySystem);
} }
else if(left == "DRIVING") else if(left == "DRIVING")
{ {
myControllers[leftPort] = new Driving(Controller::Left, myEvent, *mySystem); leftC = make_ptr<Driving>(Controller::Left, myEvent, *mySystem);
} }
else if((left == "KEYBOARD") || (left == "KEYPAD")) else if((left == "KEYBOARD") || (left == "KEYPAD"))
{ {
myControllers[leftPort] = new Keyboard(Controller::Left, myEvent, *mySystem); leftC = make_ptr<Keyboard>(Controller::Left, myEvent, *mySystem);
} }
else if(BSPF_startsWithIgnoreCase(left, "PADDLES")) else if(BSPF_startsWithIgnoreCase(left, "PADDLES"))
{ {
@ -637,50 +631,49 @@ void Console::setControllers(const string& rommd5)
swapDir = true; swapDir = true;
else if(left == "PADDLES_IAXDR") else if(left == "PADDLES_IAXDR")
swapAxis = swapDir = true; swapAxis = swapDir = true;
myControllers[leftPort] = leftC = make_ptr<Paddles>(Controller::Left, myEvent, *mySystem,
new Paddles(Controller::Left, myEvent, *mySystem, swapPaddles, swapAxis, swapDir);
swapPaddles, swapAxis, swapDir);
} }
else if(left == "TRACKBALL22") else if(left == "TRACKBALL22")
{ {
myControllers[leftPort] = new TrackBall(Controller::Left, myEvent, *mySystem, leftC = make_ptr<TrackBall>(Controller::Left, myEvent, *mySystem,
Controller::TrackBall22); Controller::TrackBall22);
} }
else if(left == "TRACKBALL80") else if(left == "TRACKBALL80")
{ {
myControllers[leftPort] = new TrackBall(Controller::Left, myEvent, *mySystem, leftC = make_ptr<TrackBall>(Controller::Left, myEvent, *mySystem,
Controller::TrackBall80); Controller::TrackBall80);
} }
else if(left == "AMIGAMOUSE") else if(left == "AMIGAMOUSE")
{ {
myControllers[leftPort] = new TrackBall(Controller::Left, myEvent, *mySystem, leftC = make_ptr<TrackBall>(Controller::Left, myEvent, *mySystem,
Controller::AmigaMouse); Controller::AmigaMouse);
} }
else if(left == "GENESIS") else if(left == "GENESIS")
{ {
myControllers[leftPort] = new Genesis(Controller::Left, myEvent, *mySystem); leftC = make_ptr<Genesis>(Controller::Left, myEvent, *mySystem);
} }
else if(left == "MINDLINK") else if(left == "MINDLINK")
{ {
myControllers[leftPort] = new MindLink(Controller::Left, myEvent, *mySystem); leftC = make_ptr<MindLink>(Controller::Left, myEvent, *mySystem);
} }
else else
{ {
myControllers[leftPort] = new Joystick(Controller::Left, myEvent, *mySystem); leftC = make_ptr<Joystick>(Controller::Left, myEvent, *mySystem);
} }
// Construct right controller // Construct right controller
if(right == "BOOSTERGRIP") if(right == "BOOSTERGRIP")
{ {
myControllers[rightPort] = new BoosterGrip(Controller::Right, myEvent, *mySystem); rightC = make_ptr<BoosterGrip>(Controller::Right, myEvent, *mySystem);
} }
else if(right == "DRIVING") else if(right == "DRIVING")
{ {
myControllers[rightPort] = new Driving(Controller::Right, myEvent, *mySystem); rightC = make_ptr<Driving>(Controller::Right, myEvent, *mySystem);
} }
else if((right == "KEYBOARD") || (right == "KEYPAD")) else if((right == "KEYBOARD") || (right == "KEYPAD"))
{ {
myControllers[rightPort] = new Keyboard(Controller::Right, myEvent, *mySystem); rightC = make_ptr<Keyboard>(Controller::Right, myEvent, *mySystem);
} }
else if(BSPF_startsWithIgnoreCase(right, "PADDLES")) else if(BSPF_startsWithIgnoreCase(right, "PADDLES"))
{ {
@ -691,53 +684,64 @@ void Console::setControllers(const string& rommd5)
swapDir = true; swapDir = true;
else if(right == "PADDLES_IAXDR") else if(right == "PADDLES_IAXDR")
swapAxis = swapDir = true; swapAxis = swapDir = true;
myControllers[rightPort] = rightC = make_ptr<Paddles>(Controller::Right, myEvent, *mySystem,
new Paddles(Controller::Right, myEvent, *mySystem, swapPaddles, swapAxis, swapDir);
swapPaddles, swapAxis, swapDir);
} }
else if(right == "TRACKBALL22") else if(right == "TRACKBALL22")
{ {
myControllers[rightPort] = new TrackBall(Controller::Left, myEvent, *mySystem, rightC = make_ptr<TrackBall>(Controller::Left, myEvent, *mySystem,
Controller::TrackBall22); Controller::TrackBall22);
} }
else if(right == "TRACKBALL80") else if(right == "TRACKBALL80")
{ {
myControllers[rightPort] = new TrackBall(Controller::Left, myEvent, *mySystem, rightC = make_ptr<TrackBall>(Controller::Left, myEvent, *mySystem,
Controller::TrackBall80); Controller::TrackBall80);
} }
else if(right == "AMIGAMOUSE") else if(right == "AMIGAMOUSE")
{ {
myControllers[rightPort] = new TrackBall(Controller::Left, myEvent, *mySystem, rightC = make_ptr<TrackBall>(Controller::Left, myEvent, *mySystem,
Controller::AmigaMouse); Controller::AmigaMouse);
} }
else if(right == "ATARIVOX") else if(right == "ATARIVOX")
{ {
const string& nvramfile = myOSystem.nvramDir() + "atarivox_eeprom.dat"; const string& nvramfile = myOSystem.nvramDir() + "atarivox_eeprom.dat";
myControllers[rightPort] = new AtariVox(Controller::Right, myEvent, rightC = make_ptr<AtariVox>(Controller::Right, myEvent,
*mySystem, myOSystem.serialPort(), *mySystem, myOSystem.serialPort(),
myOSystem.settings().getString("avoxport"), nvramfile); myOSystem.settings().getString("avoxport"), nvramfile);
} }
else if(right == "SAVEKEY") else if(right == "SAVEKEY")
{ {
const string& nvramfile = myOSystem.nvramDir() + "savekey_eeprom.dat"; const string& nvramfile = myOSystem.nvramDir() + "savekey_eeprom.dat";
myControllers[rightPort] = new SaveKey(Controller::Right, myEvent, *mySystem, rightC = make_ptr<SaveKey>(Controller::Right, myEvent, *mySystem,
nvramfile); nvramfile);
} }
else if(right == "GENESIS") else if(right == "GENESIS")
{ {
myControllers[rightPort] = new Genesis(Controller::Right, myEvent, *mySystem); rightC = make_ptr<Genesis>(Controller::Right, myEvent, *mySystem);
} }
else if(right == "KIDVID") else if(right == "KIDVID")
{ {
myControllers[rightPort] = new KidVid(Controller::Right, myEvent, *mySystem, rommd5); rightC = make_ptr<KidVid>(Controller::Right, myEvent, *mySystem, rommd5);
} }
else if(right == "MINDLINK") else if(right == "MINDLINK")
{ {
myControllers[rightPort] = new MindLink(Controller::Right, myEvent, *mySystem); rightC = make_ptr<MindLink>(Controller::Right, myEvent, *mySystem);
} }
else else
{ {
myControllers[rightPort] = new Joystick(Controller::Right, myEvent, *mySystem); rightC = make_ptr<Joystick>(Controller::Right, myEvent, *mySystem);
}
// Swap the ports if necessary
if(myProperties.get(Console_SwapPorts) == "NO")
{
myLeftControl = std::move(leftC);
myRightControl = std::move(rightC);
}
else
{
myLeftControl = std::move(rightC);
myRightControl = std::move(leftC);
} }
} }

View File

@ -20,7 +20,6 @@
#ifndef CONSOLE_HXX #ifndef CONSOLE_HXX
#define CONSOLE_HXX #define CONSOLE_HXX
class Controller;
class Event; class Event;
class Switches; class Switches;
class System; class System;
@ -82,10 +81,8 @@ class Console : public Serializable
@return The specified controller @return The specified controller
*/ */
Controller& controller(Controller::Jack jack) const Controller& leftController() const { return *myLeftControl; }
{ Controller& rightController() const { return *myRightControl; }
return *myControllers[jack];
}
/** /**
Get the TIA for this console Get the TIA for this console
@ -129,14 +126,6 @@ class Console : public Serializable
*/ */
M6532& riot() const { return *myRiot; } M6532& riot() const { return *myRiot; }
/**
Get the CompuMate handler used by the console
(only valid for CompuMate ROMs)
@return The CompuMate handler for this console (if it exists), otherwise 0
*/
CompuMate* compumate() const { return myCMHandler; }
/** /**
Saves the current state of this console class to the given Serializer. Saves the current state of this console class to the given Serializer.
@ -357,7 +346,7 @@ class Console : public Serializable
unique_ptr<Switches> mySwitches; unique_ptr<Switches> mySwitches;
// Pointers to the left and right controllers // Pointers to the left and right controllers
Controller* myControllers[2]; unique_ptr<Controller> myLeftControl, myRightControl;
// Pointer to CompuMate handler (only used in CompuMate ROMs) // Pointer to CompuMate handler (only used in CompuMate ROMs)
CompuMate* myCMHandler; CompuMate* myCMHandler;

View File

@ -632,7 +632,7 @@ void EventHandler::handleJoyEvent(int stick, int button, uInt8 state)
// enum; subtracting four gives us Controller 0 and 1 // enum; subtracting four gives us Controller 0 and 1
if(myState == S_EMULATE) if(myState == S_EMULATE)
{ {
switch(myOSystem.console().controller(Controller::Left).type()) switch(myOSystem.console().leftController().type())
{ {
case Controller::Keyboard: case Controller::Keyboard:
if(button < 12) myEvent.set(SA_Key[joy->type-4][button], state); if(button < 12) myEvent.set(SA_Key[joy->type-4][button], state);
@ -640,7 +640,7 @@ void EventHandler::handleJoyEvent(int stick, int button, uInt8 state)
default: default:
if(button < 4) myEvent.set(SA_Button[joy->type-4][button], state); if(button < 4) myEvent.set(SA_Button[joy->type-4][button], state);
} }
switch(myOSystem.console().controller(Controller::Right).type()) switch(myOSystem.console().rightController().type())
{ {
case Controller::Keyboard: case Controller::Keyboard:
if(button < 12) myEvent.set(SA_Key[joy->type-4][button], state); if(button < 12) myEvent.set(SA_Key[joy->type-4][button], state);
@ -1783,7 +1783,7 @@ void EventHandler::setMouseControllerMode(const string& enable)
usemouse = false; usemouse = false;
else // 'analog' else // 'analog'
{ {
switch(myOSystem.console().controller(Controller::Left).type()) switch(myOSystem.console().leftController().type())
{ {
case Controller::Paddles: case Controller::Paddles:
case Controller::Driving: case Controller::Driving:
@ -1796,7 +1796,7 @@ void EventHandler::setMouseControllerMode(const string& enable)
default: default:
break; break;
} }
switch(myOSystem.console().controller(Controller::Right).type()) switch(myOSystem.console().rightController().type())
{ {
case Controller::Paddles: case Controller::Paddles:
case Controller::Driving: case Controller::Driving:
@ -1909,8 +1909,7 @@ void EventHandler::setEventState(State state)
myOverlay = NULL; myOverlay = NULL;
myOSystem.sound().mute(false); myOSystem.sound().mute(false);
enableTextEvents(false); enableTextEvents(false);
if(myOSystem.console().controller(Controller::Left).type() == if(myOSystem.console().leftController().type() == Controller::CompuMate)
Controller::CompuMate)
myUseCtrlKeyFlag = false; myUseCtrlKeyFlag = false;
break; break;

View File

@ -79,15 +79,15 @@ void M6532::systemCyclesReset()
myCyclesWhenTimerSet -= mySystem->cycles(); myCyclesWhenTimerSet -= mySystem->cycles();
// We should also inform any 'smart' controllers as well // We should also inform any 'smart' controllers as well
myConsole.controller(Controller::Left).systemCyclesReset(); myConsole.leftController().systemCyclesReset();
myConsole.controller(Controller::Right).systemCyclesReset(); myConsole.rightController().systemCyclesReset();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void M6532::update() void M6532::update()
{ {
Controller& port0 = myConsole.controller(Controller::Left); Controller& port0 = myConsole.leftController();
Controller& port1 = myConsole.controller(Controller::Right); Controller& port1 = myConsole.rightController();
// Get current PA7 state // Get current PA7 state
bool prevPA7 = port0.myDigitalPinState[Controller::Four]; bool prevPA7 = port0.myDigitalPinState[Controller::Four];
@ -143,8 +143,8 @@ uInt8 M6532::peek(uInt16 addr)
{ {
case 0x00: // SWCHA - Port A I/O Register (Joystick) case 0x00: // SWCHA - Port A I/O Register (Joystick)
{ {
uInt8 value = (myConsole.controller(Controller::Left).read() << 4) | uInt8 value = (myConsole.leftController().read() << 4) |
myConsole.controller(Controller::Right).read(); myConsole.rightController().read();
// Each pin is high (1) by default and will only go low (0) if either // Each pin is high (1) by default and will only go low (0) if either
// (a) External device drives the pin low // (a) External device drives the pin low
@ -311,8 +311,8 @@ void M6532::setPinState(bool swcha)
if(DDR bit is input) set output as 1 if(DDR bit is input) set output as 1
else if(DDR bit is output) set output as bit in ORA else if(DDR bit is output) set output as bit in ORA
*/ */
Controller& port0 = myConsole.controller(Controller::Left); Controller& port0 = myConsole.leftController();
Controller& port1 = myConsole.controller(Controller::Right); Controller& port1 = myConsole.rightController();
uInt8 ioport = myOutA | ~myDDRA; uInt8 ioport = myOutA | ~myDDRA;

View File

@ -1321,27 +1321,27 @@ uInt8 TIA::peek(uInt16 addr)
case INPT0: case INPT0:
value = (value & 0x7F) | value = (value & 0x7F) |
dumpedInputPort(myConsole.controller(Controller::Left).read(Controller::Nine)); dumpedInputPort(myConsole.leftController().read(Controller::Nine));
break; break;
case INPT1: case INPT1:
value = (value & 0x7F) | value = (value & 0x7F) |
dumpedInputPort(myConsole.controller(Controller::Left).read(Controller::Five)); dumpedInputPort(myConsole.leftController().read(Controller::Five));
break; break;
case INPT2: case INPT2:
value = (value & 0x7F) | value = (value & 0x7F) |
dumpedInputPort(myConsole.controller(Controller::Right).read(Controller::Nine)); dumpedInputPort(myConsole.rightController().read(Controller::Nine));
break; break;
case INPT3: case INPT3:
value = (value & 0x7F) | value = (value & 0x7F) |
dumpedInputPort(myConsole.controller(Controller::Right).read(Controller::Five)); dumpedInputPort(myConsole.rightController().read(Controller::Five));
break; break;
case INPT4: case INPT4:
{ {
uInt8 button = (myConsole.controller(Controller::Left).read(Controller::Six) ? 0x80 : 0x00); uInt8 button = (myConsole.leftController().read(Controller::Six) ? 0x80 : 0x00);
myINPT4 = (myVBLANK & 0x40) ? (myINPT4 & button) : button; myINPT4 = (myVBLANK & 0x40) ? (myINPT4 & button) : button;
value = (value & 0x7F) | myINPT4; value = (value & 0x7F) | myINPT4;
@ -1350,7 +1350,7 @@ uInt8 TIA::peek(uInt16 addr)
case INPT5: case INPT5:
{ {
uInt8 button = (myConsole.controller(Controller::Right).read(Controller::Six) ? 0x80 : 0x00); uInt8 button = (myConsole.rightController().read(Controller::Six) ? 0x80 : 0x00);
myINPT5 = (myVBLANK & 0x40) ? (myINPT5 & button) : button; myINPT5 = (myVBLANK & 0x40) ? (myINPT5 & button) : button;
value = (value & 0x7F) | myINPT5; value = (value & 0x7F) | myINPT5;