diff options
Diffstat (limited to 'backends/platform/psp/osys_psp.cpp')
-rw-r--r-- | backends/platform/psp/osys_psp.cpp | 910 |
1 files changed, 186 insertions, 724 deletions
diff --git a/backends/platform/psp/osys_psp.cpp b/backends/platform/psp/osys_psp.cpp index 8b4c005221..022c10f5a8 100644 --- a/backends/platform/psp/osys_psp.cpp +++ b/backends/platform/psp/osys_psp.cpp @@ -23,6 +23,7 @@ * */ +#include <pspuser.h> #include <pspgu.h> #include <pspdisplay.h> @@ -33,40 +34,21 @@ #include "common/events.h" #include "common/scummsys.h" -#include "osys_psp.h" -#include "trace.h" -#include "powerman.h" +#include "backends/platform/psp/osys_psp.h" +#include "backends/platform/psp/powerman.h" #include "backends/saves/psp/psp-saves.h" #include "backends/timer/default/default-timer.h" #include "graphics/surface.h" #include "sound/mixer_intern.h" -#include "backends/platform/psp/pspkeyboard.h" +//#define __PSP_DEBUG_FUNCS__ /* For debugging function calls */ +//#define __PSP_DEBUG_PRINT__ /* For debug printouts */ +#include "backends/platform/psp/trace.h" -#define SAMPLES_PER_SEC 44100 - -#define PIXEL_SIZE (4) -#define BUF_WIDTH (512) -#define PSP_SCREEN_WIDTH 480 -#define PSP_SCREEN_HEIGHT 272 -#define PSP_FRAME_SIZE (BUF_WIDTH * PSP_SCREEN_HEIGHT * PIXEL_SIZE) -#define MOUSE_SIZE 128 -#define KBD_DATA_SIZE 130560 - -#define MAX_FPS 30 - -unsigned int __attribute__((aligned(16))) displayList[2048]; -unsigned short __attribute__((aligned(16))) clut256[256]; -unsigned short __attribute__((aligned(16))) mouseClut[256]; -unsigned short __attribute__((aligned(16))) cursorPalette[256]; -unsigned int __attribute__((aligned(16))) mouseBuf256[MOUSE_SIZE*MOUSE_SIZE]; - -unsigned long RGBToColour(unsigned long r, unsigned long g, unsigned long b) { - return (((b >> 3) << 10) | ((g >> 3) << 5) | ((r >> 3) << 0)) | 0x8000; -} +#define SAMPLES_PER_SEC 44100 static int timer_handler(int t) { DefaultTimerManager *tm = (DefaultTimerManager *)g_system->getTimerManager(); @@ -74,87 +56,51 @@ static int timer_handler(int t) { return t; } -const OSystem::GraphicsMode OSystem_PSP::s_supportedGraphicsModes[] = { - { "320x200 (centered)", "320x200 16-bit centered", CENTERED_320X200 }, - { "435x272 (best-fit, centered)", "435x272 16-bit centered", CENTERED_435X272 }, - { "480x272 (full screen)", "480x272 16-bit stretched", STRETCHED_480X272 }, - { "362x272 (4:3, centered)", "362x272 16-bit centered", CENTERED_362X272 }, - {0, 0, 0} -}; - - -OSystem_PSP::OSystem_PSP() : _screenWidth(0), _screenHeight(0), _overlayWidth(0), _overlayHeight(0), - _offscreen(0), _overlayBuffer(0), _overlayVisible(false), _shakePos(0), _lastScreenUpdate(0), - _mouseBuf(0), _prevButtons(0), _lastPadCheck(0), _mixer(0) { - memset(_palette, 0, sizeof(_palette)); - - _cursorPaletteDisabled = true; - - //init SDL - uint32 sdlFlags = SDL_INIT_AUDIO | SDL_INIT_TIMER; - SDL_Init(sdlFlags); - - _clut = clut256; - _mouseBuf = (byte *)mouseBuf256; - _graphicMode = STRETCHED_480X272; - - _mouseX = PSP_SCREEN_WIDTH >> 1; // Mouse in the middle of the screen - _mouseY = PSP_SCREEN_HEIGHT >> 1; - _dpadX = _dpadY = 0; - - - // Init GU - sceGuInit(); - sceGuStart(0, displayList); - sceGuDrawBuffer(GU_PSM_8888, (void *)0, BUF_WIDTH); - sceGuDispBuffer(PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT, (void*)PSP_FRAME_SIZE, BUF_WIDTH); - sceGuDepthBuffer((void*)(PSP_FRAME_SIZE * 2), BUF_WIDTH); - sceGuOffset(2048 - (PSP_SCREEN_WIDTH/2), 2048 - (PSP_SCREEN_HEIGHT/2)); - sceGuViewport(2048, 2048, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT); - sceGuDepthRange(0xC350, 0x2710); - sceGuScissor(0, 0, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT); - sceGuEnable(GU_SCISSOR_TEST); - sceGuFrontFace(GU_CW); - sceGuEnable(GU_TEXTURE_2D); - sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT); - sceGuFinish(); - sceGuSync(0,0); - - sceDisplayWaitVblankStart(); - sceGuDisplay(1); - +void OSystem_PSP::initSDL() { + SDL_Init(SDL_INIT_AUDIO | SDL_INIT_TIMER); } -OSystem_PSP::~OSystem_PSP() { +OSystem_PSP::~OSystem_PSP() {} - free(_offscreen); - free(_overlayBuffer); - free(_mouseBuf); - delete _keyboard; +#define PSP_SCREEN_WIDTH 480 +#define PSP_SCREEN_HEIGHT 272 - _offscreen = 0; - _overlayBuffer = 0; - _mouseBuf = 0; - sceGuTerm(); -} +void OSystem_PSP::initBackend() { + DEBUG_ENTER_FUNC(); + _cursor.enableCursorPalette(false); + _cursor.setXY(PSP_SCREEN_WIDTH >> 1, PSP_SCREEN_HEIGHT >> 1); // Mouse in the middle of the screen + + // 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(); + + initSDL(); -void OSystem_PSP::initBackend() { _savefile = new PSPSaveFileManager; _timer = new DefaultTimerManager(); - _keyboard = new PSPKeyboard(); - _keyboard->load(); - + PSP_DEBUG_PRINT("calling keyboard.load()\n"); + _keyboard.load(); // Load virtual keyboard files into memory + setTimerCallback(&timer_handler, 10); setupMixer(); OSystem::initBackend(); + + DEBUG_EXIT_FUNC(); } - bool OSystem_PSP::hasFeature(Feature f) { return (f == kFeatureOverlaySupportsAlpha || f == kFeatureCursorHasPalette); } @@ -167,733 +113,251 @@ bool OSystem_PSP::getFeatureState(Feature f) { } const OSystem::GraphicsMode* OSystem_PSP::getSupportedGraphicsModes() const { - return s_supportedGraphicsModes; + return _displayManager.getSupportedGraphicsModes(); } - int OSystem_PSP::getDefaultGraphicsMode() const { - return STRETCHED_480X272; + DEBUG_ENTER_FUNC(); + + int ret = _displayManager.getDefaultGraphicsMode(); + + DEBUG_EXIT_FUNC(); + return ret; } bool OSystem_PSP::setGraphicsMode(int mode) { - _graphicMode = mode; - return true; + DEBUG_ENTER_FUNC(); + + int ret = _displayManager.setGraphicsMode(mode); + + DEBUG_EXIT_FUNC(); + return ret; } bool OSystem_PSP::setGraphicsMode(const char *name) { - int i = 0; - - while (s_supportedGraphicsModes[i].name) { - if (!strcmpi(s_supportedGraphicsModes[i].name, name)) { - _graphicMode = s_supportedGraphicsModes[i].id; - return true; - } - i++; - } - - return false; + DEBUG_ENTER_FUNC(); + + int ret = _displayManager.setGraphicsMode(name); + + DEBUG_EXIT_FUNC(); + return ret; } int OSystem_PSP::getGraphicsMode() const { - return _graphicMode; + DEBUG_ENTER_FUNC(); + + int ret = _displayManager.getGraphicsMode(); + + DEBUG_EXIT_FUNC(); + return ret; } -void OSystem_PSP::initSize(uint width, uint height, const Graphics::PixelFormat *format) { - PSPDebugTrace("initSize\n"); - - _screenWidth = width; - _screenHeight = height; +#ifdef USE_RGB_COLOR - const int scrBufSize = _screenWidth * _screenHeight * (format ? format->bytesPerPixel : 4); +Graphics::PixelFormat OSystem_PSP::getScreenFormat() const { + return _screen.getScummvmPixelFormat(); +} - _overlayWidth = PSP_SCREEN_WIDTH; //width; - _overlayHeight = PSP_SCREEN_HEIGHT; //height; +Common::List<Graphics::PixelFormat> OSystem_PSP::getSupportedFormats() { + return _displayManager.getSupportedPixelFormats(); +} - free(_overlayBuffer); - _overlayBuffer = (OverlayColor *)memalign(16, _overlayWidth * _overlayHeight * sizeof(OverlayColor)); +#endif - free(_offscreen); - _offscreen = (byte *)memalign(16, scrBufSize); - bzero(_offscreen, scrBufSize); +void OSystem_PSP::initSize(uint width, uint height, const Graphics::PixelFormat *format) { + DEBUG_ENTER_FUNC(); + + _displayManager.setSizeAndPixelFormat(width, height, format); - clearOverlay(); - memset(_palette, 0xFFFF, 256 * sizeof(unsigned short)); + _cursor.setVisible(false); + _cursor.setLimits(_screen.getWidth(), _screen.getHeight()); - _mouseVisible = false; - sceKernelDcacheWritebackAll(); + DEBUG_EXIT_FUNC(); } int16 OSystem_PSP::getWidth() { - return _screenWidth; + DEBUG_ENTER_FUNC(); + + int16 ret = (int16)_screen.getWidth(); + + DEBUG_EXIT_FUNC(); + return ret; } int16 OSystem_PSP::getHeight() { - return _screenHeight; + DEBUG_ENTER_FUNC(); + + int16 ret = (int16)_screen.getHeight(); + + DEBUG_EXIT_FUNC(); + return ret; } void OSystem_PSP::setPalette(const byte *colors, uint start, uint num) { - const byte *b = colors; + DEBUG_ENTER_FUNC(); + + _screen.setPartialPalette(colors, start, num); + _cursor.setScreenPalette(colors, start, num); + _cursor.clearKeyColor(); - for (uint i = 0; i < num; ++i) { - _palette[start + i] = RGBToColour(b[0], b[1], b[2]); - b += 4; - } - - //copy to CLUT - memcpy(_clut, _palette, 256 * sizeof(unsigned short)); - - //force update of mouse CLUT as well, as it may have been set up before this palette was set - memcpy(mouseClut, _palette, 256 * sizeof(unsigned short)); - mouseClut[_mouseKeyColour] = 0; - - sceKernelDcacheWritebackAll(); + DEBUG_EXIT_FUNC(); } void OSystem_PSP::setCursorPalette(const byte *colors, uint start, uint num) { - const byte *b = colors; - - for (uint i = 0; i < num; ++i) { - cursorPalette[start + i] = RGBToColour(b[0], b[1], b[2]); - b += 4; - } - - cursorPalette[0] = 0; + DEBUG_ENTER_FUNC(); - _cursorPaletteDisabled = false; + _cursor.setCursorPalette(colors, start, num); + _cursor.enableCursorPalette(true); + _cursor.clearKeyColor(); // Do we need this? - sceKernelDcacheWritebackAll(); + DEBUG_EXIT_FUNC(); } void OSystem_PSP::disableCursorPalette(bool disable) { - _cursorPaletteDisabled = disable; + DEBUG_ENTER_FUNC(); + + _cursor.enableCursorPalette(!disable); + + DEBUG_EXIT_FUNC(); } void OSystem_PSP::copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h) { - //Clip the coordinates - if (x < 0) { - w += x; - buf -= x; - x = 0; - } - - if (y < 0) { - h += y; - buf -= y * pitch; - y = 0; - } - - if (w > _screenWidth - x) { - w = _screenWidth - x; - } - - if (h > _screenHeight - y) { - h = _screenHeight - y; - } - - if (w <= 0 || h <= 0) - return; + DEBUG_ENTER_FUNC(); + _screen.copyFromRect(buf, pitch, x, y, w, h); - byte *dst = _offscreen + y * _screenWidth + x; - - if (_screenWidth == pitch && pitch == w) { - memcpy(dst, buf, h * w); - } else { - do { - memcpy(dst, buf, w); - buf += pitch; - dst += _screenWidth; - } while (--h); - } - sceKernelDcacheWritebackAll(); - + DEBUG_EXIT_FUNC(); } Graphics::Surface *OSystem_PSP::lockScreen() { - _framebuffer.pixels = _offscreen; - _framebuffer.w = _screenWidth; - _framebuffer.h = _screenHeight; - _framebuffer.pitch = _screenWidth; - _framebuffer.bytesPerPixel = 1; + DEBUG_ENTER_FUNC(); - return &_framebuffer; + Graphics::Surface *ret = _screen.lockAndGetForEditing(); + + DEBUG_EXIT_FUNC(); + return ret; } void OSystem_PSP::unlockScreen() { - // The screen is always completely update anyway, so we don't have to force a full update here. - sceKernelDcacheWritebackAll(); + DEBUG_ENTER_FUNC(); + // The screen is always completely updated anyway, so we don't have to force a full update here. + _screen.unlock(); + + DEBUG_EXIT_FUNC(); } void OSystem_PSP::updateScreen() { - u32 now = getMillis(); - if (now - _lastScreenUpdate < 1000 / MAX_FPS) - return; - - _lastScreenUpdate = now; - - sceGuStart(0, displayList); - - sceGuClearColor(0xFF000000); - sceGuClear(GU_COLOR_BUFFER_BIT); - - sceGuClutMode(GU_PSM_5551, 0, 0xFF, 0); - sceGuClutLoad(32, clut256); // upload 32*8 entries (256) - sceGuTexMode(GU_PSM_T8, 0, 0, 0); // 8-bit image - if (_screenWidth == 320) - sceGuTexImage(0, 512, 256, _screenWidth, _offscreen); - else - sceGuTexImage(0, 512, 512, _screenWidth, _offscreen); - sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB); - sceGuTexFilter(GU_LINEAR, GU_LINEAR); - sceGuTexOffset(0,0); - sceGuAmbientColor(0xFFFFFFFF); - sceGuColor(0xFFFFFFFF); - - Vertex *vertices = (Vertex *)sceGuGetMemory(2 * sizeof(Vertex)); - vertices[0].u = 0.5f; - vertices[0].v = 0.5f; - vertices[1].u = _screenWidth - 0.5f; - vertices[1].v = _screenHeight - 0.5f; - - switch (_graphicMode) { - case CENTERED_320X200: - vertices[0].x = (PSP_SCREEN_WIDTH - 320) / 2; - vertices[0].y = (PSP_SCREEN_HEIGHT - 200) / 2; - vertices[0].z = 0; - vertices[1].x = PSP_SCREEN_WIDTH - (PSP_SCREEN_WIDTH - 320) / 2; - vertices[1].y = PSP_SCREEN_HEIGHT - (PSP_SCREEN_HEIGHT - 200) / 2; - vertices[1].z = 0; - break; - case CENTERED_435X272: - vertices[0].x = (PSP_SCREEN_WIDTH - 435) / 2; - vertices[0].y = 0; vertices[0].z = 0; - vertices[1].x = PSP_SCREEN_WIDTH - (PSP_SCREEN_WIDTH - 435) / 2; - vertices[1].y = PSP_SCREEN_HEIGHT; - vertices[1].z = 0; - break; - case STRETCHED_480X272: - vertices[0].x = 0; - vertices[0].y = 0; - vertices[0].z = 0; - vertices[1].x = PSP_SCREEN_WIDTH; - vertices[1].y = PSP_SCREEN_HEIGHT; - vertices[1].z = 0; - break; - case CENTERED_362X272: - vertices[0].x = (PSP_SCREEN_WIDTH - 362) / 2; - vertices[0].y = 0; - vertices[0].z = 0; - vertices[1].x = PSP_SCREEN_WIDTH - (PSP_SCREEN_WIDTH - 362) / 2; - vertices[1].y = PSP_SCREEN_HEIGHT; - vertices[1].z = 0; - break; - } - - if (_shakePos) { - vertices[0].y += _shakePos; - vertices[1].y += _shakePos; - } - - sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices); - if (_screenWidth == 640) { - // 2nd draw - Vertex *vertices2 = (Vertex *)sceGuGetMemory(2 * sizeof(Vertex)); - sceGuTexImage(0, 512, 512, _screenWidth, _offscreen+512); - vertices2[0].u = 512 + 0.5f; - vertices2[0].v = vertices[0].v; - vertices2[1].u = vertices[1].u; - vertices2[1].v = _screenHeight - 0.5f; - vertices2[0].x = vertices[0].x + (vertices[1].x - vertices[0].x) * 511 / 640; - vertices2[0].y = 0; - vertices2[0].z = 0; - vertices2[1].x = vertices[1].x; - vertices2[1].y = vertices[1].y; - vertices2[1].z = 0; - sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices2); - } - - - // draw overlay - if (_overlayVisible) { - Vertex *vertOverlay = (Vertex *)sceGuGetMemory(2 * sizeof(Vertex)); - vertOverlay[0].x = 0; - vertOverlay[0].y = 0; - vertOverlay[0].z = 0; - vertOverlay[1].x = PSP_SCREEN_WIDTH; - vertOverlay[1].y = PSP_SCREEN_HEIGHT; - vertOverlay[1].z = 0; - vertOverlay[0].u = 0.5f; - vertOverlay[0].v = 0.5f; - vertOverlay[1].u = _overlayWidth - 0.5f; - vertOverlay[1].v = _overlayHeight - 0.5f; - sceGuTexMode(GU_PSM_4444, 0, 0, 0); // 16-bit image - sceGuDisable(GU_ALPHA_TEST); - sceGuEnable(GU_BLEND); - - //sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); - sceGuBlendFunc(GU_ADD, GU_FIX, GU_ONE_MINUS_SRC_ALPHA, 0xFFFFFFFF, 0); - - if (_overlayWidth > 320) - sceGuTexImage(0, 512, 512, _overlayWidth, _overlayBuffer); - else - sceGuTexImage(0, 512, 256, _overlayWidth, _overlayBuffer); - - sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); - sceGuDrawArray(GU_SPRITES,GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D,2,0,vertOverlay); - // need to render twice for textures > 512 - if ( _overlayWidth > 512) { - Vertex *vertOverlay2 = (Vertex *)sceGuGetMemory(2 * sizeof(Vertex)); - sceGuTexImage(0, 512, 512, _overlayWidth, _overlayBuffer + 512); - vertOverlay2[0].u = 512 + 0.5f; - vertOverlay2[0].v = vertOverlay[0].v; - vertOverlay2[1].u = vertOverlay[1].u; - vertOverlay2[1].v = _overlayHeight - 0.5f; - vertOverlay2[0].x = PSP_SCREEN_WIDTH * 512 / 640; - vertOverlay2[0].y = 0; - vertOverlay2[0].z = 0; - vertOverlay2[1].x = PSP_SCREEN_WIDTH; - vertOverlay2[1].y = PSP_SCREEN_HEIGHT; - vertOverlay2[1].z = 0; - sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertOverlay2); - } - sceGuDisable(GU_BLEND); - } + DEBUG_ENTER_FUNC(); - // draw mouse - if (_mouseVisible) { - sceGuTexMode(GU_PSM_T8, 0, 0, 0); // 8-bit image - sceGuClutMode(GU_PSM_5551, 0, 0xFF, 0); - sceGuClutLoad(32, _cursorPaletteDisabled ? mouseClut : cursorPalette); // upload 32*8 entries (256) - sceGuAlphaFunc(GU_GREATER, 0, 0xFF); - sceGuEnable(GU_ALPHA_TEST); - sceGuTexImage(0, MOUSE_SIZE, MOUSE_SIZE, MOUSE_SIZE, _mouseBuf); - sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA); - - Vertex *vertMouse = (Vertex *)sceGuGetMemory(2 * sizeof(Vertex)); - vertMouse[0].u = 0.5f; - vertMouse[0].v = 0.5f; - vertMouse[1].u = _mouseWidth - 0.5f; - vertMouse[1].v = _mouseHeight - 0.5f; - - //adjust cursor position - int mX = _mouseX - _mouseHotspotX; - int mY = _mouseY - _mouseHotspotY; - - if (_overlayVisible) { - float scalex, scaley; - - scalex = (float)PSP_SCREEN_WIDTH /_overlayWidth; - scaley = (float)PSP_SCREEN_HEIGHT /_overlayHeight; - - vertMouse[0].x = mX * scalex; - vertMouse[0].y = mY * scaley; - vertMouse[0].z = 0; - vertMouse[1].x = vertMouse[0].x + _mouseWidth * scalex; - vertMouse[1].y = vertMouse[0].y + _mouseHeight * scaley; - vertMouse[1].z = 0; - } else - switch (_graphicMode) { - case CENTERED_320X200: - vertMouse[0].x = (PSP_SCREEN_WIDTH - 320) / 2 + mX; - vertMouse[0].y = (PSP_SCREEN_HEIGHT - 200) / 2 + mY; - vertMouse[0].z = 0; - vertMouse[1].x = vertMouse[0].x + _mouseWidth; - vertMouse[1].y = vertMouse[0].y + _mouseHeight; - vertMouse[1].z = 0; - break; - case CENTERED_435X272: - { - float scalex, scaley; - - scalex = 435.0f / _screenWidth; - scaley = 272.0f / _screenHeight; - - vertMouse[0].x = (PSP_SCREEN_WIDTH - 435) / 2 + mX * scalex; - vertMouse[0].y = mY * scaley; - vertMouse[0].z = 0; - vertMouse[1].x = vertMouse[0].x + _mouseWidth * scalex; - vertMouse[1].y = vertMouse[0].y + _mouseHeight * scaley; - vertMouse[1].z = 0; - } - break; - case CENTERED_362X272: - { - float scalex, scaley; - - scalex = 362.0f / _screenWidth; - scaley = 272.0f / _screenHeight; - - vertMouse[0].x = (PSP_SCREEN_WIDTH - 362) / 2 + mX * scalex; - vertMouse[0].y = mY * scaley; - vertMouse[0].z = 0; - vertMouse[1].x = vertMouse[0].x + _mouseWidth * scalex; - vertMouse[1].y = vertMouse[0].y + _mouseHeight * scaley; - vertMouse[1].z = 0; - } - break; - case STRETCHED_480X272: - { - float scalex, scaley; - - scalex = (float)PSP_SCREEN_WIDTH / _screenWidth; - scaley = (float)PSP_SCREEN_HEIGHT / _screenHeight; - - vertMouse[0].x = mX * scalex; - vertMouse[0].y = mY * scaley; - vertMouse[0].z = 0; - vertMouse[1].x = vertMouse[0].x + _mouseWidth * scalex; - vertMouse[1].y = vertMouse[0].y + _mouseHeight * scaley; - vertMouse[1].z = 0; - } - break; - } - sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertMouse); - } - - if (_keyboard->isVisible()) { - _keyboard->render(); - } - - sceGuFinish(); - sceGuSync(0,0); - - sceDisplayWaitVblankStart(); - sceGuSwapBuffers(); + _displayManager.renderAll(); + + DEBUG_EXIT_FUNC(); } void OSystem_PSP::setShakePos(int shakeOffset) { - _shakePos = shakeOffset; + DEBUG_ENTER_FUNC(); + + _screen.setShakePos(shakeOffset); + + DEBUG_EXIT_FUNC(); } void OSystem_PSP::showOverlay() { - _overlayVisible = true; + DEBUG_ENTER_FUNC(); + + _overlay.setVisible(true); + _cursor.setLimits(_overlay.getWidth(), _overlay.getHeight()); + _cursor.useGlobalScaler(false); // mouse with overlay is 1:1 + + DEBUG_EXIT_FUNC(); } void OSystem_PSP::hideOverlay() { - PSPDebugTrace("OSystem_PSP::hideOverlay called\n"); - _overlayVisible = false; + DEBUG_ENTER_FUNC(); + + _overlay.setVisible(false); + _cursor.setLimits(_screen.getWidth(), _screen.getHeight()); + _cursor.useGlobalScaler(true); // mouse needs to be scaled with screen + + DEBUG_EXIT_FUNC(); } void OSystem_PSP::clearOverlay() { - PSPDebugTrace("clearOverlay\n"); + DEBUG_ENTER_FUNC(); - bzero(_overlayBuffer, _overlayWidth * _overlayHeight * sizeof(OverlayColor)); - sceKernelDcacheWritebackAll(); -} + _overlay.clearBuffer(); -void OSystem_PSP::grabOverlay(OverlayColor *buf, int pitch) { - int h = _overlayHeight; - OverlayColor *src = _overlayBuffer; - - do { - memcpy(buf, src, _overlayWidth * sizeof(OverlayColor)); - src += _overlayWidth; - buf += pitch; - } while (--h); + DEBUG_EXIT_FUNC(); } -void OSystem_PSP::copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h) { - PSPDebugTrace("copyRectToOverlay\n"); - - //Clip the coordinates - if (x < 0) { - w += x; - buf -= x; - x = 0; - } - - if (y < 0) { - h += y; - buf -= y * pitch; - y = 0; - } +void OSystem_PSP::grabOverlay(OverlayColor *buf, int pitch) { + DEBUG_ENTER_FUNC(); - if (w > _overlayWidth - x) { - w = _overlayWidth - x; - } + _overlay.copyToArray(buf, pitch); - if (h > _overlayHeight - y) { - h = _overlayHeight - y; - } - - if (w <= 0 || h <= 0) - return; + DEBUG_EXIT_FUNC(); +} +void OSystem_PSP::copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h) { + DEBUG_ENTER_FUNC(); - OverlayColor *dst = _overlayBuffer + (y * _overlayWidth + x); + _overlay.copyFromRect(buf, pitch, x, y, w, h); - if (_overlayWidth == pitch && pitch == w) { - memcpy(dst, buf, h * w * sizeof(OverlayColor)); - } else { - do { - memcpy(dst, buf, w * sizeof(OverlayColor)); - buf += pitch; - dst += _overlayWidth; - } while (--h); - } - sceKernelDcacheWritebackAll(); + DEBUG_EXIT_FUNC(); } int16 OSystem_PSP::getOverlayWidth() { - return _overlayWidth; + return (int16) _overlay.getWidth(); } int16 OSystem_PSP::getOverlayHeight() { - return _overlayHeight; + return (int16) _overlay.getHeight(); } - void OSystem_PSP::grabPalette(byte *colors, uint start, uint num) { - uint i; - uint16 color; - - for (i = start; i < start + num; i++) { - color = _palette[i]; - *colors++ = ((color & 0x1F) << 3); - *colors++ = (((color >> 5) & 0x1F) << 3); - *colors++ = (((color >> 10) & 0x1F) << 3); - *colors++ = (color & 0x8000 ? 255 : 0); - } + DEBUG_ENTER_FUNC(); + + _screen.getPartialPalette(colors, start, num); + + DEBUG_EXIT_FUNC(); } -bool OSystem_PSP::showMouse(bool visible) { - bool last = _mouseVisible; - _mouseVisible = visible; +bool OSystem_PSP::showMouse(bool v) { + DEBUG_ENTER_FUNC(); + + PSP_DEBUG_PRINT("%s\n", v ? "true" : "false"); + bool last = _cursor.isVisible(); + _cursor.setVisible(v); + + DEBUG_EXIT_FUNC(); + return last; } void OSystem_PSP::warpMouse(int x, int y) { - //assert(x > 0 && x < _screenWidth); - //assert(y > 0 && y < _screenHeight); - _mouseX = x; - _mouseY = y; -} + DEBUG_ENTER_FUNC(); -void OSystem_PSP::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) { - //TODO: handle cursorTargetScale - _mouseWidth = w; - _mouseHeight = h; - - _mouseHotspotX = hotspotX; - _mouseHotspotY = hotspotY; - - _mouseKeyColour = keycolor & 0xFF; - - memcpy(mouseClut, _palette, 256 * sizeof(unsigned short)); - mouseClut[_mouseKeyColour] = 0; - - for (unsigned int i = 0; i < h; i++) - memcpy(_mouseBuf + i * MOUSE_SIZE, buf + i * w, w); - - sceKernelDcacheWritebackAll(); + _cursor.setXY(x,y); + + DEBUG_EXIT_FUNC(); } -#define PAD_CHECK_TIME 40 -#define PAD_DIR_MASK (PSP_CTRL_UP | PSP_CTRL_DOWN | PSP_CTRL_LEFT | PSP_CTRL_RIGHT) - -bool OSystem_PSP::processInput(Common::Event &event) { - s8 analogStepAmountX = 0; - s8 analogStepAmountY = 0; - - sceCtrlSetSamplingCycle(0); - sceCtrlSetSamplingMode(1); - sceCtrlReadBufferPositive(&pad, 1); - - bool usedInput, haveEvent; - - haveEvent = _keyboard->processInput(event, pad, usedInput); - - if (usedInput) // Check if the keyboard used up the input - return haveEvent; - - uint32 buttonsChanged = pad.Buttons ^ _prevButtons; - - int newDpadX = 0, newDpadY = 0; - event.kbd.ascii = 0; - event.kbd.flags = 0; - - if (pad.Buttons & PSP_CTRL_UP) { - newDpadY += 1; - if (pad.Buttons & PSP_CTRL_RTRIGGER) - newDpadX += 1; - } - if (pad.Buttons & PSP_CTRL_RIGHT) { - newDpadX += 1; - if (pad.Buttons & PSP_CTRL_RTRIGGER) - newDpadY -= 1; - } - if (pad.Buttons & PSP_CTRL_DOWN) { - newDpadY -= 1; - if (pad.Buttons & PSP_CTRL_RTRIGGER) - newDpadX -= 1; - } - if (pad.Buttons & PSP_CTRL_LEFT) { - newDpadX -= 1; - if (pad.Buttons & PSP_CTRL_RTRIGGER) - newDpadY += 1; - } - //fprintf(stderr, "x=%d, y=%d, oldx=%d, oldy=%d\n", newDpadX, newDpadY, _dpadX, _dpadY); - if (newDpadX != _dpadX || newDpadY != _dpadY) { - if (_dpadX == 0 && _dpadY == 0) {// We pressed dpad - event.type = Common::EVENT_KEYDOWN; - event.kbd.keycode = getDpadEvent(newDpadX, newDpadY); - event.kbd.ascii = event.kbd.keycode - Common::KEYCODE_KP0 + '0'; - _dpadX = newDpadX; - _dpadY = newDpadY; - } - else if (newDpadX == 0 && newDpadY == 0) {// We unpressed dpad - event.type = Common::EVENT_KEYUP; - event.kbd.keycode = getDpadEvent(_dpadX, _dpadY); - event.kbd.ascii = event.kbd.keycode - Common::KEYCODE_KP0 + '0'; - _dpadX = newDpadX; - _dpadY = newDpadY; - } else { // we moved from one pressed dpad to another one - event.type = Common::EVENT_KEYUP; // first release the last dpad direction - event.kbd.keycode = getDpadEvent(_dpadX, _dpadY); - event.kbd.ascii = event.kbd.keycode - Common::KEYCODE_KP0 + '0'; - _dpadX = 0; // so that we'll pick up a new dpad movement - _dpadY = 0; - } - - _prevButtons = pad.Buttons; - return true; - - } else if (buttonsChanged & (PSP_CTRL_CROSS | PSP_CTRL_CIRCLE | PSP_CTRL_LTRIGGER | PSP_CTRL_RTRIGGER | PSP_CTRL_START | - PSP_CTRL_SELECT | PSP_CTRL_SQUARE | PSP_CTRL_TRIANGLE)) { - if (buttonsChanged & PSP_CTRL_CROSS) { - event.type = (pad.Buttons & PSP_CTRL_CROSS) ? Common::EVENT_LBUTTONDOWN : Common::EVENT_LBUTTONUP; - } else if (buttonsChanged & PSP_CTRL_CIRCLE) { - event.type = (pad.Buttons & PSP_CTRL_CIRCLE) ? Common::EVENT_RBUTTONDOWN : Common::EVENT_RBUTTONUP; - } else { - //any of the other buttons. - event.type = buttonsChanged & pad.Buttons ? Common::EVENT_KEYDOWN : Common::EVENT_KEYUP; - - if (buttonsChanged & PSP_CTRL_LTRIGGER) { - event.kbd.keycode = Common::KEYCODE_ESCAPE; - event.kbd.ascii = 27; - } else if (buttonsChanged & PSP_CTRL_START) { - event.kbd.keycode = Common::KEYCODE_F5; - event.kbd.ascii = Common::ASCII_F5; - if (pad.Buttons & PSP_CTRL_RTRIGGER) { - event.kbd.flags = Common::KBD_CTRL; // Main menu to allow RTL - } -/* } else if (buttonsChanged & PSP_CTRL_SELECT) { - event.kbd.keycode = Common::KEYCODE_0; - event.kbd.ascii = '0'; -*/ } else if (buttonsChanged & PSP_CTRL_SQUARE) { - event.kbd.keycode = Common::KEYCODE_PERIOD; - event.kbd.ascii = '.'; - } else if (buttonsChanged & PSP_CTRL_TRIANGLE) { - event.kbd.keycode = Common::KEYCODE_RETURN; - event.kbd.ascii = 13; - } else if (pad.Buttons & PSP_CTRL_RTRIGGER) { - event.kbd.flags |= Common::KBD_SHIFT; - } - - } - - event.mouse.x = _mouseX; - event.mouse.y = _mouseY; - _prevButtons = pad.Buttons; - return true; - } - - uint32 time = getMillis(); - if (time - _lastPadCheck > PAD_CHECK_TIME) { - _lastPadCheck = time; - int16 newX = _mouseX; - int16 newY = _mouseY; - - if (pad.Lx < 100) { - analogStepAmountX = pad.Lx - 100; - } else if (pad.Lx > 155) { - analogStepAmountX = pad.Lx - 155; - } - - if (pad.Ly < 100) { - analogStepAmountY = pad.Ly - 100; - } else if (pad.Ly > 155) { - analogStepAmountY = pad.Ly - 155; - } - - if (analogStepAmountX != 0 || analogStepAmountY != 0) { - - _prevButtons = pad.Buttons; - - // If no movement then this has no effect - if (pad.Buttons & PSP_CTRL_RTRIGGER) { - // Fine control mode for analog - if (analogStepAmountX != 0) { - if (analogStepAmountX > 0) - newX += 1; - else - newX -= 1; - } - - if (analogStepAmountY != 0) { - if (analogStepAmountY > 0) - newY += 1; - else - newY -= 1; - } - } else { - newX += analogStepAmountX >> ((_screenWidth == 640) ? 2 : 3); - newY += analogStepAmountY >> ((_screenWidth == 640) ? 2 : 3); - } - - if (newX < 0) - newX = 0; - if (newY < 0) - newY = 0; - if (_overlayVisible) { - if (newX >= _overlayWidth) - newX = _overlayWidth - 1; - if (newY >= _overlayHeight) - newY = _overlayHeight - 1; - } else { - if (newX >= _screenWidth) - newX = _screenWidth - 1; - if (newY >= _screenHeight) - newY = _screenHeight - 1; - } - - if ((_mouseX != newX) || (_mouseY != newY)) { - event.type = Common::EVENT_MOUSEMOVE; - event.mouse.x = _mouseX = newX; - event.mouse.y = _mouseY = newY; - return true; - } - } - } - - return false; -} +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(); -inline Common::KeyCode OSystem_PSP::getDpadEvent(int x, int y) { - Common::KeyCode key; - - if (x == -1) { - if (y == -1) - key = Common::KEYCODE_KP1; - else if (y == 0) - key = Common::KEYCODE_KP4; - else /* y == 1 */ - key = Common::KEYCODE_KP7; - } else if (x == 0) { - if (y == -1) - key = Common::KEYCODE_KP2; - else /* y == 1 */ - key = Common::KEYCODE_KP8; - } else {/* x == 1 */ - if (y == -1) - key = Common::KEYCODE_KP3; - else if (y == 0) - key = Common::KEYCODE_KP6; - else /* y == 1 */ - key = Common::KEYCODE_KP9; + 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); } - - return key; + + _cursor.setKeyColor(keycolor); + _cursor.setCursorTargetScale(cursorTargetScale); + _cursor.setSizeAndScummvmPixelFormat(w, h, format); + _cursor.setHotspot(hotspotX, hotspotY); + _cursor.clearKeyColor(); + _cursor.copyFromArray(buf); + + DEBUG_EXIT_FUNC(); } bool OSystem_PSP::pollEvent(Common::Event &event) { @@ -905,8 +369,7 @@ bool OSystem_PSP::pollEvent(Common::Event &event) { PowerMan.pollPauseEngine(); - return processInput(event); - + return _inputHandler.getAllInputs(event); } @@ -997,7 +460,6 @@ void OSystem_PSP::setupMixer(void) { void OSystem_PSP::quit() { SDL_CloseAudio(); SDL_Quit(); - sceGuTerm(); sceKernelExitGame(); } |