diff --git a/stella/src/emucore/OSystem.cxx b/stella/src/emucore/OSystem.cxx index 014222a6c..5665fd58b 100644 --- a/stella/src/emucore/OSystem.cxx +++ b/stella/src/emucore/OSystem.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: OSystem.cxx,v 1.17 2005-05-18 16:02:53 stephena Exp $ +// $Id: OSystem.cxx,v 1.18 2005-05-18 22:35:36 stephena Exp $ //============================================================================ #include @@ -92,6 +92,22 @@ OSystem::~OSystem() delete mySound; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void OSystem::setBaseDir(const string& basedir) +{ + myBaseDir = basedir; + if(!fileExists(myBaseDir)) + makeDir(myBaseDir); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void OSystem::setStateDir(const string& statedir) +{ + myStateDir = statedir; + if(!fileExists(myStateDir)) + makeDir(myStateDir); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void OSystem::setPropertiesFiles(const string& userprops, const string& systemprops) diff --git a/stella/src/emucore/OSystem.hxx b/stella/src/emucore/OSystem.hxx index 67b994bed..a19a0aac4 100644 --- a/stella/src/emucore/OSystem.hxx +++ b/stella/src/emucore/OSystem.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: OSystem.hxx,v 1.15 2005-05-17 18:42:23 stephena Exp $ +// $Id: OSystem.hxx,v 1.16 2005-05-18 22:35:37 stephena Exp $ //============================================================================ #ifndef OSYSTEM_HXX @@ -38,7 +38,7 @@ class Launcher; other objects belong. @author Stephen Anthony - @version $Id: OSystem.hxx,v 1.15 2005-05-17 18:42:23 stephena Exp $ + @version $Id: OSystem.hxx,v 1.16 2005-05-18 22:35:37 stephena Exp $ */ class OSystem { @@ -148,31 +148,6 @@ class OSystem */ uInt32 frameRate() { return myDisplayFrameRate; } - /** - Set the base directory for all configuration files - */ - void setBaseDir(const string& basedir) { myBaseDir = basedir; } - - /** - Set the directory where state files are stored - */ - void setStateDir(const string& statedir) { myStateDir = statedir; } - - /** - Set the locations of game properties files - */ - void setPropertiesFiles(const string& userprops, const string& systemprops); - - /** - Set the locations of config files - */ - void setConfigFiles(const string& userconfig, const string& systemconfig); - - /** - Set the location of the gamelist cache file - */ - void setCacheFile(const string& cachefile) { myGameListCacheFile = cachefile; } - /** Return the default directory for storing data. */ @@ -303,6 +278,8 @@ class OSystem */ virtual string stateFilename(const string& md5, uInt32 state) = 0; +///////////////////////////////////////////////////// +// FIXME - move these to FSNode as static methods /** This method should be called to test whether the given file exists. @@ -320,6 +297,33 @@ class OSystem @return boolean representing whether or not the directory was created */ virtual bool makeDir(const string& path) = 0; +///////////////////////////////////////////////////// + + protected: + /** + Set the base directory for all Stella files + */ + void setBaseDir(const string& basedir); + + /** + Set the directory where state files are stored + */ + void setStateDir(const string& statedir); + + /** + Set the locations of game properties files + */ + void setPropertiesFiles(const string& userprops, const string& systemprops); + + /** + Set the locations of config files + */ + void setConfigFiles(const string& userconfig, const string& systemconfig); + + /** + Set the location of the gamelist cache file + */ + void setCacheFile(const string& cachefile) { myGameListCacheFile = cachefile; } protected: // Pointer to the EventHandler object diff --git a/stella/src/unix/OSystemUNIX.cxx b/stella/src/unix/OSystemUNIX.cxx index 59d3b2d0d..587e5c812 100644 --- a/stella/src/unix/OSystemUNIX.cxx +++ b/stella/src/unix/OSystemUNIX.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: OSystemUNIX.cxx,v 1.7 2005-05-11 19:36:00 stephena Exp $ +// $Id: OSystemUNIX.cxx,v 1.8 2005-05-18 22:35:37 stephena Exp $ //============================================================================ #include @@ -33,31 +33,38 @@ #include #endif +/** + Each derived class is responsible for calling the following methods + in its constructor: + + setBaseDir() + setStateDir() + setPropertiesFiles() + setConfigFiles() + setCacheFile() + + See OSystem.hxx for a further explanation +*/ + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - OSystemUNIX::OSystemUNIX() { // First set variables that the OSystem needs - string basedir = getenv("HOME"); + string basedir = string(getenv("HOME")) + "/.stella"; setBaseDir(basedir); - string stelladir = basedir + "/.stella"; - if(!fileExists(stelladir)) - makeDir(stelladir); - - string statedir = stelladir + "/state/"; - if(!fileExists(statedir)) - makeDir(statedir); + string statedir = basedir + "/state"; setStateDir(statedir); - string userPropertiesFile = stelladir + "/stella.pro"; + string userPropertiesFile = basedir + "/stella.pro"; string systemPropertiesFile = "/etc/stella.pro"; setPropertiesFiles(userPropertiesFile, systemPropertiesFile); - string userConfigFile = stelladir + "/stellarc"; + string userConfigFile = basedir + "/stellarc"; string systemConfigFile = "/etc/stellarc"; setConfigFiles(userConfigFile, systemConfigFile); - string cacheFile = stelladir + "/stella.cache"; + string cacheFile = basedir + "/stella.cache"; setCacheFile(cacheFile); } diff --git a/stella/src/unix/OSystemUNIX.hxx b/stella/src/unix/OSystemUNIX.hxx index ac4bd9902..233bba307 100644 --- a/stella/src/unix/OSystemUNIX.hxx +++ b/stella/src/unix/OSystemUNIX.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: OSystemUNIX.hxx,v 1.5 2005-05-05 00:10:49 stephena Exp $ +// $Id: OSystemUNIX.hxx,v 1.6 2005-05-18 22:35:37 stephena Exp $ //============================================================================ #ifndef OSYSTEM_UNIX_HXX @@ -26,7 +26,7 @@ This class defines UNIX-like OS's (Linux) system specific settings. @author Stephen Anthony - @version $Id: OSystemUNIX.hxx,v 1.5 2005-05-05 00:10:49 stephena Exp $ + @version $Id: OSystemUNIX.hxx,v 1.6 2005-05-18 22:35:37 stephena Exp $ */ class OSystemUNIX : public OSystem { @@ -67,7 +67,6 @@ class OSystemUNIX : public OSystem */ virtual string stateFilename(const string& md5, uInt32 state); - /** This method should be called to test whether the given file exists. diff --git a/stella/src/win32/OSystemWin32.cxx b/stella/src/win32/OSystemWin32.cxx new file mode 100644 index 000000000..c43931c1e --- /dev/null +++ b/stella/src/win32/OSystemWin32.cxx @@ -0,0 +1,160 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-1999 by Bradford W. Mott +// +// See the file "license" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +// +// $Id: OSystemWin32.cxx,v 1.1 2005-05-18 22:35:37 stephena Exp $ +//============================================================================ + +#include +#include +#include + +#include "bspf.hxx" +#include "OSystem.hxx" +#include "OSystemWin32.hxx" + +/** + Each derived class is responsible for calling the following methods + in its constructor: + + setBaseDir() + setStateDir() + setPropertiesFiles() + setConfigFiles() + setCacheFile() + + See OSystem.hxx for a further explanation +*/ + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +OSystemWin32::OSystemWin32() +{ + // FIXME - there really should be code here to determine which version + // of Windows is being used. + // If using a version which supports multiple users (NT and above), + // the relevant directories should be created in per-user locations. + // For now, we just put it in the same directory as the executable. + + string basedir = ".\\"; + setBaseDir(basedir); + + string stateDir = basedir + "state\\"; + setStateDir(stateDir); + + string propsFile = basedir + "stella.pro"; + setPropertiesFiles(propsFile, propsFile); // Input and output are the same + + string configFile = basedir + "stella.ini"; + setConfigFiles(configFile, configFile); // Input and output are the same + + string cacheFile = basedir + "stella.cache"; + setCacheFile(cacheFile); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +OSystemWin32::~OSystemWin32() +{ +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void OSystemWin32::mainLoop() +{ + // These variables are common to both timing options + // and are needed to calculate the overall frames per second. + uInt32 frameTime = 0, numberOfFrames = 0; + + // Set up less accurate timing stuff + uInt32 startTime, virtualTime, currentTime; + + // Set the base for the timers + virtualTime = getTicks(); + frameTime = 0; + + // Main game loop + for(;;) + { + // Exit if the user wants to quit + if(myEventHandler->doExitGame() || myEventHandler->doQuit()) + break; + + startTime = getTicks(); + myEventHandler->poll(); + myFrameBuffer->update(); + + currentTime = getTicks(); + virtualTime += myTimePerFrame; + if(currentTime < virtualTime) + { + SDL_Delay((virtualTime - currentTime)/1000); + } + + currentTime = getTicks() - startTime; + frameTime += currentTime; + ++numberOfFrames; + } + + // Only print console information if a console was actually created + if(mySettings->getBool("showinfo") && myConsole) + { + double executionTime = (double) frameTime / 1000000.0; + double framesPerSecond = (double) numberOfFrames / executionTime; + + cout << endl; + cout << numberOfFrames << " total frames drawn\n"; + cout << framesPerSecond << " frames/second\n"; + cout << endl; + cout << "Cartridge Name: " << myConsole->properties().get("Cartridge.Name"); + cout << endl; + cout << "Cartridge MD5: " << myConsole->properties().get("Cartridge.MD5"); + cout << endl << endl; + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +uInt32 OSystemWin32::getTicks() +{ + return (uInt32) SDL_GetTicks() * 1000; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +string OSystemWin32::stateFilename(const string& md5, uInt32 state) +{ + ostringstream buf; + buf << stateDir() << "\\" << md5 << ".st" << state; + + return buf.str(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool OSystemWin32::fileExists(const string& filename) +{ + // FIXME - Since I don't have time to figure out the correct + // and fast 'Win32' way of doing this, I'll cheat a bit + ifstream in(filename.c_str()); + if(in) + { + in.close(); + return true; + } + + return false; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool OSystemWin32::makeDir(const string& path) +{ + // FIXME + _mkdir(path.c_str()); + return true; +} diff --git a/stella/src/win32/OSystemWin32.hxx b/stella/src/win32/OSystemWin32.hxx new file mode 100644 index 000000000..b47a1d013 --- /dev/null +++ b/stella/src/win32/OSystemWin32.hxx @@ -0,0 +1,90 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-1999 by Bradford W. Mott +// +// See the file "license" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +// +// $Id: OSystemWin32.hxx,v 1.1 2005-05-18 22:35:37 stephena Exp $ +//============================================================================ + +#ifndef OSYSTEM_WIN32_HXX +#define OSYSTEM_WIN32_HXX + +#include "bspf.hxx" + + +/** + This class defines Windows system specific settings. + + @author Stephen Anthony + @version $Id: OSystemWin32.hxx,v 1.1 2005-05-18 22:35:37 stephena Exp $ +*/ +class OSystemWin32 : public OSystem +{ + public: + /** + Create a new Win32 operating system object + */ + OSystemWin32(); + + /** + Destructor + */ + virtual ~OSystemWin32(); + + public: + /** + This method runs the main loop. Since different platforms + may use different timing methods and/or algorithms, this method has + been abstracted to each platform. + */ + virtual void mainLoop(); + + /** + This method returns number of ticks in microseconds. + + @return Current time in microseconds. + */ + virtual uInt32 getTicks(); + + /** + 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(const string& md5, uInt32 state); + + + /** + This method should be called to test whether the given file exists. + + @param filename The filename to test for existence. + + @return boolean representing whether or not the file exists + */ + virtual bool fileExists(const string& filename); + + /** + This method should be called to create the specified directory. + + @param path The directory to create + + @return boolean representing whether or not the directory was created + */ + virtual bool makeDir(const string& path); +}; + +#endif diff --git a/stella/src/win32/SettingsWin32.cxx b/stella/src/win32/SettingsWin32.cxx index c427bbdf1..546858a11 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.13 2005-05-02 19:36:05 stephena Exp $ +// $Id: SettingsWin32.cxx,v 1.14 2005-05-18 22:35:37 stephena Exp $ //============================================================================ #include @@ -27,83 +27,11 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SettingsWin32::SettingsWin32() { - // FIXME - there really should be code here to determine which version - // of Windows is being used. - // If using a version which supports multiple users (NT and above), - // the relevant directories should be created in per-user locations. - // For now, we just put it in the same directory as the executable. - - // First set variables that the parent class needs - myBaseDir = ".\\"; - string stelladir = myBaseDir; - - myStateDir = stelladir + "state\\"; - _mkdir(myStateDir.c_str()); - - string userPropertiesFile = stelladir + "stella.pro"; -// string systemPropertiesFile = stelladir + "stella.pro"; - string userConfigFile = stelladir + "stella.ini"; -// string systemConfigFile = stelladir + "stella.ini"; - - // Set up the names of the input and output config files - myConfigOutputFile = userConfigFile; - if(fileExists(userConfigFile)) - myConfigInputFile = userConfigFile; -// else if(fileExists(systemConfigFile)) -// myConfigInputFile = systemConfigFile; - else - myConfigInputFile = ""; - - // Set up the input and output properties files - myPropertiesOutputFile = userPropertiesFile; - if(fileExists(userPropertiesFile)) - myPropertiesInputFile = userPropertiesFile; -// else if(fileExists(systemPropertiesFile)) -// myPropertiesInputFile = systemPropertiesFile; - else - myPropertiesInputFile = ""; - - // Now create Win32 specific settings set("video_driver", "windib"); // This seems to be much faster than DirectX - set("romdir", "roms"); - set("fragsize", "2048"); // Anything less than this usually causes sound skipping -#ifdef SNAPSHOT_SUPPORT - set("ssdir", ".\\"); -#endif - - // These settings are for the StellaX frontend - // If you don't use StellaX, the following settings are ignored - set("sortcol", "0"); - set("namecolwidth", "0"); - set("manufacturercolwidth", "0"); - set("raritycolwidth", "0"); + set("fragsize", "2048"); // Anything less than this usually causes sound skipping } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SettingsWin32::~SettingsWin32() { } - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string SettingsWin32::stateFilename(const string& md5, uInt32 state) -{ - ostringstream buf; - buf << myStateDir << md5 << ".st" << state; - - return buf.str(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool SettingsWin32::fileExists(const string& filename) -{ - // FIXME - Since I don't have time to figure out the correct - // and fast 'Win32' way of doing this, I'll cheat a bit - ifstream in(filename.c_str()); - if(in) - { - in.close(); - return true; - } - - return false; -} diff --git a/stella/src/win32/SettingsWin32.hxx b/stella/src/win32/SettingsWin32.hxx index fca1607ed..8655b3587 100644 --- a/stella/src/win32/SettingsWin32.hxx +++ b/stella/src/win32/SettingsWin32.hxx @@ -13,54 +13,29 @@ // 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.4 2004-07-05 00:53:48 stephena Exp $ +// $Id: SettingsWin32.hxx,v 1.5 2005-05-18 22:35:37 stephena Exp $ //============================================================================ #ifndef SETTINGS_WIN32_HXX #define SETTINGS_WIN32_HXX +class OSystem; + #include "bspf.hxx" -/** - This class defines Windows system specific settings. - - @author Stephen Anthony - @version $Id: SettingsWin32.hxx,v 1.4 2004-07-05 00:53:48 stephena Exp $ -*/ class SettingsWin32 : public Settings { public: /** Create a new UNIX settings object */ - SettingsWin32(); + SettingsWin32(OSystem* osystem); /** Destructor */ virtual ~SettingsWin32(); - - public: - /** - 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(const string& md5, uInt32 state); - - /** - This method should be called to test whether the given file exists. - - @param filename The filename to test for existence. - - @return boolean representing whether or not the file exists - */ - virtual bool fileExists(const string& filename); }; #endif