From 05260ca006e63e8a4469bf18472e821f569f705a Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Wed, 27 Feb 2019 22:39:09 +0100 Subject: [PATCH] More refactoring: remove dependency of System on OSystem. --- src/emucore/AtariVox.cxx | 5 +++-- src/emucore/AtariVox.hxx | 4 +++- src/emucore/Console.cxx | 9 ++++++--- src/emucore/MT24LC256.cxx | 17 ++++++++++------- src/emucore/MT24LC256.hxx | 7 ++++++- src/emucore/SaveKey.cxx | 9 +++++---- src/emucore/SaveKey.hxx | 6 ++++-- src/emucore/System.cxx | 7 ++----- src/emucore/System.hxx | 15 ++++----------- 9 files changed, 43 insertions(+), 36 deletions(-) diff --git a/src/emucore/AtariVox.cxx b/src/emucore/AtariVox.cxx index 6ce8a4824..c15361b54 100644 --- a/src/emucore/AtariVox.cxx +++ b/src/emucore/AtariVox.cxx @@ -17,13 +17,14 @@ #include "SerialPort.hxx" #include "System.hxx" +#include "OSystem.hxx" #include "AtariVox.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -AtariVox::AtariVox(Jack jack, const Event& event, const System& system, +AtariVox::AtariVox(Jack jack, const Event& event, const System& system, const OSystem& osystem, const SerialPort& port, const string& portname, const string& eepromfile) - : SaveKey(jack, event, system, eepromfile, Controller::AtariVox), + : SaveKey(jack, event, system, osystem, eepromfile, Controller::AtariVox), mySerialPort(const_cast(port)), myShiftCount(0), myShiftRegister(0), diff --git a/src/emucore/AtariVox.hxx b/src/emucore/AtariVox.hxx index 3743a3d12..dc474d85b 100644 --- a/src/emucore/AtariVox.hxx +++ b/src/emucore/AtariVox.hxx @@ -19,6 +19,7 @@ #define ATARIVOX_HXX class SerialPort; +class OSystem; #include "Control.hxx" #include "SaveKey.hxx" @@ -41,11 +42,12 @@ 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 port The serial port object @param portname Name of the port used for reading and writing @param eepromfile The file containing the EEPROM data */ - AtariVox(Jack jack, const Event& event, const System& system, + AtariVox(Jack jack, const Event& event, const System& system, const OSystem& osystem, const SerialPort& port, const string& portname, const string& eepromfile); virtual ~AtariVox() = default; diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx index 9c3719181..3d90c97c9 100644 --- a/src/emucore/Console.cxx +++ b/src/emucore/Console.cxx @@ -105,8 +105,11 @@ Console::Console(OSystem& osystem, unique_ptr& cart, myTIA->setFrameManager(myFrameManager.get()); + // Reinitialize the RNG + myOSystem.random().initSeed(static_cast(myOSystem.getTicks())); + // Construct the system and components - mySystem = make_unique(osystem, *my6502, *myRiot, *myTIA, *myCart); + mySystem = make_unique(myOSystem.random(), *my6502, *myRiot, *myTIA, *myCart); // The real controllers for this console will be added later // For now, we just add dummy joystick controllers, since autodetection @@ -933,13 +936,13 @@ unique_ptr Console::getControllerPort(const string& rommd5, { const string& nvramfile = myOSystem.nvramDir() + "atarivox_eeprom.dat"; controller = make_unique(port, myEvent, - *mySystem, myOSystem.serialPort(), + *mySystem, myOSystem, myOSystem.serialPort(), myOSystem.settings().getString("avoxport"), nvramfile); } else if(controllerName == "SAVEKEY") { const string& nvramfile = myOSystem.nvramDir() + "savekey_eeprom.dat"; - controller = make_unique(port, myEvent, *mySystem, + controller = make_unique(port, myEvent, *mySystem, myOSystem, nvramfile); } else if(controllerName == "GENESIS") diff --git a/src/emucore/MT24LC256.cxx b/src/emucore/MT24LC256.cxx index 64bbb9bf6..1d3a2bc79 100644 --- a/src/emucore/MT24LC256.cxx +++ b/src/emucore/MT24LC256.cxx @@ -19,6 +19,8 @@ #include "System.hxx" +#include "OSystem.hxx" + #include "Settings.hxx" #include "MT24LC256.hxx" @@ -46,8 +48,9 @@ */ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -MT24LC256::MT24LC256(const string& filename, const System& system) +MT24LC256::MT24LC256(const string& filename, const System& system, const OSystem& osystem) : mySystem(system), + myOSystem(osystem), mySDA(false), mySCL(false), myTimerActive(false), @@ -252,9 +255,9 @@ void MT24LC256::jpee_data_stop() { myDataChanged = true; myPageHit[jpee_address / PAGE_SIZE] = true; - bool devSettings = mySystem.oSystem().settings().getBool("dev.settings"); - if(mySystem.oSystem().settings().getBool(devSettings ? "dev.eepromaccess" : "plr.eepromaccess")) - mySystem.oSystem().frameBuffer().showMessage("AtariVox/SaveKey EEPROM write"); + bool devSettings = myOSystem.settings().getBool("dev.settings"); + if(myOSystem.settings().getBool(devSettings ? "dev.eepromaccess" : "plr.eepromaccess")) + myOSystem.frameBuffer().showMessage("AtariVox/SaveKey EEPROM write"); myData[(jpee_address++) & jpee_sizemask] = jpee_packet[i]; if (!(jpee_address & jpee_pagemask)) break; /* Writes can't cross page boundary! */ @@ -354,9 +357,9 @@ void MT24LC256::jpee_clock_fall() myPageHit[jpee_address / PAGE_SIZE] = true; { - bool devSettings = mySystem.oSystem().settings().getBool("dev.settings"); - if(mySystem.oSystem().settings().getBool(devSettings ? "dev.eepromaccess" : "plr.eepromaccess")) - mySystem.oSystem().frameBuffer().showMessage("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_LOG2("I2C_READ(%04X=%02X)",jpee_address,jpee_nb/2); diff --git a/src/emucore/MT24LC256.hxx b/src/emucore/MT24LC256.hxx index eba4ee975..9f2612f24 100644 --- a/src/emucore/MT24LC256.hxx +++ b/src/emucore/MT24LC256.hxx @@ -20,6 +20,7 @@ class Controller; class System; +class OSystem; #include "bspf.hxx" @@ -38,8 +39,9 @@ class MT24LC256 @param filename Data file containing the EEPROM data @param system The system using the controller of this device + @param osystem The OSystem abstraction */ - MT24LC256(const string& filename, const System& system); + MT24LC256(const string& filename, const System& system, const OSystem& osystem); ~MT24LC256(); private: @@ -87,6 +89,9 @@ class MT24LC256 // The system of the parent controller const System& mySystem; + // The OSystem abstraction + const OSystem& myOSystem; + // The EEPROM data uInt8 myData[FLASH_SIZE]; diff --git a/src/emucore/SaveKey.cxx b/src/emucore/SaveKey.cxx index e45ac5e37..af190dff7 100644 --- a/src/emucore/SaveKey.cxx +++ b/src/emucore/SaveKey.cxx @@ -16,23 +16,24 @@ //============================================================================ #include "MT24LC256.hxx" +#include "OSystem.hxx" #include "System.hxx" #include "SaveKey.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -SaveKey::SaveKey(Jack jack, const Event& event, const System& system, +SaveKey::SaveKey(Jack jack, const Event& event, const System& system, const OSystem& osystem, const string& eepromfile, Type type) : Controller(jack, event, system, type) { - myEEPROM = make_unique(eepromfile, system); + myEEPROM = make_unique(eepromfile, system, osystem); myDigitalPinState[One] = myDigitalPinState[Two] = true; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -SaveKey::SaveKey(Jack jack, const Event& event, const System& system, +SaveKey::SaveKey(Jack jack, const Event& event, const System& system, const OSystem& osystem, const string& eepromfile) - : SaveKey(jack, event, system, eepromfile, Controller::SaveKey) + : SaveKey(jack, event, system, osystem, eepromfile, Controller::SaveKey) { } diff --git a/src/emucore/SaveKey.hxx b/src/emucore/SaveKey.hxx index d802b6240..b15fd4416 100644 --- a/src/emucore/SaveKey.hxx +++ b/src/emucore/SaveKey.hxx @@ -19,6 +19,7 @@ #define SAVEKEY_HXX class MT24LC256; +class OSystem; #include "Control.hxx" @@ -40,9 +41,10 @@ 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 */ - SaveKey(Jack jack, const Event& event, const System& system, + SaveKey(Jack jack, const Event& event, const System& system, const OSystem& osystem, const string& eepromfile); virtual ~SaveKey(); @@ -51,7 +53,7 @@ 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, + SaveKey(Jack jack, const Event& event, const System& system, const OSystem& osystem, const string& eepromfile, Type type); public: diff --git a/src/emucore/System.cxx b/src/emucore/System.cxx index f17319f3e..619ed6bf0 100644 --- a/src/emucore/System.cxx +++ b/src/emucore/System.cxx @@ -27,9 +27,9 @@ #include "System.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -System::System(const OSystem& osystem, M6502& m6502, M6532& m6532, +System::System(Random& random, M6502& m6502, M6532& m6532, TIA& mTIA, Cartridge& mCart) - : myOSystem(osystem), + : myRandom(random), myM6502(m6502), myM6532(m6532), myTIA(mTIA), @@ -39,9 +39,6 @@ System::System(const OSystem& osystem, M6502& m6502, M6532& m6532, myDataBusLocked(false), mySystemInAutodetect(false) { - // Re-initialize random generator - randGenerator().initSeed(uInt32(TimerManager::getTicks())); - // Initialize page access table PageAccess access(&myNullDevice, System::PA_READ); for(int page = 0; page < NUM_PAGES; ++page) diff --git a/src/emucore/System.hxx b/src/emucore/System.hxx index 7d59b12a4..e31202dfa 100644 --- a/src/emucore/System.hxx +++ b/src/emucore/System.hxx @@ -27,7 +27,6 @@ class NullDevice; #include "bspf.hxx" #include "Device.hxx" #include "NullDev.hxx" -#include "OSystem.hxx" #include "Random.hxx" #include "Serializable.hxx" @@ -50,7 +49,7 @@ class System : public Serializable Create a new system with an addressing space of 2^13 bytes and pages of 2^6 bytes. */ - System(const OSystem& osystem, M6502& m6502, M6532& m6532, + System(Random& random, M6502& m6502, M6532& m6532, TIA& mTIA, Cartridge& mCart); virtual ~System() = default; @@ -89,13 +88,6 @@ class System : public Serializable void reset(bool autodetect = false); public: - /** - Answer the OSystem attached to the system. - - @return The attached OSystem - */ - const OSystem& oSystem() const { return myOSystem; } - /** Answer the 6502 microprocessor attached to the system. If a processor has not been attached calling this function will fail. @@ -131,7 +123,7 @@ class System : public Serializable @return The random generator */ - Random& randGenerator() const { return myOSystem.random(); } + Random& randGenerator() const { return myRandom; } /** Get the null device associated with the system. Every system @@ -385,7 +377,8 @@ class System : public Serializable bool load(Serializer& in) override; private: - const OSystem& myOSystem; + // The system RNG + Random& myRandom; // 6502 processor attached to the system M6502& myM6502;