diff options
author | Norbert Lange | 2009-08-24 17:51:47 +0000 |
---|---|---|
committer | Norbert Lange | 2009-08-24 17:51:47 +0000 |
commit | 917d4b78b36d6c5a5c25a03e7ee6a1c1b6a85fd5 (patch) | |
tree | e652563203a00f8acecfaafbf93c64dbfbd13f25 /backends | |
parent | 5f87d5090cfcb34cda3c1f5d430e0865344d7366 (diff) | |
parent | dd7868acc2512c9761d892e67a4837f4dc38bdc0 (diff) | |
download | scummvm-rg350-917d4b78b36d6c5a5c25a03e7ee6a1c1b6a85fd5.tar.gz scummvm-rg350-917d4b78b36d6c5a5c25a03e7ee6a1c1b6a85fd5.tar.bz2 scummvm-rg350-917d4b78b36d6c5a5c25a03e7ee6a1c1b6a85fd5.zip |
Merge with trunk
svn-id: r43701
Diffstat (limited to 'backends')
36 files changed, 1653 insertions, 906 deletions
diff --git a/backends/fs/psp/psp-fs-factory.cpp b/backends/fs/psp/psp-fs-factory.cpp index 27bee4de86..7ed84de034 100644 --- a/backends/fs/psp/psp-fs-factory.cpp +++ b/backends/fs/psp/psp-fs-factory.cpp @@ -34,7 +34,13 @@ AbstractFSNode *PSPFilesystemFactory::makeRootFileNode() const { AbstractFSNode *PSPFilesystemFactory::makeCurrentDirectoryFileNode() const { char buf[MAXPATHLEN]; - return getcwd(buf, MAXPATHLEN) ? new PSPFilesystemNode(buf) : NULL; + char * ret = 0; + + PowerMan.beginCriticalSection(); + ret = getcwd(buf, MAXPATHLEN); + PowerMan.endCriticalSection(); + + return (ret ? new PSPFilesystemNode(buf) : NULL); } AbstractFSNode *PSPFilesystemFactory::makeFileNodePath(const Common::String &path) const { diff --git a/backends/fs/psp/psp-fs.cpp b/backends/fs/psp/psp-fs.cpp index f5ff65c9fa..03247e86ad 100644 --- a/backends/fs/psp/psp-fs.cpp +++ b/backends/fs/psp/psp-fs.cpp @@ -26,7 +26,8 @@ #include "engines/engine.h" #include "backends/fs/abstract-fs.h" -#include "backends/fs/stdiostream.h" +#include "backends/fs/psp/psp-stream.h" +#include "backends/platform/psp/powerman.h" #include <sys/stat.h> #include <unistd.h> @@ -35,6 +36,9 @@ #define ROOT_PATH "ms0:/" +#include "backends/platform/psp/trace.h" + + /** * Implementation of the ScummVM file system API based on PSPSDK API. * @@ -61,13 +65,13 @@ public: */ PSPFilesystemNode(const Common::String &p, bool verify = true); - virtual bool exists() const { return access(_path.c_str(), F_OK) == 0; } + virtual bool exists() const; virtual Common::String getDisplayName() const { return _displayName; } virtual Common::String getName() const { return _displayName; } virtual Common::String getPath() const { return _path; } virtual bool isDirectory() const { return _isDirectory; } - virtual bool isReadable() const { return access(_path.c_str(), R_OK) == 0; } - virtual bool isWritable() const { return access(_path.c_str(), W_OK) == 0; } + virtual bool isReadable() const; + virtual bool isWritable() const; virtual AbstractFSNode *getChild(const Common::String &n) const; virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; @@ -94,11 +98,44 @@ PSPFilesystemNode::PSPFilesystemNode(const Common::String &p, bool verify) { if (verify) { struct stat st; + PowerMan.beginCriticalSection(); _isValid = (0 == stat(_path.c_str(), &st)); + PowerMan.endCriticalSection(); _isDirectory = S_ISDIR(st.st_mode); } } +bool PSPFilesystemNode::exists() const { + int ret = 0; + + PowerMan.beginCriticalSection(); // Make sure to block in case of suspend + ret = access(_path.c_str(), F_OK); + PowerMan.endCriticalSection(); + + return ret == 0; +} + +bool PSPFilesystemNode::isReadable() const { + int ret = 0; + + PowerMan.beginCriticalSection(); // Make sure to block in case of suspend + ret = access(_path.c_str(), R_OK); + PowerMan.endCriticalSection(); + + return ret == 0; +} + +bool PSPFilesystemNode::isWritable() const { + int ret = 0; + + PowerMan.beginCriticalSection(); // Make sure to block in case of suspend + ret = access(_path.c_str(), W_OK); + PowerMan.endCriticalSection(); + + return ret == 0; +} + + AbstractFSNode *PSPFilesystemNode::getChild(const Common::String &n) const { // FIXME: Pretty lame implementation! We do no error checking to speak // of, do not check if this is a special node, etc. @@ -117,6 +154,10 @@ bool PSPFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool //TODO: honor the hidden flag + bool ret = true; + + PowerMan.beginCriticalSection(); // Make sure to block in case of suspend + int dfd = sceIoDopen(_path.c_str()); if (dfd > 0) { SceIoDirent dir; @@ -149,10 +190,13 @@ bool PSPFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool } sceIoDclose(dfd); - return true; - } else { - return false; + ret = true; + } else { // dfd <= 0 + ret = false; } + + PowerMan.endCriticalSection(); + return ret; } AbstractFSNode *PSPFilesystemNode::getParent() const { @@ -166,11 +210,11 @@ AbstractFSNode *PSPFilesystemNode::getParent() const { } Common::SeekableReadStream *PSPFilesystemNode::createReadStream() { - return StdioStream::makeFromPath(getPath().c_str(), false); + return PSPIoStream::makeFromPath(getPath(), false); } Common::WriteStream *PSPFilesystemNode::createWriteStream() { - return StdioStream::makeFromPath(getPath().c_str(), true); + return PSPIoStream::makeFromPath(getPath(), true); } #endif //#ifdef __PSP__ diff --git a/backends/module.mk b/backends/module.mk index f3294c5dc6..42fbeb07eb 100644 --- a/backends/module.mk +++ b/backends/module.mk @@ -11,6 +11,7 @@ MODULE_OBJS := \ fs/posix/posix-fs-factory.o \ fs/ps2/ps2-fs-factory.o \ fs/psp/psp-fs-factory.o \ + fs/psp/psp-stream.o \ fs/symbian/symbian-fs-factory.o \ fs/windows/windows-fs-factory.o \ fs/wii/wii-fs-factory.o \ diff --git a/backends/platform/dc/dc.h b/backends/platform/dc/dc.h index b67bbb51a1..f5d200968e 100644 --- a/backends/platform/dc/dc.h +++ b/backends/platform/dc/dc.h @@ -84,7 +84,7 @@ class OSystem_Dreamcast : private DCHardware, public BaseBackend, public Filesys // Set the size of the video bitmap. // Typically, 320x200 - void initSize(uint w, uint h); + void initSize(uint w, uint h, const Graphics::PixelFormat *format); int16 getHeight() { return _screen_h; } int16 getWidth() { return _screen_w; } @@ -105,7 +105,7 @@ class OSystem_Dreamcast : private DCHardware, public BaseBackend, public Filesys void warpMouse(int x, int y); // Set the bitmap that's used when drawing the cursor. - void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale); + void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format); // Replace the specified range of cursor the palette with new colors. void setCursorPalette(const byte *colors, uint start, uint num); diff --git a/backends/platform/dc/display.cpp b/backends/platform/dc/display.cpp index d1e95c6a91..c6be514e36 100644 --- a/backends/platform/dc/display.cpp +++ b/backends/platform/dc/display.cpp @@ -193,7 +193,7 @@ void OSystem_Dreamcast::setScaling() } } -void OSystem_Dreamcast::initSize(uint w, uint h) +void OSystem_Dreamcast::initSize(uint w, uint h, const Graphics::PixelFormat *format) { assert(w <= SCREEN_W && h <= SCREEN_H); @@ -263,7 +263,7 @@ void OSystem_Dreamcast::warpMouse(int x, int y) void OSystem_Dreamcast::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, - byte keycolor, int cursorTargetScale) + uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) { _ms_cur_w = w; _ms_cur_h = h; @@ -271,7 +271,7 @@ void OSystem_Dreamcast::setMouseCursor(const byte *buf, uint w, uint h, _ms_hotspot_x = hotspot_x; _ms_hotspot_y = hotspot_y; - _ms_keycolor = keycolor; + _ms_keycolor = (byte)keycolor; if (_ms_buf) free(_ms_buf); diff --git a/backends/platform/gp2x/gp2x-common.h b/backends/platform/gp2x/gp2x-common.h index 4e6421f353..c8bbd93de0 100644 --- a/backends/platform/gp2x/gp2x-common.h +++ b/backends/platform/gp2x/gp2x-common.h @@ -58,7 +58,7 @@ public: // Set the size of the video bitmap. // Typically, 320x200 - void initSize(uint w, uint h); + void initSize(uint w, uint h, const Graphics::PixelFormat *format); int getScreenChangeID() const { return _screenChangeCount; } @@ -87,7 +87,7 @@ public: void warpMouse(int x, int y); // Set the bitmap that's used when drawing the cursor. - void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale); + void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format); // Set colors of cursor palette void setCursorPalette(const byte *colors, uint start, uint num); diff --git a/backends/platform/gp2x/graphics.cpp b/backends/platform/gp2x/graphics.cpp index 229f840d11..cf874323e0 100644 --- a/backends/platform/gp2x/graphics.cpp +++ b/backends/platform/gp2x/graphics.cpp @@ -240,9 +240,27 @@ int OSystem_GP2X::getGraphicsMode() const { return _videoMode.mode; } -void OSystem_GP2X::initSize(uint w, uint h){ +void OSystem_GP2X::initSize(uint w, uint h, const Graphics::PixelFormat *format) { assert(_transactionMode == kTransactionActive); +#ifdef USE_RGB_COLOR + //avoid redundant format changes + Graphics::PixelFormat newFormat; + if (!format) + newFormat = Graphics::PixelFormat::createFormatCLUT8(); + else + newFormat = *format; + + assert(newFormat.bytesPerPixel > 0); + + if (newFormat != _videoMode.format) + { + _videoMode.format = newFormat; + _transactionDetails.formatChanged = true; + _screenFormat = newFormat; + } +#endif + // Avoid redundant res changes if ((int)w == _videoMode.screenWidth && (int)h == _videoMode.screenHeight) return; @@ -1212,7 +1230,17 @@ void OSystem_GP2X::warpMouse(int x, int y) { } } -void OSystem_GP2X::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale) { +void OSystem_GP2X::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) { +#ifdef USE_RGB_COLOR + if (!format) + _cursorFormat = Graphics::PixelFormat::createFormatCLUT8(); + else if (format->bytesPerPixel <= _screenFormat.bytesPerPixel) + _cursorFormat = *format; + keycolor &= (1 << (_cursorFormat.bytesPerPixel << 3)) - 1; +#else + keycolor &= 0xFF; +#endif + if (w == 0 || h == 0) return; @@ -1246,16 +1274,26 @@ void OSystem_GP2X::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x } free(_mouseData); - +#ifdef USE_RGB_COLOR + _mouseData = (byte *)malloc(w * h * _cursorFormat.bytesPerPixel); + memcpy(_mouseData, buf, w * h * _cursorFormat.bytesPerPixel); +#else _mouseData = (byte *)malloc(w * h); memcpy(_mouseData, buf, w * h); +#endif + blitCursor(); } void OSystem_GP2X::blitCursor() { byte *dstPtr; const byte *srcPtr = _mouseData; +#ifdef USE_RGB_COLOR + uint32 color; + uint32 colormask = (1 << (_cursorFormat.bytesPerPixel << 3)) - 1; +#else byte color; +#endif int w, h, i, j; if (!_mouseOrigSurface || !_mouseData) @@ -1289,13 +1327,29 @@ void OSystem_GP2X::blitCursor() { for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { - color = *srcPtr; - if (color != _mouseKeyColor) { // transparent, don't draw - *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format, - palette[color].r, palette[color].g, palette[color].b); +#ifdef USE_RGB_COLOR + if (_cursorFormat.bytesPerPixel > 1) { + color = (*(uint32 *) srcPtr) & colormask; + if (color != _mouseKeyColor) { // transparent, don't draw + uint8 r,g,b; + _cursorFormat.colorToRGB(color,r,g,b); + *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format, + r, g, b); + } + dstPtr += 2; + srcPtr += _cursorFormat.bytesPerPixel; + } else { +#endif + color = *srcPtr; + if (color != _mouseKeyColor) { // transparent, don't draw + *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format, + palette[color].r, palette[color].g, palette[color].b); + } + dstPtr += 2; + srcPtr++; +#ifdef USE_RGB_COLOR } - dstPtr += 2; - srcPtr++; +#endif } dstPtr += _mouseOrigSurface->pitch - w * 2; } diff --git a/backends/platform/iphone/osys_main.h b/backends/platform/iphone/osys_main.h index 705f89319a..c4c1a8b080 100644 --- a/backends/platform/iphone/osys_main.h +++ b/backends/platform/iphone/osys_main.h @@ -126,7 +126,7 @@ public: bool setGraphicsMode(const char *name); virtual bool setGraphicsMode(int mode); virtual int getGraphicsMode() const; - virtual void initSize(uint width, uint height); + virtual void initSize(uint width, uint height, const Graphics::PixelFormat *format); virtual int16 getHeight(); virtual int16 getWidth(); virtual void setPalette(const byte *colors, uint start, uint num); @@ -149,7 +149,7 @@ public: virtual bool showMouse(bool visible); virtual void warpMouse(int x, int y); - virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor = 255, int cursorTargetScale = 1); + virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 255, int cursorTargetScale = 1, const Graphics::PixelFormat *format = NULL); virtual bool pollEvent(Common::Event &event); virtual uint32 getMillis(); diff --git a/backends/platform/iphone/osys_video.cpp b/backends/platform/iphone/osys_video.cpp index 641c341f50..6cb5e18d95 100644 --- a/backends/platform/iphone/osys_video.cpp +++ b/backends/platform/iphone/osys_video.cpp @@ -46,7 +46,7 @@ int OSystem_IPHONE::getGraphicsMode() const { return -1; } -void OSystem_IPHONE::initSize(uint width, uint height) { +void OSystem_IPHONE::initSize(uint width, uint height, const Graphics::PixelFormat *format) { //printf("initSize(%i, %i)\n", width, height); _screenWidth = width; @@ -438,7 +438,7 @@ void OSystem_IPHONE::dirtyFullOverlayScreen() { } } -void OSystem_IPHONE::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int cursorTargetScale) { +void OSystem_IPHONE::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) { //printf("setMouseCursor(%i, %i)\n", hotspotX, hotspotY); if (_mouseBuf != NULL && (_mouseWidth != w || _mouseHeight != h)) { @@ -455,7 +455,7 @@ void OSystem_IPHONE::setMouseCursor(const byte *buf, uint w, uint h, int hotspot _mouseHotspotX = hotspotX; _mouseHotspotY = hotspotY; - _mouseKeyColour = keycolor; + _mouseKeyColour = (byte)keycolor; memcpy(_mouseBuf, buf, w * h); diff --git a/backends/platform/linuxmoto/hardwarekeys.cpp b/backends/platform/linuxmoto/hardwarekeys.cpp new file mode 100644 index 0000000000..e65d2bec2b --- /dev/null +++ b/backends/platform/linuxmoto/hardwarekeys.cpp @@ -0,0 +1,100 @@ +/* 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 "backends/platform/linuxmoto/linuxmoto-sdl.h" +#include "backends/keymapper/keymapper.h" +#include "common/keyboard.h" + +#ifdef ENABLE_KEYMAPPER + +using namespace Common; + +struct Key { + const char *hwId; + KeyCode keycode; + uint16 ascii; + const char *desc; + KeyType preferredAction; + bool shiftable; +}; + +static const Key keys[] = { + { "FIRE", KEYCODE_RETURN, ASCII_RETURN, "Fire", kActionKeyType, false }, + { "CAMERA", KEYCODE_PAUSE, 0, "Camera", kActionKeyType, false }, + { "HANGUP", KEYCODE_ESCAPE, ASCII_ESCAPE, "Hangup", kStartKeyType, false }, + { "CALL", KEYCODE_SPACE, ASCII_SPACE, "Call", kActionKeyType, false }, + { "PLUS", KEYCODE_PLUS, '+', "+", kActionKeyType, false }, + { "MINUS", KEYCODE_MINUS, '-', "-", kActionKeyType, false }, + + { "a", KEYCODE_a, 'a', "a", kActionKeyType, true }, + { "b", KEYCODE_b, 'b', "b", kActionKeyType, true }, + { "c", KEYCODE_c, 'c', "c", kActionKeyType, true }, + { "d", KEYCODE_d, 'd', "d", kActionKeyType, true }, + { "e", KEYCODE_e, 'e', "e", kActionKeyType, true }, + { "f", KEYCODE_f, 'f', "f", kActionKeyType, true }, + { "g", KEYCODE_g, 'g', "g", kActionKeyType, true }, + { "h", KEYCODE_h, 'h', "h", kActionKeyType, true }, + { "i", KEYCODE_i, 'i', "i", kActionKeyType, true }, + { "j", KEYCODE_j, 'j', "j", kActionKeyType, true }, + + // Numeric keypad + + // Arrows + Home/End pad + {"UP", KEYCODE_UP, 0, "Up", kDirUpKeyType, false}, + {"DOWN", KEYCODE_DOWN, 0, "Down", kDirDownKeyType, false}, + {"RIGHT", KEYCODE_RIGHT, 0, "Right", kDirRightKeyType, false}, + {"LEFT", KEYCODE_LEFT, 0, "Left", kDirLeftKeyType, false}, + + // Function keys + + // Miscellaneous function keys + + {0, KEYCODE_INVALID, 0, 0, kGenericKeyType, false} +}; + +struct Mod { + byte flag; + const char *id; + const char *desc; + bool shiftable; +}; + +static const Mod modifiers[] = { + { 0, "", "", false }, + { KBD_CTRL, "C+", "Ctrl+", false }, + { KBD_ALT, "A+", "Alt+", false }, + { KBD_SHIFT, "", "", true }, + { KBD_CTRL | KBD_ALT, "C+A+", "Ctrl+Alt+", false }, + { KBD_SHIFT | KBD_CTRL, "S+C+", "Shift+Ctrl+", true }, + { KBD_SHIFT | KBD_CTRL | KBD_ALT, "C+A+", "Ctrl+Alt+", true }, + { 0, 0, 0, false } +}; +#endif + + +Common::HardwareKeySet *OSystem_LINUXMOTO::getHardwareKeySet() { + OSystem_SDL::getHardwareKeySet(); +} diff --git a/backends/platform/linuxmoto/linuxmoto-events.cpp b/backends/platform/linuxmoto/linuxmoto-events.cpp new file mode 100644 index 0000000000..be5eec5c7e --- /dev/null +++ b/backends/platform/linuxmoto/linuxmoto-events.cpp @@ -0,0 +1,192 @@ +/* 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 "backends/platform/linuxmoto/linuxmoto-sdl.h" +#include "backends/platform/sdl/sdl.h" + +static int mapKey(SDLKey key, SDLMod mod, Uint16 unicode) { + if (key >= SDLK_F1 && key <= SDLK_F9) { + return key - SDLK_F1 + Common::ASCII_F1; + } else if (key >= SDLK_KP0 && key <= SDLK_KP9) { + return key - SDLK_KP0 + '0'; + } else if (key >= SDLK_UP && key <= SDLK_PAGEDOWN) { + return key; + } else if (unicode) { + return unicode; + } else if (key >= 'a' && key <= 'z' && (mod & KMOD_SHIFT)) { + return key & ~0x20; + } else if (key >= SDLK_NUMLOCK && key <= SDLK_EURO) { + return 0; + } + return key; +} + +bool OSystem_LINUXMOTO::remapKey(SDL_Event &ev, Common::Event &event) { + // Motorol A1200/E6/A1600 remapkey by Lubomyr +#ifdef MOTOEZX + // Quit on MOD+Camera Key on A1200 + if (ev.key.keysym.sym == SDLK_e) { + event.type = Common::EVENT_QUIT; + return true; + } + // '1' Bypass security protection - MOD+Call key + if (ev.key.keysym.sym == SDLK_f) { + ev.key.keysym.sym = SDLK_1; + } + // F5 Game Menu - Call key + else if (ev.key.keysym.sym == SDLK_SPACE) { + ev.key.keysym.sym = SDLK_F5; + } + // Camera to VirtualKeyboard + else if (ev.key.keysym.sym == SDLK_PAUSE) { + ev.key.keysym.sym = SDLK_F7; + } + // mod+fire to enter + else if (ev.key.keysym.sym == SDLK_b) { + ev.key.keysym.sym = SDLK_RETURN; + } +#endif + // Motorola Z6/V8 remapkey by Ant-On +#ifdef MOTOMAGX + // Quit on cancel + if (ev.key.keysym.sym == SDLK_ESCAPE) { + event.type = Common::EVENT_QUIT; + return true; + } else + // F5 Game Menu - Call key + if (ev.key.keysym.sym == SDLK_SPACE) { + ev.key.keysym.sym = SDLK_F5; + } + // 'y' - Mod+Right key + // 'y' - Left soft + else if (ev.key.keysym.sym == SDLK_F9) { + ev.key.keysym.sym = SDLK_y; + } + // 'n' - Mod+Left key + // 'n' - rigth soft + else if (ev.key.keysym.sym == SDLK_F11) { + ev.key.keysym.sym = SDLK_n; + } +#endif + +// Joystick to Mouse + else if (ev.key.keysym.sym == SDLK_LEFT) { + if (ev.type == SDL_KEYDOWN) { + _km.x_vel = -1; + _km.x_down_count = 1; + } else { + _km.x_vel = 0; + _km.x_down_count = 0; + } + + event.type = Common::EVENT_MOUSEMOVE; + fillMouseEvent(event, _km.x, _km.y); + return true; + } else if (ev.key.keysym.sym == SDLK_RIGHT) { + if (ev.type == SDL_KEYDOWN) { + _km.x_vel = 1; + _km.x_down_count = 1; + } else { + _km.x_vel = 0; + _km.x_down_count = 0; + } + + event.type = Common::EVENT_MOUSEMOVE; + fillMouseEvent(event, _km.x, _km.y); + + return true; + } else if (ev.key.keysym.sym == SDLK_DOWN) { + if (ev.type == SDL_KEYDOWN) { + _km.y_vel = 1; + _km.y_down_count = 1; + } else { + _km.y_vel = 0; + _km.y_down_count = 0; + } + + event.type = Common::EVENT_MOUSEMOVE; + fillMouseEvent(event, _km.x, _km.y); + + return true; + } else if (ev.key.keysym.sym == SDLK_UP) { + if (ev.type == SDL_KEYDOWN) { + _km.y_vel = -1; + _km.y_down_count = 1; + } else { + _km.y_vel = 0; + _km.y_down_count = 0; + } + + event.type = Common::EVENT_MOUSEMOVE; + fillMouseEvent(event, _km.x, _km.y); + + return true; + } else if (ev.key.keysym.sym == SDLK_RETURN) { // Joystick center to pressing Left Mouse + // _km.y_vel = 0; + // _km.y_down_count = 0; + if (ev.key.type == SDL_KEYDOWN) { + event.type = Common::EVENT_LBUTTONDOWN; + } else { + event.type = Common::EVENT_LBUTTONUP; + } + + fillMouseEvent(event, _km.x, _km.y); + + return true; + } else if (ev.key.keysym.sym == SDLK_PLUS) { // Volume Up to pressing Right Mouse + // _km.y_vel = 0; + // _km.y_down_count = 0; + if (ev.key.type == SDL_KEYDOWN ) { + event.type = Common::EVENT_RBUTTONDOWN; + } else { + event.type = Common::EVENT_RBUTTONUP; + } + fillMouseEvent(event, _km.x, _km.y); + + return true; + } else if (ev.key.keysym.sym == SDLK_MINUS) { // Volume Down to pressing Left Mouse + //_km.y_vel = 0; + //_km.y_down_count = 0; + if (ev.key.type == SDL_KEYDOWN) { + event.type = Common::EVENT_LBUTTONDOWN; + } else { + event.type = Common::EVENT_LBUTTONUP; + } + + fillMouseEvent(event, _km.x, _km.y); + + return true; + } else { + // Let the events fall through if we didn't change them, this may not be the best way to + // set it up, but i'm not sure how sdl would like it if we let if fall through then redid it though. + // and yes i have an huge terminal size so i dont wrap soon enough. + event.type = Common::EVENT_KEYDOWN; + event.kbd.keycode = (Common::KeyCode)ev.key.keysym.sym; + event.kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod, ev.key.keysym.unicode); + } + + return false; +} diff --git a/backends/platform/linuxmoto/linuxmoto-sdl.cpp b/backends/platform/linuxmoto/linuxmoto-sdl.cpp new file mode 100644 index 0000000000..82c69bc7d7 --- /dev/null +++ b/backends/platform/linuxmoto/linuxmoto-sdl.cpp @@ -0,0 +1,69 @@ +/* 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 "backends/platform/linuxmoto/linuxmoto-sdl.h" + +void OSystem_LINUXMOTO::preprocessEvents(SDL_Event *event) { + if (event->type == SDL_ACTIVEEVENT) { + if (event->active.state == SDL_APPINPUTFOCUS && !event->active.gain) { + suspendAudio(); + for (;;) { + if (!SDL_WaitEvent(event)) { + SDL_Delay(10); + continue; + } + if (event->type == SDL_QUIT) + return; + if (event->type != SDL_ACTIVEEVENT) + continue; + if (event->active.state == SDL_APPINPUTFOCUS && event->active.gain) { + resumeAudio(); + return; + } + } + } + } +} + +void OSystem_LINUXMOTO::suspendAudio() { + SDL_CloseAudio(); + _audioSuspended = true; +} + +int OSystem_LINUXMOTO::resumeAudio() { + if (!_audioSuspended) + return -2; + if (SDL_OpenAudio(&_obtainedRate, NULL) < 0){ + return -1; + } + SDL_PauseAudio(0); + _audioSuspended = false; + return 0; +} + +void OSystem_LINUXMOTO::setupMixer() { + OSystem_SDL::setupMixer(); +} diff --git a/backends/platform/psp/osys_psp_gu.h b/backends/platform/linuxmoto/linuxmoto-sdl.h index e828a36b7d..27c423b071 100644 --- a/backends/platform/psp/osys_psp_gu.h +++ b/backends/platform/linuxmoto/linuxmoto-sdl.h @@ -18,42 +18,29 @@ * 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 <pspgu.h> -#include "common/scummsys.h" -#include "common/rect.h" -#include "osys_psp.h" +#ifndef LINUXMOTO_SDL +#define LINUXMOTO_SDL -class OSystem_PSP_GU : public OSystem_PSP -{ +#include "backends/platform/sdl/sdl.h" + +#include <SDL.h> + +class OSystem_LINUXMOTO : public OSystem_SDL { +private: + bool _audioSuspended; public: - struct Vertex - { - float u,v; - float x,y,z; - }; - - OSystem_PSP_GU(); - ~OSystem_PSP_GU(); - void updateScreen(); - void initSize(uint width, uint height); - int getDefaultGraphicsMode() const; - bool setGraphicsMode(int mode); - bool setGraphicsMode(const char *name); - int getGraphicsMode() const; - void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int cursorTargetScale); - void copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h) ; - void setPalette(const byte *colors, uint start, uint num); - bool pollEvent(Common::Event &event); - int _graphicMode; - struct Vertex *_vertices; - unsigned short* _clut; - unsigned short* _kbdClut; - bool _keyboardVisible; - int _keySelected; - int _keyboardMode; + virtual bool remapKey(SDL_Event &ev, Common::Event &event); + virtual void preprocessEvents(SDL_Event *event); + virtual void setupMixer(); + virtual Common::HardwareKeySet *getHardwareKeySet(); + void suspendAudio(); + int resumeAudio(); }; +#endif diff --git a/backends/platform/linuxmoto/main.cpp b/backends/platform/linuxmoto/main.cpp new file mode 100644 index 0000000000..7f015faff4 --- /dev/null +++ b/backends/platform/linuxmoto/main.cpp @@ -0,0 +1,44 @@ +/* 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/scummsys.h> +#include <common/system.h> + +#include <SDL/SDL.h> +#include <SDL/SDL_syswm.h> + +#include "backends/platform/linuxmoto/linuxmoto-sdl.h" +#include "base/main.h" +#include "base/internal_version.h" + +int main(int argc, char *argv[]) { + g_system = new OSystem_LINUXMOTO(); + assert(g_system); + // Invoke the actual ScummVM main entry point: + int res = scummvm_main(argc, argv); + g_system->quit(); // TODO: Consider removing / replacing this! + + return res; +} diff --git a/backends/platform/linuxmoto/module.mk b/backends/platform/linuxmoto/module.mk new file mode 100644 index 0000000000..4d816eb227 --- /dev/null +++ b/backends/platform/linuxmoto/module.mk @@ -0,0 +1,29 @@ +MODULE := backends/platform/linuxmoto + +MODULE_OBJS := \ + main.o \ + hardwarekeys.o \ + linuxmoto-events.o \ + linuxmoto-sdl.o + +MODULE_DIRS += \ + backends/platform/linuxmoto/ + +# We don't use the rules.mk here on purpose +OBJS := $(addprefix $(MODULE)/, $(MODULE_OBJS)) $(OBJS) + +MODULE := backends/platform/sdl + +MODULE_OBJS := \ + events.o \ + graphics.o \ + hardwarekeys.o \ + main.o \ + sdl.o + +MODULE_DIRS += \ + backends/platform/sdl/ + +# We don't use the rules.mk here on purpose +OBJS := $(addprefix $(MODULE)/, $(MODULE_OBJS)) $(OBJS) + diff --git a/backends/platform/psp/Makefile b/backends/platform/psp/Makefile index 91a0c60bd6..8be3937ff2 100644 --- a/backends/platform/psp/Makefile +++ b/backends/platform/psp/Makefile @@ -49,7 +49,7 @@ STRIP = psp-strip MKDIR = mkdir -p RM = rm -f RM_REC = rm -rf -MKSFO = mksfo +MKSFO = mksfoex -d MEMSIZE=1 PACK_PBP = pack-pbp FIXUP = psp-fixup-imports @@ -62,7 +62,7 @@ endif INCDIR := $(srcdir) . $(srcdir)/engines/ . $(PSPSDK)/include LIBDIR := $(LIBDIR) . $(PSPSDK)/lib -CXXFLAGS = -O2 -Wall -D__PSP__ -DNONSTANDARD_PORT -DDISABLE_TEXT_CONSOLE -DDISABLE_COMMAND_LINE -DUSE_ZLIB -Wno-multichar `$(PSPBIN)/sdl-config --cflags` +CXXFLAGS = -O3 -Wall -D__PSP__ -DNONSTANDARD_PORT -DDISABLE_TEXT_CONSOLE -DDISABLE_COMMAND_LINE -DUSE_ZLIB -DDISABLE_DOSBOX_OPL -Wno-multichar `$(PSPBIN)/sdl-config --cflags` CXXFLAGS:= $(addprefix -I,$(INCDIR)) $(CXXFLAGS) LDFLAGS := $(addprefix -L,$(LIBDIR)) $(LDFLAGS) LIBS = @@ -75,14 +75,14 @@ LIBS += -lmad CXXFLAGS+= -DUSE_VORBIS -DUSE_TREMOR LIBS += -lvorbisidec -LIBS += `$(PSPBIN)/sdl-config --libs` -lz -lstdc++ -lc -lpspdisplay -lpspgu -lpspctrl -lpspsdk -lpspnet -lpspnet_inet -lpsputility -lpspsdk -lpspuser +LIBS += `$(PSPBIN)/sdl-config --libs` -lz -lstdc++ -lc -lpspdisplay -lpspgu -lpspctrl -lpspsdk -lpspnet -lpspnet_inet -lpsputility -lpspuser -lpsppower CXXFLAGS := $(CXXFLAGS) -fno-exceptions -fno-rtti TARGET = scummvm-psp -OBJS := psp_main.o \ +OBJS := powerman.o \ + psp_main.o \ osys_psp.o \ - osys_psp_gu.o \ kbd_ss_c.o \ kbd_s_c.o \ kbd_ls_c.o \ diff --git a/backends/platform/psp/README.PSP.in b/backends/platform/psp/README.PSP.in index 2a2b53e721..7eeba7d391 100644 --- a/backends/platform/psp/README.PSP.in +++ b/backends/platform/psp/README.PSP.in @@ -13,15 +13,17 @@ Controls ======== Left trigger - ESC -Right trigger - Enter +Right trigger - Modifier key (see below for uses) Analog - Mouse movement +Right trigger + Analog - Fine control mouse Directionals - Mouse movement -Analog + triangle - Fine control mouse +Triangle - Enter Cross - Mouse button 1 Circle - Mouse button 2 Square - '.' (skip dialogue in some games) Select - Show/Hide Virtual Keyboard Start - F5 +Right trigger + Start - Return-To-Launcher menu Notes ===== @@ -32,9 +34,6 @@ Notes As such, it is recommended to play games in their original, uncompressed, form whenever possible. -- Sleep/Suspend mode currently isn't supported, so don't use it when - running ScummVM. - - This README may be outdated, for more up-to-date instructions and notes see the PSP Port Wiki: http://wiki.scummvm.org/index.php/PlayStation_Portable diff --git a/backends/platform/psp/module.mk b/backends/platform/psp/module.mk index afe9a23f58..a5c17ffa57 100644 --- a/backends/platform/psp/module.mk +++ b/backends/platform/psp/module.mk @@ -1,9 +1,9 @@ MODULE := backends/platform/psp MODULE_OBJS := \ + powerman.o \ psp_main.o \ osys_psp.o \ - osys_psp_gu.o \ kbd_ss_c.o \ kbd_s_c.o \ kbd_ls_c.o \ diff --git a/backends/platform/psp/osys_psp.cpp b/backends/platform/psp/osys_psp.cpp index 45be0a0cd3..023ec0cc82 100644 --- a/backends/platform/psp/osys_psp.cpp +++ b/backends/platform/psp/osys_psp.cpp @@ -23,43 +23,76 @@ * */ +#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" #include "graphics/surface.h" -#include "graphics/scaler.h" #include "sound/mixer_intern.h" -#include <pspgu.h> -#include <pspdisplay.h> -#include <time.h> +#define SAMPLES_PER_SEC 44100 -#include "./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[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 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) -#define SCREEN_WIDTH 480 -#define SCREEN_HEIGHT 272 -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(); @@ -75,25 +108,88 @@ 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), _mouseBuf(0), _prevButtons(0), _lastPadCheck(0), _padAccel(0), _mixer(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), _padAccel(0), _mixer(0) { memset(_palette, 0, sizeof(_palette)); + _cursorPaletteDisabled = true; + _samplesPerSec = 0; //init SDL uint32 sdlFlags = SDL_INIT_AUDIO | SDL_INIT_TIMER; SDL_Init(sdlFlags); - sceDisplaySetMode(0, SCREEN_WIDTH, SCREEN_HEIGHT); - sceDisplaySetFrameBuf((char *)DisplayBuffer, 512, 1, 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; + + + //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); + } 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(); } @@ -110,14 +206,14 @@ void OSystem_PSP::initBackend() { bool OSystem_PSP::hasFeature(Feature f) { - return false; + return (f == kFeatureOverlaySupportsAlpha || f == kFeatureCursorHasPalette); } void OSystem_PSP::setFeatureState(Feature f, bool enable) { } bool OSystem_PSP::getFeatureState(Feature f) { - return (f == kFeatureOverlaySupportsAlpha); + return false; } const OSystem::GraphicsMode* OSystem_PSP::getSupportedGraphicsModes() const { @@ -126,36 +222,56 @@ 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) { - _overlayWidth = _screenWidth = width; - _overlayHeight = _screenHeight = height; - - free(_offscreen); +void OSystem_PSP::initSize(uint width, uint height, const Graphics::PixelFormat *format) { + 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() { @@ -173,6 +289,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) { @@ -202,10 +346,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; @@ -228,52 +383,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; + } + + 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); + } - OverlayColor pixel = _overlayBuffer[(i * _overlayWidth +j)]; - 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) { @@ -380,7 +688,7 @@ void OSystem_PSP::warpMouse(int x, int y) { _mouseY = y; } -void OSystem_PSP::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int cursorTargetScale) { +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; @@ -388,18 +696,20 @@ void OSystem_PSP::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, _mouseHotspotX = hotspotX; _mouseHotspotY = hotspotY; - _mouseKeyColour = keycolor; + _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; /* @@ -411,7 +721,7 @@ bool OSystem_PSP::pollEvent(Common::Event &event) { */ uint32 buttonsChanged = pad.Buttons ^ _prevButtons; - if (buttonsChanged & (PSP_CTRL_CROSS | PSP_CTRL_CIRCLE | PSP_CTRL_LTRIGGER | PSP_CTRL_RTRIGGER | PSP_CTRL_START | PSP_CTRL_SELECT | PSP_CTRL_SQUARE)) { + 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) { @@ -419,23 +729,29 @@ bool OSystem_PSP::pollEvent(Common::Event &event) { } else { //any of the other buttons. event.type = buttonsChanged & pad.Buttons ? Common::EVENT_KEYDOWN : Common::EVENT_KEYUP; + event.kbd.ascii = 0; event.kbd.flags = 0; if (buttonsChanged & PSP_CTRL_LTRIGGER) { event.kbd.keycode = Common::KEYCODE_ESCAPE; event.kbd.ascii = 27; - } else if (buttonsChanged & PSP_CTRL_RTRIGGER) { - event.kbd.keycode = Common::KEYCODE_RETURN; - event.kbd.ascii = 13; } 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; } } @@ -484,7 +800,7 @@ bool OSystem_PSP::pollEvent(Common::Event &event) { newY += _padAccel >> 2; // If no movement then this has no effect - if (pad.Buttons & PSP_CTRL_TRIANGLE) { + if (pad.Buttons & PSP_CTRL_RTRIGGER) { // Fine control mode for analog if (analogStepAmountX != 0) { if (analogStepAmountX > 0) @@ -535,6 +851,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(); } diff --git a/backends/platform/psp/osys_psp.h b/backends/platform/psp/osys_psp.h index 34957b293c..047fbff97e 100644 --- a/backends/platform/psp/osys_psp.h +++ b/backends/platform/psp/osys_psp.h @@ -23,6 +23,9 @@ * */ +#ifndef OSYS_PSP_H +#define OSYS_PSP_H + #include "common/scummsys.h" #include "graphics/surface.h" #include "graphics/colormasks.h" @@ -47,6 +50,11 @@ public: static OSystem *instance(); protected: + struct Vertex { + float u,v; + float x,y,z; + }; + uint16 _screenWidth; uint16 _screenHeight; uint16 _overlayWidth; @@ -56,6 +64,7 @@ protected: uint16 _palette[256]; bool _overlayVisible; uint32 _shakePos; + uint32 _lastScreenUpdate; Graphics::Surface _framebuffer; @@ -65,6 +74,15 @@ protected: int _mouseHotspotX, _mouseHotspotY; byte _mouseKeyColour; byte *_mouseBuf; + bool _cursorPaletteDisabled; + + int _graphicMode; + Vertex *_vertices; + unsigned short* _clut; + unsigned short* _kbdClut; + bool _keyboardVisible; + int _keySelected; + int _keyboardMode; uint32 _prevButtons; uint32 _lastPadCheck; @@ -78,7 +96,6 @@ protected: Common::TimerManager *_timer; public: - OSystem_PSP(); virtual ~OSystem_PSP(); @@ -87,15 +104,21 @@ public: virtual bool hasFeature(Feature f); virtual void setFeatureState(Feature f, bool enable); virtual bool getFeatureState(Feature f); + virtual const GraphicsMode *getSupportedGraphicsModes() const; virtual int getDefaultGraphicsMode() const; virtual bool setGraphicsMode(int mode); bool setGraphicsMode(const char *name); virtual int getGraphicsMode() const; - virtual void initSize(uint width, uint height); + + virtual void initSize(uint width, uint height, const Graphics::PixelFormat *format); virtual int16 getWidth(); virtual int16 getHeight(); + virtual void setPalette(const byte *colors, uint start, uint num); + virtual void grabPalette(byte *colors, uint start, uint num); + virtual void setCursorPalette(const byte *colors, uint start, uint num); + virtual void disableCursorPalette(bool disable); virtual void copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h); virtual Graphics::Surface *lockScreen(); virtual void unlockScreen(); @@ -109,15 +132,15 @@ public: virtual void copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h); virtual int16 getOverlayHeight(); virtual int16 getOverlayWidth(); - virtual void grabPalette(byte *colors, uint start, uint num); virtual Graphics::PixelFormat getOverlayFormat() const { return Graphics::createPixelFormat<4444>(); } virtual bool showMouse(bool visible); - virtual void warpMouse(int x, int y); - virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor = 255, int cursorTargetScale = 1); + virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format); virtual bool pollEvent(Common::Event &event); + virtual bool processInput(Common::Event &event); + virtual uint32 getMillis(); virtual void delayMillis(uint msecs); @@ -144,3 +167,5 @@ public: virtual Common::WriteStream *createConfigWriteStream(); }; + +#endif /* OSYS_PSP_H */ diff --git a/backends/platform/psp/osys_psp_gu.cpp b/backends/platform/psp/osys_psp_gu.cpp deleted file mode 100644 index 76f6b42e37..0000000000 --- a/backends/platform/psp/osys_psp_gu.cpp +++ /dev/null @@ -1,601 +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$ - * $Id$ - */ - -#include "osys_psp_gu.h" -#include "trace.h" -#include "common/events.h" - -#include <zlib.h> - -#include <pspdisplay.h> - -#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 - -unsigned int __attribute__((aligned(16))) list[262144]; -unsigned short __attribute__((aligned(16))) clut256[256]; -unsigned short __attribute__((aligned(16))) mouseClut[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) - - -OSystem_PSP_GU::OSystem_PSP_GU() { - //sceKernelDcacheWritebackAll(); - - // setup - sceGuInit(); - sceGuStart(0, list); - 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_GU: 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_GU: 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_GU: 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_GU: 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_GU::~OSystem_PSP_GU() { - free(keyboard_symbols_shift); - free(keyboard_symbols); - free(keyboard_letters_shift); - free(keyboard_letters); - - _offscreen = 0; - _overlayBuffer = 0; - _mouseBuf = 0; - sceGuTerm(); -} - -void OSystem_PSP_GU::initSize(uint width, uint height) { - PSPDebugTrace("initSize\n"); - _screenWidth = width; - _screenHeight = height; - - _overlayWidth = PSP_SCREEN_WIDTH; //width; - _overlayHeight = PSP_SCREEN_HEIGHT; //height; - -// _offscreen = (byte *)offscreen256; - _overlayBuffer = (OverlayColor *)0x44000000 + PSP_FRAME_SIZE; - - _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(); -} - -int OSystem_PSP_GU::getDefaultGraphicsMode() const { - return STRETCHED_480X272; -} - -bool OSystem_PSP_GU::setGraphicsMode(int mode) { - _graphicMode = mode; - return true; -} - -bool OSystem_PSP_GU::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; -} - -int OSystem_PSP_GU::getGraphicsMode() const { - return _graphicMode; -} - -void OSystem_PSP_GU::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int cursorTargetScale) { - //TODO: handle cursorTargetScale - _mouseWidth = w; - _mouseHeight = h; - - _mouseHotspotX = hotspotX; - _mouseHotspotY = hotspotY; - - _mouseKeyColour = keycolor; - - memcpy(mouseClut, _palette, 256*sizeof(unsigned short)); - mouseClut[_mouseKeyColour] = 0; - sceKernelDcacheWritebackAll(); - - for (unsigned int i=0;i<h;i++) - memcpy(_mouseBuf+i*MOUSE_SIZE, buf+i*w, w); -} - -void OSystem_PSP_GU::setPalette(const byte *colors, uint start, uint num) { - const byte *b = colors; - - 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(); -} - - -void OSystem_PSP_GU::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; - - - byte *dst = _offscreen + y * _screenWidth + x; - - if (_screenWidth == pitch && pitch == w) - { - memcpy(dst, buf, h * w); -/* - sceGuStart(0,list); - 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; - } while (--h); - } -} - -void OSystem_PSP_GU::updateScreen() { - sceGuStart(0,list); - - 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 (_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) { - 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); - } - - - // 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 - if (_mouseVisible) { - sceGuTexMode(GU_PSM_T8, 0, 0, 0); // 8-bit image - sceGuClutMode(GU_PSM_5551, 0, 0xff, 0); - sceGuClutLoad(32, mouseClut); // 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); - - sceDisplayWaitVblankStart(); - sceGuSwapBuffers(); - - //sceKernelDcacheWritebackAll(); -} - -bool OSystem_PSP_GU::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 OSystem_PSP::pollEvent(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; -} - diff --git a/backends/platform/psp/psp.mk b/backends/platform/psp/psp.mk index 10e272a593..998a420ffc 100644 --- a/backends/platform/psp/psp.mk +++ b/backends/platform/psp/psp.mk @@ -9,7 +9,7 @@ PSP_EBOOT_SFO = param.sfo PSP_EBOOT_TITLE = ScummVM-PSP DATE = $(shell date +%Y%m%d) -MKSFO = mksfo +MKSFO = mksfoex -d MEMSIZE=1 PACK_PBP = pack-pbp $(PSP_EXE_STRIPPED): $(PSP_EXE) diff --git a/backends/platform/psp/psp.spec b/backends/platform/psp/psp.spec index 807b8f93b7..e319b022f7 100644 --- a/backends/platform/psp/psp.spec +++ b/backends/platform/psp/psp.spec @@ -1,3 +1,3 @@ %rename lib old_lib *lib: -%(old_lib) -lpspdebug -lpspgu -lpspctrl -lpspge -lpspdisplay -lpsphprm -lpspsdk -lpsprtc -lpspaudio -lc -lpspuser -lpsputility -lpspkernel -lpspnet_inet -lz -lstdc++ -lc -lpspdisplay -lpspgu -lpspctrl -lpspsdk -lpspnet -lpspnet_inet -lpsputility -lpspsdk -lpspuser +%(old_lib) -lpspdebug -lpspgu -lpspctrl -lpspge -lpspdisplay -lpsphprm -lpspsdk -lpsprtc -lpspaudio -lc -lpspuser -lpsputility -lpspkernel -lpspnet_inet -lz -lstdc++ -lc -lpspdisplay -lpspgu -lpspctrl -lpspsdk -lpspnet -lpspnet_inet -lpsputility -lpspuser -lpsppower diff --git a/backends/platform/psp/psp_main.cpp b/backends/platform/psp/psp_main.cpp index 0af7ebf269..74363e4ac9 100644 --- a/backends/platform/psp/psp_main.cpp +++ b/backends/platform/psp/psp_main.cpp @@ -31,12 +31,16 @@ #include <pspdebug.h> #endif +#include <psppower.h> + #include <common/system.h> #include <engines/engine.h> #include <base/main.h> #include <base/plugins.h> +#include "backends/platform/psp/powerman.h" + -#include "osys_psp_gu.h" +#include "osys_psp.h" #include "./trace.h" @@ -58,9 +62,8 @@ PSP_MODULE_INFO("SCUMMVM-PSP", 0, 1, 1); * code (crt0.c) starts this program in to be in usermode * even though the module was started in kernelmode */ -#ifndef USERSPACE_ONLY PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU); -#endif +PSP_HEAP_SIZE_KB(-128); //Leave 128kb for thread stacks, etc. #ifndef USERSPACE_ONLY @@ -91,17 +94,36 @@ void loaderInit() { #endif /* Exit callback */ -SceKernelCallbackFunction exit_callback(int /*arg1*/, int /*arg2*/, void * /*common*/) { +int exit_callback(void) { sceKernelExitGame(); return 0; } +/* Function for handling suspend/resume */ +void power_callback(int , int powerinfo) { + if (powerinfo & PSP_POWER_CB_POWER_SWITCH || powerinfo & PSP_POWER_CB_SUSPENDING) { + PowerMan.suspend(); + } else if (powerinfo & PSP_POWER_CB_RESUME_COMPLETE) { + PowerMan.resume(); + } +} + /* Callback thread */ int CallbackThread(SceSize /*size*/, void *arg) { int cbid; cbid = sceKernelCreateCallback("Exit Callback", (SceKernelCallbackFunction)exit_callback, NULL); sceKernelRegisterExitCallback(cbid); + /* Set up callbacks for PSPIoStream */ + + cbid = sceKernelCreateCallback("Power Callback", (SceKernelCallbackFunction)power_callback, 0); + if (cbid >= 0) { + if(scePowerRegisterCallback(-1, cbid) < 0) { + PSPDebugTrace("SetupCallbacks(): Couldn't register callback for power_callback\n"); + } + } else { + PSPDebugTrace("SetupCallbacks(): Couldn't create a callback for power_callback\n"); + } sceKernelSleepThreadCB(); return 0; @@ -119,18 +141,25 @@ int SetupCallbacks(void) { #undef main int main(void) { + //change clock rate to 333mhz + scePowerSetClockFrequency(333, 333, 166); + + PowerManager::instance(); // Setup power manager + SetupCallbacks(); static const char *argv[] = { "scummvm", NULL }; static int argc = sizeof(argv)/sizeof(char *)-1; - g_system = new OSystem_PSP_GU(); + g_system = new OSystem_PSP(); assert(g_system); int res = scummvm_main(argc, argv); g_system->quit(); // TODO: Consider removing / replacing this! + PowerManager::destroy(); // get rid of PowerManager + sceKernelSleepThread(); return res; diff --git a/backends/platform/sdl/events.cpp b/backends/platform/sdl/events.cpp index feb2c9a9c5..e6c8d716e3 100644 --- a/backends/platform/sdl/events.cpp +++ b/backends/platform/sdl/events.cpp @@ -186,6 +186,8 @@ bool OSystem_SDL::pollEvent(Common::Event &event) { } while (SDL_PollEvent(&ev)) { + preprocessEvents(&ev); + switch (ev.type) { case SDL_KEYDOWN:{ b = event.kbd.flags = SDLModToOSystemKeyFlags(SDL_GetModState()); diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index f3e4ce626b..a67e35cf73 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -26,6 +26,9 @@ #include "backends/platform/sdl/sdl.h" #include "common/mutex.h" #include "common/util.h" +#ifdef USE_RGB_COLOR +#include "common/list.h" +#endif #include "graphics/font.h" #include "graphics/fontman.h" #include "graphics/scaler.h" @@ -97,6 +100,9 @@ void OSystem_SDL::beginGFXTransaction(void) { _transactionDetails.needUpdatescreen = false; _transactionDetails.normal1xScaler = false; +#ifdef USE_RGB_COLOR + _transactionDetails.formatChanged = false; +#endif _oldVideoMode = _videoMode; } @@ -120,6 +126,13 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { _videoMode.mode = _oldVideoMode.mode; _videoMode.scaleFactor = _oldVideoMode.scaleFactor; +#ifdef USE_RGB_COLOR + } else if (_videoMode.format != _oldVideoMode.format) { + errors |= kTransactionFormatNotSupported; + + _videoMode.format = _oldVideoMode.format; + _screenFormat = _videoMode.format; +#endif } else if (_videoMode.screenWidth != _oldVideoMode.screenWidth || _videoMode.screenHeight != _oldVideoMode.screenHeight) { errors |= kTransactionSizeChangeFailed; @@ -143,7 +156,11 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { } } +#ifdef USE_RGB_COLOR + if (_transactionDetails.sizeChanged || _transactionDetails.formatChanged) { +#else if (_transactionDetails.sizeChanged) { +#endif unloadGFXMode(); if (!loadGFXMode()) { if (_oldVideoMode.setup) { @@ -186,12 +203,94 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { } else if (_transactionDetails.needUpdatescreen) { setGraphicsModeIntern(); internUpdateScreen(); - } + } _transactionMode = kTransactionNone; return (TransactionError)errors; } +#ifdef USE_RGB_COLOR +const Graphics::PixelFormat RGBList[] = { +#ifdef ENABLE_32BIT + // RGBA8888, ARGB8888, RGB888 + Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0), + Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24), + Graphics::PixelFormat(3, 8, 8, 8, 0, 16, 8, 0, 0), +#endif + // RGB565, XRGB1555, RGB555, RGBA4444, ARGB4444 + Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0), + Graphics::PixelFormat(2, 5, 5, 5, 1, 10, 5, 0, 15), + Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0), + Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0), + Graphics::PixelFormat(2, 4, 4, 4, 4, 8, 4, 0, 12) +}; +const Graphics::PixelFormat BGRList[] = { +#ifdef ENABLE_32BIT + // ABGR8888, BGRA8888, BGR888 + Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24), + Graphics::PixelFormat(4, 8, 8, 8, 8, 8, 16, 24, 0), + Graphics::PixelFormat(3, 8, 8, 8, 0, 0, 8, 16, 0), +#endif + // BGR565, XBGR1555, BGR555, ABGR4444, BGRA4444 + Graphics::PixelFormat(2, 5, 6, 5, 0, 0, 5, 11, 0), + Graphics::PixelFormat(2, 5, 5, 5, 1, 0, 5, 10, 15), + Graphics::PixelFormat(2, 5, 5, 5, 0, 0, 5, 10, 0), + Graphics::PixelFormat(2, 4, 4, 4, 4, 0, 4, 8, 12), + Graphics::PixelFormat(2, 4, 4, 4, 4, 4, 8, 12, 0) +}; + +// TODO: prioritize matching alpha masks +Common::List<Graphics::PixelFormat> OSystem_SDL::getSupportedFormats() { + static Common::List<Graphics::PixelFormat> list; + static bool inited = false; + + if (inited) + return list; + + bool BGR = false; + int listLength = ARRAYSIZE(RGBList); + + Graphics::PixelFormat format = Graphics::PixelFormat::createFormatCLUT8(); + if (_hwscreen) { + // Get our currently set hardware format + format = Graphics::PixelFormat(_hwscreen->format->BytesPerPixel, + 8 - _hwscreen->format->Rloss, 8 - _hwscreen->format->Gloss, + 8 - _hwscreen->format->Bloss, 8 - _hwscreen->format->Aloss, + _hwscreen->format->Rshift, _hwscreen->format->Gshift, + _hwscreen->format->Bshift, _hwscreen->format->Ashift); + + // Workaround to MacOSX SDL not providing an accurate Aloss value. + if (_hwscreen->format->Amask == 0) + format.aLoss = 8; + + // Push it first, as the prefered format. + list.push_back(format); + + if (format.bShift > format.rShift) + BGR = true; + + // Mark that we don't need to do this any more. + inited = true; + } + + for (int i = 0; i < listLength; i++) { + if (inited && (RGBList[i].bytesPerPixel > format.bytesPerPixel)) + continue; + if (BGR) { + if (BGRList[i] != format) + list.push_back(BGRList[i]); + list.push_back(RGBList[i]); + } else { + if (RGBList[i] != format) + list.push_back(RGBList[i]); + list.push_back(BGRList[i]); + } + } + list.push_back(Graphics::PixelFormat::createFormatCLUT8()); + return list; +} +#endif + bool OSystem_SDL::setGraphicsMode(int mode) { Common::StackLock lock(_graphicsMutex); @@ -340,9 +439,27 @@ int OSystem_SDL::getGraphicsMode() const { return _videoMode.mode; } -void OSystem_SDL::initSize(uint w, uint h) { +void OSystem_SDL::initSize(uint w, uint h, const Graphics::PixelFormat *format) { assert(_transactionMode == kTransactionActive); +#ifdef USE_RGB_COLOR + //avoid redundant format changes + Graphics::PixelFormat newFormat; + if (!format) + newFormat = Graphics::PixelFormat::createFormatCLUT8(); + else + newFormat = *format; + + assert(newFormat.bytesPerPixel > 0); + + if (newFormat != _videoMode.format) + { + _videoMode.format = newFormat; + _transactionDetails.formatChanged = true; + _screenFormat = newFormat; + } +#endif + // Avoid redundant res changes if ((int)w == _videoMode.screenWidth && (int)h == _videoMode.screenHeight) return; @@ -426,9 +543,21 @@ bool OSystem_SDL::loadGFXMode() { // // Create the surface that contains the 8 bit game data // +#ifdef USE_RGB_COLOR + _screen = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth, _videoMode.screenHeight, + _screenFormat.bytesPerPixel << 3, + ((1 << _screenFormat.rBits()) - 1) << _screenFormat.rShift , + ((1 << _screenFormat.gBits()) - 1) << _screenFormat.gShift , + ((1 << _screenFormat.bBits()) - 1) << _screenFormat.bShift , + ((1 << _screenFormat.aBits()) - 1) << _screenFormat.aShift ); + if (_screen == NULL) + error("allocating _screen failed"); + +#else _screen = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth, _videoMode.screenHeight, 8, 0, 0, 0, 0); if (_screen == NULL) error("allocating _screen failed"); +#endif // // Create the surface that contains the scaled graphics in 16 bit mode @@ -571,8 +700,8 @@ bool OSystem_SDL::hotswapGFXMode() { // Keep around the old _screen & _overlayscreen so we can restore the screen data // after the mode switch. SDL_Surface *old_screen = _screen; - SDL_Surface *old_overlayscreen = _overlayscreen; _screen = NULL; + SDL_Surface *old_overlayscreen = _overlayscreen; _overlayscreen = NULL; // Release the HW screen surface @@ -846,30 +975,6 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int * and just updates those, on the actual display. */ addDirtyRgnAuto(src); } else { - /* Clip the coordinates */ - if (x < 0) { - w += x; - src -= x; - x = 0; - } - - if (y < 0) { - h += y; - src -= y * pitch; - y = 0; - } - - if (w > _videoMode.screenWidth - x) { - w = _videoMode.screenWidth - x; - } - - if (h > _videoMode.screenHeight - y) { - h = _videoMode.screenHeight - y; - } - - if (w <= 0 || h <= 0) - return; - _cksumValid = false; addDirtyRect(x, y, w, h); } @@ -878,8 +983,19 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int if (SDL_LockSurface(_screen) == -1) error("SDL_LockSurface failed: %s", SDL_GetError()); +#ifdef USE_RGB_COLOR + byte *dst = (byte *)_screen->pixels + y * _videoMode.screenWidth * _screenFormat.bytesPerPixel + x * _screenFormat.bytesPerPixel; + if (_videoMode.screenWidth == w && pitch == w * _screenFormat.bytesPerPixel) { + memcpy(dst, src, h*w*_screenFormat.bytesPerPixel); + } else { + do { + memcpy(dst, src, w * _screenFormat.bytesPerPixel); + src += pitch; + dst += _videoMode.screenWidth * _screenFormat.bytesPerPixel; + } while (--h); + } +#else byte *dst = (byte *)_screen->pixels + y * _videoMode.screenWidth + x; - if (_videoMode.screenWidth == pitch && pitch == w) { memcpy(dst, src, h*w); } else { @@ -889,6 +1005,7 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int dst += _videoMode.screenWidth; } while (--h); } +#endif // Unlock the screen surface SDL_UnlockSurface(_screen); @@ -912,7 +1029,11 @@ Graphics::Surface *OSystem_SDL::lockScreen() { _framebuffer.w = _screen->w; _framebuffer.h = _screen->h; _framebuffer.pitch = _screen->pitch; +#ifdef USE_RGB_COLOR + _framebuffer.bytesPerPixel = _screenFormat.bytesPerPixel; +#else _framebuffer.bytesPerPixel = 1; +#endif return &_framebuffer; } @@ -1096,6 +1217,11 @@ int16 OSystem_SDL::getWidth() { void OSystem_SDL::setPalette(const byte *colors, uint start, uint num) { assert(colors); +#ifdef USE_RGB_COLOR + if (_screenFormat.bytesPerPixel > 1) + return; //not using a paletted pixel format +#endif + // Setting the palette before _screen is created is allowed - for now - // since we don't actually set the palette until the screen is updated. // But it could indicate a programming error, so let's warn about it. @@ -1149,10 +1275,10 @@ void OSystem_SDL::setCursorPalette(const byte *colors, uint start, uint num) { } _cursorPaletteDisabled = false; - blitCursor(); } + void OSystem_SDL::setShakePos(int shake_pos) { assert (_transactionMode == kTransactionNone); @@ -1357,7 +1483,17 @@ void OSystem_SDL::warpMouse(int x, int y) { } } -void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale) { +void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) { +#ifdef USE_RGB_COLOR + if (!format) + _cursorFormat = Graphics::PixelFormat::createFormatCLUT8(); + else if (format->bytesPerPixel <= _screenFormat.bytesPerPixel) + _cursorFormat = *format; + keycolor &= (1 << (_cursorFormat.bytesPerPixel << 3)) - 1; +#else + keycolor &= 0xFF; +#endif + if (w == 0 || h == 0) return; @@ -1391,16 +1527,26 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, } free(_mouseData); - +#ifdef USE_RGB_COLOR + _mouseData = (byte *)malloc(w * h * _cursorFormat.bytesPerPixel); + memcpy(_mouseData, buf, w * h * _cursorFormat.bytesPerPixel); +#else _mouseData = (byte *)malloc(w * h); memcpy(_mouseData, buf, w * h); +#endif + blitCursor(); } void OSystem_SDL::blitCursor() { byte *dstPtr; const byte *srcPtr = _mouseData; +#ifdef USE_RGB_COLOR + uint32 color; + uint32 colormask = (1 << (_cursorFormat.bytesPerPixel << 3)) - 1; +#else byte color; +#endif int w, h, i, j; if (!_mouseOrigSurface || !_mouseData) @@ -1434,13 +1580,29 @@ void OSystem_SDL::blitCursor() { for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { - color = *srcPtr; - if (color != _mouseKeyColor) { // transparent, don't draw - *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format, - palette[color].r, palette[color].g, palette[color].b); +#ifdef USE_RGB_COLOR + if (_cursorFormat.bytesPerPixel > 1) { + color = (*(uint32 *) srcPtr) & colormask; + if (color != _mouseKeyColor) { // transparent, don't draw + uint8 r,g,b; + _cursorFormat.colorToRGB(color,r,g,b); + *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format, + r, g, b); + } + dstPtr += 2; + srcPtr += _cursorFormat.bytesPerPixel; + } else { +#endif + color = *srcPtr; + if (color != _mouseKeyColor) { // transparent, don't draw + *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format, + palette[color].r, palette[color].g, palette[color].b); + } + dstPtr += 2; + srcPtr++; +#ifdef USE_RGB_COLOR } - dstPtr += 2; - srcPtr++; +#endif } dstPtr += _mouseOrigSurface->pitch - w * 2; } diff --git a/backends/platform/sdl/main.cpp b/backends/platform/sdl/main.cpp index 021bda155c..fa8f6ededb 100644 --- a/backends/platform/sdl/main.cpp +++ b/backends/platform/sdl/main.cpp @@ -37,7 +37,7 @@ #include "SymbianOs.h" #endif -#if !defined(__MAEMO__) && !defined(_WIN32_WCE) && !defined(GP2XWIZ) +#if !defined(__MAEMO__) && !defined(_WIN32_WCE) && !defined(GP2XWIZ)&& !defined(LINUXMOTO) #if defined (WIN32) int __stdcall WinMain(HINSTANCE /*hInst*/, HINSTANCE /*hPrevInst*/, LPSTR /*lpCmdLine*/, int /*iShowCmd*/) { diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 7b3cf4eaa1..547720d435 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -222,6 +222,10 @@ OSystem_SDL::OSystem_SDL() _osdSurface(0), _osdAlpha(SDL_ALPHA_TRANSPARENT), _osdFadeStartTime(0), #endif _hwscreen(0), _screen(0), _tmpscreen(0), +#ifdef USE_RGB_COLOR + _screenFormat(Graphics::PixelFormat::createFormatCLUT8()), + _cursorFormat(Graphics::PixelFormat::createFormatCLUT8()), +#endif _overlayVisible(false), _overlayscreen(0), _tmpscreen2(0), _samplesPerSec(0), @@ -691,7 +695,6 @@ void OSystem_SDL::mixCallback(void *sys, byte *samples, int len) { void OSystem_SDL::setupMixer() { SDL_AudioSpec desired; - SDL_AudioSpec obtained; // Determine the desired output sampling frequency. _samplesPerSec = 0; @@ -721,7 +724,7 @@ void OSystem_SDL::setupMixer() { _mixer = new Audio::MixerImpl(this); assert(_mixer); - if (SDL_OpenAudio(&desired, &obtained) != 0) { + if (SDL_OpenAudio(&desired, &_obtainedRate) != 0) { warning("Could not open audio device: %s", SDL_GetError()); _samplesPerSec = 0; _mixer->setReady(false); @@ -729,7 +732,7 @@ void OSystem_SDL::setupMixer() { // 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. - _samplesPerSec = obtained.freq; + _samplesPerSec = _obtainedRate.freq; debug(1, "Output sample rate: %d Hz", _samplesPerSec); // Tell the mixer that we are ready and start the sound processing @@ -737,7 +740,7 @@ void OSystem_SDL::setupMixer() { _mixer->setReady(true); #ifdef MIXER_DOUBLE_BUFFERING - initThreadedMixer(_mixer, obtained.samples * 4); + initThreadedMixer(_mixer, _obtainedRate.samples * 4); #endif // start the sound system diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index 2a5fda30bd..82c1e7bf1b 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -93,9 +93,17 @@ public: void beginGFXTransaction(void); TransactionError endGFXTransaction(void); - // Set the size of the video bitmap. - // Typically, 320x200 - virtual void initSize(uint w, uint h); // overloaded by CE backend +#ifdef USE_RGB_COLOR + // Game screen + virtual Graphics::PixelFormat getScreenFormat() const { return _screenFormat; } + + // Highest supported + virtual Common::List<Graphics::PixelFormat> getSupportedFormats(); +#endif + + // Set the size and format of the video bitmap. + // Typically, 320x200 CLUT8 + virtual void initSize(uint w, uint h, const Graphics::PixelFormat *format); // overloaded by CE backend virtual int getScreenChangeID() const { return _screenChangeCount; } @@ -124,7 +132,7 @@ public: virtual void warpMouse(int x, int y); // overloaded by CE backend (FIXME) // Set the bitmap that's used when drawing the cursor. - virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale); // overloaded by CE backend (FIXME) + virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format); // overloaded by CE backend (FIXME) // Set colors of cursor palette void setCursorPalette(const byte *colors, uint start, uint num); @@ -186,6 +194,7 @@ public: // Overlay virtual Graphics::PixelFormat getOverlayFormat() const { return _overlayFormat; } + virtual void showOverlay(); virtual void hideOverlay(); virtual void clearOverlay(); @@ -207,6 +216,7 @@ public: virtual bool hasFeature(Feature f); virtual void setFeatureState(Feature f, bool enable); virtual bool getFeatureState(Feature f); + virtual void preprocessEvents(SDL_Event *event) {}; #ifdef USE_OSD void displayMessageOnOSD(const char *msg); @@ -221,6 +231,7 @@ public: protected: bool _inited; + SDL_AudioSpec _obtainedRate; #ifdef USE_OSD SDL_Surface *_osdSurface; @@ -239,6 +250,10 @@ protected: // unseen game screen SDL_Surface *_screen; +#ifdef USE_RGB_COLOR + Graphics::PixelFormat _screenFormat; + Graphics::PixelFormat _cursorFormat; +#endif // temporary screen (for scalers) SDL_Surface *_tmpscreen; @@ -272,6 +287,9 @@ protected: bool needHotswap; bool needUpdatescreen; bool normal1xScaler; +#ifdef USE_RGB_COLOR + bool formatChanged; +#endif }; TransactionDetails _transactionDetails; @@ -288,6 +306,9 @@ protected: int screenWidth, screenHeight; int overlayWidth, overlayHeight; int hardwareWidth, hardwareHeight; +#ifdef USE_RGB_COLOR + Graphics::PixelFormat format; +#endif }; VideoState _videoMode, _oldVideoMode; diff --git a/backends/platform/wii/osystem.cpp b/backends/platform/wii/osystem.cpp index ae1eb11f4f..3f53605e85 100644 --- a/backends/platform/wii/osystem.cpp +++ b/backends/platform/wii/osystem.cpp @@ -52,6 +52,11 @@ OSystem_Wii::OSystem_Wii() : _currentHeight(0), _activeGraphicsMode(0), +#ifdef USE_RGB_COLOR + _texturePF(Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0)), + _screenPF(Graphics::PixelFormat::createFormatCLUT8()), + _cursorPF(Graphics::PixelFormat::createFormatCLUT8()), +#endif _fullscreen(false), diff --git a/backends/platform/wii/osystem.h b/backends/platform/wii/osystem.h index e4176e8415..72263af5a8 100644 --- a/backends/platform/wii/osystem.h +++ b/backends/platform/wii/osystem.h @@ -75,6 +75,11 @@ private: u16 _currentWidth, _currentHeight; s32 _activeGraphicsMode; +#ifdef USE_RGB_COLOR + const Graphics::PixelFormat _texturePF; + Graphics::PixelFormat _screenPF; + Graphics::PixelFormat _cursorPF; +#endif bool _fullscreen; @@ -82,7 +87,7 @@ private: s32 _mouseX, _mouseY; u32 _mouseWidth, _mouseHeight; s32 _mouseHotspotX, _mouseHotspotY; - u8 _mouseKeyColor; + u16 _mouseKeyColor; u8 *_mouseCursor; bool _kbd_active; @@ -119,8 +124,13 @@ public: virtual const GraphicsMode *getSupportedGraphicsModes() const; virtual int getDefaultGraphicsMode() const; virtual bool setGraphicsMode(int mode); +#ifdef USE_RGB_COLOR + virtual Graphics::PixelFormat getScreenFormat() const; + virtual Common::List<Graphics::PixelFormat> getSupportedFormats(); +#endif virtual int getGraphicsMode() const; - virtual void initSize(uint width, uint height); + virtual void initSize(uint width, uint height, + const Graphics::PixelFormat *format); virtual int16 getWidth(); virtual int16 getHeight(); virtual void setPalette(const byte *colors, uint start, uint num); @@ -142,14 +152,15 @@ public: int x, int y, int w, int h); virtual int16 getOverlayWidth(); virtual int16 getOverlayHeight(); - virtual Graphics::PixelFormat getOverlayFormat() const { return Graphics::createPixelFormat<565>(); } + virtual Graphics::PixelFormat getOverlayFormat() const; virtual bool showMouse(bool visible); virtual void warpMouse(int x, int y); virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, - int hotspotY, byte keycolor = 255, - int cursorTargetScale = 1); + int hotspotY, uint32 keycolor, + int cursorTargetScale, + const Graphics::PixelFormat *format); virtual bool pollEvent(Common::Event &event); virtual uint32 getMillis(); diff --git a/backends/platform/wii/osystem_gfx.cpp b/backends/platform/wii/osystem_gfx.cpp index 4454acb318..b0e3f112c1 100644 --- a/backends/platform/wii/osystem_gfx.cpp +++ b/backends/platform/wii/osystem_gfx.cpp @@ -21,6 +21,8 @@ #include <malloc.h> +#include "graphics/conversion.h" + #include "osystem.h" #include "gx_supp.h" @@ -143,21 +145,70 @@ int OSystem_Wii::getGraphicsMode() const { return _activeGraphicsMode; } -void OSystem_Wii::initSize(uint width, uint height) { - if (_gameWidth != width || _gameHeight != height) { - printf("initSize %u %u\n", width, height); +#ifdef USE_RGB_COLOR +Graphics::PixelFormat OSystem_Wii::getScreenFormat() const { + return _screenPF; +} + +Common::List<Graphics::PixelFormat> OSystem_Wii::getSupportedFormats() { + Common::List<Graphics::PixelFormat> res; + res.push_back(_texturePF); + res.push_back(Graphics::PixelFormat::createFormatCLUT8()); + + return res; +} +#endif + +void OSystem_Wii::initSize(uint width, uint height, + const Graphics::PixelFormat *format) { + bool update = false; + +#ifdef USE_RGB_COLOR + Graphics::PixelFormat newFormat; + if (format) + newFormat = *format; + else + newFormat = Graphics::PixelFormat::createFormatCLUT8(); + if (newFormat.bytesPerPixel > 2) + newFormat = Graphics::PixelFormat::createFormatCLUT8(); + + if (_screenPF != newFormat) { + _screenPF = newFormat; + update = true; + } +#endif + + if (_gameWidth != width || _gameHeight != height) { assert((width <= 640) && (height <= 480)); _gameWidth = width; _gameHeight = height; + update = true; + } + + if (update) { +#ifdef USE_RGB_COLOR + printf("initSize %u*%u*%u (%u,%u,%u)\n", + _gameWidth, _gameHeight, + _screenPF.bytesPerPixel * 8, + _screenPF.rShift, _screenPF.gShift, _screenPF.bShift); +#else + printf("initSize %u*%u\n", _gameWidth, _gameHeight); +#endif if(_gamePixels) free(_gamePixels); +#ifdef USE_RGB_COLOR + _gamePixels = (u8 *) memalign(32, _gameWidth * _gameHeight * + _screenPF.bytesPerPixel); + memset(_gamePixels, 0, _gameWidth * _gameHeight * + _screenPF.bytesPerPixel); +#else _gamePixels = (u8 *) memalign(32, _gameWidth * _gameHeight); memset(_gamePixels, 0, _gameWidth * _gameHeight); - +#endif if (!_overlayVisible) { _currentWidth = _gameWidth; _currentHeight = _gameHeight; @@ -177,6 +228,10 @@ int16 OSystem_Wii::getHeight() { } void OSystem_Wii::setPalette(const byte *colors, uint start, uint num) { +#ifdef USE_RGB_COLOR + assert(_screenPF.bytesPerPixel == 1); +#endif + const byte *p = colors; for (uint i = 0; i < num; ++i) { _palette[start + i] = Graphics::RGBToColor<Graphics::ColorMasks<565> >(p[0], p[1], p[2]); @@ -213,37 +268,36 @@ void OSystem_Wii::disableCursorPalette(bool disable) { void OSystem_Wii::copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h) { - if (x < 0) { - w += x; - buf -= x; - x = 0; - } - - if (y < 0) { - h += y; - buf -= y * pitch; - y = 0; - } - - if (w > _gameWidth - x) - w = _gameWidth - x; - - if (h > _gameHeight - y) - h = _gameHeight - y; - - if (w <= 0 || h <= 0) - return; - - byte *dst = _gamePixels + y * _gameWidth + x; - if (_gameWidth == pitch && pitch == w) { - memcpy(dst, buf, h * w); + assert(x >= 0 && x < _gameWidth); + assert(y >= 0 && y < _gameHeight); + assert(w > 0 && x + w <= _gameWidth); + assert(h > 0 && y + h <= _gameHeight); + +#ifdef USE_RGB_COLOR + if (_screenPF.bytesPerPixel > 1) { + if (!Graphics::crossBlit(_gamePixels + + y * _gameWidth * _screenPF.bytesPerPixel + + x * _screenPF.bytesPerPixel, + buf, _gameWidth * _screenPF.bytesPerPixel, + pitch, w, h, _texturePF, _screenPF)) { + printf("crossBlit failed\n"); + ::abort(); + } } else { - do { - memcpy(dst, buf, w); - buf += pitch; - dst += _gameWidth; - } while (--h); +#endif + byte *dst = _gamePixels + y * _gameWidth + x; + if (_gameWidth == pitch && pitch == w) { + memcpy(dst, buf, h * w); + } else { + do { + memcpy(dst, buf, w); + buf += pitch; + dst += _gameWidth; + } while (--h); + } +#ifdef USE_RGB_COLOR } +#endif } void OSystem_Wii::updateScreen() { @@ -251,6 +305,9 @@ void OSystem_Wii::updateScreen() { static s16 msx, msy, mox, moy, mskip; static u16 mpx, mpy; static u8 *s; +#ifdef USE_RGB_COLOR + static u16 *s2; +#endif static u16 *d, *p; u32 now = getMillis(); @@ -267,12 +324,21 @@ void OSystem_Wii::updateScreen() { if (_overlayVisible) { memcpy(_texture, _overlayPixels, _overlaySize); } else { - for (y = 0; y < _gameHeight; ++y) { - for (x = 0; x < _gameWidth; ++x) - _texture[h + x] = _palette[_gamePixels[h + x]]; +#ifdef USE_RGB_COLOR + if (_screenPF.bytesPerPixel > 1) { + memcpy(_texture, _gamePixels, + _gameWidth * _gameHeight * _screenPF.bytesPerPixel); + } else { +#endif + for (y = 0; y < _gameHeight; ++y) { + for (x = 0; x < _gameWidth; ++x) + _texture[h + x] = _palette[_gamePixels[h + x]]; - h += _gameWidth; + h += _gameWidth; + } +#ifdef USE_RGB_COLOR } +#endif } if (_mouseVisible) { @@ -308,25 +374,51 @@ void OSystem_Wii::updateScreen() { skip = _currentWidth - mpx; mskip = _mouseWidth - mpx; - s = _mouseCursor + moy * _mouseWidth + mox; - d = _texture + (msy * _currentWidth + msx); +#ifdef USE_RGB_COLOR + if (_cursorPF.bytesPerPixel > 1) { + s2 = (u16 *) _mouseCursor + moy * _mouseWidth + mox; + d = _texture + (msy * _currentWidth + msx); - for (y = 0; y < mpy; ++y) { - for (x = 0; x < mpx; ++x) { - if (*s == _mouseKeyColor) { - s++; - d++; + for (y = 0; y < mpy; ++y) { + for (x = 0; x < mpx; ++x) { + if (*s2 == _mouseKeyColor) { + s2++; + d++; - continue; + continue; + } + + *d++ = *s2; + s2++; } - *d++ = p[*s]; - s++; + d += skip; + s2 += mskip; } + } else { +#endif + s = _mouseCursor + moy * _mouseWidth + mox; + d = _texture + (msy * _currentWidth + msx); + + for (y = 0; y < mpy; ++y) { + for (x = 0; x < mpx; ++x) { + if (*s == _mouseKeyColor) { + s++; + d++; + + continue; + } - d += skip; - s += mskip; + *d++ = p[*s]; + s++; + } + + d += skip; + s += mskip; + } +#ifdef USE_RGB_COLOR } +#endif } GX_Render(_currentWidth, _currentHeight, (u8 *) _texture, @@ -338,7 +430,11 @@ Graphics::Surface *OSystem_Wii::lockScreen() { _surface.w = _gameWidth; _surface.h = _gameHeight; _surface.pitch = _gameWidth; +#ifdef USE_RGB_COLOR + _surface.bytesPerPixel = _screenPF.bytesPerPixel; +#else _surface.bytesPerPixel = 1; +#endif return &_surface; } @@ -429,6 +525,10 @@ int16 OSystem_Wii::getOverlayHeight() { return _overlayHeight; } +Graphics::PixelFormat OSystem_Wii::getOverlayFormat() const { + return Graphics::createPixelFormat<565>(); +} + bool OSystem_Wii::showMouse(bool visible) { bool last = _mouseVisible; _mouseVisible = visible; @@ -442,20 +542,37 @@ void OSystem_Wii::warpMouse(int x, int y) { } void OSystem_Wii::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, - int hotspotY, byte keycolor, - int cursorTargetScale) { + int hotspotY, uint32 keycolor, + int cursorTargetScale, + const Graphics::PixelFormat *format) { (void) cursorTargetScale; // TODO +#ifdef USE_RGB_COLOR + if (!format) + _cursorPF = Graphics::PixelFormat::createFormatCLUT8(); + else + _cursorPF = *format; + + if (_cursorPF.bytesPerPixel > 1) + _mouseKeyColor = keycolor & 0xffff; + else +#endif + _mouseKeyColor = keycolor & 0xff; + _mouseWidth = w; _mouseHeight = h; _mouseHotspotX = hotspotX; _mouseHotspotY = hotspotY; - _mouseKeyColor = keycolor; if (_mouseCursor) free(_mouseCursor); +#ifdef USE_RGB_COLOR + _mouseCursor = (u8 *) memalign(32, w * h * _cursorPF.bytesPerPixel); + memcpy(_mouseCursor, buf, w * h * _cursorPF.bytesPerPixel); +#else _mouseCursor = (u8 *) memalign(32, w * h); memcpy(_mouseCursor, buf, w * h); +#endif } diff --git a/backends/platform/wince/CEScaler.cpp b/backends/platform/wince/CEScaler.cpp index d26db3190f..0a71fda167 100644 --- a/backends/platform/wince/CEScaler.cpp +++ b/backends/platform/wince/CEScaler.cpp @@ -27,25 +27,25 @@ template<int bitFormat> void PocketPCPortraitTemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) { - uint8 *work; - int i; + uint16 *work; + // Various casts below go via (void *) to avoid warning. This is + // safe as these are all even addresses. while (height--) { - i = 0; - work = dstPtr; + work = (uint16 *)(void *)dstPtr; for (int i=0; i<width; i+=4) { // Work with 4 pixels - uint16 color1 = *(((const uint16 *)srcPtr) + i); - uint16 color2 = *(((const uint16 *)srcPtr) + (i + 1)); - uint16 color3 = *(((const uint16 *)srcPtr) + (i + 2)); - uint16 color4 = *(((const uint16 *)srcPtr) + (i + 3)); + uint16 color1 = *(((const uint16 *)(const void *)srcPtr) + i); + uint16 color2 = *(((const uint16 *)(const void *)srcPtr) + (i + 1)); + uint16 color3 = *(((const uint16 *)(const void *)srcPtr) + (i + 2)); + uint16 color4 = *(((const uint16 *)(const void *)srcPtr) + (i + 3)); - *(((uint16 *)work) + 0) = interpolate32_3_1<bitFormat>(color1, color2); - *(((uint16 *)work) + 1) = interpolate32_1_1<bitFormat>(color2, color3); - *(((uint16 *)work) + 2) = interpolate32_3_1<bitFormat>(color4, color3); + work[0] = interpolate32_3_1<bitFormat>(color1, color2); + work[1] = interpolate32_1_1<bitFormat>(color2, color3); + work[2] = interpolate32_3_1<bitFormat>(color4, color3); - work += 3 * sizeof(uint16); + work += 3; } srcPtr += srcPitch; dstPtr += dstPitch; @@ -65,7 +65,8 @@ void PocketPCLandscapeAspect(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr int i,j; unsigned int p1, p2; - uint8 *inbuf, *outbuf, *instart, *outstart; + const uint8 *inbuf, *instart; + uint8 *outbuf, *outstart; #define RB(x) ((x & RBM)<<8) #define G(x) ((x & GM)<<3) @@ -77,34 +78,36 @@ void PocketPCLandscapeAspect(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr #define MAKEPIXEL(rb,g) ((((rb)>>8) & RBM | ((g)>>3) & GM)) - inbuf = (uint8 *)srcPtr; + inbuf = (const uint8 *)srcPtr; outbuf = (uint8 *)dstPtr; height /= 5; + // Various casts below go via (void *) to avoid warning. This is + // safe as these are all even addresses. for (i = 0; i < height; i++) { instart = inbuf; outstart = outbuf; for (j=0; j < width; j++) { - p1 = *(uint16*)inbuf; inbuf += srcPitch; - *(uint16*)outbuf = p1; outbuf += dstPitch; + p1 = *(const uint16*)(const void *)inbuf; inbuf += srcPitch; + *(uint16*)(void *)outbuf = p1; outbuf += dstPitch; - p2 = *(uint16*)inbuf; inbuf += srcPitch; - *(uint16*)outbuf = MAKEPIXEL(P20(RB(p1))+P80(RB(p2)),P20(G(p1))+P80(G(p2))); outbuf += dstPitch; + p2 = *(const uint16*)(const void *)inbuf; inbuf += srcPitch; + *(uint16*)(void *)outbuf = MAKEPIXEL(P20(RB(p1))+P80(RB(p2)),P20(G(p1))+P80(G(p2))); outbuf += dstPitch; p1 = p2; - p2 = *(uint16*)inbuf; inbuf += srcPitch; - *(uint16*)outbuf = MAKEPIXEL(P40(RB(p1))+P60(RB(p2)),P40(G(p1))+P60(G(p2))); outbuf += dstPitch; + p2 = *(const uint16*)(const void *)inbuf; inbuf += srcPitch; + *(uint16*)(void *)outbuf = MAKEPIXEL(P40(RB(p1))+P60(RB(p2)),P40(G(p1))+P60(G(p2))); outbuf += dstPitch; p1 = p2; - p2 = *(uint16*)inbuf; inbuf += srcPitch; - *(uint16*)outbuf = MAKEPIXEL(P60(RB(p1))+P40(RB(p2)),P60(G(p1))+P40(G(p2))); outbuf += dstPitch; + p2 = *(const uint16*)(const void *)inbuf; inbuf += srcPitch; + *(uint16*)(void *)outbuf = MAKEPIXEL(P60(RB(p1))+P40(RB(p2)),P60(G(p1))+P40(G(p2))); outbuf += dstPitch; p1 = p2; - p2 = *(uint16*)inbuf; - *(uint16*)outbuf = MAKEPIXEL(P80(RB(p1))+P20(RB(p2)),P80(G(p1))+P20(G(p2))); outbuf += dstPitch; + p2 = *(const uint16*)(const void *)inbuf; + *(uint16*)(void *)outbuf = MAKEPIXEL(P80(RB(p1))+P20(RB(p2)),P80(G(p1))+P20(G(p2))); outbuf += dstPitch; - *(uint16*)outbuf = p2; + *(uint16*)(void *)outbuf = p2; inbuf = inbuf - srcPitch*4 + sizeof(uint16); outbuf = outbuf - dstPitch*5 + sizeof(uint16); @@ -127,11 +130,9 @@ extern "C" { template<int bitFormat> void PocketPCHalfTemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) { uint8 *work; - int i; uint16 srcPitch16 = (uint16)(srcPitch / sizeof(uint16)); while ((height -= 2) >= 0) { - i = 0; work = dstPtr; for (int i=0; i<width; i+=2) { @@ -163,23 +164,20 @@ void PocketPCHalf(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 ds template<int bitFormat> void PocketPCHalfZoomTemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) { - uint8 *work; - int i; - uint16 srcPitch16 = (uint16)(srcPitch / sizeof(uint16)); + uint16 *work; if (!height) return; + // Various casts below go via (void *) to avoid warning. This is + // safe as these are all even addresses. while (height--) { - i = 0; - work = dstPtr; + work = (uint16 *)(void *)dstPtr; for (int i = 0; i < width; i += 2) { - uint16 color1 = *(((const uint16 *)srcPtr) + i); - uint16 color2 = *(((const uint16 *)srcPtr) + (i + 1)); - *(((uint16 *)work) + 0) = interpolate32_1_1<bitFormat>(color1, color2); - - work += sizeof(uint16); + uint16 color1 = *(((const uint16 *)(const void *)srcPtr) + i); + uint16 color2 = *(((const uint16 *)(const void *)srcPtr) + (i + 1)); + *work++ = interpolate32_1_1<bitFormat>(color1, color2); } srcPtr += srcPitch; dstPtr += dstPitch; @@ -190,11 +188,9 @@ MAKE_WRAPPER(PocketPCHalfZoom) template<int bitFormat> void SmartphoneLandscapeTemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) { uint8 *work; - int i; int line = 0; while (height--) { - i = 0; work = dstPtr; for (int i = 0; i < width; i += 3) { diff --git a/backends/platform/wince/wince-sdl.cpp b/backends/platform/wince/wince-sdl.cpp index 65082014da..ab7860dd85 100644 --- a/backends/platform/wince/wince-sdl.cpp +++ b/backends/platform/wince/wince-sdl.cpp @@ -1084,7 +1084,7 @@ void OSystem_WINCE3::update_game_settings() { _noDoubleTapRMB = ConfMan.getBool("no_doubletap_rightclick"); } -void OSystem_WINCE3::initSize(uint w, uint h) { +void OSystem_WINCE3::initSize(uint w, uint h, const Graphics::PixelFormat *format) { if (_hasSmartphoneResolution && h == 240) h = 200; // mainly for the launcher @@ -1120,7 +1120,7 @@ void OSystem_WINCE3::initSize(uint w, uint h) { _videoMode.overlayWidth = w; _videoMode.overlayHeight = h; - OSystem_SDL::initSize(w, h); + OSystem_SDL::initSize(w, h, format); if (_scalersChanged) { unloadGFXMode(); diff --git a/backends/platform/wince/wince-sdl.h b/backends/platform/wince/wince-sdl.h index deafde6d80..7b4d0f2b25 100644 --- a/backends/platform/wince/wince-sdl.h +++ b/backends/platform/wince/wince-sdl.h @@ -66,7 +66,7 @@ public: void internUpdateScreen(); void setGraphicsModeIntern(); - void initSize(uint w, uint h); + void initSize(uint w, uint h, const Graphics::PixelFormat *format); void initBackend(); // Overloaded from SDL backend (toolbar handling) diff --git a/backends/timer/default/default-timer.cpp b/backends/timer/default/default-timer.cpp index bd2222bbbc..dd468bbe09 100644 --- a/backends/timer/default/default-timer.cpp +++ b/backends/timer/default/default-timer.cpp @@ -124,6 +124,12 @@ bool DefaultTimerManager::installTimerProc(TimerProc callback, int32 interval, v slot->nextFireTimeMicro = interval % 1000; slot->next = 0; + // FIXME: It seems we do allow the client to add one callback multiple times over here, + // but "removeTimerProc" will remove *all* added instances. We should either prevent + // multiple additions of a timer proc OR we should change removeTimerProc to only remove + // a specific timer proc entry. + // Probably we can safely just allow a single addition of a specific function once + // and just update our Timer documentation accordingly. insertPrioQueue(_head, slot); return true; |