From f7e712386bf3392f289c27da10163e075ed26481 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Fri, 9 Dec 2016 19:04:14 -0330 Subject: [PATCH] Fixed bug with SaveKey and AtariVox not properly closing their memory files before starting another instance of the same ROM. --- src/emucore/AtariVox.cxx | 7 +++++++ src/emucore/AtariVox.hxx | 7 +++++++ src/emucore/Console.cxx | 3 +++ src/emucore/Control.hxx | 7 +++++++ src/emucore/OSystem.cxx | 1 + src/emucore/SaveKey.cxx | 7 +++++++ src/emucore/SaveKey.hxx | 7 +++++++ 7 files changed, 39 insertions(+) diff --git a/src/emucore/AtariVox.cxx b/src/emucore/AtariVox.cxx index 3d8d89ebf..c131eab9c 100644 --- a/src/emucore/AtariVox.cxx +++ b/src/emucore/AtariVox.cxx @@ -142,6 +142,13 @@ void AtariVox::clockDataIn(bool value) myLastDataWriteCycle = cycle; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void AtariVox::close() +{ + // Force the EEPROM object to cleanup + myEEPROM.reset(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void AtariVox::systemCyclesReset() { diff --git a/src/emucore/AtariVox.hxx b/src/emucore/AtariVox.hxx index 97c4459f0..390859ae0 100644 --- a/src/emucore/AtariVox.hxx +++ b/src/emucore/AtariVox.hxx @@ -82,6 +82,13 @@ class AtariVox : public Controller */ void update() override { } + /** + Notification method invoked by the system indicating that the + console is about to be destroyed. It may be necessary to override + this method for controllers that need cleanup before exiting. + */ + void close() override; + /** Notification method invoked by the system right before the system resets its cycle counter to zero. It may be necessary diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx index 30a534d83..542d3605f 100644 --- a/src/emucore/Console.cxx +++ b/src/emucore/Console.cxx @@ -172,6 +172,9 @@ Console::Console(OSystem& osystem, unique_ptr& cart, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Console::~Console() { + // Some smart controllers need to be informed that the console is going away + myLeftControl->close(); + myRightControl->close(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/Control.hxx b/src/emucore/Control.hxx index 6a30544f1..ee6ac6a46 100644 --- a/src/emucore/Control.hxx +++ b/src/emucore/Control.hxx @@ -167,6 +167,13 @@ class Controller : public Serializable */ virtual void update() = 0; + /** + Notification method invoked by the system indicating that the + console is about to be destroyed. It may be necessary to override + this method for controllers that need cleanup before exiting. + */ + virtual void close() { }; + /** Notification method invoked by the system right before the system resets its cycle counter to zero. It may be necessary diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index 4b5dd3eb4..d9a4730be 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -554,6 +554,7 @@ void OSystem::closeConsole() // If a previous console existed, save cheats before creating a new one myCheatManager->saveCheats(myConsole->properties().get(Cartridge_MD5)); #endif + myConsole.reset(); } } diff --git a/src/emucore/SaveKey.cxx b/src/emucore/SaveKey.cxx index fc5378722..ac6eb5772 100644 --- a/src/emucore/SaveKey.cxx +++ b/src/emucore/SaveKey.cxx @@ -75,6 +75,13 @@ void SaveKey::write(DigitalPin pin, bool value) } } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void SaveKey::close() +{ + // Force the EEPROM object to cleanup + myEEPROM.reset(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void SaveKey::systemCyclesReset() { diff --git a/src/emucore/SaveKey.hxx b/src/emucore/SaveKey.hxx index cb61b645c..e746aa452 100644 --- a/src/emucore/SaveKey.hxx +++ b/src/emucore/SaveKey.hxx @@ -77,6 +77,13 @@ class SaveKey : public Controller */ void update() override { } + /** + Notification method invoked by the system indicating that the + console is about to be destroyed. It may be necessary to override + this method for controllers that need cleanup before exiting. + */ + void close() override; + /** Notification method invoked by the system right before the system resets its cycle counter to zero. It may be necessary