8
8
// SS SS tt ee ll ll aa aa
9
9
// SSSS ttt eeeee llll llll aaaaa
11
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
11
// Copyright (c) 1995-2008 by Bradford W. Mott and the Stella team
13
13
// See the file "license" for information on usage and redistribution of
14
14
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
16
// $Id: OSystemUNIX.cxx,v 1.20 2006/03/25 00:34:17 stephena Exp $
16
// $Id: OSystemUNIX.cxx,v 1.29 2008/05/16 23:56:31 stephena Exp $
17
17
//============================================================================
20
#include <SDL_syswm.h>
41
38
in its constructor:
49
43
See OSystem.hxx for a further explanation
52
46
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
53
47
OSystemUNIX::OSystemUNIX()
55
// First set variables that the OSystem needs
56
string basedir = string(getenv("HOME")) + "/.stella";
50
const string& basedir = string(getenv("HOME")) + "/.stella";
57
51
setBaseDir(basedir);
59
setStateDir(basedir + "/state");
61
setPropertiesDir(basedir);
62
52
setConfigFile(basedir + "/stellarc");
64
setCacheFile(basedir + "/stella.cache");
67
55
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
72
60
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
73
void OSystemUNIX::mainLoop()
75
// These variables are common to both timing options
76
// and are needed to calculate the overall frames per second.
77
uInt32 frameTime = 0, numberOfFrames = 0;
79
if(mySettings->getBool("accurate")) // normal, CPU-intensive timing
81
// Set up accurate timing stuff
82
uInt32 startTime, delta;
84
// Set the base for the timers
90
// Exit if the user wants to quit
91
if(myEventHandler->doQuit())
94
startTime = getTicks();
95
myEventHandler->poll(startTime);
96
myFrameBuffer->update();
98
// Now, waste time if we need to so that we are at the desired frame rate
101
delta = getTicks() - startTime;
103
if(delta >= myTimePerFrame)
107
frameTime += getTicks() - startTime;
111
else // less accurate, less CPU-intensive timing
113
// Set up less accurate timing stuff
114
uInt32 startTime, virtualTime, currentTime;
116
// Set the base for the timers
117
virtualTime = getTicks();
123
// Exit if the user wants to quit
124
if(myEventHandler->doQuit())
127
startTime = getTicks();
128
myEventHandler->poll(startTime);
129
myFrameBuffer->update();
131
currentTime = getTicks();
132
virtualTime += myTimePerFrame;
133
if(currentTime < virtualTime)
135
SDL_Delay((virtualTime - currentTime)/1000);
138
currentTime = getTicks() - startTime;
139
frameTime += currentTime;
144
// Only print console information if a console was actually created
145
if(mySettings->getBool("showinfo") && myConsole)
147
double executionTime = (double) frameTime / 1000000.0;
148
double framesPerSecond = (double) numberOfFrames / executionTime;
151
cout << numberOfFrames << " total frames drawn\n";
152
cout << framesPerSecond << " frames/second\n";
154
cout << "Cartridge Name: " << myConsole->properties().get(Cartridge_Name);
156
cout << "Cartridge MD5: " << myConsole->properties().get(Cartridge_MD5);
157
cout << endl << endl;
161
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
162
uInt32 OSystemUNIX::getTicks()
61
uInt32 OSystemUNIX::getTicks() const
164
63
#ifdef HAVE_GETTIMEOFDAY
170
69
return (uInt32) SDL_GetTicks() * 1000;
174
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
175
void OSystemUNIX::getScreenDimensions(int& width, int& height)
177
// We might need to temporarily enable VIDEO support to check
179
bool isAlreadyInitialized = (SDL_WasInit(SDL_INIT_VIDEO) & SDL_INIT_VIDEO) > 0;
180
if(!isAlreadyInitialized)
181
SDL_Init(SDL_INIT_VIDEO);
183
SDL_SysWMinfo myWMInfo;
184
SDL_VERSION(&myWMInfo.version);
185
if(SDL_GetWMInfo(&myWMInfo) > 0 && myWMInfo.subsystem == SDL_SYSWM_X11)
187
myWMInfo.info.x11.lock_func();
188
width = DisplayWidth(myWMInfo.info.x11.display,
189
DefaultScreen(myWMInfo.info.x11.display));
190
height = DisplayHeight(myWMInfo.info.x11.display,
191
DefaultScreen(myWMInfo.info.x11.display));
192
myWMInfo.info.x11.unlock_func();
195
if(!isAlreadyInitialized)
196
SDL_QuitSubSystem(SDL_INIT_VIDEO);