From e7330aa0afec88c6d7327ac9fd1a49736daaad6f Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 21 May 2010 18:18:52 +0000 Subject: Fix spelling svn-id: r49130 --- backends/platform/sdl/sdl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/platform') diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 6b23acfb8b..33a06629f8 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -521,7 +521,7 @@ void OSystem_SDL::quit() { SDL_Quit(); - // Even Manager requires save manager for storing + // Event Manager requires save manager for storing // recorded events delete getEventManager(); delete _savefile; -- cgit v1.2.3 From 01c55efc95b2510eca1842058ab878e1ebd5ed4e Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 21 May 2010 18:22:11 +0000 Subject: SDL: Split quit() method into deinit() so error codes could be returned. svn-id: r49131 --- backends/platform/sdl/main.cpp | 2 +- backends/platform/sdl/sdl.cpp | 6 +++++- backends/platform/sdl/sdl.h | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) (limited to 'backends/platform') diff --git a/backends/platform/sdl/main.cpp b/backends/platform/sdl/main.cpp index b38b815438..13e614a4a2 100644 --- a/backends/platform/sdl/main.cpp +++ b/backends/platform/sdl/main.cpp @@ -63,7 +63,7 @@ int main(int argc, char *argv[]) { // Invoke the actual ScummVM main entry point: int res = scummvm_main(argc, argv); - g_system->quit(); // TODO: Consider removing / replacing this! + ((OSystem_SDL *)g_system)->deinit(); return res; } diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 33a06629f8..9fa43cb389 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -496,7 +496,7 @@ bool OSystem_SDL::getFeatureState(Feature f) { } } -void OSystem_SDL::quit() { +void OSystem_SDL::deinit() { if (_cdrom) { SDL_CDStop(_cdrom); SDL_CDClose(_cdrom); @@ -525,6 +525,10 @@ void OSystem_SDL::quit() { // recorded events delete getEventManager(); delete _savefile; +} + +void OSystem_SDL::quit() { + deinit(); #if !defined(SAMSUNGTV) exit(0); diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index b178d58994..c850ec5ab1 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -202,6 +202,8 @@ public: // Quit virtual void quit(); // overloaded by CE backend + void deinit(); + virtual void getTimeAndDate(TimeDate &t) const; virtual Common::TimerManager *getTimerManager(); -- cgit v1.2.3 From 47d6e9eab7f657ac36b01c143a0bd5edba1d2361 Mon Sep 17 00:00:00 2001 From: Paweł Kołodziejski Date: Fri, 21 May 2010 18:33:24 +0000 Subject: sync with parent sdl backend svn-id: r49134 --- backends/platform/samsungtv/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/platform') diff --git a/backends/platform/samsungtv/main.cpp b/backends/platform/samsungtv/main.cpp index a6b8376912..2c025b750c 100644 --- a/backends/platform/samsungtv/main.cpp +++ b/backends/platform/samsungtv/main.cpp @@ -43,7 +43,7 @@ extern "C" int Game_Main(char *path, char *) { // Invoke the actual ScummVM main entry point: int res = scummvm_main(0, 0); - g_system->quit(); // TODO: Consider removing / replacing this! + ((OSystem_SDL *)g_system)->deinit(); return res; } -- cgit v1.2.3 From 7a6a2a62eebfea5f09bf86fee3935e1ad031959d Mon Sep 17 00:00:00 2001 From: Yotam Barnoy Date: Sun, 23 May 2010 05:51:32 +0000 Subject: PSP: switched from SDL's audio to my own thread. Removed needless blocking while playing and made it generally more efficient. To deactivate, simply comment out USE_PSP_AUDIO svn-id: r49149 --- backends/platform/psp/Makefile | 4 +- backends/platform/psp/audio.cpp | 228 +++++++++++++++++++++++++++++++++++++ backends/platform/psp/audio.h | 71 ++++++++++++ backends/platform/psp/module.mk | 3 +- backends/platform/psp/osys_psp.cpp | 31 ++++- backends/platform/psp/osys_psp.h | 2 + 6 files changed, 332 insertions(+), 7 deletions(-) create mode 100644 backends/platform/psp/audio.cpp create mode 100644 backends/platform/psp/audio.h (limited to 'backends/platform') diff --git a/backends/platform/psp/Makefile b/backends/platform/psp/Makefile index 8e83563d10..6967973da7 100644 --- a/backends/platform/psp/Makefile +++ b/backends/platform/psp/Makefile @@ -147,8 +147,8 @@ OBJS := powerman.o \ cursor.o \ trace.o \ psploader.o \ - pspkeyboard.o - + pspkeyboard.o \ + audio.o # Include common Scummvm makefile include $(srcdir)/Makefile.common diff --git a/backends/platform/psp/audio.cpp b/backends/platform/psp/audio.cpp new file mode 100644 index 0000000000..c19cbb52a2 --- /dev/null +++ b/backends/platform/psp/audio.cpp @@ -0,0 +1,228 @@ +/* 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. + * + * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/platform/psp/osys_psp.cpp $ + * $Id: osys_psp.cpp 46126 2009-11-24 14:18:46Z fingolfin $ + * + */ + +#include +#include +#include + +#include "common/scummsys.h" +#include "backends/platform/psp/audio.h" + +//#define __PSP_DEBUG_FUNCS__ /* For debugging function calls */ +//#define __PSP_DEBUG_PRINT__ /* For debug printouts */ + +#include "backends/platform/psp/trace.h" + +bool PspAudio::open(uint32 freq, uint32 numOfChannels, uint32 numOfSamples, callbackFunc callback, void *userData) { + DEBUG_ENTER_FUNC(); + if (_init) { + PSP_ERROR("audio device already initialized\n"); + return true; + } + + PSP_DEBUG_PRINT("freq[%d], numOfChannels[%d], numOfSamples[%d], callback[%p], userData[%x]\n", + freq, numOfChannels, numOfSamples, callback, (uint32)userData); + + numOfSamples = PSP_AUDIO_SAMPLE_ALIGN(numOfSamples); + uint32 bufLen = numOfSamples * numOfChannels * NUM_BUFFERS * sizeof(uint16); + + PSP_DEBUG_PRINT("total buffer size[%d]\n", bufLen); + + _buffers[0] = (byte *)memalign(64, bufLen); + if (!_buffers[0]) { + PSP_ERROR("failed to allocate memory for audio buffers\n"); + return false; + } + memset(_buffers[0], 0, bufLen); // clean the buffer + + // Fill in the rest of the buffer pointers + byte *pBuffer = _buffers[0]; + for (int i = 1; i < NUM_BUFFERS; i++) { + pBuffer += numOfSamples * numOfChannels * sizeof(uint16); + _buffers[i] = pBuffer; + } + + // Reserve a HW channel for our audio + _pspChannel = sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL, numOfSamples, numOfChannels == 2 ? PSP_AUDIO_FORMAT_STEREO : PSP_AUDIO_FORMAT_MONO); + if (_pspChannel < 0) { + PSP_ERROR("failed to reserve audio channel\n"); + return false; + } + + PSP_DEBUG_PRINT("reserved channel[%d] for audio\n", _pspChannel); + + // Save our data + _numOfChannels = numOfChannels; + _numOfSamples = numOfSamples; + _bufferSize = numOfSamples * numOfChannels * sizeof(uint16); // should be the right size to send the app + _callback = callback; + _userData = userData; + _emptyBuffers = NUM_BUFFERS; + _bufferToFill = 0; + _bufferToPlay = 0; + + _init = true; + _paused = true; // start in paused mode + + createThread(); + + return true; +} + +bool PspAudio::createThread() { + DEBUG_ENTER_FUNC(); + int threadId = sceKernelCreateThread("audioThread", thread, 30, 16*1024, THREAD_ATTR_USER, 0); + + if (threadId < 0) { // error + PSP_ERROR("failed to create audio thread. Error code %d\n", threadId); + return false; + } + + PspAudio *_this = this; // trick to get into context when the thread starts + + if (sceKernelStartThread(threadId, sizeof(uint32 *), &_this) < 0) { + PSP_ERROR("failed to start thread %d\n", threadId); + return false; + } + + PSP_DEBUG_PRINT("created audio thread[%x]\n", threadId); + + return true; +} + +// Static function to be called upon thread startup. Will call a non-static function +int PspAudio::thread(SceSize, void *__this) { + DEBUG_ENTER_FUNC(); + PspAudio *_this = *(PspAudio **)__this; // get our this for the context + + _this->audioThread(); + return 0; +}; + +// The real thread function +void PspAudio::audioThread() { + bool isPlaying = false; + int remainingSamples = 0; + + assert(_callback); + PSP_DEBUG_PRINT_FUNC("audio thread started\n"); + + while (_init) { // Keep looping so long as we haven't been told to stop + if (_paused) + PSP_DEBUG_PRINT("audio thread paused\n"); + while (_paused) { // delay until we stop pausing + SDL_Delay(100); + } + if (!_paused) + PSP_DEBUG_PRINT("audio thread unpaused\n"); + + // check if the audio is playing + remainingSamples = sceAudioGetChannelRestLen(_pspChannel); + if (remainingSamples < 0) { + PSP_ERROR("failed to get remaining samples\n"); + return; + } + isPlaying = remainingSamples ? true : false; + + PSP_DEBUG_PRINT("remaining samples[%d]\n", remainingSamples); + + while (true) { // really only execute once. this just helps write the logic + if (isPlaying) { + _stoppedPlayingOnceFlag = false; + + // check if a buffer is empty + if (_emptyBuffers) { // we have some empty buffers + PSP_DEBUG_PRINT("sound playing & an empty buffer. filling buffer[%d]. empty buffers[%d]\n", _bufferToFill, _emptyBuffers); + _callback(_userData, _buffers[_bufferToFill], _bufferSize); // ask mixer to fill in + nextBuffer(_bufferToFill); + _emptyBuffers--; + break; + } else { // we have no empty buffers + // calculate how long we need to sleep. time(us) = samples * 1000000 / freq + // since frequency is always 44100, we can do a shortcut: + // time(us) = samples * (10000 / 441) + uint32 sleepTime = (remainingSamples * 10000) / 441; + if (!sleepTime) + break; + PSP_DEBUG_PRINT("sound playing & no empty buffers. sleeping for %d samples for %dus\n", remainingSamples, sleepTime); + sceKernelDelayThread(sleepTime); + break; + } + } else { // we're not playing right now + if (_stoppedPlayingOnceFlag == false) { // we only want to do this when we finish playing + nextBuffer(_bufferToPlay); + _emptyBuffers++; + _stoppedPlayingOnceFlag = true; + } + + if (_emptyBuffers == NUM_BUFFERS) { // problem: we have only empty buffers! + PSP_DEBUG_PRINT("no sound playing & no full buffer. filling buffer[%d]. empty buffers[%d]\n", _bufferToFill, _emptyBuffers); + _callback(_userData, _buffers[_bufferToFill], _bufferSize); + nextBuffer(_bufferToFill); + _emptyBuffers--; + break; + } else { // we have at least one non-empty buffer + PSP_DEBUG_PRINT("no sound playing & a full buffer. playing buffer[%d]. empty buffers[%d]\n", _bufferToPlay, _emptyBuffers); + playBuffer(); + break; + } + } + } // while true + } // while _init + + // destroy everything + free(_buffers[0]); + sceAudioChRelease(_pspChannel); + PSP_DEBUG_PRINT("audio thread exiting. ****************************\n"); +} + +// Much faster than using % +inline void PspAudio::nextBuffer(int &bufferIdx) { + DEBUG_ENTER_FUNC(); + bufferIdx++; + if (bufferIdx >= NUM_BUFFERS) + bufferIdx = 0; +} + +// Don't do it with blocking +inline bool PspAudio::playBuffer() { + DEBUG_ENTER_FUNC(); + int ret; + if (_numOfChannels == 1) + ret = sceAudioOutput(_pspChannel, PSP_AUDIO_VOLUME_MAX, _buffers[_bufferToPlay]); + else + ret = sceAudioOutputPanned(_pspChannel, PSP_AUDIO_VOLUME_MAX, PSP_AUDIO_VOLUME_MAX, _buffers[_bufferToPlay]); + + if (ret < 0) { + PSP_ERROR("failed to output audio. Error[%d]\n", ret); + return false; + } + return true; +} + +void PspAudio::close() { + PSP_DEBUG_PRINT("close had been called ***************\n"); + _init = false; +} diff --git a/backends/platform/psp/audio.h b/backends/platform/psp/audio.h new file mode 100644 index 0000000000..97e2391319 --- /dev/null +++ b/backends/platform/psp/audio.h @@ -0,0 +1,71 @@ +/* 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. + * + * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/platform/psp/osys_psp.cpp $ + * $Id: osys_psp.cpp 46126 2009-11-24 14:18:46Z fingolfin $ + * + */ + +#ifndef PSP_AUDIO_H +#define PSP_AUDIO_H + +class PspAudio { +public: + enum { + NUM_BUFFERS = 2, + FREQUENCY = 44100 /* only frequency we allow */ + }; + typedef void (* callbackFunc)(void *userData, byte *samples, int len); + PspAudio() : _pspChannel(0), + _numOfChannels(0), _numOfSamples(0), _callback(0), + _bufferToPlay(0), _bufferToFill(0), _emptyBuffers(NUM_BUFFERS), + _init(false), _paused(true), _stoppedPlayingOnceFlag(true) { + for (int i=0; i samplesPerSec * 2) samples >>= 1; + assert(!_mixer); + +#ifdef USE_PSP_AUDIO + if (!_audio.open(samplesPerSec, 2, samples, mixCallback, this)) { + PSP_ERROR("failed to open audio\n"); + return; + } + samplesPerSec = _audio.getFrequency(); // may have been changed by audio system + _mixer = new Audio::MixerImpl(this, samplesPerSec); + assert(_mixer); + _mixer->setReady(true); + _audio.unpause(); +#else + SDL_AudioSpec obtained; + SDL_AudioSpec desired; + memset(&desired, 0, sizeof(desired)); desired.freq = samplesPerSec; desired.format = AUDIO_S16SYS; @@ -356,8 +375,7 @@ void OSystem_PSP::setupMixer(void) { desired.samples = samples; desired.callback = mixCallback; desired.userdata = this; - - assert(!_mixer); + if (SDL_OpenAudio(&desired, &obtained) != 0) { warning("Could not open audio: %s", SDL_GetError()); _mixer = new Audio::MixerImpl(this, samplesPerSec); @@ -376,10 +394,15 @@ void OSystem_PSP::setupMixer(void) { SDL_PauseAudio(0); } +#endif /* USE_PSP_AUDIO */ } void OSystem_PSP::quit() { +#ifdef USE_PSP_AUDIO + _audio.close(); +#else SDL_CloseAudio(); +#endif SDL_Quit(); sceKernelExitGame(); } diff --git a/backends/platform/psp/osys_psp.h b/backends/platform/psp/osys_psp.h index 8c5b40dcdf..4d9cf31b18 100644 --- a/backends/platform/psp/osys_psp.h +++ b/backends/platform/psp/osys_psp.h @@ -38,6 +38,7 @@ #include "backends/platform/psp/pspkeyboard.h" #include "backends/platform/psp/display_manager.h" #include "backends/platform/psp/input.h" +#include "backends/platform/psp/audio.h" #include @@ -55,6 +56,7 @@ private: DisplayManager _displayManager; PSPKeyboard _keyboard; InputHandler _inputHandler; + PspAudio _audio; void initSDL(); -- cgit v1.2.3 From 20c654f63b29a5eb120e5d7d72d06080995a463a Mon Sep 17 00:00:00 2001 From: Yotam Barnoy Date: Sun, 23 May 2010 11:48:21 +0000 Subject: PSP: replaced SDL's timer with much simpler and more efficient PspTimer class svn-id: r49155 --- backends/platform/psp/Makefile | 3 +- backends/platform/psp/audio.cpp | 3 +- backends/platform/psp/display_manager.cpp | 3 +- backends/platform/psp/module.mk | 3 +- backends/platform/psp/osys_psp.cpp | 11 +++-- backends/platform/psp/osys_psp.h | 2 + backends/platform/psp/psp_main.cpp | 3 +- backends/platform/psp/timer.cpp | 80 +++++++++++++++++++++++++++++++ backends/platform/psp/timer.h | 47 ++++++++++++++++++ 9 files changed, 146 insertions(+), 9 deletions(-) create mode 100644 backends/platform/psp/timer.cpp create mode 100644 backends/platform/psp/timer.h (limited to 'backends/platform') diff --git a/backends/platform/psp/Makefile b/backends/platform/psp/Makefile index 6967973da7..6acd8e970a 100644 --- a/backends/platform/psp/Makefile +++ b/backends/platform/psp/Makefile @@ -148,7 +148,8 @@ OBJS := powerman.o \ trace.o \ psploader.o \ pspkeyboard.o \ - audio.o + audio.o \ + timer.o # Include common Scummvm makefile include $(srcdir)/Makefile.common diff --git a/backends/platform/psp/audio.cpp b/backends/platform/psp/audio.cpp index c19cbb52a2..58b2251811 100644 --- a/backends/platform/psp/audio.cpp +++ b/backends/platform/psp/audio.cpp @@ -29,6 +29,7 @@ #include "common/scummsys.h" #include "backends/platform/psp/audio.h" +#include "backends/platform/psp/thread.h" //#define __PSP_DEBUG_FUNCS__ /* For debugging function calls */ //#define __PSP_DEBUG_PRINT__ /* For debug printouts */ @@ -93,7 +94,7 @@ bool PspAudio::open(uint32 freq, uint32 numOfChannels, uint32 numOfSamples, call bool PspAudio::createThread() { DEBUG_ENTER_FUNC(); - int threadId = sceKernelCreateThread("audioThread", thread, 30, 16*1024, THREAD_ATTR_USER, 0); + int threadId = sceKernelCreateThread("audioThread", thread, PRIORITY_AUDIO_THREAD, STACK_AUDIO_THREAD, THREAD_ATTR_USER, 0); if (threadId < 0) { // error PSP_ERROR("failed to create audio thread. Error code %d\n", threadId); diff --git a/backends/platform/psp/display_manager.cpp b/backends/platform/psp/display_manager.cpp index 0982512a86..c2f21e084b 100644 --- a/backends/platform/psp/display_manager.cpp +++ b/backends/platform/psp/display_manager.cpp @@ -34,6 +34,7 @@ #include "backends/platform/psp/default_display_client.h" #include "backends/platform/psp/cursor.h" #include "backends/platform/psp/pspkeyboard.h" +#include "backends/platform/psp/thread.h" #define USE_DISPLAY_CALLBACK // to use callback for finishing the render #include "backends/platform/psp/display_manager.h" @@ -64,7 +65,7 @@ const OSystem::GraphicsMode DisplayManager::_supportedModes[] = { void MasterGuRenderer::setupCallbackThread() { DEBUG_ENTER_FUNC(); - int thid = sceKernelCreateThread("displayCbThread", guCallbackThread, 0x11, 4*1024, THREAD_ATTR_USER, 0); + int thid = sceKernelCreateThread("displayCbThread", guCallbackThread, PRIORITY_DISPLAY_THREAD, STACK_DISPLAY_THREAD, THREAD_ATTR_USER, 0); PSP_DEBUG_PRINT("Display CB thread id is %x\n", thid); diff --git a/backends/platform/psp/module.mk b/backends/platform/psp/module.mk index 0e5bd8737d..461df629bf 100644 --- a/backends/platform/psp/module.mk +++ b/backends/platform/psp/module.mk @@ -13,7 +13,8 @@ MODULE_OBJS := powerman.o \ trace.o \ psploader.o \ pspkeyboard.o \ - audio.o + audio.o \ + timer.o MODULE_DIRS += \ backends/platform/psp/ diff --git a/backends/platform/psp/osys_psp.cpp b/backends/platform/psp/osys_psp.cpp index 5f51135a9a..f33081abbc 100644 --- a/backends/platform/psp/osys_psp.cpp +++ b/backends/platform/psp/osys_psp.cpp @@ -60,9 +60,9 @@ static int timer_handler(int t) { void OSystem_PSP::initSDL() { #ifdef USE_PSP_AUDIO - SDL_Init(SDL_INIT_TIMER); + SDL_Init(0); #else - SDL_Init(SDL_INIT_AUDIO | SDL_INIT_TIMER); + SDL_Init(SDL_INIT_AUDIO); #endif } @@ -90,7 +90,7 @@ void OSystem_PSP::initBackend() { _inputHandler.init(); initSDL(); - + _savefile = new PSPSaveFileManager; _timer = new DefaultTimerManager(); @@ -308,7 +308,10 @@ void OSystem_PSP::delayMillis(uint msecs) { } void OSystem_PSP::setTimerCallback(TimerProc callback, int interval) { - SDL_SetTimer(interval, (SDL_TimerCallback)callback); + //SDL_SetTimer(interval, (SDL_TimerCallback)callback); + _pspTimer.setCallback((PspTimer::CallbackFunc)callback); + _pspTimer.setIntervalMs(interval); + _pspTimer.start(); } OSystem::MutexRef OSystem_PSP::createMutex(void) { diff --git a/backends/platform/psp/osys_psp.h b/backends/platform/psp/osys_psp.h index 4d9cf31b18..413de0f528 100644 --- a/backends/platform/psp/osys_psp.h +++ b/backends/platform/psp/osys_psp.h @@ -39,6 +39,7 @@ #include "backends/platform/psp/display_manager.h" #include "backends/platform/psp/input.h" #include "backends/platform/psp/audio.h" +#include "backends/platform/psp/timer.h" #include @@ -57,6 +58,7 @@ private: PSPKeyboard _keyboard; InputHandler _inputHandler; PspAudio _audio; + PspTimer _pspTimer; void initSDL(); diff --git a/backends/platform/psp/psp_main.cpp b/backends/platform/psp/psp_main.cpp index e568184990..e6940eba13 100644 --- a/backends/platform/psp/psp_main.cpp +++ b/backends/platform/psp/psp_main.cpp @@ -39,6 +39,7 @@ #include #include #include "backends/platform/psp/powerman.h" +#include "backends/platform/psp/thread.h" #include "backends/plugins/psp/psp-provider.h" #include "backends/platform/psp/psppixelformat.h" @@ -140,7 +141,7 @@ int CallbackThread(SceSize /*size*/, void *arg) { /* Sets up the callback thread and returns its thread id */ int SetupCallbacks(void) { - int thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, THREAD_ATTR_USER, 0); + int thid = sceKernelCreateThread("power_thread", CallbackThread, PRIORITY_POWER_THREAD, STACK_POWER_THREAD, THREAD_ATTR_USER, 0); if (thid >= 0) { sceKernelStartThread(thid, 0, 0); } diff --git a/backends/platform/psp/timer.cpp b/backends/platform/psp/timer.cpp new file mode 100644 index 0000000000..a35bd9d827 --- /dev/null +++ b/backends/platform/psp/timer.cpp @@ -0,0 +1,80 @@ +/* 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. + * + * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/platform/psp/osys_psp.cpp $ + * $Id: osys_psp.cpp 46126 2009-11-24 14:18:46Z fingolfin $ + * + */ + +#include + +#include "common/scummsys.h" +#include "common/timer.h" +#include "backends/platform/psp/thread.h" +#include "backends/platform/psp/timer.h" + +//#define __PSP_DEBUG_FUNCS__ /* For debugging function calls */ +//#define __PSP_DEBUG_PRINT__ /* For debug printouts */ + +#include "backends/platform/psp/trace.h" + +bool PspTimer::start() { + DEBUG_ENTER_FUNC(); + + if (!_interval || !_callback) + return false; + + _threadId = sceKernelCreateThread("timerThread", thread, PRIORITY_TIMER_THREAD, STACK_TIMER_THREAD, THREAD_ATTR_USER, 0); + + if (_threadId < 0) { // error + PSP_ERROR("failed to create timer thread. Error code %d\n", _threadId); + return false; + } + + PspTimer *_this = this; // trick to get into context when the thread starts + _init = true; + + if (sceKernelStartThread(_threadId, sizeof(uint32 *), &_this) < 0) { + PSP_ERROR("failed to start thread %d\n", _threadId); + return false; + } + + PSP_DEBUG_PRINT("created timer thread[%x]\n", _threadId); + + return true; +} + +int PspTimer::thread(SceSize, void *__this) { + DEBUG_ENTER_FUNC(); + PspTimer *_this = *(PspTimer **)__this; // get our this for the context + + _this->timerThread(); + return 0; +}; + +void PspTimer::timerThread() { + DEBUG_ENTER_FUNC(); + + while (_init) { + sceKernelDelayThread(_interval); + PSP_DEBUG_PRINT("calling callback!\n"); + _callback(); + } +}; diff --git a/backends/platform/psp/timer.h b/backends/platform/psp/timer.h new file mode 100644 index 0000000000..ec31addb72 --- /dev/null +++ b/backends/platform/psp/timer.h @@ -0,0 +1,47 @@ +/* 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. + * + * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/platform/psp/osys_psp.cpp $ + * $Id: osys_psp.cpp 46126 2009-11-24 14:18:46Z fingolfin $ + * + */ + +#ifndef PSP_TIMER_H +#define PSP_TIMER_H + +class PspTimer { +public: + typedef void (* CallbackFunc)(void); + PspTimer() : _callback(0), _interval(0), _threadId(-1), _init(false) {} + void stop() { _init = false; } + bool start(); + ~PspTimer() { stop(); } + void setCallback(CallbackFunc cb) { _callback = cb; } + void setIntervalMs(uint32 interval) { _interval = interval * 1000; } + static int thread(SceSize, void *__this); // static thread to use as bridge + void timerThread(); +private: + CallbackFunc _callback; // pointer to timer callback + uint32 _interval; + int _threadId; + bool _init; +}; + +#endif -- cgit v1.2.3 From e321e255147fc93a76518c92bcd521771f3ca651 Mon Sep 17 00:00:00 2001 From: Yotam Barnoy Date: Sun, 23 May 2010 17:35:31 +0000 Subject: PSP: forgot to add a file svn-id: r49162 --- backends/platform/psp/thread.h | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 backends/platform/psp/thread.h (limited to 'backends/platform') diff --git a/backends/platform/psp/thread.h b/backends/platform/psp/thread.h new file mode 100644 index 0000000000..5879d044ed --- /dev/null +++ b/backends/platform/psp/thread.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. + * + * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/platform/psp/portdefs.h $ + * $Id: portdefs.h 38687 2009-02-21 12:08:52Z joostp $ + * + */ + +#ifndef PSP_THREAD_H +#define PSP_THREAD_H + +enum ThreadPriority { + PRIORITY_MAIN_THREAD = 36, + PRIORITY_AUDIO_THREAD = 35, // We'll alternate between this and main thread priority + PRIORITY_TIMER_THREAD = 30, + PRIORITY_POWER_THREAD = 20, + PRIORITY_DISPLAY_THREAD = 17 +}; + +enum StackSizes { + STACK_AUDIO_THREAD = 16 * 1024, + STACK_TIMER_THREAD = 4 * 1024, + STACK_DISPLAY_THREAD = 4 * 1024, + STACK_POWER_THREAD = 4 * 1024 +}; + +#endif /* PSP_THREADS_H */ + + -- cgit v1.2.3 From e5d239b779ba24e75f1f911b023c6c94b63ffefd Mon Sep 17 00:00:00 2001 From: Yotam Barnoy Date: Sun, 23 May 2010 19:31:38 +0000 Subject: PSP: changed thread stack sizes to prevent crashes in COMI svn-id: r49168 --- backends/platform/psp/thread.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'backends/platform') diff --git a/backends/platform/psp/thread.h b/backends/platform/psp/thread.h index 5879d044ed..d395d6713e 100644 --- a/backends/platform/psp/thread.h +++ b/backends/platform/psp/thread.h @@ -36,8 +36,8 @@ enum ThreadPriority { enum StackSizes { STACK_AUDIO_THREAD = 16 * 1024, - STACK_TIMER_THREAD = 4 * 1024, - STACK_DISPLAY_THREAD = 4 * 1024, + STACK_TIMER_THREAD = 16 * 1024, + STACK_DISPLAY_THREAD = 2 * 1024, STACK_POWER_THREAD = 4 * 1024 }; -- cgit v1.2.3 From 734042a32ce37822551094feac81887743998b6c Mon Sep 17 00:00:00 2001 From: Yotam Barnoy Date: Sun, 23 May 2010 19:32:56 +0000 Subject: PSP: commented out new PSP audio. Still has some clicking issues svn-id: r49169 --- backends/platform/psp/osys_psp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/platform') diff --git a/backends/platform/psp/osys_psp.cpp b/backends/platform/psp/osys_psp.cpp index f33081abbc..d29196619b 100644 --- a/backends/platform/psp/osys_psp.cpp +++ b/backends/platform/psp/osys_psp.cpp @@ -48,7 +48,7 @@ #include "backends/platform/psp/trace.h" -#define USE_PSP_AUDIO +//#define USE_PSP_AUDIO #define SAMPLES_PER_SEC 44100 -- cgit v1.2.3 From 50847c02a6ca526a01f3eecae024e32973413a90 Mon Sep 17 00:00:00 2001 From: Yotam Barnoy Date: Mon, 24 May 2010 03:05:17 +0000 Subject: PSP: moved timer thread to backends/timer/psp svn-id: r49173 --- backends/platform/psp/Makefile | 3 +- backends/platform/psp/module.mk | 3 +- backends/platform/psp/osys_psp.h | 2 +- backends/platform/psp/timer.cpp | 80 ---------------------------------------- backends/platform/psp/timer.h | 47 ----------------------- 5 files changed, 3 insertions(+), 132 deletions(-) delete mode 100644 backends/platform/psp/timer.cpp delete mode 100644 backends/platform/psp/timer.h (limited to 'backends/platform') diff --git a/backends/platform/psp/Makefile b/backends/platform/psp/Makefile index 6acd8e970a..6967973da7 100644 --- a/backends/platform/psp/Makefile +++ b/backends/platform/psp/Makefile @@ -148,8 +148,7 @@ OBJS := powerman.o \ trace.o \ psploader.o \ pspkeyboard.o \ - audio.o \ - timer.o + audio.o # Include common Scummvm makefile include $(srcdir)/Makefile.common diff --git a/backends/platform/psp/module.mk b/backends/platform/psp/module.mk index 461df629bf..0e5bd8737d 100644 --- a/backends/platform/psp/module.mk +++ b/backends/platform/psp/module.mk @@ -13,8 +13,7 @@ MODULE_OBJS := powerman.o \ trace.o \ psploader.o \ pspkeyboard.o \ - audio.o \ - timer.o + audio.o MODULE_DIRS += \ backends/platform/psp/ diff --git a/backends/platform/psp/osys_psp.h b/backends/platform/psp/osys_psp.h index 413de0f528..3f075d0139 100644 --- a/backends/platform/psp/osys_psp.h +++ b/backends/platform/psp/osys_psp.h @@ -39,7 +39,7 @@ #include "backends/platform/psp/display_manager.h" #include "backends/platform/psp/input.h" #include "backends/platform/psp/audio.h" -#include "backends/platform/psp/timer.h" +#include "backends/timer/psp/timer.h" #include diff --git a/backends/platform/psp/timer.cpp b/backends/platform/psp/timer.cpp deleted file mode 100644 index a35bd9d827..0000000000 --- a/backends/platform/psp/timer.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* 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. - * - * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/platform/psp/osys_psp.cpp $ - * $Id: osys_psp.cpp 46126 2009-11-24 14:18:46Z fingolfin $ - * - */ - -#include - -#include "common/scummsys.h" -#include "common/timer.h" -#include "backends/platform/psp/thread.h" -#include "backends/platform/psp/timer.h" - -//#define __PSP_DEBUG_FUNCS__ /* For debugging function calls */ -//#define __PSP_DEBUG_PRINT__ /* For debug printouts */ - -#include "backends/platform/psp/trace.h" - -bool PspTimer::start() { - DEBUG_ENTER_FUNC(); - - if (!_interval || !_callback) - return false; - - _threadId = sceKernelCreateThread("timerThread", thread, PRIORITY_TIMER_THREAD, STACK_TIMER_THREAD, THREAD_ATTR_USER, 0); - - if (_threadId < 0) { // error - PSP_ERROR("failed to create timer thread. Error code %d\n", _threadId); - return false; - } - - PspTimer *_this = this; // trick to get into context when the thread starts - _init = true; - - if (sceKernelStartThread(_threadId, sizeof(uint32 *), &_this) < 0) { - PSP_ERROR("failed to start thread %d\n", _threadId); - return false; - } - - PSP_DEBUG_PRINT("created timer thread[%x]\n", _threadId); - - return true; -} - -int PspTimer::thread(SceSize, void *__this) { - DEBUG_ENTER_FUNC(); - PspTimer *_this = *(PspTimer **)__this; // get our this for the context - - _this->timerThread(); - return 0; -}; - -void PspTimer::timerThread() { - DEBUG_ENTER_FUNC(); - - while (_init) { - sceKernelDelayThread(_interval); - PSP_DEBUG_PRINT("calling callback!\n"); - _callback(); - } -}; diff --git a/backends/platform/psp/timer.h b/backends/platform/psp/timer.h deleted file mode 100644 index ec31addb72..0000000000 --- a/backends/platform/psp/timer.h +++ /dev/null @@ -1,47 +0,0 @@ -/* 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. - * - * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/platform/psp/osys_psp.cpp $ - * $Id: osys_psp.cpp 46126 2009-11-24 14:18:46Z fingolfin $ - * - */ - -#ifndef PSP_TIMER_H -#define PSP_TIMER_H - -class PspTimer { -public: - typedef void (* CallbackFunc)(void); - PspTimer() : _callback(0), _interval(0), _threadId(-1), _init(false) {} - void stop() { _init = false; } - bool start(); - ~PspTimer() { stop(); } - void setCallback(CallbackFunc cb) { _callback = cb; } - void setIntervalMs(uint32 interval) { _interval = interval * 1000; } - static int thread(SceSize, void *__this); // static thread to use as bridge - void timerThread(); -private: - CallbackFunc _callback; // pointer to timer callback - uint32 _interval; - int _threadId; - bool _init; -}; - -#endif -- cgit v1.2.3 From 87eb782496c71fe10ac829769a8c9762f5372e6f Mon Sep 17 00:00:00 2001 From: Yotam Barnoy Date: Mon, 24 May 2010 06:57:58 +0000 Subject: PSP: switched to the way SDL does things in the audio thread to get rid of clicking. PSP's thread is still more efficient. svn-id: r49175 --- backends/platform/psp/audio.cpp | 70 ++++++++++++-------------------------- backends/platform/psp/osys_psp.cpp | 2 +- 2 files changed, 22 insertions(+), 50 deletions(-) (limited to 'backends/platform') diff --git a/backends/platform/psp/audio.cpp b/backends/platform/psp/audio.cpp index 58b2251811..2afc62d450 100644 --- a/backends/platform/psp/audio.cpp +++ b/backends/platform/psp/audio.cpp @@ -23,7 +23,6 @@ * */ -#include #include #include @@ -80,7 +79,7 @@ bool PspAudio::open(uint32 freq, uint32 numOfChannels, uint32 numOfSamples, call _bufferSize = numOfSamples * numOfChannels * sizeof(uint16); // should be the right size to send the app _callback = callback; _userData = userData; - _emptyBuffers = NUM_BUFFERS; + _emptyBuffers = NUM_BUFFERS - 1; // because we'll increase in the beginning _bufferToFill = 0; _bufferToPlay = 0; @@ -134,10 +133,10 @@ void PspAudio::audioThread() { if (_paused) PSP_DEBUG_PRINT("audio thread paused\n"); while (_paused) { // delay until we stop pausing - SDL_Delay(100); + sceKernelDelayThread(100000); // 100ms + if (!_paused) + PSP_DEBUG_PRINT("audio thread unpaused\n"); } - if (!_paused) - PSP_DEBUG_PRINT("audio thread unpaused\n"); // check if the audio is playing remainingSamples = sceAudioGetChannelRestLen(_pspChannel); @@ -148,49 +147,22 @@ void PspAudio::audioThread() { isPlaying = remainingSamples ? true : false; PSP_DEBUG_PRINT("remaining samples[%d]\n", remainingSamples); + + if (!isPlaying) { + _emptyBuffers++; + } + + while (_emptyBuffers) { // we have some empty buffers + PSP_DEBUG_PRINT("filling buffer[%d]. empty buffers[%d]\n", _bufferToFill, _emptyBuffers); + _callback(_userData, _buffers[_bufferToFill], _bufferSize); // ask mixer to fill in + nextBuffer(_bufferToFill); + _emptyBuffers--; + break; + } - while (true) { // really only execute once. this just helps write the logic - if (isPlaying) { - _stoppedPlayingOnceFlag = false; - - // check if a buffer is empty - if (_emptyBuffers) { // we have some empty buffers - PSP_DEBUG_PRINT("sound playing & an empty buffer. filling buffer[%d]. empty buffers[%d]\n", _bufferToFill, _emptyBuffers); - _callback(_userData, _buffers[_bufferToFill], _bufferSize); // ask mixer to fill in - nextBuffer(_bufferToFill); - _emptyBuffers--; - break; - } else { // we have no empty buffers - // calculate how long we need to sleep. time(us) = samples * 1000000 / freq - // since frequency is always 44100, we can do a shortcut: - // time(us) = samples * (10000 / 441) - uint32 sleepTime = (remainingSamples * 10000) / 441; - if (!sleepTime) - break; - PSP_DEBUG_PRINT("sound playing & no empty buffers. sleeping for %d samples for %dus\n", remainingSamples, sleepTime); - sceKernelDelayThread(sleepTime); - break; - } - } else { // we're not playing right now - if (_stoppedPlayingOnceFlag == false) { // we only want to do this when we finish playing - nextBuffer(_bufferToPlay); - _emptyBuffers++; - _stoppedPlayingOnceFlag = true; - } - - if (_emptyBuffers == NUM_BUFFERS) { // problem: we have only empty buffers! - PSP_DEBUG_PRINT("no sound playing & no full buffer. filling buffer[%d]. empty buffers[%d]\n", _bufferToFill, _emptyBuffers); - _callback(_userData, _buffers[_bufferToFill], _bufferSize); - nextBuffer(_bufferToFill); - _emptyBuffers--; - break; - } else { // we have at least one non-empty buffer - PSP_DEBUG_PRINT("no sound playing & a full buffer. playing buffer[%d]. empty buffers[%d]\n", _bufferToPlay, _emptyBuffers); - playBuffer(); - break; - } - } - } // while true + PSP_DEBUG_PRINT("playing buffer[%d]. empty buffers[%d]\n", _bufferToPlay, _emptyBuffers); + playBuffer(); + nextBuffer(_bufferToPlay); } // while _init // destroy everything @@ -212,9 +184,9 @@ inline bool PspAudio::playBuffer() { DEBUG_ENTER_FUNC(); int ret; if (_numOfChannels == 1) - ret = sceAudioOutput(_pspChannel, PSP_AUDIO_VOLUME_MAX, _buffers[_bufferToPlay]); + ret = sceAudioOutputBlocking(_pspChannel, PSP_AUDIO_VOLUME_MAX, _buffers[_bufferToPlay]); else - ret = sceAudioOutputPanned(_pspChannel, PSP_AUDIO_VOLUME_MAX, PSP_AUDIO_VOLUME_MAX, _buffers[_bufferToPlay]); + ret = sceAudioOutputPannedBlocking(_pspChannel, PSP_AUDIO_VOLUME_MAX, PSP_AUDIO_VOLUME_MAX, _buffers[_bufferToPlay]); if (ret < 0) { PSP_ERROR("failed to output audio. Error[%d]\n", ret); diff --git a/backends/platform/psp/osys_psp.cpp b/backends/platform/psp/osys_psp.cpp index d29196619b..f33081abbc 100644 --- a/backends/platform/psp/osys_psp.cpp +++ b/backends/platform/psp/osys_psp.cpp @@ -48,7 +48,7 @@ #include "backends/platform/psp/trace.h" -//#define USE_PSP_AUDIO +#define USE_PSP_AUDIO #define SAMPLES_PER_SEC 44100 -- cgit v1.2.3 From cfbf1a8a673295a621ee618be86bb7c42c531a8f Mon Sep 17 00:00:00 2001 From: Yotam Barnoy Date: Mon, 24 May 2010 09:19:40 +0000 Subject: PSP: turn off psp audio thread again. Must have tested it wrong. svn-id: r49178 --- backends/platform/psp/osys_psp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/platform') diff --git a/backends/platform/psp/osys_psp.cpp b/backends/platform/psp/osys_psp.cpp index f33081abbc..d29196619b 100644 --- a/backends/platform/psp/osys_psp.cpp +++ b/backends/platform/psp/osys_psp.cpp @@ -48,7 +48,7 @@ #include "backends/platform/psp/trace.h" -#define USE_PSP_AUDIO +//#define USE_PSP_AUDIO #define SAMPLES_PER_SEC 44100 -- cgit v1.2.3 From 55e29af78a52a13269d9905c6410e70f56b5920d Mon Sep 17 00:00:00 2001 From: Yotam Barnoy Date: Mon, 24 May 2010 11:41:45 +0000 Subject: PSP: switched to using slightly faster delay and getMillis svn-id: r49179 --- backends/platform/psp/Makefile | 3 ++- backends/platform/psp/module.mk | 3 ++- backends/platform/psp/osys_psp.cpp | 7 +++-- backends/platform/psp/thread.cpp | 52 ++++++++++++++++++++++++++++++++++++++ backends/platform/psp/thread.h | 10 ++++++++ 5 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 backends/platform/psp/thread.cpp (limited to 'backends/platform') diff --git a/backends/platform/psp/Makefile b/backends/platform/psp/Makefile index 6967973da7..7c33999b4d 100644 --- a/backends/platform/psp/Makefile +++ b/backends/platform/psp/Makefile @@ -148,7 +148,8 @@ OBJS := powerman.o \ trace.o \ psploader.o \ pspkeyboard.o \ - audio.o + audio.o \ + thread.o # Include common Scummvm makefile include $(srcdir)/Makefile.common diff --git a/backends/platform/psp/module.mk b/backends/platform/psp/module.mk index 0e5bd8737d..4d375bcef0 100644 --- a/backends/platform/psp/module.mk +++ b/backends/platform/psp/module.mk @@ -13,7 +13,8 @@ MODULE_OBJS := powerman.o \ trace.o \ psploader.o \ pspkeyboard.o \ - audio.o + audio.o \ + thread.o MODULE_DIRS += \ backends/platform/psp/ diff --git a/backends/platform/psp/osys_psp.cpp b/backends/platform/psp/osys_psp.cpp index d29196619b..ed7fb2d3cf 100644 --- a/backends/platform/psp/osys_psp.cpp +++ b/backends/platform/psp/osys_psp.cpp @@ -37,6 +37,7 @@ #include "backends/platform/psp/psppixelformat.h" #include "backends/platform/psp/osys_psp.h" #include "backends/platform/psp/powerman.h" +#include "backends/platform/psp/thread.h" #include "backends/saves/psp/psp-saves.h" #include "backends/timer/default/default-timer.h" @@ -298,17 +299,15 @@ bool OSystem_PSP::pollEvent(Common::Event &event) { return _inputHandler.getAllInputs(event); } - uint32 OSystem_PSP::getMillis() { - return SDL_GetTicks(); + return PspThread::getMillis(); } void OSystem_PSP::delayMillis(uint msecs) { - SDL_Delay(msecs); + PspThread::delayMillis(msecs); } void OSystem_PSP::setTimerCallback(TimerProc callback, int interval) { - //SDL_SetTimer(interval, (SDL_TimerCallback)callback); _pspTimer.setCallback((PspTimer::CallbackFunc)callback); _pspTimer.setIntervalMs(interval); _pspTimer.start(); diff --git a/backends/platform/psp/thread.cpp b/backends/platform/psp/thread.cpp new file mode 100644 index 0000000000..88e7b6fe38 --- /dev/null +++ b/backends/platform/psp/thread.cpp @@ -0,0 +1,52 @@ +/* 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. + * + * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/platform/psp/osys_psp.h $ + * $Id: osys_psp.h 49173 2010-05-24 03:05:17Z bluddy $ + * + */ + +#include +#include +#include +#include + +#include "backends/platform/psp/thread.h" + +void PspThread::delayMillis(uint32 ms) { + sceKernelDelayThread(ms * 1000); +} + +void PspThread::delayMicros(uint32 us) { + sceKernelDelayThread(us); +} + +uint32 PspThread::getMillis() { + uint32 ticks[2]; + sceRtcGetCurrentTick((u64 *)ticks); + return (ticks[0]/1000); +} + +uint32 PspThread::getMicros() { + uint32 ticks[2]; + sceRtcGetCurrentTick((u64 *)ticks); + return ticks[0]; +} + diff --git a/backends/platform/psp/thread.h b/backends/platform/psp/thread.h index d395d6713e..9ed3a2e2dc 100644 --- a/backends/platform/psp/thread.h +++ b/backends/platform/psp/thread.h @@ -26,6 +26,16 @@ #ifndef PSP_THREAD_H #define PSP_THREAD_H +#include "common/scummsys.h" + +class PspThread { +public: + static void delayMillis(uint32 ms); + static void delayMicros(uint32 us); + static uint32 getMillis(); + static uint32 getMicros(); +}; + enum ThreadPriority { PRIORITY_MAIN_THREAD = 36, PRIORITY_AUDIO_THREAD = 35, // We'll alternate between this and main thread priority -- cgit v1.2.3 From 1caf98700b7319719f6db062f7409ea9dc9caa57 Mon Sep 17 00:00:00 2001 From: Yotam Barnoy Date: Mon, 24 May 2010 18:20:16 +0000 Subject: PSP: to fix the audio, I cleaned up the audio thread and changed the thread priorities. svn-id: r49200 --- backends/platform/psp/audio.cpp | 30 +++++------------------------- backends/platform/psp/audio.h | 6 ++---- backends/platform/psp/osys_psp.cpp | 2 +- backends/platform/psp/thread.h | 8 ++++---- 4 files changed, 12 insertions(+), 34 deletions(-) (limited to 'backends/platform') diff --git a/backends/platform/psp/audio.cpp b/backends/platform/psp/audio.cpp index 2afc62d450..bf1fb9ab41 100644 --- a/backends/platform/psp/audio.cpp +++ b/backends/platform/psp/audio.cpp @@ -79,7 +79,6 @@ bool PspAudio::open(uint32 freq, uint32 numOfChannels, uint32 numOfSamples, call _bufferSize = numOfSamples * numOfChannels * sizeof(uint16); // should be the right size to send the app _callback = callback; _userData = userData; - _emptyBuffers = NUM_BUFFERS - 1; // because we'll increase in the beginning _bufferToFill = 0; _bufferToPlay = 0; @@ -122,10 +121,7 @@ int PspAudio::thread(SceSize, void *__this) { }; // The real thread function -void PspAudio::audioThread() { - bool isPlaying = false; - int remainingSamples = 0; - +void PspAudio::audioThread() { assert(_callback); PSP_DEBUG_PRINT_FUNC("audio thread started\n"); @@ -138,29 +134,13 @@ void PspAudio::audioThread() { PSP_DEBUG_PRINT("audio thread unpaused\n"); } - // check if the audio is playing - remainingSamples = sceAudioGetChannelRestLen(_pspChannel); - if (remainingSamples < 0) { - PSP_ERROR("failed to get remaining samples\n"); - return; - } - isPlaying = remainingSamples ? true : false; - PSP_DEBUG_PRINT("remaining samples[%d]\n", remainingSamples); - if (!isPlaying) { - _emptyBuffers++; - } - - while (_emptyBuffers) { // we have some empty buffers - PSP_DEBUG_PRINT("filling buffer[%d]. empty buffers[%d]\n", _bufferToFill, _emptyBuffers); - _callback(_userData, _buffers[_bufferToFill], _bufferSize); // ask mixer to fill in - nextBuffer(_bufferToFill); - _emptyBuffers--; - break; - } + PSP_DEBUG_PRINT("filling buffer[%d]\n", _bufferToFill); + _callback(_userData, _buffers[_bufferToFill], _bufferSize); // ask mixer to fill in + nextBuffer(_bufferToFill); - PSP_DEBUG_PRINT("playing buffer[%d]. empty buffers[%d]\n", _bufferToPlay, _emptyBuffers); + PSP_DEBUG_PRINT("playing buffer[%d].\n", _bufferToPlay); playBuffer(); nextBuffer(_bufferToPlay); } // while _init diff --git a/backends/platform/psp/audio.h b/backends/platform/psp/audio.h index 97e2391319..603f8f6bfc 100644 --- a/backends/platform/psp/audio.h +++ b/backends/platform/psp/audio.h @@ -35,8 +35,8 @@ public: typedef void (* callbackFunc)(void *userData, byte *samples, int len); PspAudio() : _pspChannel(0), _numOfChannels(0), _numOfSamples(0), _callback(0), - _bufferToPlay(0), _bufferToFill(0), _emptyBuffers(NUM_BUFFERS), - _init(false), _paused(true), _stoppedPlayingOnceFlag(true) { + _bufferToPlay(0), _bufferToFill(0), + _init(false), _paused(true) { for (int i=0; i> 1 : 0; uint32 gapY = _useGlobalScaler ? (PSP_SCREEN_HEIGHT - outputHeight) >> 1 : 0; + // Save scaled offset on screen + float scaledOffsetOnScreenX = scaleSourceToOutputX(_offsetOnScreen.x); + float scaledOffsetOnScreenY = scaleSourceToOutputY(_offsetOnScreen.y); + float imageStartX, imageStartY, imageEndX, imageEndY; - imageStartX = gapX + (scaleSourceToOutputX(_maxTextureOffset.x)); - imageStartY = gapY; - - imageStartX += scaleSourceToOutputX(_offsetOnScreen.x); - imageStartY += scaleSourceToOutputY(_offsetOnScreen.y); + imageStartX = gapX + scaledOffsetOnScreenX + (scaleSourceToOutputX(_maxTextureOffset.x)); + imageStartY = gapY + scaledOffsetOnScreenY; if (_fullScreen) { // shortcut - imageEndX = PSP_SCREEN_WIDTH - gapX; - imageEndY = PSP_SCREEN_HEIGHT - gapY; + imageEndX = PSP_SCREEN_WIDTH - gapX + scaledOffsetOnScreenX; + imageEndY = PSP_SCREEN_HEIGHT - gapY + scaledOffsetOnScreenY; // needed for screen shake } else { /* !fullScreen */ imageEndX = imageStartX + scaleSourceToOutputX(_drawSize.width); imageEndY = imageStartY + scaleSourceToOutputY(_drawSize.height); -- cgit v1.2.3 From 1c32db1e084698f6594a66e142c217e83cab60d9 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Sat, 29 May 2010 08:09:47 +0000 Subject: Removed some unused variables, found by cppcheck. svn-id: r49306 --- backends/platform/gp2x/graphics.cpp | 5 ----- backends/platform/gp2xwiz/gp2xwiz-graphics.cpp | 5 ----- backends/platform/linuxmoto/linuxmoto-graphics.cpp | 5 ----- backends/platform/sdl/graphics.cpp | 5 ----- 4 files changed, 20 deletions(-) (limited to 'backends/platform') diff --git a/backends/platform/gp2x/graphics.cpp b/backends/platform/gp2x/graphics.cpp index 243c37dcb1..449e744e8b 100644 --- a/backends/platform/gp2x/graphics.cpp +++ b/backends/platform/gp2x/graphics.cpp @@ -1502,7 +1502,6 @@ void OSystem_GP2X::drawMouse() { SDL_Rect zoomdst; SDL_Rect dst; int scale; - int width, height; int hotX, hotY; int tmpScreenWidth, tmpScreenHeight; @@ -1523,16 +1522,12 @@ void OSystem_GP2X::drawMouse() { if (!_overlayVisible) { scale = _videoMode.scaleFactor; - width = _videoMode.screenWidth; - height = _videoMode.screenHeight; dst.w = _mouseCurState.vW; dst.h = _mouseCurState.vH; hotX = _mouseCurState.vHotX; hotY = _mouseCurState.vHotY; } else { scale = 1; - width = _videoMode.overlayWidth; - height = _videoMode.overlayHeight; dst.w = _mouseCurState.rW; dst.h = _mouseCurState.rH; hotX = _mouseCurState.rHotX; diff --git a/backends/platform/gp2xwiz/gp2xwiz-graphics.cpp b/backends/platform/gp2xwiz/gp2xwiz-graphics.cpp index b20087e6d9..28c03db4b0 100644 --- a/backends/platform/gp2xwiz/gp2xwiz-graphics.cpp +++ b/backends/platform/gp2xwiz/gp2xwiz-graphics.cpp @@ -154,7 +154,6 @@ void OSystem_GP2XWIZ::drawMouse() { SDL_Rect dst; int scale; - int width, height; int hotX, hotY; if (_videoMode.mode == GFX_HALF && !_overlayVisible){ @@ -167,16 +166,12 @@ void OSystem_GP2XWIZ::drawMouse() { if (!_overlayVisible) { scale = _videoMode.scaleFactor; - width = _videoMode.screenWidth; - height = _videoMode.screenHeight; dst.w = _mouseCurState.vW; dst.h = _mouseCurState.vH; hotX = _mouseCurState.vHotX; hotY = _mouseCurState.vHotY; } else { scale = 1; - width = _videoMode.overlayWidth; - height = _videoMode.overlayHeight; dst.w = _mouseCurState.rW; dst.h = _mouseCurState.rH; hotX = _mouseCurState.rHotX; diff --git a/backends/platform/linuxmoto/linuxmoto-graphics.cpp b/backends/platform/linuxmoto/linuxmoto-graphics.cpp index 8f718c82f6..482ed772c7 100644 --- a/backends/platform/linuxmoto/linuxmoto-graphics.cpp +++ b/backends/platform/linuxmoto/linuxmoto-graphics.cpp @@ -173,7 +173,6 @@ void OSystem_LINUXMOTO::drawMouse() { SDL_Rect dst; int scale; - int width, height; int hotX, hotY; if (_videoMode.mode == GFX_HALF && !_overlayVisible) { @@ -186,16 +185,12 @@ void OSystem_LINUXMOTO::drawMouse() { if (!_overlayVisible) { scale = _videoMode.scaleFactor; - width = _videoMode.screenWidth; - height = _videoMode.screenHeight; dst.w = _mouseCurState.vW; dst.h = _mouseCurState.vH; hotX = _mouseCurState.vHotX; hotY = _mouseCurState.vHotY; } else { scale = 1; - width = _videoMode.overlayWidth; - height = _videoMode.overlayHeight; dst.w = _mouseCurState.rW; dst.h = _mouseCurState.rH; hotX = _mouseCurState.rHotX; diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index b3ef101e9e..e0bf7565fb 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -1771,7 +1771,6 @@ void OSystem_SDL::drawMouse() { SDL_Rect dst; int scale; - int width, height; int hotX, hotY; dst.x = _mouseCurState.x; @@ -1779,16 +1778,12 @@ void OSystem_SDL::drawMouse() { if (!_overlayVisible) { scale = _videoMode.scaleFactor; - width = _videoMode.screenWidth; - height = _videoMode.screenHeight; dst.w = _mouseCurState.vW; dst.h = _mouseCurState.vH; hotX = _mouseCurState.vHotX; hotY = _mouseCurState.vHotY; } else { scale = 1; - width = _videoMode.overlayWidth; - height = _videoMode.overlayHeight; dst.w = _mouseCurState.rW; dst.h = _mouseCurState.rH; hotX = _mouseCurState.rHotX; -- cgit v1.2.3 From 989c1fddddbe63075a9d4b9860476a080711164c Mon Sep 17 00:00:00 2001 From: Neil Millstone Date: Sat, 29 May 2010 20:30:54 +0000 Subject: DS: Various fixes to allow the DS port to compile on DevkitARM r30 and libnds 1.4.3. svn-id: r49313 --- backends/platform/ds/arm7/source/main.cpp | 4 ++-- backends/platform/ds/arm9/makefile | 2 +- backends/platform/ds/arm9/source/dsmain.cpp | 4 ++-- backends/platform/ds/commoninclude/NDS/scummvm_ipc.h | 12 ++++++++++++ 4 files changed, 17 insertions(+), 5 deletions(-) (limited to 'backends/platform') diff --git a/backends/platform/ds/arm7/source/main.cpp b/backends/platform/ds/arm7/source/main.cpp index 7029d96405..a4cde02ba6 100644 --- a/backends/platform/ds/arm7/source/main.cpp +++ b/backends/platform/ds/arm7/source/main.cpp @@ -38,7 +38,7 @@ #include #include #include -//#include // not needed in current libnds +#include // Needed for SOUND_CR #include ////////////////////////////////////////////////////////////////////// #ifdef USE_DEBUGGER @@ -590,7 +590,7 @@ int main(int argc, char ** argv) { IPC->reset = false; - fifoInit(); + //fifoInit(); for (int r = 0; r < 8; r++) { IPC->adpcm.arm7Buffer[r] = (u8 *) malloc(512); diff --git a/backends/platform/ds/arm9/makefile b/backends/platform/ds/arm9/makefile index eca170ef96..7f03f4c310 100644 --- a/backends/platform/ds/arm9/makefile +++ b/backends/platform/ds/arm9/makefile @@ -75,7 +75,7 @@ else ifdef DS_BUILD_K else - USE_MAD = 1 + # USE_MAD = 1 endif endif endif diff --git a/backends/platform/ds/arm9/source/dsmain.cpp b/backends/platform/ds/arm9/source/dsmain.cpp index 1e9986e4e9..4828ae2192 100644 --- a/backends/platform/ds/arm9/source/dsmain.cpp +++ b/backends/platform/ds/arm9/source/dsmain.cpp @@ -701,7 +701,7 @@ void displayMode8Bit() { - consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 2, 0, true); + consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 2, 0, true, true); // Set this again because consoleinit resets it videoSetMode(MODE_5_2D | (consoleEnable? DISPLAY_BG0_ACTIVE: 0) | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP); @@ -939,7 +939,7 @@ void displayMode16Bit() { SUB_BG0_CR = BG_MAP_BASE(4) | BG_TILE_BASE(0); SUB_BG0_Y0 = 0; - consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 4, 0, false); + consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 4, 0, false, true); // consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(4), (u16*)CHAR_BASE_BLOCK_SUB(0), 16); for (int r = 0; r < 32 * 32; r++) { diff --git a/backends/platform/ds/commoninclude/NDS/scummvm_ipc.h b/backends/platform/ds/commoninclude/NDS/scummvm_ipc.h index 9344be68f9..f41548f400 100644 --- a/backends/platform/ds/commoninclude/NDS/scummvm_ipc.h +++ b/backends/platform/ds/commoninclude/NDS/scummvm_ipc.h @@ -33,6 +33,18 @@ ////////////////////////////////////////////////////////////////////// +typedef struct sTransferSoundData { +//--------------------------------------------------------------------------------- + const void *data; + u32 len; + u32 rate; + u8 vol; + u8 pan; + u8 format; + u8 PADDING; +} TransferSoundData, * pTransferSoundData; + + //--------------------------------------------------------------------------------- -- cgit v1.2.3 From 6884ffc2918d192c9b091d4836f8c566ef3a7fcb Mon Sep 17 00:00:00 2001 From: Yotam Barnoy Date: Sun, 30 May 2010 09:47:00 +0000 Subject: PSP: added preliminary support for using ME hardware to play MP3 files. If the decoder fails to load, MAD is used instead. Disable with DISABLE_PSP_MP3. svn-id: r49319 --- backends/platform/psp/Makefile | 6 +- backends/platform/psp/module.mk | 3 +- backends/platform/psp/mp3.cpp | 487 ++++++++++++++++++++++++++++++++++++++++ backends/platform/psp/mp3.h | 121 ++++++++++ backends/platform/psp/psp.spec | 2 +- 5 files changed, 615 insertions(+), 4 deletions(-) create mode 100644 backends/platform/psp/mp3.cpp create mode 100644 backends/platform/psp/mp3.h (limited to 'backends/platform') diff --git a/backends/platform/psp/Makefile b/backends/platform/psp/Makefile index 7c33999b4d..7f8bb63b0a 100644 --- a/backends/platform/psp/Makefile +++ b/backends/platform/psp/Makefile @@ -129,7 +129,8 @@ SDLFLAGS := $(shell $(PSPBIN)/sdl-config --cflags) SDLLIBS := $(shell $(PSPBIN)/sdl-config --libs) # PSP LIBS PSPLIBS = -lpspprof -lpspvfpu -lpspdebug -lpspgu -lpspge -lpspdisplay -lpspctrl -lpspsdk \ - -lpsputility -lpspuser -lpsppower -lpsphprm -lpspsdk -lpsprtc -lpspaudio -lpspkernel + -lpsputility -lpspuser -lpsppower -lpsphprm -lpspsdk -lpsprtc -lpspaudio -lpspaudiocodec \ + -lpspkernel # Add in PSPSDK includes and libraries. CXXFLAGS += $(SDLFLAGS) @@ -149,7 +150,8 @@ OBJS := powerman.o \ psploader.o \ pspkeyboard.o \ audio.o \ - thread.o + thread.o \ + mp3.o # Include common Scummvm makefile include $(srcdir)/Makefile.common diff --git a/backends/platform/psp/module.mk b/backends/platform/psp/module.mk index 4d375bcef0..99170ce7fb 100644 --- a/backends/platform/psp/module.mk +++ b/backends/platform/psp/module.mk @@ -14,7 +14,8 @@ MODULE_OBJS := powerman.o \ psploader.o \ pspkeyboard.o \ audio.o \ - thread.o + thread.o \ + mp3.o MODULE_DIRS += \ backends/platform/psp/ diff --git a/backends/platform/psp/mp3.cpp b/backends/platform/psp/mp3.cpp new file mode 100644 index 0000000000..972c5a8ba8 --- /dev/null +++ b/backends/platform/psp/mp3.cpp @@ -0,0 +1,487 @@ +/* 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. + * + * $URL$ + * $Id$ + * + */ + + +#include "common/debug.h" +#include "common/stream.h" +#include "common/util.h" +#include "common/singleton.h" +#include "common/mutex.h" + +#include "sound/audiostream.h" + +#include +#include +#include +#include +#include +#include +#include +#include "backends/platform/psp/mp3.h" + +//#define DISABLE_PSP_MP3 // to make us use the regular MAD decoder instead + +//#define __PSP_DEBUG_FUNCS__ /* For debugging the stack */ +//#define __PSP_DEBUG_PRINT__ +#include "backends/platform/psp/trace.h" + +//#define PRINT_BUFFERS /* to debug MP3 buffers */ + +namespace Audio { + +class Mp3PspStream; + +bool Mp3PspStream::_decoderInit = false; // has the decoder been initialized +#ifdef DISABLE_PSP_MP3 +bool Mp3PspStream::_decoderFail = true; // pretend the decoder failed +#else +bool Mp3PspStream::_decoderFail = false; // has the decoder failed to load +#endif + +bool Mp3PspStream::initDecoder() { + DEBUG_ENTER_FUNC(); + + if (_decoderInit) { + PSP_ERROR("Already initialized!"); + return true; + } + + // Based on PSP firmware version, we need to do different things to do Media Engine processing + uint32 firmware = sceKernelDevkitVersion(); + PSP_DEBUG_PRINT("Firmware version 0x%x\n", firmware); + if (firmware == 0x01050001){ + if (!loadStartAudioModule((char *)(void *)"flash0:/kd/me_for_vsh.prx", + PSP_MEMORY_PARTITION_KERNEL)) { + PSP_ERROR("failed to load me_for_vsh.prx. ME cannot start.\n"); + _decoderFail = true; + return false; + } + if (!loadStartAudioModule((char *)(void *)"flash0:/kd/audiocodec.prx", PSP_MEMORY_PARTITION_KERNEL)) { + PSP_ERROR("failed to load audiocodec.prx. ME cannot start.\n"); + _decoderFail = true; + return false; + } + } else { + if (sceUtilityLoadAvModule(PSP_AV_MODULE_AVCODEC) < 0) { + PSP_ERROR("failed to load AVCODEC module.\n"); + _decoderFail = true; + return false; + } + } + + PSP_INFO_PRINT("Using PSP's ME for MP3\n"); // important to know this is happening + + _decoderInit = true; + return true; +} + +bool Mp3PspStream::stopDecoder() { + DEBUG_ENTER_FUNC(); + + if (!_decoderInit) + return true; + + // Based on PSP firmware version, we need to do different things to do Media Engine processing + if (sceKernelDevkitVersion() == 0x01050001){ +/* if (!unloadAudioModule("flash0:/kd/me_for_vsh.prx", PSP_MEMORY_PARTITION_KERNEL) || + !unloadAudioModule("flash0:/kd/audiocodec.prx", PSP_MEMORY_PARTITION_KERNEL) { + PSP_ERROR("failed to unload audio module\n"); + return false; + } +*/ + }else{ + if (sceUtilityUnloadModule(PSP_MODULE_AV_AVCODEC) < 0) { + PSP_ERROR("failed to unload avcodec module\n"); + return false; + } + } + + _decoderInit = false; + return true; +} + +//Load a PSP audio module +bool Mp3PspStream::loadStartAudioModule(const char *modname, int partition){ + DEBUG_ENTER_FUNC(); + + SceKernelLMOption option; + SceUID modid; + + memset(&option, 0, sizeof(option)); + option.size = sizeof(option); + option.mpidtext = partition; + option.mpiddata = partition; + option.position = 0; + option.access = 1; + + modid = sceKernelLoadModule(modname, 0, &option); + if (modid < 0) { + PSP_ERROR("Failed to load module %s. Got error 0x%x\n", modname, modid); + return false; + } + + int ret = sceKernelStartModule(modid, 0, NULL, NULL, NULL); + if (ret < 0) { + PSP_ERROR("Failed to start module %s. Got error 0x%x\n", modname, ret); + return false; + } + return true; +} + +// TODO: make parallel function for unloading the 1.50 modules + +Mp3PspStream::Mp3PspStream(Common::SeekableReadStream *inStream, DisposeAfterUse::Flag dispose) : + _inStream(inStream), + _disposeAfterUse(dispose), + _pcmLength(0), + _posInFrame(0), + _state(MP3_STATE_INIT), + _length(0, 1000), + _sampleRate(0), + _totalTime(mad_timer_zero) { + + DEBUG_ENTER_FUNC(); + + assert(_decoderInit); // must be initialized by now + + // let's leave the buffer guard -- who knows, it may be good? + memset(_buf, 0, sizeof(_buf)); + memset(_codecInBuffer, 0, sizeof(_codecInBuffer)); + + initStream(); // init needed stuff for the stream + + while (_state != MP3_STATE_EOS) + findValidHeader(); // get a first header so we can read basic stuff + + _sampleRate = _header.samplerate; // copy it before it gets destroyed + + _length = Timestamp(mad_timer_count(_totalTime, MAD_UNITS_MILLISECONDS), getRate()); + + //initStreamME(); // init the stuff needed for the ME to work + + deinitStream(); + //releaseStreamME(); + + _state = MP3_STATE_INIT; +} + +int Mp3PspStream::initStream() { + DEBUG_ENTER_FUNC(); + + if (_state != MP3_STATE_INIT) + deinitStream(); + + // Init MAD + mad_stream_init(&_stream); + mad_header_init(&_header); + + // Reset the stream data + _inStream->seek(0, SEEK_SET); + _totalTime = mad_timer_zero; + _posInFrame = 0; + + // Update state + _state = MP3_STATE_READY; + + // Read the first few sample bytes into the buffer + readMP3DataIntoBuffer(); + + return true; +} + +bool Mp3PspStream::initStreamME() { + // The following will eventually go into the thread + sceAudiocodecReleaseEDRAM(_codecParams); // do we need this? + + memset(_codecParams, 0, sizeof(_codecParams)); + + // Init the MP3 hardware + int ret = 0; + ret = sceAudiocodecCheckNeedMem(_codecParams, 0x1002); + if (ret < 0) { + PSP_ERROR("failed to init MP3 ME module. sceAudiocodecCheckNeedMem returned 0x%x.\n", ret); + return false; + } + PSP_DEBUG_PRINT("sceAudiocodecCheckNeedMem returned %d\n", ret); + ret = sceAudiocodecGetEDRAM(_codecParams, 0x1002); + if (ret < 0) { + PSP_ERROR("failed to init MP3 ME module. sceAudiocodecGetEDRAM returned 0x%x.\n", ret); + return false; + } + PSP_DEBUG_PRINT("sceAudioCodecGetEDRAM returned %d\n", ret); + + PSP_DEBUG_PRINT("samplerate[%d]\n", _sampleRate); + _codecParams[10] = _sampleRate; + + ret = sceAudiocodecInit(_codecParams, 0x1002); + if (ret < 0) { + PSP_ERROR("failed to init MP3 ME module. sceAudiocodecInit returned 0x%x.\n", ret); + return false; + } + + return true; +} + +Mp3PspStream::~Mp3PspStream() { + DEBUG_ENTER_FUNC(); + + deinitStream(); + releaseStreamME(); // free the memory used for this stream + + if (_disposeAfterUse == DisposeAfterUse::YES) + delete _inStream; +} + +void Mp3PspStream::deinitStream() { + DEBUG_ENTER_FUNC(); + + if (_state == MP3_STATE_INIT) + return; + + // Deinit MAD + mad_header_finish(&_header); + mad_stream_finish(&_stream); + + _state = MP3_STATE_EOS; +} + +void Mp3PspStream::releaseStreamME() { + sceAudiocodecReleaseEDRAM(_codecParams); +} + +void Mp3PspStream::decodeMP3Data() { + DEBUG_ENTER_FUNC(); + + do { + if (_state == MP3_STATE_INIT) { + initStream(); + initStreamME(); + } + + if (_state == MP3_STATE_EOS) + return; + + findValidHeader(); // seach for next valid header + + while (_state == MP3_STATE_READY) { + _stream.error = MAD_ERROR_NONE; + + uint32 frame_size = _stream.next_frame - _stream.this_frame; + uint32 samplesPerFrame = _header.layer == MAD_LAYER_III ? 576 : 1152; // Varies by layer + // calculate frame size -- try + //uint32 calc_frame_size = ((144 * _header.bitrate) / 22050) + (_header.flags & MAD_FLAG_PADDING ? 1 : 0); + + // Get stereo/mono + uint32 multFactor = 1; + if (_header.mode != MAD_MODE_SINGLE_CHANNEL) // mono - x2 for 16bit + multFactor *= 2; // stereo - x4 for 16bit + + PSP_DEBUG_PRINT("MP3 frame size[%d]. Samples[%d]. Multfactor[%d] pad[%d]\n", frame_size, samplesPerFrame, multFactor, _header.flags & MAD_FLAG_PADDING); + memcpy(_codecInBuffer, _stream.this_frame, frame_size); // we need it aligned + + // set up parameters for ME + _codecParams[6] = (unsigned long)_codecInBuffer; + _codecParams[8] = (unsigned long)_pcmSamples; + _codecParams[7] = frame_size; + _codecParams[9] = samplesPerFrame * multFactor; // x2 for stereo + + // debug +#ifdef PRINT_BUFFERS + PSP_DEBUG_PRINT("mp3 frame:\n"); + for (int i=0; i < (int)frame_size; i++) { + PSP_DEBUG_PRINT_SAMELN("%x ", _codecInBuffer[i]); + } + PSP_DEBUG_PRINT("\n"); +#endif + // Decode the next frame + // This function blocks. We'll want to put it in a thread + int ret = sceAudiocodecDecode(_codecParams, 0x1002); + if (ret < 0) { + PSP_ERROR("failed to decode MP3 data in ME. sceAudiocodecDecode returned 0x%x\n", ret); + // handle error here + } + +#ifdef PRINT_BUFFERS + PSP_DEBUG_PRINT("PCM frame:\n"); + for (int i=0; i < (int)_codecParams[9]; i+=2) { // changed from i+=2 + PSP_DEBUG_PRINT_SAMELN("%d ", (int16)_pcmSamples[i]); + } + PSP_DEBUG_PRINT("\n"); +#endif + _pcmLength = samplesPerFrame; + _posInFrame = 0; + break; + } + } while (_state != MP3_STATE_EOS && _stream.error == MAD_ERROR_BUFLEN); + + if (_stream.error != MAD_ERROR_NONE) // catch EOS + _state = MP3_STATE_EOS; +} + +void Mp3PspStream::readMP3DataIntoBuffer() { + DEBUG_ENTER_FUNC(); + + uint32 remaining = 0; + + // Give up immediately if we already used up all data in the stream + if (_inStream->eos()) { + _state = MP3_STATE_EOS; + return; + } + + if (_stream.next_frame) { + // If there is still data in the MAD stream, we need to preserve it. + // Note that we use memmove, as we are reusing the same buffer, + // and hence the data regions we copy from and to may overlap. + remaining = _stream.bufend - _stream.next_frame; + assert(remaining < BUFFER_SIZE); // Paranoia check + memmove(_buf, _stream.next_frame, remaining); // TODO: may want another buffer + } + + // Try to read the next block + uint32 size = _inStream->read(_buf + remaining, BUFFER_SIZE - remaining); + if (size <= 0) { + _state = MP3_STATE_EOS; + return; + } + + // Feed the data we just read into the stream decoder + _stream.error = MAD_ERROR_NONE; + mad_stream_buffer(&_stream, _buf, size + remaining); // just setup the pointers +} + +bool Mp3PspStream::seek(const Timestamp &where) { + DEBUG_ENTER_FUNC(); + + if (where == _length) { + _state = MP3_STATE_EOS; + return true; + } else if (where > _length) { + return false; + } + + const uint32 time = where.msecs(); + + mad_timer_t destination; + mad_timer_set(&destination, time / 1000, time % 1000, 1000); + + // Check if we need to rewind + if (_state != MP3_STATE_READY || mad_timer_compare(destination, _totalTime) < 0) { + initStream(); + initStreamME(); + } + + // The ME will need clear data no matter what once we seek? + //if (mad_timer_compare(destination, _totalTime) > 0 && _state != MP3_STATE_EOS) + // initStreamME(); + + // Skip ahead + while (mad_timer_compare(destination, _totalTime) > 0 && _state != MP3_STATE_EOS) + findValidHeader(); + + return (_state != MP3_STATE_EOS); +} + +// Seek in the stream, finding the next valid header +void Mp3PspStream::findValidHeader() { + DEBUG_ENTER_FUNC(); + + if (_state != MP3_STATE_READY) + return; + + // If necessary, load more data into the stream decoder + if (_stream.error == MAD_ERROR_BUFLEN) + readMP3DataIntoBuffer(); + + while (_state != MP3_STATE_EOS) { + _stream.error = MAD_ERROR_NONE; + + // Decode the next header. + if (mad_header_decode(&_header, &_stream) == -1) { + if (_stream.error == MAD_ERROR_BUFLEN) { + readMP3DataIntoBuffer(); // Read more data + continue; + } else if (MAD_RECOVERABLE(_stream.error)) { + debug(6, "MP3PSPStream: Recoverable error in mad_header_decode (%s)", mad_stream_errorstr(&_stream)); + continue; + } else { + warning("MP3PSPStream: Unrecoverable error in mad_header_decode (%s)", mad_stream_errorstr(&_stream)); + break; + } + } + + // Sum up the total playback time so far + mad_timer_add(&_totalTime, _header.duration); + break; + } + + if (_stream.error != MAD_ERROR_NONE) + _state = MP3_STATE_EOS; +} + +int Mp3PspStream::readBuffer(int16 *buffer, const int numSamples) { + DEBUG_ENTER_FUNC(); + + int samples = 0; +#ifdef PRINT_BUFFERS + int16 *debugBuffer = buffer; +#endif + + // Keep going as long as we have input available + while (samples < numSamples && _state != MP3_STATE_EOS) { + const int len = MIN(numSamples, samples + (int)(_pcmLength - _posInFrame) * MAD_NCHANNELS(&_header)); + + while (samples < len) { + *buffer++ = _pcmSamples[_posInFrame << 1]; + samples++; + if (MAD_NCHANNELS(&_header) == 2) { + *buffer++ = _pcmSamples[(_posInFrame << 1) + 1]; + samples++; + } + _posInFrame++; // always skip an extra sample since ME always outputs stereo + } + + //memcpy(buffer, &_pcmSamples[_posInFrame], len << 1); // 16 bits + //_posInFrame += len; // next time we start from the middle + + if (_posInFrame >= _pcmLength) { + // We used up all PCM data in the current frame -- read & decode more + decodeMP3Data(); + } + } + +#ifdef PRINT_BUFFERS + PSP_INFO_PRINT("buffer:\n"); + for (int i = 0; i What's New? ------------------------------------------------------------------------ +ScummVM DS 1.1.1 + + * Bugfix release: no new features + ScummVM DS 1.1.0 * New games are supported in this stable build: Return to Zork, Rodney's @@ -319,7 +323,7 @@ CANNOT DO THIS. ------------------------------------------------------------------------ I'm glad you asked. Here is a list of the compatible games in version -1.1.0. Demo versions of the games listed should work too. +1.1.1. Demo versions of the games listed should work too. Flight of the Amazon Queen, Beneath a Steel Sky, and Lure of the Temptress have generously been released as freeware by the original diff --git a/backends/platform/ds/arm9/source/dsmain.cpp b/backends/platform/ds/arm9/source/dsmain.cpp index 4828ae2192..5a63e5f08f 100644 --- a/backends/platform/ds/arm9/source/dsmain.cpp +++ b/backends/platform/ds/arm9/source/dsmain.cpp @@ -103,6 +103,7 @@ #include "profiler/cyg-profile.h" #endif #include "backends/fs/ds/ds-fs.h" +#include "base/version.h" #include "engine.h" extern "C" void OurIntrMain(void); @@ -3162,7 +3163,7 @@ int main(void) { consolePrintf("-------------------------------\n"); consolePrintf("ScummVM DS\n"); consolePrintf("Ported by Neil Millstone\n"); - consolePrintf("Version 1.1.0 "); + consolePrintf("Version %s ", gScummVMVersion); #if defined(DS_BUILD_A) consolePrintf("build A\n"); consolePrintf("Lucasarts SCUMM games (SCUMM)\n"); -- cgit v1.2.3 From c9a38abf605197c4641b74fcef06d44d8d87b2d7 Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Mon, 31 May 2010 22:41:46 +0000 Subject: modifications to get the ps2 to use the ps2loader svn-id: r49363 --- backends/platform/ps2/module.mk | 3 ++- backends/platform/ps2/systemps2.cpp | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'backends/platform') diff --git a/backends/platform/ps2/module.mk b/backends/platform/ps2/module.mk index 86b12cb668..69a28b93c4 100644 --- a/backends/platform/ps2/module.mk +++ b/backends/platform/ps2/module.mk @@ -16,7 +16,8 @@ MODULE_OBJS := \ systemps2.o \ ps2mutex.o \ ps2time.o \ - ps2debug.o + ps2debug.o \ + ps2loader.o MODULE_DIRS += \ backends/platform/ps2/ diff --git a/backends/platform/ps2/systemps2.cpp b/backends/platform/ps2/systemps2.cpp index 49d583d1a1..fe8cc6b29c 100644 --- a/backends/platform/ps2/systemps2.cpp +++ b/backends/platform/ps2/systemps2.cpp @@ -59,6 +59,7 @@ #include "backends/platform/ps2/ps2debug.h" #include "backends/fs/ps2/ps2-fs-factory.h" +#include "backends/plugins/ps2/ps2-provider.h" #include "backends/saves/default/default-saves.h" #include "common/config-manager.h" @@ -132,6 +133,10 @@ extern "C" int main(int argc, char *argv[]) { g_systemPs2->init(); +#ifdef DYNAMIC_MODULES + PluginManager::instance().addPluginProvider(new PS2PluginProvider()); +#endif + sioprintf("init done. starting ScummVM.\n"); int res = scummvm_main(argc, argv); sioprintf("scummvm_main terminated: %d\n", res); -- cgit v1.2.3 From 400542a1fe688bb702a89333c833bc1d89dd1ed4 Mon Sep 17 00:00:00 2001 From: Jordi Vilalta Prat Date: Mon, 31 May 2010 23:04:30 +0000 Subject: Revert the rest of 49362, which wasn't meant for trunk svn-id: r49366 --- backends/platform/ps2/module.mk | 3 +-- backends/platform/ps2/systemps2.cpp | 5 ----- 2 files changed, 1 insertion(+), 7 deletions(-) (limited to 'backends/platform') diff --git a/backends/platform/ps2/module.mk b/backends/platform/ps2/module.mk index 69a28b93c4..86b12cb668 100644 --- a/backends/platform/ps2/module.mk +++ b/backends/platform/ps2/module.mk @@ -16,8 +16,7 @@ MODULE_OBJS := \ systemps2.o \ ps2mutex.o \ ps2time.o \ - ps2debug.o \ - ps2loader.o + ps2debug.o MODULE_DIRS += \ backends/platform/ps2/ diff --git a/backends/platform/ps2/systemps2.cpp b/backends/platform/ps2/systemps2.cpp index fe8cc6b29c..49d583d1a1 100644 --- a/backends/platform/ps2/systemps2.cpp +++ b/backends/platform/ps2/systemps2.cpp @@ -59,7 +59,6 @@ #include "backends/platform/ps2/ps2debug.h" #include "backends/fs/ps2/ps2-fs-factory.h" -#include "backends/plugins/ps2/ps2-provider.h" #include "backends/saves/default/default-saves.h" #include "common/config-manager.h" @@ -133,10 +132,6 @@ extern "C" int main(int argc, char *argv[]) { g_systemPs2->init(); -#ifdef DYNAMIC_MODULES - PluginManager::instance().addPluginProvider(new PS2PluginProvider()); -#endif - sioprintf("init done. starting ScummVM.\n"); int res = scummvm_main(argc, argv); sioprintf("scummvm_main terminated: %d\n", res); -- cgit v1.2.3 From caf1a6bee4bb60014290a2208ec0daa0c68496cd Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 1 Jun 2010 15:38:09 +0000 Subject: Remove dead code from PS2 and GP2x backends svn-id: r49374 --- backends/platform/gp2x/gp2x-common.h | 18 ------------------ backends/platform/gp2x/gp2x.cpp | 25 +------------------------ backends/platform/ps2/systemps2.cpp | 17 ----------------- backends/platform/ps2/systemps2.h | 6 ------ 4 files changed, 1 insertion(+), 65 deletions(-) (limited to 'backends/platform') diff --git a/backends/platform/gp2x/gp2x-common.h b/backends/platform/gp2x/gp2x-common.h index 79eb3f65cf..9f3a79ff97 100644 --- a/backends/platform/gp2x/gp2x-common.h +++ b/backends/platform/gp2x/gp2x-common.h @@ -121,19 +121,6 @@ public: virtual Audio::Mixer *getMixer(); - // Poll CD status - // Returns true if cd audio is playing - bool pollCD(); - - // Play CD audio track - void playCD(int track, int num_loops, int start_frame, int duration); - - // Stop CD audio track - void stopCD(); - - // Update CD audio status - void updateCD(); - // Quit void quit(); @@ -206,11 +193,6 @@ protected: bool _overlayVisible; Graphics::PixelFormat _overlayFormat; - // CD Audio - SDL_CD *_cdrom; - int _cdTrack, _cdNumLoops, _cdStartFrame, _cdDuration; - uint32 _cdEndTime, _cdStopTime; - enum { DF_WANT_RECT_OPTIM = 1 << 0 }; diff --git a/backends/platform/gp2x/gp2x.cpp b/backends/platform/gp2x/gp2x.cpp index 3d4ed51c1f..8669671c4e 100644 --- a/backends/platform/gp2x/gp2x.cpp +++ b/backends/platform/gp2x/gp2x.cpp @@ -246,7 +246,7 @@ OSystem_GP2X::OSystem_GP2X() _hwscreen(0), _screen(0), _tmpscreen(0), _overlayVisible(false), _overlayscreen(0), _tmpscreen2(0), - _cdrom(0), _scalerProc(0), _modeChanged(false), _screenChangeCount(0), _dirtyChecksums(0), + _scalerProc(0), _modeChanged(false), _screenChangeCount(0), _dirtyChecksums(0), _mouseVisible(false), _mouseNeedsRedraw(false), _mouseData(0), _mouseSurface(0), _mouseOrigSurface(0), _cursorTargetScale(1), _cursorPaletteDisabled(true), _joystick(0), @@ -650,26 +650,3 @@ Audio::Mixer *OSystem_GP2X::getMixer() { assert(_mixer); return _mixer; } - -#pragma mark - -#pragma mark --- CD Audio --- -#pragma mark - - -bool OSystem_GP2X::openCD(int drive) { - return (_cdrom = NULL); -} - -void OSystem_GP2X::stopCD() { -} - -void OSystem_GP2X::playCD(int track, int num_loops, int start_frame, int duration) { - return; -} - -bool OSystem_GP2X::pollCD() { - return false; -} - -void OSystem_GP2X::updateCD() { - return; -} diff --git a/backends/platform/ps2/systemps2.cpp b/backends/platform/ps2/systemps2.cpp index 49d583d1a1..7659d5194d 100644 --- a/backends/platform/ps2/systemps2.cpp +++ b/backends/platform/ps2/systemps2.cpp @@ -624,23 +624,6 @@ void OSystem_PS2::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, _screen->setMouseOverlay(buf, w, h, hotspot_x, hotspot_y, keycolor); } -bool OSystem_PS2::openCD(int drive) { - return false; -} - -bool OSystem_PS2::pollCD(void) { - return false; -} - -void OSystem_PS2::playCD(int track, int num_loops, int start_frame, int duration) { -} - -void OSystem_PS2::stopCD(void) { -} - -void OSystem_PS2::updateCD(void) { -} - void OSystem_PS2::showOverlay(void) { _screen->showOverlay(); } diff --git a/backends/platform/ps2/systemps2.h b/backends/platform/ps2/systemps2.h index 0068ffd93f..78973ed3f0 100644 --- a/backends/platform/ps2/systemps2.h +++ b/backends/platform/ps2/systemps2.h @@ -97,12 +97,6 @@ public: virtual Audio::Mixer *getMixer(); - virtual bool openCD(int drive); - virtual bool pollCD(); - virtual void playCD(int track, int num_loops, int start_frame, int duration); - virtual void stopCD(); - virtual void updateCD(); - virtual MutexRef createMutex(void); virtual void lockMutex(MutexRef mutex); virtual void unlockMutex(MutexRef mutex); -- cgit v1.2.3 From 4cb3a2b41b5f92fda50f6db15e4e69be7dd0129a Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Tue, 1 Jun 2010 17:03:43 +0000 Subject: This hopefully fixes the compilation of the GP2x backend. svn-id: r49378 --- backends/platform/gp2x/gp2x-common.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'backends/platform') diff --git a/backends/platform/gp2x/gp2x-common.h b/backends/platform/gp2x/gp2x-common.h index 9f3a79ff97..8183a87300 100644 --- a/backends/platform/gp2x/gp2x-common.h +++ b/backends/platform/gp2x/gp2x-common.h @@ -150,8 +150,6 @@ public: bool setGraphicsMode(int mode); int getGraphicsMode() const; - bool openCD(int drive); - bool hasFeature(Feature f); void setFeatureState(Feature f, bool enable); bool getFeatureState(Feature f); -- cgit v1.2.3 From 93867d567fd76f909bfbb64f8300d6841af584e2 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 1 Jun 2010 22:28:24 +0000 Subject: Inline palettes in SDL backend into class OSystem_SDL svn-id: r49383 --- backends/platform/sdl/sdl.cpp | 10 +++------- backends/platform/sdl/sdl.h | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) (limited to 'backends/platform') diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 9fa43cb389..c947e32cd8 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -251,9 +251,9 @@ OSystem_SDL::OSystem_SDL() _screenIsLocked(false), _graphicsMutex(0), _transactionMode(kTransactionNone) { - // allocate palette storage - _currentPalette = (SDL_Color *)calloc(sizeof(SDL_Color), 256); - _cursorPalette = (SDL_Color *)calloc(sizeof(SDL_Color), 256); + // clear palette storage + memset(_currentPalette, 0, sizeof(_currentPalette)); + memset(_cursorPalette, 0, sizeof(_cursorPalette)); _mouseBackup.x = _mouseBackup.y = _mouseBackup.w = _mouseBackup.h = 0; @@ -282,8 +282,6 @@ OSystem_SDL::~OSystem_SDL() { closeMixer(); free(_dirtyChecksums); - free(_currentPalette); - free(_cursorPalette); free(_mouseData); delete _savefile; @@ -513,8 +511,6 @@ void OSystem_SDL::deinit() { closeMixer(); free(_dirtyChecksums); - free(_currentPalette); - free(_cursorPalette); free(_mouseData); delete _timer; diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index c850ec5ab1..bfaabab80a 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -422,11 +422,11 @@ protected: int _newShakePos; // Palette data - SDL_Color *_currentPalette; + SDL_Color _currentPalette[256]; uint _paletteDirtyStart, _paletteDirtyEnd; // Cursor palette data - SDL_Color *_cursorPalette; + SDL_Color _cursorPalette[256]; /** * Mutex which prevents multiple threads from interfering with each other -- cgit v1.2.3 From 9f14e43d16a45c37b041ed2e3041fd8e7690121d Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 1 Jun 2010 22:29:55 +0000 Subject: Fix bug #2999153: "IPHONE: No grabPalette() implementation" svn-id: r49384 --- backends/platform/iphone/osys_video.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'backends/platform') diff --git a/backends/platform/iphone/osys_video.cpp b/backends/platform/iphone/osys_video.cpp index 6cb5e18d95..76c2031758 100644 --- a/backends/platform/iphone/osys_video.cpp +++ b/backends/platform/iphone/osys_video.cpp @@ -86,7 +86,7 @@ int16 OSystem_IPHONE::getWidth() { } void OSystem_IPHONE::setPalette(const byte *colors, uint start, uint num) { - //printf("setPalette()\n"); + assert(start + num <= 256); const byte *b = colors; for (uint i = start; i < start + num; ++i) { @@ -98,7 +98,14 @@ void OSystem_IPHONE::setPalette(const byte *colors, uint start, uint num) { } void OSystem_IPHONE::grabPalette(byte *colors, uint start, uint num) { - //printf("grabPalette()\n"); + assert(start + num <= 256); + byte *b = colors; + + for (uint i = start; i < start + num; ++i) { + Graphics::colorToRGB >(_palette[i], b[0], b[1], b[2]); + b[3] = 0xFF; + b += 4; + } } void OSystem_IPHONE::copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h) { -- cgit v1.2.3 From 767edc91faebdc1a60e5c8b3764b169dc9807ea5 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 2 Jun 2010 00:52:57 +0000 Subject: OSYSTEM: Get rid of kFeatureAutoComputeDirtyRects svn-id: r49388 --- backends/platform/gp2x/gp2x-common.h | 11 -- backends/platform/gp2x/gp2x.cpp | 15 +-- backends/platform/gp2x/graphics.cpp | 137 +++------------------ backends/platform/gp2xwiz/gp2xwiz-graphics.cpp | 5 - backends/platform/linuxmoto/linuxmoto-graphics.cpp | 5 - backends/platform/samsungtv/samsungtv.cpp | 9 -- backends/platform/sdl/graphics.cpp | 100 +-------------- backends/platform/sdl/sdl.cpp | 15 +-- backends/platform/sdl/sdl.h | 11 -- backends/platform/symbian/src/SymbianOS.cpp | 1 - backends/platform/wince/wince-sdl.cpp | 61 ++++----- 11 files changed, 44 insertions(+), 326 deletions(-) (limited to 'backends/platform') diff --git a/backends/platform/gp2x/gp2x-common.h b/backends/platform/gp2x/gp2x-common.h index 8183a87300..b54e2d4d4f 100644 --- a/backends/platform/gp2x/gp2x-common.h +++ b/backends/platform/gp2x/gp2x-common.h @@ -191,10 +191,6 @@ protected: bool _overlayVisible; Graphics::PixelFormat _overlayFormat; - enum { - DF_WANT_RECT_OPTIM = 1 << 0 - }; - enum { kTransactionNone = 0, kTransactionActive = 1, @@ -235,7 +231,6 @@ protected: Graphics::Surface _framebuffer; /** Current video mode flags (see DF_* constants) */ - uint32 _modeFlags; bool _modeChanged; int _screenChangeCount; @@ -252,9 +247,6 @@ protected: // Dirty rect management SDL_Rect _dirtyRectList[NUM_DIRTY_RECT]; int _numDirtyRects; - uint32 *_dirtyChecksums; - bool _cksumValid; - int _cksumNum; // Keyboard mouse emulation. Disabled by fingolfin 2004-12-18. // I am keeping the rest of the code in for now, since the joystick @@ -351,9 +343,6 @@ protected: Common::TimerManager *_timer; protected: - void addDirtyRgnAuto(const byte *buf); - void makeChecksums(const byte *buf); - virtual void addDirtyRect(int x, int y, int w, int h, bool realCoordinates = false); void drawMouse(); diff --git a/backends/platform/gp2x/gp2x.cpp b/backends/platform/gp2x/gp2x.cpp index 8669671c4e..88d4f9d632 100644 --- a/backends/platform/gp2x/gp2x.cpp +++ b/backends/platform/gp2x/gp2x.cpp @@ -193,13 +193,11 @@ void OSystem_GP2X::initBackend() { memset(&_videoMode, 0, sizeof(_videoMode)); memset(&_transactionDetails, 0, sizeof(_transactionDetails)); - _cksumValid = false; _videoMode.mode = GFX_NORMAL; _videoMode.scaleFactor = 1; _scalerProc = Normal1x; _videoMode.aspectRatioCorrection = ConfMan.getBool("aspect_ratio"); _scalerType = 0; - _modeFlags = 0; _adjustZoomOnMouse = false; ConfMan.setBool("FM_low_quality", true); @@ -246,7 +244,7 @@ OSystem_GP2X::OSystem_GP2X() _hwscreen(0), _screen(0), _tmpscreen(0), _overlayVisible(false), _overlayscreen(0), _tmpscreen2(0), - _scalerProc(0), _modeChanged(false), _screenChangeCount(0), _dirtyChecksums(0), + _scalerProc(0), _modeChanged(false), _screenChangeCount(0), _mouseVisible(false), _mouseNeedsRedraw(false), _mouseData(0), _mouseSurface(0), _mouseOrigSurface(0), _cursorTargetScale(1), _cursorPaletteDisabled(true), _joystick(0), @@ -281,7 +279,6 @@ OSystem_GP2X::~OSystem_GP2X() { SDL_RemoveTimer(_timerID); closeMixer(); - free(_dirtyChecksums); free(_currentPalette); free(_cursorPalette); free(_mouseData); @@ -380,7 +377,6 @@ bool OSystem_GP2X::hasFeature(Feature f) { return (f == kFeatureFullscreenMode) || (f == kFeatureAspectRatioCorrection) || - (f == kFeatureAutoComputeDirtyRects) || (f == kFeatureCursorHasPalette); } @@ -391,12 +387,6 @@ void OSystem_GP2X::setFeatureState(Feature f, bool enable) { case kFeatureAspectRatioCorrection: setAspectRatioCorrection(enable); break; - case kFeatureAutoComputeDirtyRects: - if (enable) - _modeFlags |= DF_WANT_RECT_OPTIM; - else - _modeFlags &= ~DF_WANT_RECT_OPTIM; - break; case kFeatureDisableKeyFiltering: // TODO: Extend as more support for this is added to engines. return; @@ -413,8 +403,6 @@ bool OSystem_GP2X::getFeatureState(Feature f) { return false; case kFeatureAspectRatioCorrection: return _videoMode.aspectRatioCorrection; - case kFeatureAutoComputeDirtyRects: - return _modeFlags & DF_WANT_RECT_OPTIM; default: return false; } @@ -431,7 +419,6 @@ void OSystem_GP2X::quit() { SDL_RemoveTimer(_timerID); closeMixer(); - free(_dirtyChecksums); free(_currentPalette); free(_cursorPalette); free(_mouseData); diff --git a/backends/platform/gp2x/graphics.cpp b/backends/platform/gp2x/graphics.cpp index 449e744e8b..4a3c668c52 100644 --- a/backends/platform/gp2x/graphics.cpp +++ b/backends/platform/gp2x/graphics.cpp @@ -270,12 +270,7 @@ void OSystem_GP2X::initSize(uint w, uint h, const Graphics::PixelFormat *format) _videoMode.screenWidth = w; _videoMode.screenHeight = h; - _cksumNum = (w * h / (8 * 8)); - _transactionDetails.sizeChanged = true; - - free(_dirtyChecksums); - _dirtyChecksums = (uint32 *)calloc(_cksumNum * 2, sizeof(uint32)); } int OSystem_GP2X::effectiveScreenHeight() const { @@ -724,40 +719,31 @@ void OSystem_GP2X::copyRectToScreen(const byte *src, int pitch, int x, int y, in assert(h > 0 && y + h <= _videoMode.screenHeight); assert(w > 0 && x + w <= _videoMode.screenWidth); - if (IS_ALIGNED(src, 4) && pitch == _videoMode.screenWidth && x == 0 && y == 0 && - w == _videoMode.screenWidth && h == _videoMode.screenHeight && _modeFlags & DF_WANT_RECT_OPTIM) { - /* Special, optimized case for full screen updates. - * It tries to determine what areas were actually changed, - * and just updates those, on the actual display. */ - addDirtyRgnAuto(src); - } else { - /* Clip the coordinates */ - if (x < 0) { - w += x; - src -= x; - x = 0; - } + /* Clip the coordinates */ + if (x < 0) { + w += x; + src -= x; + x = 0; + } - if (y < 0) { - h += y; - src -= y * pitch; - y = 0; - } + if (y < 0) { + h += y; + src -= y * pitch; + y = 0; + } - if (w > _videoMode.screenWidth - x) { - w = _videoMode.screenWidth - x; - } + if (w > _videoMode.screenWidth - x) { + w = _videoMode.screenWidth - x; + } - if (h > _videoMode.screenHeight - y) { - h = _videoMode.screenHeight - y; - } + if (h > _videoMode.screenHeight - y) { + h = _videoMode.screenHeight - y; + } - if (w <= 0 || h <= 0) - return; + if (w <= 0 || h <= 0) + return; - _cksumValid = false; - addDirtyRect(x, y, w, h); - } + addDirtyRect(x, y, w, h); // Try to lock the screen surface if (SDL_LockSurface(_screen) == -1) @@ -885,88 +871,6 @@ void OSystem_GP2X::addDirtyRect(int x, int y, int w, int h, bool realCoordinates } } -void OSystem_GP2X::makeChecksums(const byte *buf) { - assert(buf); - uint32 *sums = _dirtyChecksums; - uint x,y; - const uint last_x = (uint)_videoMode.screenWidth / 8; - const uint last_y = (uint)_videoMode.screenHeight / 8; - - const uint BASE = 65521; /* largest prime smaller than 65536 */ - - /* the 8x8 blocks in buf are enumerated starting in the top left corner and - * reading each line at a time from left to right */ - for (y = 0; y != last_y; y++, buf += _videoMode.screenWidth * (8 - 1)) - for (x = 0; x != last_x; x++, buf += 8) { - // Adler32 checksum algorithm (from RFC1950, used by gzip and zlib). - // This computes the Adler32 checksum of a 8x8 pixel block. Note - // that we can do the modulo operation (which is the slowest part) - // of the algorithm) at the end, instead of doing each iteration, - // since we only have 64 iterations in total - and thus s1 and - // s2 can't overflow anyway. - uint32 s1 = 1; - uint32 s2 = 0; - const byte *ptr = buf; - for (int subY = 0; subY < 8; subY++) { - for (int subX = 0; subX < 8; subX++) { - s1 += ptr[subX]; - s2 += s1; - } - ptr += _videoMode.screenWidth; - } - - s1 %= BASE; - s2 %= BASE; - - /* output the checksum for this block */ - *sums++ = (s2 << 16) + s1; - } -} - -void OSystem_GP2X::addDirtyRgnAuto(const byte *buf) { - assert(buf); - assert(IS_ALIGNED(buf, 4)); - - /* generate a table of the checksums */ - makeChecksums(buf); - - if (!_cksumValid) { - _forceFull = true; - _cksumValid = true; - } - - /* go through the checksum list, compare it with the previous checksums, - and add all dirty rectangles to a list. try to combine small rectangles - into bigger ones in a simple way */ - if (!_forceFull) { - int x, y, w; - uint32 *ck = _dirtyChecksums; - - for (y = 0; y != _videoMode.screenHeight / 8; y++) { - for (x = 0; x != _videoMode.screenWidth / 8; x++, ck++) { - if (ck[0] != ck[_cksumNum]) { - /* found a dirty 8x8 block, now go as far to the right as possible, - and at the same time, unmark the dirty status by setting old to new. */ - w=0; - do { - ck[w + _cksumNum] = ck[w]; - w++; - } while (x + w != _videoMode.screenWidth / 8 && ck[w] != ck[w + _cksumNum]); - - addDirtyRect(x * 8, y * 8, w * 8, 8); - - if (_forceFull) - goto get_out; - } - } - } - } else { - get_out:; - /* Copy old checksums to new */ - memcpy(_dirtyChecksums + _cksumNum, _dirtyChecksums, _cksumNum * sizeof(uint32)); - } -} - int16 OSystem_GP2X::getHeight() { return _videoMode.screenHeight; } @@ -1175,7 +1079,6 @@ void OSystem_GP2X::copyRectToOverlay(const OverlayColor *buf, int pitch, int x, return; // Mark the modified region as dirty - _cksumValid = false; addDirtyRect(x, y, w, h); if (SDL_LockSurface(_overlayscreen) == -1) diff --git a/backends/platform/gp2xwiz/gp2xwiz-graphics.cpp b/backends/platform/gp2xwiz/gp2xwiz-graphics.cpp index 28c03db4b0..6abddd52f3 100644 --- a/backends/platform/gp2xwiz/gp2xwiz-graphics.cpp +++ b/backends/platform/gp2xwiz/gp2xwiz-graphics.cpp @@ -127,12 +127,7 @@ void OSystem_GP2XWIZ::initSize(uint w, uint h) { toggleMouseGrab(); } - _cksumNum = (w * h / (8 * 8)); - _transactionDetails.sizeChanged = true; - - free(_dirtyChecksums); - _dirtyChecksums = (uint32 *)calloc(_cksumNum * 2, sizeof(uint32)); } bool OSystem_GP2XWIZ::loadGFXMode() { diff --git a/backends/platform/linuxmoto/linuxmoto-graphics.cpp b/backends/platform/linuxmoto/linuxmoto-graphics.cpp index 482ed772c7..a39416ebc4 100644 --- a/backends/platform/linuxmoto/linuxmoto-graphics.cpp +++ b/backends/platform/linuxmoto/linuxmoto-graphics.cpp @@ -128,12 +128,7 @@ void OSystem_LINUXMOTO::initSize(uint w, uint h) { toggleMouseGrab(); } - _cksumNum = (w * h / (8 * 8)); - _transactionDetails.sizeChanged = true; - - free(_dirtyChecksums); - _dirtyChecksums = (uint32 *)calloc(_cksumNum * 2, sizeof(uint32)); } bool OSystem_LINUXMOTO::loadGFXMode() { diff --git a/backends/platform/samsungtv/samsungtv.cpp b/backends/platform/samsungtv/samsungtv.cpp index 4f0f3a1e3e..aa79b92558 100644 --- a/backends/platform/samsungtv/samsungtv.cpp +++ b/backends/platform/samsungtv/samsungtv.cpp @@ -30,7 +30,6 @@ bool OSystem_SDL_SamsungTV::hasFeature(Feature f) { return (f == kFeatureAspectRatioCorrection) || - (f == kFeatureAutoComputeDirtyRects) || (f == kFeatureCursorHasPalette); } @@ -39,12 +38,6 @@ void OSystem_SDL_SamsungTV::setFeatureState(Feature f, bool enable) { case kFeatureAspectRatioCorrection: setAspectRatioCorrection(enable); break; - case kFeatureAutoComputeDirtyRects: - if (enable) - _modeFlags |= DF_WANT_RECT_OPTIM; - else - _modeFlags &= ~DF_WANT_RECT_OPTIM; - break; default: break; } @@ -56,8 +49,6 @@ bool OSystem_SDL_SamsungTV::getFeatureState(Feature f) { switch (f) { case kFeatureAspectRatioCorrection: return _videoMode.aspectRatioCorrection; - case kFeatureAutoComputeDirtyRects: - return _modeFlags & DF_WANT_RECT_OPTIM; default: return false; } diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index e0bf7565fb..82670cfcb7 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -469,12 +469,7 @@ void OSystem_SDL::initSize(uint w, uint h, const Graphics::PixelFormat *format) _videoMode.screenWidth = w; _videoMode.screenHeight = h; - _cksumNum = (w * h / (8 * 8)); - _transactionDetails.sizeChanged = true; - - free(_dirtyChecksums); - _dirtyChecksums = (uint32 *)calloc(_cksumNum * 2, sizeof(uint32)); } int OSystem_SDL::effectiveScreenHeight() const { @@ -976,16 +971,7 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int assert(h > 0 && y + h <= _videoMode.screenHeight); assert(w > 0 && x + w <= _videoMode.screenWidth); - if (IS_ALIGNED(src, 4) && pitch == _videoMode.screenWidth && x == 0 && y == 0 && - w == _videoMode.screenWidth && h == _videoMode.screenHeight && _modeFlags & DF_WANT_RECT_OPTIM) { - /* Special, optimized case for full screen updates. - * It tries to determine what areas were actually changed, - * and just updates those, on the actual display. */ - addDirtyRgnAuto(src); - } else { - _cksumValid = false; - addDirtyRect(x, y, w, h); - } + addDirtyRect(x, y, w, h); // Try to lock the screen surface if (SDL_LockSurface(_screen) == -1) @@ -1131,89 +1117,6 @@ void OSystem_SDL::addDirtyRect(int x, int y, int w, int h, bool realCoordinates) } } - -void OSystem_SDL::makeChecksums(const byte *buf) { - assert(buf); - uint32 *sums = _dirtyChecksums; - uint x,y; - const uint last_x = (uint)_videoMode.screenWidth / 8; - const uint last_y = (uint)_videoMode.screenHeight / 8; - - const uint BASE = 65521; /* largest prime smaller than 65536 */ - - /* the 8x8 blocks in buf are enumerated starting in the top left corner and - * reading each line at a time from left to right */ - for (y = 0; y != last_y; y++, buf += _videoMode.screenWidth * (8 - 1)) - for (x = 0; x != last_x; x++, buf += 8) { - // Adler32 checksum algorithm (from RFC1950, used by gzip and zlib). - // This computes the Adler32 checksum of a 8x8 pixel block. Note - // that we can do the modulo operation (which is the slowest part) - // of the algorithm) at the end, instead of doing each iteration, - // since we only have 64 iterations in total - and thus s1 and - // s2 can't overflow anyway. - uint32 s1 = 1; - uint32 s2 = 0; - const byte *ptr = buf; - for (int subY = 0; subY < 8; subY++) { - for (int subX = 0; subX < 8; subX++) { - s1 += ptr[subX]; - s2 += s1; - } - ptr += _videoMode.screenWidth; - } - - s1 %= BASE; - s2 %= BASE; - - /* output the checksum for this block */ - *sums++ = (s2 << 16) + s1; - } -} - -void OSystem_SDL::addDirtyRgnAuto(const byte *buf) { - assert(buf); - assert(IS_ALIGNED(buf, 4)); - - /* generate a table of the checksums */ - makeChecksums(buf); - - if (!_cksumValid) { - _forceFull = true; - _cksumValid = true; - } - - /* go through the checksum list, compare it with the previous checksums, - and add all dirty rectangles to a list. try to combine small rectangles - into bigger ones in a simple way */ - if (!_forceFull) { - int x, y, w; - uint32 *ck = _dirtyChecksums; - - for (y = 0; y != _videoMode.screenHeight / 8; y++) { - for (x = 0; x != _videoMode.screenWidth / 8; x++, ck++) { - if (ck[0] != ck[_cksumNum]) { - /* found a dirty 8x8 block, now go as far to the right as possible, - and at the same time, unmark the dirty status by setting old to new. */ - w=0; - do { - ck[w + _cksumNum] = ck[w]; - w++; - } while (x + w != _videoMode.screenWidth / 8 && ck[w] != ck[w + _cksumNum]); - - addDirtyRect(x * 8, y * 8, w * 8, 8); - - if (_forceFull) - goto get_out; - } - } - } - } else { - get_out:; - /* Copy old checksums to new */ - memcpy(_dirtyChecksums + _cksumNum, _dirtyChecksums, _cksumNum * sizeof(uint32)); - } -} - int16 OSystem_SDL::getHeight() { return _videoMode.screenHeight; } @@ -1432,7 +1335,6 @@ void OSystem_SDL::copyRectToOverlay(const OverlayColor *buf, int pitch, int x, i return; // Mark the modified region as dirty - _cksumValid = false; addDirtyRect(x, y, w, h); if (SDL_LockSurface(_overlayscreen) == -1) diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index c947e32cd8..f8ae824acf 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -149,7 +149,6 @@ void OSystem_SDL::initBackend() { memset(&_videoMode, 0, sizeof(_videoMode)); memset(&_transactionDetails, 0, sizeof(_transactionDetails)); - _cksumValid = false; #if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) && defined(USE_SCALERS) _videoMode.mode = GFX_DOUBLESIZE; _videoMode.scaleFactor = 2; @@ -163,7 +162,6 @@ void OSystem_SDL::initBackend() { _scalerProc = Normal1x; #endif _scalerType = 0; - _modeFlags = 0; #if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) _videoMode.fullscreen = ConfMan.getBool("fullscreen"); @@ -233,7 +231,7 @@ OSystem_SDL::OSystem_SDL() #endif _overlayVisible(false), _overlayscreen(0), _tmpscreen2(0), - _cdrom(0), _scalerProc(0), _modeChanged(false), _screenChangeCount(0), _dirtyChecksums(0), + _cdrom(0), _scalerProc(0), _modeChanged(false), _screenChangeCount(0), _scrollLock(false), _mouseVisible(false), _mouseNeedsRedraw(false), _mouseData(0), _mouseSurface(0), _mouseOrigSurface(0), _cursorTargetScale(1), _cursorPaletteDisabled(true), @@ -281,7 +279,6 @@ OSystem_SDL::~OSystem_SDL() { SDL_RemoveTimer(_timerID); closeMixer(); - free(_dirtyChecksums); free(_mouseData); delete _savefile; @@ -451,7 +448,6 @@ bool OSystem_SDL::hasFeature(Feature f) { return (f == kFeatureFullscreenMode) || (f == kFeatureAspectRatioCorrection) || - (f == kFeatureAutoComputeDirtyRects) || (f == kFeatureCursorHasPalette) || (f == kFeatureIconifyWindow); } @@ -464,12 +460,6 @@ void OSystem_SDL::setFeatureState(Feature f, bool enable) { case kFeatureAspectRatioCorrection: setAspectRatioCorrection(enable); break; - case kFeatureAutoComputeDirtyRects: - if (enable) - _modeFlags |= DF_WANT_RECT_OPTIM; - else - _modeFlags &= ~DF_WANT_RECT_OPTIM; - break; case kFeatureIconifyWindow: if (enable) SDL_WM_IconifyWindow(); @@ -487,8 +477,6 @@ bool OSystem_SDL::getFeatureState(Feature f) { return _videoMode.fullscreen; case kFeatureAspectRatioCorrection: return _videoMode.aspectRatioCorrection; - case kFeatureAutoComputeDirtyRects: - return _modeFlags & DF_WANT_RECT_OPTIM; default: return false; } @@ -510,7 +498,6 @@ void OSystem_SDL::deinit() { SDL_RemoveTimer(_timerID); closeMixer(); - free(_dirtyChecksums); free(_mouseData); delete _timer; diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index bfaabab80a..341a59c8cf 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -290,10 +290,6 @@ protected: int _cdTrack, _cdNumLoops, _cdStartFrame, _cdDuration; uint32 _cdEndTime, _cdStopTime; - enum { - DF_WANT_RECT_OPTIM = 1 << 0 - }; - enum { kTransactionNone = 0, kTransactionActive = 1, @@ -342,7 +338,6 @@ protected: Graphics::Surface _framebuffer; /** Current video mode flags (see DF_* constants) */ - uint32 _modeFlags; bool _modeChanged; int _screenChangeCount; @@ -354,9 +349,6 @@ protected: // Dirty rect management SDL_Rect _dirtyRectList[NUM_DIRTY_RECT]; int _numDirtyRects; - uint32 *_dirtyChecksums; - bool _cksumValid; - int _cksumNum; // Keyboard mouse emulation. Disabled by fingolfin 2004-12-18. // I am keeping the rest of the code in for now, since the joystick @@ -459,9 +451,6 @@ protected: Common::TimerManager *_timer; protected: - void addDirtyRgnAuto(const byte *buf); - void makeChecksums(const byte *buf); - virtual void addDirtyRect(int x, int y, int w, int h, bool realCoordinates = false); // overloaded by CE backend virtual void drawMouse(); // overloaded by CE backend diff --git a/backends/platform/symbian/src/SymbianOS.cpp b/backends/platform/symbian/src/SymbianOS.cpp index f8df2a5d5c..2ae47b07a8 100644 --- a/backends/platform/symbian/src/SymbianOS.cpp +++ b/backends/platform/symbian/src/SymbianOS.cpp @@ -83,7 +83,6 @@ bool OSystem_SDL_Symbian::hasFeature(Feature f) { switch (f) { case kFeatureFullscreenMode: case kFeatureAspectRatioCorrection: - case kFeatureAutoComputeDirtyRects: case kFeatureCursorHasPalette: #ifdef USE_VIBRA_SE_PXXX case kFeatureVibration: diff --git a/backends/platform/wince/wince-sdl.cpp b/backends/platform/wince/wince-sdl.cpp index 7ce689fb63..b3480702b5 100644 --- a/backends/platform/wince/wince-sdl.cpp +++ b/backends/platform/wince/wince-sdl.cpp @@ -926,7 +926,7 @@ const OSystem::GraphicsMode *OSystem_WINCE3::getSupportedGraphicsModes() const { } bool OSystem_WINCE3::hasFeature(Feature f) { - return (f == kFeatureAutoComputeDirtyRects || f == kFeatureVirtualKeyboard); + return (f == kFeatureVirtualKeyboard); } void OSystem_WINCE3::setFeatureState(Feature f, bool enable) { @@ -1151,14 +1151,12 @@ bool OSystem_WINCE3::update_scalers() { _scaleFactorYm = 1; _scaleFactorYd = 1; _scalerProc = DownscaleHorizByThreeQuarters; - _modeFlags = 0; } else { _scaleFactorXm = 1; _scaleFactorXd = 1; _scaleFactorYm = 1; _scaleFactorYd = 1; _scalerProc = Normal1x; - _modeFlags = 0; } } else if ( _orientationLandscape && (_videoMode.screenWidth == 320 || !_videoMode.screenWidth)) { if (!_panelVisible && !_hasSmartphoneResolution && !_overlayVisible && _canBeAspectScaled) { @@ -1167,7 +1165,6 @@ bool OSystem_WINCE3::update_scalers() { _scaleFactorYm = 6; _scaleFactorYd = 5; _scalerProc = Normal1xAspect; - _modeFlags = 0; _videoMode.aspectRatioCorrection = true; } else { _scaleFactorXm = 1; @@ -1175,7 +1172,6 @@ bool OSystem_WINCE3::update_scalers() { _scaleFactorYm = 1; _scaleFactorYd = 1; _scalerProc = Normal1x; - _modeFlags = 0; } } else if (_videoMode.screenWidth == 640 && !(isOzone() && (getScreenWidth() >= 640 || getScreenHeight() >= 640))) { _scaleFactorXm = 1; @@ -1183,14 +1179,12 @@ bool OSystem_WINCE3::update_scalers() { _scaleFactorYm = 1; _scaleFactorYd = 2; _scalerProc = DownscaleAllByHalf; - _modeFlags = 0; } else if (_videoMode.screenWidth == 640 && (isOzone() && (getScreenWidth() >= 640 || getScreenHeight() >= 640))) { _scaleFactorXm = 1; _scaleFactorXd = 1; _scaleFactorYm = 1; _scaleFactorYd = 1; _scalerProc = Normal1x; - _modeFlags = 0; } return true; @@ -1203,7 +1197,6 @@ bool OSystem_WINCE3::update_scalers() { _scaleFactorYm = 12; _scaleFactorYd = 5; _scalerProc = Normal2xAspect; - _modeFlags = 0; _videoMode.aspectRatioCorrection = true; } else if ( (_panelVisible || _overlayVisible) && _canBeAspectScaled ) { _scaleFactorXm = 2; @@ -1211,7 +1204,6 @@ bool OSystem_WINCE3::update_scalers() { _scaleFactorYm = 2; _scaleFactorYd = 1; _scalerProc = Normal2x; - _modeFlags = 0; } return true; } @@ -1232,7 +1224,6 @@ bool OSystem_WINCE3::update_scalers() { _scaleFactorYm = 7; _scaleFactorYd = 8; _scalerProc = SmartphoneLandscape; - _modeFlags = 0; initZones(); return true; } @@ -1824,7 +1815,6 @@ void OSystem_WINCE3::copyRectToOverlay(const OverlayColor *buf, int pitch, int x return; // Mark the modified region as dirty - _cksumValid = false; addDirtyRect(x, y, w, h); undrawMouse(); @@ -1851,40 +1841,31 @@ void OSystem_WINCE3::copyRectToScreen(const byte *src, int pitch, int x, int y, Common::StackLock lock(_graphicsMutex); // Lock the mutex until this function ends - if (((long)src & 3) == 0 && pitch == _videoMode.screenWidth && x == 0 && y == 0 && - w == _videoMode.screenWidth && h == _videoMode.screenHeight && _modeFlags & DF_WANT_RECT_OPTIM) { - /* Special, optimized case for full screen updates. - * It tries to determine what areas were actually changed, - * and just updates those, on the actual display. */ - addDirtyRgnAuto(src); - } else { - /* Clip the coordinates */ - if (x < 0) { - w += x; - src -= x; - x = 0; - } + /* Clip the coordinates */ + if (x < 0) { + w += x; + src -= x; + x = 0; + } - if (y < 0) { - h += y; - src -= y * pitch; - y = 0; - } + if (y < 0) { + h += y; + src -= y * pitch; + y = 0; + } - if (w > _videoMode.screenWidth - x) { - w = _videoMode.screenWidth - x; - } + if (w > _videoMode.screenWidth - x) { + w = _videoMode.screenWidth - x; + } - if (h > _videoMode.screenHeight - y) { - h = _videoMode.screenHeight - y; - } + if (h > _videoMode.screenHeight - y) { + h = _videoMode.screenHeight - y; + } - if (w <= 0 || h <= 0) - return; + if (w <= 0 || h <= 0) + return; - _cksumValid = false; - addDirtyRect(x, y, w, h); - } + addDirtyRect(x, y, w, h); undrawMouse(); -- cgit v1.2.3 From 90649938d2d70115967c45cdd1cbb8dab1635794 Mon Sep 17 00:00:00 2001 From: Oystein Eftevaag Date: Thu, 3 Jun 2010 03:22:10 +0000 Subject: We'll now default to non-touchpad mode on the iPad svn-id: r49403 --- backends/platform/iphone/iphone_common.h | 1 + backends/platform/iphone/iphone_video.h | 2 -- backends/platform/iphone/iphone_video.m | 6 ++++++ backends/platform/iphone/osys_main.cpp | 3 ++- 4 files changed, 9 insertions(+), 3 deletions(-) (limited to 'backends/platform') diff --git a/backends/platform/iphone/iphone_common.h b/backends/platform/iphone/iphone_common.h index 9f7e3e808f..1f5ed01982 100644 --- a/backends/platform/iphone/iphone_common.h +++ b/backends/platform/iphone/iphone_common.h @@ -72,6 +72,7 @@ void iPhone_updateScreenRect(unsigned short* screen, int x1, int y1, int x2, int void iPhone_initSurface(int width, int height); bool iPhone_fetchEvent(int *outEvent, float *outX, float *outY); const char* iPhone_getDocumentsDir(); +bool iPhone_isHighResDevice(); #ifdef __cplusplus } diff --git a/backends/platform/iphone/iphone_video.h b/backends/platform/iphone/iphone_video.h index daa5e1d18e..1060a2a223 100644 --- a/backends/platform/iphone/iphone_video.h +++ b/backends/platform/iphone/iphone_video.h @@ -43,8 +43,6 @@ SoftKeyboard* _keyboardView; CALayer* _screenLayer; - int _fullWidth; - int _fullHeight; int _widthOffset; int _heightOffset; diff --git a/backends/platform/iphone/iphone_video.m b/backends/platform/iphone/iphone_video.m index e8977be2f2..faa0719b6c 100644 --- a/backends/platform/iphone/iphone_video.m +++ b/backends/platform/iphone/iphone_video.m @@ -29,6 +29,8 @@ static iPhoneView *sharedInstance = nil; static int _width = 0; static int _height = 0; +static int _fullWidth; +static int _fullHeight; static CGRect _screenRect; static char* _textureBuffer = 0; static int _textureWidth = 0; @@ -42,6 +44,10 @@ static UITouch* _secondTouch = NULL; // static long lastTick = 0; // static int frames = 0; +bool iPhone_isHighResDevice() { + return _fullHeight > 480; +} + void iPhone_updateScreen() { if (!_needsScreenUpdate) { _needsScreenUpdate = 1; diff --git a/backends/platform/iphone/osys_main.cpp b/backends/platform/iphone/osys_main.cpp index b151688e4e..6c26b6ca8d 100644 --- a/backends/platform/iphone/osys_main.cpp +++ b/backends/platform/iphone/osys_main.cpp @@ -57,7 +57,7 @@ OSystem_IPHONE::OSystem_IPHONE() : _overlayVisible(false), _overlayBuffer(NULL), _fullscreen(NULL), _mouseHeight(0), _mouseWidth(0), _mouseBuf(NULL), _lastMouseTap(0), _secondaryTapped(false), _lastSecondaryTap(0), _screenOrientation(kScreenOrientationFlippedLandscape), - _needEventRestPeriod(false), _mouseClickAndDragEnabled(false), _touchpadModeEnabled(true), + _needEventRestPeriod(false), _mouseClickAndDragEnabled(false), _gestureStartX(-1), _gestureStartY(-1), _fullScreenIsDirty(false), _fullScreenOverlayIsDirty(false), _mouseDirty(false), _timeSuspended(0), _lastDragPosX(-1), _lastDragPosY(-1), _screenChangeCount(0) @@ -65,6 +65,7 @@ OSystem_IPHONE::OSystem_IPHONE() : _queuedInputEvent.type = (Common::EventType)0; _lastDrawnMouseRect = Common::Rect(0, 0, 0, 0); + _touchpadModeEnabled = !iPhone_isHighResDevice(); _fsFactory = new POSIXFilesystemFactory(); } -- cgit v1.2.3