Preparations for addition of the Snapshot class to the core.

git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@182 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2003-09-12 18:08:54 +00:00
parent b1c31fdd1a
commit 14de7f7e62
16 changed files with 185 additions and 342 deletions

View File

@ -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: makefile,v 1.37 2003-09-11 20:53:51 stephena Exp $
## $Id: makefile,v 1.38 2003-09-12 18:08:52 stephena Exp $
##============================================================================
##============================================================================
@ -30,9 +30,9 @@ OPTIMIZATIONS = $(CXXFLAGS) -Wall -Wno-unused
### SDL sound not yet supported in the X11 version
### comment out all lines to completely disable sound
###
SOUND_ALSA = 1
SOUND_OSS = 1
SOUND_SDL = 1
#SOUND_ALSA = 1
#SOUND_OSS = 1
#SOUND_SDL = 1
### if your C++ compiler doesn't support the bool type
# BSPF_BOOL = 1
@ -47,8 +47,8 @@ SOUND_SDL = 1
JOYSTICK_SUPPORT = 1
### to include support for saving snapshots in png format
### (requires PNG library)
### Only X11 and SDL ports supported for now
### (requires PNG library) FIXME
### Only X11 and SDL ports supported for now FIXME
SNAPSHOT_SUPPORT = 1
### comment this out if your system doesn't
@ -118,11 +118,11 @@ endif
ifdef SNAPSHOT_SUPPORT
OBJS.X11 += Snapshot.o
OPTS.X11 += -DHAVE_PNG=1
OPTS.X11 += -DSNAPSHOT_SUPPORT=1
LIBS.X11 += -lpng -lz
OBJS.SDL += Snapshot.o
OPTS.SDL += -DHAVE_PNG=1
OPTS.SDL += -DSNAPSHOT_SUPPORT=1
LIBS.SDL += -lpng -lz
endif

View File

@ -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.13 2003-09-07 18:30:28 stephena Exp $
// $Id: Console.cxx,v 1.14 2003-09-12 18:08:53 stephena Exp $
//============================================================================
#include <assert.h>
@ -44,6 +44,10 @@
#include "System.hxx"
#include "TIA.hxx"
#ifdef SNAPSHOT_SUPPORT
#include "Snapshot.hxx"
#endif
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Console::Console(const uInt8* image, uInt32 size, const char* filename,
Settings& rcsettings, PropertiesSet& propertiesSet, Frontend& frontend,
@ -69,6 +73,11 @@ Console::Console(const uInt8* image, uInt32 size, const char* filename,
myEventHandler = new EventHandler(this);
myEvent = myEventHandler->event();
#ifdef SNAPSHOT_SUPPORT
// Create a snapshot object which will handle taking snapshots
mySnapshot = new Snapshot();
#endif
// Get the MD5 message-digest for the ROM image
string md5 = MD5(image, size);
@ -163,9 +172,6 @@ Console::Console(const uInt8* image, uInt32 size, const char* filename,
// Remember what my media source is
myMediaSource = tia;
// Let the event handler know about the mediasource
myEventHandler->setMediaSource(myMediaSource);
// Reset, the system to its power-on state
mySystem->reset();
}

View File

@ -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.hxx,v 1.9 2003-09-07 18:30:28 stephena Exp $
// $Id: Console.hxx,v 1.10 2003-09-12 18:08:53 stephena Exp $
//============================================================================
#ifndef CONSOLE_HXX
@ -27,6 +27,7 @@ class Frontend;
class MediaSource;
class PropertiesSet;
class Settings;
class Snapshot;
class Sound;
class Switches;
class System;
@ -35,11 +36,12 @@ class System;
#include "Control.hxx"
#include "Props.hxx"
/**
This class represents the entire game console.
@author Bradford W. Mott
@version $Id: Console.hxx,v 1.9 2003-09-07 18:30:28 stephena Exp $
@version $Id: Console.hxx,v 1.10 2003-09-12 18:08:53 stephena Exp $
*/
class Console
{
@ -160,6 +162,22 @@ class Console
*/
static const Properties& defaultProperties();
#ifdef SNAPSHOT_SUPPORT
public:
// Pointer to the Snapshot object
Snapshot* mySnapshot;
/**
Get the snapshot object of the console
@return The snapshot object for this console
*/
Snapshot& snapshot() const
{
return *mySnapshot;
}
#endif
#ifdef DEVELOPER_SUPPORT
public:
/**

View File

@ -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.5 2003-09-07 18:30:28 stephena Exp $
// $Id: EventHandler.cxx,v 1.6 2003-09-12 18:08:53 stephena Exp $
//============================================================================
#include <algorithm>
@ -29,6 +29,9 @@
#include "System.hxx"
#include "bspf.hxx"
#ifdef SNAPSHOT_SUPPORT
#include "Snapshot.hxx"
#endif
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EventHandler::EventHandler(Console* console)
@ -76,12 +79,6 @@ Event* EventHandler::event()
return myEvent;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::setMediaSource(MediaSource* mediaSource)
{
myMediaSource = mediaSource;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::sendKeyEvent(StellaEvent::KeyCode key, Int32 state)
{
@ -110,11 +107,11 @@ void EventHandler::sendKeyEvent(StellaEvent::KeyCode key, Int32 state)
loadState();
return;
}
// else if(event == Event::TakeSnapshot)
// {
// FIXME ... make a call to takeSnapshot()
// return;
// }
else if(event == Event::TakeSnapshot)
{
takeSnapshot();
return;
}
else if(event == Event::Pause)
{
myConsole->frontend().setPauseEvent();
@ -128,7 +125,7 @@ void EventHandler::sendKeyEvent(StellaEvent::KeyCode key, Int32 state)
}
if(ourMessageTable[event] != "")
myMediaSource->showMessage(ourMessageTable[event], 120);
myConsole->mediaSource().showMessage(ourMessageTable[event], 120);
}
// Otherwise, pass it to the emulation core
@ -164,11 +161,11 @@ void EventHandler::sendJoyEvent(StellaEvent::JoyStick stick,
loadState();
return;
}
// else if(event == Event::TakeSnapshot)
// {
// FIXME ... make a call to takeSnapshot()
// return;
// }
else if(event == Event::TakeSnapshot)
{
takeSnapshot();
return;
}
else if(event == Event::Pause)
{
myConsole->frontend().setPauseEvent();
@ -182,7 +179,7 @@ void EventHandler::sendJoyEvent(StellaEvent::JoyStick stick,
}
if(ourMessageTable[event] != "")
myMediaSource->showMessage(ourMessageTable[event], 120);
myConsole->mediaSource().showMessage(ourMessageTable[event], 120);
}
// Otherwise, pass it to the emulation core
@ -408,7 +405,7 @@ void EventHandler::saveState()
buf << "Invalid state " << myCurrentState << " file";
string message = buf.str();
myMediaSource->showMessage(message, 120);
myConsole->mediaSource().showMessage(message, 120);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -423,7 +420,7 @@ void EventHandler::changeState()
ostringstream buf;
buf << "Changed to slot " << myCurrentState;
string message = buf.str();
myMediaSource->showMessage(message, 120);
myConsole->mediaSource().showMessage(message, 120);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -444,5 +441,24 @@ void EventHandler::loadState()
buf << "Invalid state " << myCurrentState << " file";
string message = buf.str();
myMediaSource->showMessage(message, 120);
myConsole->mediaSource().showMessage(message, 120);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::takeSnapshot()
{
#ifdef SNAPSHOT_SUPPORT
string message, filename;
// Now save the snapshot file
filename = myConsole->frontend().snapshotFilename();
myConsole->snapshot().savePNG(filename, myConsole->mediaSource(),
myConsole->settings().theZoomLevel);
message = "Snapshot saved";
myConsole->mediaSource().showMessage(message, 120);
#else
string message = "Snapshots unsupported";
myConsole->mediaSource().showMessage(message, 120);
#endif
}

View File

@ -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.hxx,v 1.5 2003-09-07 18:30:28 stephena Exp $
// $Id: EventHandler.hxx,v 1.6 2003-09-12 18:08:53 stephena Exp $
//============================================================================
#ifndef EVENTHANDLER_HXX
@ -40,7 +40,7 @@ class MediaSource;
unchanged to the remap class, where key remapping can take place.
@author Stephen Anthony
@version $Id: EventHandler.hxx,v 1.5 2003-09-07 18:30:28 stephena Exp $
@version $Id: EventHandler.hxx,v 1.6 2003-09-12 18:08:53 stephena Exp $
*/
class EventHandler
{
@ -122,6 +122,7 @@ class EventHandler
void saveState();
void changeState();
void loadState();
void takeSnapshot();
private:
// Array of key events

View File

@ -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: Frontend.hxx,v 1.4 2003-09-11 20:53:51 stephena Exp $
// $Id: Frontend.hxx,v 1.5 2003-09-12 18:08:53 stephena Exp $
//============================================================================
#ifndef FRONTEND_HXX
@ -27,7 +27,7 @@ class Console;
This class provides an interface for accessing frontend specific data.
@author Stephen Anthony
@version $Id: Frontend.hxx,v 1.4 2003-09-11 20:53:51 stephena Exp $
@version $Id: Frontend.hxx,v 1.5 2003-09-12 18:08:53 stephena Exp $
*/
class Frontend
{
@ -84,12 +84,11 @@ class Frontend
virtual string stateFilename(string& md5, uInt32 state) = 0;
/**
This method should be called to get the filename of a snapshot
file given the md5 and state number.
This method should be called to get the filename of a snapshot.
@return String representing the full path of the snapshot filename.
*/
virtual string snapshotFilename(string& md5, uInt32 state) = 0;
virtual string snapshotFilename() = 0;
/**
This method should be called to get the filename of the users

View File

@ -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.3 2003-09-11 20:53:51 stephena Exp $
// $Id: Settings.cxx,v 1.4 2003-09-12 18:08:53 stephena Exp $
//============================================================================
#include "bspf.hxx"
@ -22,6 +22,12 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Settings::Settings()
{
theKeymapList = "";
theJoymapList = "";
theSnapshotDir = "";
theSnapshotName = "romname";
theMultipleSnapshotFlag = true;
theZoomLevel = 1;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -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.3 2003-09-11 20:53:51 stephena Exp $
// $Id: Settings.hxx,v 1.4 2003-09-12 18:08:53 stephena Exp $
//============================================================================
#ifndef SETTINGS_HXX
@ -32,7 +32,7 @@ class Console;
This class provides an interface for accessing frontend specific settings.
@author Stephen Anthony
@version $Id: Settings.hxx,v 1.3 2003-09-11 20:53:51 stephena Exp $
@version $Id: Settings.hxx,v 1.4 2003-09-12 18:08:53 stephena Exp $
*/
class Settings
{
@ -68,7 +68,7 @@ class Settings
virtual void setConsole(Console* console) = 0;
public:
// The following settings are used by the emulation core and are
// The following settings are needed by the emulation core and are
// common among all settings objects
// The keymap to use
@ -77,6 +77,19 @@ class Settings
// The joymap to use
string theJoymapList;
// The path to save snapshot files
string theSnapshotDir;
// What the snapshot should be called (romname or md5sum)
string theSnapshotName;
// Indicates whether to generate multiple snapshots or keep
// overwriting the same file.
bool theMultipleSnapshotFlag;
// The amount the of zoom for the window/screen
uInt32 theZoomLevel;
#ifdef DEVELOPER_SUPPORT
// User-modified properties
Properties userDefinedProperties;

View File

@ -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 2003-09-11 20:53:51 stephena Exp $
// $Id: SettingsUNIX.cxx,v 1.2 2003-09-12 18:08:53 stephena Exp $
//============================================================================
#include <fstream>
@ -34,24 +34,18 @@ SettingsUNIX::SettingsUNIX(const string& infile, const string& outfile)
: mySettingsInputFilename(infile),
mySettingsOutputFilename(outfile)
{
theKeymapList = "";
theJoymapList = "";
theUseFullScreenFlag = false;
theGrabMouseFlag = false;
theCenterWindowFlag = false;
theShowInfoFlag = false;
theHideCursorFlag = false;
theUsePrivateColormapFlag = false;
theMultipleSnapShotFlag = true;
theAccurateTimingFlag = true;
theDesiredVolume = -1;
theDesiredFrameRate = 60;
thePaddleMode = 0;
theAlternateProFile = "";
theSnapShotDir = "";
theSnapShotName = "";
theSoundDriver = "oss";
theWindowSize = 1;
theLeftJoystickNumber = 0;
theRightJoystickNumber = 1;
@ -146,8 +140,8 @@ void SettingsUNIX::parseArg(string& key, string& value)
{
// They're setting the desired frame rate
uInt32 rate = atoi(value.c_str());
if((rate < 1) || (rate > 300))
cout << "Invalid rate " << rate << " (1-300)\n";
if(rate < 1)
cout << "Invalid rate " << rate << endl;
else
theDesiredFrameRate = rate;
}
@ -225,11 +219,11 @@ void SettingsUNIX::parseArg(string& key, string& value)
else if(key == "zoom")
{
// They're setting the initial window size
uInt32 size = atoi(value.c_str());
if((size < 1) || (size > 4))
cout << "Invalid zoom value " << size << " (1-4)\n";
uInt32 zoom = atoi(value.c_str());
if(zoom < 1)
cout << "Invalid zoom value " << zoom << endl;
else
theWindowSize = size;
theZoomLevel = zoom;
}
else if(key == "volume")
{
@ -244,19 +238,22 @@ void SettingsUNIX::parseArg(string& key, string& value)
}
else if(key == "ssdir")
{
theSnapShotDir = value;
theSnapshotDir = value;
}
else if(key == "ssname")
{
theSnapShotName = value;
if((value != "md5sum") && (value != "romname"))
cout << "Invalid snapshot name " << value << endl;
else
theSnapshotName = value;
}
else if(key == "sssingle")
{
uInt32 option = atoi(value.c_str());
if(option == 1)
theMultipleSnapShotFlag = false;
theMultipleSnapshotFlag = false;
else if(option == 0)
theMultipleSnapShotFlag = true;
theMultipleSnapshotFlag = true;
}
else if(key == "sound")
{
@ -324,11 +321,11 @@ void SettingsUNIX::save()
<< "center = " << theCenterWindowFlag << endl
<< "showinfo = " << theShowInfoFlag << endl
<< "accurate = " << theAccurateTimingFlag << endl
<< "zoom = " << theWindowSize << endl
<< "zoom = " << theZoomLevel << endl
<< "volume = " << theDesiredVolume << endl
<< "ssdir = " << theSnapShotDir << endl
<< "ssname = " << theSnapShotName << endl
<< "sssingle = " << theMultipleSnapShotFlag << endl
<< "ssdir = " << theSnapshotDir << endl
<< "ssname = " << theSnapshotName << endl
<< "sssingle = " << theMultipleSnapshotFlag << endl
<< "sound = " << theSoundDriver << endl
#ifdef DEVELOPER_SUPPORT
<< "Dmerge = " << theMergePropertiesFlag << endl

View File

@ -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 2003-09-11 20:53:51 stephena Exp $
// $Id: SettingsUNIX.hxx,v 1.2 2003-09-12 18:08:54 stephena Exp $
//============================================================================
#ifndef SETTINGS_UNIX_HXX
@ -28,7 +28,7 @@ class Console;
This class defines UNIX-like OS's (Linux) system specific settings.
@author Stephen Anthony
@version $Id: SettingsUNIX.hxx,v 1.1 2003-09-11 20:53:51 stephena Exp $
@version $Id: SettingsUNIX.hxx,v 1.2 2003-09-12 18:08:54 stephena Exp $
*/
class SettingsUNIX : public Settings
{
@ -86,10 +86,6 @@ class SettingsUNIX : public Settings
// Indicates whether to allocate colors from a private color map
bool theUsePrivateColormapFlag;
// Indicates whether to generate multiple snapshots or keep
// overwriting the same file. Set to true by default.
bool theMultipleSnapShotFlag;
// Indicates whether to use more/less accurate emulation,
// resulting in more/less CPU usage.
bool theAccurateTimingFlag;
@ -111,18 +107,9 @@ class SettingsUNIX : public Settings
// An alternate properties file to use
string theAlternateProFile;
// The path to save snapshot files
string theSnapShotDir;
// What the snapshot should be called (romname or md5sum)
string theSnapShotName;
// Indicates which sound driver to use at run-time
string theSoundDriver;
// The size of the window/screen
uInt32 theWindowSize;
// The left joystick number (0 .. StellaEvent::LastJSTICK)
Int32 theLeftJoystickNumber;

View File

@ -13,13 +13,14 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Snapshot.cxx,v 1.4 2002-12-05 16:44:56 stephena Exp $
// $Id: Snapshot.cxx,v 1.5 2003-09-12 18:08:54 stephena Exp $
//============================================================================
#include <png.h>
#include <iostream>
#include <fstream>
#include "bspf.hxx"
#include "Snapshot.hxx"
@ -60,7 +61,7 @@ void Snapshot::png_user_error(png_structp ctx, png_const_charp str)
This routine saves the current frame buffer to a 256 color PNG file,
appropriately scaled by the amount specified in 'multiplier'.
*/
int Snapshot::savePNG(string filename, MediaSource& mediaSource, int multiplier)
int Snapshot::savePNG(string filename, MediaSource& mediaSource, uInt32 multiplier)
{
png_structp png_ptr = 0;
png_infop info_ptr = 0;

View File

@ -13,15 +13,15 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Snapshot.hxx,v 1.1 2002-03-10 01:29:54 stephena Exp $
// $Id: Snapshot.hxx,v 1.2 2003-09-12 18:08:54 stephena Exp $
//============================================================================
#ifndef SNAPSHOT_HXX
#define SNAPSHOT_HXX
#include <png.h>
#include <string>
#include "bspf.hxx"
#include "MediaSrc.hxx"
class Snapshot
@ -30,7 +30,7 @@ class Snapshot
Snapshot();
~Snapshot();
int savePNG(string filename, MediaSource& mediaSource, int multiplier = 1);
int savePNG(string filename, MediaSource& mediaSource, uInt32 multiplier = 1);
private:
static void png_write_data(png_structp ctx, png_bytep area, png_size_t size);

View File

@ -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: FrontendUNIX.cxx,v 1.2 2003-09-06 21:17:48 stephena Exp $
// $Id: FrontendUNIX.cxx,v 1.3 2003-09-12 18:08:54 stephena Exp $
//============================================================================
#include <cstdlib>
@ -26,11 +26,13 @@
#include "bspf.hxx"
#include "Console.hxx"
#include "FrontendUNIX.hxx"
#include "Settings.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FrontendUNIX::FrontendUNIX()
: myPauseIndicator(false),
myQuitIndicator(false)
myQuitIndicator(false),
myConsole(0)
{
myHomeDir = getenv("HOME");
string path = myHomeDir + "/.stella";
@ -97,8 +99,45 @@ string FrontendUNIX::stateFilename(string& md5, uInt32 state)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string FrontendUNIX::snapshotFilename(string& md5, uInt32 state)
string FrontendUNIX::snapshotFilename()
{
if(!myConsole)
return "";
string path = myConsole->settings().theSnapshotDir;
string filename;
if(myConsole->settings().theSnapshotName == "romname")
path = path + "/" + myConsole->properties().get("Cartridge.Name");
else if(myConsole->settings().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(myConsole->settings().theMultipleSnapshotFlag)
{
// 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;
}

View File

@ -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: FrontendUNIX.hxx,v 1.3 2003-09-07 18:30:28 stephena Exp $
// $Id: FrontendUNIX.hxx,v 1.4 2003-09-12 18:08:54 stephena Exp $
//============================================================================
#ifndef FRONTEND_UNIX_HXX
@ -29,7 +29,7 @@ class Console;
and events.
@author Stephen Anthony
@version $Id: FrontendUNIX.hxx,v 1.3 2003-09-07 18:30:28 stephena Exp $
@version $Id: FrontendUNIX.hxx,v 1.4 2003-09-12 18:08:54 stephena Exp $
*/
class FrontendUNIX : public Frontend
{
@ -80,13 +80,11 @@ class FrontendUNIX : public Frontend
virtual string stateFilename(string& md5, uInt32 state);
/**
Returns the UNIX filename representing a state file.
Returns the UNIX filename representing a snapshot file.
@param md5 The md5 string to use as part of the filename.
@param state The state number to use as part of the filename.
@return The full path and filename of the snapshot file.
*/
virtual string snapshotFilename(string& md5, uInt32 state);
virtual string snapshotFilename();
/**
Returns the UNIX filename representing a users properties file.

View File

@ -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: mainSDL.cxx,v 1.49 2003-09-11 20:53:51 stephena Exp $
// $Id: mainSDL.cxx,v 1.50 2003-09-12 18:08:54 stephena Exp $
//============================================================================
#include <fstream>
@ -54,10 +54,6 @@
#include "SoundSDL.hxx"
#endif
#ifdef HAVE_PNG
#include "Snapshot.hxx"
#endif
#ifdef UNIX
#include "FrontendUNIX.hxx"
#include "SettingsUNIX.hxx"
@ -112,8 +108,6 @@ static bool setupProperties(PropertiesSet& set);
static void handleRCFile();
static void usage();
static string theSnapShotDir, theSnapShotName;
#ifdef HAVE_JOYSTICK
static SDL_Joystick* theLeftJoystick = (SDL_Joystick*) NULL;
static SDL_Joystick* theRightJoystick = (SDL_Joystick*) NULL;
@ -123,10 +117,6 @@ static string theSnapShotDir, theSnapShotName;
#endif
#ifdef HAVE_PNG
static Snapshot* theSnapshot;
#endif
// Pointer to the console object or the null pointer
static Console* theConsole = (Console*) NULL;
@ -323,10 +313,10 @@ bool setupDisplay()
theMaxWindowSize = maxWindowSizeForScreen();
// Check to see if window size will fit in the screen
if(theSettings->theWindowSize > theMaxWindowSize)
if(theSettings->theZoomLevel > theMaxWindowSize)
theWindowSize = theMaxWindowSize;
else
theWindowSize = theSettings->theWindowSize;
theWindowSize = theSettings->theZoomLevel;
// Set up the rectangle list to be used in updateDisplay
rectList = new RectList();
@ -870,10 +860,6 @@ void handleEvents()
{
toggleFullscreen();
}
else if(key == SDLK_F12)
{
takeSnapshot();
}
else if((mod & KMOD_CTRL) && key == SDLK_g)
{
// don't change grabmouse in fullscreen mode
@ -1098,88 +1084,6 @@ void handleEvents()
}
/**
Called when the user wants to take a snapshot of the current display.
Images are stored in png format in the directory specified by the 'ssdir'
argument, or in $HOME by default.
Images are named consecutively as "NAME".png, where name is specified by
the 'ssname' argument. If that name exists, they are named as "Name"_x.png,
where x starts with 1 and increases if the previous name already exists.
All spaces in filenames are converted to underscore '_'.
If theMultipleSnapShotFlag is false, then consecutive images are overwritten.
*/
void takeSnapshot()
{
#ifdef HAVE_PNG
string message;
if(!theSnapshot)
{
message = "Snapshots disabled";
theConsole->mediaSource().showMessage(message, 120);
return;
}
// Now find the correct name for the snapshot
string path = theSnapShotDir;
string filename;
if(theSnapShotName == "romname")
path = path + "/" + theConsole->properties().get("Cartridge.Name");
else if(theSnapShotName == "md5sum")
path = path + "/" + theConsole->properties().get("Cartridge.MD5");
else
{
cerr << "ERROR: unknown name " << theSnapShotName
<< " for snapshot type" << endl;
return;
}
// Replace all spaces in name with underscores
replace(path.begin(), path.end(), ' ', '_');
// Check whether we want multiple snapshots created
if(theSettings->theMultipleSnapShotFlag)
{
// 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";
// Now save the snapshot file
theSnapshot->savePNG(filename, theConsole->mediaSource(), theWindowSize);
if(access(filename.c_str(), F_OK) == 0)
{
message = "Snapshot saved";
theConsole->mediaSource().showMessage(message, 120);
}
else
{
message = "Snapshot not saved";
theConsole->mediaSource().showMessage(message, 120);
}
#else
string message = "Snapshots unsupported";
theConsole->mediaSource().showMessage(message, 120);
#endif
}
/**
Calculate the maximum window size that the current screen can hold.
Only works in X11 for now. If not running under X11, always return 3.
@ -1217,7 +1121,7 @@ uInt32 maxWindowSizeForScreen()
}
if(found)
return (multiplier > 4 ? 4 : multiplier);
return multiplier;
else
return 1;
}
@ -1282,11 +1186,6 @@ void cleanup()
if(theConsole)
delete theConsole;
#ifdef HAVE_PNG
if(theSnapshot)
delete theSnapshot;
#endif
if(theSound)
{
theSound->closeDevice();
@ -1347,21 +1246,6 @@ int main(int argc, char* argv[])
return 0;
}
#ifdef HAVE_PNG
// Take care of the snapshot stuff.
theSnapshot = new Snapshot();
if(theSettings->theSnapShotDir == "")
theSnapShotDir = theFrontend->userHomeDir();
else
theSnapShotDir = theSettings->theSnapShotDir;
if(theSettings->theSnapShotName == "")
theSnapShotName = "romname";
else
theSnapShotName = theSettings->theSnapShotName;
#endif
// Get a pointer to the file which contains the cartridge ROM
const char* file = argv[argc - 1];

View File

@ -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: mainX11.cxx,v 1.40 2003-09-11 20:53:51 stephena Exp $
// $Id: mainX11.cxx,v 1.41 2003-09-12 18:08:54 stephena Exp $
//============================================================================
#include <fstream>
@ -22,8 +22,6 @@
#include <string>
#include <algorithm>
#include <unistd.h>
#ifdef HAVE_GETTIMEOFDAY
#include <time.h>
#include <sys/time.h>
@ -55,10 +53,6 @@
#include "SoundOSS.hxx"
#endif
#ifdef HAVE_PNG
#include "Snapshot.hxx"
#endif
#ifdef HAVE_JOYSTICK
#include <sys/types.h>
#include <sys/stat.h>
@ -104,23 +98,11 @@ static void cleanup();
static bool setupJoystick();
static void handleEvents();
static void takeSnapshot();
static uInt32 getTicks();
static bool setupProperties(PropertiesSet& set);
static void handleRCFile();
static void usage();
static void loadState();
static void saveState();
static void changeState(int direction);
static string theSnapShotDir, theSnapShotName;
#ifdef HAVE_PNG
static Snapshot* theSnapshot;
#endif
#ifdef HAVE_JOYSTICK
// File descriptors for the joystick devices
static int theLeftJoystickFd;
@ -327,10 +309,10 @@ bool setupDisplay()
theMaxWindowSize = maxWindowSizeForScreen();
// Check to see if window size will fit in the screen
if(theSettings->theWindowSize > theMaxWindowSize)
if(theSettings->theZoomLevel > theMaxWindowSize)
theWindowSize = theMaxWindowSize;
else
theWindowSize = theSettings->theWindowSize;
theWindowSize = theSettings->theZoomLevel;
// Figure out the desired size of the window
int width = theWidth * theWindowSize * 2;
@ -673,10 +655,6 @@ void handleEvents()
{
resizeWindow(0);
}
else if((key == XK_F12) && (event.type == KeyPress))
{
takeSnapshot();
}
// FIXME - change x to Ctrl-x
else if((key == XK_g) && (event.type == KeyPress))
{
@ -1091,86 +1069,6 @@ bool createCursors()
return true;
}
/**
Called when the user wants to take a snapshot of the current display.
Images are stored in png format in the directory specified by the 'ssdir'
argument, or in $HOME by default.
Images are named consecutively as "NAME".png, where name is specified by
the 'ssname' argument. If that name exists, they are named as "Name"_x.png,
where x starts with 1 and increases if the previous name already exists.
All spaces in filenames are converted to underscore '_'.
If theMultipleSnapShotFlag is false, then consecutive images are overwritten.
*/
void takeSnapshot()
{
#ifdef HAVE_PNG
string message;
if(!theSnapshot)
{
message = "Snapshots disabled";
theConsole->mediaSource().showMessage(message, 120);
return;
}
// Now find the correct name for the snapshot
string path = theSettings->theSnapShotDir;
string filename;
if(theSettings->theSnapShotName == "romname")
path = path + "/" + theConsole->properties().get("Cartridge.Name");
else if(theSettings->theSnapShotName == "md5sum")
path = path + "/" + theConsole->properties().get("Cartridge.MD5");
else
{
cerr << "ERROR: unknown name " << theSettings->theSnapShotName
<< " for snapshot type" << endl;
return;
}
// Replace all spaces in name with underscores
replace(path.begin(), path.end(), ' ', '_');
// Check whether we want multiple snapshots created
if(theSettings->theMultipleSnapShotFlag)
{
// 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";
// Now save the snapshot file
theSnapshot->savePNG(filename, theConsole->mediaSource(), theSettings->theWindowSize);
if(access(filename.c_str(), F_OK) == 0)
{
message = "Snapshot saved";
theConsole->mediaSource().showMessage(message, 120);
}
else
{
message = "Snapshot not saved";
theConsole->mediaSource().showMessage(message, 120);
}
#else
string message = "Snapshots unsupported";
theConsole->mediaSource().showMessage(message, 120);
#endif
}
/**
Calculate the maximum window size that the current screen can hold
@ -1261,11 +1159,6 @@ void cleanup()
if(theConsole)
delete theConsole;
#ifdef HAVE_PNG
if(theSnapshot)
delete theSnapshot;
#endif
if(theSound)
{
theSound->closeDevice();
@ -1333,21 +1226,6 @@ int main(int argc, char* argv[])
return 0;
}
#ifdef HAVE_PNG
// Take care of the snapshot stuff.
theSnapshot = new Snapshot();
if(theSettings->theSnapShotDir == "")
theSnapShotDir = theFrontend->userHomeDir();
else
theSnapShotDir = theSettings->theSnapShotDir;
if(theSettings->theSnapShotName == "")
theSnapShotName = "romname";
else
theSnapShotName = theSettings->theSnapShotName;
#endif
// Get a pointer to the file which contains the cartridge ROM
const char* file = argv[argc - 1];