Completely removed OSystem dependency for Cart classes.

This commit is contained in:
Stephen Anthony 2019-02-26 21:37:35 -03:30
parent 61cf68cb98
commit e7169ac010
8 changed files with 19 additions and 51 deletions

View File

@ -184,12 +184,13 @@ class Cartridge : public Device
virtual string name() const = 0;
/**
Informs the cartridge about the name of the ROM file used when
creating this cart.
Informs the cartridge about the name of the nvram file it will
use; not all carts support this.
@param name The properties file name of the ROM
@param nvramdir The full path of the nvram directory
@param romfile The name of the cart from ROM properties
*/
virtual void setRomName(const string& name) { }
virtual void setNVRamFile(const string& nvramdir, const string& romfile) { }
/**
Thumbulator only supports 16-bit ARM code. Some Harmony/Melody drivers,
@ -207,17 +208,6 @@ class Cartridge : public Device
virtual CartDebugWidget* debugWidget(GuiObject* boss, const GUI::Font& lfont,
const GUI::Font& nfont, int x, int y, int w, int h) { return nullptr; }
/**
We don't want cartridges to depend on OSystem by default. Cartridges that require OSystem
should override this method to get the OSystem instance injected via setter.
*/
virtual bool requiresOSystem() { return false; }
/**
Setter for injecting OSystem.
*/
virtual void setOSystem(OSystem* osystem) {}
protected:
/**
Get a random value to use when a read from the write port happens.

View File

@ -25,7 +25,6 @@
CartridgeCTY::CartridgeCTY(const BytePtr& image, uInt32 size,
const string& md5, const Settings& settings)
: Cartridge(settings, md5),
myOSystem(nullptr),
myOperationType(0),
myTunePosition(0),
myLDAimmediate(false),
@ -343,9 +342,9 @@ bool CartridgeCTY::load(Serializer& in)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CartridgeCTY::setRomName(const string& name)
void CartridgeCTY::setNVRamFile(const string& nvramdir, const string& romfile)
{
myEEPROMFile = myOSystem->nvramDir() + name + "_eeprom.dat";
myEEPROMFile = nvramdir + romfile + "_eeprom.dat";
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -194,12 +194,12 @@ class CartridgeCTY : public Cartridge
string name() const override { return "CartridgeCTY"; }
/**
Informs the cartridge about the name of the ROM file used when
creating this cart.
Informs the cartridge about the name of the nvram file it will use.
@param name The properties file name of the ROM
@param nvramdir The full path of the nvram directory
@param romfile The name of the cart from ROM properties
*/
void setRomName(const string& name) override;
void setNVRamFile(const string& nvramdir, const string& romfile) override;
#ifdef DEBUGGER_SUPPORT
/**
@ -256,14 +256,7 @@ class CartridgeCTY : public Cartridge
void updateTune();
bool requiresOSystem() override { return true; }
void setOSystem(OSystem* osystem) override { myOSystem = osystem; }
private:
// OSsytem currently in use
const OSystem* myOSystem;
// The 32K ROM image of the cartridge
uInt8 myImage[32768];

View File

@ -25,7 +25,6 @@
CartridgeFA2::CartridgeFA2(const BytePtr& image, uInt32 size,
const string& md5, const Settings& settings)
: Cartridge(settings, md5),
myOSystem(nullptr),
mySize(28 * 1024),
myRamAccessTimeout(0),
myBankOffset(0)
@ -304,9 +303,9 @@ bool CartridgeFA2::load(Serializer& in)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CartridgeFA2::setRomName(const string& name)
void CartridgeFA2::setNVRamFile(const string& nvramdir, const string& romfile)
{
myFlashFile = myOSystem->nvramDir() + name + "_flash.dat";
myFlashFile = nvramdir + romfile + "_flash.dat";
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -134,12 +134,12 @@ class CartridgeFA2 : public Cartridge
string name() const override { return "CartridgeFA2"; }
/**
Informs the cartridge about the name of the ROM file used when
creating this cart.
Informs the cartridge about the name of the nvram file it will use.
@param name The properties file name of the ROM
@param nvramdir The full path of the nvram directory
@param romfile The name of the cart from ROM properties
*/
void setRomName(const string& name) override;
void setNVRamFile(const string& nvramdir, const string& romfile) override;
#ifdef DEBUGGER_SUPPORT
/**
@ -189,14 +189,7 @@ class CartridgeFA2 : public Cartridge
*/
void flash(uInt8 operation);
bool requiresOSystem() override { return true; }
void setOSystem(OSystem* osystem) override { myOSystem = osystem; }
private:
// OSsytem currently in use
const OSystem* myOSystem;
// The 24K/28K ROM image of the cartridge
uInt8 myImage[28 * 1024];

View File

@ -206,7 +206,8 @@ Console::Console(OSystem& osystem, unique_ptr<Cartridge>& cart,
myConsoleInfo.Control1 = myRightControl->about(swappedPorts);
myConsoleInfo.BankSwitch = myCart->about();
myCart->setRomName(myConsoleInfo.CartName);
// Some carts have an associated nvram file
myCart->setNVRamFile(myOSystem.nvramDir(), myConsoleInfo.CartName);
// Let the other devices know about the new console
mySystem->consoleChanged(myConsoleTiming);

View File

@ -499,8 +499,6 @@ unique_ptr<Console> OSystem::openConsole(const FilesystemNode& romfile, string&
unique_ptr<Cartridge> cart =
CartDetector::create(romfile, image, size, cartmd5, type, *mySettings);
if (cart->requiresOSystem()) cart->setOSystem(this);
// It's possible that the cart created was from a piece of the image,
// and that the md5 (and hence the cart) has changed
if(props.get(Cartridge_MD5) != cartmd5)

View File

@ -83,10 +83,5 @@ bool ProfilingRunner::runOne(const ProfilingRun run)
return false;
}
if (cartridge->requiresOSystem()) {
cout << "ERROR: profiling not supported for " << cartridge->name() << " ROM images" << endl;
return false;
}
return true;
}