aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/psp/osys_psp.cpp
diff options
context:
space:
mode:
authorJoost Peters2009-08-21 22:30:35 +0000
committerJoost Peters2009-08-21 22:30:35 +0000
commit9a3218e67302e825b3df4e2f26df5601fb48f0db (patch)
tree21da52ccd6589d3ddffe4803c16953deb77855fa /backends/platform/psp/osys_psp.cpp
parent894635e91d7bdaa4517618a957441db016b2798b (diff)
downloadscummvm-rg350-9a3218e67302e825b3df4e2f26df5601fb48f0db.tar.gz
scummvm-rg350-9a3218e67302e825b3df4e2f26df5601fb48f0db.tar.bz2
scummvm-rg350-9a3218e67302e825b3df4e2f26df5601fb48f0db.zip
unify OSystem_PSP_GU and OSystem_PSP (which was hopelessly outdated and mostly useless)
svn-id: r43615
Diffstat (limited to 'backends/platform/psp/osys_psp.cpp')
-rw-r--r--backends/platform/psp/osys_psp.cpp564
1 files changed, 502 insertions, 62 deletions
diff --git a/backends/platform/psp/osys_psp.cpp b/backends/platform/psp/osys_psp.cpp
index d4b1c61537..a9e9aeb7d8 100644
--- a/backends/platform/psp/osys_psp.cpp
+++ b/backends/platform/psp/osys_psp.cpp
@@ -23,12 +23,19 @@
*
*/
+#include <pspgu.h>
+#include <pspdisplay.h>
+
+#include <time.h>
+#include <zlib.h>
+
#include "common/config-manager.h"
#include "common/events.h"
#include "common/rect.h"
#include "common/scummsys.h"
#include "osys_psp.h"
+#include "trace.h"
#include "backends/saves/psp/psp-saves.h"
#include "backends/timer/default/default-timer.h"
@@ -36,30 +43,62 @@
#include "graphics/scaler.h"
#include "sound/mixer_intern.h"
-#include <pspgu.h>
-#include <pspdisplay.h>
-
-#include <time.h>
-
-#include "./trace.h"
#define SAMPLES_PER_SEC 44100
#define SCREEN_WIDTH 480
#define SCREEN_HEIGHT 272
+#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[262144];
+unsigned short __attribute__((aligned(16))) clut256[256];
+unsigned short __attribute__((aligned(16))) mouseClut[256];
+unsigned short __attribute__((aligned(16))) cursorPalette[256];
+unsigned short __attribute__((aligned(16))) kbClut[256];
+//unsigned int __attribute__((aligned(16))) offscreen256[640*480];
+//unsigned int __attribute__((aligned(16))) overlayBuffer256[640*480*2];
+unsigned int __attribute__((aligned(16))) mouseBuf256[MOUSE_SIZE*MOUSE_SIZE];
+
+extern unsigned long RGBToColour(unsigned long r, unsigned long g, unsigned long b);
+
+extern unsigned int size_keyboard_symbols_compressed;
+extern unsigned char keyboard_symbols_compressed[];
+extern unsigned int size_keyboard_symbols_shift_compressed;
+extern unsigned char keyboard_symbols_shift_compressed[];
+extern unsigned int size_keyboard_letters_compressed;
+extern unsigned char keyboard_letters_compressed[];
+extern unsigned int size_keyboard_letters_shift_compressed;
+extern unsigned char keyboard_letters_shift_compressed[];
+unsigned char *keyboard_symbols;
+unsigned char *keyboard_symbols_shift;
+unsigned char *keyboard_letters;
+unsigned char *keyboard_letters_shift;
+
+unsigned char kbd_ascii[] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '[', ']', '\\', ';', '\'', ',', '.', '/', '`'};
+Common::KeyCode kbd_code[] = {Common::KEYCODE_1, Common::KEYCODE_2, Common::KEYCODE_3, Common::KEYCODE_4, Common::KEYCODE_5, Common::KEYCODE_6, Common::KEYCODE_7, Common::KEYCODE_8, Common::KEYCODE_9, Common::KEYCODE_0, Common::KEYCODE_MINUS, Common::KEYCODE_EQUALS, Common::KEYCODE_LEFTBRACKET, Common::KEYCODE_RIGHTBRACKET,
+ Common::KEYCODE_BACKSLASH, Common::KEYCODE_SEMICOLON, Common::KEYCODE_QUOTE, Common::KEYCODE_COMMA, Common::KEYCODE_PERIOD, Common::KEYCODE_SLASH, Common::KEYCODE_BACKQUOTE};
+unsigned char kbd_ascii_cl[] = {'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '{', '}', '|', ':', '"', '<', '>', '?', '~'};
+Common::KeyCode kbd_code_cl[] = {Common::KEYCODE_EXCLAIM, Common::KEYCODE_AT, Common::KEYCODE_HASH, Common::KEYCODE_DOLLAR, (Common::KeyCode)37, Common::KEYCODE_CARET, Common::KEYCODE_AMPERSAND, Common::KEYCODE_ASTERISK, Common::KEYCODE_LEFTPAREN, Common::KEYCODE_RIGHTPAREN, Common::KEYCODE_UNDERSCORE,
+ Common::KEYCODE_PLUS, (Common::KeyCode)123, (Common::KeyCode)125, (Common::KeyCode)124, Common::KEYCODE_COLON, Common::KEYCODE_QUOTEDBL, Common::KEYCODE_LESS, Common::KEYCODE_GREATER, Common::KEYCODE_QUESTION, (Common::KeyCode)126};
+#define CAPS_LOCK (1 << 0)
+#define SYMBOLS (1 << 1)
+
+
-unsigned short *DrawBuffer = (unsigned short *)0x44044000;
-unsigned short *DisplayBuffer = (unsigned short *)0x44000000;
unsigned long RGBToColour(unsigned long r, unsigned long g, unsigned long b) {
return (((b >> 3) << 10) | ((g >> 3) << 5) | ((r >> 3) << 0)) | 0x8000;
}
-void putPixel(uint16 x, uint16 y, unsigned long colour) {
- *(unsigned short *)(DrawBuffer + (y << 9) + x ) = colour;
-}
-
static int timer_handler(int t) {
DefaultTimerManager *tm = (DefaultTimerManager *)g_system->getTimerManager();
tm->handler();
@@ -76,7 +115,6 @@ const OSystem::GraphicsMode OSystem_PSP::s_supportedGraphicsModes[] = {
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), _padAccel(0), _mixer(0) {
-
memset(_palette, 0, sizeof(_palette));
_cursorPaletteDisabled = true;
@@ -87,15 +125,75 @@ OSystem_PSP::OSystem_PSP() : _screenWidth(0), _screenHeight(0), _overlayWidth(0)
uint32 sdlFlags = SDL_INIT_AUDIO | SDL_INIT_TIMER;
SDL_Init(sdlFlags);
- sceDisplaySetMode(0, SCREEN_WIDTH, SCREEN_HEIGHT);
- sceDisplaySetFrameBuf((char *)DisplayBuffer, 512, 1, 1);
+
+ //sceKernelDcacheWritebackAll();
+
+ // setup
+ 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);
+
+ //decompress keyboard data
+ uLongf kbdSize = KBD_DATA_SIZE;
+ keyboard_letters = (unsigned char *)memalign(16, KBD_DATA_SIZE);
+ if (Z_OK != uncompress((Bytef *)keyboard_letters, &kbdSize, (const Bytef *)keyboard_letters_compressed, size_keyboard_letters_compressed))
+ error("OSystem_PSP: uncompressing keyboard_letters failed");
+
+ kbdSize = KBD_DATA_SIZE;
+ keyboard_letters_shift = (unsigned char *)memalign(16, KBD_DATA_SIZE);
+ if (Z_OK != uncompress((Bytef *)keyboard_letters_shift, &kbdSize, (const Bytef *)keyboard_letters_shift_compressed, size_keyboard_letters_shift_compressed))
+ error("OSystem_PSP: uncompressing keyboard_letters_shift failed");
+
+ kbdSize = KBD_DATA_SIZE;
+ keyboard_symbols = (unsigned char *)memalign(16, KBD_DATA_SIZE);
+ if (Z_OK != uncompress((Bytef *)keyboard_symbols, &kbdSize, (const Bytef *)keyboard_symbols_compressed, size_keyboard_symbols_compressed))
+ error("OSystem_PSP: uncompressing keyboard_symbols failed");
+
+ kbdSize = KBD_DATA_SIZE;
+ keyboard_symbols_shift = (unsigned char *)memalign(16, KBD_DATA_SIZE);
+ if (Z_OK != uncompress((Bytef *)keyboard_symbols_shift, &kbdSize, (const Bytef *)keyboard_symbols_shift_compressed, size_keyboard_symbols_shift_compressed))
+ error("OSystem_PSP: uncompressing keyboard_symbols_shift failed");
+
+ _keyboardVisible = false;
+ _clut = (unsigned short *)(((unsigned int)clut256) | 0x40000000);
+ _kbdClut = (unsigned short *)(((unsigned int)kbClut) | 0x40000000);
+ _mouseBuf = (byte *)mouseBuf256;
+ _graphicMode = STRETCHED_480X272;
+ _keySelected = 1;
+ _keyboardMode = 0;
+ _mouseX = PSP_SCREEN_WIDTH >> 1;
+ _mouseY = PSP_SCREEN_HEIGHT >> 1;
}
OSystem_PSP::~OSystem_PSP() {
+ free(keyboard_symbols_shift);
+ free(keyboard_symbols);
+ free(keyboard_letters_shift);
+ free(keyboard_letters);
+
free(_offscreen);
free(_overlayBuffer);
free(_mouseBuf);
+
+ _offscreen = 0;
+ _overlayBuffer = 0;
+ _mouseBuf = 0;
+ sceGuTerm();
}
@@ -128,36 +226,54 @@ const OSystem::GraphicsMode* OSystem_PSP::getSupportedGraphicsModes() const {
int OSystem_PSP::getDefaultGraphicsMode() const {
- return -1;
+ return STRETCHED_480X272;
}
bool OSystem_PSP::setGraphicsMode(int mode) {
+ _graphicMode = mode;
return true;
}
bool OSystem_PSP::setGraphicsMode(const char *name) {
- return true;
+ 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;
}
int OSystem_PSP::getGraphicsMode() const {
- return -1;
+ return _graphicMode;
}
void OSystem_PSP::initSize(uint width, uint height, const Graphics::PixelFormat *format) {
- _overlayWidth = _screenWidth = width;
- _overlayHeight = _screenHeight = height;
-
- free(_offscreen);
+ PSPDebugTrace("initSize\n");
+ _screenWidth = width;
+ _screenHeight = height;
- _offscreen = (byte *)malloc(width * height);
+ _overlayWidth = PSP_SCREEN_WIDTH; //width;
+ _overlayHeight = PSP_SCREEN_HEIGHT; //height;
- free(_overlayBuffer);
+// _offscreen = (byte *)offscreen256;
+ _overlayBuffer = (OverlayColor *)0x44000000 + PSP_FRAME_SIZE;
- _overlayBuffer = (OverlayColor *)malloc(_overlayWidth * _overlayHeight * sizeof(OverlayColor));
+ _offscreen = (byte *)_overlayBuffer + _overlayWidth * _overlayHeight * sizeof(OverlayColor);
bzero(_offscreen, width * height);
clearOverlay();
-
+ memset(_palette, 0xFFFF, 256 * sizeof(unsigned short));
+ _kbdClut[0] = 0xFFFF;
+ _kbdClut[246] = 0x4CCC;
+ _kbdClut[247] = 0x0000;
+ for (int i = 1; i < 31; i++)
+ _kbdClut[i] = 0xF888;
_mouseVisible = false;
+ sceKernelDcacheWritebackAll();
}
int16 OSystem_PSP::getWidth() {
@@ -175,6 +291,34 @@ void OSystem_PSP::setPalette(const byte *colors, uint start, uint num) {
_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();
+}
+
+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;
+
+ _cursorPaletteDisabled = false;
+
+ sceKernelDcacheWritebackAll();
+}
+
+void OSystem_PSP::disableCursorPalette(bool disable) {
+ _cursorPaletteDisabled = disable;
}
void OSystem_PSP::copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h) {
@@ -204,10 +348,21 @@ void OSystem_PSP::copyRectToScreen(const byte *buf, int pitch, int x, int y, int
byte *dst = _offscreen + y * _screenWidth + x;
- if (_screenWidth == pitch && pitch == w) {
+
+ if (_screenWidth == pitch && pitch == w)
+ {
memcpy(dst, buf, h * w);
- } else {
- do {
+/*
+ sceGuStart(0, displayList);
+ sceGuCopyImage( 3, 0, 0, w/2, h, w/2, (void *)buf, x/2, y, _screenWidth /2, _offscreen);
+ sceGuFinish();
+ sceGuSync(0,0);
+*/
+ }
+ else
+ {
+ do
+ {
memcpy(dst, buf, w);
buf += pitch;
dst += _screenWidth;
@@ -230,52 +385,205 @@ void OSystem_PSP::unlockScreen() {
}
void OSystem_PSP::updateScreen() {
- unsigned short *temp;
+ u32 now = getMillis();
+ if (now - _lastScreenUpdate < 1000 / MAX_FPS)
+ return;
- uint xStart = (SCREEN_WIDTH >> 1) - (_screenWidth >> 1);
- uint yStart = (SCREEN_HEIGHT >> 1) - (_screenHeight >> 1);
+ _lastScreenUpdate = now;
- for (int i = 0; i < _screenHeight; ++i) {
- for (int j = 0; j < _screenWidth; ++j) {
- putPixel(xStart + j, yStart + i, _palette[_offscreen[i * _screenWidth +j]]);
- }
+
+ 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);
+
+ struct Vertex* vertices = (struct Vertex*)sceGuGetMemory(2 * sizeof(struct Vertex));
+ vertices[0].u = 0.5; vertices[0].v = 0.5;
+ vertices[1].u = _screenWidth - 0.5; vertices[1].v = _screenHeight - 0.5;
+ 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 (_overlayVisible) {
- for (int i = 0; i < _screenHeight; ++i) {
- for (int j = 0; j < _screenWidth; ++j) {
+ if (_shakePos) {
+ vertices[0].y += _shakePos;
+ vertices[1].y += _shakePos;
+ }
- OverlayColor pixel = _overlayBuffer[(i * _overlayWidth +j)];
+ sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices);
+ if (_screenWidth == 640) {
+ sceGuTexImage(0, 512, 512, _screenWidth, _offscreen+512);
+ vertices[0].u = 512 + 0.5; vertices[1].v = _screenHeight - 0.5;
+ vertices[0].x += (vertices[1].x - vertices[0].x) * 511 / 640; vertices[0].y = 0; vertices[0].z = 0;
+ sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices);
+ }
- if (pixel & 0x8000)
- putPixel(xStart + j, yStart + i, pixel);
- }
+
+ // draw overlay
+ if (_overlayVisible) {
+ 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;
+ vertices[0].u = 0.5; vertices[0].v = 0.5;
+ vertices[1].u = _overlayWidth - 0.5; vertices[1].v = _overlayHeight - 0.5;
+ 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,vertices);
+ // need to render twice for textures > 512
+ if ( _overlayWidth > 512) {
+ sceGuTexImage(0, 512, 512, _overlayWidth, _overlayBuffer + 512);
+ vertices[0].u = 512 + 0.5; vertices[1].v = _overlayHeight - 0.5;
+ vertices[0].x = PSP_SCREEN_WIDTH * 512 / 640; vertices[0].y = 0; vertices[0].z = 0;
+ sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices);
}
+ sceGuDisable(GU_BLEND);
}
- //draw mouse on top
+ // draw mouse
if (_mouseVisible) {
- for (int y = 0; y < _mouseHeight; ++y) {
- for (int x = 0; x < _mouseWidth; ++x) {
- if (_mouseBuf[y * _mouseHeight + x] != _mouseKeyColour) {
- int my = _mouseY + y; // + _mouseHotspotY;
- int mx = _mouseX + x; // + _mouseHotspotX;
-
- if (mx >= 0 && mx < _screenWidth && my >= 0 && my < _screenHeight)
- putPixel(xStart + mx, yStart + my, _palette[_mouseBuf[y * _mouseHeight + x]]);
- }
+ 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);
+
+ vertices[0].u = 0.5; vertices[0].v = 0.5;
+ vertices[1].u = _mouseWidth - 0.5; vertices[1].v = _mouseHeight - 0.5;
+
+ //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;
+
+ vertices[0].x = mX * scalex; vertices[0].y = mY * scaley; vertices[0].z = 0;
+ vertices[1].x = vertices[0].x + _mouseWidth * scalex; vertices[1].y = vertices[0].y + _mouseHeight * scaley; vertices[0].z = 0;
+ } else
+ switch(_graphicMode) {
+ case CENTERED_320X200:
+ vertices[0].x = (PSP_SCREEN_WIDTH - 320) / 2 + mX; vertices[0].y = (PSP_SCREEN_HEIGHT - 200) / 2 + mY; vertices[0].z = 0;
+ vertices[1].x = vertices[0].x+_mouseWidth; vertices[1].y = vertices[0].y + _mouseHeight; vertices[1].z = 0;
+ break;
+ case CENTERED_435X272:
+ {
+ float scalex, scaley;
+
+ scalex = 435.0f / _screenWidth;
+ scaley = 272.0f / _screenHeight;
+
+ vertices[0].x = (PSP_SCREEN_WIDTH - 435) / 2 + mX * scalex; vertices[0].y = mY * scaley; vertices[0].z = 0;
+ vertices[1].x = vertices[0].x + _mouseWidth * scalex; vertices[1].y = vertices[0].y + _mouseHeight * scaley; vertices[0].z = 0;
+
+ }
+ break;
+ case CENTERED_362X272:
+ {
+ float scalex, scaley;
+
+ scalex = 362.0f / _screenWidth;
+ scaley = 272.0f / _screenHeight;
+
+ vertices[0].x = (PSP_SCREEN_WIDTH - 362) / 2 + mX * scalex; vertices[0].y = mY * scaley; vertices[0].z = 0;
+ vertices[1].x = vertices[0].x + _mouseWidth * scalex; vertices[1].y = vertices[0].y + _mouseHeight * scaley; vertices[0].z = 0;
+ }
+ break;
+ case STRETCHED_480X272:
+ {
+ float scalex, scaley;
+
+ scalex = (float)PSP_SCREEN_WIDTH / _screenWidth;
+ scaley = (float)PSP_SCREEN_HEIGHT / _screenHeight;
+
+ vertices[0].x = mX * scalex; vertices[0].y = mY * scaley; vertices[0].z = 0;
+ vertices[1].x = vertices[0].x + _mouseWidth * scalex; vertices[1].y = vertices[0].y + _mouseHeight * scaley; vertices[0].z = 0;
}
+ break;
}
+ sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices);
}
+ if (_keyboardVisible) {
+ sceGuTexMode(GU_PSM_T8, 0, 0, 0); // 8-bit image
+ sceGuClutMode(GU_PSM_4444, 0, 0xFF, 0);
+ sceGuClutLoad(32, kbClut); // upload 32*8 entries (256)
+ sceGuDisable(GU_ALPHA_TEST);
+ sceGuEnable(GU_BLEND);
+ sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
+ switch(_keyboardMode) {
+ case 0:
+ sceGuTexImage(0, 512, 512, 480, keyboard_letters);
+ break;
+ case CAPS_LOCK:
+ sceGuTexImage(0, 512, 512, 480, keyboard_letters_shift);
+ break;
+ case SYMBOLS:
+ sceGuTexImage(0, 512, 512, 480, keyboard_symbols);
+ break;
+ case (CAPS_LOCK | SYMBOLS):
+ sceGuTexImage(0, 512, 512, 480, keyboard_symbols_shift);
+ break;
+ }
+ sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
+
+ vertices[0].u = 0.5; vertices[0].v = 0.5;
+ vertices[1].u = PSP_SCREEN_WIDTH-0.5; vertices[1].v = PSP_SCREEN_HEIGHT-0.5;
+ 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[0].z = 0;
+ sceGuDrawArray(GU_SPRITES,GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D,2,0,vertices);
+ sceGuDisable(GU_BLEND);
+ }
+ sceKernelDcacheWritebackAll();
+
+ sceGuFinish();
+ sceGuSync(0,0);
- // switch buffers
- temp = DrawBuffer;
- DrawBuffer = DisplayBuffer;
- DisplayBuffer = temp;
sceDisplayWaitVblankStart();
- sceDisplaySetFrameBuf((char *)DisplayBuffer, 512, 1, 1);
+ sceGuSwapBuffers();
+ //sceKernelDcacheWritebackAll();
}
void OSystem_PSP::setShakePos(int shakeOffset) {
@@ -392,16 +700,18 @@ void OSystem_PSP::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX,
_mouseKeyColour = keycolor & 0xFF;
- free(_mouseBuf);
+ memcpy(mouseClut, _palette, 256 * sizeof(unsigned short));
+ mouseClut[_mouseKeyColour] = 0;
+ sceKernelDcacheWritebackAll();
- _mouseBuf = (byte *)malloc(w * h);
- memcpy(_mouseBuf, buf, w * h);
+ for (unsigned int i = 0; i < h; i++)
+ memcpy(_mouseBuf + i * MOUSE_SIZE, buf + i * w, w);
}
#define PAD_CHECK_TIME 40
#define PAD_DIR_MASK (PSP_CTRL_UP | PSP_CTRL_DOWN | PSP_CTRL_LEFT | PSP_CTRL_RIGHT)
-bool OSystem_PSP::pollEvent(Common::Event &event) {
+bool OSystem_PSP::processInput(Common::Event &event) {
s8 analogStepAmountX = 0;
s8 analogStepAmountY = 0;
/*
@@ -543,6 +853,136 @@ bool OSystem_PSP::pollEvent(Common::Event &event) {
return false;
}
+bool OSystem_PSP::pollEvent(Common::Event &event) {
+ float nub_angle = -1;
+ int x, y;
+
+ sceCtrlSetSamplingCycle(0);
+ sceCtrlSetSamplingMode(1);
+ sceCtrlReadBufferPositive(&pad, 1);
+
+ uint32 buttonsChanged = pad.Buttons ^ _prevButtons;
+
+ if ((buttonsChanged & PSP_CTRL_SELECT) || (pad.Buttons & PSP_CTRL_SELECT)) {
+ if ( !(pad.Buttons & PSP_CTRL_SELECT) )
+ _keyboardVisible = !_keyboardVisible;
+ _prevButtons = pad.Buttons;
+ return false;
+ }
+
+ if (!_keyboardVisible)
+ return processInput(event);
+
+ if ( (buttonsChanged & PSP_CTRL_RTRIGGER) && !(pad.Buttons & PSP_CTRL_RTRIGGER))
+ _keyboardMode ^= CAPS_LOCK;
+
+ if ( (buttonsChanged & PSP_CTRL_LTRIGGER) && !(pad.Buttons & PSP_CTRL_LTRIGGER))
+ _keyboardMode ^= SYMBOLS;
+
+ if ( (buttonsChanged & PSP_CTRL_LEFT) && !(pad.Buttons & PSP_CTRL_LEFT)) {
+ event.kbd.flags = 0;
+ event.kbd.ascii = 0;
+ event.kbd.keycode = Common::KEYCODE_LEFT;
+ _prevButtons = pad.Buttons;
+ return true;
+ }
+
+ if ( (buttonsChanged & PSP_CTRL_RIGHT) && !(pad.Buttons & PSP_CTRL_RIGHT)) {
+ event.kbd.flags = 0;
+ event.kbd.ascii = 0;
+ event.kbd.keycode = Common::KEYCODE_RIGHT;
+ _prevButtons = pad.Buttons;
+ return true;
+ }
+
+ if ( (buttonsChanged & PSP_CTRL_UP) && !(pad.Buttons & PSP_CTRL_UP)) {
+ event.kbd.flags = 0;
+ event.kbd.ascii = 0;
+ event.kbd.keycode = Common::KEYCODE_UP;
+ _prevButtons = pad.Buttons;
+ return true;
+ }
+
+ if ( (buttonsChanged & PSP_CTRL_DOWN) && !(pad.Buttons & PSP_CTRL_DOWN)) {
+ event.kbd.flags = 0;
+ event.kbd.ascii = 0;
+ event.kbd.keycode = Common::KEYCODE_DOWN;
+ _prevButtons = pad.Buttons;
+ return true;
+ }
+
+ // compute nub direction
+ x = pad.Lx-128;
+ y = pad.Ly-128;
+ _kbdClut[_keySelected] = 0xf888;
+ if (x*x + y*y > 10000) {
+ nub_angle = atan2(y, x);
+ _keySelected = (int)(1 + (M_PI + nub_angle) * 30 / (2 * M_PI));
+ _keySelected -= 2;
+ if (_keySelected < 1)
+ _keySelected += 30;
+ _kbdClut[_keySelected] = 0xFFFF;
+
+ if (buttonsChanged & PSP_CTRL_CROSS) {
+ event.type = (pad.Buttons & PSP_CTRL_CROSS) ? Common::EVENT_KEYDOWN : Common::EVENT_KEYUP;
+ if (_keySelected > 26) {
+ event.kbd.flags = 0;
+ switch(_keySelected) {
+ case 27:
+ event.kbd.ascii = ' ';
+ event.kbd.keycode = Common::KEYCODE_SPACE;
+ break;
+ case 28:
+ event.kbd.ascii = 127;
+ event.kbd.keycode = Common::KEYCODE_DELETE;
+ break;
+ case 29:
+ event.kbd.ascii = 8;
+ event.kbd.keycode = Common::KEYCODE_BACKSPACE;
+ break;
+ case 30:
+ event.kbd.ascii = 13;
+ event.kbd.keycode = Common::KEYCODE_RETURN;
+ break;
+ }
+ } else {
+ switch( _keyboardMode) {
+ case 0:
+ event.kbd.flags = 0;
+ event.kbd.ascii = 'a'+_keySelected-1;
+ event.kbd.keycode = (Common::KeyCode)(Common::KEYCODE_a + _keySelected-1);
+ break;
+ case CAPS_LOCK:
+ event.kbd.ascii = 'A'+_keySelected-1;
+ event.kbd.keycode = (Common::KeyCode)(Common::KEYCODE_a + _keySelected-1);
+ event.kbd.flags = Common::KBD_SHIFT;
+ break;
+ case SYMBOLS:
+ if (_keySelected < 21) {
+ event.kbd.flags = 0;
+ event.kbd.ascii = kbd_ascii[_keySelected-1];
+ event.kbd.keycode = kbd_code[ _keySelected-1];
+ }
+ break;
+ case (SYMBOLS|CAPS_LOCK):
+ if (_keySelected < 21) {
+ event.kbd.flags = 0;
+ event.kbd.ascii = kbd_ascii_cl[_keySelected-1];
+ event.kbd.keycode = kbd_code_cl[ _keySelected-1];
+ }
+ break;
+ }
+ }
+ _prevButtons = pad.Buttons;
+ return true;
+ }
+ }
+
+ _prevButtons = pad.Buttons;
+ return false;
+}
+
+
uint32 OSystem_PSP::getMillis() {
return SDL_GetTicks();
}