diff options
Diffstat (limited to 'backends')
-rw-r--r-- | backends/events/openpandora/op-events.cpp (renamed from backends/platform/openpandora/op-events.cpp) | 146 | ||||
-rw-r--r-- | backends/events/openpandora/op-events.h | 46 | ||||
-rw-r--r-- | backends/graphics/openpandora/op-graphics.cpp (renamed from backends/platform/openpandora/op-graphics.cpp) | 22 | ||||
-rw-r--r-- | backends/graphics/openpandora/op-graphics.h | 62 | ||||
-rw-r--r-- | backends/module.mk | 2 | ||||
-rwxr-xr-x | backends/platform/openpandora/module.mk | 3 | ||||
-rw-r--r-- | backends/platform/openpandora/op-backend.cpp | 273 | ||||
-rw-r--r-- | backends/platform/openpandora/op-main.cpp | 234 | ||||
-rw-r--r-- | backends/platform/openpandora/op-sdl.h | 22 |
9 files changed, 495 insertions, 315 deletions
diff --git a/backends/platform/openpandora/op-events.cpp b/backends/events/openpandora/op-events.cpp index 24283aa8ba..381cbf89e9 100644 --- a/backends/platform/openpandora/op-events.cpp +++ b/backends/events/openpandora/op-events.cpp @@ -18,16 +18,19 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * $URL$ - * $Id$ - * */ +#include "common/scummsys.h" + /* * OpenPandora: Device Specific Event Handling. * */ +#if defined(OPENPANDORA) + +#include "backends/events/openpandora/op-events.h" +#include "backends/graphics/openpandora/op-graphics.h" #include "backends/platform/openpandora/op-sdl.h" #include "backends/platform/openpandora/op-options.h" @@ -41,81 +44,87 @@ enum { TAPMODE_HOVER = 2 }; +OPEventSource::OPEventSource() + : _buttonStateL(false){ +} + /* On the OpenPandora by default the ABXY and L/R Trigger buttons are returned by SDL as (A): SDLK_HOME (B): SDLK_END (X): SDLK_PAGEDOWN (Y): SDLK_PAGEUP (L): SDLK_RSHIFT (R): SDLK_RCTRL */ -bool OSystem_OP::handleKeyDown(SDL_Event &ev, Common::Event &event) { - switch (ev.key.keysym.sym) { - case SDLK_HOME: - event.type = Common::EVENT_LBUTTONDOWN; - fillMouseEvent(event, _km.x, _km.y); - return true; - break; - case SDLK_END: - event.type = Common::EVENT_RBUTTONDOWN; - fillMouseEvent(event, _km.x, _km.y); - return true; - break; - case SDLK_PAGEDOWN: - event.type = Common::EVENT_MAINMENU; - return true; - break; - case SDLK_PAGEUP: - OP::ToggleTapMode(); - if (OP::tapmodeLevel == TAPMODE_LEFT) { - displayMessageOnOSD("Touchscreen 'Tap Mode' - Left Click"); - } else if (OP::tapmodeLevel == TAPMODE_RIGHT) { - displayMessageOnOSD("Touchscreen 'Tap Mode' - Right Click"); - } else if (OP::tapmodeLevel == TAPMODE_HOVER) { - displayMessageOnOSD("Touchscreen 'Tap Mode' - Hover (No Click)"); - } - break; - case SDLK_RSHIFT: - BUTTON_STATE_L = true; - break; - case SDLK_RCTRL: - break; - default: - return OSystem_SDL::handleKeyDown(ev, event); - break; - } - return false; -} +bool OPEventSource::remapKey(SDL_Event &ev, Common::Event &event) { -bool OSystem_OP::handleKeyUp(SDL_Event &ev, Common::Event &event) { - switch (ev.key.keysym.sym) { - case SDLK_HOME: - event.type = Common::EVENT_LBUTTONUP; - fillMouseEvent(event, _km.x, _km.y); - return true; - break; - case SDLK_END: - event.type = Common::EVENT_RBUTTONUP; - fillMouseEvent(event, _km.x, _km.y); - return true; - break; - case SDLK_PAGEDOWN: - event.type = Common::EVENT_MAINMENU; - return true; - break; - case SDLK_PAGEUP: - break; - case SDLK_RSHIFT: - BUTTON_STATE_L = false; - break; - case SDLK_RCTRL: - break; - default: - return OSystem_SDL::handleKeyUp(ev, event); - break; + if (ev.type == SDL_KEYDOWN) { + switch (ev.key.keysym.sym) { + case SDLK_HOME: + event.type = Common::EVENT_LBUTTONDOWN; + fillMouseEvent(event, _km.x, _km.y); + return true; + break; + case SDLK_END: + event.type = Common::EVENT_RBUTTONDOWN; + fillMouseEvent(event, _km.x, _km.y); + return true; + break; + case SDLK_PAGEDOWN: + event.type = Common::EVENT_MAINMENU; + return true; + break; + case SDLK_PAGEUP: + OP::ToggleTapMode(); + if (OP::tapmodeLevel == TAPMODE_LEFT) { + g_system->displayMessageOnOSD("Touchscreen 'Tap Mode' - Left Click"); + } else if (OP::tapmodeLevel == TAPMODE_RIGHT) { + g_system->displayMessageOnOSD("Touchscreen 'Tap Mode' - Right Click"); + } else if (OP::tapmodeLevel == TAPMODE_HOVER) { + g_system->displayMessageOnOSD("Touchscreen 'Tap Mode' - Hover (No Click)"); + } + break; + case SDLK_RSHIFT: + BUTTON_STATE_L = true; + break; + case SDLK_RCTRL: + break; + default: + return false; + break; + } + return false; + } else { + switch (ev.key.keysym.sym) { + case SDLK_HOME: + event.type = Common::EVENT_LBUTTONUP; + fillMouseEvent(event, _km.x, _km.y); + return true; + break; + case SDLK_END: + event.type = Common::EVENT_RBUTTONUP; + fillMouseEvent(event, _km.x, _km.y); + return true; + break; + case SDLK_PAGEDOWN: + event.type = Common::EVENT_MAINMENU; + return true; + break; + case SDLK_PAGEUP: + break; + case SDLK_RSHIFT: + BUTTON_STATE_L = false; + break; + case SDLK_RCTRL: + break; + default: + return false; + break; + } + return false; } return false; } /* Custom handleMouseButtonDown/handleMouseButtonUp to deal with 'Tap Mode' for the touchscreen */ -bool OSystem_OP::handleMouseButtonDown(SDL_Event &ev, Common::Event &event) { +bool OPEventSource::handleMouseButtonDown(SDL_Event &ev, Common::Event &event) { if (ev.button.button == SDL_BUTTON_LEFT){ if (BUTTON_STATE_L == true) /* BUTTON_STATE_L = Left Trigger Held, force Right Click */ event.type = Common::EVENT_RBUTTONDOWN; @@ -148,7 +157,7 @@ bool OSystem_OP::handleMouseButtonDown(SDL_Event &ev, Common::Event &event) { return true; } -bool OSystem_OP::handleMouseButtonUp(SDL_Event &ev, Common::Event &event) { +bool OPEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &event) { if (ev.button.button == SDL_BUTTON_LEFT){ if (BUTTON_STATE_L == true) /* BUTTON_STATE_L = Left Trigger Held, force Right Click */ event.type = Common::EVENT_RBUTTONUP; @@ -174,3 +183,4 @@ bool OSystem_OP::handleMouseButtonUp(SDL_Event &ev, Common::Event &event) { return true; } +#endif diff --git a/backends/events/openpandora/op-events.h b/backends/events/openpandora/op-events.h new file mode 100644 index 0000000000..4b13ef2105 --- /dev/null +++ b/backends/events/openpandora/op-events.h @@ -0,0 +1,46 @@ +/* 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. + * + * 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 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#if !defined(BACKEND_EVENTS_OP_H) && !defined(DISABLE_DEFAULT_EVENTMANAGER) +#define BACKEND_EVENTS_OP_H + +#include "backends/events/sdl/sdl-events.h" + +/** + * Events manager for the OpenPandora. + */ +class OPEventSource : public SdlEventSource { +public: + OPEventSource(); + +protected: + /** Button state for L button modifier */ + bool _buttonStateL; + + bool remapKey(SDL_Event &ev, Common::Event &event); + +//private: + bool handleMouseButtonDown(SDL_Event &ev, Common::Event &event); + bool handleMouseButtonUp(SDL_Event &ev, Common::Event &event); +}; + +#endif /* BACKEND_EVENTS_OP_H */ diff --git a/backends/platform/openpandora/op-graphics.cpp b/backends/graphics/openpandora/op-graphics.cpp index ef95f52e99..ab6974ba5f 100644 --- a/backends/platform/openpandora/op-graphics.cpp +++ b/backends/graphics/openpandora/op-graphics.cpp @@ -18,11 +18,14 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * $URL$ - * $Id$ - * */ +#include "common/scummsys.h" + +#if defined(OPENPANDORA) + +#include "backends/graphics/openpandora/op-graphics.h" +#include "backends/events/openpandora/op-events.h" #include "backends/platform/openpandora/op-sdl.h" #include "common/mutex.h" #include "common/translation.h" @@ -31,7 +34,11 @@ #include "graphics/scaler/aspect.h" #include "graphics/surface.h" -bool OSystem_OP::loadGFXMode() { +OPGraphicsManager::OPGraphicsManager(SdlEventSource *boss) + : SdlGraphicsManager(boss) { +} + +bool OPGraphicsManager::loadGFXMode() { /* FIXME: For now we just cheat and set the overlay to 640*480 not 800*480 and let SDL deal with the boarders (it saves cleaning up the overlay when the game screen is smaller than the overlay ;) @@ -43,8 +50,7 @@ bool OSystem_OP::loadGFXMode() { if (_videoMode.screenHeight != 200 && _videoMode.screenHeight != 400) _videoMode.aspectRatioCorrection = false; - OSystem_SDL::loadGFXMode(); - - return true; - + return SdlGraphicsManager::loadGFXMode(); } + +#endif diff --git a/backends/graphics/openpandora/op-graphics.h b/backends/graphics/openpandora/op-graphics.h new file mode 100644 index 0000000000..b0d4298620 --- /dev/null +++ b/backends/graphics/openpandora/op-graphics.h @@ -0,0 +1,62 @@ +/* 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. + * + * 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 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef BACKENDS_GRAPHICS_OP_H +#define BACKENDS_GRAPHICS_OP_H + +#include "backends/graphics/sdl/sdl-graphics.h" +#include "graphics/scaler/aspect.h" // for aspect2Real +#include "graphics/scaler/downscaler.h" + +enum { + GFX_HALF = 12 +}; + +class OPGraphicsManager : public SdlGraphicsManager { +public: + OPGraphicsManager(SdlEventSource *boss); + + bool hasFeature(OSystem::Feature f); + void setFeatureState(OSystem::Feature f, bool enable); + bool getFeatureState(OSystem::Feature f); + int getDefaultGraphicsMode() const; + + void initSize(uint w, uint h); + const OSystem::GraphicsMode *getSupportedGraphicsModes() const; + bool setGraphicsMode(const char *name); + bool setGraphicsMode(int mode); + void setGraphicsModeIntern(); + void internUpdateScreen(); + void showOverlay(); + void hideOverlay(); + bool loadGFXMode(); + void drawMouse(); + void undrawMouse(); + virtual void warpMouse(int x, int y); + + SdlGraphicsManager::MousePos *getMouseCurState(); + SdlGraphicsManager::VideoState *getVideoMode(); + + virtual void adjustMouseEvent(const Common::Event &event); +}; + +#endif /* BACKENDS_GRAPHICS_OP_H */ diff --git a/backends/module.mk b/backends/module.mk index c8e03421b7..c562aea4b4 100644 --- a/backends/module.mk +++ b/backends/module.mk @@ -10,6 +10,7 @@ MODULE_OBJS := \ events/gp2xsdl/gp2xsdl-events.o \ events/gph/gph-events.o \ events/linuxmotosdl/linuxmotosdl-events.o \ + events/openpandora/op-events.o \ events/samsungtvsdl/samsungtvsdl-events.o \ events/sdl/sdl-events.o \ events/symbiansdl/symbiansdl-events.o \ @@ -28,6 +29,7 @@ MODULE_OBJS := \ graphics/opengl/gltexture.o \ graphics/opengl/opengl-graphics.o \ graphics/openglsdl/openglsdl-graphics.o \ + graphics/openpandora/op-graphics.o \ graphics/sdl/sdl-graphics.o \ graphics/symbiansdl/symbiansdl-graphics.o \ graphics/wincesdl/wincesdl-graphics.o \ diff --git a/backends/platform/openpandora/module.mk b/backends/platform/openpandora/module.mk index 1e5f6bcd69..8e60b87aa6 100755 --- a/backends/platform/openpandora/module.mk +++ b/backends/platform/openpandora/module.mk @@ -1,9 +1,8 @@ MODULE := backends/platform/openpandora MODULE_OBJS := \ - op-graphics.o \ - op-events.o \ op-options.o \ + op-backend.o \ op-main.o MODULE_DIRS += \ diff --git a/backends/platform/openpandora/op-backend.cpp b/backends/platform/openpandora/op-backend.cpp new file mode 100644 index 0000000000..5b333929c9 --- /dev/null +++ b/backends/platform/openpandora/op-backend.cpp @@ -0,0 +1,273 @@ +/* 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. + * + * 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 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +// Disable symbol overrides so that we can use system headers. +#define FORBIDDEN_SYMBOL_ALLOW_ALL + +#include "backends/platform/openpandora/op-sdl.h" +#include "base/main.h" + +#include "backends/saves/default/default-saves.h" + +#include "common/archive.h" +#include "common/config-manager.h" +#include "common/debug.h" +#include "common/events.h" +#include "common/util.h" + +#include "common/file.h" +#include "base/main.h" + +#include "backends/saves/default/default-saves.h" + +#include "backends/timer/default/default-timer.h" +#include "audio/mixer_intern.h" + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <limits.h> +#include <errno.h> +#include <sys/stat.h> +#include <time.h> // for getTimeAndDate() + +/* Dump console info to files. */ +#define DUMP_STDOUT + +static SDL_Cursor *hiddenCursor; + +static Uint32 timer_handler(Uint32 interval, void *param) { + ((DefaultTimerManager *)param)->handler(); + return interval; +} + +void OSystem_OP::initBackend() { + + assert(!_inited); + +// int joystick_num = ConfMan.getInt("joystick_num"); +// uint32 sdlFlags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER; +// +// if (ConfMan.hasKey("disable_sdl_parachute")) +// sdlFlags |= SDL_INIT_NOPARACHUTE; +// +// if (joystick_num > -1) +// sdlFlags |= SDL_INIT_JOYSTICK; +// +// if (SDL_Init(sdlFlags) == -1) { +// error("Could not initialize SDL: %s", SDL_GetError()); +// } +// + + /* Setup default save path to be workingdir/saves */ + + char savePath[PATH_MAX+1]; + char workDirName[PATH_MAX+1]; + + if (getcwd(workDirName, PATH_MAX) == NULL) { + error("Could not obtain current working directory."); + } else { + printf("Current working directory: %s\n", workDirName); + } + + strcpy(savePath, workDirName); + strcat(savePath, "/../saves"); + printf("Current save directory: %s\n", savePath); + struct stat sb; + if (stat(savePath, &sb) == -1) + if (errno == ENOENT) // Create the dir if it does not exist + if (mkdir(savePath, 0755) != 0) + warning("mkdir for '%s' failed!", savePath); + +// _savefileManager = new DefaultSaveFileManager(savePath); + + #ifdef DUMP_STDOUT + // The OpenPandora has a serial console on the EXT connection but most users do not use this so we + // output all our STDOUT and STDERR to files for debug purposes. + char STDOUT_FILE[PATH_MAX+1]; + char STDERR_FILE[PATH_MAX+1]; + + strcpy(STDOUT_FILE, workDirName); + strcpy(STDERR_FILE, workDirName); + strcat(STDOUT_FILE, "/scummvm.stdout.txt"); + strcat(STDERR_FILE, "/scummvm.stderr.txt"); + + // Flush the output in case anything is queued + fclose(stdout); + fclose(stderr); + + // Redirect standard input and standard output + FILE *newfp = freopen(STDOUT_FILE, "w", stdout); + if (newfp == NULL) { + #if !defined(stdout) + stdout = fopen(STDOUT_FILE, "w"); + #else + newfp = fopen(STDOUT_FILE, "w"); + if (newfp) { + *stdout = *newfp; + } + #endif + } + + newfp = freopen(STDERR_FILE, "w", stderr); + if (newfp == NULL) { + #if !defined(stderr) + stderr = fopen(STDERR_FILE, "w"); + #else + newfp = fopen(STDERR_FILE, "w"); + if (newfp) { + *stderr = *newfp; + } + #endif + } + + setbuf(stderr, NULL); + printf("%s\n", "Debug: STDOUT and STDERR redirected to text files."); + #endif /* DUMP_STDOUT */ + + /* Trigger autosave every 4 minutes. */ + ConfMan.registerDefault("autosave_period", 4 * 60); + + ConfMan.registerDefault("fullscreen", true); + + /* Make sure that aspect ratio correction is enabled on the 1st run to stop + users asking me what the 'wasted space' at the bottom is ;-). */ + ConfMan.registerDefault("aspect_ratio", true); + + /* Make sure SDL knows that we have a joystick we want to use. */ + ConfMan.setInt("joystick_num", 0); + + // Create the events manager + if (_eventSource == 0) + _eventSource = new OPEventSource(); + + // Create the graphics manager + if (_graphicsManager == 0) + _graphicsManager = new OPGraphicsManager(_eventSource); + +// _graphicsMutex = createMutex(); + + // Invoke parent implementation of this method + OSystem_POSIX::initBackend(); + + _inited = true; +} + + + + // enable joystick +// if (joystick_num > -1 && SDL_NumJoysticks() > 0) { +// printf("Using joystick: %s\n", SDL_JoystickName(0)); +// _joystick = SDL_JoystickOpen(joystick_num); +// } +// +// setupMixer(); + + // Note: We could implement a custom SDLTimerManager by using + // 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. + // 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. +// _timer = new DefaultTimerManager(); +// _timerID = SDL_AddTimer(10, &timer_handler, _timer); + +void OSystem_OP::initSDL() { + // Check if SDL has not been initialized + if (!_initedSDL) { + + uint32 sdlFlags = SDL_INIT_EVENTTHREAD; + if (ConfMan.hasKey("disable_sdl_parachute")) + sdlFlags |= SDL_INIT_NOPARACHUTE; + + // Initialize SDL (SDL Subsystems are initiliazed in the corresponding sdl managers) + if (SDL_Init(sdlFlags) == -1) + error("Could not initialize SDL: %s", SDL_GetError()); + + uint8_t hiddenCursorData = 0; + + hiddenCursor = SDL_CreateCursor(&hiddenCursorData, &hiddenCursorData, 8, 1, 0, 0); + + /* On the OpenPandora we need to work around an SDL assumption that + returns relative mouse coordinates when you get to the screen + edges using the touchscreen. The workaround is to set a blank + SDL cursor and not disable it (Hackish I know). + + The root issues likes in the Windows Manager GRAB code in SDL. + That is why the issue is not seen on framebuffer devices like the + GP2X (there is no X window manager ;)). + */ + SDL_ShowCursor(SDL_ENABLE); + SDL_SetCursor(hiddenCursor); + SDL_EnableUNICODE(1); + +// memset(&_oldVideoMode, 0, sizeof(_oldVideoMode)); +// memset(&_videoMode, 0, sizeof(_videoMode)); +// memset(&_transactionDetails, 0, sizeof(_transactionDetails)); + +// _videoMode.mode = GFX_DOUBLESIZE; +// _videoMode.scaleFactor = 2; +// _videoMode.aspectRatioCorrection = ConfMan.getBool("aspect_ratio"); +// _scalerProc = Normal2x; +// _scalerType = 0; + +// _videoMode.fullscreen = true; + + _initedSDL = true; + } +} + +void OSystem_OP::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) { + + /* Setup default extra data paths for engine data files and plugins */ + + char workDirName[PATH_MAX+1]; + + if (getcwd(workDirName, PATH_MAX) == NULL) { + error("Error: Could not obtain current working directory."); + } + + char enginedataPath[PATH_MAX+1]; + + strcpy(enginedataPath, workDirName); + strcat(enginedataPath, "/../data"); + printf("Default engine data directory: %s\n", enginedataPath); + + Common::FSNode engineNode(enginedataPath); + if (engineNode.exists() && engineNode.isDirectory()) { + s.add("__OP_ENGDATA__", new Common::FSDirectory(enginedataPath), priority); + } +} + +void OSystem_OP::quit() { + + SDL_FreeCursor(hiddenCursor); + + #ifdef DUMP_STDOUT + printf("%s\n", "Debug: STDOUT and STDERR text files closed."); + fclose(stdout); + fclose(stderr); + #endif /* DUMP_STDOUT */ + + OSystem_POSIX::quit(); +} diff --git a/backends/platform/openpandora/op-main.cpp b/backends/platform/openpandora/op-main.cpp index 6e64baddc7..ab777fec8f 100644 --- a/backends/platform/openpandora/op-main.cpp +++ b/backends/platform/openpandora/op-main.cpp @@ -18,250 +18,36 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * $URL$ - * $Id$ - * */ -// Disable symbol overrides so that we can use system headers. -#define FORBIDDEN_SYMBOL_ALLOW_ALL #include "backends/platform/sdl/sdl-sys.h" - #include "backends/platform/openpandora/op-sdl.h" #include "backends/plugins/posix/posix-provider.h" #include "base/main.h" -#include "common/archive.h" -#include "common/config-manager.h" -#include "common/debug.h" -#include "common/events.h" -#include "common/util.h" - -#include "common/file.h" -#include "base/main.h" - -#include "backends/saves/default/default-saves.h" - -#include "backends/timer/default/default-timer.h" -#include "audio/mixer_intern.h" - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <limits.h> -#include <errno.h> -#include <sys/stat.h> -#include <time.h> // for getTimeAndDate() - -/* Dump console info to files. */ -#define DUMP_STDOUT - -static SDL_Cursor *hiddenCursor; +#if defined(OPENPANDORA) int main(int argc, char *argv[]) { + + // Create our OSystem instance g_system = new OSystem_OP(); assert(g_system); + // Pre initialize the backend + //((OSystem_OP *)g_system)->init(); + #ifdef DYNAMIC_MODULES PluginManager::instance().addPluginProvider(new POSIXPluginProvider()); #endif // Invoke the actual ScummVM main entry point: int res = scummvm_main(argc, argv); - g_system->quit(); - - return res; -} - -static Uint32 timer_handler(Uint32 interval, void *param) { - ((DefaultTimerManager *)param)->handler(); - return interval; -} - -void OSystem_OP::initBackend() { - - assert(!_inited); - - uint8_t hiddenCursorData = 0; - - int joystick_num = ConfMan.getInt("joystick_num"); - uint32 sdlFlags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER; - - if (ConfMan.hasKey("disable_sdl_parachute")) - sdlFlags |= SDL_INIT_NOPARACHUTE; - - if (joystick_num > -1) - sdlFlags |= SDL_INIT_JOYSTICK; - - if (SDL_Init(sdlFlags) == -1) { - error("Could not initialize SDL: %s", SDL_GetError()); - } - - hiddenCursor = SDL_CreateCursor(&hiddenCursorData, &hiddenCursorData, 8, 1, 0, 0); - - /* Setup default save path to be workingdir/saves */ - - char savePath[PATH_MAX+1]; - char workDirName[PATH_MAX+1]; - - if (getcwd(workDirName, PATH_MAX) == NULL) { - error("Could not obtain current working directory."); - } else { - printf("Current working directory: %s\n", workDirName); - } - - strcpy(savePath, workDirName); - strcat(savePath, "/../saves"); - printf("Current save directory: %s\n", savePath); - struct stat sb; - if (stat(savePath, &sb) == -1) - if (errno == ENOENT) // Create the dir if it does not exist - if (mkdir(savePath, 0755) != 0) - warning("mkdir for '%s' failed!", savePath); - - _savefile = new DefaultSaveFileManager(savePath); - - #ifdef DUMP_STDOUT - // The OpenPandora has a serial console on the EXT connection but most users do not use this so we - // output all our STDOUT and STDERR to files for debug purposes. - char STDOUT_FILE[PATH_MAX+1]; - char STDERR_FILE[PATH_MAX+1]; - - strcpy(STDOUT_FILE, workDirName); - strcpy(STDERR_FILE, workDirName); - strcat(STDOUT_FILE, "/scummvm.stdout.txt"); - strcat(STDERR_FILE, "/scummvm.stderr.txt"); - - // Flush the output in case anything is queued - fclose(stdout); - fclose(stderr); - // Redirect standard input and standard output - FILE *newfp = freopen(STDOUT_FILE, "w", stdout); - if (newfp == NULL) { - #if !defined(stdout) - stdout = fopen(STDOUT_FILE, "w"); - #else - newfp = fopen(STDOUT_FILE, "w"); - if (newfp) { - *stdout = *newfp; - } - #endif - } + // Free OSystem + delete (OSystem_OP *)g_system; - newfp = freopen(STDERR_FILE, "w", stderr); - if (newfp == NULL) { - #if !defined(stderr) - stderr = fopen(STDERR_FILE, "w"); - #else - newfp = fopen(STDERR_FILE, "w"); - if (newfp) { - *stderr = *newfp; - } - #endif - } - - setbuf(stderr, NULL); - printf("%s\n", "Debug: STDOUT and STDERR redirected to text files."); - #endif /* DUMP_STDOUT */ - - /* Trigger autosave every 4 minutes. */ - ConfMan.registerDefault("autosave_period", 4 * 60); - - ConfMan.registerDefault("fullscreen", true); - - /* Make sure that aspect ratio correction is enabled on the 1st run to stop - users asking me what the 'wasted space' at the bottom is ;-). */ - ConfMan.registerDefault("aspect_ratio", true); - - /* Make sure SDL knows that we have a joystick we want to use. */ - ConfMan.setInt("joystick_num", 0); - - _graphicsMutex = createMutex(); - - /* On the OpenPandora we need to work around an SDL assumption that - returns relative mouse coordinates when you get to the screen - edges using the touchscreen. The workaround is to set a blank - SDL cursor and not disable it (Hackish I know). - - The root issues likes in the Windows Manager GRAB code in SDL. - That is why the issue is not seen on framebuffer devices like the - GP2X (there is no X window manager ;)). - */ - SDL_ShowCursor(SDL_ENABLE); - SDL_SetCursor(hiddenCursor); - - // Enable unicode support if possible - SDL_EnableUNICODE(1); - - memset(&_oldVideoMode, 0, sizeof(_oldVideoMode)); - memset(&_videoMode, 0, sizeof(_videoMode)); - memset(&_transactionDetails, 0, sizeof(_transactionDetails)); - - _videoMode.mode = GFX_DOUBLESIZE; - _videoMode.scaleFactor = 2; - _videoMode.aspectRatioCorrection = ConfMan.getBool("aspect_ratio"); - _scalerProc = Normal2x; - _scalerType = 0; - - _videoMode.fullscreen = true; - - // enable joystick - if (joystick_num > -1 && SDL_NumJoysticks() > 0) { - printf("Using joystick: %s\n", SDL_JoystickName(0)); - _joystick = SDL_JoystickOpen(joystick_num); - } - - setupMixer(); - - // Note: We could implement a custom SDLTimerManager by using - // 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. - // 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. - _timer = new DefaultTimerManager(); - _timerID = SDL_AddTimer(10, &timer_handler, _timer); - - // Invoke parent implementation of this method - OSystem::initBackend(); - - _inited = true; -} - -void OSystem_OP::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) { - - /* Setup default extra data paths for engine data files and plugins */ - - char workDirName[PATH_MAX+1]; - - if (getcwd(workDirName, PATH_MAX) == NULL) { - error("Error: Could not obtain current working directory."); - } - - char enginedataPath[PATH_MAX+1]; - - strcpy(enginedataPath, workDirName); - strcat(enginedataPath, "/../data"); - printf("Default engine data directory: %s\n", enginedataPath); - - Common::FSNode engineNode(enginedataPath); - if (engineNode.exists() && engineNode.isDirectory()) { - s.add("__OP_ENGDATA__", new Common::FSDirectory(enginedataPath), priority); - } + return res; } -void OSystem_OP::quit() { - - SDL_FreeCursor(hiddenCursor); - - #ifdef DUMP_STDOUT - printf("%s\n", "Debug: STDOUT and STDERR text files closed."); - fclose(stdout); - fclose(stderr); - #endif /* DUMP_STDOUT */ - - OSystem_SDL::quit(); -} +#endif diff --git a/backends/platform/openpandora/op-sdl.h b/backends/platform/openpandora/op-sdl.h index 8561b42498..93c82ca397 100644 --- a/backends/platform/openpandora/op-sdl.h +++ b/backends/platform/openpandora/op-sdl.h @@ -18,15 +18,18 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * $URL$ - * $Id$ - * */ #ifndef OP_SDL_H #define OP_SDL_H +#if defined(OPENPANDORA) + +#include "backends/base-backend.h" #include "backends/platform/sdl/sdl.h" +#include "backends/platform/sdl/posix/posix.h" +#include "backends/events/openpandora/op-events.h" +#include "backends/graphics/openpandora/op-graphics.h" #define __OPENPANDORA__ #define MIXER_DOUBLE_BUFFERING 1 @@ -35,25 +38,18 @@ #define PATH_MAX 255 #endif -class OSystem_OP : public OSystem_SDL { +class OSystem_OP : public OSystem_POSIX { public: OSystem_OP() {} - /* Events */ - bool handleKeyDown(SDL_Event &ev, Common::Event &event); - bool handleKeyUp(SDL_Event &ev, Common::Event &event); - bool handleMouseButtonDown(SDL_Event &ev, Common::Event &event); - bool handleMouseButtonUp(SDL_Event &ev, Common::Event &event); - - /* Graphics */ - bool loadGFXMode(); - /* Platform Setup Stuff */ void addSysArchivesToSearchSet(Common::SearchSet &s, int priority); void initBackend(); + void initSDL(); void quit(); protected: }; #endif +#endif //OP_SDL_H |