From 7c8f426a1b3f65ec56dfd40311dd38451124c7ca Mon Sep 17 00:00:00 2001 From: Thomas Jentzsch Date: Tue, 28 Sep 2021 21:43:46 +0200 Subject: [PATCH] added missing write method to QuadTari (fixes #832, SaveKey not working in QT) --- src/emucore/Props.cxx | 2 +- src/emucore/QuadTari.cxx | 34 +++++++++++++++++++++++----------- src/emucore/QuadTari.hxx | 13 +++++++++++++ 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/emucore/Props.cxx b/src/emucore/Props.cxx index 465ac32d6..7464c4d60 100644 --- a/src/emucore/Props.cxx +++ b/src/emucore/Props.cxx @@ -171,7 +171,7 @@ void Properties::print() const << get(PropType::Controller_Left2) << "|" << get(PropType::Controller_Right) << "|" << get(PropType::Controller_Right1) << "|" - << get(PropType::Controller_Right2) << "|" + << get(PropType::Controller_Right2) << "|" << get(PropType::Controller_SwapPaddles) << "|" << get(PropType::Controller_PaddlesXCenter) << "|" << get(PropType::Controller_PaddlesYCenter) << "|" diff --git a/src/emucore/QuadTari.cxx b/src/emucore/QuadTari.cxx index 8ef19993a..44f31cb2e 100644 --- a/src/emucore/QuadTari.cxx +++ b/src/emucore/QuadTari.cxx @@ -107,6 +107,19 @@ unique_ptr QuadTari::addController(const Controller::Type type, bool } } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool QuadTari::isFirst() +{ + constexpr int MIN_CYCLES = 76; // minimal cycles required for stable input switch (just to be safe) + + if(mySystem.tia().dumpPortsCycles() < MIN_CYCLES) + // Random controller if read too soon after dump ports changed + return mySystem.randGenerator().next() % 2; + else + // If bit 7 of VBlank is not set, read first, else second controller + return !(mySystem.tia().registerValue(VBLANK) & 0x80); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool QuadTari::read(DigitalPin pin) { @@ -114,22 +127,21 @@ bool QuadTari::read(DigitalPin pin) // can switch the controller multiple times per frame // (we can't just read 60 times per second in the ::update() method) - constexpr int MIN_CYCLES = 76; // minimal cycles required for stable input switch (just to be safe) - bool readFirst; - - if(mySystem.tia().dumpPortsCycles() < MIN_CYCLES) - // Random controller if read too soon after dump ports changed - readFirst = mySystem.randGenerator().next() % 2; - else - // If bit 7 of VBlank is not set, read first, else second controller - readFirst = !(mySystem.tia().registerValue(VBLANK) & 0x80); - - if(readFirst) + if(isFirst()) return myFirstController->read(pin); else return mySecondController->read(pin); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void QuadTari::write(DigitalPin pin, bool value) +{ + if(isFirst()) + return myFirstController->write(pin, value); + else + return mySecondController->write(pin, value); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void QuadTari::update() { diff --git a/src/emucore/QuadTari.hxx b/src/emucore/QuadTari.hxx index 26080ba0e..fb930e450 100644 --- a/src/emucore/QuadTari.hxx +++ b/src/emucore/QuadTari.hxx @@ -59,6 +59,16 @@ class QuadTari : public Controller */ bool read(DigitalPin pin) override; + /** + Write the given value to the specified digital pin for this + controller. Writing is only allowed to the pins associated + with the PIA. Therefore you cannot write to pin six. + + @param pin The pin of the controller jack to write to + @param value The value to write to the pin + */ + void write(DigitalPin pin, bool value) override; + /** Update the entire digital and analog pin state according to the events currently set. @@ -96,6 +106,9 @@ class QuadTari : public Controller Controller::Type xtype, int xid, Controller::Type ytype, int yid) override; private: + // determine which controller is active + bool isFirst(); + unique_ptr addController(const Controller::Type type, bool second); const OSystem& myOSystem;