2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2005-08-16 17:15:37 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-08-16 17:15:37 +00:00
|
|
|
*
|
2006-02-11 12:47:47 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2005-08-16 17:15:37 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-04-12 07:28:54 +00:00
|
|
|
#include <pspuser.h>
|
2009-08-21 22:30:35 +00:00
|
|
|
#include <pspgu.h>
|
|
|
|
#include <pspdisplay.h>
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
#include <zlib.h>
|
|
|
|
|
2007-03-18 18:59:35 +00:00
|
|
|
#include "common/config-manager.h"
|
|
|
|
#include "common/events.h"
|
2005-08-16 17:15:37 +00:00
|
|
|
#include "common/scummsys.h"
|
|
|
|
|
2010-05-17 07:22:26 +00:00
|
|
|
#include "backends/platform/psp/psppixelformat.h"
|
2010-04-12 06:49:05 +00:00
|
|
|
#include "backends/platform/psp/osys_psp.h"
|
|
|
|
#include "backends/platform/psp/powerman.h"
|
2005-08-16 17:15:37 +00:00
|
|
|
|
2008-11-03 22:21:34 +00:00
|
|
|
#include "backends/saves/psp/psp-saves.h"
|
2007-02-11 11:24:37 +00:00
|
|
|
#include "backends/timer/default/default-timer.h"
|
2007-03-18 18:59:35 +00:00
|
|
|
#include "graphics/surface.h"
|
2008-06-28 15:28:29 +00:00
|
|
|
#include "sound/mixer_intern.h"
|
2007-02-11 11:24:37 +00:00
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
//#define __PSP_DEBUG_FUNCS__ /* For debugging function calls */
|
|
|
|
//#define __PSP_DEBUG_PRINT__ /* For debug printouts */
|
2009-11-24 10:33:30 +00:00
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
#include "backends/platform/psp/trace.h"
|
2005-08-16 17:15:37 +00:00
|
|
|
|
2010-05-24 06:57:58 +00:00
|
|
|
#define USE_PSP_AUDIO
|
2009-08-21 22:30:35 +00:00
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
#define SAMPLES_PER_SEC 44100
|
2005-08-16 17:15:37 +00:00
|
|
|
|
2007-02-11 11:24:37 +00:00
|
|
|
static int timer_handler(int t) {
|
|
|
|
DefaultTimerManager *tm = (DefaultTimerManager *)g_system->getTimerManager();
|
|
|
|
tm->handler();
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
void OSystem_PSP::initSDL() {
|
2010-05-23 05:51:32 +00:00
|
|
|
#ifdef USE_PSP_AUDIO
|
2010-05-23 11:48:21 +00:00
|
|
|
SDL_Init(0);
|
2010-05-23 05:51:32 +00:00
|
|
|
#else
|
2010-05-23 11:48:21 +00:00
|
|
|
SDL_Init(SDL_INIT_AUDIO);
|
2010-05-23 05:51:32 +00:00
|
|
|
#endif
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
OSystem_PSP::~OSystem_PSP() {}
|
2009-08-21 22:30:35 +00:00
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
#define PSP_SCREEN_WIDTH 480
|
|
|
|
#define PSP_SCREEN_HEIGHT 272
|
2009-08-21 22:30:35 +00:00
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
void OSystem_PSP::initBackend() {
|
|
|
|
DEBUG_ENTER_FUNC();
|
2005-08-16 17:15:37 +00:00
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
_cursor.enableCursorPalette(false);
|
|
|
|
_cursor.setXY(PSP_SCREEN_WIDTH >> 1, PSP_SCREEN_HEIGHT >> 1); // Mouse in the middle of the screen
|
2010-04-12 07:28:54 +00:00
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
// Set pointers for display manager
|
|
|
|
_displayManager.setCursor(&_cursor);
|
|
|
|
_displayManager.setScreen(&_screen);
|
|
|
|
_displayManager.setOverlay(&_overlay);
|
|
|
|
_displayManager.setKeyboard(&_keyboard);
|
|
|
|
_displayManager.init();
|
|
|
|
|
|
|
|
// Set pointers for input handler
|
|
|
|
_inputHandler.setCursor(&_cursor);
|
|
|
|
_inputHandler.setKeyboard(&_keyboard);
|
|
|
|
_inputHandler.init();
|
|
|
|
|
2010-04-12 07:28:54 +00:00
|
|
|
initSDL();
|
2010-05-23 11:48:21 +00:00
|
|
|
|
2008-11-03 22:21:34 +00:00
|
|
|
_savefile = new PSPSaveFileManager;
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2007-02-11 11:24:37 +00:00
|
|
|
_timer = new DefaultTimerManager();
|
2009-11-24 10:33:30 +00:00
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
PSP_DEBUG_PRINT("calling keyboard.load()\n");
|
|
|
|
_keyboard.load(); // Load virtual keyboard files into memory
|
2010-04-12 07:28:54 +00:00
|
|
|
|
2007-02-11 11:24:37 +00:00
|
|
|
setTimerCallback(&timer_handler, 10);
|
|
|
|
|
2008-07-08 17:20:26 +00:00
|
|
|
setupMixer();
|
|
|
|
|
2007-02-11 11:24:37 +00:00
|
|
|
OSystem::initBackend();
|
|
|
|
}
|
|
|
|
|
2006-05-29 18:06:02 +00:00
|
|
|
bool OSystem_PSP::hasFeature(Feature f) {
|
2009-08-18 18:06:50 +00:00
|
|
|
return (f == kFeatureOverlaySupportsAlpha || f == kFeatureCursorHasPalette);
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
2006-05-29 18:06:02 +00:00
|
|
|
void OSystem_PSP::setFeatureState(Feature f, bool enable) {
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
2006-05-29 18:06:02 +00:00
|
|
|
bool OSystem_PSP::getFeatureState(Feature f) {
|
2009-08-18 18:06:50 +00:00
|
|
|
return false;
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
2006-05-29 18:06:02 +00:00
|
|
|
const OSystem::GraphicsMode* OSystem_PSP::getSupportedGraphicsModes() const {
|
2010-04-12 06:49:05 +00:00
|
|
|
return _displayManager.getSupportedGraphicsModes();
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
2006-05-29 18:06:02 +00:00
|
|
|
int OSystem_PSP::getDefaultGraphicsMode() const {
|
2010-04-12 06:49:05 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
2010-04-25 15:12:24 +00:00
|
|
|
return _displayManager.getDefaultGraphicsMode();
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
2006-05-29 18:06:02 +00:00
|
|
|
bool OSystem_PSP::setGraphicsMode(int mode) {
|
2010-04-12 06:49:05 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
2010-04-25 15:12:24 +00:00
|
|
|
return _displayManager.setGraphicsMode(mode);
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
2006-05-29 18:06:02 +00:00
|
|
|
bool OSystem_PSP::setGraphicsMode(const char *name) {
|
2010-04-12 06:49:05 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
2010-04-25 15:12:24 +00:00
|
|
|
return _displayManager.setGraphicsMode(name);
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
2006-05-29 18:06:02 +00:00
|
|
|
int OSystem_PSP::getGraphicsMode() const {
|
2010-04-12 06:49:05 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
2010-04-25 15:12:24 +00:00
|
|
|
return _displayManager.getGraphicsMode();
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
#ifdef USE_RGB_COLOR
|
2006-05-30 21:22:52 +00:00
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
Graphics::PixelFormat OSystem_PSP::getScreenFormat() const {
|
|
|
|
return _screen.getScummvmPixelFormat();
|
|
|
|
}
|
2009-10-04 22:59:39 +00:00
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
Common::List<Graphics::PixelFormat> OSystem_PSP::getSupportedFormats() {
|
|
|
|
return _displayManager.getSupportedPixelFormats();
|
|
|
|
}
|
2005-08-16 17:15:37 +00:00
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
#endif
|
2006-05-30 21:22:52 +00:00
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
void OSystem_PSP::initSize(uint width, uint height, const Graphics::PixelFormat *format) {
|
|
|
|
DEBUG_ENTER_FUNC();
|
|
|
|
_displayManager.setSizeAndPixelFormat(width, height, format);
|
2009-11-24 14:18:46 +00:00
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
_cursor.setVisible(false);
|
|
|
|
_cursor.setLimits(_screen.getWidth(), _screen.getHeight());
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int16 OSystem_PSP::getWidth() {
|
2010-04-12 06:49:05 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
2010-04-25 15:12:24 +00:00
|
|
|
return (int16)_screen.getWidth();
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
2006-05-29 17:40:31 +00:00
|
|
|
int16 OSystem_PSP::getHeight() {
|
2010-04-12 06:49:05 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
2010-04-25 15:12:24 +00:00
|
|
|
return (int16)_screen.getHeight();
|
2006-05-29 17:40:31 +00:00
|
|
|
}
|
|
|
|
|
2005-08-16 17:15:37 +00:00
|
|
|
void OSystem_PSP::setPalette(const byte *colors, uint start, uint num) {
|
2010-04-12 06:49:05 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
|
|
|
_screen.setPartialPalette(colors, start, num);
|
|
|
|
_cursor.setScreenPalette(colors, start, num);
|
|
|
|
_cursor.clearKeyColor();
|
2009-08-21 22:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_PSP::setCursorPalette(const byte *colors, uint start, uint num) {
|
2010-04-12 06:49:05 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
|
|
|
_cursor.setCursorPalette(colors, start, num);
|
|
|
|
_cursor.enableCursorPalette(true);
|
|
|
|
_cursor.clearKeyColor(); // Do we need this?
|
2009-08-21 22:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_PSP::disableCursorPalette(bool disable) {
|
2010-04-12 06:49:05 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
|
|
|
_cursor.enableCursorPalette(!disable);
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_PSP::copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h) {
|
2010-04-12 06:49:05 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
|
|
|
_screen.copyFromRect(buf, pitch, x, y, w, h);
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
2007-06-19 22:39:59 +00:00
|
|
|
Graphics::Surface *OSystem_PSP::lockScreen() {
|
2010-04-12 06:49:05 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
2010-04-25 15:12:24 +00:00
|
|
|
return _screen.lockAndGetForEditing();
|
2007-06-19 22:39:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_PSP::unlockScreen() {
|
2010-04-12 06:49:05 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
|
|
|
// The screen is always completely updated anyway, so we don't have to force a full update here.
|
|
|
|
_screen.unlock();
|
2006-07-07 10:38:56 +00:00
|
|
|
}
|
|
|
|
|
2005-08-16 17:15:37 +00:00
|
|
|
void OSystem_PSP::updateScreen() {
|
2010-04-12 06:49:05 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
|
|
|
_displayManager.renderAll();
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_PSP::setShakePos(int shakeOffset) {
|
2010-04-12 07:28:54 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
2010-04-12 06:49:05 +00:00
|
|
|
_screen.setShakePos(shakeOffset);
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
2006-05-29 18:06:02 +00:00
|
|
|
void OSystem_PSP::showOverlay() {
|
2010-04-12 06:49:05 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
|
|
|
_overlay.setVisible(true);
|
|
|
|
_cursor.setLimits(_overlay.getWidth(), _overlay.getHeight());
|
|
|
|
_cursor.useGlobalScaler(false); // mouse with overlay is 1:1
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
2006-05-29 18:06:02 +00:00
|
|
|
void OSystem_PSP::hideOverlay() {
|
2010-04-12 06:49:05 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
|
|
|
_overlay.setVisible(false);
|
|
|
|
_cursor.setLimits(_screen.getWidth(), _screen.getHeight());
|
|
|
|
_cursor.useGlobalScaler(true); // mouse needs to be scaled with screen
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
2006-05-29 18:06:02 +00:00
|
|
|
void OSystem_PSP::clearOverlay() {
|
2010-04-12 06:49:05 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
|
|
|
_overlay.clearBuffer();
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
void OSystem_PSP::grabOverlay(OverlayColor *buf, int pitch) {
|
|
|
|
DEBUG_ENTER_FUNC();
|
|
|
|
_overlay.copyToArray(buf, pitch);
|
|
|
|
}
|
2005-08-16 17:15:37 +00:00
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
void OSystem_PSP::copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h) {
|
|
|
|
DEBUG_ENTER_FUNC();
|
|
|
|
_overlay.copyFromRect(buf, pitch, x, y, w, h);
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
2006-05-29 18:06:02 +00:00
|
|
|
int16 OSystem_PSP::getOverlayWidth() {
|
2010-04-12 06:49:05 +00:00
|
|
|
return (int16) _overlay.getWidth();
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
2006-05-29 18:06:02 +00:00
|
|
|
int16 OSystem_PSP::getOverlayHeight() {
|
2010-04-12 06:49:05 +00:00
|
|
|
return (int16) _overlay.getHeight();
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
2006-05-29 18:06:02 +00:00
|
|
|
void OSystem_PSP::grabPalette(byte *colors, uint start, uint num) {
|
2010-04-12 06:49:05 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
|
|
|
_screen.getPartialPalette(colors, start, num);
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
bool OSystem_PSP::showMouse(bool v) {
|
|
|
|
DEBUG_ENTER_FUNC();
|
|
|
|
PSP_DEBUG_PRINT("%s\n", v ? "true" : "false");
|
|
|
|
bool last = _cursor.isVisible();
|
|
|
|
_cursor.setVisible(v);
|
2010-04-12 07:28:54 +00:00
|
|
|
|
2005-08-16 17:15:37 +00:00
|
|
|
return last;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_PSP::warpMouse(int x, int y) {
|
2010-04-12 06:49:05 +00:00
|
|
|
DEBUG_ENTER_FUNC();
|
2010-04-12 07:28:54 +00:00
|
|
|
_cursor.setXY(x, y);
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
void OSystem_PSP::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) {
|
|
|
|
DEBUG_ENTER_FUNC();
|
|
|
|
PSP_DEBUG_PRINT("pbuf[%p], w[%u], h[%u], hotspot:X[%d], Y[%d], keycolor[%d], scale[%d], pformat[%p]\n", buf, w, h, hotspotX, hotspotY, keycolor, cursorTargetScale, format);
|
|
|
|
if (format) {
|
|
|
|
PSP_DEBUG_PRINT("format: bpp[%d], rLoss[%d], gLoss[%d], bLoss[%d], aLoss[%d], rShift[%d], gShift[%d], bShift[%d], aShift[%d]\n", format->bytesPerPixel, format->rLoss, format->gLoss, format->bLoss, format->aLoss, format->rShift, format->gShift, format->bShift, format->aShift);
|
2009-12-31 23:59:07 +00:00
|
|
|
}
|
2010-04-12 07:28:54 +00:00
|
|
|
|
|
|
|
_cursor.setKeyColor(keycolor);
|
2010-04-12 06:49:05 +00:00
|
|
|
_cursor.setCursorTargetScale(cursorTargetScale);
|
|
|
|
_cursor.setSizeAndScummvmPixelFormat(w, h, format);
|
|
|
|
_cursor.setHotspot(hotspotX, hotspotY);
|
|
|
|
_cursor.clearKeyColor();
|
|
|
|
_cursor.copyFromArray(buf);
|
2009-12-31 23:59:07 +00:00
|
|
|
}
|
|
|
|
|
2009-08-21 22:30:35 +00:00
|
|
|
bool OSystem_PSP::pollEvent(Common::Event &event) {
|
2009-11-24 14:18:46 +00:00
|
|
|
|
|
|
|
// If we're polling for events, we should check for pausing the engine
|
2009-09-23 16:11:23 +00:00
|
|
|
// Pausing the engine is a necessary fix for games that use the timer for music synchronization
|
|
|
|
// recovering many hours later causes the game to crash. We're polling without mutexes since it's not critical to
|
|
|
|
// get it right now.
|
|
|
|
|
|
|
|
PowerMan.pollPauseEngine();
|
2009-11-24 14:18:46 +00:00
|
|
|
|
2010-04-12 06:49:05 +00:00
|
|
|
return _inputHandler.getAllInputs(event);
|
2009-08-21 22:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-16 17:15:37 +00:00
|
|
|
uint32 OSystem_PSP::getMillis() {
|
|
|
|
return SDL_GetTicks();
|
|
|
|
}
|
|
|
|
|
2008-01-27 19:47:41 +00:00
|
|
|
void OSystem_PSP::delayMillis(uint msecs) {
|
2005-08-16 17:15:37 +00:00
|
|
|
SDL_Delay(msecs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_PSP::setTimerCallback(TimerProc callback, int interval) {
|
2010-05-23 11:48:21 +00:00
|
|
|
//SDL_SetTimer(interval, (SDL_TimerCallback)callback);
|
|
|
|
_pspTimer.setCallback((PspTimer::CallbackFunc)callback);
|
|
|
|
_pspTimer.setIntervalMs(interval);
|
|
|
|
_pspTimer.start();
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OSystem::MutexRef OSystem_PSP::createMutex(void) {
|
|
|
|
return (MutexRef)SDL_CreateMutex();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_PSP::lockMutex(MutexRef mutex) {
|
|
|
|
SDL_mutexP((SDL_mutex *)mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_PSP::unlockMutex(MutexRef mutex) {
|
|
|
|
SDL_mutexV((SDL_mutex *)mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_PSP::deleteMutex(MutexRef mutex) {
|
|
|
|
SDL_DestroyMutex((SDL_mutex *)mutex);
|
|
|
|
}
|
|
|
|
|
2008-07-08 17:20:26 +00:00
|
|
|
void OSystem_PSP::mixCallback(void *sys, byte *samples, int len) {
|
|
|
|
OSystem_PSP *this_ = (OSystem_PSP *)sys;
|
|
|
|
assert(this_);
|
|
|
|
|
|
|
|
if (this_->_mixer)
|
|
|
|
this_->_mixer->mixCallback(samples, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_PSP::setupMixer(void) {
|
2005-08-16 17:15:37 +00:00
|
|
|
|
2010-03-11 23:39:51 +00:00
|
|
|
// Determine the desired output sampling frequency.
|
|
|
|
uint32 samplesPerSec = 0;
|
2005-08-16 17:15:37 +00:00
|
|
|
if (ConfMan.hasKey("output_rate"))
|
2010-03-10 21:01:44 +00:00
|
|
|
samplesPerSec = ConfMan.getInt("output_rate");
|
2010-03-11 23:39:51 +00:00
|
|
|
if (samplesPerSec <= 0)
|
2010-03-10 21:01:44 +00:00
|
|
|
samplesPerSec = SAMPLES_PER_SEC;
|
2005-08-16 17:15:37 +00:00
|
|
|
|
2010-03-11 23:39:51 +00:00
|
|
|
// Determine the sample buffer size. We want it to store enough data for
|
|
|
|
// at least 1/16th of a second (though at most 8192 samples). Note
|
|
|
|
// that it must be a power of two. So e.g. at 22050 Hz, we request a
|
|
|
|
// sample buffer size of 2048.
|
|
|
|
uint32 samples = 8192;
|
|
|
|
while (samples * 16 > samplesPerSec * 2)
|
2005-08-16 17:15:37 +00:00
|
|
|
samples >>= 1;
|
|
|
|
|
2010-05-23 05:51:32 +00:00
|
|
|
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;
|
|
|
|
|
2010-03-11 23:39:51 +00:00
|
|
|
memset(&desired, 0, sizeof(desired));
|
2010-03-10 21:01:44 +00:00
|
|
|
desired.freq = samplesPerSec;
|
2005-08-16 17:15:37 +00:00
|
|
|
desired.format = AUDIO_S16SYS;
|
|
|
|
desired.channels = 2;
|
|
|
|
desired.samples = samples;
|
2008-07-08 17:20:26 +00:00
|
|
|
desired.callback = mixCallback;
|
|
|
|
desired.userdata = this;
|
2010-05-23 05:51:32 +00:00
|
|
|
|
2005-08-16 17:15:37 +00:00
|
|
|
if (SDL_OpenAudio(&desired, &obtained) != 0) {
|
2008-07-08 17:20:26 +00:00
|
|
|
warning("Could not open audio: %s", SDL_GetError());
|
2010-03-11 23:39:51 +00:00
|
|
|
_mixer = new Audio::MixerImpl(this, samplesPerSec);
|
|
|
|
assert(_mixer);
|
2008-07-08 17:20:26 +00:00
|
|
|
_mixer->setReady(false);
|
|
|
|
} else {
|
|
|
|
// Note: This should be the obtained output rate, but it seems that at
|
|
|
|
// least on some platforms SDL will lie and claim it did get the rate
|
|
|
|
// even if it didn't. Probably only happens for "weird" rates, though.
|
2010-03-10 21:01:44 +00:00
|
|
|
samplesPerSec = obtained.freq;
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2010-03-11 23:39:51 +00:00
|
|
|
// Create the mixer instance and start the sound processing
|
|
|
|
_mixer = new Audio::MixerImpl(this, samplesPerSec);
|
|
|
|
assert(_mixer);
|
2008-07-08 17:20:26 +00:00
|
|
|
_mixer->setReady(true);
|
|
|
|
|
|
|
|
SDL_PauseAudio(0);
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
2010-05-23 05:51:32 +00:00
|
|
|
#endif /* USE_PSP_AUDIO */
|
2005-08-16 17:15:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_PSP::quit() {
|
2010-05-23 05:51:32 +00:00
|
|
|
#ifdef USE_PSP_AUDIO
|
|
|
|
_audio.close();
|
|
|
|
#else
|
2008-06-28 15:13:54 +00:00
|
|
|
SDL_CloseAudio();
|
2010-05-23 05:51:32 +00:00
|
|
|
#endif
|
2005-08-16 17:15:37 +00:00
|
|
|
SDL_Quit();
|
|
|
|
sceKernelExitGame();
|
|
|
|
}
|
|
|
|
|
2009-10-08 19:41:38 +00:00
|
|
|
void OSystem_PSP::getTimeAndDate(TimeDate &td) const {
|
2008-03-19 11:07:27 +00:00
|
|
|
time_t curTime = time(0);
|
2009-10-08 19:41:38 +00:00
|
|
|
struct tm t = *localtime(&curTime);
|
|
|
|
td.tm_sec = t.tm_sec;
|
|
|
|
td.tm_min = t.tm_min;
|
|
|
|
td.tm_hour = t.tm_hour;
|
|
|
|
td.tm_mday = t.tm_mday;
|
|
|
|
td.tm_mon = t.tm_mon;
|
|
|
|
td.tm_year = t.tm_year;
|
2008-03-19 11:07:27 +00:00
|
|
|
}
|
|
|
|
|
2008-10-16 17:18:15 +00:00
|
|
|
#define PSP_CONFIG_FILE "ms0:/scummvm.ini"
|
|
|
|
|
2009-01-23 03:30:40 +00:00
|
|
|
Common::SeekableReadStream *OSystem_PSP::createConfigReadStream() {
|
2008-10-16 17:18:15 +00:00
|
|
|
Common::FSNode file(PSP_CONFIG_FILE);
|
2009-01-23 03:41:36 +00:00
|
|
|
return file.createReadStream();
|
2008-10-16 17:18:15 +00:00
|
|
|
}
|
|
|
|
|
2009-01-23 03:30:40 +00:00
|
|
|
Common::WriteStream *OSystem_PSP::createConfigWriteStream() {
|
2008-10-16 17:18:15 +00:00
|
|
|
Common::FSNode file(PSP_CONFIG_FILE);
|
2009-01-23 03:41:36 +00:00
|
|
|
return file.createWriteStream();
|
2008-10-16 17:18:15 +00:00
|
|
|
}
|