diff --git a/src/cheat/CheatManager.cxx b/src/cheat/CheatManager.cxx index b732ec4c9..e6abb36ad 100644 --- a/src/cheat/CheatManager.cxx +++ b/src/cheat/CheatManager.cxx @@ -42,8 +42,6 @@ CheatManager::CheatManager(OSystem& osystem) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CheatManager::~CheatManager() { - saveCheatDatabase(); - myCheatMap.clear(); clear(); } diff --git a/src/emucore/MediaFactory.hxx b/src/common/MediaFactory.hxx similarity index 100% rename from src/emucore/MediaFactory.hxx rename to src/common/MediaFactory.hxx diff --git a/src/debugger/Debugger.cxx b/src/debugger/Debugger.cxx index 6419acf50..26f8fc482 100644 --- a/src/debugger/Debugger.cxx +++ b/src/debugger/Debugger.cxx @@ -150,8 +150,6 @@ Debugger::~Debugger() delete myBreakPoints; delete myReadTraps; delete myWriteTraps; - - myStaticDebugger = nullptr; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx index e359b50db..002eb884a 100644 --- a/src/emucore/Console.cxx +++ b/src/emucore/Console.cxx @@ -896,11 +896,11 @@ void Console::toggleFixedColors() const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Console::addDebugger() +void Console::attachDebugger(Debugger& dbg) { #ifdef DEBUGGER_SUPPORT - myOSystem.createDebugger(*this); - mySystem->m6502().attach(myOSystem.debugger()); +// myOSystem.createDebugger(*this); + mySystem->m6502().attach(dbg); #endif } diff --git a/src/emucore/Console.hxx b/src/emucore/Console.hxx index 0528987d8..047e616d7 100644 --- a/src/emucore/Console.hxx +++ b/src/emucore/Console.hxx @@ -28,6 +28,7 @@ class M6502; class M6532; class Cartridge; class CompuMate; +class Debugger; #include "bspf.hxx" #include "Control.hxx" @@ -164,7 +165,7 @@ class Console : public Serializable /** Set up the console to use the debugger. */ - void addDebugger(); + void attachDebugger(Debugger& dbg); /** Informs the Console of a change in EventHandler state. diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index be9c9d872..99eda2c02 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -904,10 +904,7 @@ void EventHandler::handleEvent(Event::Type event, int state) // Go back to the launcher, or immediately quit if(myOSystem.settings().getBool("exitlauncher") || myOSystem.launcherUsed()) - { - myOSystem.deleteConsole(); myOSystem.createLauncher(); - } else handleEvent(Event::Quit, 1); } diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index c46987e46..f4cd15022 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -61,12 +61,7 @@ OSystem::OSystem() : myConsole(nullptr), myLauncherUsed(false), - myDebugger(nullptr), - myQuitLoop(false), - myRomFile(""), - myRomMD5(""), - myFeatures(""), - myBuildInfo("") + myQuitLoop(false) { // Calculate startup time myMillisAtStart = (uInt32)(time(NULL) * 1000); @@ -102,11 +97,6 @@ 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() { // Ask all subsystems to save their settings - if(myFrameBuffer) - myFrameBuffer->tiaSurface().ntsc().saveConfig(*mySettings); + myFrameBuffer->tiaSurface().ntsc().saveConfig(*mySettings); 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() { @@ -309,9 +288,6 @@ void OSystem::createSound() string OSystem::createConsole(const FilesystemNode& rom, const string& md5sum, bool newrom) { - // Do a little error checking; it shouldn't be necessary - if(myConsole) deleteConsole(); - bool showmessage = false; // 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; 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); } catch(const char* err_msg) { - myConsole = 0; buf << "ERROR: Couldn't create console (" << err_msg << ")"; logMessage(buf.str(), 0); return buf.str(); @@ -348,7 +328,9 @@ string OSystem::createConsole(const FilesystemNode& rom, const string& md5sum, if(myConsole) { #ifdef DEBUGGER_SUPPORT - myConsole->addDebugger(); + myDebugger = make_ptr(*this, *myConsole); + myDebugger->initialize(); + myConsole->attachDebugger(*myDebugger); #endif #ifdef CHEATCODE_SUPPORT myCheatManager->loadCheats(myRomMD5); @@ -372,7 +354,7 @@ string OSystem::createConsole(const FilesystemNode& rom, const string& md5sum, } buf << "Game console created:" << endl << " ROM file: " << myRomFile.getShortPath() << endl << endl - << getROMInfo(myConsole) << endl; + << getROMInfo(*myConsole) << endl; logMessage(buf.str(), 1); // Update the timing info for a new console run @@ -418,42 +400,18 @@ string OSystem::createConsole(const FilesystemNode& rom, const string& md5sum, 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() { - deleteConsole(); return createConsole(myRomFile, myRomMD5, false) == EmptyString; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool OSystem::createLauncher(const string& startdir) { + if(mySound) + mySound->close(); + mySettings->setValue("tmpromdir", startdir); bool status = false; @@ -479,7 +437,7 @@ bool OSystem::createLauncher(const string& startdir) string OSystem::getROMInfo(const FilesystemNode& romfile) { string md5, type, id, result = ""; - Console* console = 0; + unique_ptr console; try { console = openConsole(romfile, md5, type, id); @@ -491,8 +449,7 @@ string OSystem::getROMInfo(const FilesystemNode& romfile) return buf.str(); } - result = getROMInfo(console); - delete console; + result = getROMInfo(*console); return result; } @@ -513,14 +470,14 @@ void OSystem::logMessage(const string& message, uInt8 level) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Console* OSystem::openConsole(const FilesystemNode& romfile, string& md5, - string& type, string& id) +unique_ptr OSystem::openConsole(const FilesystemNode& romfile, + string& md5, string& type, string& id) { #define CMDLINE_PROPS_UPDATE(cl_name, prop_name) \ s = mySettings->getString(cl_name); \ if(s != "") props.set(prop_name, s); - Console* console = nullptr; + unique_ptr console; // Open the cartridge image and read it in uInt8* image = 0; @@ -573,7 +530,7 @@ Console* OSystem::openConsole(const FilesystemNode& romfile, string& md5, // Finally, create the cart with the correct properties if(cart) - console = new Console(*this, cart, props); + console = make_ptr(*this, cart, props); } // 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 // contain a valid name - uInt8* image = 0; + uInt8* image = nullptr; if((size = rom.read(image)) == 0) { delete[] image; - return (uInt8*) 0; + return nullptr; } // 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; buf << " Cart Name: " << info.CartName << endl @@ -719,6 +676,14 @@ void OSystem::mainLoop() myTimingInfo.totalFrames++; } } + + // Cleanup time +#ifdef CHEATCODE_SUPPORT + if(myConsole) + myCheatManager->saveCheats(myConsole->properties().get(Cartridge_MD5)); + + myCheatManager->saveCheatDatabase(); +#endif } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/OSystem.hxx b/src/emucore/OSystem.hxx index 5fa4067a7..4d757caf2 100644 --- a/src/emucore/OSystem.hxx +++ b/src/emucore/OSystem.hxx @@ -199,11 +199,6 @@ class OSystem void saveConfig(); #ifdef DEBUGGER_SUPPORT - /** - Create all child objects which belong to this OSystem - */ - void createDebugger(Console& console); - /** Get the ROM debugger of the system. @@ -320,12 +315,6 @@ class OSystem string createConsole(const FilesystemNode& rom, const string& md5 = "", 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). This can be thought of as a real console off/on toggle. @@ -475,7 +464,7 @@ class OSystem unique_ptr myPropSet; // Pointer to the (currently defined) Console object - Console* myConsole; + unique_ptr myConsole; // Pointer to the serial port object unique_ptr mySerialPort; @@ -491,7 +480,7 @@ class OSystem bool myLauncherUsed; // Pointer to the Debugger object - Debugger* myDebugger; + unique_ptr myDebugger; // Pointer to the CheatManager object unique_ptr myCheatManager; @@ -564,11 +553,10 @@ class OSystem @param type The bankswitch type of the ROM @param id The additional id (if any) used by the ROM - @return The actual Console object, otherwise nullptr - (calling method is responsible for deleting it) + @return The actual Console object, otherwise nullptr. */ - Console* openConsole(const FilesystemNode& romfile, string& md5, - string& type, string& id); + unique_ptr openConsole(const FilesystemNode& romfile, string& md5, + string& type, string& id); /** Open the given ROM and return an array containing its contents. @@ -591,7 +579,7 @@ class OSystem @param console The console to use @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