diff --git a/stella/src/emucore/Console.cxx b/stella/src/emucore/Console.cxx index 7938ea237..6f3cd67ee 100644 --- a/stella/src/emucore/Console.cxx +++ b/stella/src/emucore/Console.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Console.cxx,v 1.27 2004-04-27 00:50:51 stephena Exp $ +// $Id: Console.cxx,v 1.28 2004-05-28 22:07:57 stephena Exp $ //============================================================================ #include @@ -65,9 +65,6 @@ Console::Console(const uInt8* image, uInt32 size, const char* filename, mySystem = 0; myEvent = 0; - // Inform the settings object about the console - mySettings.setConsole(this); - // Create an event handler which will collect and dispatch events myEventHandler = new EventHandler(this); myEvent = myEventHandler->event(); diff --git a/stella/src/emucore/EventHandler.cxx b/stella/src/emucore/EventHandler.cxx index 34b670b77..474928bfb 100644 --- a/stella/src/emucore/EventHandler.cxx +++ b/stella/src/emucore/EventHandler.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: EventHandler.cxx,v 1.24 2004-05-28 18:25:19 stephena Exp $ +// $Id: EventHandler.cxx,v 1.25 2004-05-28 22:07:57 stephena Exp $ //============================================================================ #include @@ -343,7 +343,7 @@ void EventHandler::saveState() // Do a state save using the System string md5 = myConsole->properties().get("Cartridge.MD5"); - string filename = myConsole->settings().stateFilename(myCurrentState); + string filename = myConsole->settings().stateFilename(md5, myCurrentState); int result = myConsole->system().saveState(filename, md5); // Print appropriate message @@ -380,7 +380,7 @@ void EventHandler::loadState() // Do a state save using the System string md5 = myConsole->properties().get("Cartridge.MD5"); - string filename = myConsole->settings().stateFilename(myCurrentState); + string filename = myConsole->settings().stateFilename(md5, myCurrentState); int result = myConsole->system().loadState(filename, md5); if(result == 1) @@ -397,8 +397,42 @@ void EventHandler::loadState() void EventHandler::takeSnapshot() { #ifdef SNAPSHOT_SUPPORT + // Figure out the correct snapshot name + string filename; + string sspath = myConsole->settings().getString("ssdir"); + string ssname = myConsole->settings().getString("ssname"); + + if(ssname == "romname") + sspath = sspath + BSPF_PATH_SEPARATOR + myConsole->properties().get("Cartridge.Name"); + else if(ssname == "md5sum") + sspath = sspath + BSPF_PATH_SEPARATOR + myConsole->properties().get("Cartridge.MD5"); + + // Replace all spaces in name with underscores + replace(sspath.begin(), sspath.end(), ' ', '_'); + + // Check whether we want multiple snapshots created + if(!myConsole->settings().getBool("sssingle")) + { + // Determine if the file already exists, checking each successive filename + // until one doesn't exist + filename = sspath + ".png"; + if(myConsole->settings().fileExists(filename)) + { + ostringstream buf; + for(uInt32 i = 1; ;++i) + { + buf.str(""); + buf << sspath << "_" << i << ".png"; + if(!myConsole->settings().fileExists(buf.str())) + break; + } + filename = buf.str(); + } + } + else + filename = sspath + ".png"; + // Now save the snapshot file - string filename = myConsole->settings().snapshotFilename(); uInt32 multiplier = myConsole->settings().getInt("zoom"); myConsole->snapshot().savePNG(filename, multiplier); diff --git a/stella/src/emucore/Settings.cxx b/stella/src/emucore/Settings.cxx index af1a39ab3..70f6e93a9 100644 --- a/stella/src/emucore/Settings.cxx +++ b/stella/src/emucore/Settings.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Settings.cxx,v 1.19 2004-04-27 00:50:51 stephena Exp $ +// $Id: Settings.cxx,v 1.20 2004-05-28 22:07:57 stephena Exp $ //============================================================================ #include @@ -21,8 +21,6 @@ #include #include "bspf.hxx" -#include "Console.hxx" -#include "EventHandler.hxx" #include "Settings.hxx" #ifdef DEVELOPER_SUPPORT @@ -32,7 +30,6 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Settings::Settings() - : myConsole(0) { // First create the settings array myCapacity = 30; diff --git a/stella/src/emucore/Settings.hxx b/stella/src/emucore/Settings.hxx index 0d338920f..df5ea2601 100644 --- a/stella/src/emucore/Settings.hxx +++ b/stella/src/emucore/Settings.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Settings.hxx,v 1.12 2004-04-21 16:27:18 stephena Exp $ +// $Id: Settings.hxx,v 1.13 2004-05-28 22:07:57 stephena Exp $ //============================================================================ #ifndef SETTINGS_HXX @@ -25,14 +25,12 @@ #include "bspf.hxx" -class Console; - /** This class provides an interface for accessing frontend specific settings. @author Stephen Anthony - @version $Id: Settings.hxx,v 1.12 2004-04-21 16:27:18 stephena Exp $ + @version $Id: Settings.hxx,v 1.13 2004-05-28 22:07:57 stephena Exp $ */ class Settings { @@ -145,16 +143,21 @@ class Settings This method should be called to get the filename of a state file given the state number. + @param md5 The md5sum to use as part of the filename. + @param state The state to use as part of the filename. + @return String representing the full path of the state filename. */ - virtual string stateFilename(uInt32 state) = 0; + virtual string stateFilename(const string& md5, uInt32 state) = 0; /** - This method should be called to get the filename of a snapshot. + This method should be called to test whether the given file exists. - @return String representing the full path of the snapshot filename. + @param filename The filename to test for existence. + + @return boolean representing whether or not the file exists */ - virtual string snapshotFilename() = 0; + virtual bool fileExists(const string& filename) = 0; /** This method should be called to display usage information. @@ -164,12 +167,6 @@ class Settings virtual void usage(string& message) = 0; public: - /** - This method should be called when the emulation core sets - the console object. - */ - void setConsole(Console* console) { myConsole = console; } - /** This method should be called to get the filename of the users' properties (stella.pro) file. @@ -225,9 +222,6 @@ class Settings string myUserConfigFile; string mySystemConfigFile; - // The global Console object - Console* myConsole; - // The full pathname of the settings file for input string mySettingsInputFilename; diff --git a/stella/src/emucore/m6502/src/bspf/src/bspf.hxx b/stella/src/emucore/m6502/src/bspf/src/bspf.hxx index ec89043b1..71854591a 100644 --- a/stella/src/emucore/m6502/src/bspf/src/bspf.hxx +++ b/stella/src/emucore/m6502/src/bspf/src/bspf.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: bspf.hxx,v 1.3 2002-04-10 04:07:39 bwmott Exp $ +// $Id: bspf.hxx,v 1.4 2004-05-28 22:07:57 stephena Exp $ //============================================================================ #ifndef BSPF_HXX @@ -24,7 +24,7 @@ that need to be defined for different operating systems. @author Bradford W. Mott - @version $Id: bspf.hxx,v 1.3 2002-04-10 04:07:39 bwmott Exp $ + @version $Id: bspf.hxx,v 1.4 2004-05-28 22:07:57 stephena Exp $ */ // Types for 8-bit signed and unsigned integers @@ -54,7 +54,7 @@ typedef unsigned int uInt32; #ifdef BSPF_WIN32 // pragma to avoid all of the int <-> bool conversion warnings - #pragma warning(disable: 4800) +// #pragma warning(disable: 4800) #endif // Some old compilers do not support the bool type @@ -66,12 +66,11 @@ typedef unsigned int uInt32; // Defines to help with path handling #if defined BSPF_UNIX - #define BSPF_PATH_SEPARATOR '/' + #define BSPF_PATH_SEPARATOR "/" #elif (defined(BSPF_DOS) || defined(BSPF_WIN32) || defined(BSPF_OS2)) - #define BSPF_PATH_SEPARATOR '\\' -#elif defined BSPF_MACOS - #define BSPF_PATH_SEPARATOR ':' + #define BSPF_PATH_SEPARATOR "\\" +#elif defined BSPF_MAC_OSX + #define BSPF_PATH_SEPARATOR ":" #endif #endif - diff --git a/stella/src/unix/SettingsUNIX.cxx b/stella/src/unix/SettingsUNIX.cxx index e317e4648..535c27db8 100644 --- a/stella/src/unix/SettingsUNIX.cxx +++ b/stella/src/unix/SettingsUNIX.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: SettingsUNIX.cxx,v 1.1 2004-05-24 17:18:23 stephena Exp $ +// $Id: SettingsUNIX.cxx,v 1.2 2004-05-28 22:07:57 stephena Exp $ //============================================================================ #include @@ -25,10 +25,6 @@ #include #include "bspf.hxx" -#include "Console.hxx" -#include "EventHandler.hxx" -#include "StellaEvent.hxx" - #include "Settings.hxx" #include "SettingsUNIX.hxx" @@ -39,11 +35,11 @@ SettingsUNIX::SettingsUNIX() myBaseDir = getenv("HOME"); string stelladir = myBaseDir + "/.stella"; - if(access(stelladir.c_str(), R_OK|W_OK|X_OK) != 0 ) + if(!fileExists(stelladir)) mkdir(stelladir.c_str(), 0777); myStateDir = stelladir + "/state/"; - if(access(myStateDir.c_str(), R_OK|W_OK|X_OK) != 0 ) + if(!fileExists(myStateDir)) mkdir(myStateDir.c_str(), 0777); myUserPropertiesFile = stelladir + "/stella.pro"; @@ -53,7 +49,7 @@ SettingsUNIX::SettingsUNIX() // Set up the names of the input and output config files mySettingsOutputFilename = myUserConfigFile; - if(access(myUserConfigFile.c_str(), R_OK) == 0) + if(fileExists(myUserConfigFile)) mySettingsInputFilename = myUserConfigFile; else mySettingsInputFilename = mySystemConfigFile; @@ -124,59 +120,18 @@ void SettingsUNIX::usage(string& message) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string SettingsUNIX::stateFilename(uInt32 state) +string SettingsUNIX::stateFilename(const string& md5, uInt32 state) { - if(!myConsole) - return ""; - ostringstream buf; - buf << myStateDir << myConsole->properties().get("Cartridge.MD5") - << ".st" << state; + buf << myStateDir << md5 << ".st" << state; myStateFile = buf.str(); + return myStateFile; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string SettingsUNIX::snapshotFilename() +bool SettingsUNIX::fileExists(const string& filename) { - if(!myConsole) - return ""; - - string filename; - string path = getString("ssdir"); - string theSnapshotName = getString("ssname"); - - if(theSnapshotName == "romname") - path = path + "/" + myConsole->properties().get("Cartridge.Name"); - else if(theSnapshotName == "md5sum") - path = path + "/" + myConsole->properties().get("Cartridge.MD5"); - - // Replace all spaces in name with underscores - replace(path.begin(), path.end(), ' ', '_'); - - // Check whether we want multiple snapshots created - if(!getBool("sssingle")) - { - // Determine if the file already exists, checking each successive filename - // until one doesn't exist - filename = path + ".png"; - if(access(filename.c_str(), F_OK) == 0 ) - { - ostringstream buf; - for(uInt32 i = 1; ;++i) - { - buf.str(""); - buf << path << "_" << i << ".png"; - if(access(buf.str().c_str(), F_OK) == -1 ) - break; - } - filename = buf.str(); - } - } - else - filename = path + ".png"; - - mySnapshotFile = filename; - return mySnapshotFile; + return (access(filename.c_str(), F_OK|W_OK) == 0); } diff --git a/stella/src/unix/SettingsUNIX.hxx b/stella/src/unix/SettingsUNIX.hxx index 6def00ab9..aaf6d7646 100644 --- a/stella/src/unix/SettingsUNIX.hxx +++ b/stella/src/unix/SettingsUNIX.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: SettingsUNIX.hxx,v 1.1 2004-05-24 17:18:23 stephena Exp $ +// $Id: SettingsUNIX.hxx,v 1.2 2004-05-28 22:07:57 stephena Exp $ //============================================================================ #ifndef SETTINGS_UNIX_HXX @@ -21,14 +21,12 @@ #include "bspf.hxx" -class Console; - /** This class defines UNIX-like OS's (Linux) system specific settings. @author Stephen Anthony - @version $Id: SettingsUNIX.hxx,v 1.1 2004-05-24 17:18:23 stephena Exp $ + @version $Id: SettingsUNIX.hxx,v 1.2 2004-05-28 22:07:57 stephena Exp $ */ class SettingsUNIX : public Settings { @@ -48,16 +46,22 @@ class SettingsUNIX : public Settings This method should be called to get the filename of a state file given the state number. + @param md5 The md5sum to use as part of the filename. + @param state The state to use as part of the filename. + @return String representing the full path of the state filename. */ - virtual string stateFilename(uInt32 state); + virtual string stateFilename(const string& md5, uInt32 state); + /** - This method should be called to get the filename of a snapshot. + This method should be called to test whether the given file exists. - @return String representing the full path of the snapshot filename. + @param filename The filename to test for existence. + + @return boolean representing whether or not the file exists */ - virtual string snapshotFilename(); + virtual bool fileExists(const string& filename); /** Display the commandline settings for this UNIX version of Stella. diff --git a/stella/src/win32/SettingsWin32.cxx b/stella/src/win32/SettingsWin32.cxx index 5ef1f380e..d6e5b38e5 100644 --- a/stella/src/win32/SettingsWin32.cxx +++ b/stella/src/win32/SettingsWin32.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: SettingsWin32.cxx,v 1.1 2004-05-24 17:18:23 stephena Exp $ +// $Id: SettingsWin32.cxx,v 1.2 2004-05-28 22:07:57 stephena Exp $ //============================================================================ #include @@ -25,10 +25,6 @@ #include #include "bspf.hxx" -#include "Console.hxx" -#include "EventHandler.hxx" -#include "StellaEvent.hxx" - #include "Settings.hxx" #include "SettingsWin32.hxx" @@ -130,59 +126,18 @@ void SettingsWin32::usage(string& message) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string SettingsWin32::stateFilename(uInt32 state) +string SettingsWin32::stateFilename(const string& md5, uInt32 state) { - if(!myConsole) - return ""; - ostringstream buf; - buf << myStateDir << myConsole->properties().get("Cartridge.MD5") - << ".st" << state; + buf << myStateDir << md5 << ".st" << state; myStateFile = buf.str(); + return myStateFile; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string SettingsWin32::snapshotFilename() +bool SettingsWin32::fileExists(const string& filename) { - if(!myConsole) - return ""; - - string filename; - string path = getString("ssdir"); - string theSnapshotName = getString("ssname"); - - if(theSnapshotName == "romname") - path = path + "\\" + myConsole->properties().get("Cartridge.Name"); - else if(theSnapshotName == "md5sum") - path = path + "\\" + myConsole->properties().get("Cartridge.MD5"); - - // Replace all spaces in name with underscores - replace(path.begin(), path.end(), ' ', '_'); - - // Check whether we want multiple snapshots created - if(!getBool("sssingle")) - { - // Determine if the file already exists, checking each successive filename - // until one doesn't exist - filename = path + ".png"; - if(access(filename.c_str(), F_OK) == 0 ) - { - ostringstream buf; - for(uInt32 i = 1; ;++i) - { - buf.str(""); - buf << path << "_" << i << ".png"; - if(access(buf.str().c_str(), F_OK) == -1 ) - break; - } - filename = buf.str(); - } - } - else - filename = path + ".png"; - - mySnapshotFile = filename; - return mySnapshotFile; + return false;//FIXME(access(filename.c_str(), F_OK|W_OK) == 0); } diff --git a/stella/src/win32/SettingsWin32.hxx b/stella/src/win32/SettingsWin32.hxx index 5543a58fd..4b7fbbd0f 100644 --- a/stella/src/win32/SettingsWin32.hxx +++ b/stella/src/win32/SettingsWin32.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: SettingsWin32.hxx,v 1.1 2004-05-24 17:18:23 stephena Exp $ +// $Id: SettingsWin32.hxx,v 1.2 2004-05-28 22:07:57 stephena Exp $ //============================================================================ #ifndef SETTINGS_WIN32_HXX @@ -21,14 +21,12 @@ #include "bspf.hxx" -class Console; - /** This class defines Windows system specific settings. @author Stephen Anthony - @version $Id: SettingsWin32.hxx,v 1.1 2004-05-24 17:18:23 stephena Exp $ + @version $Id: SettingsWin32.hxx,v 1.2 2004-05-28 22:07:57 stephena Exp $ */ class SettingsWin32 : public Settings { @@ -48,16 +46,21 @@ class SettingsWin32 : public Settings This method should be called to get the filename of a state file given the state number. + @param md5 The md5sum to use as part of the filename. + @param state The state to use as part of the filename. + @return String representing the full path of the state filename. */ - virtual string stateFilename(uInt32 state); + virtual string stateFilename(const string& md5, uInt32 state) = 0; /** - This method should be called to get the filename of a snapshot. + This method should be called to test whether the given file exists. - @return String representing the full path of the snapshot filename. + @param filename The filename to test for existence. + + @return boolean representing whether or not the file exists */ - virtual string snapshotFilename(); + virtual bool fileExists(const string& filename) = 0; /** Display the commandline settings for this UNIX version of Stella.