More refactoring: remove dependency of System on OSystem.

This commit is contained in:
Christian Speckner 2019-02-27 22:39:09 +01:00
parent b93c95e041
commit 05260ca006
9 changed files with 43 additions and 36 deletions

View File

@ -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<SerialPort&>(port)),
myShiftCount(0),
myShiftRegister(0),

View File

@ -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;

View File

@ -105,8 +105,11 @@ Console::Console(OSystem& osystem, unique_ptr<Cartridge>& cart,
myTIA->setFrameManager(myFrameManager.get());
// Reinitialize the RNG
myOSystem.random().initSeed(static_cast<uInt32>(myOSystem.getTicks()));
// Construct the system and components
mySystem = make_unique<System>(osystem, *my6502, *myRiot, *myTIA, *myCart);
mySystem = make_unique<System>(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<Controller> Console::getControllerPort(const string& rommd5,
{
const string& nvramfile = myOSystem.nvramDir() + "atarivox_eeprom.dat";
controller = make_unique<AtariVox>(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<SaveKey>(port, myEvent, *mySystem,
controller = make_unique<SaveKey>(port, myEvent, *mySystem, myOSystem,
nvramfile);
}
else if(controllerName == "GENESIS")

View File

@ -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);

View File

@ -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];

View File

@ -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<MT24LC256>(eepromfile, system);
myEEPROM = make_unique<MT24LC256>(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)
{
}

View File

@ -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:

View File

@ -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)

View File

@ -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;