From 77f9f9c6cfc0834492b6e2afd428e87cdff35349 Mon Sep 17 00:00:00 2001 From: John Willis Date: Wed, 25 Oct 2006 19:51:47 +0000 Subject: Update GP2X port to support Fingolfin's ongoing implementation of the Modular Backends ideas :). Also add a few updates from my local tree (Batt level checking and STDOUT/STDERR file mapping code stolen from the Symbian backend (thanks)). svn-id: r24507 --- backends/platform/gp2x/build/bundle.sh | 9 ++- backends/platform/gp2x/gp2x-common.h | 25 +++++-- backends/platform/gp2x/gp2x-hw.cpp | 12 ++++ backends/platform/gp2x/gp2x-hw.h | 2 + backends/platform/gp2x/gp2x.cpp | 119 +++++++++++++++++++++++++++++++-- 5 files changed, 153 insertions(+), 14 deletions(-) (limited to 'backends/platform/gp2x') diff --git a/backends/platform/gp2x/build/bundle.sh b/backends/platform/gp2x/build/bundle.sh index 93efa63a83..0378fcdf60 100644 --- a/backends/platform/gp2x/build/bundle.sh +++ b/backends/platform/gp2x/build/bundle.sh @@ -11,20 +11,25 @@ export LDFLAGS=-L/tools/open2x_gcc/gcc-4.0.2-glibc-2.3.5/arm-open2x-linux/lib echo Collecting files. mkdir "scummvm-gp2x-`date '+%Y-%m-%d'`" +mkdir "scummvm-gp2x-`date '+%Y-%m-%d'`\saves" +echo "Please put your save games in this dir" >> "scummvm-gp2x-`date '+%Y-%m-%d'`\saves\PUT_SAVES_IN_THIS_DIR" + +cp ./scummvm.gpe ./scummvm-gp2x-`date '+%Y-%m-%d'`/ cp ./scummvm.png ./scummvm-gp2x-`date '+%Y-%m-%d'`/ cp ./README-GP2X.html ./scummvm-gp2x-`date '+%Y-%m-%d'`/ cp ./README-GP2X ./scummvm-gp2x-`date '+%Y-%m-%d'`/ -cp ../../../../scummvm.gpe ./scummvm-gp2x-`date '+%Y-%m-%d'`/ +cp ../../../../scummvm.gp2x ./scummvm-gp2x-`date '+%Y-%m-%d'`/ cp ../../../../AUTHORS ./scummvm-gp2x-`date '+%Y-%m-%d'`/ cp ../../../../README ./scummvm-gp2x-`date '+%Y-%m-%d'`/ cp ../../../../COPYING ./scummvm-gp2x-`date '+%Y-%m-%d'`/ +cp ../../../../NEWS ./scummvm-gp2x-`date '+%Y-%m-%d'`/ cp ../../../../gui/themes/modern.ini ./scummvm-gp2x-`date '+%Y-%m-%d'`/ cp ../../../../gui/themes/modern.zip ./scummvm-gp2x-`date '+%Y-%m-%d'`/ echo Making Stripped GPE. -arm-open2x-linux-strip ./scummvm-gp2x-`date '+%Y-%m-%d'`/scummvm.gpe +arm-open2x-linux-strip ./scummvm-gp2x-`date '+%Y-%m-%d'`/scummvm.gp2x echo Building ZIP bundle. echo You should have a "scummvm-gp2x-`date '+%Y-%m-%d'`.zip" for the GP2X port ready to go. \ No newline at end of file diff --git a/backends/platform/gp2x/gp2x-common.h b/backends/platform/gp2x/gp2x-common.h index d768e1c4d8..24c2dba44f 100644 --- a/backends/platform/gp2x/gp2x-common.h +++ b/backends/platform/gp2x/gp2x-common.h @@ -37,6 +37,15 @@ #include #include +namespace Audio { + class Mixer; +} + +namespace Common { + class SaveFileManager; + class TimerManager; +} + //#define DISABLE_SCALERS enum { @@ -123,7 +132,9 @@ public: virtual bool pollEvent(Event &event); // overloaded by CE backend // Set function that generates samples + typedef void (*SoundProc)(void *param, byte *buf, int len); virtual bool setSoundCallback(SoundProc proc, void *param); // overloaded by CE backend + virtual Audio::Mixer *getMixer(); void clearSoundCallback(); @@ -143,9 +154,7 @@ public: // Quit virtual void quit(); // overloaded by CE backend - - // Add a callback timer - void setTimerCallback(TimerProc callback, int timer); + virtual Common::TimerManager *getTimerManager(); // Mutex handling MutexRef createMutex(); @@ -184,6 +193,8 @@ public: void displayMessageOnOSD(const char *msg); + virtual Common::SaveFileManager *getSavefileManager(); + protected: bool _inited; @@ -326,11 +337,8 @@ protected: byte *_mouseData; SDL_Rect _mouseBackup; MousePos _mouseCurState; - //int16 _mouseHotspotX; - //int16 _mouseHotspotY; byte _mouseKeyColor; int _cursorTargetScale; - //bool _cursorHasOwnPalette; bool _cursorPaletteDisabled; SDL_Surface *_mouseOrigSurface; SDL_Surface *_mouseSurface; @@ -359,6 +367,11 @@ protected: */ MutexRef _graphicsMutex; + Common::SaveFileManager *_savefile; + Audio::Mixer *_mixer; + + SDL_TimerID _timerID; + Common::TimerManager *_timer; void addDirtyRgnAuto(const byte *buf); void makeChecksums(const byte *buf); diff --git a/backends/platform/gp2x/gp2x-hw.cpp b/backends/platform/gp2x/gp2x-hw.cpp index e967b6df62..9f573c86e0 100644 --- a/backends/platform/gp2x/gp2x-hw.cpp +++ b/backends/platform/gp2x/gp2x-hw.cpp @@ -37,6 +37,9 @@ #include #include #include +#include +#include +#include static unsigned long gp2x_dev[8]={0,0,0,0,0,0,0,0};//, gp2x_ticks_per_second; static volatile unsigned short *gp2x_memregs; @@ -138,6 +141,15 @@ void GP2X_setCpuspeed(unsigned int mhz) set_920_Div(0); } +int GP2X_getBattLevel() { + int devbatt; + unsigned short currentval=0; + devbatt = open("/dev/batt", O_RDONLY); + read (devbatt, ¤tval, 2); + close (devbatt); + return (currentval); +} + void set_display_clock_div(unsigned div) { div=((div & 63) | 64)<<8; diff --git a/backends/platform/gp2x/gp2x-hw.h b/backends/platform/gp2x/gp2x-hw.h index 59593882b0..8f769200d5 100644 --- a/backends/platform/gp2x/gp2x-hw.h +++ b/backends/platform/gp2x/gp2x-hw.h @@ -62,6 +62,8 @@ extern void GP2X_mixer_set_volume(int, int); extern int GP2X_mixer_get_volume(); extern void GP2X_mixer_move_volume(int); extern void GP2X_setCpuspeed(unsigned int cpuspeed); +extern int GP2X_getBattLevel(); + extern void save_system_regs(void); /* save some registers */ extern void set_display_clock_div(unsigned div); diff --git a/backends/platform/gp2x/gp2x.cpp b/backends/platform/gp2x/gp2x.cpp index 975c64a7ab..a29ae4b8f9 100644 --- a/backends/platform/gp2x/gp2x.cpp +++ b/backends/platform/gp2x/gp2x.cpp @@ -34,6 +34,11 @@ #include "common/util.h" #include "base/main.h" +#include "backends/saves/default/default-saves.h" +#include "backends/timer/default/default-timer.h" +#include "backends/plugins/posix/posix-provider.h" +#include "sound/mixer.h" + #include #include #include @@ -41,10 +46,18 @@ #include #include +// Disable for normal serial logging. +#define DUMP_STDOUT + #if defined(HAVE_CONFIG_H) #include "config.h" #endif +static Uint32 timer_handler(Uint32 interval, void *param) { + ((DefaultTimerManager *)param)->handler(); + return interval; +} + int main(int argc, char *argv[]) { // Setup GP2X upper 32MB caching @@ -82,8 +95,6 @@ void OSystem_GP2X::initBackend() { error("Could not initialize SDL: %s", SDL_GetError()); } - // TODO: Clean way of flushing the file on every write without resorting to this or hacking the POSIX FS code. - //system("/bin/mount -t vfat -o remount,sync,iocharset=utf8 /dev/mmcsd/disc0/part1 /mnt/sd"); // Setup default save path to be workingdir/saves #ifndef PATH_MAX @@ -109,6 +120,49 @@ void OSystem_GP2X::initBackend() { ConfMan.registerDefault("savepath", savePath); + // Note: Review and clean this, it's OTT at the moment. + + #if defined(DUMP_STDOUT) + // The GP2X has a serial console 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) { /* This happens on NT */ + #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) { /* This happens on NT */ + #if !defined(stderr) + stderr = fopen(STDERR_FILE, "w"); + #else + newfp = fopen(STDERR_FILE, "w"); + if (newfp) { + *stderr = *newfp; + } + #endif + } + setbuf(stderr, NULL); /* No buffering */ + #endif // DUMP_STDOUT + // Setup other defaults. ConfMan.registerDefault("aspect_ratio", true); @@ -145,6 +199,33 @@ void OSystem_GP2X::initBackend() { SDL_ShowCursor(SDL_DISABLE); + // Create the savefile manager, if none exists yet (we check for this to + // allow subclasses to provide their own). + if (_savefile == 0) { + _savefile = new DefaultSaveFileManager(); + } + + // Create and hook up the mixer, if none exists yet (we check for this to + // allow subclasses to provide their own). + if (_mixer == 0) { + _mixer = new Audio::Mixer(); + setSoundCallback(Audio::Mixer::mixCallback, _mixer); + } + + // 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) { + // TODO: 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. + // Unfortunately, not all our code is prepared for that, so we can't just + // switch. But it's a long term goal to do just that! + _timer = new DefaultTimerManager(); + _timerID = SDL_AddTimer(10, &timer_handler, _timer); + } + OSystem::initBackend(); _inited = true; @@ -164,6 +245,9 @@ OSystem_GP2X::OSystem_GP2X() _joystick(0), _currentShakePos(0), _newShakePos(0), _paletteDirtyStart(0), _paletteDirtyEnd(0), + _savefile(0), + _mixer(0), + _timer(0), _graphicsMutex(0), _transactionMode(kTransactionNone) { // allocate palette storage @@ -180,10 +264,17 @@ OSystem_GP2X::OSystem_GP2X() } OSystem_GP2X::~OSystem_GP2X() { + SDL_RemoveTimer(_timerID); + SDL_CloseAudio(); + free(_dirtyChecksums); free(_currentPalette); free(_cursorPalette); free(_mouseData); + + delete _savefile; + delete _mixer; + delete _timer; } uint32 OSystem_GP2X::getMillis() { @@ -194,10 +285,20 @@ void OSystem_GP2X::delayMillis(uint msecs) { SDL_Delay(msecs); } -void OSystem_GP2X::setTimerCallback(TimerProc callback, int timer) { - SDL_SetTimer(timer, (SDL_TimerCallback) callback); +Common::TimerManager *OSystem_GP2X::getTimerManager() { + assert(_timer); + return _timer; } +Common::SaveFileManager *OSystem_GP2X::getSavefileManager() { + assert(_savefile); + return _savefile; +} + +//void OSystem_GP2X::setTimerCallback(TimerProc callback, int timer) { +// SDL_SetTimer(timer, (SDL_TimerCallback) callback); +//} + bool OSystem_GP2X::hasFeature(Feature f) { return (f == kFeatureFullscreenMode) || @@ -250,8 +351,9 @@ void OSystem_GP2X::quit() { //CloseRam(); GP2X_device_deinit(); SDL_Quit(); - chdir("/usr/gp2x"); - execl("/usr/gp2x/gp2xmenu", "/usr/gp2x/gp2xmenu", NULL); + //chdir("/usr/gp2x"); + //execl("/usr/gp2x/gp2xmenu", "/usr/gp2x/gp2xmenu", NULL); + exit(0); } OSystem::MutexRef OSystem_GP2X::createMutex(void) { @@ -315,6 +417,11 @@ int OSystem_GP2X::getOutputSampleRate() const { return _samplesPerSec; } +Audio::Mixer *OSystem_GP2X::getMixer() { + assert(_mixer); + return _mixer; +} + #pragma mark - #pragma mark --- CD Audio --- #pragma mark - -- cgit v1.2.3