mirror of https://github.com/stella-emu/stella.git
Cleaned up the OSystem code for managing Console and Debugger, removing
stuff from destructors and using unique_ptr. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@3063 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
db139bef1a
commit
4c9e139fcc
|
@ -42,8 +42,6 @@ CheatManager::CheatManager(OSystem& osystem)
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
CheatManager::~CheatManager()
|
CheatManager::~CheatManager()
|
||||||
{
|
{
|
||||||
saveCheatDatabase();
|
|
||||||
myCheatMap.clear();
|
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -150,8 +150,6 @@ Debugger::~Debugger()
|
||||||
delete myBreakPoints;
|
delete myBreakPoints;
|
||||||
delete myReadTraps;
|
delete myReadTraps;
|
||||||
delete myWriteTraps;
|
delete myWriteTraps;
|
||||||
|
|
||||||
myStaticDebugger = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -896,11 +896,11 @@ void Console::toggleFixedColors() const
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void Console::addDebugger()
|
void Console::attachDebugger(Debugger& dbg)
|
||||||
{
|
{
|
||||||
#ifdef DEBUGGER_SUPPORT
|
#ifdef DEBUGGER_SUPPORT
|
||||||
myOSystem.createDebugger(*this);
|
// myOSystem.createDebugger(*this);
|
||||||
mySystem->m6502().attach(myOSystem.debugger());
|
mySystem->m6502().attach(dbg);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ class M6502;
|
||||||
class M6532;
|
class M6532;
|
||||||
class Cartridge;
|
class Cartridge;
|
||||||
class CompuMate;
|
class CompuMate;
|
||||||
|
class Debugger;
|
||||||
|
|
||||||
#include "bspf.hxx"
|
#include "bspf.hxx"
|
||||||
#include "Control.hxx"
|
#include "Control.hxx"
|
||||||
|
@ -164,7 +165,7 @@ class Console : public Serializable
|
||||||
/**
|
/**
|
||||||
Set up the console to use the debugger.
|
Set up the console to use the debugger.
|
||||||
*/
|
*/
|
||||||
void addDebugger();
|
void attachDebugger(Debugger& dbg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Informs the Console of a change in EventHandler state.
|
Informs the Console of a change in EventHandler state.
|
||||||
|
|
|
@ -904,10 +904,7 @@ void EventHandler::handleEvent(Event::Type event, int state)
|
||||||
// Go back to the launcher, or immediately quit
|
// Go back to the launcher, or immediately quit
|
||||||
if(myOSystem.settings().getBool("exitlauncher") ||
|
if(myOSystem.settings().getBool("exitlauncher") ||
|
||||||
myOSystem.launcherUsed())
|
myOSystem.launcherUsed())
|
||||||
{
|
|
||||||
myOSystem.deleteConsole();
|
|
||||||
myOSystem.createLauncher();
|
myOSystem.createLauncher();
|
||||||
}
|
|
||||||
else
|
else
|
||||||
handleEvent(Event::Quit, 1);
|
handleEvent(Event::Quit, 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,12 +61,7 @@
|
||||||
OSystem::OSystem()
|
OSystem::OSystem()
|
||||||
: myConsole(nullptr),
|
: myConsole(nullptr),
|
||||||
myLauncherUsed(false),
|
myLauncherUsed(false),
|
||||||
myDebugger(nullptr),
|
myQuitLoop(false)
|
||||||
myQuitLoop(false),
|
|
||||||
myRomFile(""),
|
|
||||||
myRomMD5(""),
|
|
||||||
myFeatures(""),
|
|
||||||
myBuildInfo("")
|
|
||||||
{
|
{
|
||||||
// Calculate startup time
|
// Calculate startup time
|
||||||
myMillisAtStart = (uInt32)(time(NULL) * 1000);
|
myMillisAtStart = (uInt32)(time(NULL) * 1000);
|
||||||
|
@ -102,11 +97,6 @@ OSystem::OSystem()
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
OSystem::~OSystem()
|
OSystem::~OSystem()
|
||||||
{
|
{
|
||||||
// Remove any game console that is currently attached
|
|
||||||
deleteConsole();
|
|
||||||
#ifdef DEBUGGER_SUPPORT
|
|
||||||
delete myDebugger;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -184,22 +174,11 @@ void OSystem::loadConfig()
|
||||||
void OSystem::saveConfig()
|
void OSystem::saveConfig()
|
||||||
{
|
{
|
||||||
// Ask all subsystems to save their settings
|
// Ask all subsystems to save their settings
|
||||||
if(myFrameBuffer)
|
myFrameBuffer->tiaSurface().ntsc().saveConfig(*mySettings);
|
||||||
myFrameBuffer->tiaSurface().ntsc().saveConfig(*mySettings);
|
|
||||||
|
|
||||||
mySettings->saveConfig();
|
mySettings->saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUGGER_SUPPORT
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
void OSystem::createDebugger(Console& console)
|
|
||||||
{
|
|
||||||
delete myDebugger; myDebugger = nullptr;
|
|
||||||
myDebugger = new Debugger(*this, console);
|
|
||||||
myDebugger->initialize();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void OSystem::setConfigPaths()
|
void OSystem::setConfigPaths()
|
||||||
{
|
{
|
||||||
|
@ -309,9 +288,6 @@ void OSystem::createSound()
|
||||||
string OSystem::createConsole(const FilesystemNode& rom, const string& md5sum,
|
string OSystem::createConsole(const FilesystemNode& rom, const string& md5sum,
|
||||||
bool newrom)
|
bool newrom)
|
||||||
{
|
{
|
||||||
// Do a little error checking; it shouldn't be necessary
|
|
||||||
if(myConsole) deleteConsole();
|
|
||||||
|
|
||||||
bool showmessage = false;
|
bool showmessage = false;
|
||||||
|
|
||||||
// If same ROM has been given, we reload the current one (assuming one exists)
|
// If same ROM has been given, we reload the current one (assuming one exists)
|
||||||
|
@ -335,11 +311,15 @@ string OSystem::createConsole(const FilesystemNode& rom, const string& md5sum,
|
||||||
string type, id;
|
string type, id;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
#ifdef CHEATCODE_SUPPORT
|
||||||
|
// If a previous console existed, save cheats before creating a new one
|
||||||
|
if(myConsole)
|
||||||
|
myCheatManager->saveCheats(myConsole->properties().get(Cartridge_MD5));
|
||||||
|
#endif
|
||||||
myConsole = openConsole(myRomFile, myRomMD5, type, id);
|
myConsole = openConsole(myRomFile, myRomMD5, type, id);
|
||||||
}
|
}
|
||||||
catch(const char* err_msg)
|
catch(const char* err_msg)
|
||||||
{
|
{
|
||||||
myConsole = 0;
|
|
||||||
buf << "ERROR: Couldn't create console (" << err_msg << ")";
|
buf << "ERROR: Couldn't create console (" << err_msg << ")";
|
||||||
logMessage(buf.str(), 0);
|
logMessage(buf.str(), 0);
|
||||||
return buf.str();
|
return buf.str();
|
||||||
|
@ -348,7 +328,9 @@ string OSystem::createConsole(const FilesystemNode& rom, const string& md5sum,
|
||||||
if(myConsole)
|
if(myConsole)
|
||||||
{
|
{
|
||||||
#ifdef DEBUGGER_SUPPORT
|
#ifdef DEBUGGER_SUPPORT
|
||||||
myConsole->addDebugger();
|
myDebugger = make_ptr<Debugger>(*this, *myConsole);
|
||||||
|
myDebugger->initialize();
|
||||||
|
myConsole->attachDebugger(*myDebugger);
|
||||||
#endif
|
#endif
|
||||||
#ifdef CHEATCODE_SUPPORT
|
#ifdef CHEATCODE_SUPPORT
|
||||||
myCheatManager->loadCheats(myRomMD5);
|
myCheatManager->loadCheats(myRomMD5);
|
||||||
|
@ -372,7 +354,7 @@ string OSystem::createConsole(const FilesystemNode& rom, const string& md5sum,
|
||||||
}
|
}
|
||||||
buf << "Game console created:" << endl
|
buf << "Game console created:" << endl
|
||||||
<< " ROM file: " << myRomFile.getShortPath() << endl << endl
|
<< " ROM file: " << myRomFile.getShortPath() << endl << endl
|
||||||
<< getROMInfo(myConsole) << endl;
|
<< getROMInfo(*myConsole) << endl;
|
||||||
logMessage(buf.str(), 1);
|
logMessage(buf.str(), 1);
|
||||||
|
|
||||||
// Update the timing info for a new console run
|
// Update the timing info for a new console run
|
||||||
|
@ -418,42 +400,18 @@ string OSystem::createConsole(const FilesystemNode& rom, const string& md5sum,
|
||||||
return EmptyString;
|
return EmptyString;
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
void OSystem::deleteConsole()
|
|
||||||
{
|
|
||||||
if(myConsole)
|
|
||||||
{
|
|
||||||
mySound->close();
|
|
||||||
#ifdef CHEATCODE_SUPPORT
|
|
||||||
myCheatManager->saveCheats(myConsole->properties().get(Cartridge_MD5));
|
|
||||||
#endif
|
|
||||||
ostringstream buf;
|
|
||||||
double executionTime = (double) myTimingInfo.totalTime / 1000000.0;
|
|
||||||
double framesPerSecond = (double) myTimingInfo.totalFrames / executionTime;
|
|
||||||
buf << "Game console stats:" << endl
|
|
||||||
<< " Total frames drawn: " << myTimingInfo.totalFrames << endl
|
|
||||||
<< " Total time (sec): " << executionTime << endl
|
|
||||||
<< " Frames per second: " << framesPerSecond << endl
|
|
||||||
<< endl;
|
|
||||||
logMessage(buf.str(), 1);
|
|
||||||
|
|
||||||
delete myConsole; myConsole = nullptr;
|
|
||||||
#ifdef DEBUGGER_SUPPORT
|
|
||||||
delete myDebugger; myDebugger = nullptr;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool OSystem::reloadConsole()
|
bool OSystem::reloadConsole()
|
||||||
{
|
{
|
||||||
deleteConsole();
|
|
||||||
return createConsole(myRomFile, myRomMD5, false) == EmptyString;
|
return createConsole(myRomFile, myRomMD5, false) == EmptyString;
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool OSystem::createLauncher(const string& startdir)
|
bool OSystem::createLauncher(const string& startdir)
|
||||||
{
|
{
|
||||||
|
if(mySound)
|
||||||
|
mySound->close();
|
||||||
|
|
||||||
mySettings->setValue("tmpromdir", startdir);
|
mySettings->setValue("tmpromdir", startdir);
|
||||||
bool status = false;
|
bool status = false;
|
||||||
|
|
||||||
|
@ -479,7 +437,7 @@ bool OSystem::createLauncher(const string& startdir)
|
||||||
string OSystem::getROMInfo(const FilesystemNode& romfile)
|
string OSystem::getROMInfo(const FilesystemNode& romfile)
|
||||||
{
|
{
|
||||||
string md5, type, id, result = "";
|
string md5, type, id, result = "";
|
||||||
Console* console = 0;
|
unique_ptr<Console> console;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
console = openConsole(romfile, md5, type, id);
|
console = openConsole(romfile, md5, type, id);
|
||||||
|
@ -491,8 +449,7 @@ string OSystem::getROMInfo(const FilesystemNode& romfile)
|
||||||
return buf.str();
|
return buf.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
result = getROMInfo(console);
|
result = getROMInfo(*console);
|
||||||
delete console;
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -513,14 +470,14 @@ void OSystem::logMessage(const string& message, uInt8 level)
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
Console* OSystem::openConsole(const FilesystemNode& romfile, string& md5,
|
unique_ptr<Console> OSystem::openConsole(const FilesystemNode& romfile,
|
||||||
string& type, string& id)
|
string& md5, string& type, string& id)
|
||||||
{
|
{
|
||||||
#define CMDLINE_PROPS_UPDATE(cl_name, prop_name) \
|
#define CMDLINE_PROPS_UPDATE(cl_name, prop_name) \
|
||||||
s = mySettings->getString(cl_name); \
|
s = mySettings->getString(cl_name); \
|
||||||
if(s != "") props.set(prop_name, s);
|
if(s != "") props.set(prop_name, s);
|
||||||
|
|
||||||
Console* console = nullptr;
|
unique_ptr<Console> console;
|
||||||
|
|
||||||
// Open the cartridge image and read it in
|
// Open the cartridge image and read it in
|
||||||
uInt8* image = 0;
|
uInt8* image = 0;
|
||||||
|
@ -573,7 +530,7 @@ Console* OSystem::openConsole(const FilesystemNode& romfile, string& md5,
|
||||||
|
|
||||||
// Finally, create the cart with the correct properties
|
// Finally, create the cart with the correct properties
|
||||||
if(cart)
|
if(cart)
|
||||||
console = new Console(*this, cart, props);
|
console = make_ptr<Console>(*this, cart, props);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free the image since we don't need it any longer
|
// Free the image since we don't need it any longer
|
||||||
|
@ -591,11 +548,11 @@ uInt8* OSystem::openROM(const FilesystemNode& rom, string& md5, uInt32& size)
|
||||||
// but also adds a properties entry if the one for the ROM doesn't
|
// but also adds a properties entry if the one for the ROM doesn't
|
||||||
// contain a valid name
|
// contain a valid name
|
||||||
|
|
||||||
uInt8* image = 0;
|
uInt8* image = nullptr;
|
||||||
if((size = rom.read(image)) == 0)
|
if((size = rom.read(image)) == 0)
|
||||||
{
|
{
|
||||||
delete[] image;
|
delete[] image;
|
||||||
return (uInt8*) 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we get to this point, we know we have a valid file to open
|
// If we get to this point, we know we have a valid file to open
|
||||||
|
@ -614,9 +571,9 @@ uInt8* OSystem::openROM(const FilesystemNode& rom, string& md5, uInt32& size)
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
string OSystem::getROMInfo(const Console* console)
|
string OSystem::getROMInfo(const Console& console)
|
||||||
{
|
{
|
||||||
const ConsoleInfo& info = console->about();
|
const ConsoleInfo& info = console.about();
|
||||||
ostringstream buf;
|
ostringstream buf;
|
||||||
|
|
||||||
buf << " Cart Name: " << info.CartName << endl
|
buf << " Cart Name: " << info.CartName << endl
|
||||||
|
@ -719,6 +676,14 @@ void OSystem::mainLoop()
|
||||||
myTimingInfo.totalFrames++;
|
myTimingInfo.totalFrames++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cleanup time
|
||||||
|
#ifdef CHEATCODE_SUPPORT
|
||||||
|
if(myConsole)
|
||||||
|
myCheatManager->saveCheats(myConsole->properties().get(Cartridge_MD5));
|
||||||
|
|
||||||
|
myCheatManager->saveCheatDatabase();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -199,11 +199,6 @@ class OSystem
|
||||||
void saveConfig();
|
void saveConfig();
|
||||||
|
|
||||||
#ifdef DEBUGGER_SUPPORT
|
#ifdef DEBUGGER_SUPPORT
|
||||||
/**
|
|
||||||
Create all child objects which belong to this OSystem
|
|
||||||
*/
|
|
||||||
void createDebugger(Console& console);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Get the ROM debugger of the system.
|
Get the ROM debugger of the system.
|
||||||
|
|
||||||
|
@ -320,12 +315,6 @@ class OSystem
|
||||||
string createConsole(const FilesystemNode& rom, const string& md5 = "",
|
string createConsole(const FilesystemNode& rom, const string& md5 = "",
|
||||||
bool newrom = true);
|
bool newrom = true);
|
||||||
|
|
||||||
/**
|
|
||||||
Deletes the currently defined console, if it exists.
|
|
||||||
Also prints some statistics (fps, total frames, etc).
|
|
||||||
*/
|
|
||||||
void deleteConsole();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Reloads the current console (essentially deletes and re-creates it).
|
Reloads the current console (essentially deletes and re-creates it).
|
||||||
This can be thought of as a real console off/on toggle.
|
This can be thought of as a real console off/on toggle.
|
||||||
|
@ -475,7 +464,7 @@ class OSystem
|
||||||
unique_ptr<PropertiesSet> myPropSet;
|
unique_ptr<PropertiesSet> myPropSet;
|
||||||
|
|
||||||
// Pointer to the (currently defined) Console object
|
// Pointer to the (currently defined) Console object
|
||||||
Console* myConsole;
|
unique_ptr<Console> myConsole;
|
||||||
|
|
||||||
// Pointer to the serial port object
|
// Pointer to the serial port object
|
||||||
unique_ptr<SerialPort> mySerialPort;
|
unique_ptr<SerialPort> mySerialPort;
|
||||||
|
@ -491,7 +480,7 @@ class OSystem
|
||||||
bool myLauncherUsed;
|
bool myLauncherUsed;
|
||||||
|
|
||||||
// Pointer to the Debugger object
|
// Pointer to the Debugger object
|
||||||
Debugger* myDebugger;
|
unique_ptr<Debugger> myDebugger;
|
||||||
|
|
||||||
// Pointer to the CheatManager object
|
// Pointer to the CheatManager object
|
||||||
unique_ptr<CheatManager> myCheatManager;
|
unique_ptr<CheatManager> myCheatManager;
|
||||||
|
@ -564,11 +553,10 @@ class OSystem
|
||||||
@param type The bankswitch type of the ROM
|
@param type The bankswitch type of the ROM
|
||||||
@param id The additional id (if any) used by the ROM
|
@param id The additional id (if any) used by the ROM
|
||||||
|
|
||||||
@return The actual Console object, otherwise nullptr
|
@return The actual Console object, otherwise nullptr.
|
||||||
(calling method is responsible for deleting it)
|
|
||||||
*/
|
*/
|
||||||
Console* openConsole(const FilesystemNode& romfile, string& md5,
|
unique_ptr<Console> openConsole(const FilesystemNode& romfile, string& md5,
|
||||||
string& type, string& id);
|
string& type, string& id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Open the given ROM and return an array containing its contents.
|
Open the given ROM and return an array containing its contents.
|
||||||
|
@ -591,7 +579,7 @@ class OSystem
|
||||||
@param console The console to use
|
@param console The console to use
|
||||||
@return Some information about this console
|
@return Some information about this console
|
||||||
*/
|
*/
|
||||||
string getROMInfo(const Console* console);
|
string getROMInfo(const Console& console);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Initializes the timing so that the mainloop is reset to its
|
Initializes the timing so that the mainloop is reset to its
|
||||||
|
|
Loading…
Reference in New Issue