Completely remove OSystem/FrameBuffer/Settings dependency on AVox/SaveKey.

- Added a new callback that enables sending messages back to the parent (Console)
This commit is contained in:
Stephen Anthony 2019-03-03 22:03:44 -03:30
parent 3b15f8da5d
commit 9f6b91cff6
8 changed files with 54 additions and 45 deletions

View File

@ -21,9 +21,10 @@
#include "AtariVox.hxx" #include "AtariVox.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AtariVox::AtariVox(Jack jack, const Event& event, const System& system, const OSystem& osystem, AtariVox::AtariVox(Jack jack, const Event& event, const System& system,
const string& portname, const string& eepromfile) const string& portname, const string& eepromfile,
: SaveKey(jack, event, system, osystem, eepromfile, Controller::AtariVox), onMessageCallback callback)
: SaveKey(jack, event, system, eepromfile, callback, Controller::AtariVox),
myShiftCount(0), myShiftCount(0),
myShiftRegister(0), myShiftRegister(0),
myLastDataWriteCycle(0) myLastDataWriteCycle(0)

View File

@ -42,12 +42,13 @@ class AtariVox : public SaveKey
@param jack The jack the controller is plugged into @param jack The jack the controller is plugged into
@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
@param osystem The OSystem abstraction
@param portname Name of the serial port used for reading and writing @param portname Name of the serial port used for reading and writing
@param eepromfile The file containing the EEPROM data @param eepromfile The file containing the EEPROM data
@param callback Called to pass messages back to the parent controller
*/ */
AtariVox(Jack jack, const Event& event, const System& system, const OSystem& osystem, AtariVox(Jack jack, const Event& event, const System& system,
const string& portname, const string& eepromfile); const string& portname, const string& eepromfile,
onMessageCallback callback);
virtual ~AtariVox() = default; virtual ~AtariVox() = default;
public: public:

View File

@ -936,14 +936,23 @@ unique_ptr<Controller> Console::getControllerPort(const string& rommd5,
else if(controllerName == "ATARIVOX") else if(controllerName == "ATARIVOX")
{ {
const string& nvramfile = myOSystem.nvramDir() + "atarivox_eeprom.dat"; const string& nvramfile = myOSystem.nvramDir() + "atarivox_eeprom.dat";
controller = make_unique<AtariVox>(port, myEvent, Controller::onMessageCallback callback = [&os = myOSystem](const string& msg) {
*mySystem, myOSystem, myOSystem.settings().getString("avoxport"), nvramfile); bool devSettings = os.settings().getBool("dev.settings");
if(os.settings().getBool(devSettings ? "dev.eepromaccess" : "plr.eepromaccess"))
os.frameBuffer().showMessage(msg);
};
controller = make_unique<AtariVox>(port, myEvent, *mySystem,
myOSystem.settings().getString("avoxport"), nvramfile, callback);
} }
else if(controllerName == "SAVEKEY") else if(controllerName == "SAVEKEY")
{ {
const string& nvramfile = myOSystem.nvramDir() + "savekey_eeprom.dat"; const string& nvramfile = myOSystem.nvramDir() + "savekey_eeprom.dat";
controller = make_unique<SaveKey>(port, myEvent, *mySystem, myOSystem, Controller::onMessageCallback callback = [&os = myOSystem](const string& msg) {
nvramfile); bool devSettings = os.settings().getBool("dev.settings");
if(os.settings().getBool(devSettings ? "dev.eepromaccess" : "plr.eepromaccess"))
os.frameBuffer().showMessage(msg);
};
controller = make_unique<SaveKey>(port, myEvent, *mySystem, nvramfile, callback);
} }
else if(controllerName == "GENESIS") else if(controllerName == "GENESIS")
{ {

View File

@ -99,6 +99,11 @@ class Controller : public Serializable
*/ */
using onAnalogPinUpdateCallback = std::function<void(AnalogPin)>; using onAnalogPinUpdateCallback = std::function<void(AnalogPin)>;
/**
Callback type for general controller messages
*/
using onMessageCallback = std::function<void(const string&)>;
public: public:
/** /**
Create a new controller plugged into the specified jack Create a new controller plugged into the specified jack

View File

@ -18,16 +18,10 @@
#include <cstdio> #include <cstdio>
#include "System.hxx" #include "System.hxx"
#include "OSystem.hxx"
#include "Settings.hxx"
#include "MT24LC256.hxx" #include "MT24LC256.hxx"
//#define DEBUG_EEPROM //#define DEBUG_EEPROM
// FIXME - It seems we only need OSystem here to print a message; I think this
// can be abstracted away from the class; perhaps use a lambda to
// register a callback when a write happens??
#ifdef DEBUG_EEPROM #ifdef DEBUG_EEPROM
static char jpee_msg[256]; static char jpee_msg[256];
#define JPEE_LOG0(msg) jpee_logproc(msg) #define JPEE_LOG0(msg) jpee_logproc(msg)
@ -49,9 +43,10 @@
*/ */
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MT24LC256::MT24LC256(const string& filename, const System& system, const OSystem& osystem) MT24LC256::MT24LC256(const string& filename, const System& system,
Controller::onMessageCallback callback)
: mySystem(system), : mySystem(system),
myOSystem(osystem), myCallback(callback),
mySDA(false), mySDA(false),
mySCL(false), mySCL(false),
myTimerActive(false), myTimerActive(false),
@ -256,9 +251,9 @@ void MT24LC256::jpee_data_stop()
{ {
myDataChanged = true; myDataChanged = true;
myPageHit[jpee_address / PAGE_SIZE] = true; myPageHit[jpee_address / PAGE_SIZE] = true;
bool devSettings = myOSystem.settings().getBool("dev.settings");
if(myOSystem.settings().getBool(devSettings ? "dev.eepromaccess" : "plr.eepromaccess")) myCallback("AtariVox/SaveKey EEPROM write");
myOSystem.frameBuffer().showMessage("AtariVox/SaveKey EEPROM write");
myData[(jpee_address++) & jpee_sizemask] = jpee_packet[i]; myData[(jpee_address++) & jpee_sizemask] = jpee_packet[i];
if (!(jpee_address & jpee_pagemask)) if (!(jpee_address & jpee_pagemask))
break; /* Writes can't cross page boundary! */ break; /* Writes can't cross page boundary! */
@ -357,11 +352,8 @@ void MT24LC256::jpee_clock_fall()
jpee_state=3; jpee_state=3;
myPageHit[jpee_address / PAGE_SIZE] = true; myPageHit[jpee_address / PAGE_SIZE] = true;
{ myCallback("AtariVox/SaveKey EEPROM read");
bool devSettings = myOSystem.settings().getBool("dev.settings");
if(myOSystem.settings().getBool(devSettings ? "dev.eepromaccess" : "plr.eepromaccess"))
myOSystem.frameBuffer().showMessage("AtariVox/SaveKey EEPROM read");
}
jpee_nb = (myData[jpee_address & jpee_sizemask] << 1) | 1; /* Fall through */ jpee_nb = (myData[jpee_address & jpee_sizemask] << 1) | 1; /* Fall through */
JPEE_LOG2("I2C_READ(%04X=%02X)",jpee_address,jpee_nb/2); JPEE_LOG2("I2C_READ(%04X=%02X)",jpee_address,jpee_nb/2);
[[fallthrough]]; [[fallthrough]];

View File

@ -18,10 +18,9 @@
#ifndef MT24LC256_HXX #ifndef MT24LC256_HXX
#define MT24LC256_HXX #define MT24LC256_HXX
class Controller;
class System; class System;
class OSystem;
#include "Control.hxx"
#include "bspf.hxx" #include "bspf.hxx"
/** /**
@ -37,11 +36,12 @@ class MT24LC256
/** /**
Create a new 24LC256 with its data stored in the given file Create a new 24LC256 with its data stored in the given file
@param filename Data file containing the EEPROM data @param filename Data file containing the EEPROM data
@param system The system using the controller of this device @param system The system using the controller of this device
@param osystem The OSystem abstraction @param callback Called to pass messages back to the parent controller
*/ */
MT24LC256(const string& filename, const System& system, const OSystem& osystem); MT24LC256(const string& filename, const System& system,
Controller::onMessageCallback callback);
~MT24LC256(); ~MT24LC256();
private: private:
@ -89,8 +89,9 @@ class MT24LC256
// The system of the parent controller // The system of the parent controller
const System& mySystem; const System& mySystem;
// The OSystem abstraction // Sends messages back to the parent class
const OSystem& myOSystem; // Currently used for indicating read/write access
Controller::onMessageCallback myCallback;
// The EEPROM data // The EEPROM data
uInt8 myData[FLASH_SIZE]; uInt8 myData[FLASH_SIZE];

View File

@ -21,19 +21,19 @@
#include "SaveKey.hxx" #include "SaveKey.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SaveKey::SaveKey(Jack jack, const Event& event, const System& system, const OSystem& osystem, SaveKey::SaveKey(Jack jack, const Event& event, const System& system,
const string& eepromfile, Type type) const string& eepromfile, onMessageCallback callback, Type type)
: Controller(jack, event, system, type) : Controller(jack, event, system, type)
{ {
myEEPROM = make_unique<MT24LC256>(eepromfile, system, osystem); myEEPROM = make_unique<MT24LC256>(eepromfile, system, callback);
myDigitalPinState[One] = myDigitalPinState[Two] = true; myDigitalPinState[One] = myDigitalPinState[Two] = true;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SaveKey::SaveKey(Jack jack, const Event& event, const System& system, const OSystem& osystem, SaveKey::SaveKey(Jack jack, const Event& event, const System& system,
const string& eepromfile) const string& eepromfile, onMessageCallback callback)
: SaveKey(jack, event, system, osystem, eepromfile, Controller::SaveKey) : SaveKey(jack, event, system, eepromfile, callback, Controller::SaveKey)
{ {
} }

View File

@ -41,11 +41,11 @@ class SaveKey : public Controller
@param jack The jack the controller is plugged into @param jack The jack the controller is plugged into
@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
@param osystem The OSystem abstraction
@param eepromfile The file containing the EEPROM data @param eepromfile The file containing the EEPROM data
@param callback Called to pass messages back to the parent controller
*/ */
SaveKey(Jack jack, const Event& event, const System& system, const OSystem& osystem, SaveKey(Jack jack, const Event& event, const System& system,
const string& eepromfile); const string& eepromfile, onMessageCallback callback);
virtual ~SaveKey(); virtual ~SaveKey();
protected: protected:
@ -53,8 +53,8 @@ class SaveKey : public Controller
Delegating constructor currently used by both this class and classes Delegating constructor currently used by both this class and classes
that inherit from SaveKey (currently, AtariVox) that inherit from SaveKey (currently, AtariVox)
*/ */
SaveKey(Jack jack, const Event& event, const System& system, const OSystem& osystem, SaveKey(Jack jack, const Event& event, const System& system,
const string& eepromfile, Type type); const string& eepromfile, onMessageCallback callback, Type type);
public: public:
using Controller::read; using Controller::read;