mirror of https://github.com/stella-emu/stella.git
Some small code cleanups in preparation for the 1.3 release.
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@156 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
fd2dc1e33b
commit
c41a53ac7c
|
@ -13,7 +13,7 @@
|
||||||
// See the file "license" for information on usage and redistribution of
|
// See the file "license" for information on usage and redistribution of
|
||||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||||
//
|
//
|
||||||
// $Id: mainSDL.cxx,v 1.40 2002-12-01 17:06:18 stephena Exp $
|
// $Id: mainSDL.cxx,v 1.41 2002-12-05 16:46:14 stephena Exp $
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
@ -221,8 +221,13 @@ static bool isCentered = false;
|
||||||
// Indicates the current state to use for state saving
|
// Indicates the current state to use for state saving
|
||||||
static uInt32 currentState = 0;
|
static uInt32 currentState = 0;
|
||||||
|
|
||||||
|
// The locations for various required files
|
||||||
|
static string homeDir;
|
||||||
|
static string stateDir;
|
||||||
static string homePropertiesFile;
|
static string homePropertiesFile;
|
||||||
static string systemPropertiesFile;
|
static string systemPropertiesFile;
|
||||||
|
static string homeRCFile;
|
||||||
|
static string systemRCFile;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -279,7 +284,7 @@ bool setupDisplay()
|
||||||
snapshot = new Snapshot();
|
snapshot = new Snapshot();
|
||||||
|
|
||||||
if(settings->theSnapShotDir == "")
|
if(settings->theSnapShotDir == "")
|
||||||
settings->theSnapShotDir = getenv("HOME");
|
settings->theSnapShotDir = homeDir;
|
||||||
if(settings->theSnapShotName == "")
|
if(settings->theSnapShotName == "")
|
||||||
settings->theSnapShotName = "romname";
|
settings->theSnapShotName = "romname";
|
||||||
#endif
|
#endif
|
||||||
|
@ -626,7 +631,7 @@ void togglePause()
|
||||||
thePauseIndicator = true;
|
thePauseIndicator = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pause the console and the audio
|
// Pause the console
|
||||||
theConsole->mediaSource().pause(thePauseIndicator);
|
theConsole->mediaSource().pause(thePauseIndicator);
|
||||||
|
|
||||||
// Show a different palette depending on pause state
|
// Show a different palette depending on pause state
|
||||||
|
@ -665,7 +670,7 @@ void saveState()
|
||||||
{
|
{
|
||||||
ostringstream buf;
|
ostringstream buf;
|
||||||
string md5 = theConsole->properties().get("Cartridge.MD5");
|
string md5 = theConsole->properties().get("Cartridge.MD5");
|
||||||
buf << getenv("HOME") << "/.stella/state/" << md5 << ".st" << currentState;
|
buf << stateDir << md5 << ".st" << currentState;
|
||||||
string filename = buf.str();
|
string filename = buf.str();
|
||||||
|
|
||||||
// Do a state save using the System
|
// Do a state save using the System
|
||||||
|
@ -722,7 +727,7 @@ void loadState()
|
||||||
{
|
{
|
||||||
ostringstream buf;
|
ostringstream buf;
|
||||||
string md5 = theConsole->properties().get("Cartridge.MD5");
|
string md5 = theConsole->properties().get("Cartridge.MD5");
|
||||||
buf << getenv("HOME") << "/.stella/state/" << md5 << ".st" << currentState;
|
buf << stateDir << md5 << ".st" << currentState;
|
||||||
string filename = buf.str();
|
string filename = buf.str();
|
||||||
|
|
||||||
// Do a state load using the System
|
// Do a state load using the System
|
||||||
|
@ -1048,8 +1053,7 @@ void handleEvents()
|
||||||
}
|
}
|
||||||
else // Save to file in home directory
|
else // Save to file in home directory
|
||||||
{
|
{
|
||||||
string newPropertiesFile = getenv("HOME");
|
string newPropertiesFile = homeDir + "/" + \
|
||||||
newPropertiesFile = newPropertiesFile + "/" + \
|
|
||||||
theConsole->properties().get("Cartridge.Name") + ".pro";
|
theConsole->properties().get("Cartridge.Name") + ".pro";
|
||||||
replace(newPropertiesFile.begin(), newPropertiesFile.end(), ' ', '_');
|
replace(newPropertiesFile.begin(), newPropertiesFile.end(), ' ', '_');
|
||||||
theConsole->saveProperties(newPropertiesFile);
|
theConsole->saveProperties(newPropertiesFile);
|
||||||
|
@ -1450,7 +1454,7 @@ void usage()
|
||||||
#else
|
#else
|
||||||
" -paddle <0|1|2|3> Indicates which paddle the mouse should emulate",
|
" -paddle <0|1|2|3> Indicates which paddle the mouse should emulate",
|
||||||
#endif
|
#endif
|
||||||
" -showinfo <0|1> Shows some game info on exit",
|
" -showinfo <0|1> Shows some game info",
|
||||||
#ifdef HAVE_PNG
|
#ifdef HAVE_PNG
|
||||||
" -ssdir <path> The directory to save snapshot files to",
|
" -ssdir <path> The directory to save snapshot files to",
|
||||||
" -ssname <name> How to name the snapshot (romname or md5sum)",
|
" -ssname <name> How to name the snapshot (romname or md5sum)",
|
||||||
|
@ -1465,7 +1469,7 @@ void usage()
|
||||||
" alsa ALSA version 0.9 driver",
|
" alsa ALSA version 0.9 driver",
|
||||||
#endif
|
#endif
|
||||||
#ifdef SOUND_OSS
|
#ifdef SOUND_OSS
|
||||||
" oss Open Sound System driver (most compatible)",
|
" oss Open Sound System driver",
|
||||||
#endif
|
#endif
|
||||||
#ifdef SOUND_SDL
|
#ifdef SOUND_SDL
|
||||||
" sdl Native SDL driver",
|
" sdl Native SDL driver",
|
||||||
|
@ -1552,17 +1556,14 @@ bool setupProperties(PropertiesSet& set)
|
||||||
*/
|
*/
|
||||||
void handleRCFile()
|
void handleRCFile()
|
||||||
{
|
{
|
||||||
string homeRCFile = getenv("HOME");
|
|
||||||
homeRCFile += "/.stella/stellarc";
|
|
||||||
|
|
||||||
if(access(homeRCFile.c_str(), R_OK) == 0 )
|
if(access(homeRCFile.c_str(), R_OK) == 0 )
|
||||||
{
|
{
|
||||||
ifstream homeStream(homeRCFile.c_str());
|
ifstream homeStream(homeRCFile.c_str());
|
||||||
settings->handleRCFile(homeStream);
|
settings->handleRCFile(homeStream);
|
||||||
}
|
}
|
||||||
else if(access("/etc/stellarc", R_OK) == 0 )
|
else if(access(systemRCFile.c_str(), R_OK) == 0 )
|
||||||
{
|
{
|
||||||
ifstream systemStream("/etc/stellarc");
|
ifstream systemStream(systemRCFile.c_str());
|
||||||
settings->handleRCFile(systemStream);
|
settings->handleRCFile(systemStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1588,7 +1589,10 @@ void cleanup()
|
||||||
delete rectList;
|
delete rectList;
|
||||||
|
|
||||||
if(sound)
|
if(sound)
|
||||||
|
{
|
||||||
|
sound->closeDevice();
|
||||||
delete sound;
|
delete sound;
|
||||||
|
}
|
||||||
|
|
||||||
if(SDL_WasInit(SDL_INIT_EVERYTHING))
|
if(SDL_WasInit(SDL_INIT_EVERYTHING))
|
||||||
{
|
{
|
||||||
|
@ -1604,36 +1608,17 @@ void cleanup()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Returns number of ticks in microseconds
|
|
||||||
*/
|
|
||||||
#ifdef HAVE_GETTIMEOFDAY
|
|
||||||
inline uInt32 getTicks()
|
|
||||||
{
|
|
||||||
timeval now;
|
|
||||||
gettimeofday(&now, 0);
|
|
||||||
|
|
||||||
return (uInt32) (now.tv_sec * 1000000 + now.tv_usec);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
inline uInt32 getTicks()
|
|
||||||
{
|
|
||||||
return (uInt32) SDL_GetTicks() * 1000;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates some directories under $HOME.
|
Creates some directories under $HOME.
|
||||||
Required directories are $HOME/.stella and $HOME/.stella/state
|
Required directories are $HOME/.stella and $HOME/.stella/state
|
||||||
Also sets up various locations for properties files, etc.
|
Also sets up various locations for properties files, etc.
|
||||||
|
|
||||||
|
This must be called before any other function.
|
||||||
*/
|
*/
|
||||||
bool setupDirs()
|
bool setupDirs()
|
||||||
{
|
{
|
||||||
string path;
|
homeDir = getenv("HOME");
|
||||||
|
string path = homeDir + "/.stella";
|
||||||
path = getenv("HOME");
|
|
||||||
path += "/.stella";
|
|
||||||
|
|
||||||
if(access(path.c_str(), R_OK|W_OK|X_OK) != 0 )
|
if(access(path.c_str(), R_OK|W_OK|X_OK) != 0 )
|
||||||
{
|
{
|
||||||
|
@ -1641,16 +1626,17 @@ bool setupDirs()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
path += "/state";
|
stateDir = homeDir + "/.stella/state/";
|
||||||
if(access(path.c_str(), R_OK|W_OK|X_OK) != 0 )
|
if(access(stateDir.c_str(), R_OK|W_OK|X_OK) != 0 )
|
||||||
{
|
{
|
||||||
if(mkdir(path.c_str(), 0777) != 0)
|
if(mkdir(stateDir.c_str(), 0777) != 0)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
homePropertiesFile = getenv("HOME");
|
homePropertiesFile = homeDir + "/.stella/stella.pro";
|
||||||
homePropertiesFile += "/.stella/stella.pro";
|
|
||||||
systemPropertiesFile = "/etc/stella.pro";
|
systemPropertiesFile = "/etc/stella.pro";
|
||||||
|
homeRCFile = homeDir + "/.stella/stellarc";
|
||||||
|
systemRCFile = "/etc/stellarc";
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1748,7 +1734,7 @@ int main(int argc, char* argv[])
|
||||||
else // a driver that doesn't exist was requested, so disable sound
|
else // a driver that doesn't exist was requested, so disable sound
|
||||||
{
|
{
|
||||||
cerr << "ERROR: Sound support for "
|
cerr << "ERROR: Sound support for "
|
||||||
<< settings->theSoundDriver << " disabled.\n";
|
<< settings->theSoundDriver << " not available.\n";
|
||||||
sound = new Sound();
|
sound = new Sound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1774,14 +1760,12 @@ int main(int argc, char* argv[])
|
||||||
if(!setupDisplay())
|
if(!setupDisplay())
|
||||||
{
|
{
|
||||||
cerr << "ERROR: Couldn't set up display.\n";
|
cerr << "ERROR: Couldn't set up display.\n";
|
||||||
sound->closeDevice();
|
|
||||||
cleanup();
|
cleanup();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(!setupJoystick())
|
if(!setupJoystick())
|
||||||
{
|
{
|
||||||
cerr << "ERROR: Couldn't set up joysticks.\n";
|
cerr << "ERROR: Couldn't set up joysticks.\n";
|
||||||
sound->closeDevice();
|
|
||||||
cleanup();
|
cleanup();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1892,7 +1876,25 @@ int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup time ...
|
// Cleanup time ...
|
||||||
sound->closeDevice();
|
|
||||||
cleanup();
|
cleanup();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns number of ticks in microseconds
|
||||||
|
*/
|
||||||
|
#ifdef HAVE_GETTIMEOFDAY
|
||||||
|
inline uInt32 getTicks()
|
||||||
|
{
|
||||||
|
timeval now;
|
||||||
|
gettimeofday(&now, 0);
|
||||||
|
|
||||||
|
return (uInt32) (now.tv_sec * 1000000 + now.tv_usec);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
inline uInt32 getTicks()
|
||||||
|
{
|
||||||
|
return (uInt32) SDL_GetTicks() * 1000;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
// See the file "license" for information on usage and redistribution of
|
// See the file "license" for information on usage and redistribution of
|
||||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||||
//
|
//
|
||||||
// $Id: mainX11.cxx,v 1.35 2002-12-01 17:06:18 stephena Exp $
|
// $Id: mainX11.cxx,v 1.36 2002-12-05 16:46:14 stephena Exp $
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
@ -221,8 +221,13 @@ static bool isCentered = false;
|
||||||
// Indicates the current state to use for state saving
|
// Indicates the current state to use for state saving
|
||||||
static uInt32 currentState = 0;
|
static uInt32 currentState = 0;
|
||||||
|
|
||||||
|
// The locations for various required files
|
||||||
|
static string homeDir;
|
||||||
|
static string stateDir;
|
||||||
static string homePropertiesFile;
|
static string homePropertiesFile;
|
||||||
static string systemPropertiesFile;
|
static string systemPropertiesFile;
|
||||||
|
static string homeRCFile;
|
||||||
|
static string systemRCFile;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -354,7 +359,7 @@ bool setupDisplay()
|
||||||
snapshot = new Snapshot();
|
snapshot = new Snapshot();
|
||||||
|
|
||||||
if(settings->theSnapShotDir == "")
|
if(settings->theSnapShotDir == "")
|
||||||
settings->theSnapShotDir = getenv("HOME");
|
settings->theSnapShotDir = homeDir;
|
||||||
if(settings->theSnapShotName == "")
|
if(settings->theSnapShotName == "")
|
||||||
settings->theSnapShotName = "romname";
|
settings->theSnapShotName = "romname";
|
||||||
#endif
|
#endif
|
||||||
|
@ -722,8 +727,7 @@ void handleEvents()
|
||||||
}
|
}
|
||||||
else // Save to file in home directory
|
else // Save to file in home directory
|
||||||
{
|
{
|
||||||
string newPropertiesFile = getenv("HOME");
|
string newPropertiesFile = homeDir + "/" + \
|
||||||
newPropertiesFile = newPropertiesFile + "/" + \
|
|
||||||
theConsole->properties().get("Cartridge.Name") + ".pro";
|
theConsole->properties().get("Cartridge.Name") + ".pro";
|
||||||
replace(newPropertiesFile.begin(), newPropertiesFile.end(), ' ', '_');
|
replace(newPropertiesFile.begin(), newPropertiesFile.end(), ' ', '_');
|
||||||
theConsole->saveProperties(newPropertiesFile);
|
theConsole->saveProperties(newPropertiesFile);
|
||||||
|
@ -1068,7 +1072,7 @@ void saveState()
|
||||||
{
|
{
|
||||||
ostringstream buf;
|
ostringstream buf;
|
||||||
string md5 = theConsole->properties().get("Cartridge.MD5");
|
string md5 = theConsole->properties().get("Cartridge.MD5");
|
||||||
buf << getenv("HOME") << "/.stella/state/" << md5 << ".st" << currentState;
|
buf << stateDir << md5 << ".st" << currentState;
|
||||||
string filename = buf.str();
|
string filename = buf.str();
|
||||||
|
|
||||||
// Do a state save using the System
|
// Do a state save using the System
|
||||||
|
@ -1123,7 +1127,7 @@ void loadState()
|
||||||
{
|
{
|
||||||
ostringstream buf;
|
ostringstream buf;
|
||||||
string md5 = theConsole->properties().get("Cartridge.MD5");
|
string md5 = theConsole->properties().get("Cartridge.MD5");
|
||||||
buf << getenv("HOME") << "/.stella/state/" << md5 << ".st" << currentState;
|
buf << stateDir << md5 << ".st" << currentState;
|
||||||
string filename = buf.str();
|
string filename = buf.str();
|
||||||
|
|
||||||
// Do a state load using the System
|
// Do a state load using the System
|
||||||
|
@ -1353,7 +1357,7 @@ void usage()
|
||||||
#else
|
#else
|
||||||
" -paddle <0|1|2|3> Indicates which paddle the mouse should emulate",
|
" -paddle <0|1|2|3> Indicates which paddle the mouse should emulate",
|
||||||
#endif
|
#endif
|
||||||
" -showinfo <0|1> Shows some game info on exit",
|
" -showinfo <0|1> Shows some game info",
|
||||||
#ifdef HAVE_PNG
|
#ifdef HAVE_PNG
|
||||||
" -ssdir <path> The directory to save snapshot files to",
|
" -ssdir <path> The directory to save snapshot files to",
|
||||||
" -ssname <name> How to name the snapshot (romname or md5sum)",
|
" -ssname <name> How to name the snapshot (romname or md5sum)",
|
||||||
|
@ -1368,7 +1372,7 @@ void usage()
|
||||||
" alsa ALSA version 0.9 driver",
|
" alsa ALSA version 0.9 driver",
|
||||||
#endif
|
#endif
|
||||||
#ifdef SOUND_OSS
|
#ifdef SOUND_OSS
|
||||||
" oss Open Sound System driver (most compatible)",
|
" oss Open Sound System driver",
|
||||||
#endif
|
#endif
|
||||||
"",
|
"",
|
||||||
#ifdef DEVELOPER_SUPPORT
|
#ifdef DEVELOPER_SUPPORT
|
||||||
|
@ -1450,17 +1454,14 @@ bool setupProperties(PropertiesSet& set)
|
||||||
*/
|
*/
|
||||||
void handleRCFile()
|
void handleRCFile()
|
||||||
{
|
{
|
||||||
string homeRCFile = getenv("HOME");
|
|
||||||
homeRCFile += "/.stella/stellarc";
|
|
||||||
|
|
||||||
if(access(homeRCFile.c_str(), R_OK) == 0 )
|
if(access(homeRCFile.c_str(), R_OK) == 0 )
|
||||||
{
|
{
|
||||||
ifstream homeStream(homeRCFile.c_str());
|
ifstream homeStream(homeRCFile.c_str());
|
||||||
settings->handleRCFile(homeStream);
|
settings->handleRCFile(homeStream);
|
||||||
}
|
}
|
||||||
else if(access("/etc/stellarc", R_OK) == 0 )
|
else if(access(systemRCFile.c_str(), R_OK) == 0 )
|
||||||
{
|
{
|
||||||
ifstream systemStream("/etc/stellarc");
|
ifstream systemStream(systemRCFile.c_str());
|
||||||
settings->handleRCFile(systemStream);
|
settings->handleRCFile(systemStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1482,7 +1483,10 @@ void cleanup()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(sound)
|
if(sound)
|
||||||
|
{
|
||||||
|
sound->closeDevice();
|
||||||
delete sound;
|
delete sound;
|
||||||
|
}
|
||||||
|
|
||||||
if(normalCursor)
|
if(normalCursor)
|
||||||
XFreeCursor(theDisplay, normalCursor);
|
XFreeCursor(theDisplay, normalCursor);
|
||||||
|
@ -1508,13 +1512,13 @@ void cleanup()
|
||||||
Creates some directories under $HOME.
|
Creates some directories under $HOME.
|
||||||
Required directories are $HOME/.stella and $HOME/.stella/state
|
Required directories are $HOME/.stella and $HOME/.stella/state
|
||||||
Also sets up various locations for properties files, etc.
|
Also sets up various locations for properties files, etc.
|
||||||
|
|
||||||
|
This must be called before any other function.
|
||||||
*/
|
*/
|
||||||
bool setupDirs()
|
bool setupDirs()
|
||||||
{
|
{
|
||||||
string path;
|
homeDir = getenv("HOME");
|
||||||
|
string path = homeDir + "/.stella";
|
||||||
path = getenv("HOME");
|
|
||||||
path += "/.stella";
|
|
||||||
|
|
||||||
if(access(path.c_str(), R_OK|W_OK|X_OK) != 0 )
|
if(access(path.c_str(), R_OK|W_OK|X_OK) != 0 )
|
||||||
{
|
{
|
||||||
|
@ -1522,16 +1526,17 @@ bool setupDirs()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
path += "/state";
|
stateDir = homeDir + "/.stella/state/";
|
||||||
if(access(path.c_str(), R_OK|W_OK|X_OK) != 0 )
|
if(access(stateDir.c_str(), R_OK|W_OK|X_OK) != 0 )
|
||||||
{
|
{
|
||||||
if(mkdir(path.c_str(), 0777) != 0)
|
if(mkdir(stateDir.c_str(), 0777) != 0)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
homePropertiesFile = getenv("HOME");
|
homePropertiesFile = homeDir + "/.stella/stella.pro";
|
||||||
homePropertiesFile += "/.stella/stella.pro";
|
|
||||||
systemPropertiesFile = "/etc/stella.pro";
|
systemPropertiesFile = "/etc/stella.pro";
|
||||||
|
homeRCFile = homeDir + "/.stella/stellarc";
|
||||||
|
systemRCFile = "/etc/stellarc";
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1620,7 +1625,7 @@ int main(int argc, char* argv[])
|
||||||
else // a driver that doesn't exist was requested, so disable sound
|
else // a driver that doesn't exist was requested, so disable sound
|
||||||
{
|
{
|
||||||
cerr << "ERROR: Sound support for "
|
cerr << "ERROR: Sound support for "
|
||||||
<< settings->theSoundDriver << " disabled.\n";
|
<< settings->theSoundDriver << " not available.\n";
|
||||||
sound = new Sound();
|
sound = new Sound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue