mirror of https://github.com/stella-emu/stella.git
Updated X11 and SDL versions to use the new Settings class. Currently
working on updating the DOS version. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@53 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
fff4d40d77
commit
735a362381
|
@ -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.14 2002-03-20 00:03:24 stephena Exp $
|
||||
// $Id: mainSDL.cxx,v 1.15 2002-03-21 22:50:36 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#include <fstream>
|
||||
|
@ -36,6 +36,7 @@
|
|||
#include "System.hxx"
|
||||
#include "SndUnix.hxx"
|
||||
#include "RectList.hxx"
|
||||
#include "Settings.hxx"
|
||||
|
||||
#ifdef HAVE_PNG
|
||||
#include "Snapshot.hxx"
|
||||
|
@ -49,38 +50,33 @@
|
|||
#define SDL_DISABLE 0
|
||||
#endif
|
||||
|
||||
#define HAVE_GETTIMEOFDAY
|
||||
|
||||
SDL_Joystick* theLeftJoystick;
|
||||
SDL_Joystick* theRightJoystick;
|
||||
#define HAVE_GETTIMEOFDAY 1
|
||||
|
||||
// function prototypes
|
||||
bool setupDisplay();
|
||||
bool setupJoystick();
|
||||
bool createScreen(int width, int height);
|
||||
void recalculate8BitPalette();
|
||||
void setupPalette();
|
||||
void cleanup();
|
||||
static bool setupDisplay();
|
||||
static bool setupJoystick();
|
||||
static bool createScreen(int width, int height);
|
||||
static void recalculate8BitPalette();
|
||||
static void setupPalette();
|
||||
static void cleanup();
|
||||
|
||||
void updateDisplay(MediaSource& mediaSource);
|
||||
void handleEvents();
|
||||
static void updateDisplay(MediaSource& mediaSource);
|
||||
static void handleEvents();
|
||||
|
||||
void doQuit();
|
||||
void resizeWindow(int mode);
|
||||
void centerWindow();
|
||||
void showCursor(bool show);
|
||||
void grabMouse(bool grab);
|
||||
void toggleFullscreen();
|
||||
void takeSnapshot();
|
||||
void togglePause();
|
||||
uInt32 maxWindowSizeForScreen();
|
||||
uInt32 getTicks();
|
||||
static void doQuit();
|
||||
static void resizeWindow(int mode);
|
||||
static void centerWindow();
|
||||
static void showCursor(bool show);
|
||||
static void grabMouse(bool grab);
|
||||
static void toggleFullscreen();
|
||||
static void takeSnapshot();
|
||||
static void togglePause();
|
||||
static uInt32 maxWindowSizeForScreen();
|
||||
static uInt32 getTicks();
|
||||
|
||||
bool setupProperties(PropertiesSet& set);
|
||||
void handleCommandLineArguments(int ac, char* av[]);
|
||||
void handleRCFile();
|
||||
void parseRCOptions(istream& in);
|
||||
void usage();
|
||||
static bool setupProperties(PropertiesSet& set);
|
||||
static void handleRCFile();
|
||||
static void usage();
|
||||
|
||||
// Globals for the SDL stuff
|
||||
static SDL_Surface* screen;
|
||||
|
@ -94,6 +90,8 @@ static bool x11Available = false;
|
|||
static SDL_SysWMinfo info;
|
||||
static int sdlflags;
|
||||
static RectList* rectList;
|
||||
static SDL_Joystick* theLeftJoystick;
|
||||
static SDL_Joystick* theRightJoystick;
|
||||
|
||||
#ifdef HAVE_PNG
|
||||
static Snapshot* snapshot;
|
||||
|
@ -168,85 +166,30 @@ static Switches list[] = {
|
|||
{ SDLK_F8, Event::ConsoleRightDifficultyB }
|
||||
};
|
||||
|
||||
// Event objects to use
|
||||
static Event theEvent;
|
||||
static Event keyboardEvent;
|
||||
|
||||
// Default window size of 0, meaning it must be set somewhere else
|
||||
uInt32 theWindowSize = 0;
|
||||
|
||||
// Indicates the maximum window size for the current screen
|
||||
uInt32 theMaxWindowSize;
|
||||
|
||||
// Indicates the width and height of the game display based on properties
|
||||
uInt32 theHeight;
|
||||
uInt32 theWidth;
|
||||
|
||||
// Pointer to the console object or the null pointer
|
||||
Console* theConsole;
|
||||
static Console* theConsole;
|
||||
|
||||
// Event object to use
|
||||
Event theEvent;
|
||||
// Pointer to the settings object or the null pointer
|
||||
static Settings* settings;
|
||||
|
||||
// Indicates if the user wants to quit
|
||||
bool theQuitIndicator = false;
|
||||
static bool theQuitIndicator = false;
|
||||
|
||||
// Indicates if the emulator should be paused
|
||||
bool thePauseIndicator = false;
|
||||
static bool thePauseIndicator = false;
|
||||
|
||||
// Indicates if the entire frame should be redrawn
|
||||
bool theRedrawEntireFrameFlag = true;
|
||||
|
||||
// Indicates whether to use fullscreen
|
||||
bool theUseFullScreenFlag = false;
|
||||
|
||||
// Indicates whether mouse can leave the game window
|
||||
bool theGrabMouseFlag = false;
|
||||
|
||||
// Indicates whether to center the game window
|
||||
bool theCenterWindowFlag = false;
|
||||
|
||||
// Indicates whether to show some game info on program exit
|
||||
bool theShowInfoFlag = false;
|
||||
|
||||
// Indicates whether to show cursor in the game window
|
||||
bool theHideCursorFlag = false;
|
||||
|
||||
// Indicates whether to allocate colors from a private color map
|
||||
bool theUsePrivateColormapFlag = false;
|
||||
static bool theRedrawEntireFrameIndicator = true;
|
||||
|
||||
// Indicates whether the game is currently in fullscreen
|
||||
bool isFullscreen = false;
|
||||
static bool isFullscreen = false;
|
||||
|
||||
// Indicates whether the window is currently centered
|
||||
bool isCentered = false;
|
||||
|
||||
// Indicates what the desired volume is
|
||||
uInt32 theDesiredVolume = 75;
|
||||
|
||||
// Indicates what the desired frame rate is
|
||||
uInt32 theDesiredFrameRate = 60;
|
||||
|
||||
// Indicate which paddle mode we're using:
|
||||
// 0 - Mouse emulates paddle 0
|
||||
// 1 - Mouse emulates paddle 1
|
||||
// 2 - Mouse emulates paddle 2
|
||||
// 3 - Mouse emulates paddle 3
|
||||
// 4 - Use real Atari 2600 paddles
|
||||
uInt32 thePaddleMode = 0;
|
||||
|
||||
// An alternate properties file to use
|
||||
string theAlternateProFile = "";
|
||||
|
||||
#ifdef HAVE_PNG
|
||||
// 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. Set to true by default.
|
||||
bool theMultipleSnapShotFlag = true;
|
||||
#endif
|
||||
static bool isCentered = false;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -270,44 +213,44 @@ bool setupDisplay()
|
|||
x11Available = true;
|
||||
|
||||
sdlflags = SDL_HWSURFACE;
|
||||
sdlflags |= theUseFullScreenFlag ? SDL_FULLSCREEN : 0;
|
||||
sdlflags |= theUsePrivateColormapFlag ? SDL_HWPALETTE : 0;
|
||||
sdlflags |= settings->theUseFullScreenFlag ? SDL_FULLSCREEN : 0;
|
||||
sdlflags |= settings->theUsePrivateColormapFlag ? SDL_HWPALETTE : 0;
|
||||
|
||||
// Get the desired width and height of the display
|
||||
theWidth = theConsole->mediaSource().width();
|
||||
theHeight = theConsole->mediaSource().height();
|
||||
settings->theWidth = theConsole->mediaSource().width();
|
||||
settings->theHeight = theConsole->mediaSource().height();
|
||||
|
||||
// Get the maximum size of a window for THIS screen
|
||||
// Must be called after display and screen are known, as well as
|
||||
// theWidth and theHeight
|
||||
// Defaults to 3 on systems without X11, maximum of 4 on any system.
|
||||
theMaxWindowSize = maxWindowSizeForScreen();
|
||||
settings->theMaxWindowSize = maxWindowSizeForScreen();
|
||||
|
||||
// If theWindowSize is not 0, then it must have been set on the commandline
|
||||
// Now we check to see if it is within bounds
|
||||
if(theWindowSize != 0)
|
||||
if(settings->theWindowSize != 0)
|
||||
{
|
||||
if(theWindowSize < 1)
|
||||
theWindowSize = 1;
|
||||
else if(theWindowSize > theMaxWindowSize)
|
||||
theWindowSize = theMaxWindowSize;
|
||||
if(settings->theWindowSize < 1)
|
||||
settings->theWindowSize = 1;
|
||||
else if(settings->theWindowSize > settings->theMaxWindowSize)
|
||||
settings->theWindowSize = settings->theMaxWindowSize;
|
||||
}
|
||||
else // theWindowSize hasn't been set so we do the default
|
||||
{
|
||||
if(theMaxWindowSize < 2)
|
||||
theWindowSize = 1;
|
||||
if(settings->theMaxWindowSize < 2)
|
||||
settings->theWindowSize = 1;
|
||||
else
|
||||
theWindowSize = 2;
|
||||
settings->theWindowSize = 2;
|
||||
}
|
||||
|
||||
#ifdef HAVE_PNG
|
||||
// Take care of the snapshot stuff.
|
||||
snapshot = new Snapshot();
|
||||
|
||||
if(theSnapShotDir == "")
|
||||
theSnapShotDir = getenv("HOME");
|
||||
if(theSnapShotName == "")
|
||||
theSnapShotName = "romname";
|
||||
if(settings->theSnapShotDir == "")
|
||||
settings->theSnapShotDir = getenv("HOME");
|
||||
if(settings->theSnapShotName == "")
|
||||
settings->theSnapShotName = "romname";
|
||||
#endif
|
||||
|
||||
// Set up the rectangle list to be used in updateDisplay
|
||||
|
@ -325,8 +268,8 @@ bool setupDisplay()
|
|||
SDL_WM_SetCaption(name, "stella");
|
||||
|
||||
// Figure out the desired size of the window
|
||||
int width = theWidth * 2 * theWindowSize;
|
||||
int height = theHeight * theWindowSize;
|
||||
int width = settings->theWidth * settings->theWindowSize * 2;
|
||||
int height = settings->theHeight * settings->theWindowSize;
|
||||
|
||||
// Create the screen
|
||||
if(!createScreen(width, height))
|
||||
|
@ -334,7 +277,7 @@ bool setupDisplay()
|
|||
setupPalette();
|
||||
|
||||
// Make sure that theUseFullScreenFlag sets up fullscreen mode correctly
|
||||
if(theUseFullScreenFlag)
|
||||
if(settings->theUseFullScreenFlag)
|
||||
{
|
||||
grabMouse(true);
|
||||
showCursor(false);
|
||||
|
@ -343,14 +286,14 @@ bool setupDisplay()
|
|||
else
|
||||
{
|
||||
// Keep mouse in game window if grabmouse is selected
|
||||
grabMouse(theGrabMouseFlag);
|
||||
grabMouse(settings->theGrabMouseFlag);
|
||||
|
||||
// Show or hide the cursor depending on the 'hidecursor' argument
|
||||
showCursor(!theHideCursorFlag);
|
||||
showCursor(!settings->theHideCursorFlag);
|
||||
}
|
||||
|
||||
// Center the window if centering is selected and not fullscreen
|
||||
if(theCenterWindowFlag && !theUseFullScreenFlag)
|
||||
if(settings->theCenterWindowFlag && !settings->theUseFullScreenFlag)
|
||||
centerWindow();
|
||||
|
||||
return true;
|
||||
|
@ -507,32 +450,32 @@ void resizeWindow(int mode)
|
|||
|
||||
if(mode == 1) // increase size
|
||||
{
|
||||
if(theWindowSize == theMaxWindowSize)
|
||||
theWindowSize = 1;
|
||||
if(settings->theWindowSize == settings->theMaxWindowSize)
|
||||
settings->theWindowSize = 1;
|
||||
else
|
||||
theWindowSize++;
|
||||
settings->theWindowSize++;
|
||||
}
|
||||
else // decrease size
|
||||
{
|
||||
if(theWindowSize == 1)
|
||||
theWindowSize = theMaxWindowSize;
|
||||
if(settings->theWindowSize == 1)
|
||||
settings->theWindowSize = settings->theMaxWindowSize;
|
||||
else
|
||||
theWindowSize--;
|
||||
settings->theWindowSize--;
|
||||
}
|
||||
|
||||
// Figure out the desired size of the window
|
||||
int width = theWidth * 2 * theWindowSize;
|
||||
int height = theHeight * theWindowSize;
|
||||
int width = settings->theWidth * settings->theWindowSize * 2;
|
||||
int height = settings->theHeight * settings->theWindowSize;
|
||||
|
||||
if(!createScreen(width, height))
|
||||
return;
|
||||
|
||||
theRedrawEntireFrameFlag = true;
|
||||
theRedrawEntireFrameIndicator = true;
|
||||
|
||||
// A resize may mean that the window is no longer centered
|
||||
isCentered = false;
|
||||
|
||||
if(theCenterWindowFlag)
|
||||
if(settings->theCenterWindowFlag)
|
||||
centerWindow();
|
||||
}
|
||||
|
||||
|
@ -575,8 +518,8 @@ void centerWindow()
|
|||
*/
|
||||
void toggleFullscreen()
|
||||
{
|
||||
int width = theWidth * 2 * theWindowSize;
|
||||
int height = theHeight * theWindowSize;
|
||||
int width = settings->theWidth * settings->theWindowSize * 2;
|
||||
int height = settings->theHeight * settings->theWindowSize;
|
||||
|
||||
isFullscreen = !isFullscreen;
|
||||
if(isFullscreen)
|
||||
|
@ -594,14 +537,14 @@ void toggleFullscreen()
|
|||
}
|
||||
else // now in windowed mode
|
||||
{
|
||||
grabMouse(theGrabMouseFlag);
|
||||
showCursor(!theHideCursorFlag);
|
||||
grabMouse(settings->theGrabMouseFlag);
|
||||
showCursor(!settings->theHideCursorFlag);
|
||||
|
||||
if(theCenterWindowFlag)
|
||||
if(settings->theCenterWindowFlag)
|
||||
centerWindow();
|
||||
}
|
||||
|
||||
theRedrawEntireFrameFlag = true;
|
||||
theRedrawEntireFrameIndicator = true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -654,7 +597,10 @@ void updateDisplay(MediaSource& mediaSource)
|
|||
{
|
||||
uInt8* currentFrame = mediaSource.currentFrameBuffer();
|
||||
uInt8* previousFrame = mediaSource.previousFrameBuffer();
|
||||
uInt16 screenMultiple = (uInt16)theWindowSize;
|
||||
uInt16 screenMultiple = (uInt16) settings->theWindowSize;
|
||||
|
||||
uInt32 width = settings->theWidth;
|
||||
uInt32 height = settings->theHeight;
|
||||
|
||||
struct Rectangle
|
||||
{
|
||||
|
@ -678,7 +624,7 @@ void updateDisplay(MediaSource& mediaSource)
|
|||
|
||||
// This update procedure requires theWidth to be a multiple of four.
|
||||
// This is validated when the properties are loaded.
|
||||
for(uInt16 y = 0; y < theHeight; ++y)
|
||||
for(uInt16 y = 0; y < height; ++y)
|
||||
{
|
||||
// Indicates the number of current rectangles
|
||||
uInt16 currentCount = 0;
|
||||
|
@ -687,10 +633,10 @@ void updateDisplay(MediaSource& mediaSource)
|
|||
uInt32* current = (uInt32*)(currentFrame);
|
||||
uInt32* previous = (uInt32*)(previousFrame);
|
||||
|
||||
for(uInt16 x = 0; x < theWidth; x += 4, ++current, ++previous)
|
||||
for(uInt16 x = 0; x < width; x += 4, ++current, ++previous)
|
||||
{
|
||||
// Has something changed in this set of four pixels?
|
||||
if((*current != *previous) || theRedrawEntireFrameFlag)
|
||||
if((*current != *previous) || theRedrawEntireFrameIndicator)
|
||||
{
|
||||
uInt8* c = (uInt8*)current;
|
||||
uInt8* p = (uInt8*)previous;
|
||||
|
@ -699,7 +645,7 @@ void updateDisplay(MediaSource& mediaSource)
|
|||
for(uInt16 i = 0; i < 4; ++i, ++c, ++p)
|
||||
{
|
||||
// See if this pixel has changed
|
||||
if((*c != *p) || theRedrawEntireFrameFlag)
|
||||
if((*c != *p) || theRedrawEntireFrameIndicator)
|
||||
{
|
||||
// Can we extend a rectangle or do we have to create a new one?
|
||||
if((currentCount != 0) &&
|
||||
|
@ -779,8 +725,8 @@ void updateDisplay(MediaSource& mediaSource)
|
|||
activeRectangles = tmp;
|
||||
activeCount = currentCount;
|
||||
|
||||
currentFrame += theWidth;
|
||||
previousFrame += theWidth;
|
||||
currentFrame += width;
|
||||
previousFrame += width;
|
||||
}
|
||||
|
||||
// Flush any rectangles that are still active
|
||||
|
@ -802,7 +748,7 @@ void updateDisplay(MediaSource& mediaSource)
|
|||
SDL_UpdateRects(screen, rectList->numRects(), rectList->rects());
|
||||
|
||||
// The frame doesn't need to be completely redrawn anymore
|
||||
theRedrawEntireFrameFlag = false;
|
||||
theRedrawEntireFrameIndicator = false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -859,8 +805,8 @@ void handleEvents()
|
|||
// don't change grabmouse in fullscreen mode
|
||||
if(!isFullscreen)
|
||||
{
|
||||
theGrabMouseFlag = !theGrabMouseFlag;
|
||||
grabMouse(theGrabMouseFlag);
|
||||
settings->theGrabMouseFlag = !settings->theGrabMouseFlag;
|
||||
grabMouse(settings->theGrabMouseFlag);
|
||||
}
|
||||
}
|
||||
else if(key == SDLK_h)
|
||||
|
@ -868,8 +814,8 @@ void handleEvents()
|
|||
// don't change hidecursor in fullscreen mode
|
||||
if(!isFullscreen)
|
||||
{
|
||||
theHideCursorFlag = !theHideCursorFlag;
|
||||
showCursor(!theHideCursorFlag);
|
||||
settings->theHideCursorFlag = !settings->theHideCursorFlag;
|
||||
showCursor(!settings->theHideCursorFlag);
|
||||
}
|
||||
}
|
||||
else // check all the other keys
|
||||
|
@ -902,18 +848,18 @@ void handleEvents()
|
|||
{
|
||||
int resistance = 0, x = 0;
|
||||
float fudgeFactor = 1000000.0;
|
||||
int width = theWidth * 2 * theWindowSize;
|
||||
Int32 width = settings->theWidth * settings->theWindowSize * 2;
|
||||
|
||||
// Grabmouse and hidecursor introduce some lag into the mouse movement,
|
||||
// so we need to fudge the numbers a bit
|
||||
if(theGrabMouseFlag && theHideCursorFlag)
|
||||
if(settings->theGrabMouseFlag && settings->theHideCursorFlag)
|
||||
{
|
||||
mouseX = (int)((float)mouseX + (float)event.motion.xrel
|
||||
* 1.5 * (float)theWindowSize);
|
||||
* 1.5 * (float) settings->theWindowSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
mouseX = mouseX + event.motion.xrel * theWindowSize;
|
||||
mouseX = mouseX + event.motion.xrel * settings->theWindowSize;
|
||||
}
|
||||
|
||||
// Check to make sure mouseX is within the game window
|
||||
|
@ -926,35 +872,35 @@ void handleEvents()
|
|||
resistance = (Int32)((fudgeFactor * x) / width);
|
||||
|
||||
// Now, set the event of the correct paddle to the calculated resistance
|
||||
if(thePaddleMode == 0)
|
||||
if(settings->thePaddleMode == 0)
|
||||
theEvent.set(Event::PaddleZeroResistance, resistance);
|
||||
else if(thePaddleMode == 1)
|
||||
else if(settings->thePaddleMode == 1)
|
||||
theEvent.set(Event::PaddleOneResistance, resistance);
|
||||
else if(thePaddleMode == 2)
|
||||
else if(settings->thePaddleMode == 2)
|
||||
theEvent.set(Event::PaddleTwoResistance, resistance);
|
||||
else if(thePaddleMode == 3)
|
||||
else if(settings->thePaddleMode == 3)
|
||||
theEvent.set(Event::PaddleThreeResistance, resistance);
|
||||
}
|
||||
else if(event.type == SDL_MOUSEBUTTONDOWN)
|
||||
{
|
||||
if(thePaddleMode == 0)
|
||||
if(settings->thePaddleMode == 0)
|
||||
theEvent.set(Event::PaddleZeroFire, 1);
|
||||
else if(thePaddleMode == 1)
|
||||
else if(settings->thePaddleMode == 1)
|
||||
theEvent.set(Event::PaddleOneFire, 1);
|
||||
else if(thePaddleMode == 2)
|
||||
else if(settings->thePaddleMode == 2)
|
||||
theEvent.set(Event::PaddleTwoFire, 1);
|
||||
else if(thePaddleMode == 3)
|
||||
else if(settings->thePaddleMode == 3)
|
||||
theEvent.set(Event::PaddleThreeFire, 1);
|
||||
}
|
||||
else if(event.type == SDL_MOUSEBUTTONUP)
|
||||
{
|
||||
if(thePaddleMode == 0)
|
||||
if(settings->thePaddleMode == 0)
|
||||
theEvent.set(Event::PaddleZeroFire, 0);
|
||||
else if(thePaddleMode == 1)
|
||||
else if(settings->thePaddleMode == 1)
|
||||
theEvent.set(Event::PaddleOneFire, 0);
|
||||
else if(thePaddleMode == 2)
|
||||
else if(settings->thePaddleMode == 2)
|
||||
theEvent.set(Event::PaddleTwoFire, 0);
|
||||
else if(thePaddleMode == 3)
|
||||
else if(settings->thePaddleMode == 3)
|
||||
theEvent.set(Event::PaddleThreeFire, 0);
|
||||
}
|
||||
else if(event.type == SDL_ACTIVEEVENT)
|
||||
|
@ -988,7 +934,7 @@ void handleEvents()
|
|||
1 : keyboardEvent.get(Event::JoystickZeroFire));
|
||||
|
||||
// If we're using real paddles then set paddle event as well
|
||||
if(thePaddleMode == 4)
|
||||
if(settings->thePaddleMode == 4)
|
||||
theEvent.set(Event::PaddleZeroFire, state);
|
||||
}
|
||||
else if(button == 1) // booster button
|
||||
|
@ -997,7 +943,7 @@ void handleEvents()
|
|||
1 : keyboardEvent.get(Event::BoosterGripZeroTrigger));
|
||||
|
||||
// If we're using real paddles then set paddle event as well
|
||||
if(thePaddleMode == 4)
|
||||
if(settings->thePaddleMode == 4)
|
||||
theEvent.set(Event::PaddleOneFire, state);
|
||||
}
|
||||
}
|
||||
|
@ -1014,7 +960,7 @@ void handleEvents()
|
|||
1 : keyboardEvent.get(Event::JoystickZeroRight));
|
||||
|
||||
// If we're using real paddles then set paddle events as well
|
||||
if(thePaddleMode == 4)
|
||||
if(settings->thePaddleMode == 4)
|
||||
{
|
||||
uInt32 r = (uInt32)((1.0E6L * (value + 32767L)) / 65536);
|
||||
theEvent.set(Event::PaddleZeroResistance, r);
|
||||
|
@ -1028,7 +974,7 @@ void handleEvents()
|
|||
1 : keyboardEvent.get(Event::JoystickZeroDown));
|
||||
|
||||
// If we're using real paddles then set paddle events as well
|
||||
if(thePaddleMode == 4)
|
||||
if(settings->thePaddleMode == 4)
|
||||
{
|
||||
uInt32 r = (uInt32)((1.0E6L * (value + 32767L)) / 65536);
|
||||
theEvent.set(Event::PaddleOneResistance, r);
|
||||
|
@ -1052,7 +998,7 @@ void handleEvents()
|
|||
1 : keyboardEvent.get(Event::JoystickOneFire));
|
||||
|
||||
// If we're using real paddles then set paddle event as well
|
||||
if(thePaddleMode == 4)
|
||||
if(settings->thePaddleMode == 4)
|
||||
theEvent.set(Event::PaddleTwoFire, state);
|
||||
}
|
||||
else if(button == 1) // booster button
|
||||
|
@ -1061,7 +1007,7 @@ void handleEvents()
|
|||
1 : keyboardEvent.get(Event::BoosterGripOneTrigger));
|
||||
|
||||
// If we're using real paddles then set paddle event as well
|
||||
if(thePaddleMode == 4)
|
||||
if(settings->thePaddleMode == 4)
|
||||
theEvent.set(Event::PaddleThreeFire, state);
|
||||
}
|
||||
}
|
||||
|
@ -1078,7 +1024,7 @@ void handleEvents()
|
|||
1 : keyboardEvent.get(Event::JoystickOneRight));
|
||||
|
||||
// If we're using real paddles then set paddle events as well
|
||||
if(thePaddleMode == 4)
|
||||
if(settings->thePaddleMode == 4)
|
||||
{
|
||||
uInt32 r = (uInt32)((1.0E6L * (value + 32767L)) / 65536);
|
||||
theEvent.set(Event::PaddleTwoResistance, r);
|
||||
|
@ -1092,7 +1038,7 @@ void handleEvents()
|
|||
1 : keyboardEvent.get(Event::JoystickOneDown));
|
||||
|
||||
// If we're using real paddles then set paddle events as well
|
||||
if(thePaddleMode == 4)
|
||||
if(settings->thePaddleMode == 4)
|
||||
{
|
||||
uInt32 r = (uInt32)((1.0E6L * (value + 32767L)) / 65536);
|
||||
theEvent.set(Event::PaddleThreeResistance, r);
|
||||
|
@ -1124,14 +1070,14 @@ void takeSnapshot()
|
|||
}
|
||||
|
||||
// Now find the correct name for the snapshot
|
||||
string filename = theSnapShotDir;
|
||||
if(theSnapShotName == "romname")
|
||||
string filename = settings->theSnapShotDir;
|
||||
if(settings->theSnapShotName == "romname")
|
||||
filename = filename + "/" + theConsole->properties().get("Cartridge.Name");
|
||||
else if(theSnapShotName == "md5sum")
|
||||
else if(settings->theSnapShotName == "md5sum")
|
||||
filename = filename + "/" + theConsole->properties().get("Cartridge.MD5");
|
||||
else
|
||||
{
|
||||
cerr << "ERROR: unknown name " << theSnapShotName
|
||||
cerr << "ERROR: unknown name " << settings->theSnapShotName
|
||||
<< " for snapshot type" << endl;
|
||||
return;
|
||||
}
|
||||
|
@ -1140,7 +1086,7 @@ void takeSnapshot()
|
|||
replace(filename.begin(), filename.end(), ' ', '_');
|
||||
|
||||
// Check whether we want multiple snapshots created
|
||||
if(theMultipleSnapShotFlag)
|
||||
if(settings->theMultipleSnapShotFlag)
|
||||
{
|
||||
// Determine if the file already exists, checking each successive filename
|
||||
// until one doesn't exist
|
||||
|
@ -1165,7 +1111,7 @@ void takeSnapshot()
|
|||
filename = filename + ".png";
|
||||
|
||||
// Now save the snapshot file
|
||||
snapshot->savePNG(filename, theConsole->mediaSource(), theWindowSize);
|
||||
snapshot->savePNG(filename, theConsole->mediaSource(), settings->theWindowSize);
|
||||
|
||||
if(access(filename.c_str(), F_OK) == 0)
|
||||
cerr << "Snapshot saved as " << filename << endl;
|
||||
|
@ -1198,14 +1144,14 @@ uInt32 maxWindowSizeForScreen()
|
|||
int screenHeight = DisplayHeight(info.info.x11.display,
|
||||
DefaultScreen(theX11Display));
|
||||
|
||||
uInt32 multiplier = screenWidth / (theWidth * 2);
|
||||
uInt32 multiplier = screenWidth / (settings->theWidth * 2);
|
||||
bool found = false;
|
||||
|
||||
while(!found && (multiplier > 0))
|
||||
{
|
||||
// Figure out the desired size of the window
|
||||
int width = theWidth * 2 * multiplier;
|
||||
int height = theHeight * multiplier;
|
||||
int width = settings->theWidth * multiplier * 2;
|
||||
int height = settings->theHeight * multiplier;
|
||||
|
||||
if((width < screenWidth) && (height < screenHeight))
|
||||
found = true;
|
||||
|
@ -1277,16 +1223,16 @@ bool setupProperties(PropertiesSet& set)
|
|||
|
||||
// Check to see if the user has specified an alternate .pro file.
|
||||
// If it exists, use it.
|
||||
if(theAlternateProFile != "")
|
||||
if(settings->theAlternateProFile != "")
|
||||
{
|
||||
if(access(theAlternateProFile.c_str(), R_OK) == 0)
|
||||
if(access(settings->theAlternateProFile.c_str(), R_OK) == 0)
|
||||
{
|
||||
set.load(theAlternateProFile, &Console::defaultProperties(), false);
|
||||
set.load(settings->theAlternateProFile, &Console::defaultProperties(), false);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "ERROR: Couldn't find \"" << theAlternateProFile <<
|
||||
cerr << "ERROR: Couldn't find \"" << settings->theAlternateProFile <<
|
||||
"\" properties file." << endl;
|
||||
return false;
|
||||
}
|
||||
|
@ -1310,115 +1256,6 @@ bool setupProperties(PropertiesSet& set)
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
Should be called to parse the command line arguments
|
||||
|
||||
@param argc The count of command line arguments
|
||||
@param argv The command line arguments
|
||||
*/
|
||||
void handleCommandLineArguments(int argc, char* argv[])
|
||||
{
|
||||
// Make sure we have the correct number of command line arguments
|
||||
if(argc == 1)
|
||||
usage();
|
||||
|
||||
for(Int32 i = 1; i < (argc - 1); ++i)
|
||||
{
|
||||
// See which command line switch they're using
|
||||
if(string(argv[i]) == "-fps")
|
||||
{
|
||||
// They're setting the desired frame rate
|
||||
Int32 rate = atoi(argv[++i]);
|
||||
if((rate < 1) || (rate > 300))
|
||||
{
|
||||
rate = 60;
|
||||
}
|
||||
|
||||
theDesiredFrameRate = rate;
|
||||
}
|
||||
else if(string(argv[i]) == "-paddle")
|
||||
{
|
||||
// They're trying to set the paddle emulation mode
|
||||
if(string(argv[i + 1]) == "real")
|
||||
{
|
||||
thePaddleMode = 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
thePaddleMode = atoi(argv[i + 1]);
|
||||
if((thePaddleMode < 0) || (thePaddleMode > 3))
|
||||
{
|
||||
usage();
|
||||
}
|
||||
}
|
||||
++i;
|
||||
}
|
||||
else if(string(argv[i]) == "-owncmap")
|
||||
{
|
||||
theUsePrivateColormapFlag = true;
|
||||
}
|
||||
else if(string(argv[i]) == "-fullscreen")
|
||||
{
|
||||
theUseFullScreenFlag = true;
|
||||
}
|
||||
else if(string(argv[i]) == "-grabmouse")
|
||||
{
|
||||
theGrabMouseFlag = true;
|
||||
}
|
||||
else if(string(argv[i]) == "-hidecursor")
|
||||
{
|
||||
theHideCursorFlag = true;
|
||||
}
|
||||
else if(string(argv[i]) == "-center")
|
||||
{
|
||||
theCenterWindowFlag = true;
|
||||
}
|
||||
else if(string(argv[i]) == "-showinfo")
|
||||
{
|
||||
theShowInfoFlag = true;
|
||||
}
|
||||
else if(string(argv[i]) == "-zoom")
|
||||
{
|
||||
uInt32 size = atoi(argv[++i]);
|
||||
theWindowSize = size;
|
||||
}
|
||||
else if(string(argv[i]) == "-volume")
|
||||
{
|
||||
// They're setting the desired volume
|
||||
Int32 volume = atoi(argv[++i]);
|
||||
if(volume < 0)
|
||||
volume = 0;
|
||||
if(volume > 100)
|
||||
volume = 100;
|
||||
|
||||
theDesiredVolume = volume;
|
||||
}
|
||||
#ifdef HAVE_PNG
|
||||
else if(string(argv[i]) == "-ssdir")
|
||||
{
|
||||
theSnapShotDir = argv[++i];
|
||||
}
|
||||
else if(string(argv[i]) == "-ssname")
|
||||
{
|
||||
theSnapShotName = argv[++i];
|
||||
}
|
||||
else if(string(argv[i]) == "-sssingle")
|
||||
{
|
||||
theMultipleSnapShotFlag = false;
|
||||
}
|
||||
#endif
|
||||
else if(string(argv[i]) == "-pro")
|
||||
{
|
||||
theAlternateProFile = argv[++i];
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Undefined option " << argv[i] << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Should be called to determine if an rc file exists. First checks if there
|
||||
is a user specified file ".stellarc" and then if there is a system-wide
|
||||
|
@ -1432,161 +1269,12 @@ void handleRCFile()
|
|||
if(access(homeRCFile.c_str(), R_OK) == 0 )
|
||||
{
|
||||
ifstream homeStream(homeRCFile.c_str());
|
||||
parseRCOptions(homeStream);
|
||||
settings->handleRCFile(homeStream);
|
||||
}
|
||||
else if(access("/etc/stellarc", R_OK) == 0 )
|
||||
{
|
||||
ifstream systemStream("/etc/stellarc");
|
||||
parseRCOptions(systemStream);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Parses each line of the given rcfile and sets options accordingly.
|
||||
|
||||
@param in The file to parse for options
|
||||
*/
|
||||
void parseRCOptions(istream& in)
|
||||
{
|
||||
string line, key, value;
|
||||
uInt32 equalPos;
|
||||
|
||||
while(getline(in, line))
|
||||
{
|
||||
// Strip all whitespace and tabs from the line
|
||||
uInt32 garbage;
|
||||
while((garbage = line.find(" ")) != string::npos)
|
||||
line.erase(garbage, 1);
|
||||
while((garbage = line.find("\t")) != string::npos)
|
||||
line.erase(garbage, 1);
|
||||
|
||||
// Ignore commented and empty lines
|
||||
if((line.length() == 0) || (line[0] == ';'))
|
||||
continue;
|
||||
|
||||
// Search for the equal sign and discard the line if its not found
|
||||
if((equalPos = line.find("=")) == string::npos)
|
||||
continue;
|
||||
|
||||
key = line.substr(0, equalPos);
|
||||
value = line.substr(equalPos + 1, line.length() - key.length() - 1);
|
||||
|
||||
// Check for absent key or value
|
||||
if((key.length() == 0) || (value.length() == 0))
|
||||
continue;
|
||||
|
||||
// Now set up the options by key
|
||||
if(key == "fps")
|
||||
{
|
||||
// They're setting the desired frame rate
|
||||
uInt32 rate = atoi(value.c_str());
|
||||
if((rate < 1) || (rate > 300))
|
||||
{
|
||||
rate = 60;
|
||||
}
|
||||
|
||||
theDesiredFrameRate = rate;
|
||||
}
|
||||
else if(key == "paddle")
|
||||
{
|
||||
// They're trying to set the paddle emulation mode
|
||||
uInt32 pMode;
|
||||
if(value == "real")
|
||||
{
|
||||
thePaddleMode = 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
pMode = atoi(value.c_str());
|
||||
if((pMode > 0) && (pMode < 4))
|
||||
thePaddleMode = pMode;
|
||||
}
|
||||
}
|
||||
else if(key == "owncmap")
|
||||
{
|
||||
uInt32 option = atoi(value.c_str());
|
||||
if(option == 1)
|
||||
theUsePrivateColormapFlag = true;
|
||||
else if(option == 0)
|
||||
theUsePrivateColormapFlag = false;
|
||||
}
|
||||
else if(key == "fullscreen")
|
||||
{
|
||||
uInt32 option = atoi(value.c_str());
|
||||
if(option == 1)
|
||||
theUseFullScreenFlag = true;
|
||||
else if(option == 0)
|
||||
theUseFullScreenFlag = false;
|
||||
}
|
||||
else if(key == "grabmouse")
|
||||
{
|
||||
uInt32 option = atoi(value.c_str());
|
||||
if(option == 1)
|
||||
theGrabMouseFlag = true;
|
||||
else if(option == 0)
|
||||
theGrabMouseFlag = false;
|
||||
}
|
||||
else if(key == "hidecursor")
|
||||
{
|
||||
uInt32 option = atoi(value.c_str());
|
||||
if(option == 1)
|
||||
theHideCursorFlag = true;
|
||||
else if(option == 0)
|
||||
theHideCursorFlag = false;
|
||||
}
|
||||
else if(key == "center")
|
||||
{
|
||||
uInt32 option = atoi(value.c_str());
|
||||
if(option == 1)
|
||||
theCenterWindowFlag = true;
|
||||
else if(option == 0)
|
||||
theCenterWindowFlag = false;
|
||||
}
|
||||
else if(key == "showinfo")
|
||||
{
|
||||
uInt32 option = atoi(value.c_str());
|
||||
if(option == 1)
|
||||
theShowInfoFlag = true;
|
||||
else if(option == 0)
|
||||
theShowInfoFlag = false;
|
||||
}
|
||||
else if(key == "zoom")
|
||||
{
|
||||
// They're setting the initial window size
|
||||
// Don't do bounds checking here, it will be taken care of later
|
||||
uInt32 size = atoi(value.c_str());
|
||||
theWindowSize = size;
|
||||
}
|
||||
else if(key == "volume")
|
||||
{
|
||||
// They're setting the desired volume
|
||||
uInt32 volume = atoi(value.c_str());
|
||||
if(volume < 0)
|
||||
volume = 0;
|
||||
if(volume > 100)
|
||||
volume = 100;
|
||||
|
||||
theDesiredVolume = volume;
|
||||
}
|
||||
#ifdef HAVE_PNG
|
||||
else if(key == "ssdir")
|
||||
{
|
||||
theSnapShotDir = value;
|
||||
}
|
||||
else if(key == "ssname")
|
||||
{
|
||||
theSnapShotName = value;
|
||||
}
|
||||
else if(key == "sssingle")
|
||||
{
|
||||
uInt32 option = atoi(value.c_str());
|
||||
if(option == 1)
|
||||
theMultipleSnapShotFlag = false;
|
||||
else if(option == 0)
|
||||
theMultipleSnapShotFlag = true;
|
||||
}
|
||||
#endif
|
||||
settings->handleRCFile(systemStream);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1599,6 +1287,9 @@ void cleanup()
|
|||
if(theConsole)
|
||||
delete theConsole;
|
||||
|
||||
if(settings)
|
||||
delete settings;
|
||||
|
||||
#ifdef HAVE_PNG
|
||||
if(snapshot)
|
||||
delete snapshot;
|
||||
|
@ -1619,11 +1310,23 @@ void cleanup()
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
// First create some settings for the emulator
|
||||
settings = new Settings();
|
||||
if(!settings)
|
||||
{
|
||||
cerr << "ERROR: Couldn't create settings." << endl;
|
||||
cleanup();
|
||||
}
|
||||
|
||||
// Load in any user defined settings from an RC file
|
||||
handleRCFile();
|
||||
|
||||
// Handle the command line arguments
|
||||
handleCommandLineArguments(argc, argv);
|
||||
if(!settings->handleCommandLineArgs(argc, argv))
|
||||
{
|
||||
usage();
|
||||
cleanup();
|
||||
}
|
||||
|
||||
// Get a pointer to the file which contains the cartridge ROM
|
||||
const char* file = argv[argc - 1];
|
||||
|
@ -1633,7 +1336,7 @@ int main(int argc, char* argv[])
|
|||
if(!in)
|
||||
{
|
||||
cerr << "ERROR: Couldn't open " << file << "..." << endl;
|
||||
exit(1);
|
||||
cleanup();
|
||||
}
|
||||
|
||||
uInt8* image = new uInt8[512 * 1024];
|
||||
|
@ -1646,11 +1349,11 @@ int main(int argc, char* argv[])
|
|||
if(!setupProperties(propertiesSet))
|
||||
{
|
||||
delete[] image;
|
||||
exit(1);
|
||||
cleanup();
|
||||
}
|
||||
|
||||
// Create a sound object for use with the console
|
||||
SoundUnix sound(theDesiredVolume);
|
||||
SoundUnix sound(settings->theDesiredVolume);
|
||||
|
||||
// Get just the filename of the file containing the ROM image
|
||||
const char* filename = (!strrchr(file, '/')) ? file : strrchr(file, '/') + 1;
|
||||
|
@ -1718,7 +1421,7 @@ int main(int argc, char* argv[])
|
|||
// Set up timing stuff
|
||||
uInt32 startTime, frameTime, delta;
|
||||
uInt32 numberOfFrames = 0;
|
||||
uInt32 timePerFrame = (uInt32) (1000000.0 / (double) theDesiredFrameRate);
|
||||
uInt32 timePerFrame = (uInt32) (1000000.0 / (double) settings->theDesiredFrameRate);
|
||||
|
||||
// Set the base for the timers
|
||||
frameTime = 0;
|
||||
|
@ -1760,7 +1463,7 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
#endif
|
||||
|
||||
if(theShowInfoFlag)
|
||||
if(settings->theShowInfoFlag)
|
||||
{
|
||||
double executionTime = (double) frameTime / 1000000.0;
|
||||
double framesPerSecond = (double) numberOfFrames / executionTime;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue