2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2002-04-21 17:46:42 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-04-21 17:46:42 +00:00
|
|
|
*
|
2006-02-11 12:47:47 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2002-04-21 17:46:42 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-08-05 00:21:46 +00:00
|
|
|
#if defined(WIN32)
|
|
|
|
#include <windows.h>
|
|
|
|
#if defined(ARRAYSIZE)
|
|
|
|
// winnt.h defines ARRAYSIZE, but we want our own one... - this is needed before including util.h
|
|
|
|
#undef ARRAYSIZE
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2007-08-11 08:44:43 +00:00
|
|
|
#include "backends/platform/sdl/sdl.h"
|
2008-09-07 21:30:55 +00:00
|
|
|
#include "common/archive.h"
|
2004-02-29 00:49:40 +00:00
|
|
|
#include "common/config-manager.h"
|
2007-09-19 13:55:05 +00:00
|
|
|
#include "common/events.h"
|
2002-09-19 17:03:24 +00:00
|
|
|
#include "common/util.h"
|
2001-11-05 19:21:49 +00:00
|
|
|
|
2008-11-03 10:45:59 +00:00
|
|
|
#ifdef UNIX
|
|
|
|
#include "backends/saves/posix/posix-saves.h"
|
|
|
|
#else
|
|
|
|
#include "backends/saves/default/default-saves.h"
|
|
|
|
#endif
|
2006-10-22 15:42:29 +00:00
|
|
|
#include "backends/timer/default/default-timer.h"
|
2008-06-28 15:28:29 +00:00
|
|
|
#include "sound/mixer_intern.h"
|
2006-10-22 15:42:29 +00:00
|
|
|
|
2006-04-14 00:55:37 +00:00
|
|
|
#include "icons/scummvm.xpm"
|
2002-03-10 07:48:01 +00:00
|
|
|
|
2008-03-12 18:36:51 +00:00
|
|
|
#include <time.h> // for getTimeAndDate()
|
|
|
|
|
2008-01-22 14:16:02 +00:00
|
|
|
//#define SAMPLES_PER_SEC 11025
|
|
|
|
#define SAMPLES_PER_SEC 22050
|
|
|
|
//#define SAMPLES_PER_SEC 44100
|
|
|
|
|
2008-08-03 17:05:01 +00:00
|
|
|
|
2008-03-11 17:24:34 +00:00
|
|
|
/*
|
|
|
|
* Include header files needed for the getFilesystemFactory() method.
|
|
|
|
*/
|
|
|
|
#if defined(__amigaos4__)
|
|
|
|
#include "backends/fs/amigaos4/amigaos4-fs-factory.h"
|
|
|
|
#elif defined(UNIX)
|
|
|
|
#include "backends/fs/posix/posix-fs-factory.h"
|
|
|
|
#elif defined(WIN32)
|
|
|
|
#include "backends/fs/windows/windows-fs-factory.h"
|
|
|
|
#endif
|
|
|
|
|
2008-01-22 14:16:02 +00:00
|
|
|
|
2008-08-03 17:05:01 +00:00
|
|
|
#if defined(UNIX)
|
|
|
|
#ifdef MACOSX
|
|
|
|
#define DEFAULT_CONFIG_FILE "Library/Preferences/ScummVM Preferences"
|
|
|
|
#else
|
|
|
|
#define DEFAULT_CONFIG_FILE ".scummvmrc"
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#define DEFAULT_CONFIG_FILE "scummvm.ini"
|
|
|
|
#endif
|
|
|
|
|
2008-09-07 21:30:55 +00:00
|
|
|
#if defined(MACOSX) || defined(IPHONE)
|
|
|
|
#include "CoreFoundation/CoreFoundation.h"
|
|
|
|
#endif
|
2008-08-03 17:05:01 +00:00
|
|
|
|
|
|
|
|
2006-11-12 11:47:43 +00:00
|
|
|
static Uint32 timer_handler(Uint32 interval, void *param) {
|
|
|
|
((DefaultTimerManager *)param)->handler();
|
|
|
|
return interval;
|
|
|
|
}
|
|
|
|
|
2005-04-19 20:22:50 +00:00
|
|
|
void OSystem_SDL::initBackend() {
|
|
|
|
assert(!_inited);
|
2002-11-13 14:38:49 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
int joystick_num = ConfMan.getInt("joystick_num");
|
|
|
|
uint32 sdlFlags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER;
|
2002-04-13 12:43:02 +00:00
|
|
|
|
2005-10-18 03:52:21 +00:00
|
|
|
if (ConfMan.hasKey("disable_sdl_parachute"))
|
|
|
|
sdlFlags |= SDL_INIT_NOPARACHUTE;
|
|
|
|
|
2004-05-09 14:27:53 +00:00
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
if (ConfMan.hasKey("use_GDI") && ConfMan.getBool("use_GDI")) {
|
|
|
|
SDL_VideoInit("windib", 0);
|
|
|
|
sdlFlags ^= SDL_INIT_VIDEO;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
if (joystick_num > -1)
|
|
|
|
sdlFlags |= SDL_INIT_JOYSTICK;
|
2003-10-05 00:40:25 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
if (SDL_Init(sdlFlags) == -1) {
|
|
|
|
error("Could not initialize SDL: %s", SDL_GetError());
|
2001-11-06 20:00:47 +00:00
|
|
|
}
|
2002-06-14 04:31:17 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
_graphicsMutex = createMutex();
|
2003-06-22 11:55:40 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
SDL_ShowCursor(SDL_DISABLE);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
// Enable unicode support if possible
|
2005-07-30 21:11:48 +00:00
|
|
|
SDL_EnableUNICODE(1);
|
2001-11-06 20:00:47 +00:00
|
|
|
|
2008-11-14 23:10:14 +00:00
|
|
|
memset(&_oldVideoMode, 0, sizeof(_oldVideoMode));
|
|
|
|
memset(&_videoMode, 0, sizeof(_videoMode));
|
|
|
|
memset(&_transactionDetails, 0, sizeof(_transactionDetails));
|
2008-11-14 22:08:10 +00:00
|
|
|
|
2004-12-01 21:16:55 +00:00
|
|
|
_cksumValid = false;
|
2005-09-20 18:16:09 +00:00
|
|
|
#if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) && !defined(DISABLE_SCALERS)
|
2008-11-14 22:08:10 +00:00
|
|
|
_videoMode.mode = GFX_DOUBLESIZE;
|
|
|
|
_videoMode.scaleFactor = 2;
|
|
|
|
_videoMode.aspectRatio = ConfMan.getBool("aspect_ratio");
|
2004-10-15 22:28:12 +00:00
|
|
|
_scalerProc = Normal2x;
|
2005-06-21 20:39:09 +00:00
|
|
|
#else // for small screen platforms
|
2008-11-14 22:08:10 +00:00
|
|
|
_videoMode.mode = GFX_NORMAL;
|
|
|
|
_videoMode.scaleFactor = 1;
|
|
|
|
_videoMode.aspectRatio = false;
|
2004-10-15 22:28:12 +00:00
|
|
|
_scalerProc = Normal1x;
|
2007-08-11 08:44:43 +00:00
|
|
|
#endif
|
|
|
|
_scalerType = 0;
|
|
|
|
_modeFlags = 0;
|
2005-09-20 18:16:09 +00:00
|
|
|
|
2006-06-03 01:05:09 +00:00
|
|
|
#if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
|
2008-11-14 22:08:10 +00:00
|
|
|
_videoMode.fullscreen = ConfMan.getBool("fullscreen");
|
2005-09-20 18:16:09 +00:00
|
|
|
#else
|
2008-11-14 22:08:10 +00:00
|
|
|
_videoMode.fullscreen = true;
|
2005-09-20 18:16:09 +00:00
|
|
|
#endif
|
|
|
|
|
2007-08-11 08:44:43 +00:00
|
|
|
#if !defined(MACOSX) && !defined(__SYMBIAN32__)
|
|
|
|
// Setup a custom program icon.
|
|
|
|
// Don't set icon on OS X, as we use a nicer external icon there.
|
|
|
|
// Don't for Symbian: it uses the EScummVM.aif file for the icon.
|
|
|
|
setupIcon();
|
2004-02-29 00:49:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// enable joystick
|
|
|
|
if (joystick_num > -1 && SDL_NumJoysticks() > 0) {
|
|
|
|
printf("Using joystick: %s\n", SDL_JoystickName(0));
|
2004-12-01 21:16:55 +00:00
|
|
|
_joystick = SDL_JoystickOpen(joystick_num);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-10-22 15:42:29 +00:00
|
|
|
|
|
|
|
// Create the savefile manager, if none exists yet (we check for this to
|
|
|
|
// allow subclasses to provide their own).
|
|
|
|
if (_savefile == 0) {
|
2008-11-03 10:45:59 +00:00
|
|
|
#ifdef UNIX
|
|
|
|
_savefile = new POSIXSaveFileManager();
|
|
|
|
#else
|
|
|
|
_savefile = new DefaultSaveFileManager();
|
|
|
|
#endif
|
2006-10-22 15:42:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create and hook up the mixer, if none exists yet (we check for this to
|
|
|
|
// allow subclasses to provide their own).
|
|
|
|
if (_mixer == 0) {
|
2008-06-28 15:28:29 +00:00
|
|
|
setupMixer();
|
2006-10-22 15:42:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create and hook up the timer manager, if none exists yet (we check for
|
|
|
|
// this to allow subclasses to provide their own).
|
|
|
|
if (_timer == 0) {
|
2007-08-11 08:44:43 +00:00
|
|
|
// Note: We could implement a custom SDLTimerManager by using
|
2006-10-22 16:05:07 +00:00
|
|
|
// SDL_AddTimer. That might yield better timer resolution, but it would
|
|
|
|
// also change the semantics of a timer: Right now, ScummVM timers
|
|
|
|
// *never* run in parallel, due to the way they are implemented. If we
|
|
|
|
// switched to SDL_AddTimer, each timer might run in a separate thread.
|
2007-08-11 08:44:43 +00:00
|
|
|
// However, not all our code is prepared for that, so we can't just
|
|
|
|
// switch. Still, it's a potential future change to keep in mind.
|
2006-10-22 15:42:29 +00:00
|
|
|
_timer = new DefaultTimerManager();
|
2006-10-22 16:05:07 +00:00
|
|
|
_timerID = SDL_AddTimer(10, &timer_handler, _timer);
|
2006-10-22 15:42:29 +00:00
|
|
|
}
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-08-11 08:44:43 +00:00
|
|
|
// Invoke parent implementation of this method
|
2006-10-22 15:42:29 +00:00
|
|
|
OSystem::initBackend();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-04-19 20:22:50 +00:00
|
|
|
_inited = true;
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
OSystem_SDL::OSystem_SDL()
|
2004-03-13 14:19:15 +00:00
|
|
|
:
|
|
|
|
#ifdef USE_OSD
|
|
|
|
_osdSurface(0), _osdAlpha(SDL_ALPHA_TRANSPARENT), _osdFadeStartTime(0),
|
|
|
|
#endif
|
2008-11-14 22:08:10 +00:00
|
|
|
_hwscreen(0), _screen(0), _tmpscreen(0),
|
2006-05-17 23:52:45 +00:00
|
|
|
_overlayVisible(false),
|
2005-03-09 23:07:32 +00:00
|
|
|
_overlayscreen(0), _tmpscreen2(0),
|
2004-07-16 10:24:29 +00:00
|
|
|
_samplesPerSec(0),
|
2006-08-04 13:10:28 +00:00
|
|
|
_cdrom(0), _scalerProc(0), _modeChanged(false), _screenChangeCount(0), _dirtyChecksums(0),
|
2005-02-17 23:01:00 +00:00
|
|
|
_mouseVisible(false), _mouseDrawn(false), _mouseData(0), _mouseSurface(0),
|
2006-05-25 19:43:33 +00:00
|
|
|
_mouseOrigSurface(0), _cursorTargetScale(1), _cursorPaletteDisabled(true),
|
2004-12-01 21:16:55 +00:00
|
|
|
_joystick(0),
|
2004-02-29 00:49:40 +00:00
|
|
|
_currentShakePos(0), _newShakePos(0),
|
|
|
|
_paletteDirtyStart(0), _paletteDirtyEnd(0),
|
2008-07-29 00:02:06 +00:00
|
|
|
#ifdef MIXER_DOUBLE_BUFFERING
|
|
|
|
_soundMutex(0), _soundCond(0), _soundThread(0),
|
|
|
|
_soundThreadIsRunning(false), _soundThreadShouldQuit(false),
|
|
|
|
#endif
|
2008-08-22 11:36:47 +00:00
|
|
|
_fsFactory(0),
|
2006-10-22 15:42:29 +00:00
|
|
|
_savefile(0),
|
|
|
|
_mixer(0),
|
|
|
|
_timer(0),
|
2007-06-19 22:39:59 +00:00
|
|
|
_screenIsLocked(false),
|
2004-11-23 21:30:38 +00:00
|
|
|
_graphicsMutex(0), _transactionMode(kTransactionNone) {
|
2004-02-29 00:49:40 +00:00
|
|
|
|
|
|
|
// allocate palette storage
|
|
|
|
_currentPalette = (SDL_Color *)calloc(sizeof(SDL_Color), 256);
|
2005-02-17 23:01:00 +00:00
|
|
|
_cursorPalette = (SDL_Color *)calloc(sizeof(SDL_Color), 256);
|
2004-02-29 00:49:40 +00:00
|
|
|
|
2005-02-17 23:01:00 +00:00
|
|
|
_mouseBackup.x = _mouseBackup.y = _mouseBackup.w = _mouseBackup.h = 0;
|
2004-02-29 00:49:40 +00:00
|
|
|
|
|
|
|
// reset mouse state
|
2004-12-01 21:16:55 +00:00
|
|
|
memset(&_km, 0, sizeof(_km));
|
|
|
|
memset(&_mouseCurState, 0, sizeof(_mouseCurState));
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-04-19 20:22:50 +00:00
|
|
|
_inited = false;
|
2008-08-22 11:45:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
#if defined(__amigaos4__)
|
|
|
|
_fsFactory = new AmigaOSFilesystemFactory();
|
|
|
|
#elif defined(UNIX)
|
|
|
|
_fsFactory = new POSIXFilesystemFactory();
|
|
|
|
#elif defined(WIN32)
|
|
|
|
_fsFactory = new WindowsFilesystemFactory();
|
|
|
|
#elif defined(__SYMBIAN32__)
|
|
|
|
// Do nothing since its handled by the Symbian SDL inheritance
|
|
|
|
#else
|
|
|
|
#error Unknown and unsupported FS backend
|
|
|
|
#endif
|
2004-02-29 00:49:40 +00:00
|
|
|
}
|
2002-11-23 00:13:52 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
OSystem_SDL::~OSystem_SDL() {
|
2006-10-22 16:05:07 +00:00
|
|
|
SDL_RemoveTimer(_timerID);
|
2008-07-15 17:13:06 +00:00
|
|
|
closeMixer();
|
2006-10-22 16:05:07 +00:00
|
|
|
|
2004-12-01 21:16:55 +00:00
|
|
|
free(_dirtyChecksums);
|
2004-02-29 00:49:40 +00:00
|
|
|
free(_currentPalette);
|
2005-02-17 23:01:00 +00:00
|
|
|
free(_cursorPalette);
|
2004-12-01 21:16:55 +00:00
|
|
|
free(_mouseData);
|
2006-10-22 16:05:07 +00:00
|
|
|
|
|
|
|
delete _savefile;
|
|
|
|
delete _timer;
|
2004-02-29 00:49:40 +00:00
|
|
|
}
|
2002-11-23 00:13:52 +00:00
|
|
|
|
2004-09-28 20:19:37 +00:00
|
|
|
uint32 OSystem_SDL::getMillis() {
|
2007-09-19 13:55:05 +00:00
|
|
|
uint32 millis = SDL_GetTicks();
|
|
|
|
getEventManager()->processMillis(millis);
|
|
|
|
return millis;
|
2004-02-29 00:49:40 +00:00
|
|
|
}
|
2002-11-23 00:13:52 +00:00
|
|
|
|
2004-09-28 20:19:37 +00:00
|
|
|
void OSystem_SDL::delayMillis(uint msecs) {
|
2004-02-29 00:49:40 +00:00
|
|
|
SDL_Delay(msecs);
|
|
|
|
}
|
2002-11-23 00:13:52 +00:00
|
|
|
|
2008-03-12 18:36:51 +00:00
|
|
|
void OSystem_SDL::getTimeAndDate(struct tm &t) const {
|
|
|
|
time_t curTime = time(0);
|
|
|
|
t = *localtime(&curTime);
|
|
|
|
}
|
|
|
|
|
2006-10-22 15:42:29 +00:00
|
|
|
Common::TimerManager *OSystem_SDL::getTimerManager() {
|
|
|
|
assert(_timer);
|
|
|
|
return _timer;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::SaveFileManager *OSystem_SDL::getSavefileManager() {
|
|
|
|
assert(_savefile);
|
|
|
|
return _savefile;
|
|
|
|
}
|
|
|
|
|
2008-03-11 17:24:34 +00:00
|
|
|
FilesystemFactory *OSystem_SDL::getFilesystemFactory() {
|
2008-08-22 11:49:34 +00:00
|
|
|
assert(_fsFactory);
|
2008-08-22 11:36:47 +00:00
|
|
|
return _fsFactory;
|
2008-03-11 17:24:34 +00:00
|
|
|
}
|
|
|
|
|
2008-09-27 18:32:01 +00:00
|
|
|
void OSystem_SDL::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) {
|
2008-09-07 21:30:55 +00:00
|
|
|
|
|
|
|
#ifdef DATA_PATH
|
|
|
|
// Add the global DATA_PATH to the directory search list
|
|
|
|
// FIXME: We use depth = 4 for now, to match the old code. May want to change that
|
2008-10-02 16:58:59 +00:00
|
|
|
Common::FSNode dataNode(DATA_PATH);
|
2008-09-07 21:30:55 +00:00
|
|
|
if (dataNode.exists() && dataNode.isDirectory()) {
|
2008-11-07 13:50:56 +00:00
|
|
|
s.add(DATA_PATH, new Common::FSDirectory(dataNode, 4), priority);
|
2008-09-07 21:30:55 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(MACOSX) || defined(IPHONE)
|
|
|
|
// Get URL of the Resource directory of the .app bundle
|
|
|
|
CFURLRef fileUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
|
|
|
|
if (fileUrl) {
|
|
|
|
// Try to convert the URL to an absolute path
|
|
|
|
UInt8 buf[MAXPATHLEN];
|
|
|
|
if (CFURLGetFileSystemRepresentation(fileUrl, true, buf, sizeof(buf))) {
|
|
|
|
// Success: Add it to the search path
|
|
|
|
Common::String bundlePath((const char *)buf);
|
2008-11-07 13:50:56 +00:00
|
|
|
s.add("__OSX_BUNDLE__", new Common::FSDirectory(bundlePath), priority);
|
2008-09-07 21:30:55 +00:00
|
|
|
}
|
|
|
|
CFRelease(fileUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-03 17:05:01 +00:00
|
|
|
static Common::String getDefaultConfigFileName() {
|
|
|
|
char configFile[MAXPATHLEN];
|
|
|
|
#if defined (WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
|
|
|
|
OSVERSIONINFO win32OsVersion;
|
|
|
|
ZeroMemory(&win32OsVersion, sizeof(OSVERSIONINFO));
|
|
|
|
win32OsVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
|
|
|
GetVersionEx(&win32OsVersion);
|
|
|
|
// Check for non-9X version of Windows.
|
|
|
|
if (win32OsVersion.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS) {
|
|
|
|
// Use the Application Data directory of the user profile.
|
|
|
|
if (win32OsVersion.dwMajorVersion >= 5) {
|
|
|
|
if (!GetEnvironmentVariable("APPDATA", configFile, sizeof(configFile)))
|
|
|
|
error("Unable to access application data directory");
|
|
|
|
} else {
|
|
|
|
if (!GetEnvironmentVariable("USERPROFILE", configFile, sizeof(configFile)))
|
|
|
|
error("Unable to access user profile directory");
|
|
|
|
|
|
|
|
strcat(configFile, "\\Application Data");
|
|
|
|
CreateDirectory(configFile, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
strcat(configFile, "\\ScummVM");
|
|
|
|
CreateDirectory(configFile, NULL);
|
|
|
|
strcat(configFile, "\\" DEFAULT_CONFIG_FILE);
|
|
|
|
|
2008-08-16 22:30:47 +00:00
|
|
|
FILE *tmp = NULL;
|
|
|
|
if ((tmp = fopen(configFile, "r")) == NULL) {
|
2008-08-03 17:05:01 +00:00
|
|
|
// Check windows directory
|
|
|
|
char oldConfigFile[MAXPATHLEN];
|
|
|
|
GetWindowsDirectory(oldConfigFile, MAXPATHLEN);
|
|
|
|
strcat(oldConfigFile, "\\" DEFAULT_CONFIG_FILE);
|
2008-08-16 22:30:47 +00:00
|
|
|
if ((tmp = fopen(oldConfigFile, "r"))) {
|
2008-08-03 17:05:01 +00:00
|
|
|
strcpy(configFile, oldConfigFile);
|
2008-08-16 22:30:47 +00:00
|
|
|
|
|
|
|
fclose(tmp);
|
2008-08-03 17:05:01 +00:00
|
|
|
}
|
2008-08-16 22:30:47 +00:00
|
|
|
} else {
|
|
|
|
fclose(tmp);
|
2008-08-03 17:05:01 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Check windows directory
|
|
|
|
GetWindowsDirectory(configFile, MAXPATHLEN);
|
|
|
|
strcat(configFile, "\\" DEFAULT_CONFIG_FILE);
|
|
|
|
}
|
|
|
|
#elif defined(UNIX)
|
|
|
|
// On UNIX type systems, by default we store the config file inside
|
|
|
|
// to the HOME directory of the user.
|
|
|
|
//
|
|
|
|
// GP2X is Linux based but Home dir can be read only so do not use
|
|
|
|
// it and put the config in the executable dir.
|
|
|
|
//
|
|
|
|
// On the iPhone, the home dir of the user when you launch the app
|
|
|
|
// from the Springboard, is /. Which we don't want.
|
|
|
|
const char *home = getenv("HOME");
|
|
|
|
if (home != NULL && strlen(home) < MAXPATHLEN)
|
|
|
|
snprintf(configFile, MAXPATHLEN, "%s/%s", home, DEFAULT_CONFIG_FILE);
|
|
|
|
else
|
|
|
|
strcpy(configFile, DEFAULT_CONFIG_FILE);
|
|
|
|
#else
|
|
|
|
strcpy(configFile, DEFAULT_CONFIG_FILE);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return configFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::SeekableReadStream *OSystem_SDL::openConfigFileForReading() {
|
2008-10-02 16:58:59 +00:00
|
|
|
Common::FSNode file(getDefaultConfigFileName());
|
2008-08-22 11:45:29 +00:00
|
|
|
return file.openForReading();
|
2008-08-03 17:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::WriteStream *OSystem_SDL::openConfigFileForWriting() {
|
2008-10-02 16:58:59 +00:00
|
|
|
Common::FSNode file(getDefaultConfigFileName());
|
2008-08-22 11:45:29 +00:00
|
|
|
return file.openForWriting();
|
2008-08-03 17:05:01 +00:00
|
|
|
}
|
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
void OSystem_SDL::setWindowCaption(const char *caption) {
|
|
|
|
SDL_WM_SetCaption(caption, caption);
|
|
|
|
}
|
2002-09-29 18:19:57 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
bool OSystem_SDL::hasFeature(Feature f) {
|
|
|
|
return
|
|
|
|
(f == kFeatureFullscreenMode) ||
|
|
|
|
(f == kFeatureAspectRatioCorrection) ||
|
2005-02-17 23:01:00 +00:00
|
|
|
(f == kFeatureAutoComputeDirtyRects) ||
|
2006-10-02 04:46:50 +00:00
|
|
|
(f == kFeatureCursorHasPalette) ||
|
|
|
|
(f == kFeatureIconifyWindow);
|
2004-02-29 00:49:40 +00:00
|
|
|
}
|
2003-07-21 00:01:05 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
void OSystem_SDL::setFeatureState(Feature f, bool enable) {
|
|
|
|
switch (f) {
|
|
|
|
case kFeatureFullscreenMode:
|
|
|
|
setFullscreenMode(enable);
|
|
|
|
break;
|
|
|
|
case kFeatureAspectRatioCorrection:
|
2004-11-23 21:30:38 +00:00
|
|
|
setAspectRatioCorrection(enable);
|
2004-02-29 00:49:40 +00:00
|
|
|
break;
|
|
|
|
case kFeatureAutoComputeDirtyRects:
|
|
|
|
if (enable)
|
2005-07-30 21:11:48 +00:00
|
|
|
_modeFlags |= DF_WANT_RECT_OPTIM;
|
2004-02-29 00:49:40 +00:00
|
|
|
else
|
2005-07-30 21:11:48 +00:00
|
|
|
_modeFlags &= ~DF_WANT_RECT_OPTIM;
|
2004-02-29 00:49:40 +00:00
|
|
|
break;
|
2006-10-02 04:46:50 +00:00
|
|
|
case kFeatureIconifyWindow:
|
|
|
|
if (enable)
|
|
|
|
SDL_WM_IconifyWindow();
|
|
|
|
break;
|
2004-02-29 00:49:40 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-05-10 15:33:02 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
bool OSystem_SDL::getFeatureState(Feature f) {
|
2004-12-04 14:47:22 +00:00
|
|
|
assert (_transactionMode == kTransactionNone);
|
2004-11-23 21:30:38 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
switch (f) {
|
|
|
|
case kFeatureFullscreenMode:
|
2008-11-14 22:08:10 +00:00
|
|
|
return _videoMode.fullscreen;
|
2004-02-29 00:49:40 +00:00
|
|
|
case kFeatureAspectRatioCorrection:
|
2008-11-14 22:08:10 +00:00
|
|
|
return _videoMode.aspectRatio;
|
2004-02-29 00:49:40 +00:00
|
|
|
case kFeatureAutoComputeDirtyRects:
|
2004-12-01 21:16:55 +00:00
|
|
|
return _modeFlags & DF_WANT_RECT_OPTIM;
|
2004-02-29 00:49:40 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2002-09-29 18:19:57 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
void OSystem_SDL::quit() {
|
2004-12-01 21:16:55 +00:00
|
|
|
if (_cdrom) {
|
2004-02-29 00:49:40 +00:00
|
|
|
SDL_CDStop(_cdrom);
|
|
|
|
SDL_CDClose(_cdrom);
|
2002-09-29 18:19:57 +00:00
|
|
|
}
|
2004-12-01 21:16:55 +00:00
|
|
|
unloadGFXMode();
|
|
|
|
deleteMutex(_graphicsMutex);
|
2002-09-29 18:19:57 +00:00
|
|
|
|
2004-12-01 21:16:55 +00:00
|
|
|
if (_joystick)
|
|
|
|
SDL_JoystickClose(_joystick);
|
2004-02-29 00:49:40 +00:00
|
|
|
SDL_ShowCursor(SDL_ENABLE);
|
2008-03-26 19:29:33 +00:00
|
|
|
|
|
|
|
SDL_RemoveTimer(_timerID);
|
2008-07-15 17:13:06 +00:00
|
|
|
closeMixer();
|
2008-03-26 19:29:33 +00:00
|
|
|
|
|
|
|
free(_dirtyChecksums);
|
|
|
|
free(_currentPalette);
|
|
|
|
free(_cursorPalette);
|
|
|
|
free(_mouseData);
|
|
|
|
|
|
|
|
delete _savefile;
|
|
|
|
delete _timer;
|
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
SDL_Quit();
|
2002-04-15 17:45:52 +00:00
|
|
|
|
2007-09-19 13:55:05 +00:00
|
|
|
delete getEventManager();
|
2008-03-26 19:29:33 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
2002-04-15 17:45:52 +00:00
|
|
|
|
2004-12-01 21:16:55 +00:00
|
|
|
void OSystem_SDL::setupIcon() {
|
2008-08-27 18:21:03 +00:00
|
|
|
int x, y, w, h, ncols, nbytes, i;
|
|
|
|
unsigned int rgba[256];
|
|
|
|
unsigned int *icon;
|
2002-05-04 00:11:57 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
sscanf(scummvm_icon[0], "%d %d %d %d", &w, &h, &ncols, &nbytes);
|
2008-08-27 18:21:03 +00:00
|
|
|
if ((w > 512) || (h > 512) || (ncols > 255) || (nbytes > 1)) {
|
|
|
|
warning("Could not load the built-in icon (%d %d %d %d)", w, h, ncols, nbytes);
|
2004-02-29 00:49:40 +00:00
|
|
|
return;
|
2002-05-04 00:11:57 +00:00
|
|
|
}
|
2008-08-27 18:21:03 +00:00
|
|
|
icon = (unsigned int*)malloc(w*h*sizeof(unsigned int));
|
|
|
|
if (!icon) {
|
|
|
|
warning("Could not allocate temp storage for the built-in icon");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
for (i = 0; i < ncols; i++) {
|
|
|
|
unsigned char code;
|
|
|
|
char color[32];
|
|
|
|
unsigned int col;
|
|
|
|
sscanf(scummvm_icon[1 + i], "%c c %s", &code, color);
|
|
|
|
if (!strcmp(color, "None"))
|
|
|
|
col = 0x00000000;
|
|
|
|
else if (!strcmp(color, "black"))
|
|
|
|
col = 0xFF000000;
|
|
|
|
else if (color[0] == '#') {
|
|
|
|
sscanf(color + 1, "%06x", &col);
|
|
|
|
col |= 0xFF000000;
|
2003-05-28 21:57:22 +00:00
|
|
|
} else {
|
2008-08-27 18:21:03 +00:00
|
|
|
warning("Could not load the built-in icon (%d %s - %s) ", code, color, scummvm_icon[1 + i]);
|
|
|
|
free(icon);
|
2004-02-29 00:49:40 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
rgba[code] = col;
|
|
|
|
}
|
2008-08-27 18:21:03 +00:00
|
|
|
for (y = 0; y < h; y++) {
|
|
|
|
const char *line = scummvm_icon[1 + ncols + y];
|
|
|
|
for (x = 0; x < w; x++) {
|
|
|
|
icon[x + w * y] = rgba[(int)line[x]];
|
2004-02-29 00:49:40 +00:00
|
|
|
}
|
|
|
|
}
|
2003-03-06 18:30:44 +00:00
|
|
|
|
2008-08-27 18:21:03 +00:00
|
|
|
SDL_Surface *sdl_surf = SDL_CreateRGBSurfaceFrom(icon, w, h, 32, w * 4, 0xFF0000, 0x00FF00, 0x0000FF, 0xFF000000);
|
|
|
|
if (!sdl_surf) {
|
|
|
|
warning("SDL_CreateRGBSurfaceFrom(icon) failed");
|
|
|
|
}
|
|
|
|
SDL_WM_SetIcon(sdl_surf, NULL);
|
2004-02-29 00:49:40 +00:00
|
|
|
SDL_FreeSurface(sdl_surf);
|
2008-08-27 18:21:03 +00:00
|
|
|
free(icon);
|
2004-02-29 00:49:40 +00:00
|
|
|
}
|
2003-03-18 13:31:37 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
OSystem::MutexRef OSystem_SDL::createMutex(void) {
|
|
|
|
return (MutexRef) SDL_CreateMutex();
|
|
|
|
}
|
2003-03-18 13:31:37 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
void OSystem_SDL::lockMutex(MutexRef mutex) {
|
|
|
|
SDL_mutexP((SDL_mutex *) mutex);
|
|
|
|
}
|
2003-06-22 11:55:40 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
void OSystem_SDL::unlockMutex(MutexRef mutex) {
|
|
|
|
SDL_mutexV((SDL_mutex *) mutex);
|
|
|
|
}
|
2003-03-18 13:31:37 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
void OSystem_SDL::deleteMutex(MutexRef mutex) {
|
|
|
|
SDL_DestroyMutex((SDL_mutex *) mutex);
|
|
|
|
}
|
2003-03-18 13:31:37 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark --- Audio ---
|
|
|
|
#pragma mark -
|
2003-06-22 11:55:40 +00:00
|
|
|
|
2008-07-15 17:13:06 +00:00
|
|
|
#ifdef MIXER_DOUBLE_BUFFERING
|
|
|
|
|
|
|
|
void OSystem_SDL::mixerProducerThread() {
|
|
|
|
byte nextSoundBuffer;
|
|
|
|
|
|
|
|
SDL_LockMutex(_soundMutex);
|
|
|
|
while (true) {
|
|
|
|
// Wait till we are allowed to produce data
|
|
|
|
SDL_CondWait(_soundCond, _soundMutex);
|
|
|
|
|
|
|
|
if (_soundThreadShouldQuit)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Generate samples and put them into the next buffer
|
|
|
|
nextSoundBuffer = _activeSoundBuf ^ 1;
|
|
|
|
_mixer->mixCallback(_soundBuffers[nextSoundBuffer], _soundBufSize);
|
2008-09-03 15:22:19 +00:00
|
|
|
|
2008-07-15 17:13:06 +00:00
|
|
|
// Swap buffers
|
|
|
|
_activeSoundBuf = nextSoundBuffer;
|
|
|
|
}
|
|
|
|
SDL_UnlockMutex(_soundMutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SDLCALL OSystem_SDL::mixerProducerThreadEntry(void *arg) {
|
|
|
|
OSystem_SDL *this_ = (OSystem_SDL *)arg;
|
|
|
|
assert(this_);
|
|
|
|
this_->mixerProducerThread();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OSystem_SDL::initThreadedMixer(Audio::MixerImpl *mixer, uint bufSize) {
|
|
|
|
_soundThreadIsRunning = false;
|
|
|
|
_soundThreadShouldQuit = false;
|
|
|
|
|
|
|
|
// Create mutex and condition variable
|
|
|
|
_soundMutex = SDL_CreateMutex();
|
|
|
|
_soundCond = SDL_CreateCond();
|
|
|
|
|
|
|
|
// Create two sound buffers
|
|
|
|
_activeSoundBuf = 0;
|
|
|
|
_soundBufSize = bufSize;
|
|
|
|
_soundBuffers[0] = (byte *)calloc(1, bufSize);
|
|
|
|
_soundBuffers[1] = (byte *)calloc(1, bufSize);
|
|
|
|
|
|
|
|
_soundThreadIsRunning = true;
|
|
|
|
|
|
|
|
// Finally start the thread
|
|
|
|
_soundThread = SDL_CreateThread(mixerProducerThreadEntry, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_SDL::deinitThreadedMixer() {
|
|
|
|
// Kill thread?? _soundThread
|
|
|
|
|
|
|
|
if (_soundThreadIsRunning) {
|
|
|
|
// Signal the producer thread to end, and wait for it to actually finish.
|
|
|
|
_soundThreadShouldQuit = true;
|
|
|
|
SDL_CondBroadcast(_soundCond);
|
|
|
|
SDL_WaitThread(_soundThread, NULL);
|
|
|
|
|
2008-09-03 15:22:19 +00:00
|
|
|
// Kill the mutex & cond variables.
|
2008-07-15 17:13:06 +00:00
|
|
|
// Attention: AT this point, the mixer callback must not be running
|
|
|
|
// anymore, else we will crash!
|
|
|
|
SDL_DestroyMutex(_soundMutex);
|
|
|
|
SDL_DestroyCond(_soundCond);
|
|
|
|
|
|
|
|
_soundThreadIsRunning = false;
|
|
|
|
|
|
|
|
free(_soundBuffers[0]);
|
|
|
|
free(_soundBuffers[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OSystem_SDL::mixCallback(void *arg, byte *samples, int len) {
|
|
|
|
OSystem_SDL *this_ = (OSystem_SDL *)arg;
|
|
|
|
assert(this_);
|
|
|
|
assert(this_->_mixer);
|
|
|
|
|
|
|
|
assert((int)this_->_soundBufSize == len);
|
|
|
|
|
|
|
|
// Lock mutex, to ensure our data is not overwritten by the producer thread
|
|
|
|
SDL_LockMutex(this_->_soundMutex);
|
2008-09-03 15:22:19 +00:00
|
|
|
|
2008-07-15 17:13:06 +00:00
|
|
|
// Copy data from the current sound buffer
|
|
|
|
memcpy(samples, this_->_soundBuffers[this_->_activeSoundBuf], len);
|
2008-09-03 15:22:19 +00:00
|
|
|
|
2008-07-15 17:13:06 +00:00
|
|
|
// Unlock mutex and wake up the produced thread
|
|
|
|
SDL_UnlockMutex(this_->_soundMutex);
|
|
|
|
SDL_CondSignal(this_->_soundCond);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2008-06-28 15:28:29 +00:00
|
|
|
void OSystem_SDL::mixCallback(void *sys, byte *samples, int len) {
|
|
|
|
OSystem_SDL *this_ = (OSystem_SDL *)sys;
|
|
|
|
assert(this_);
|
2008-07-15 17:13:06 +00:00
|
|
|
assert(this_->_mixer);
|
2008-06-28 15:28:29 +00:00
|
|
|
|
2008-07-15 17:13:06 +00:00
|
|
|
this_->_mixer->mixCallback(samples, len);
|
2008-06-28 15:28:29 +00:00
|
|
|
}
|
|
|
|
|
2008-07-15 17:13:06 +00:00
|
|
|
#endif
|
|
|
|
|
2008-06-28 15:28:29 +00:00
|
|
|
void OSystem_SDL::setupMixer() {
|
2004-02-29 00:49:40 +00:00
|
|
|
SDL_AudioSpec desired;
|
2004-07-16 10:24:29 +00:00
|
|
|
SDL_AudioSpec obtained;
|
2003-06-22 11:55:40 +00:00
|
|
|
|
2007-08-11 08:44:43 +00:00
|
|
|
// Determine the desired output sampling frequency.
|
2005-06-07 14:43:12 +00:00
|
|
|
_samplesPerSec = 0;
|
2004-07-16 10:24:29 +00:00
|
|
|
if (ConfMan.hasKey("output_rate"))
|
|
|
|
_samplesPerSec = ConfMan.getInt("output_rate");
|
2005-06-07 14:43:12 +00:00
|
|
|
if (_samplesPerSec <= 0)
|
2004-07-16 10:24:29 +00:00
|
|
|
_samplesPerSec = SAMPLES_PER_SEC;
|
|
|
|
|
2007-08-11 08:44:43 +00:00
|
|
|
// Determine the sample buffer size. We want it to store enough data for
|
2008-06-22 12:39:40 +00:00
|
|
|
// about 1/16th of a second. Note that it must be a power of two.
|
2007-08-11 08:44:43 +00:00
|
|
|
// So e.g. at 22050 Hz, we request a sample buffer size of 2048.
|
2008-05-27 08:01:06 +00:00
|
|
|
int samples = 8192;
|
2008-06-04 17:20:25 +00:00
|
|
|
while (16 * samples >= _samplesPerSec) {
|
2004-07-16 10:24:29 +00:00
|
|
|
samples >>= 1;
|
|
|
|
}
|
|
|
|
|
2007-08-11 08:44:43 +00:00
|
|
|
memset(&desired, 0, sizeof(desired));
|
2004-07-16 10:24:29 +00:00
|
|
|
desired.freq = _samplesPerSec;
|
2004-02-29 00:49:40 +00:00
|
|
|
desired.format = AUDIO_S16SYS;
|
|
|
|
desired.channels = 2;
|
2005-06-07 14:43:12 +00:00
|
|
|
desired.samples = (uint16)samples;
|
2008-06-28 15:28:29 +00:00
|
|
|
desired.callback = mixCallback;
|
|
|
|
desired.userdata = this;
|
|
|
|
|
|
|
|
// Create the mixer instance
|
|
|
|
assert(!_mixer);
|
|
|
|
_mixer = new Audio::MixerImpl(this);
|
|
|
|
assert(_mixer);
|
|
|
|
|
2004-07-16 10:24:29 +00:00
|
|
|
if (SDL_OpenAudio(&desired, &obtained) != 0) {
|
2005-06-07 14:43:12 +00:00
|
|
|
warning("Could not open audio device: %s", SDL_GetError());
|
2008-06-28 15:28:29 +00:00
|
|
|
_samplesPerSec = 0;
|
|
|
|
_mixer->setReady(false);
|
|
|
|
} else {
|
|
|
|
// Note: This should be the obtained output rate, but it seems that at
|
|
|
|
// least on some platforms SDL will lie and claim it did get the rate
|
|
|
|
// even if it didn't. Probably only happens for "weird" rates, though.
|
|
|
|
_samplesPerSec = obtained.freq;
|
|
|
|
debug(1, "Output sample rate: %d Hz", _samplesPerSec);
|
2008-09-03 15:22:19 +00:00
|
|
|
|
2008-06-28 15:28:29 +00:00
|
|
|
// Tell the mixer that we are ready and start the sound processing
|
|
|
|
_mixer->setOutputRate(_samplesPerSec);
|
|
|
|
_mixer->setReady(true);
|
2008-07-15 17:13:06 +00:00
|
|
|
|
|
|
|
#ifdef MIXER_DOUBLE_BUFFERING
|
|
|
|
initThreadedMixer(_mixer, obtained.samples * 4);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// start the sound system
|
2008-06-28 15:28:29 +00:00
|
|
|
SDL_PauseAudio(0);
|
2004-02-29 00:49:40 +00:00
|
|
|
}
|
|
|
|
}
|
2002-09-29 18:19:57 +00:00
|
|
|
|
2008-07-15 17:13:06 +00:00
|
|
|
void OSystem_SDL::closeMixer() {
|
|
|
|
if (_mixer)
|
|
|
|
_mixer->setReady(false);
|
|
|
|
|
|
|
|
SDL_CloseAudio();
|
|
|
|
|
2008-07-18 09:36:49 +00:00
|
|
|
delete _mixer;
|
|
|
|
_mixer = 0;
|
|
|
|
|
2008-07-15 17:13:06 +00:00
|
|
|
#ifdef MIXER_DOUBLE_BUFFERING
|
|
|
|
deinitThreadedMixer();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-10-22 15:42:29 +00:00
|
|
|
Audio::Mixer *OSystem_SDL::getMixer() {
|
|
|
|
assert(_mixer);
|
|
|
|
return _mixer;
|
|
|
|
}
|
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark --- CD Audio ---
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
bool OSystem_SDL::openCD(int drive) {
|
|
|
|
if (SDL_InitSubSystem(SDL_INIT_CDROM) == -1)
|
|
|
|
_cdrom = NULL;
|
|
|
|
else {
|
|
|
|
_cdrom = SDL_CDOpen(drive);
|
|
|
|
// Did it open? Check if _cdrom is NULL
|
|
|
|
if (!_cdrom) {
|
|
|
|
warning("Couldn't open drive: %s", SDL_GetError());
|
|
|
|
} else {
|
2004-12-01 21:16:55 +00:00
|
|
|
_cdNumLoops = 0;
|
|
|
|
_cdStopTime = 0;
|
|
|
|
_cdEndTime = 0;
|
2004-02-29 00:49:40 +00:00
|
|
|
}
|
2002-05-10 15:33:02 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
return (_cdrom != NULL);
|
|
|
|
}
|
2002-05-09 18:23:33 +00:00
|
|
|
|
2004-09-28 20:19:37 +00:00
|
|
|
void OSystem_SDL::stopCD() { /* Stop CD Audio in 1/10th of a second */
|
2004-12-01 21:16:55 +00:00
|
|
|
_cdStopTime = SDL_GetTicks() + 100;
|
|
|
|
_cdNumLoops = 0;
|
2002-03-17 13:00:11 +00:00
|
|
|
}
|
2001-11-11 16:54:45 +00:00
|
|
|
|
2004-09-28 20:19:37 +00:00
|
|
|
void OSystem_SDL::playCD(int track, int num_loops, int start_frame, int duration) {
|
2004-02-29 00:49:40 +00:00
|
|
|
if (!num_loops && !start_frame)
|
|
|
|
return;
|
2003-08-22 07:40:40 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
if (!_cdrom)
|
|
|
|
return;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-02-29 00:49:40 +00:00
|
|
|
if (duration > 0)
|
|
|
|
duration += 5;
|
|
|
|
|
2004-12-01 21:16:55 +00:00
|
|
|
_cdTrack = track;
|
|
|
|
_cdNumLoops = num_loops;
|
|
|
|
_cdStartFrame = start_frame;
|
2004-02-29 00:49:40 +00:00
|
|
|
|
|
|
|
SDL_CDStatus(_cdrom);
|
|
|
|
if (start_frame == 0 && duration == 0)
|
|
|
|
SDL_CDPlayTracks(_cdrom, track, 0, 1, 0);
|
|
|
|
else
|
|
|
|
SDL_CDPlayTracks(_cdrom, track, start_frame, 0, duration);
|
2004-12-01 21:16:55 +00:00
|
|
|
_cdDuration = duration;
|
|
|
|
_cdStopTime = 0;
|
|
|
|
_cdEndTime = SDL_GetTicks() + _cdrom->track[track].length * 1000 / CD_FPS;
|
2003-08-22 07:40:40 +00:00
|
|
|
}
|
2004-02-25 09:53:36 +00:00
|
|
|
|
2004-09-28 20:19:37 +00:00
|
|
|
bool OSystem_SDL::pollCD() {
|
2004-02-29 00:49:40 +00:00
|
|
|
if (!_cdrom)
|
|
|
|
return false;
|
2004-02-28 13:00:19 +00:00
|
|
|
|
2004-12-01 21:16:55 +00:00
|
|
|
return (_cdNumLoops != 0 && (SDL_GetTicks() < _cdEndTime || SDL_CDStatus(_cdrom) != CD_STOPPED));
|
2004-02-29 00:49:40 +00:00
|
|
|
}
|
|
|
|
|
2004-09-28 20:19:37 +00:00
|
|
|
void OSystem_SDL::updateCD() {
|
2004-02-29 00:49:40 +00:00
|
|
|
if (!_cdrom)
|
|
|
|
return;
|
|
|
|
|
2004-12-01 21:16:55 +00:00
|
|
|
if (_cdStopTime != 0 && SDL_GetTicks() >= _cdStopTime) {
|
2004-02-29 00:49:40 +00:00
|
|
|
SDL_CDStop(_cdrom);
|
2004-12-01 21:16:55 +00:00
|
|
|
_cdNumLoops = 0;
|
|
|
|
_cdStopTime = 0;
|
2004-02-29 00:49:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-12-01 21:16:55 +00:00
|
|
|
if (_cdNumLoops == 0 || SDL_GetTicks() < _cdEndTime)
|
2004-02-29 00:49:40 +00:00
|
|
|
return;
|
|
|
|
|
2004-12-01 21:16:55 +00:00
|
|
|
if (_cdNumLoops != 1 && SDL_CDStatus(_cdrom) != CD_STOPPED) {
|
2004-02-29 00:49:40 +00:00
|
|
|
// Wait another second for it to be done
|
2004-12-01 21:16:55 +00:00
|
|
|
_cdEndTime += 1000;
|
2004-02-29 00:49:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-12-01 21:16:55 +00:00
|
|
|
if (_cdNumLoops > 0)
|
|
|
|
_cdNumLoops--;
|
2004-02-29 00:49:40 +00:00
|
|
|
|
2004-12-01 21:16:55 +00:00
|
|
|
if (_cdNumLoops != 0) {
|
|
|
|
if (_cdStartFrame == 0 && _cdDuration == 0)
|
|
|
|
SDL_CDPlayTracks(_cdrom, _cdTrack, 0, 1, 0);
|
2004-02-29 00:49:40 +00:00
|
|
|
else
|
2004-12-01 21:16:55 +00:00
|
|
|
SDL_CDPlayTracks(_cdrom, _cdTrack, _cdStartFrame, 0, _cdDuration);
|
|
|
|
_cdEndTime = SDL_GetTicks() + _cdrom->track[_cdTrack].length * 1000 / CD_FPS;
|
2004-02-25 09:53:36 +00:00
|
|
|
}
|
|
|
|
}
|