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"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AtariVox::AtariVox(Jack jack, const Event& event, const System& system, const OSystem& osystem,
const string& portname, const string& eepromfile)
: SaveKey(jack, event, system, osystem, eepromfile, Controller::AtariVox),
AtariVox::AtariVox(Jack jack, const Event& event, const System& system,
const string& portname, const string& eepromfile,
onMessageCallback callback)
: SaveKey(jack, event, system, eepromfile, callback, Controller::AtariVox),
myShiftCount(0),
myShiftRegister(0),
myLastDataWriteCycle(0)

View File

@ -42,12 +42,13 @@ class AtariVox : public SaveKey
@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 osystem The OSystem abstraction
@param portname Name of the serial port used for reading and writing
@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,
const string& portname, const string& eepromfile);
AtariVox(Jack jack, const Event& event, const System& system,
const string& portname, const string& eepromfile,
onMessageCallback callback);
virtual ~AtariVox() = default;
public:

View File

@ -936,14 +936,23 @@ unique_ptr<Controller> Console::getControllerPort(const string& rommd5,
else if(controllerName == "ATARIVOX")
{
const string& nvramfile = myOSystem.nvramDir() + "atarivox_eeprom.dat";
controller = make_unique<AtariVox>(port, myEvent,
*mySystem, myOSystem, myOSystem.settings().getString("avoxport"), nvramfile);
Controller::onMessageCallback callback = [&os = myOSystem](const string& msg) {
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")
{
const string& nvramfile = myOSystem.nvramDir() + "savekey_eeprom.dat";
controller = make_unique<SaveKey>(port, myEvent, *mySystem, myOSystem,
nvramfile);
Controller::onMessageCallback callback = [&os = myOSystem](const string& msg) {
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")
{

View File

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

View File

@ -18,16 +18,10 @@
#include <cstdio>
#include "System.hxx"
#include "OSystem.hxx"
#include "Settings.hxx"
#include "MT24LC256.hxx"
//#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
static char jpee_msg[256];
#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),
myOSystem(osystem),
myCallback(callback),
mySDA(false),
mySCL(false),
myTimerActive(false),
@ -256,9 +251,9 @@ void MT24LC256::jpee_data_stop()
{
myDataChanged = true;
myPageHit[jpee_address / PAGE_SIZE] = true;
bool devSettings = myOSystem.settings().getBool("dev.settings");
if(myOSystem.settings().getBool(devSettings ? "dev.eepromaccess" : "plr.eepromaccess"))
myOSystem.frameBuffer().showMessage("AtariVox/SaveKey EEPROM write");
myCallback("AtariVox/SaveKey EEPROM write");
myData[(jpee_address++) & jpee_sizemask] = jpee_packet[i];
if (!(jpee_address & jpee_pagemask))
break; /* Writes can't cross page boundary! */
@ -357,11 +352,8 @@ void MT24LC256::jpee_clock_fall()
jpee_state=3;
myPageHit[jpee_address / PAGE_SIZE] = true;
{
bool devSettings = myOSystem.settings().getBool("dev.settings");
if(myOSystem.settings().getBool(devSettings ? "dev.eepromaccess" : "plr.eepromaccess"))
myOSystem.frameBuffer().showMessage("AtariVox/SaveKey EEPROM read");
}
myCallback("AtariVox/SaveKey EEPROM read");
jpee_nb = (myData[jpee_address & jpee_sizemask] << 1) | 1; /* Fall through */
JPEE_LOG2("I2C_READ(%04X=%02X)",jpee_address,jpee_nb/2);
[[fallthrough]];

View File

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

View File

@ -21,19 +21,19 @@
#include "SaveKey.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SaveKey::SaveKey(Jack jack, const Event& event, const System& system, const OSystem& osystem,
const string& eepromfile, Type type)
SaveKey::SaveKey(Jack jack, const Event& event, const System& system,
const string& eepromfile, onMessageCallback callback, Type 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;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SaveKey::SaveKey(Jack jack, const Event& event, const System& system, const OSystem& osystem,
const string& eepromfile)
: SaveKey(jack, event, system, osystem, eepromfile, Controller::SaveKey)
SaveKey::SaveKey(Jack jack, const Event& event, const System& system,
const string& eepromfile, onMessageCallback callback)
: 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 event The event object to use for events
@param system The system using this controller
@param osystem The OSystem abstraction
@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,
const string& eepromfile);
SaveKey(Jack jack, const Event& event, const System& system,
const string& eepromfile, onMessageCallback callback);
virtual ~SaveKey();
protected:
@ -53,8 +53,8 @@ class SaveKey : public Controller
Delegating constructor currently used by both this class and classes
that inherit from SaveKey (currently, AtariVox)
*/
SaveKey(Jack jack, const Event& event, const System& system, const OSystem& osystem,
const string& eepromfile, Type type);
SaveKey(Jack jack, const Event& event, const System& system,
const string& eepromfile, onMessageCallback callback, Type type);
public:
using Controller::read;