Some more code cleanups related to key remapping. I think we may

lose the ability for Shift-F10 to cycle downwards through the
available states.

One other thing; the current CVS source won't compile for X11 or DOS,
and not everything works in SDL.  This can't be helped, as I'm fixing
the frontends one at a time.

Windows hasn't been able to compile for quite some time, and unless
someone looks at it soon, its going to get a serious case of bit-rot ...


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@175 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2003-09-04 23:23:06 +00:00
parent 69bb79776d
commit 3d45e5801e
4 changed files with 146 additions and 146 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: Event.hxx,v 1.1.1.1 2001-12-27 19:54:21 bwmott Exp $
// $Id: Event.hxx,v 1.2 2003-09-04 23:23:06 stephena Exp $
//============================================================================
#ifndef EVENT_HXX
@ -25,7 +25,7 @@ class Event;
/**
@author Bradford W. Mott
@version $Id: Event.hxx,v 1.1.1.1 2001-12-27 19:54:21 bwmott Exp $
@version $Id: Event.hxx,v 1.2 2003-09-04 23:23:06 stephena Exp $
*/
class Event
{
@ -66,6 +66,8 @@ class Event
DrivingZeroClockwise, DrivingZeroCounterClockwise, DrivingZeroFire,
DrivingOneClockwise, DrivingOneCounterClockwise, DrivingOneFire,
ChangeState, LoadState, SaveState, TakeSnapshot,
LastType
};

View File

@ -13,19 +13,24 @@
// 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.2 2003-09-04 16:50:48 stephena Exp $
// $Id: EventHandler.cxx,v 1.3 2003-09-04 23:23:06 stephena Exp $
//============================================================================
#include <sstream>
#include "Console.hxx"
#include "Event.hxx"
#include "StellaEvent.hxx"
#include "EventHandler.hxx"
#include "MediaSrc.hxx"
#include "StellaEvent.hxx"
#include "System.hxx"
#include "bspf.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EventHandler::EventHandler(Console* console)
: myConsole(console)
: myConsole(console),
myCurrentState(0)
{
// Create the event object which will be used for this handler
myEvent = new Event();
@ -37,8 +42,8 @@ EventHandler::EventHandler(Console* console)
keyTable[i].message = "";
}
setDefaultKeyMapping();
setDefaultJoyMapping();
setDefaultKeymap();
setDefaultJoymap();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -68,14 +73,38 @@ void EventHandler::sendKeyEvent(StellaEvent::KeyCode key,
if(keyTable[key].type == Event::LastType)
return;
if((keyTable[key].message != "") && (state == StellaEvent::KSTATE_PRESSED))
myMediaSource->showMessage(keyTable[key].message, 120);
// Take care of special events that aren't technically part of
// the emulation core
if(state == StellaEvent::KSTATE_PRESSED)
{
if(keyTable[key].type == Event::SaveState)
{
saveState();
return;
}
else if(keyTable[key].type == Event::ChangeState)
{
changeState();
return;
}
else if(keyTable[key].type == Event::LoadState)
{
loadState();
return;
}
// else if(keyTable[key].type == Event::TakeSnapshot)
// cerr << "Event::TakeSnapshot received\n";
if(keyTable[key].message != "")
myMediaSource->showMessage(keyTable[key].message, 120);
}
// Otherwise, pass it to the emulation core
myEvent->set(keyTable[key].type, state);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::setDefaultKeyMapping()
void EventHandler::setDefaultKeymap()
{
keyTable[StellaEvent::KCODE_1].type = Event::KeyboardZero1;
keyTable[StellaEvent::KCODE_2].type = Event::KeyboardZero2;
@ -127,10 +156,10 @@ void EventHandler::setDefaultKeyMapping()
keyTable[StellaEvent::KCODE_F6].type = Event::ConsoleLeftDifficultyB;
keyTable[StellaEvent::KCODE_F7].type = Event::ConsoleRightDifficultyA;
keyTable[StellaEvent::KCODE_F8].type = Event::ConsoleRightDifficultyB;
// keyTable[StellaEvent::KCODE_F9].type = Event::
// keyTable[StellaEvent::KCODE_F10].type = Event::
// keyTable[StellaEvent::KCODE_F11].type = Event::
// keyTable[StellaEvent::KCODE_F12].type = Event::
keyTable[StellaEvent::KCODE_F9].type = Event::SaveState;
keyTable[StellaEvent::KCODE_F10].type = Event::ChangeState;
keyTable[StellaEvent::KCODE_F11].type = Event::LoadState;
keyTable[StellaEvent::KCODE_F12].type = Event::TakeSnapshot;
keyTable[StellaEvent::KCODE_F3].message = "Color Mode";
keyTable[StellaEvent::KCODE_F4].message = "BW Mode";
@ -146,6 +175,79 @@ void EventHandler::setDefaultKeyMapping()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::setDefaultJoyMapping()
void EventHandler::setDefaultJoymap()
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::saveState()
{
ostringstream buf;
string md5 = myConsole->properties().get("Cartridge.MD5");
// string filename = frontend->stateFilename(md5, myCurrentState);
// FIXME !!! This MUST be changed to reflect the frontend/OS being used
string stateDir = "/home/stephena/.stella/state/";
buf << stateDir << md5 << ".st" << myCurrentState;
string filename = buf.str();
/////////////////////////////////////////////////////////
// Do a state save using the System
int result = myConsole->system().saveState(filename, md5);
// Print appropriate message
buf.str("");
if(result == 1)
buf << "State " << myCurrentState << " saved";
else if(result == 2)
buf << "Error saving state " << myCurrentState;
else if(result == 3)
buf << "Invalid state " << myCurrentState << " file";
string message = buf.str();
myMediaSource->showMessage(message, 120);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::changeState()
{
if(myCurrentState == 9)
myCurrentState = 0;
else
++myCurrentState;
// Print appropriate message
ostringstream buf;
buf << "Changed to slot " << myCurrentState;
string message = buf.str();
myMediaSource->showMessage(message, 120);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::loadState()
{
ostringstream buf;
string md5 = myConsole->properties().get("Cartridge.MD5");
// string filename = frontend->stateFilename(md5, myCurrentState);
// FIXME !!! This MUST be changed to reflect the frontend/OS being used
string stateDir = "/home/stephena/.stella/state/";
buf << stateDir << md5 << ".st" << myCurrentState;
string filename = buf.str();
/////////////////////////////////////////////////////////
// Do a state save using the System
int result = myConsole->system().loadState(filename, md5);
// Print appropriate message
buf.str("");
if(result == 1)
buf << "State " << myCurrentState << " loaded";
else if(result == 2)
buf << "Error loading state " << myCurrentState;
else if(result == 3)
buf << "Invalid state " << myCurrentState << " file";
string message = buf.str();
myMediaSource->showMessage(message, 120);
}

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.2 2003-09-04 16:50:48 stephena Exp $
// $Id: EventHandler.hxx,v 1.3 2003-09-04 23:23:06 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.2 2003-09-04 16:50:48 stephena Exp $
@version $Id: EventHandler.hxx,v 1.3 2003-09-04 23:23:06 stephena Exp $
*/
class EventHandler
{
@ -94,8 +94,11 @@ class EventHandler
#endif
private:
void setDefaultKeyMapping();
void setDefaultJoyMapping();
void setDefaultKeymap();
void setDefaultJoymap();
void saveState();
void changeState();
void loadState();
private:
struct KeyEvent
@ -115,6 +118,9 @@ class EventHandler
// Global mediasource object
MediaSource* myMediaSource;
// Indicates the current state to use for state loading/saving
uInt32 myCurrentState;
};
#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: mainSDL.cxx,v 1.43 2003-09-04 16:50:48 stephena Exp $
// $Id: mainSDL.cxx,v 1.44 2003-09-04 23:23:06 stephena Exp $
//============================================================================
#include <fstream>
@ -39,7 +39,6 @@
#include "MediaSrc.hxx"
#include "PropsSet.hxx"
#include "Sound.hxx"
#include "System.hxx"
#include "RectList.hxx"
#include "Settings.hxx"
@ -96,10 +95,6 @@ static bool setupProperties(PropertiesSet& set);
static void handleRCFile();
static void usage();
static void loadState();
static void saveState();
static void changeState(int direction);
// Globals for the SDL stuff
static SDL_Surface* screen = (SDL_Surface*) NULL;
static Uint32 palette[256];
@ -113,6 +108,7 @@ static SDL_SysWMinfo info;
static int sdlflags;
static RectList* rectList = (RectList*) NULL;
static uInt32 theWidth, theHeight, theMaxWindowSize, theWindowSize;
static string theSnapShotDir, theSnapShotName;
#ifdef HAVE_JOYSTICK
static SDL_Joystick* theLeftJoystick = (SDL_Joystick*) NULL;
@ -226,16 +222,12 @@ static Switches list[] = {
{ SDLK_RIGHTBRACKET,StellaEvent::KCODE_RIGHTBRACKET}
};
// Pointer to the event handler object or the null pointer
static Event theEvent;
static Event keyboardEvent;
// Pointer to the console object or the null pointer
static Console* theConsole = (Console*) NULL;
// Pointer to the settings object or the null pointer
//static Settings* settings = (Settings*) NULL;
// Pointer to the sound object or the null pointer
static Sound* sound = (Sound*) NULL;
@ -260,9 +252,6 @@ static bool isFullscreen = false;
// Indicates whether the window is currently centered
static bool isCentered = false;
// Indicates the current state to use for state saving
static uInt32 currentState = 0;
// The locations for various required files
static string homeDir;
static string stateDir;
@ -328,9 +317,14 @@ bool setupDisplay()
snapshot = new Snapshot();
if(theConsole->settings().theSnapShotDir == "")
theConsole->settings().theSnapShotDir = homeDir;
theSnapShotDir = homeDir;
else
theSnapShotDir = theConsole->settings().theSnapShotDir;
if(theConsole->settings().theSnapShotName == "")
theConsole->settings().theSnapShotName = "romname";
theSnapShotName = "romname";
else
theSnapShotName = theConsole->settings().theSnapShotName;
#endif
// Set up the rectangle list to be used in updateDisplay
@ -709,91 +703,6 @@ void grabMouse(bool grab)
}
/**
Saves state of the current game in the current slot.
*/
void saveState()
{
ostringstream buf;
string md5 = theConsole->properties().get("Cartridge.MD5");
buf << stateDir << md5 << ".st" << currentState;
string filename = buf.str();
// Do a state save using the System
int result = theConsole->system().saveState(filename, md5);
// Print appropriate message
buf.str("");
if(result == 1)
buf << "State " << currentState << " saved";
else if(result == 2)
buf << "Error saving state " << currentState;
else if(result == 3)
buf << "Invalid state " << currentState << " file";
string message = buf.str();
theConsole->mediaSource().showMessage(message, MESSAGE_INTERVAL *
theConsole->settings().theDesiredFrameRate);
}
/**
Changes the current state slot.
*/
void changeState(int direction)
{
if(direction == 1) // increase current state slot
{
if(currentState == 9)
currentState = 0;
else
++currentState;
}
else // decrease current state slot
{
if(currentState == 0)
currentState = 9;
else
--currentState;
}
// Print appropriate message
ostringstream buf;
buf << "Changed to slot " << currentState;
string message = buf.str();
theConsole->mediaSource().showMessage(message, MESSAGE_INTERVAL *
theConsole->settings().theDesiredFrameRate);
}
/**
Loads state from the current slot for the current game.
*/
void loadState()
{
ostringstream buf;
string md5 = theConsole->properties().get("Cartridge.MD5");
buf << stateDir << md5 << ".st" << currentState;
string filename = buf.str();
// Do a state load using the System
int result = theConsole->system().loadState(filename, md5);
// Print appropriate message
buf.str("");
if(result == 1)
buf << "State " << currentState << " loaded";
else if(result == 2)
buf << "Error loading state " << currentState;
else if(result == 3)
buf << "Invalid state " << currentState << " file";
string message = buf.str();
theConsole->mediaSource().showMessage(message, MESSAGE_INTERVAL *
theConsole->settings().theDesiredFrameRate);
}
/**
This routine should be called anytime the display needs to be updated
*/
@ -996,21 +905,6 @@ void handleEvents()
{
toggleFullscreen();
}
else if(key == SDLK_F9)
{
saveState();
}
else if(key == SDLK_F10)
{
if(mod & KMOD_SHIFT)
changeState(0);
else
changeState(1);
}
else if(key == SDLK_F11)
{
loadState();
}
else if(key == SDLK_F12)
{
takeSnapshot();
@ -1359,22 +1253,21 @@ void takeSnapshot()
if(!snapshot)
{
message = "Snapshots disabled";
theConsole->mediaSource().showMessage(message,
MESSAGE_INTERVAL * theConsole->settings().theDesiredFrameRate);
theConsole->mediaSource().showMessage(message, 120);
return;
}
// Now find the correct name for the snapshot
string path = theConsole->settings().theSnapShotDir;
string path = theSnapShotDir;
string filename;
if(theConsole->settings().theSnapShotName == "romname")
if(theSnapShotName == "romname")
path = path + "/" + theConsole->properties().get("Cartridge.Name");
else if(theConsole->settings().theSnapShotName == "md5sum")
else if(theSnapShotName == "md5sum")
path = path + "/" + theConsole->properties().get("Cartridge.MD5");
else
{
cerr << "ERROR: unknown name " << theConsole->settings().theSnapShotName
cerr << "ERROR: unknown name " << theSnapShotName
<< " for snapshot type" << endl;
return;
}
@ -1410,19 +1303,16 @@ void takeSnapshot()
if(access(filename.c_str(), F_OK) == 0)
{
message = "Snapshot saved";
theConsole->mediaSource().showMessage(message,
MESSAGE_INTERVAL * theConsole->settings().theDesiredFrameRate);
theConsole->mediaSource().showMessage(message, 120);
}
else
{
message = "Snapshot not saved";
theConsole->mediaSource().showMessage(message,
MESSAGE_INTERVAL * theConsole->settings().theDesiredFrameRate);
theConsole->mediaSource().showMessage(message, 120);
}
#else
string message = "Snapshots unsupported";
theConsole->mediaSource().showMessage(message,
MESSAGE_INTERVAL * theConsole->settings().theDesiredFrameRate);
theConsole->mediaSource().showMessage(message, 120);
#endif
}