mirror of https://github.com/stella-emu/stella.git
Cleaned up the SDL event gathering loop. It now almost exclusively
makes use of switch/case statements instead of the slower if/elseif structure. Hopefully this will fix event problems some users were experiencing. The Control or Alt button can actually now be used in event remapping. Due to the old event handling, the Control key could be assigned to an event but would never actually be usable. Removed the option to remap the exit event (for now), since I haven't figured out a way to remap it *back* to 'Escape' if that mapping is ever removed. Added beginning of support for Stella to automatically determine the correct framerate based on ROM format type. The final version of this will probably wait until Stella 1.5. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@329 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
e060f52112
commit
0f0625d9fe
|
@ -13,12 +13,13 @@
|
||||||
// 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.13 2004-07-21 00:15:08 stephena Exp $
|
// $Id: mainSDL.cxx,v 1.14 2004-07-28 23:54:38 stephena Exp $
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
@ -57,15 +58,14 @@
|
||||||
#error Unsupported platform!
|
#error Unsupported platform!
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void cleanup();
|
static void Cleanup();
|
||||||
static bool setupJoystick();
|
static bool SetupJoystick();
|
||||||
static void handleEvents();
|
static void HandleEvents();
|
||||||
static uInt32 getTicks();
|
static uInt32 GetTicks();
|
||||||
static void setupProperties(PropertiesSet& set);
|
static void SetupProperties(PropertiesSet& set);
|
||||||
|
static void ShowInfo(const string& msg);
|
||||||
|
|
||||||
#ifdef JOYSTICK_SUPPORT
|
#ifdef JOYSTICK_SUPPORT
|
||||||
// static uInt32 thePaddleNumber;
|
|
||||||
|
|
||||||
// Lookup table for joystick numbers and events
|
// Lookup table for joystick numbers and events
|
||||||
StellaEvent::JoyStick joyList[StellaEvent::LastJSTICK] = {
|
StellaEvent::JoyStick joyList[StellaEvent::LastJSTICK] = {
|
||||||
StellaEvent::JSTICK_0, StellaEvent::JSTICK_1, StellaEvent::JSTICK_2,
|
StellaEvent::JSTICK_0, StellaEvent::JSTICK_1, StellaEvent::JSTICK_2,
|
||||||
|
@ -103,6 +103,18 @@ static void setupProperties(PropertiesSet& set);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Lookup table for paddle resistance events
|
||||||
|
static Event::Type Paddle_Resistance[4] = {
|
||||||
|
Event::PaddleZeroResistance, Event::PaddleOneResistance,
|
||||||
|
Event::PaddleTwoResistance, Event::PaddleThreeResistance
|
||||||
|
};
|
||||||
|
|
||||||
|
// Lookup table for paddle button events
|
||||||
|
static Event::Type Paddle_Button[4] = {
|
||||||
|
Event::PaddleZeroFire, Event::PaddleOneFire,
|
||||||
|
Event::PaddleTwoFire, Event::PaddleThreeFire
|
||||||
|
};
|
||||||
|
|
||||||
// Pointer to the console object or the null pointer
|
// Pointer to the console object or the null pointer
|
||||||
static Console* theConsole = (Console*) NULL;
|
static Console* theConsole = (Console*) NULL;
|
||||||
|
|
||||||
|
@ -253,11 +265,22 @@ static KeyList keyList[] = {
|
||||||
{ SDLK_PAGEDOWN, StellaEvent::KCODE_PAGEDOWN }
|
{ SDLK_PAGEDOWN, StellaEvent::KCODE_PAGEDOWN }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Prints given message based on 'theShowInfoFlag'
|
||||||
|
*/
|
||||||
|
static void ShowInfo(const string& msg)
|
||||||
|
{
|
||||||
|
if(theShowInfoFlag)
|
||||||
|
cout << msg << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns number of ticks in microseconds
|
Returns number of ticks in microseconds
|
||||||
*/
|
*/
|
||||||
#ifdef HAVE_GETTIMEOFDAY
|
#ifdef HAVE_GETTIMEOFDAY
|
||||||
inline uInt32 getTicks()
|
inline uInt32 GetTicks()
|
||||||
{
|
{
|
||||||
timeval now;
|
timeval now;
|
||||||
gettimeofday(&now, 0);
|
gettimeofday(&now, 0);
|
||||||
|
@ -265,7 +288,7 @@ inline uInt32 getTicks()
|
||||||
return (uInt32) (now.tv_sec * 1000000 + now.tv_usec);
|
return (uInt32) (now.tv_sec * 1000000 + now.tv_usec);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
inline uInt32 getTicks()
|
inline uInt32 GetTicks()
|
||||||
{
|
{
|
||||||
return (uInt32) SDL_GetTicks() * 1000;
|
return (uInt32) SDL_GetTicks() * 1000;
|
||||||
}
|
}
|
||||||
|
@ -276,9 +299,11 @@ inline uInt32 getTicks()
|
||||||
This routine should be called once setupDisplay is called
|
This routine should be called once setupDisplay is called
|
||||||
to create the joystick stuff.
|
to create the joystick stuff.
|
||||||
*/
|
*/
|
||||||
bool setupJoystick()
|
bool SetupJoystick()
|
||||||
{
|
{
|
||||||
#ifdef JOYSTICK_SUPPORT
|
#ifdef JOYSTICK_SUPPORT
|
||||||
|
ostringstream message;
|
||||||
|
|
||||||
// Keep track of how many Stelladaptors we've found
|
// Keep track of how many Stelladaptors we've found
|
||||||
uInt8 saCount = 0;
|
uInt8 saCount = 0;
|
||||||
|
|
||||||
|
@ -292,9 +317,7 @@ bool setupJoystick()
|
||||||
// Initialize the joystick subsystem
|
// Initialize the joystick subsystem
|
||||||
if((SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) || (SDL_NumJoysticks() <= 0))
|
if((SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) || (SDL_NumJoysticks() <= 0))
|
||||||
{
|
{
|
||||||
if(theShowInfoFlag)
|
ShowInfo("No joysticks present, use the keyboard.");
|
||||||
cout << "No joysticks present, use the keyboard.\n";
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,6 +326,8 @@ bool setupJoystick()
|
||||||
SDL_NumJoysticks() : StellaEvent::LastJSTICK;
|
SDL_NumJoysticks() : StellaEvent::LastJSTICK;
|
||||||
for(uInt32 i = 0; i < limit; i++)
|
for(uInt32 i = 0; i < limit; i++)
|
||||||
{
|
{
|
||||||
|
message.str("");
|
||||||
|
|
||||||
string name = SDL_JoystickName(i);
|
string name = SDL_JoystickName(i);
|
||||||
theJoysticks[i].stick = SDL_JoystickOpen(i);
|
theJoysticks[i].stick = SDL_JoystickOpen(i);
|
||||||
|
|
||||||
|
@ -330,18 +355,17 @@ bool setupJoystick()
|
||||||
theJoysticks[i].type = JT_STELLADAPTOR_2;
|
theJoysticks[i].type = JT_STELLADAPTOR_2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(theShowInfoFlag)
|
message << "Joystick " << i << ": " << name;
|
||||||
cout << "Joystick " << i << ": " << name << endl;
|
ShowInfo(message.str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
theJoysticks[i].type = JT_REGULAR;
|
theJoysticks[i].type = JT_REGULAR;
|
||||||
if(theShowInfoFlag)
|
|
||||||
{
|
message << "Joystick " << i << ": " << SDL_JoystickName(i)
|
||||||
cout << "Joystick " << i << ": " << SDL_JoystickName(i)
|
<< " with " << SDL_JoystickNumButtons(theJoysticks[i].stick)
|
||||||
<< " with " << SDL_JoystickNumButtons(theJoysticks[i].stick)
|
<< " buttons.";
|
||||||
<< " buttons.\n";
|
ShowInfo(message.str());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -353,226 +377,206 @@ bool setupJoystick()
|
||||||
/**
|
/**
|
||||||
This routine should be called regularly to handle events
|
This routine should be called regularly to handle events
|
||||||
*/
|
*/
|
||||||
void handleEvents()
|
void HandleEvents()
|
||||||
{
|
{
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
Uint8 type;
|
|
||||||
SDLKey key;
|
|
||||||
SDLMod mod;
|
|
||||||
|
|
||||||
// Check for an event
|
// Check for an event
|
||||||
while(SDL_PollEvent(&event))
|
while(SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
// keyboard events
|
switch(event.type)
|
||||||
if(event.type == SDL_KEYDOWN)
|
|
||||||
{
|
{
|
||||||
key = event.key.keysym.sym;
|
// keyboard events
|
||||||
mod = event.key.keysym.mod;
|
case SDL_KEYUP:
|
||||||
type = event.type;
|
case SDL_KEYDOWN:
|
||||||
|
|
||||||
// An attempt to speed up event processing
|
|
||||||
// All SDL-specific event actions are accessed by either
|
|
||||||
// Control or Alt keys. So we quickly check for those.
|
|
||||||
if(mod & KMOD_ALT)
|
|
||||||
{
|
{
|
||||||
if(key == SDLK_EQUALS)
|
SDLKey key = event.key.keysym.sym;
|
||||||
theDisplay->resize(1);
|
SDLMod mod = event.key.keysym.mod;
|
||||||
else if(key == SDLK_MINUS)
|
uInt32 state = event.key.type == SDL_KEYDOWN ? 1 : 0;
|
||||||
theDisplay->resize(-1);
|
|
||||||
else if(key == SDLK_RETURN)
|
// An attempt to speed up event processing
|
||||||
theDisplay->toggleFullscreen();
|
// All SDL-specific event actions are accessed by either
|
||||||
|
// Control or Alt keys. So we quickly check for those.
|
||||||
|
if(mod & KMOD_ALT && state)
|
||||||
|
{
|
||||||
|
switch(int(key))
|
||||||
|
{
|
||||||
|
case SDLK_EQUALS:
|
||||||
|
theDisplay->resize(1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDLK_MINUS:
|
||||||
|
theDisplay->resize(-1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDLK_RETURN:
|
||||||
|
theDisplay->toggleFullscreen();
|
||||||
|
break;
|
||||||
#ifdef DISPLAY_OPENGL
|
#ifdef DISPLAY_OPENGL
|
||||||
else if(key == SDLK_f && theUseOpenGLFlag)
|
case SDLK_f:
|
||||||
((FrameBufferGL*)theDisplay)->toggleFilter();
|
if(theUseOpenGLFlag)
|
||||||
|
((FrameBufferGL*)theDisplay)->toggleFilter();
|
||||||
#endif
|
#endif
|
||||||
#ifdef DEVELOPER_SUPPORT
|
#ifdef DEVELOPER_SUPPORT
|
||||||
else if(key == SDLK_END) // Alt-End increases XStart
|
case SDLK_END: // Alt-End increases XStart
|
||||||
{
|
theConsole->changeXStart(1);
|
||||||
theConsole->changeXStart(1);
|
theDisplay->resize(0);
|
||||||
theDisplay->resize(0);
|
break;
|
||||||
}
|
|
||||||
else if(key == SDLK_HOME) // Alt-Home decreases XStart
|
case SDLK_HOME: // Alt-Home decreases XStart
|
||||||
{
|
theConsole->changeXStart(0);
|
||||||
theConsole->changeXStart(0);
|
theDisplay->resize(0);
|
||||||
theDisplay->resize(0);
|
break;
|
||||||
}
|
|
||||||
else if(key == SDLK_PAGEUP) // Alt-PageUp increases YStart
|
case SDLK_PAGEUP: // Alt-PageUp increases YStart
|
||||||
{
|
theConsole->changeYStart(1);
|
||||||
theConsole->changeYStart(1);
|
theDisplay->resize(0);
|
||||||
theDisplay->resize(0);
|
break;
|
||||||
}
|
|
||||||
else if(key == SDLK_PAGEDOWN) // Alt-PageDown decreases YStart
|
case SDLK_PAGEDOWN: // Alt-PageDown decreases YStart
|
||||||
{
|
theConsole->changeYStart(0);
|
||||||
theConsole->changeYStart(0);
|
theDisplay->resize(0);
|
||||||
theDisplay->resize(0);
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if(mod & KMOD_CTRL)
|
else if(mod & KMOD_CTRL && state)
|
||||||
{
|
|
||||||
if(key == SDLK_g)
|
|
||||||
{
|
{
|
||||||
// don't change grabmouse in fullscreen mode
|
switch(int(key))
|
||||||
if(!theDisplay->fullScreen())
|
|
||||||
{
|
{
|
||||||
theGrabMouseIndicator = !theGrabMouseIndicator;
|
case SDLK_g:
|
||||||
theSettings->setBool("grabmouse", theGrabMouseIndicator);
|
// don't change grabmouse in fullscreen mode
|
||||||
theDisplay->grabMouse(theGrabMouseIndicator);
|
if(!theDisplay->fullScreen())
|
||||||
}
|
{
|
||||||
}
|
theGrabMouseIndicator = !theGrabMouseIndicator;
|
||||||
else if(key == SDLK_h)
|
theSettings->setBool("grabmouse", theGrabMouseIndicator);
|
||||||
{
|
theDisplay->grabMouse(theGrabMouseIndicator);
|
||||||
// don't change hidecursor in fullscreen mode
|
}
|
||||||
if(!theDisplay->fullScreen())
|
break;
|
||||||
{
|
|
||||||
theHideCursorIndicator = !theHideCursorIndicator;
|
case SDLK_h:
|
||||||
theSettings->setBool("hidecursor", theHideCursorIndicator);
|
// don't change hidecursor in fullscreen mode
|
||||||
theDisplay->showCursor(!theHideCursorIndicator);
|
if(!theDisplay->fullScreen())
|
||||||
}
|
{
|
||||||
}
|
theHideCursorIndicator = !theHideCursorIndicator;
|
||||||
else if(key == SDLK_f) // Ctrl-f toggles NTSC/PAL mode
|
theSettings->setBool("hidecursor", theHideCursorIndicator);
|
||||||
{
|
theDisplay->showCursor(!theHideCursorIndicator);
|
||||||
theConsole->toggleFormat();
|
}
|
||||||
theDisplay->setupPalette();
|
break;
|
||||||
}
|
|
||||||
else if(key == SDLK_p) // Ctrl-p toggles different palettes
|
case SDLK_f: // Ctrl-f toggles NTSC/PAL mode
|
||||||
{
|
theConsole->toggleFormat();
|
||||||
theConsole->togglePalette();
|
theDisplay->setupPalette();
|
||||||
theDisplay->setupPalette();
|
break;
|
||||||
}
|
|
||||||
|
case SDLK_p: // Ctrl-p toggles different palettes
|
||||||
|
theConsole->togglePalette();
|
||||||
|
theDisplay->setupPalette();
|
||||||
|
break;
|
||||||
|
|
||||||
#ifdef DEVELOPER_SUPPORT
|
#ifdef DEVELOPER_SUPPORT
|
||||||
else if(key == SDLK_END) // Ctrl-End increases Width
|
case SDLK_END: // Ctrl-End increases Width
|
||||||
{
|
theConsole->changeWidth(1);
|
||||||
theConsole->changeWidth(1);
|
theDisplay->resize(0);
|
||||||
theDisplay->resize(0);
|
break;
|
||||||
}
|
|
||||||
else if(key == SDLK_HOME) // Ctrl-Home decreases Width
|
case SDLK_HOME: // Ctrl-Home decreases Width
|
||||||
{
|
theConsole->changeWidth(0);
|
||||||
theConsole->changeWidth(0);
|
theDisplay->resize(0);
|
||||||
theDisplay->resize(0);
|
break;
|
||||||
}
|
|
||||||
else if(key == SDLK_PAGEUP) // Ctrl-PageUp increases Height
|
case SDLK_PAGEUP: // Ctrl-PageUp increases Height
|
||||||
{
|
theConsole->changeHeight(1);
|
||||||
theConsole->changeHeight(1);
|
theDisplay->resize(0);
|
||||||
theDisplay->resize(0);
|
break;
|
||||||
}
|
|
||||||
else if(key == SDLK_PAGEDOWN) // Ctrl-PageDown decreases Height
|
case SDLK_PAGEDOWN: // Ctrl-PageDown decreases Height
|
||||||
{
|
theConsole->changeHeight(0);
|
||||||
theConsole->changeHeight(0);
|
theDisplay->resize(0);
|
||||||
theDisplay->resize(0);
|
break;
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
else if(key == SDLK_s) // Ctrl-s saves properties to a file
|
case SDLK_s: // Ctrl-s saves properties to a file
|
||||||
{
|
// Attempt to merge with propertiesSet
|
||||||
if(theConsole->settings().getBool("mergeprops")) // Attempt to merge with propertiesSet
|
if(theConsole->settings().getBool("mergeprops"))
|
||||||
{
|
theConsole->saveProperties(theSettings->userPropertiesFilename(), true);
|
||||||
theConsole->saveProperties(theSettings->userPropertiesFilename(), true);
|
else // Save to file in home directory
|
||||||
}
|
{
|
||||||
else // Save to file in home directory
|
string newPropertiesFile = theConsole->settings().baseDir() + "/" + \
|
||||||
{
|
theConsole->properties().get("Cartridge.Name") + ".pro";
|
||||||
string newPropertiesFile = theConsole->settings().baseDir() + "/" + \
|
theConsole->saveProperties(newPropertiesFile);
|
||||||
theConsole->properties().get("Cartridge.Name") + ".pro";
|
}
|
||||||
theConsole->saveProperties(newPropertiesFile);
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else // check all the other keys
|
// check all the other keys
|
||||||
{
|
for(uInt32 i = 0; i < sizeof(keyList) / sizeof(KeyList); ++i)
|
||||||
for(unsigned int i = 0; i < sizeof(keyList) / sizeof(KeyList); ++i)
|
|
||||||
{
|
|
||||||
if(keyList[i].scanCode == key)
|
if(keyList[i].scanCode == key)
|
||||||
theConsole->eventHandler().sendKeyEvent(keyList[i].keyCode, 1);
|
theConsole->eventHandler().sendKeyEvent(keyList[i].keyCode, state);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(event.type == SDL_KEYUP)
|
|
||||||
{
|
|
||||||
key = event.key.keysym.sym;
|
|
||||||
type = event.type;
|
|
||||||
|
|
||||||
for(unsigned int i = 0; i < sizeof(keyList) / sizeof(KeyList); ++i)
|
break; // SDL_KEYUP, SDL_KEYDOWN
|
||||||
{
|
|
||||||
if(keyList[i].scanCode == key)
|
|
||||||
theConsole->eventHandler().sendKeyEvent(keyList[i].keyCode, 0);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if(event.type == SDL_MOUSEMOTION)
|
|
||||||
{
|
|
||||||
Int32 resistance;
|
|
||||||
uInt32 zoom = theDisplay->zoomLevel();
|
|
||||||
Int32 width = theDisplay->width() * zoom;
|
|
||||||
Event::Type type = Event::NoType;
|
|
||||||
|
|
||||||
// Grabmouse and hidecursor introduce some lag into the mouse movement,
|
case SDL_MOUSEMOTION:
|
||||||
// so we need to fudge the numbers a bit
|
|
||||||
if(theGrabMouseIndicator && theHideCursorIndicator)
|
|
||||||
{
|
{
|
||||||
mouseX = (int)((float)mouseX + (float)event.motion.xrel
|
uInt32 zoom = theDisplay->zoomLevel();
|
||||||
* 1.5 * (float) zoom);
|
Int32 width = theDisplay->width() * zoom;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mouseX = mouseX + event.motion.xrel * zoom;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check to make sure mouseX is within the game window
|
// Grabmouse and hidecursor introduce some lag into the mouse movement,
|
||||||
if(mouseX < 0)
|
// so we need to fudge the numbers a bit
|
||||||
mouseX = 0;
|
if(theGrabMouseIndicator && theHideCursorIndicator)
|
||||||
else if(mouseX > width)
|
mouseX = (int)((float)mouseX + (float)event.motion.xrel
|
||||||
mouseX = width;
|
* 1.5 * (float) zoom);
|
||||||
|
else
|
||||||
|
mouseX = mouseX + event.motion.xrel * zoom;
|
||||||
|
|
||||||
|
// Check to make sure mouseX is within the game window
|
||||||
|
if(mouseX < 0)
|
||||||
|
mouseX = 0;
|
||||||
|
else if(mouseX > width)
|
||||||
|
mouseX = width;
|
||||||
|
|
||||||
resistance = (Int32)(1000000.0 * (width - mouseX) / width);
|
Int32 resistance = (Int32)(1000000.0 * (width - mouseX) / width);
|
||||||
|
|
||||||
// Now, set the event of the correct paddle to the calculated resistance
|
theConsole->eventHandler().sendEvent(Paddle_Resistance[thePaddleMode], resistance);
|
||||||
if(thePaddleMode == 0)
|
|
||||||
type = Event::PaddleZeroResistance;
|
|
||||||
else if(thePaddleMode == 1)
|
|
||||||
type = Event::PaddleOneResistance;
|
|
||||||
else if(thePaddleMode == 2)
|
|
||||||
type = Event::PaddleTwoResistance;
|
|
||||||
else if(thePaddleMode == 3)
|
|
||||||
type = Event::PaddleThreeResistance;
|
|
||||||
|
|
||||||
theConsole->eventHandler().sendEvent(type, resistance);
|
break; // SDL_MOUSEMOTION
|
||||||
}
|
}
|
||||||
else if(event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEBUTTONUP)
|
|
||||||
{
|
case SDL_MOUSEBUTTONUP:
|
||||||
Event::Type type = Event::LastType;
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
Int32 value;
|
{
|
||||||
|
Int32 value = event.button.type == SDL_MOUSEBUTTONDOWN ? 1 : 0;
|
||||||
if(event.type == SDL_MOUSEBUTTONDOWN)
|
|
||||||
value = 1;
|
theConsole->eventHandler().sendEvent(Paddle_Button[thePaddleMode], value);
|
||||||
else
|
|
||||||
value = 0;
|
break; // SDL_MOUSEBUTTONUP, SDL_MOUSEBUTTONDOWN
|
||||||
|
}
|
||||||
if(thePaddleMode == 0)
|
|
||||||
type = Event::PaddleZeroFire;
|
case SDL_ACTIVEEVENT:
|
||||||
else if(thePaddleMode == 1)
|
{
|
||||||
type = Event::PaddleOneFire;
|
if((event.active.state & SDL_APPACTIVE) && (event.active.gain == 0))
|
||||||
else if(thePaddleMode == 2)
|
{
|
||||||
type = Event::PaddleTwoFire;
|
if(!theConsole->eventHandler().doPause())
|
||||||
else if(thePaddleMode == 3)
|
theConsole->eventHandler().sendEvent(Event::Pause, 1);
|
||||||
type = Event::PaddleThreeFire;
|
}
|
||||||
|
|
||||||
theConsole->eventHandler().sendEvent(type, value);
|
break; // SDL_ACTIVEEVENT
|
||||||
}
|
}
|
||||||
else if(event.type == SDL_ACTIVEEVENT)
|
|
||||||
{
|
case SDL_QUIT:
|
||||||
if((event.active.state & SDL_APPACTIVE) && (event.active.gain == 0))
|
{
|
||||||
{
|
theConsole->eventHandler().sendEvent(Event::Quit, 1);
|
||||||
if(!theConsole->eventHandler().doPause())
|
|
||||||
{
|
break; // SDL_QUIT
|
||||||
theConsole->eventHandler().sendEvent(Event::Pause, 1);
|
}
|
||||||
}
|
|
||||||
|
case SDL_VIDEOEXPOSE:
|
||||||
|
{
|
||||||
|
theDisplay->refresh();
|
||||||
|
|
||||||
|
break; // SDL_VIDEOEXPOSE
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if(event.type == SDL_QUIT)
|
|
||||||
{
|
|
||||||
theConsole->eventHandler().sendEvent(Event::Quit, 1);
|
|
||||||
}
|
|
||||||
else if(event.type == SDL_VIDEOEXPOSE)
|
|
||||||
{
|
|
||||||
theDisplay->refresh();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef JOYSTICK_SUPPORT
|
#ifdef JOYSTICK_SUPPORT
|
||||||
|
@ -600,98 +604,102 @@ void handleEvents()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JT_REGULAR:
|
case JT_REGULAR:
|
||||||
|
switch(event.type)
|
||||||
if((event.type == SDL_JOYBUTTONDOWN) || (event.type == SDL_JOYBUTTONUP))
|
|
||||||
{
|
{
|
||||||
if(event.jbutton.button >= StellaEvent::LastJCODE)
|
case SDL_JOYBUTTONUP:
|
||||||
return;
|
case SDL_JOYBUTTONDOWN:
|
||||||
|
if(event.jbutton.button >= StellaEvent::LastJCODE)
|
||||||
|
return;
|
||||||
|
|
||||||
code = joyButtonList[event.jbutton.button];
|
code = joyButtonList[event.jbutton.button];
|
||||||
state = event.jbutton.state == SDL_PRESSED ? 1 : 0;
|
state = event.jbutton.state == SDL_PRESSED ? 1 : 0;
|
||||||
|
|
||||||
theConsole->eventHandler().sendJoyEvent(stick, code, state);
|
theConsole->eventHandler().sendJoyEvent(stick, code, state);
|
||||||
}
|
break;
|
||||||
else if(event.type == SDL_JOYAXISMOTION)
|
|
||||||
{
|
|
||||||
axis = event.jaxis.axis;
|
|
||||||
value = event.jaxis.value;
|
|
||||||
|
|
||||||
if(axis == 0) // x-axis
|
case SDL_JOYAXISMOTION:
|
||||||
{
|
axis = event.jaxis.axis;
|
||||||
theConsole->eventHandler().sendJoyEvent(stick, StellaEvent::JAXIS_LEFT,
|
value = event.jaxis.value;
|
||||||
(value < -16384) ? 1 : 0);
|
|
||||||
theConsole->eventHandler().sendJoyEvent(stick, StellaEvent::JAXIS_RIGHT,
|
if(axis == 0) // x-axis
|
||||||
(value > 16384) ? 1 : 0);
|
{
|
||||||
}
|
theConsole->eventHandler().sendJoyEvent(stick, StellaEvent::JAXIS_LEFT,
|
||||||
else if(axis == 1) // y-axis
|
(value < -16384) ? 1 : 0);
|
||||||
{
|
theConsole->eventHandler().sendJoyEvent(stick, StellaEvent::JAXIS_RIGHT,
|
||||||
theConsole->eventHandler().sendJoyEvent(stick, StellaEvent::JAXIS_UP,
|
(value > 16384) ? 1 : 0);
|
||||||
(value < -16384) ? 1 : 0);
|
}
|
||||||
theConsole->eventHandler().sendJoyEvent(stick, StellaEvent::JAXIS_DOWN,
|
else if(axis == 1) // y-axis
|
||||||
(value > 16384) ? 1 : 0);
|
{
|
||||||
}
|
theConsole->eventHandler().sendJoyEvent(stick, StellaEvent::JAXIS_UP,
|
||||||
|
(value < -16384) ? 1 : 0);
|
||||||
|
theConsole->eventHandler().sendJoyEvent(stick, StellaEvent::JAXIS_DOWN,
|
||||||
|
(value > 16384) ? 1 : 0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break; // Regular joystick
|
break; // Regular joystick
|
||||||
|
|
||||||
case JT_STELLADAPTOR_1:
|
case JT_STELLADAPTOR_1:
|
||||||
case JT_STELLADAPTOR_2:
|
case JT_STELLADAPTOR_2:
|
||||||
|
switch(event.type)
|
||||||
if((event.type == SDL_JOYBUTTONDOWN) || (event.type == SDL_JOYBUTTONUP))
|
|
||||||
{
|
{
|
||||||
button = event.jbutton.button;
|
case SDL_JOYBUTTONUP:
|
||||||
state = event.jbutton.state == SDL_PRESSED ? 1 : 0;
|
case SDL_JOYBUTTONDOWN:
|
||||||
|
button = event.jbutton.button;
|
||||||
|
state = event.jbutton.state == SDL_PRESSED ? 1 : 0;
|
||||||
|
|
||||||
// Send button events for the joysticks/paddles
|
// Send button events for the joysticks/paddles
|
||||||
if(button == 0)
|
if(button == 0)
|
||||||
{
|
|
||||||
if(type == JT_STELLADAPTOR_1)
|
|
||||||
{
|
{
|
||||||
theConsole->eventHandler().sendEvent(Event::JoystickZeroFire, state);
|
if(type == JT_STELLADAPTOR_1)
|
||||||
theConsole->eventHandler().sendEvent(Event::DrivingZeroFire, state);
|
{
|
||||||
theConsole->eventHandler().sendEvent(Event::PaddleZeroFire, state);
|
theConsole->eventHandler().sendEvent(Event::JoystickZeroFire, state);
|
||||||
|
theConsole->eventHandler().sendEvent(Event::DrivingZeroFire, state);
|
||||||
|
theConsole->eventHandler().sendEvent(Event::PaddleZeroFire, state);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
theConsole->eventHandler().sendEvent(Event::JoystickOneFire, state);
|
||||||
|
theConsole->eventHandler().sendEvent(Event::DrivingOneFire, state);
|
||||||
|
theConsole->eventHandler().sendEvent(Event::PaddleTwoFire, state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else if(button == 1)
|
||||||
{
|
{
|
||||||
theConsole->eventHandler().sendEvent(Event::JoystickOneFire, state);
|
if(type == JT_STELLADAPTOR_1)
|
||||||
theConsole->eventHandler().sendEvent(Event::DrivingOneFire, state);
|
theConsole->eventHandler().sendEvent(Event::PaddleOneFire, state);
|
||||||
theConsole->eventHandler().sendEvent(Event::PaddleTwoFire, state);
|
else
|
||||||
|
theConsole->eventHandler().sendEvent(Event::PaddleThreeFire, state);
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
else if(button == 1)
|
|
||||||
{
|
|
||||||
if(type == JT_STELLADAPTOR_1)
|
|
||||||
theConsole->eventHandler().sendEvent(Event::PaddleOneFire, state);
|
|
||||||
else
|
|
||||||
theConsole->eventHandler().sendEvent(Event::PaddleThreeFire, state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(event.type == SDL_JOYAXISMOTION)
|
|
||||||
{
|
|
||||||
axis = event.jaxis.axis;
|
|
||||||
value = event.jaxis.value;
|
|
||||||
|
|
||||||
// Send axis events for the joysticks
|
case SDL_JOYAXISMOTION:
|
||||||
theConsole->eventHandler().sendEvent(SA_Axis[type-2][axis][0],
|
axis = event.jaxis.axis;
|
||||||
(value < -16384) ? 1 : 0);
|
value = event.jaxis.value;
|
||||||
theConsole->eventHandler().sendEvent(SA_Axis[type-2][axis][1],
|
|
||||||
(value > 16384) ? 1 : 0);
|
|
||||||
|
|
||||||
// Send axis events for the paddles
|
// Send axis events for the joysticks
|
||||||
resistance = (Int32) (1000000.0 * (32767 - value) / 65534);
|
theConsole->eventHandler().sendEvent(SA_Axis[type-2][axis][0],
|
||||||
theConsole->eventHandler().sendEvent(SA_Axis[type-2][axis][2], resistance);
|
(value < -16384) ? 1 : 0);
|
||||||
|
theConsole->eventHandler().sendEvent(SA_Axis[type-2][axis][1],
|
||||||
|
(value > 16384) ? 1 : 0);
|
||||||
|
|
||||||
|
// Send axis events for the paddles
|
||||||
|
resistance = (Int32) (1000000.0 * (32767 - value) / 65534);
|
||||||
|
theConsole->eventHandler().sendEvent(SA_Axis[type-2][axis][2], resistance);
|
||||||
|
|
||||||
// Send events for the driving controllers
|
// Send events for the driving controllers
|
||||||
if(axis == 1)
|
if(axis == 1)
|
||||||
{
|
{
|
||||||
if(value <= -16384-4096)
|
if(value <= -16384-4096)
|
||||||
theConsole->eventHandler().sendEvent(SA_DrivingValue[type-2],2);
|
theConsole->eventHandler().sendEvent(SA_DrivingValue[type-2],2);
|
||||||
else if(value > 16384+4096)
|
else if(value > 16384+4096)
|
||||||
theConsole->eventHandler().sendEvent(SA_DrivingValue[type-2],1);
|
theConsole->eventHandler().sendEvent(SA_DrivingValue[type-2],1);
|
||||||
else if(value >= 16384-4096)
|
else if(value >= 16384-4096)
|
||||||
theConsole->eventHandler().sendEvent(SA_DrivingValue[type-2],0);
|
theConsole->eventHandler().sendEvent(SA_DrivingValue[type-2],0);
|
||||||
else
|
else
|
||||||
theConsole->eventHandler().sendEvent(SA_DrivingValue[type-2],3);
|
theConsole->eventHandler().sendEvent(SA_DrivingValue[type-2],3);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break; // Stelladaptor joystick
|
break; // Stelladaptor joystick
|
||||||
|
|
||||||
|
@ -707,7 +715,7 @@ void handleEvents()
|
||||||
Setup the properties set by first checking for a user file,
|
Setup the properties set by first checking for a user file,
|
||||||
then a system-wide file.
|
then a system-wide file.
|
||||||
*/
|
*/
|
||||||
void setupProperties(PropertiesSet& set)
|
void SetupProperties(PropertiesSet& set)
|
||||||
{
|
{
|
||||||
bool useMemList = false;
|
bool useMemList = false;
|
||||||
string theAlternateProFile = theSettings->getString("altpro");
|
string theAlternateProFile = theSettings->getString("altpro");
|
||||||
|
@ -731,9 +739,9 @@ void setupProperties(PropertiesSet& set)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Does general cleanup in case any operation failed (or at end of program).
|
Does general Cleanup in case any operation failed (or at end of program).
|
||||||
*/
|
*/
|
||||||
void cleanup()
|
void Cleanup()
|
||||||
{
|
{
|
||||||
#ifdef JOYSTICK_SUPPORT
|
#ifdef JOYSTICK_SUPPORT
|
||||||
if(SDL_WasInit(SDL_INIT_JOYSTICK) & SDL_INIT_JOYSTICK)
|
if(SDL_WasInit(SDL_INIT_JOYSTICK) & SDL_INIT_JOYSTICK)
|
||||||
|
@ -775,7 +783,7 @@ int main(int argc, char* argv[])
|
||||||
#endif
|
#endif
|
||||||
if(!theSettings)
|
if(!theSettings)
|
||||||
{
|
{
|
||||||
cleanup();
|
Cleanup();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
theSettings->loadConfig();
|
theSettings->loadConfig();
|
||||||
|
@ -783,20 +791,20 @@ int main(int argc, char* argv[])
|
||||||
// Take care of commandline arguments
|
// Take care of commandline arguments
|
||||||
if(!theSettings->loadCommandLine(argc, argv))
|
if(!theSettings->loadCommandLine(argc, argv))
|
||||||
{
|
{
|
||||||
cleanup();
|
Cleanup();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a properties set for us to use and set it up
|
// Create a properties set for us to use and set it up
|
||||||
PropertiesSet propertiesSet;
|
PropertiesSet propertiesSet;
|
||||||
setupProperties(propertiesSet);
|
SetupProperties(propertiesSet);
|
||||||
|
|
||||||
// Check to see if the 'listroms' argument was given
|
// Check to see if the 'listroms' argument was given
|
||||||
// If so, list the roms and immediately exit
|
// If so, list the roms and immediately exit
|
||||||
if(theSettings->getBool("listrominfo"))
|
if(theSettings->getBool("listrominfo"))
|
||||||
{
|
{
|
||||||
propertiesSet.print();
|
propertiesSet.print();
|
||||||
cleanup();
|
Cleanup();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -817,7 +825,7 @@ int main(int argc, char* argv[])
|
||||||
if(!in)
|
if(!in)
|
||||||
{
|
{
|
||||||
cerr << "ERROR: Couldn't open " << file << "..." << endl;
|
cerr << "ERROR: Couldn't open " << file << "..." << endl;
|
||||||
cleanup();
|
Cleanup();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -831,30 +839,27 @@ int main(int argc, char* argv[])
|
||||||
if(videodriver == "soft")
|
if(videodriver == "soft")
|
||||||
{
|
{
|
||||||
theDisplay = new FrameBufferSoft();
|
theDisplay = new FrameBufferSoft();
|
||||||
if(theShowInfoFlag)
|
ShowInfo("Using software mode for video.");
|
||||||
cout << "Using software mode for video.\n";
|
|
||||||
}
|
}
|
||||||
#ifdef DISPLAY_OPENGL
|
#ifdef DISPLAY_OPENGL
|
||||||
else if(videodriver == "gl")
|
else if(videodriver == "gl")
|
||||||
{
|
{
|
||||||
theDisplay = new FrameBufferGL();
|
theDisplay = new FrameBufferGL();
|
||||||
theUseOpenGLFlag = true;
|
theUseOpenGLFlag = true;
|
||||||
if(theShowInfoFlag)
|
ShowInfo("Using OpenGL mode for video.");
|
||||||
cout << "Using OpenGL mode for video.\n";
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else // a driver that doesn't exist was requested, so use software mode
|
else // a driver that doesn't exist was requested, so use software mode
|
||||||
{
|
{
|
||||||
theDisplay = new FrameBufferSoft();
|
theDisplay = new FrameBufferSoft();
|
||||||
if(theShowInfoFlag)
|
ShowInfo("Using software mode for video.");
|
||||||
cout << "Using software mode for video.\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!theDisplay)
|
if(!theDisplay)
|
||||||
{
|
{
|
||||||
cerr << "ERROR: Couldn't set up display.\n";
|
cerr << "ERROR: Couldn't set up display.\n";
|
||||||
delete[] image;
|
delete[] image;
|
||||||
cleanup();
|
Cleanup();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -863,17 +868,15 @@ int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
uInt32 fragsize = theSettings->getInt("fragsize");
|
uInt32 fragsize = theSettings->getInt("fragsize");
|
||||||
theSound = new SoundSDL(fragsize);
|
theSound = new SoundSDL(fragsize);
|
||||||
if(theShowInfoFlag)
|
|
||||||
{
|
ostringstream message;
|
||||||
cout << "Sound enabled, using fragment size = " << fragsize;
|
message << "Sound enabled, using fragment size = " << fragsize << ".";
|
||||||
cout << "." << endl;
|
ShowInfo(message.str());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else // even if sound has been disabled, we still need a sound object
|
else // even if sound has been disabled, we still need a sound object
|
||||||
{
|
{
|
||||||
theSound = new Sound();
|
theSound = new Sound();
|
||||||
if(theShowInfoFlag)
|
ShowInfo("Sound disabled.");
|
||||||
cout << "Sound disabled.\n";
|
|
||||||
}
|
}
|
||||||
theSound->setVolume(theSettings->getInt("volume"));
|
theSound->setVolume(theSettings->getInt("volume"));
|
||||||
|
|
||||||
|
@ -887,12 +890,17 @@ int main(int argc, char* argv[])
|
||||||
// Free the image since we don't need it any longer
|
// Free the image since we don't need it any longer
|
||||||
delete[] image;
|
delete[] image;
|
||||||
|
|
||||||
|
// Print message about the framerate
|
||||||
|
ostringstream message;
|
||||||
|
message << "Using framerate = " << theSettings->getInt("framerate") << ".";
|
||||||
|
ShowInfo(message.str());
|
||||||
|
|
||||||
// Setup the SDL joysticks
|
// Setup the SDL joysticks
|
||||||
// This must be done after the console is created
|
// This must be done after the console is created
|
||||||
if(!setupJoystick())
|
if(!SetupJoystick())
|
||||||
{
|
{
|
||||||
cerr << "ERROR: Couldn't set up joysticks.\n";
|
cerr << "ERROR: Couldn't set up joysticks.\n";
|
||||||
cleanup();
|
Cleanup();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -904,7 +912,7 @@ int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
// Set up accurate timing stuff
|
// Set up accurate timing stuff
|
||||||
uInt32 startTime, delta;
|
uInt32 startTime, delta;
|
||||||
uInt32 timePerFrame = (uInt32)(1000000.0 / (double)theSettings->getInt("framerate"));
|
uInt32 timePerFrame = (uInt32)(1000000.0 / (double) theSettings->getInt("framerate"));
|
||||||
|
|
||||||
// Set the base for the timers
|
// Set the base for the timers
|
||||||
frameTime = 0;
|
frameTime = 0;
|
||||||
|
@ -918,20 +926,20 @@ int main(int argc, char* argv[])
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
startTime = getTicks();
|
startTime = GetTicks();
|
||||||
handleEvents();
|
HandleEvents();
|
||||||
theConsole->update();
|
theConsole->update();
|
||||||
|
|
||||||
// Now, waste time if we need to so that we are at the desired frame rate
|
// Now, waste time if we need to so that we are at the desired frame rate
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
delta = getTicks() - startTime;
|
delta = GetTicks() - startTime;
|
||||||
|
|
||||||
if(delta >= timePerFrame)
|
if(delta >= timePerFrame)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
frameTime += getTicks() - startTime;
|
frameTime += GetTicks() - startTime;
|
||||||
++numberOfFrames;
|
++numberOfFrames;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -939,10 +947,10 @@ int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
// Set up less accurate timing stuff
|
// Set up less accurate timing stuff
|
||||||
uInt32 startTime, virtualTime, currentTime;
|
uInt32 startTime, virtualTime, currentTime;
|
||||||
uInt32 timePerFrame = (uInt32)(1000000.0 / (double)theSettings->getInt("framerate"));
|
uInt32 timePerFrame = (uInt32)(1000000.0 / (double) theSettings->getInt("framerate"));
|
||||||
|
|
||||||
// Set the base for the timers
|
// Set the base for the timers
|
||||||
virtualTime = getTicks();
|
virtualTime = GetTicks();
|
||||||
frameTime = 0;
|
frameTime = 0;
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
|
@ -954,18 +962,18 @@ int main(int argc, char* argv[])
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
startTime = getTicks();
|
startTime = GetTicks();
|
||||||
handleEvents();
|
HandleEvents();
|
||||||
theConsole->update();
|
theConsole->update();
|
||||||
|
|
||||||
currentTime = getTicks();
|
currentTime = GetTicks();
|
||||||
virtualTime += timePerFrame;
|
virtualTime += timePerFrame;
|
||||||
if(currentTime < virtualTime)
|
if(currentTime < virtualTime)
|
||||||
{
|
{
|
||||||
SDL_Delay((virtualTime - currentTime)/1000);
|
SDL_Delay((virtualTime - currentTime)/1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
currentTime = getTicks() - startTime;
|
currentTime = GetTicks() - startTime;
|
||||||
frameTime += currentTime;
|
frameTime += currentTime;
|
||||||
++numberOfFrames;
|
++numberOfFrames;
|
||||||
}
|
}
|
||||||
|
@ -987,6 +995,6 @@ int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup time ...
|
// Cleanup time ...
|
||||||
cleanup();
|
Cleanup();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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: Console.cxx,v 1.35 2004-07-22 01:54:08 stephena Exp $
|
// $Id: Console.cxx,v 1.36 2004-07-28 23:54:38 stephena Exp $
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
@ -65,8 +65,6 @@ Console::Console(const uInt8* image, uInt32 size, const char* filename,
|
||||||
mySystem = 0;
|
mySystem = 0;
|
||||||
myEvent = 0;
|
myEvent = 0;
|
||||||
|
|
||||||
myFrameRate = mySettings.getInt("framerate");
|
|
||||||
|
|
||||||
// Create an event handler which will collect and dispatch events
|
// Create an event handler which will collect and dispatch events
|
||||||
myEventHandler = new EventHandler(this);
|
myEventHandler = new EventHandler(this);
|
||||||
myEvent = myEventHandler->event();
|
myEvent = myEventHandler->event();
|
||||||
|
@ -162,13 +160,25 @@ Console::Console(const uInt8* image, uInt32 size, const char* filename,
|
||||||
// Reset, the system to its power-on state
|
// Reset, the system to its power-on state
|
||||||
mySystem->reset();
|
mySystem->reset();
|
||||||
|
|
||||||
|
// Set the correct framerate based on the format of the ROM
|
||||||
|
// This can be overridden by the '-framerate' option
|
||||||
|
myFrameRate = 60;
|
||||||
|
if(mySettings.getInt("framerate") > 0)
|
||||||
|
myFrameRate = mySettings.getInt("framerate");
|
||||||
|
// else if(myProperties.get("Display.Format") == "NTSC")
|
||||||
|
// myFrameRate = 60;
|
||||||
|
// else if(myProperties.get("Display.Format") == "PAL")
|
||||||
|
// myFrameRate = 50;
|
||||||
|
// mySettings.setInt("framerate", myFrameRate, false);
|
||||||
|
mySettings.setInt("framerate", myFrameRate);
|
||||||
|
|
||||||
// Initialize the framebuffer interface.
|
// Initialize the framebuffer interface.
|
||||||
// This must be done *after* a reset, since it needs updated values.
|
// This must be done *after* a reset, since it needs updated values.
|
||||||
myFrameBuffer.initDisplay(this, myMediaSource);
|
myFrameBuffer.initDisplay(this, myMediaSource);
|
||||||
|
|
||||||
// Initialize the sound interface.
|
// Initialize the sound interface.
|
||||||
uInt32 framerate = (myProperties.get("Display.Format") == "PAL") ? 50 : 60;
|
uInt32 soundFrameRate = (myProperties.get("Display.Format") == "PAL") ? 50 : 60;
|
||||||
mySound.init(this, myMediaSource, mySystem, framerate);
|
mySound.init(this, myMediaSource, mySystem, soundFrameRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -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: EventHandler.cxx,v 1.28 2004-07-21 00:15:08 stephena Exp $
|
// $Id: EventHandler.cxx,v 1.29 2004-07-28 23:54:39 stephena Exp $
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -338,15 +338,13 @@ bool EventHandler::isValidList(string list, uInt32 length)
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void EventHandler::saveState()
|
void EventHandler::saveState()
|
||||||
{
|
{
|
||||||
ostringstream buf;
|
|
||||||
|
|
||||||
// Do a state save using the System
|
// Do a state save using the System
|
||||||
string md5 = myConsole->properties().get("Cartridge.MD5");
|
string md5 = myConsole->properties().get("Cartridge.MD5");
|
||||||
string filename = myConsole->settings().stateFilename(md5, myCurrentState);
|
string filename = myConsole->settings().stateFilename(md5, myCurrentState);
|
||||||
int result = myConsole->system().saveState(filename, md5);
|
int result = myConsole->system().saveState(filename, md5);
|
||||||
|
|
||||||
// Print appropriate message
|
// Print appropriate message
|
||||||
buf.str("");
|
ostringstream buf;
|
||||||
if(result == 1)
|
if(result == 1)
|
||||||
buf << "State " << myCurrentState << " saved";
|
buf << "State " << myCurrentState << " saved";
|
||||||
else if(result == 2)
|
else if(result == 2)
|
||||||
|
@ -375,13 +373,13 @@ void EventHandler::changeState()
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void EventHandler::loadState()
|
void EventHandler::loadState()
|
||||||
{
|
{
|
||||||
ostringstream buf;
|
|
||||||
|
|
||||||
// Do a state save using the System
|
// Do a state save using the System
|
||||||
string md5 = myConsole->properties().get("Cartridge.MD5");
|
string md5 = myConsole->properties().get("Cartridge.MD5");
|
||||||
string filename = myConsole->settings().stateFilename(md5, myCurrentState);
|
string filename = myConsole->settings().stateFilename(md5, myCurrentState);
|
||||||
int result = myConsole->system().loadState(filename, md5);
|
int result = myConsole->system().loadState(filename, md5);
|
||||||
|
|
||||||
|
// Print appropriate message
|
||||||
|
ostringstream buf;
|
||||||
if(result == 1)
|
if(result == 1)
|
||||||
buf << "State " << myCurrentState << " loaded";
|
buf << "State " << myCurrentState << " loaded";
|
||||||
else if(result == 2)
|
else if(result == 2)
|
||||||
|
|
|
@ -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: FrameBuffer.cxx,v 1.11 2004-07-22 01:54:08 stephena Exp $
|
// $Id: FrameBuffer.cxx,v 1.12 2004-07-28 23:54:39 stephena Exp $
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -696,7 +696,7 @@ FrameBuffer::MainMenuItem FrameBuffer::ourMainMenu[2] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
FrameBuffer::RemapMenuItem FrameBuffer::ourRemapMenu[58] = {
|
FrameBuffer::RemapMenuItem FrameBuffer::ourRemapMenu[57] = {
|
||||||
{ Event::ConsoleSelect, "Select", "" },
|
{ Event::ConsoleSelect, "Select", "" },
|
||||||
{ Event::ConsoleReset, "Reset", "" },
|
{ Event::ConsoleReset, "Reset", "" },
|
||||||
{ Event::ConsoleColor, "Color TV", "" },
|
{ Event::ConsoleColor, "Color TV", "" },
|
||||||
|
@ -710,7 +710,7 @@ FrameBuffer::RemapMenuItem FrameBuffer::ourRemapMenu[58] = {
|
||||||
{ Event::LoadState, "Load State", "" },
|
{ Event::LoadState, "Load State", "" },
|
||||||
{ Event::TakeSnapshot, "Snapshot", "" },
|
{ Event::TakeSnapshot, "Snapshot", "" },
|
||||||
{ Event::Pause, "Pause", "" },
|
{ Event::Pause, "Pause", "" },
|
||||||
{ Event::Quit, "Quit", "" },
|
// { Event::Quit, "Quit", "" },
|
||||||
|
|
||||||
{ Event::JoystickZeroUp, "Left-Joy Up", "" },
|
{ Event::JoystickZeroUp, "Left-Joy Up", "" },
|
||||||
{ Event::JoystickZeroDown, "Left-Joy Down", "" },
|
{ Event::JoystickZeroDown, "Left-Joy Down", "" },
|
||||||
|
|
|
@ -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: FrameBuffer.hxx,v 1.11 2004-07-22 01:54:08 stephena Exp $
|
// $Id: FrameBuffer.hxx,v 1.12 2004-07-28 23:54:39 stephena Exp $
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
#ifndef FRAMEBUFFER_HXX
|
#ifndef FRAMEBUFFER_HXX
|
||||||
|
@ -35,7 +35,7 @@ class Console;
|
||||||
can be changed.
|
can be changed.
|
||||||
|
|
||||||
@author Stephen Anthony
|
@author Stephen Anthony
|
||||||
@version $Id: FrameBuffer.hxx,v 1.11 2004-07-22 01:54:08 stephena Exp $
|
@version $Id: FrameBuffer.hxx,v 1.12 2004-07-28 23:54:39 stephena Exp $
|
||||||
*/
|
*/
|
||||||
class FrameBuffer
|
class FrameBuffer
|
||||||
{
|
{
|
||||||
|
@ -337,7 +337,7 @@ class FrameBuffer
|
||||||
static MainMenuItem ourMainMenu[2];
|
static MainMenuItem ourMainMenu[2];
|
||||||
|
|
||||||
// Holds static strings for the remap menu
|
// Holds static strings for the remap menu
|
||||||
static RemapMenuItem ourRemapMenu[58];
|
static RemapMenuItem ourRemapMenu[57];
|
||||||
|
|
||||||
// Holds the current key mappings
|
// Holds the current key mappings
|
||||||
Event::Type* myKeyTable;
|
Event::Type* myKeyTable;
|
||||||
|
|
|
@ -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: Props.cxx,v 1.7 2004-07-12 04:05:03 stephena Exp $
|
// $Id: Props.cxx,v 1.8 2004-07-28 23:54:39 stephena Exp $
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
#include "Props.hxx"
|
#include "Props.hxx"
|
||||||
|
@ -151,10 +151,14 @@ void Properties::save(ostream& out)
|
||||||
// Write out each of the key and value pairs
|
// Write out each of the key and value pairs
|
||||||
for(uInt32 i = 0; i < mySize; ++i)
|
for(uInt32 i = 0; i < mySize; ++i)
|
||||||
{
|
{
|
||||||
writeQuotedString(out, myProperties[i].key);
|
// Try to save some space by only saving the items that differ from default
|
||||||
out.put(' ');
|
if(myProperties[i].value != myDefaults->get(myProperties[i].key))
|
||||||
writeQuotedString(out, myProperties[i].value);
|
{
|
||||||
out.put('\n');
|
writeQuotedString(out, myProperties[i].key);
|
||||||
|
out.put(' ');
|
||||||
|
writeQuotedString(out, myProperties[i].value);
|
||||||
|
out.put('\n');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put a trailing null string so we know when to stop reading
|
// Put a trailing null string so we know when to stop reading
|
||||||
|
|
|
@ -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: Settings.cxx,v 1.26 2004-07-12 02:26:57 stephena Exp $
|
// $Id: Settings.cxx,v 1.27 2004-07-28 23:54:39 stephena Exp $
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
@ -45,7 +45,7 @@ Settings::Settings()
|
||||||
set("hidecursor", "false");
|
set("hidecursor", "false");
|
||||||
set("volume", "-1");
|
set("volume", "-1");
|
||||||
set("accurate", "false");
|
set("accurate", "false");
|
||||||
set("framerate", "60");
|
set("framerate", "-1");
|
||||||
set("keymap", "");
|
set("keymap", "");
|
||||||
set("joymap", "");
|
set("joymap", "");
|
||||||
set("zoom", "1");
|
set("zoom", "1");
|
||||||
|
@ -167,7 +167,7 @@ void Settings::usage()
|
||||||
{
|
{
|
||||||
#ifndef MAC_OSX
|
#ifndef MAC_OSX
|
||||||
cout << endl
|
cout << endl
|
||||||
<< "Stella version 1.4\n\nUsage: stella [options ...] romfile" << endl
|
<< "Stella version 1.4.1_cvs\n\nUsage: stella [options ...] romfile" << endl
|
||||||
<< endl
|
<< endl
|
||||||
<< "Valid options are:" << endl
|
<< "Valid options are:" << endl
|
||||||
<< endl
|
<< endl
|
||||||
|
@ -282,39 +282,39 @@ void Settings::set(const string& key, const string& value, bool save)
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void Settings::setInt(const string& key, const uInt32 value)
|
void Settings::setInt(const string& key, const uInt32 value, bool save)
|
||||||
{
|
{
|
||||||
ostringstream stream;
|
ostringstream stream;
|
||||||
stream << value;
|
stream << value;
|
||||||
|
|
||||||
set(key, stream.str());
|
set(key, stream.str(), save);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void Settings::setFloat(const string& key, const float value)
|
void Settings::setFloat(const string& key, const float value, bool save)
|
||||||
{
|
{
|
||||||
ostringstream stream;
|
ostringstream stream;
|
||||||
stream << value;
|
stream << value;
|
||||||
|
|
||||||
set(key, stream.str());
|
set(key, stream.str(), save);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void Settings::setBool(const string& key, const bool value)
|
void Settings::setBool(const string& key, const bool value, bool save)
|
||||||
{
|
{
|
||||||
ostringstream stream;
|
ostringstream stream;
|
||||||
stream << value;
|
stream << value;
|
||||||
|
|
||||||
set(key, stream.str());
|
set(key, stream.str(), save);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void Settings::setString(const string& key, const string& value)
|
void Settings::setString(const string& key, const string& value, bool save)
|
||||||
{
|
{
|
||||||
ostringstream stream;
|
ostringstream stream;
|
||||||
stream << value;
|
stream << value;
|
||||||
|
|
||||||
set(key, stream.str());
|
set(key, stream.str(), save);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -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: Settings.hxx,v 1.16 2004-07-09 00:27:39 stephena Exp $
|
// $Id: Settings.hxx,v 1.17 2004-07-28 23:54:39 stephena Exp $
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
#ifndef SETTINGS_HXX
|
#ifndef SETTINGS_HXX
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
This class provides an interface for accessing frontend specific settings.
|
This class provides an interface for accessing frontend specific settings.
|
||||||
|
|
||||||
@author Stephen Anthony
|
@author Stephen Anthony
|
||||||
@version $Id: Settings.hxx,v 1.16 2004-07-09 00:27:39 stephena Exp $
|
@version $Id: Settings.hxx,v 1.17 2004-07-28 23:54:39 stephena Exp $
|
||||||
*/
|
*/
|
||||||
class Settings
|
class Settings
|
||||||
{
|
{
|
||||||
|
@ -107,7 +107,7 @@ class Settings
|
||||||
@param value The value to assign to the setting
|
@param value The value to assign to the setting
|
||||||
@param save Whether this setting should be saved to the rc-file.
|
@param save Whether this setting should be saved to the rc-file.
|
||||||
*/
|
*/
|
||||||
void setInt(const string& key, const uInt32 value);
|
void setInt(const string& key, const uInt32 value, bool save = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Set the value associated with key to the given value.
|
Set the value associated with key to the given value.
|
||||||
|
@ -116,7 +116,7 @@ class Settings
|
||||||
@param value The value to assign to the setting
|
@param value The value to assign to the setting
|
||||||
@param save Whether this setting should be saved to the rc-file.
|
@param save Whether this setting should be saved to the rc-file.
|
||||||
*/
|
*/
|
||||||
void setFloat(const string& key, const float value);
|
void setFloat(const string& key, const float value, bool save = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Set the value associated with key to the given value.
|
Set the value associated with key to the given value.
|
||||||
|
@ -125,7 +125,7 @@ class Settings
|
||||||
@param value The value to assign to the setting
|
@param value The value to assign to the setting
|
||||||
@param save Whether this setting should be saved to the rc-file.
|
@param save Whether this setting should be saved to the rc-file.
|
||||||
*/
|
*/
|
||||||
void setBool(const string& key, const bool value);
|
void setBool(const string& key, const bool value, bool save = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Set the value associated with key to the given value.
|
Set the value associated with key to the given value.
|
||||||
|
@ -134,7 +134,7 @@ class Settings
|
||||||
@param value The value to assign to the setting
|
@param value The value to assign to the setting
|
||||||
@param save Whether this setting should be saved to the rc-file.
|
@param save Whether this setting should be saved to the rc-file.
|
||||||
*/
|
*/
|
||||||
void setString(const string& key, const string& value);
|
void setString(const string& key, const string& value, bool save = true);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -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.3 2004-07-14 06:54:17 markgrebe Exp $
|
// $Id: mainSDL.cxx,v 1.4 2004-07-28 23:54:39 stephena Exp $
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
@ -558,13 +558,13 @@ void handleEvents()
|
||||||
{
|
{
|
||||||
if (theSettings->getInt("framerate") != 10000000)
|
if (theSettings->getInt("framerate") != 10000000)
|
||||||
{
|
{
|
||||||
theSettings->setInt("framerate",10000000);
|
theSettings->setInt("framerate",10000000, false);
|
||||||
timePerFrame = 1.0 / 10000000.0;
|
timePerFrame = 1.0 / 10000000.0;
|
||||||
setSpeedLimitMenu(0);
|
setSpeedLimitMenu(0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
theSettings->setInt("framerate",60);
|
theSettings->setInt("framerate",60, false);
|
||||||
timePerFrame = 1.0 / 60.0;
|
timePerFrame = 1.0 / 60.0;
|
||||||
setSpeedLimitMenu(1);
|
setSpeedLimitMenu(1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue