Fixes for previous commit; remove indirection and inherit directly from ControllerLowLevel.

This commit is contained in:
Stephen Anthony 2019-03-29 21:07:20 -02:30
parent cfe79ec0b1
commit e6e337cd02
11 changed files with 55 additions and 61 deletions

View File

@ -29,7 +29,7 @@ AtariVoxWidget::AtariVoxWidget(GuiObject* boss, const GUI::Font& font,
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void AtariVoxWidget::eraseCurrent() void AtariVoxWidget::eraseCurrent()
{ {
AtariVox& avox = static_cast<AtariVox&>(myController->base()); AtariVox& avox = static_cast<AtariVox&>(controller());
avox.eraseCurrent(); avox.eraseCurrent();
} }
@ -37,7 +37,7 @@ void AtariVoxWidget::eraseCurrent()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool AtariVoxWidget::isPageUsed(uInt32 page) bool AtariVoxWidget::isPageUsed(uInt32 page)
{ {
AtariVox& avox = static_cast<AtariVox&>(myController->base()); AtariVox& avox = static_cast<AtariVox&>(controller());
return avox.isPageUsed(page); return avox.isPageUsed(page);
} }

View File

@ -78,16 +78,16 @@ BoosterWidget::BoosterWidget(GuiObject* boss, const GUI::Font& font,
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void BoosterWidget::loadConfig() void BoosterWidget::loadConfig()
{ {
myPins[kJUp]->setState(!myController->getPin(ourPinNo[kJUp])); myPins[kJUp]->setState(!getPin(ourPinNo[kJUp]));
myPins[kJDown]->setState(!myController->getPin(ourPinNo[kJDown])); myPins[kJDown]->setState(!getPin(ourPinNo[kJDown]));
myPins[kJLeft]->setState(!myController->getPin(ourPinNo[kJLeft])); myPins[kJLeft]->setState(!getPin(ourPinNo[kJLeft]));
myPins[kJRight]->setState(!myController->getPin(ourPinNo[kJRight])); myPins[kJRight]->setState(!getPin(ourPinNo[kJRight]));
myPins[kJFire]->setState(!myController->getPin(ourPinNo[kJFire])); myPins[kJFire]->setState(!getPin(ourPinNo[kJFire]));
myPins[kJBooster]->setState( myPins[kJBooster]->setState(
myController->getPin(Controller::AnalogPin::Five) == Controller::MIN_RESISTANCE); getPin(Controller::AnalogPin::Five) == Controller::MIN_RESISTANCE);
myPins[kJTrigger]->setState( myPins[kJTrigger]->setState(
myController->getPin(Controller::AnalogPin::Nine) == Controller::MIN_RESISTANCE); getPin(Controller::AnalogPin::Nine) == Controller::MIN_RESISTANCE);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -103,15 +103,15 @@ void BoosterWidget::handleCommand(
case kJLeft: case kJLeft:
case kJRight: case kJRight:
case kJFire: case kJFire:
myController->setPin(ourPinNo[id], !myPins[id]->getState()); setPin(ourPinNo[id], !myPins[id]->getState());
break; break;
case kJBooster: case kJBooster:
myController->setPin(Controller::AnalogPin::Five, setPin(Controller::AnalogPin::Five,
myPins[id]->getState() ? Controller::MIN_RESISTANCE : myPins[id]->getState() ? Controller::MIN_RESISTANCE :
Controller::MAX_RESISTANCE); Controller::MAX_RESISTANCE);
break; break;
case kJTrigger: case kJTrigger:
myController->setPin(Controller::AnalogPin::Nine, setPin(Controller::AnalogPin::Nine,
myPins[id]->getState() ? Controller::MIN_RESISTANCE : myPins[id]->getState() ? Controller::MIN_RESISTANCE :
Controller::MAX_RESISTANCE); Controller::MAX_RESISTANCE);
break; break;

View File

@ -27,38 +27,32 @@ class ButtonWidget;
#include "Command.hxx" #include "Command.hxx"
#include "ControlLowLevel.hxx" #include "ControlLowLevel.hxx"
class ControllerWidget : public Widget, public CommandSender, public ControllerLowLevel
class ControllerWidget : public Widget, public CommandSender
{ {
public: public:
ControllerWidget(GuiObject* boss, const GUI::Font& font, int x, int y, ControllerWidget(GuiObject* boss, const GUI::Font& font, int x, int y,
Controller& controller) Controller& controller)
: Widget(boss, font, x, y, 16, 16), : Widget(boss, font, x, y, 16, 16),
CommandSender(boss), CommandSender(boss),
myController(make_unique<ControllerLowLevel>(controller)) ControllerLowLevel(controller)
{ {
_w = 18 * font.getMaxCharWidth(); _w = 18 * font.getMaxCharWidth();
_h = 8 * font.getLineHeight(); _h = 8 * font.getLineHeight();
} }
virtual ~ControllerWidget() = default; virtual ~ControllerWidget() = default;
virtual void loadConfig() override { } virtual void loadConfig() override { }
protected:
unique_ptr<ControllerLowLevel> myController;
protected: protected:
bool isLeftPort() bool isLeftPort()
{ {
bool swappedPorts = instance().console().properties().get(Console_SwapPorts) == "YES"; bool swappedPorts = instance().console().properties().get(Console_SwapPorts) == "YES";
return (controller().jack() == Controller::Jack::Left) ^ swappedPorts;
return (myController->base().jack() == Controller::Jack::Left) ^ swappedPorts;
} }
string getHeader() string getHeader()
{ {
return (isLeftPort() ? "Left (" : "Right (") + myController->base().name() + ")"; return (isLeftPort() ? "Left (" : "Right (") + controller().name() + ")";
} }
private: private:

View File

@ -60,8 +60,8 @@ DrivingWidget::DrivingWidget(GuiObject* boss, const GUI::Font& font,
void DrivingWidget::loadConfig() void DrivingWidget::loadConfig()
{ {
uInt8 gray = 0; uInt8 gray = 0;
if(myController->getPin(Controller::DigitalPin::One)) gray += 1; if(getPin(Controller::DigitalPin::One)) gray += 1;
if(myController->getPin(Controller::DigitalPin::Two)) gray += 2; if(getPin(Controller::DigitalPin::Two)) gray += 2;
for(myGrayIndex = 0; myGrayIndex < 4; ++myGrayIndex) for(myGrayIndex = 0; myGrayIndex < 4; ++myGrayIndex)
{ {
@ -72,7 +72,7 @@ void DrivingWidget::loadConfig()
} }
} }
myFire->setState(!myController->getPin(Controller::DigitalPin::Six)); myFire->setState(!getPin(Controller::DigitalPin::Six));
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -83,18 +83,18 @@ void DrivingWidget::handleCommand(
{ {
case kGrayUpCmd: case kGrayUpCmd:
myGrayIndex = (myGrayIndex + 1) % 4; myGrayIndex = (myGrayIndex + 1) % 4;
myController->setPin(Controller::DigitalPin::One, (ourGrayTable[myGrayIndex] & 0x1) != 0); setPin(Controller::DigitalPin::One, (ourGrayTable[myGrayIndex] & 0x1) != 0);
myController->setPin(Controller::DigitalPin::Two, (ourGrayTable[myGrayIndex] & 0x2) != 0); setPin(Controller::DigitalPin::Two, (ourGrayTable[myGrayIndex] & 0x2) != 0);
setValue(myGrayIndex); setValue(myGrayIndex);
break; break;
case kGrayDownCmd: case kGrayDownCmd:
myGrayIndex = myGrayIndex == 0 ? 3 : myGrayIndex - 1; myGrayIndex = myGrayIndex == 0 ? 3 : myGrayIndex - 1;
myController->setPin(Controller::DigitalPin::One, (ourGrayTable[myGrayIndex] & 0x1) != 0); setPin(Controller::DigitalPin::One, (ourGrayTable[myGrayIndex] & 0x1) != 0);
myController->setPin(Controller::DigitalPin::Two, (ourGrayTable[myGrayIndex] & 0x2) != 0); setPin(Controller::DigitalPin::Two, (ourGrayTable[myGrayIndex] & 0x2) != 0);
setValue(myGrayIndex); setValue(myGrayIndex);
break; break;
case kFireCmd: case kFireCmd:
myController->setPin(Controller::DigitalPin::Six, !myFire->getState()); setPin(Controller::DigitalPin::Six, !myFire->getState());
break; break;
} }
} }

View File

@ -72,14 +72,14 @@ GenesisWidget::GenesisWidget(GuiObject* boss, const GUI::Font& font,
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void GenesisWidget::loadConfig() void GenesisWidget::loadConfig()
{ {
myPins[kJUp]->setState(!myController->getPin(ourPinNo[kJUp])); myPins[kJUp]->setState(!getPin(ourPinNo[kJUp]));
myPins[kJDown]->setState(!myController->getPin(ourPinNo[kJDown])); myPins[kJDown]->setState(!getPin(ourPinNo[kJDown]));
myPins[kJLeft]->setState(!myController->getPin(ourPinNo[kJLeft])); myPins[kJLeft]->setState(!getPin(ourPinNo[kJLeft]));
myPins[kJRight]->setState(!myController->getPin(ourPinNo[kJRight])); myPins[kJRight]->setState(!getPin(ourPinNo[kJRight]));
myPins[kJBbtn]->setState(!myController->getPin(ourPinNo[kJBbtn])); myPins[kJBbtn]->setState(!getPin(ourPinNo[kJBbtn]));
myPins[kJCbtn]->setState( myPins[kJCbtn]->setState(
myController->getPin(Controller::AnalogPin::Five) == Controller::MAX_RESISTANCE); getPin(Controller::AnalogPin::Five) == Controller::MAX_RESISTANCE);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -95,10 +95,10 @@ void GenesisWidget::handleCommand(
case kJLeft: case kJLeft:
case kJRight: case kJRight:
case kJBbtn: case kJBbtn:
myController->setPin(ourPinNo[id], !myPins[id]->getState()); setPin(ourPinNo[id], !myPins[id]->getState());
break; break;
case kJCbtn: case kJCbtn:
myController->setPin(Controller::AnalogPin::Five, setPin(Controller::AnalogPin::Five,
myPins[id]->getState() ? Controller::MAX_RESISTANCE : myPins[id]->getState() ? Controller::MAX_RESISTANCE :
Controller::MIN_RESISTANCE); Controller::MIN_RESISTANCE);
break; break;

View File

@ -65,11 +65,11 @@ JoystickWidget::JoystickWidget(GuiObject* boss, const GUI::Font& font,
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void JoystickWidget::loadConfig() void JoystickWidget::loadConfig()
{ {
myPins[kJUp]->setState(!myController->getPin(ourPinNo[kJUp])); myPins[kJUp]->setState(!getPin(ourPinNo[kJUp]));
myPins[kJDown]->setState(!myController->getPin(ourPinNo[kJDown])); myPins[kJDown]->setState(!getPin(ourPinNo[kJDown]));
myPins[kJLeft]->setState(!myController->getPin(ourPinNo[kJLeft])); myPins[kJLeft]->setState(!getPin(ourPinNo[kJLeft]));
myPins[kJRight]->setState(!myController->getPin(ourPinNo[kJRight])); myPins[kJRight]->setState(!getPin(ourPinNo[kJRight]));
myPins[kJFire]->setState(!myController->getPin(ourPinNo[kJFire])); myPins[kJFire]->setState(!getPin(ourPinNo[kJFire]));
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -77,7 +77,7 @@ void JoystickWidget::handleCommand(
CommandSender* sender, int cmd, int data, int id) CommandSender* sender, int cmd, int data, int id)
{ {
if(cmd == CheckboxWidget::kCheckActionCmd) if(cmd == CheckboxWidget::kCheckActionCmd)
myController->setPin(ourPinNo[id], !myPins[id]->getState()); setPin(ourPinNo[id], !myPins[id]->getState());
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -68,11 +68,11 @@ PaddleWidget::PaddleWidget(GuiObject* boss, const GUI::Font& font,
void PaddleWidget::loadConfig() void PaddleWidget::loadConfig()
{ {
myP0Resistance->setValue(Int32(Paddles::MAX_RESISTANCE - myP0Resistance->setValue(Int32(Paddles::MAX_RESISTANCE -
myController->getPin(Controller::AnalogPin::Nine))); getPin(Controller::AnalogPin::Nine)));
myP1Resistance->setValue(Int32(Paddles::MAX_RESISTANCE - myP1Resistance->setValue(Int32(Paddles::MAX_RESISTANCE -
myController->getPin(Controller::AnalogPin::Five))); getPin(Controller::AnalogPin::Five)));
myP0Fire->setState(!myController->getPin(Controller::DigitalPin::Four)); myP0Fire->setState(!getPin(Controller::DigitalPin::Four));
myP1Fire->setState(!myController->getPin(Controller::DigitalPin::Three)); myP1Fire->setState(!getPin(Controller::DigitalPin::Three));
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -82,18 +82,18 @@ void PaddleWidget::handleCommand(
switch(cmd) switch(cmd)
{ {
case kP0Changed: case kP0Changed:
myController->setPin(Controller::AnalogPin::Nine, setPin(Controller::AnalogPin::Nine,
Int32(Paddles::MAX_RESISTANCE - myP0Resistance->getValue())); Int32(Paddles::MAX_RESISTANCE - myP0Resistance->getValue()));
break; break;
case kP1Changed: case kP1Changed:
myController->setPin(Controller::AnalogPin::Five, setPin(Controller::AnalogPin::Five,
Int32(Paddles::MAX_RESISTANCE - myP1Resistance->getValue())); Int32(Paddles::MAX_RESISTANCE - myP1Resistance->getValue()));
break; break;
case kP0Fire: case kP0Fire:
myController->setPin(Controller::DigitalPin::Four, !myP0Fire->getState()); setPin(Controller::DigitalPin::Four, !myP0Fire->getState());
break; break;
case kP1Fire: case kP1Fire:
myController->setPin(Controller::DigitalPin::Three, !myP1Fire->getState()); setPin(Controller::DigitalPin::Three, !myP1Fire->getState());
break; break;
} }
} }

View File

@ -75,7 +75,7 @@ void PointingDeviceWidget::loadConfig()
{ {
setGrayCodeH(); setGrayCodeH();
setGrayCodeV(); setGrayCodeV();
myFire->setState(!myController->getPin(Controller::DigitalPin::Six)); myFire->setState(!getPin(Controller::DigitalPin::Six));
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -83,7 +83,7 @@ void PointingDeviceWidget::handleCommand(CommandSender* sender, int cmd, int dat
{ {
// since the PointingDevice uses its own, internal state (not reading the controller), // since the PointingDevice uses its own, internal state (not reading the controller),
// we have to communicate directly with it // we have to communicate directly with it
PointingDevice& pDev = static_cast<PointingDevice&>(myController->base()); PointingDevice& pDev = static_cast<PointingDevice&>(controller());
switch(cmd) switch(cmd)
{ {
@ -108,7 +108,7 @@ void PointingDeviceWidget::handleCommand(CommandSender* sender, int cmd, int dat
setGrayCodeV(); setGrayCodeV();
break; break;
case kTBFire: case kTBFire:
myController->setPin(Controller::DigitalPin::Six, !myFire->getState()); setPin(Controller::DigitalPin::Six, !myFire->getState());
break; break;
} }
} }
@ -116,7 +116,7 @@ void PointingDeviceWidget::handleCommand(CommandSender* sender, int cmd, int dat
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PointingDeviceWidget::setGrayCodeH() void PointingDeviceWidget::setGrayCodeH()
{ {
PointingDevice& pDev = static_cast<PointingDevice&>(myController->base()); PointingDevice& pDev = static_cast<PointingDevice&>(controller());
pDev.myCountH &= 0b11; pDev.myCountH &= 0b11;
setValue(myGrayValueH, pDev.myCountH, pDev.myTrackBallLeft); setValue(myGrayValueH, pDev.myCountH, pDev.myTrackBallLeft);
@ -125,7 +125,7 @@ void PointingDeviceWidget::setGrayCodeH()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PointingDeviceWidget::setGrayCodeV() void PointingDeviceWidget::setGrayCodeV()
{ {
PointingDevice& pDev = static_cast<PointingDevice&>(myController->base()); PointingDevice& pDev = static_cast<PointingDevice&>(controller());
pDev.myCountV &= 0b11; pDev.myCountV &= 0b11;
setValue(myGrayValueV, pDev.myCountV, !pDev.myTrackBallDown); setValue(myGrayValueV, pDev.myCountV, !pDev.myTrackBallDown);

View File

@ -29,7 +29,7 @@ SaveKeyWidget::SaveKeyWidget(GuiObject* boss, const GUI::Font& font,
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SaveKeyWidget::eraseCurrent() void SaveKeyWidget::eraseCurrent()
{ {
SaveKey& skey = static_cast<SaveKey&>(myController->base()); SaveKey& skey = static_cast<SaveKey&>(controller());
skey.eraseCurrent(); skey.eraseCurrent();
} }
@ -37,7 +37,7 @@ void SaveKeyWidget::eraseCurrent()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool SaveKeyWidget::isPageUsed(uInt32 page) bool SaveKeyWidget::isPageUsed(uInt32 page)
{ {
SaveKey& skey = static_cast<SaveKey&>(myController->base()); SaveKey& skey = static_cast<SaveKey&>(controller());
return skey.isPageUsed(page); return skey.isPageUsed(page);
} }

View File

@ -66,7 +66,7 @@ class Controller : public Serializable
Various classes that need special access to the underlying controller state Various classes that need special access to the underlying controller state
*/ */
friend class M6532; // FIXME - only needs two methods from this class friend class M6532; // FIXME - only needs two methods from this class
friend class CompuMate; friend class CompuMate; // FIXME - should go through CMControl instead
friend class ControllerLowLevel; friend class ControllerLowLevel;
public: public:

View File

@ -56,7 +56,7 @@ class ControllerLowLevel
inline void resetAnalogPins() { inline void resetAnalogPins() {
myController.resetAnalogPins(); myController.resetAnalogPins();
} }
inline Controller& base() const { return myController; } inline Controller& controller() const { return myController; }
protected: protected:
Controller& myController; Controller& myController;