From e5ea2f99be04f044a3054365fd7e7a111bfbd834 Mon Sep 17 00:00:00 2001 From: markgrebe Date: Sat, 28 May 2005 01:28:36 +0000 Subject: [PATCH] Added Mac Specific Classes git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@446 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/macosx/OSystemMACOSX.cxx | 183 ++++++++++++++++++++++++++++ stella/src/macosx/OSystemMACOSX.hxx | 61 ++++++++++ 2 files changed, 244 insertions(+) create mode 100644 stella/src/macosx/OSystemMACOSX.cxx create mode 100644 stella/src/macosx/OSystemMACOSX.hxx diff --git a/stella/src/macosx/OSystemMACOSX.cxx b/stella/src/macosx/OSystemMACOSX.cxx new file mode 100644 index 000000000..652c74014 --- /dev/null +++ b/stella/src/macosx/OSystemMACOSX.cxx @@ -0,0 +1,183 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-1999 by Bradford W. Mott +// +// See the file "license" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +// +// $Id: OSystemMACOSX.cxx,v 1.1 2005-05-28 01:28:36 markgrebe Exp $ +//============================================================================ + +#include +#include +#include +#include + +#include +#include +#include + +#include "bspf.hxx" +#include "OSystem.hxx" +#include "OSystemMACOSX.hxx" + +#ifdef HAVE_GETTIMEOFDAY + #include + #include +#endif + +extern "C" { +void macOpenConsole(char *romname); +} + +// Pointer to the main parent osystem object or the null pointer +extern OSystem* theOSystem; + +static double Atari_time(void); + +// Allow the SDL main object to pass request to open cartridges from +// the OS into the application. +void macOpenConsole(char *romname) +{ + theOSystem->createConsole(romname); +} + +/** + Each derived class is responsible for calling the following methods + in its constructor: + + setBaseDir() + setStateDir() + setPropertiesFiles() + setConfigFiles() + setCacheFile() + + See OSystem.hxx for a further explanation +*/ + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +OSystemMACOSX::OSystemMACOSX() +{ + // First set variables that the OSystem needs + string basedir = string(getenv("HOME")) + "/.stella"; + setBaseDir(basedir); + + string statedir = basedir + "/state"; + setStateDir(statedir); + + string userPropertiesFile = basedir + "/stella.pro"; + string systemPropertiesFile = "/etc/stella.pro"; + setPropertiesFiles(userPropertiesFile, systemPropertiesFile); + + string userConfigFile = basedir + "/stellarc"; + string systemConfigFile = "/etc/stellarc"; + setConfigFiles(userConfigFile, systemConfigFile); + + string cacheFile = basedir + "/stella.cache"; + setCacheFile(cacheFile); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +OSystemMACOSX::~OSystemMACOSX() +{ +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void OSystemMACOSX::mainLoop() +{ +#if 0 + double lasttime = Atari_time(); + double lastcurtime = 0; + double curtime, delaytime; + double timePerFrame = 1.0 / 60.0; + + // Main game loop + for(;;) + { + // Exit if the user wants to quit + if(myEventHandler->doQuit()) + break; + + myEventHandler->poll(); + myFrameBuffer->update(); + + if (timePerFrame > 0.0) + { + curtime = Atari_time(); + delaytime = lasttime + timePerFrame - curtime; + if (delaytime > 0) + usleep((int) (delaytime * 1e6)); + curtime = Atari_time(); + + lastcurtime = curtime; + + lasttime += timePerFrame; + if ((lasttime + timePerFrame) < curtime) + lasttime = curtime; + } + } +#else + // These variables are common to both timing options + // and are needed to calculate the overall frames per second. + uInt32 frameTime = 0, numberOfFrames = 0; + + // Set up less accurate timing stuff + uInt32 startTime, virtualTime, currentTime; + + // Set the base for the timers + virtualTime = getTicks(); + frameTime = 0; + + // Main game loop + for(;;) + { + // Exit if the user wants to quit + if(myEventHandler->doQuit()) + break; + + startTime = getTicks(); + myEventHandler->poll(startTime); + myFrameBuffer->update(); + + currentTime = getTicks(); + virtualTime += myTimePerFrame; + if(currentTime < virtualTime) + { + SDL_Delay((virtualTime - currentTime)/1000); + } + + currentTime = getTicks() - startTime; + frameTime += currentTime; + ++numberOfFrames; + } +#endif +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +uInt32 OSystemMACOSX::getTicks() +{ +#ifdef HAVE_GETTIMEOFDAY + timeval now; + gettimeofday(&now, 0); + + return (uInt32) (now.tv_sec * 1000000 + now.tv_usec); +#else + return (uInt32) SDL_GetTicks() * 1000; +#endif +} + +static double Atari_time(void) +{ + struct timeval tp; + + gettimeofday(&tp, NULL); + return tp.tv_sec + 1e-6 * tp.tv_usec; +} diff --git a/stella/src/macosx/OSystemMACOSX.hxx b/stella/src/macosx/OSystemMACOSX.hxx new file mode 100644 index 000000000..2569529c6 --- /dev/null +++ b/stella/src/macosx/OSystemMACOSX.hxx @@ -0,0 +1,61 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-1999 by Bradford W. Mott +// +// See the file "license" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +// +// $Id: OSystemMACOSX.hxx,v 1.1 2005-05-28 01:28:36 markgrebe Exp $ +//============================================================================ + +#ifndef OSYSTEM_MACOSX_HXX +#define OSYSTEM_MACOSX_HXX + +#include "bspf.hxx" + + +/** + This class defines UNIX-like OS's (Linux) system specific settings. + + @author Mark Grebe + @version $Id: OSystemMACOSX.hxx,v 1.1 2005-05-28 01:28:36 markgrebe Exp $ +*/ +class OSystemMACOSX : public OSystem +{ + public: + /** + Create a new UNIX-specific operating system object + */ + OSystemMACOSX(); + + /** + Destructor + */ + virtual ~OSystemMACOSX(); + + public: + /** + This method runs the main loop. Since different platforms + may use different timing methods and/or algorithms, this method has + been abstracted to each platform. + */ + virtual void mainLoop(); + + /** + This method returns number of ticks in microseconds. + + @return Current time in microseconds. + */ + virtual uInt32 getTicks(); + +}; + +#endif