[Scummvm-cvs-logs] SF.net SVN: scummvm:[48632] scummvm/trunk
Bluddy at users.sourceforge.net
Bluddy at users.sourceforge.net
Mon Apr 12 08:49:06 CEST 2010
Revision: 48632
http://scummvm.svn.sourceforge.net/scummvm/?rev=48632&view=rev
Author: Bluddy
Date: 2010-04-12 06:49:05 +0000 (Mon, 12 Apr 2010)
Log Message:
-----------
PSP: refactoring/redesign of the backend
Modified Paths:
--------------
scummvm/trunk/backends/fs/psp/psp-fs-factory.h
scummvm/trunk/backends/fs/psp/psp-fs.cpp
scummvm/trunk/backends/fs/psp/psp-stream.cpp
scummvm/trunk/backends/fs/psp/psp-stream.h
scummvm/trunk/backends/platform/psp/Makefile
scummvm/trunk/backends/platform/psp/README.PSP.in
scummvm/trunk/backends/platform/psp/module.mk
scummvm/trunk/backends/platform/psp/osys_psp.cpp
scummvm/trunk/backends/platform/psp/osys_psp.h
scummvm/trunk/backends/platform/psp/powerman.cpp
scummvm/trunk/backends/platform/psp/powerman.h
scummvm/trunk/backends/platform/psp/psp_main.cpp
scummvm/trunk/backends/platform/psp/pspkeyboard.cpp
scummvm/trunk/backends/platform/psp/pspkeyboard.h
scummvm/trunk/backends/platform/psp/psploader.h
scummvm/trunk/backends/platform/psp/trace.cpp
scummvm/trunk/backends/platform/psp/trace.h
scummvm/trunk/configure
Added Paths:
-----------
scummvm/trunk/backends/platform/psp/cursor.cpp
scummvm/trunk/backends/platform/psp/cursor.h
scummvm/trunk/backends/platform/psp/default_display_client.cpp
scummvm/trunk/backends/platform/psp/default_display_client.h
scummvm/trunk/backends/platform/psp/display_client.cpp
scummvm/trunk/backends/platform/psp/display_client.h
scummvm/trunk/backends/platform/psp/display_manager.cpp
scummvm/trunk/backends/platform/psp/display_manager.h
scummvm/trunk/backends/platform/psp/input.cpp
scummvm/trunk/backends/platform/psp/input.h
scummvm/trunk/backends/platform/psp/memory.cpp
scummvm/trunk/backends/platform/psp/memory.h
scummvm/trunk/backends/platform/psp/psppixelformat.cpp
scummvm/trunk/backends/platform/psp/psppixelformat.h
Modified: scummvm/trunk/backends/fs/psp/psp-fs-factory.h
===================================================================
--- scummvm/trunk/backends/fs/psp/psp-fs-factory.h 2010-04-11 22:01:18 UTC (rev 48631)
+++ scummvm/trunk/backends/fs/psp/psp-fs-factory.h 2010-04-12 06:49:05 UTC (rev 48632)
@@ -35,6 +35,7 @@
*/
class PSPFilesystemFactory : public FilesystemFactory, public Common::Singleton<PSPFilesystemFactory> {
public:
+ const char *getObjectName() const { return "PSPFilesystemFactory"; }
virtual AbstractFSNode *makeRootFileNode() const;
virtual AbstractFSNode *makeCurrentDirectoryFileNode() const;
virtual AbstractFSNode *makeFileNodePath(const Common::String &path) const;
Modified: scummvm/trunk/backends/fs/psp/psp-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/psp/psp-fs.cpp 2010-04-11 22:01:18 UTC (rev 48631)
+++ scummvm/trunk/backends/fs/psp/psp-fs.cpp 2010-04-12 06:49:05 UTC (rev 48632)
@@ -35,6 +35,9 @@
#define ROOT_PATH "ms0:/"
+//#define __PSP_PRINT_TO_FILE__
+//#define __PSP_DEBUG_FUNCS__ /* For debugging function calls */
+//#define __PSP_DEBUG_PRINT__ /* For debug printouts */
#include "backends/platform/psp/trace.h"
/**
@@ -63,6 +66,7 @@
*/
PSPFilesystemNode(const Common::String &p, bool verify = true);
+ const char *getObjectName() const { return "PSPFileSystemNode"; }
virtual bool exists() const;
virtual Common::String getDisplayName() const { return _displayName; }
virtual Common::String getName() const { return _displayName; }
@@ -87,6 +91,7 @@
}
PSPFilesystemNode::PSPFilesystemNode(const Common::String &p, bool verify) {
+ DEBUG_ENTER_FUNC();
assert(p.size() > 0);
_path = p;
@@ -94,54 +99,70 @@
_isValid = true;
_isDirectory = true;
+ PSP_DEBUG_PRINT_FUNC("path [%s]\n", _path.c_str());
+
if (verify) {
struct stat st;
if (PowerMan.beginCriticalSection()==PowerManager::Blocked)
- PSPDebugSuspend("Suspended in PSPFilesystemNode::PSPFilesystemNode\n");
+ PSP_DEBUG_PRINT_FUNC("Suspended\n");
_isValid = (0 == stat(_path.c_str(), &st));
PowerMan.endCriticalSection();
_isDirectory = S_ISDIR(st.st_mode);
}
+ DEBUG_EXIT_FUNC();
}
bool PSPFilesystemNode::exists() const {
+ DEBUG_ENTER_FUNC();
int ret = 0;
if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
- PSPDebugSuspend("Suspended in PSPFilesystemNode::exists()\n"); // Make sure to block in case of suspend
+ PSP_DEBUG_PRINT_FUNC("Suspended\n"); // Make sure to block in case of suspend
+ PSP_DEBUG_PRINT_FUNC("path [%s]\n", _path.c_str());
+
ret = access(_path.c_str(), F_OK);
PowerMan.endCriticalSection();
- return ret == 0;
+ DEBUG_EXIT_FUNC();
+ return (ret == 0);
}
bool PSPFilesystemNode::isReadable() const {
+ DEBUG_ENTER_FUNC();
int ret = 0;
if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
- PSPDebugSuspend("Suspended in PSPFilesystemNode::isReadable()\n"); // Make sure to block in case of suspend
+ PSP_DEBUG_PRINT_FUNC("Suspended\n"); // Make sure to block in case of suspend
+ PSP_DEBUG_PRINT_FUNC("path [%s]\n", _path.c_str());
+
ret = access(_path.c_str(), R_OK);
PowerMan.endCriticalSection();
- return ret == 0;
+ DEBUG_EXIT_FUNC();
+ return (ret == 0);
}
bool PSPFilesystemNode::isWritable() const {
+ DEBUG_ENTER_FUNC();
int ret = 0;
if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
- PSPDebugSuspend("Suspended in PSPFilesystemNode::isWritable()\n"); // Make sure to block in case of suspend
+ PSP_DEBUG_PRINT_FUNC("Suspended\n"); // Make sure to block in case of suspend
+ PSP_DEBUG_PRINT_FUNC("path [%s]\n", _path.c_str());
+
ret = access(_path.c_str(), W_OK);
PowerMan.endCriticalSection();
+ DEBUG_EXIT_FUNC();
return ret == 0;
}
AbstractFSNode *PSPFilesystemNode::getChild(const Common::String &n) const {
+ DEBUG_ENTER_FUNC();
// FIXME: Pretty lame implementation! We do no error checking to speak
// of, do not check if this is a special node, etc.
assert(_isDirectory);
@@ -151,10 +172,16 @@
newPath += '/';
newPath += n;
- return new PSPFilesystemNode(newPath, true);
+ PSP_DEBUG_PRINT_FUNC("child [%s]\n", newPath.c_str());
+
+ AbstractFSNode *node = new PSPFilesystemNode(newPath, true);
+
+ DEBUG_EXIT_FUNC();
+ return node;
}
bool PSPFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const {
+ DEBUG_ENTER_FUNC();
assert(_isDirectory);
//TODO: honor the hidden flag
@@ -162,8 +189,10 @@
bool ret = true;
if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
- PSPDebugSuspend("Suspended in PSPFilesystemNode::getChildren\n"); // Make sure to block in case of suspend
+ PSP_DEBUG_PRINT_FUNC("Suspended\n"); // Make sure to block in case of suspend
+ PSP_DEBUG_PRINT_FUNC("Current path[%s]\n", _path.c_str());
+
int dfd = sceIoDopen(_path.c_str());
if (dfd > 0) {
SceIoDirent dir;
@@ -186,7 +215,9 @@
entry._path = newPath;
entry._isDirectory = dir.d_stat.st_attr & FIO_SO_IFDIR;
-
+
+ PSP_DEBUG_PRINT_FUNC("Child[%s], %s\n", entry._path.c_str(), entry._isDirectory ? "dir" : "file");
+
// Honor the chosen mode
if ((mode == Common::FSNode::kListFilesOnly && entry._isDirectory) ||
(mode == Common::FSNode::kListDirectoriesOnly && !entry._isDirectory))
@@ -202,17 +233,24 @@
}
PowerMan.endCriticalSection();
+
+ DEBUG_EXIT_FUNC();
return ret;
}
AbstractFSNode *PSPFilesystemNode::getParent() const {
+ DEBUG_ENTER_FUNC();
if (_path == ROOT_PATH)
return 0;
+ PSP_DEBUG_PRINT_FUNC("current[%s]\n", _path.c_str());
+
const char *start = _path.c_str();
const char *end = lastPathComponent(_path, '/');
- return new PSPFilesystemNode(Common::String(start, end - start), false);
+ AbstractFSNode *node = new PSPFilesystemNode(Common::String(start, end - start), false);
+ DEBUG_EXIT_FUNC();
+ return node;
}
Common::SeekableReadStream *PSPFilesystemNode::createReadStream() {
Modified: scummvm/trunk/backends/fs/psp/psp-stream.cpp
===================================================================
--- scummvm/trunk/backends/fs/psp/psp-stream.cpp 2010-04-11 22:01:18 UTC (rev 48631)
+++ scummvm/trunk/backends/fs/psp/psp-stream.cpp 2010-04-12 06:49:05 UTC (rev 48632)
@@ -27,15 +27,20 @@
#include <SDL/SDL_thread.h>
#include <SDL/SDL_mutex.h>
-#include "backends/platform/psp/trace.h"
#include "backends/platform/psp/powerman.h"
#include "backends/fs/psp/psp-stream.h"
#include <errno.h>
+//#define __PSP_PRINT_TO_FILE__
+//#define __PSP_DEBUG_FUNCS__ /* For debugging function calls */
+//#define __PSP_DEBUG_PRINT__ /* For debug printouts */
+#include "backends/platform/psp/trace.h"
+
PSPIoStream::PSPIoStream(const Common::String &path, bool writeMode)
: StdioStream((void *)1), _path(path), _writeMode(writeMode) {
-
+ DEBUG_ENTER_FUNC();
+
assert(!path.empty());
_handle = (void *)0; // Need to do this since base class asserts not 0.
@@ -43,34 +48,40 @@
_feof = false;
_pos = 0;
-#ifdef __PSP_DEBUG_SUSPEND__
+ /* for error checking */
_errorSuspend = 0;
_errorSource = 0;
_errorPos = 0;
_errorHandle = 0;
_suspendCount = 0;
-#endif
+
+ DEBUG_EXIT_FUNC();
}
PSPIoStream::~PSPIoStream() {
+ DEBUG_ENTER_FUNC();
+
if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
- PSPDebugSuspend("Suspended in PSPIoStream::~PSPIoStream()\n");
+ PSP_DEBUG_PRINT_FUNC("Suspended\n");
PowerMan.unregisterSuspend(this); // Unregister with powermanager to be suspended
- // Must do this before fclose() or resume() will reopen.
+ // Must do this before fclose() or resume() will reopen.
fclose((FILE *)_handle); // We don't need a critical section(?). Worst case, the handle gets closed on its own
PowerMan.endCriticalSection();
+
+ DEBUG_EXIT_FUNC();
}
-// Function to open the file pointed to by the path.
-//
-//
+/* Function to open the file pointed to by the path.
+ *
+ */
void *PSPIoStream::open() {
+ DEBUG_ENTER_FUNC();
if (PowerMan.beginCriticalSection() == PowerManager::Blocked) {
// No need to open. Just return the _handle resume() already opened.
- PSPDebugSuspend("Suspended in PSPIoStream::open\n");
+ PSP_DEBUG_PRINT_FUNC("Suspended\n");
}
_handle = fopen(_path.c_str(), _writeMode ? "wb" : "rb"); // open
@@ -79,20 +90,22 @@
PowerMan.endCriticalSection();
+ DEBUG_EXIT_FUNC();
return _handle;
}
bool PSPIoStream::err() const {
+ DEBUG_ENTER_FUNC();
if (_ferror)
- PSPDebugSuspend("In PSPIoStream::err - mem_ferror=%d, source=%d, suspend error=%d, pos=%d, _errorPos=%d, _errorHandle=%p, suspendCount=%d _handle\n",
+ PSP_ERROR("mem_ferror[%d], source[%d], suspend error[%d], pos[%d], _errorPos[%d], _errorHandle[%p], suspendCount[%d]\n",
_ferror, _errorSource, _errorSuspend, _pos, _errorPos, _errorHandle, _suspendCount);
+ DEBUG_EXIT_FUNC();
return _ferror;
}
void PSPIoStream::clearErr() {
_ferror = false; // Remove regular error bit
-
}
bool PSPIoStream::eos() const {
@@ -105,45 +118,43 @@
int32 PSPIoStream::size() const {
+ DEBUG_ENTER_FUNC();
if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
- PSPDebugSuspend("Suspended in PSPIoStream::size()\n");
+ PSP_DEBUG_PRINT_FUNC("Suspended\n");
fseek((FILE *)_handle, 0, SEEK_END);
int32 length = ftell((FILE *)_handle);
fseek((FILE *)_handle, _pos, SEEK_SET);
if (_pos < 0 || length < 0) { // Check for errors
- PSPDebugSuspend("In PSPIoStream::size(). encountered an error!\n");
+ _errorSource = 2;
+ PSP_ERROR("pos[%d] or length[%d] < 0!\n", _pos, length);
_ferror = true;
length = -1; // If our oldPos is bad, we want length to be bad too to signal
clearerr((FILE *)_handle);
-
-#ifdef __PSP_DEBUG_SUSPEND__
- _errorSource = 2;
-#endif
}
PowerMan.endCriticalSection();
+ DEBUG_EXIT_FUNC();
return length;
}
bool PSPIoStream::seek(int32 offs, int whence) {
+ DEBUG_ENTER_FUNC();
+
// Check if we can access the file
if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
- PSPDebugSuspend("Suspended in PSPIoStream::seek()\n");
+ PSP_DEBUG_PRINT_FUNC("Suspended\n");
int ret = fseek((FILE *)_handle, offs, whence);
if (ret != 0) {
_ferror = true;
- PSPDebugSuspend("In PSPIoStream::seek(). encountered an error!\n");
+ PSP_ERROR("fseek returned with [%d], non-zero\n", ret);
clearerr((FILE *)_handle);
_feof = feof((FILE *)_handle);
-
-#ifdef __PSP_DEBUG_SUSPEND__
_errorSource = 3;
-#endif
}
else { // everything ok
_feof = false; // Reset eof flag since we know it was ok
@@ -153,13 +164,17 @@
PowerMan.endCriticalSection();
- return ret == 0;
+ DEBUG_EXIT_FUNC();
+ return (ret == 0);
}
uint32 PSPIoStream::read(void *ptr, uint32 len) {
+ DEBUG_ENTER_FUNC();
// Check if we can access the file
if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
- PSPDebugSuspend("Suspended in PSPIoStream::read()\n");
+ PSP_DEBUG_PRINT_FUNC("Suspended\n");
+
+ PSP_DEBUG_PRINT_FUNC("filename[%s], len[%d]\n", _path.c_str(), len);
size_t ret = fread((byte *)ptr, 1, len, (FILE *)_handle);
@@ -171,24 +186,25 @@
_ferror = true;
clearerr((FILE *)_handle);
_pos = ftell((FILE *)_handle); // Update our position
- PSPDebugSuspend("In PSPIoStream::read(). encountered an error!\n");
-
-#ifdef __PSP_DEBUG_SUSPEND__
_errorSource = 4;
-#endif
+ PSP_ERROR("fread returned ret[%d] instead of len[%d]\n", ret, len);
}
}
PowerMan.endCriticalSection();
+ DEBUG_EXIT_FUNC();
return ret;
}
uint32 PSPIoStream::write(const void *ptr, uint32 len) {
+ DEBUG_ENTER_FUNC();
// Check if we can access the file
if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
- PSPDebugSuspend("Suspended in PSPIoStream::read()\n");
+ PSP_DEBUG_PRINT_FUNC("Suspended\n");
+ PSP_DEBUG_PRINT_FUNC("filename[%s], len[%d]\n", _path.c_str(), len);
+
size_t ret = fwrite(ptr, 1, len, (FILE *)_handle);
_pos += ret;
@@ -197,73 +213,73 @@
_ferror = true;
clearerr((FILE *)_handle);
_pos = ftell((FILE *)_handle); // Update pos
- PSPDebugTrace("In PSPIoStream::write(). encountered an error!\n");
-
-#ifdef __PSP_DEBUG_SUSPEND__
_errorSource = 5;
-#endif
+ PSP_ERROR("fwrite returned[%d] instead of len[%d]\n", ret, len);
}
PowerMan.endCriticalSection();
+ DEBUG_EXIT_FUNC();
return ret;
}
bool PSPIoStream::flush() {
+ DEBUG_ENTER_FUNC();
// Enter critical section
if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
- PSPDebugSuspend("Suspended in PSPIoStream::read()\n");
+ PSP_DEBUG_PRINT_FUNC("Suspended\n");
int ret = fflush((FILE *)_handle);
if (ret != 0) {
_ferror = true;
clearerr((FILE *)_handle);
- PSPDebugSuspend("In PSPIoStream::flush(). encountered an error!\n");
-
-#ifdef __PSP_DEBUG_SUSPEND__
_errorSource = 6;
-#endif
+ PSP_ERROR("fflush returned ret[%u]\n", ret);
}
PowerMan.endCriticalSection();
- return ret == 0;
+ DEBUG_EXIT_FUNC();
+ return (ret == 0);
}
// For the PSP, since we're building in suspend support, we moved opening
// the actual file to an open function since we need an actual PSPIoStream object to suspend.
//
PSPIoStream *PSPIoStream::makeFromPath(const Common::String &path, bool writeMode) {
+ DEBUG_ENTER_FUNC();
PSPIoStream *stream = new PSPIoStream(path, writeMode);
- if (stream->open() > 0) {
- return stream;
- } else {
+ if (stream->open() <= 0) {
delete stream;
- return 0;
+ stream = 0;
}
+
+ DEBUG_EXIT_FUNC();
+ return stream;
}
/*
* Function to suspend the IO stream (called by PowerManager)
+ * we can have no output here
*/
int PSPIoStream::suspend() {
-#ifdef __PSP_DEBUG_SUSPEND__
+ DEBUG_ENTER_FUNC();
_suspendCount++;
- if (_handle > 0 && _pos < 0) {
+ if (_handle > 0 && _pos < 0) { /* check for error */
_errorSuspend = SuspendError;
_errorPos = _pos;
_errorHandle = _handle;
}
-#endif /* __PSP_DEBUG_SUSPEND__ */
if (_handle > 0) {
fclose((FILE *)_handle); // close our file descriptor
_handle = (void *)0xFFFFFFFF; // Set handle to non-null invalid value so makeFromPath doesn't return error
}
+ DEBUG_EXIT_FUNC();
return 0;
}
@@ -271,31 +287,27 @@
* Function to resume the IO stream (called by Power Manager)
*/
int PSPIoStream::resume() {
+ DEBUG_ENTER_FUNC();
int ret = 0;
-#ifdef __PSP_DEBUG_SUSPEND__
_suspendCount--;
-#endif
// We reopen our file descriptor
_handle = fopen(_path.c_str(), _writeMode ? "wb" : "rb");
if (_handle <= 0) {
- PSPDebugSuspend("PSPIoStream::resume(): Couldn't reopen file %s\n", _path.c_str());
+ PSP_ERROR("Couldn't reopen file %s\n", _path.c_str());
}
// Resume our previous position
if (_handle > 0 && _pos > 0) {
ret = fseek((FILE *)_handle, _pos, SEEK_SET);
-#ifdef __PSP_DEBUG_SUSPEND__
if (ret != 0) { // Check for problem
_errorSuspend = ResumeError;
_errorPos = _pos;
_errorHandle = _handle;
}
-#endif
-
}
-
+ DEBUG_EXIT_FUNC();
return ret;
}
Modified: scummvm/trunk/backends/fs/psp/psp-stream.h
===================================================================
--- scummvm/trunk/backends/fs/psp/psp-stream.h 2010-04-11 22:01:18 UTC (rev 48631)
+++ scummvm/trunk/backends/fs/psp/psp-stream.h 2010-04-12 06:49:05 UTC (rev 48632)
@@ -49,13 +49,14 @@
int _errorSuspend;
mutable int _errorSource;
-#ifdef __PSP_DEBUG_SUSPEND__
+ // Error checking
int _errorPos;
void * _errorHandle;
int _suspendCount;
-#endif /* __PSP_DEBUG_SUSPEND__ */
public:
+
+ const char *getObjectName() const { return "PSPIoStream"; }
/**
* Given a path, invoke fopen on that path and wrap the result in a
* PSPIoStream instance.
Modified: scummvm/trunk/backends/platform/psp/Makefile
===================================================================
--- scummvm/trunk/backends/platform/psp/Makefile 2010-04-11 22:01:18 UTC (rev 48631)
+++ scummvm/trunk/backends/platform/psp/Makefile 2010-04-12 06:49:05 UTC (rev 48632)
@@ -66,7 +66,7 @@
#CC = psp-gcc
CXX = psp-g++
CXXFLAGS = -O3 -Wall -Wno-multichar -fno-exceptions -fno-rtti
-DEFINES = -D__PSP__ -DNONSTANDARD_PORT -DDISABLE_TEXT_CONSOLE -DDISABLE_COMMAND_LINE -DUSE_ZLIB -DDISABLE_DOSBOX_OPL
+DEFINES = -D__PSP__ -DNONSTANDARD_PORT -DDISABLE_TEXT_CONSOLE -DDISABLE_COMMAND_LINE -DUSE_ZLIB -DDISABLE_DOSBOX_OPL -DUSE_RGB_COLOR
LDFLAGS :=
INCDIR := $(srcdir) . $(srcdir)/engines/ $(PSPSDK)/include
INCLUDES := $(addprefix -I, $(INCDIR))
@@ -133,6 +133,13 @@
OBJS := powerman.o \
psp_main.o \
osys_psp.o \
+ psppixelformat.o \
+ memory.o \
+ display_manager.o \
+ display_client.o \
+ default_display_client.o \
+ input.o \
+ cursor.o \
trace.o \
psploader.o \
pspkeyboard.o
Modified: scummvm/trunk/backends/platform/psp/README.PSP.in
===================================================================
--- scummvm/trunk/backends/platform/psp/README.PSP.in 2010-04-11 22:01:18 UTC (rev 48631)
+++ scummvm/trunk/backends/platform/psp/README.PSP.in 2010-04-12 06:49:05 UTC (rev 48632)
@@ -16,12 +16,13 @@
Right trigger - Modifier key (see below for uses)
Analog - Mouse movement
Right trigger + Analog - Fine control mouse
-Directionals - Mouse movement
+Directions - Arrow keys
+Directions + Right Trigger - Diagonal arrow keys
Triangle - Enter
Cross - Mouse button 1
Circle - Mouse button 2
Square - '.' (skip dialogue in some games)
-Start - F5
+Start - F5 (Main Menu)
Right trigger + Start - Return-To-Launcher menu
Virtual Keyboard
Added: scummvm/trunk/backends/platform/psp/cursor.cpp
===================================================================
--- scummvm/trunk/backends/platform/psp/cursor.cpp (rev 0)
+++ scummvm/trunk/backends/platform/psp/cursor.cpp 2010-04-12 06:49:05 UTC (rev 48632)
@@ -0,0 +1,365 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/platform/psp/osys_psp.h $
+ * $Id: osys_psp.h 46120 2009-11-24 10:33:30Z Bluddy $
+ *
+ */
+
+#include "common/scummsys.h"
+#include "backends/platform/psp/display_client.h"
+#include "backends/platform/psp/default_display_client.h"
+#include "backends/platform/psp/cursor.h"
+
+//#define __PSP_DEBUG_FUNCS__ /* For debugging the stack */
+//#define __PSP_DEBUG_PRINT__
+
+#include "backends/platform/psp/trace.h"
+
+void Cursor::init() {
+ DEBUG_ENTER_FUNC();
+
+ _renderer.setBuffer(&_buffer); // We do this explicitly
+ _renderer.setPalette(&_screenPalette); // because we want to choose screenpalette by default
+ _renderer.setUseGlobalScaler(true);
+ setRendererModePalettized(true); // Assume we start in 8bit mode
+
+ // Default modes
+ _palette.setPixelFormats(PSPPixelFormat::Type_5551, PSPPixelFormat::Type_Palette_8bit); // default
+ _screenPalette.setPixelFormats(PSPPixelFormat::Type_5551, PSPPixelFormat::Type_Palette_8bit);
+ _buffer.setPixelFormat(PSPPixelFormat::Type_5551);
+
+ DEBUG_EXIT_FUNC();
+}
+
+void Cursor::deallocate() {
+ DEBUG_ENTER_FUNC();
+
+ _buffer.deallocate();
+ _palette.deallocate();
+ _screenPalette.deallocate();
+
+ DEBUG_EXIT_FUNC();
+}
+
+void Cursor::setCursorPalette(const byte *colors, uint start, uint num) {
+ DEBUG_ENTER_FUNC();
+
+ if (!_palette.isAllocated()) {
+ _palette.allocate();
+ }
+
+ // Workaround: This is wrong, but we seem to not be getting setScreenPalette
+ if (!_screenPalette.isAllocated()) {
+ _screenPalette.allocate();
+ }
+
+ _palette.setPartial(colors, start, num);
+ setDirty();
+
+ DEBUG_EXIT_FUNC();
+}
+
+void Cursor::setScreenPalette(const byte *colors, uint start, uint num) {
+ DEBUG_ENTER_FUNC();
+
+ if (!_screenPalette.isAllocated()) {
+ _screenPalette.allocate();
+ }
+
+ _screenPalette.setPartial(colors, start, num);
+ setDirty();
+
+ DEBUG_EXIT_FUNC();
+}
+
+void Cursor::setKeyColor(uint32 color) {
+ DEBUG_ENTER_FUNC();
+ PSP_DEBUG_PRINT("new color[%u], old color[%u]\n", color, _keyColor);
+
+ // If it's a different color, undo the last keycolor
+ if (_buffer.hasPalette() && color != _keyColor) {
+ if (_screenPalette.isAllocated())
+ _screenPalette.setColorPositionAlpha(_keyColor, true);
+ if (_palette.isAllocated())
+ _palette.setColorPositionAlpha(_keyColor, true);
+ }
+ // Don't need anything special for 16-bit
+ _keyColor = color;
+
+ DEBUG_EXIT_FUNC();
+}
+
+void Cursor::clearKeyColor() {
+ DEBUG_ENTER_FUNC();
+ PSP_DEBUG_PRINT("keyColor[%d]\n", _keyColor);
+
+ // We need 2 mechanisms: one for palettized and one for 16 bit
+ if (_buffer.hasPalette()) {
+ if (_screenPalette.isAllocated())
+ _screenPalette.setColorPositionAlpha(_keyColor, false); // set keycolor to 0
+ if (_palette.isAllocated())
+ _palette.setColorPositionAlpha(_keyColor, false);
+ } else { // 16bit
+ _renderer.setKeyColor(_keyColor);
+ }
+ setDirty();
+
+ DEBUG_EXIT_FUNC();
+}
+
+void Cursor::enableCursorPalette(bool enable) {
+ DEBUG_ENTER_FUNC();
+ PSP_DEBUG_PRINT("enable[%s]\n", enable ? "true" : "false");
+
+ _useCursorPalette = enable;
+ if (enable)
+ _renderer.setPalette(&_palette); // very important that we do this switch
+ else
+ _renderer.setPalette(&_screenPalette);
+
+ setDirty();
+ DEBUG_EXIT_FUNC();
+}
+
+inline void Cursor::setSize(uint32 width, uint32 height) {
+ DEBUG_ENTER_FUNC();
+ PSP_DEBUG_PRINT("width[%u], height[%u]\n", width, height);
+
+ _buffer.setSize(width, height, Buffer::kSizeByTextureSize); // we'll use texture size for mouse
+ _renderer.setDrawWholeBuffer(); // We need to let the renderer know how much to draw
+
+ DEBUG_EXIT_FUNC();
+}
+
+void Cursor::copyFromArray(const byte *array) {
+ DEBUG_ENTER_FUNC();
+
+ if (!_buffer.isAllocated()) {
+ _buffer.allocate();
+ }
+
+ _buffer.copyFromArray(array, _buffer.getSourceWidthInBytes()); // pitch is source width
+ setDirty();
+
+ // debug
+ //PSP_DEBUG_DO(_buffer.print(0xF));
+
+ DEBUG_EXIT_FUNC();
+
+}
+
+void Cursor::setHotspot(int32 x, int32 y) {
+ DEBUG_ENTER_FUNC();
+
+ _hotspotX = x;
+ _hotspotY = y;
+ updateRendererOffset(); // Important
+
+ PSP_DEBUG_PRINT("hotspotX[%d], hotspotY[%d]\n", x, y);
+ DEBUG_EXIT_FUNC();
+}
+
+// Returns true if change in x or y
+bool Cursor::increaseXY(int32 incX, int32 incY) {
+ DEBUG_ENTER_FUNC();
+
+ int32 oldX = _x, oldY = _y;
+
+ // adjust for differences in X and Y
+ adjustXYForScreenSize(incX, incY);
+
+ _x += incX;
+ _y += incY;
+
+ // Clamp mouse
+ if (_x < 0)
+ _x = 0;
+ if (_y < 0)
+ _y = 0;
+ if (_x >= (int)_mouseLimitWidth)
+ _x = (int)_mouseLimitWidth - 1;
+ if (_y >= (int)_mouseLimitHeight)
+ _y = (int)_mouseLimitHeight - 1;
+
+ PSP_DEBUG_PRINT("X[%d], Y[%d]\n", _x, _y);
+
+ if (oldX != _x || oldY != _y) {
+ updateRendererOffset();
+ setDirty();
+ DEBUG_EXIT_FUNC();
+ return true;
+ }
+
+ DEBUG_EXIT_FUNC();
+ return false;
+}
+
+// Set limits on the movement of the cursor ie. screen size
+void Cursor::setLimits(uint32 width, uint32 height) {
+ #define PSP_SCREEN_WIDTH 480
+ #define PSP_SCREEN_HEIGHT 272
+ DEBUG_ENTER_FUNC();
+
+ PSP_DEBUG_PRINT("width[%u], height[%u]\n", width, height);
+ _mouseLimitWidth = width;
+ _mouseLimitHeight = height;
+
+ DEBUG_EXIT_FUNC();
+}
+
+// Adjust X,Y movement for the screen size to keep it consistent
+inline void Cursor::adjustXYForScreenSize(int32 &x, int32 &y) {
+ DEBUG_ENTER_FUNC();
+ // We have our speed calibrated for the y axis at 480x272. The idea is to adjust this for other
+ // resolutions and for x, which is wider.
+ int32 newX = x, newY = y;
+
+ // adjust width movement to match height (usually around 1.5)
+ if (_mouseLimitWidth >= _mouseLimitHeight + (_mouseLimitHeight >> 1))
+ newX = newX + (newX >> 1);
+
+ if (_mouseLimitWidth >= 600) { // multiply by 2
+ newX <<= 1;
+ newY <<= 1;
+ } else if (_mouseLimitWidth >= 480) { // multiply by 1.5
+ newX = newX + (newX >> 1);
+ newY = newY + (newY >> 1);
+ }
+
+ // Divide all movements by 8
+ newX >>= 3;
+ newY >>= 3;
+
+ // Make sure we didn't destroy minimum movement
+ if (!((x && !newX) || (y && !newY))) {
+ x = newX;
+ y = newY;
+ }
+
+ DEBUG_EXIT_FUNC();
+}
+
+// This is only called when we have a new screen
+void Cursor::setScreenPaletteScummvmPixelFormat(const Graphics::PixelFormat *format) {
+ DEBUG_ENTER_FUNC();
+
+ uint32 oldPaletteSize = 0;
+ if (_screenPalette.isAllocated())
+ oldPaletteSize = _screenPalette.getSizeInBytes();
+
+ PSPPixelFormat::Type bufferType = PSPPixelFormat::Type_Unknown;
+ PSPPixelFormat::Type paletteType = PSPPixelFormat::Type_Unknown;
+ bool swapRedBlue = false;
+
+ // Convert Scummvm Pixel Format to PSPPixelFormat
+ PSPPixelFormat::convertFromScummvmPixelFormat(format, bufferType, paletteType, swapRedBlue);
+
+ if (paletteType == PSPPixelFormat::Type_None) {
+ //_screenPalette.deallocate(); // leave palette for default CLUT8
+ setRendererModePalettized(false); // use 16-bit mechanism
+ } else { // We have a palette
+ _screenPalette.setPixelFormats(paletteType, bufferType);
+ _palette.setPixelFormats(paletteType, bufferType);
+ setRendererModePalettized(true); // use palettized mechanism
+ }
+
+ DEBUG_EXIT_FUNC();
+}
+
+// This is called many many times
+void Cursor::setSizeAndScummvmPixelFormat(uint32 width, uint32 height, const Graphics::PixelFormat *format) {
+ DEBUG_ENTER_FUNC();
+
+ PSP_DEBUG_PRINT("useCursorPalette[%s]\n", _useCursorPalette ? "true" : "false");
+
+ uint32 oldBufferSize = 0, oldPaletteSize = 0;
+
+ if (_buffer.isAllocated())
+ oldBufferSize = _buffer.getSizeInBytes();
+
+ if (_palette.isAllocated())
+ oldPaletteSize = _palette.getSizeInBytes();
+
+ setSize(width, height);
+
+ PSPPixelFormat::Type bufferType = PSPPixelFormat::Type_Unknown;
+ PSPPixelFormat::Type paletteType = PSPPixelFormat::Type_Unknown;
+ bool swapRedBlue = false;
+
+ PSPPixelFormat::convertFromScummvmPixelFormat(format, bufferType, paletteType, swapRedBlue);
+ PSP_DEBUG_PRINT("bufferType[%u], paletteType[%u]\n", bufferType, paletteType);
+
+ // Check if we need to set new pixel format
+ if (_buffer.getPixelFormat() != bufferType) {
+ PSP_DEBUG_PRINT("new buffer pixel format[%u] is different from [%u]. Setting it.\n", bufferType, _buffer.getPixelFormat());
+ _buffer.setPixelFormat(bufferType);
+ }
+
+ // Check if we need to reallocate
+ if (_buffer.getSizeInBytes() != oldBufferSize) {
+ _buffer.allocate();
+ PSP_DEBUG_PRINT("reallocating buffer. new size: width[%u], height[%u]\n", width, height);
+ }
+
+ PSP_DEBUG_PRINT("palette pixel format[%u]\n", paletteType);
+
+ if (paletteType == PSPPixelFormat::Type_None) {
+ setRendererModePalettized(false); // use palettized mechanism
+ } else { // We have a palette
+ _palette.setPixelFormats(paletteType, bufferType);
+ setRendererModePalettized(true); // use palettized mechanism
+ }
+
+ // debug
+ // PSP_DEBUG_DO(_palette.print(10));
+ // PSP_DEBUG_DO(_screenPalette.print(10));
+
+ DEBUG_EXIT_FUNC();
+}
+
+void Cursor::setXY(int x, int y) {
+ DEBUG_ENTER_FUNC();
+
+ _x = x;
+ _y = y;
+ updateRendererOffset(); // Very important to let renderer know things changed
+ setDirty();
+
+ DEBUG_EXIT_FUNC();
+}
+
+inline void Cursor::updateRendererOffset() {
+ DEBUG_ENTER_FUNC();
+ _renderer.setOffsetOnScreen(_x - _hotspotX, _y - _hotspotY);
+ DEBUG_EXIT_FUNC();
+}
+
+inline void Cursor::setRendererModePalettized(bool palettized) {
+ if (palettized) { // We have a palette. Use blending
+ _renderer.setAlphaBlending(true);
+ _renderer.setAlphaReverse(false);
+ _renderer.setColorTest(false);
+ } else { // 16 bits, no palette
+ _renderer.setAlphaBlending(true);
+ _renderer.setAlphaReverse(true); // We can't change all alpha values, so just reverse
+ _renderer.setColorTest(true); // Color test to make our key color transparent
+ }
+}
Property changes on: scummvm/trunk/backends/platform/psp/cursor.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: scummvm/trunk/backends/platform/psp/cursor.h
===================================================================
--- scummvm/trunk/backends/platform/psp/cursor.h (rev 0)
+++ scummvm/trunk/backends/platform/psp/cursor.h 2010-04-12 06:49:05 UTC (rev 48632)
@@ -0,0 +1,81 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/platform/psp/osys_psp.h $
+ * $Id: osys_psp.h 46120 2009-11-24 10:33:30Z Bluddy $
+ *
+ */
+
+#ifndef MOUSE_H
+#define MOUSE_H
+
+class Cursor : public DefaultDisplayClient {
+private:
+ int _hotspotX, _hotspotY;
+ uint32 _keyColor;
+ int _cursorTargetScale;
+ bool _useCursorPalette;
+ bool _hasCursorPalette;
+ uint32 _mouseLimitWidth;
+ uint32 _mouseLimitHeight;
+ int32 _x, _y;
+ Palette _screenPalette; // separate palette for screen. default 'palette' is cursor palette.
+
+ void updateRendererOffset();
+
+public:
+ Cursor() : _hotspotX(0), _hotspotY(0), _keyColor(0), _cursorTargetScale(0),
+ _useCursorPalette(false), _hasCursorPalette(false), _mouseLimitWidth(0),
+ _mouseLimitHeight(0), _x(0), _y(0) { }
+ virtual ~Cursor() { deallocate(); }
+
+ void setKeyColor(uint32 color);
+ void setCursorTargetScale(int scale) { _cursorTargetScale = scale; }
+ void setScreenPalette(const byte *colors, uint start, uint num);
+ void copyFromArray(const byte *array);
+ Palette &palette() { return _palette; }
+ Buffer &buffer() { return _buffer; }
+ void setCursorPalette(const byte *colors, uint start, uint num);
+ void enableCursorPalette(bool enable);
+ void setLimits(uint32 width, uint32 height);
+ void setXY(int x, int y);
+ int32 getX() { return _x; }
+ int32 getY() { return _y; }
+ bool increaseXY(int32 incX, int32 incY); // returns true if there's a change in x or y
+ void adjustXYForScreenSize(int32 &x, int32 &y);
+ void init();
+ void setHotspot(int32 x, int32 y);
+ void setScreenPaletteScummvmPixelFormat(const Graphics::PixelFormat *format);
+ void setSizeAndScummvmPixelFormat(uint32 widht, uint32 height, const Graphics::PixelFormat *format);
+ void clearKeyColor();
+ void useGlobalScaler(bool val) { _renderer.setUseGlobalScaler(val); }
+ bool allocate();
+ void deallocate();
+
+private:
+ void setSize(uint32 width, uint32 height);
+ void getPixelFormatsFromScummvmPixelFormat(const Graphics::PixelFormat *format,
+ PSPPixelFormat::Type &bufferFormat,
+ PSPPixelFormat::Type &paletteFormat,
+ uint32 &numOfEntries);
+ void setRendererModePalettized(bool palettized);
+};
+
+#endif /* MOUSE_H */
Property changes on: scummvm/trunk/backends/platform/psp/cursor.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: scummvm/trunk/backends/platform/psp/default_display_client.cpp
===================================================================
--- scummvm/trunk/backends/platform/psp/default_display_client.cpp (rev 0)
+++ scummvm/trunk/backends/platform/psp/default_display_client.cpp 2010-04-12 06:49:05 UTC (rev 48632)
@@ -0,0 +1,238 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/platform/psp/osys_psp.h $
+ * $Id: osys_psp.h 46120 2009-11-24 10:33:30Z Bluddy $
+ *
+ */
+
+#include "common/scummsys.h"
+#include "backends/platform/psp/display_client.h"
+#include "backends/platform/psp/default_display_client.h"
+
+//#define __PSP_DEBUG_FUNCS__ /* For debugging the stack */
+//#define __PSP_DEBUG_PRINT__
+
+#include "backends/platform/psp/trace.h"
+
+// Class DefaultDisplayClient ---------------------------------------------
+
+bool DefaultDisplayClient::allocate(bool bufferInVram /* = false */, bool paletteInVram /* = false */) {
+ DEBUG_ENTER_FUNC();
+
+ if (!_buffer.allocate(bufferInVram)) {
+ PSP_ERROR("Couldn't allocate buffer.\n");
+ DEBUG_EXIT_FUNC();
+ return false;
+ }
+
+ if (_buffer.hasPalette())
+ {
+ PSP_DEBUG_PRINT("_palette[%p]\n", &_palette);
+
+ if (!_palette.allocate()) {
+ PSP_ERROR("Couldn't allocate pallette.\n");
+ DEBUG_EXIT_FUNC();
+ return false;
+ }
+ }
+
+ DEBUG_EXIT_FUNC();
+ return true;
+}
+
+void DefaultDisplayClient::deallocate() {
+ _buffer.deallocate();
+ if (_buffer.hasPalette())
+ _palette.deallocate();
+}
+
+
+void DefaultDisplayClient::clearBuffer() {
+ DEBUG_ENTER_FUNC();
+ _buffer.clear();
+ setDirty();
+ DEBUG_EXIT_FUNC();
+}
+
+inline void DefaultDisplayClient::clearPalette() {
+ DEBUG_ENTER_FUNC();
+ _palette.clear();
+ setDirty();
+ DEBUG_EXIT_FUNC();
+}
+
+void DefaultDisplayClient::init() {
+ DEBUG_ENTER_FUNC();
+ _renderer.setBuffer(&_buffer);
+ _renderer.setPalette(&_palette);
+ DEBUG_EXIT_FUNC();
+}
+
+void DefaultDisplayClient::copyFromRect(const byte *buf, int pitch, int destX, int destY, int recWidth, int recHeight) {
+ DEBUG_ENTER_FUNC();
+ _buffer.copyFromRect(buf, pitch, destX, destY, recWidth, recHeight);
+ setDirty();
+ DEBUG_EXIT_FUNC();
+}
+
+void DefaultDisplayClient::copyToArray(byte *dst, int pitch) {
+ DEBUG_ENTER_FUNC();
+ _buffer.copyToArray(dst, pitch);
+ DEBUG_EXIT_FUNC();
+}
+
+// Class Overlay -------------------------------------------------------
+
+void Overlay::init() {
+ DEBUG_ENTER_FUNC();
+
+ DefaultDisplayClient::init();
+ _renderer.setAlphaBlending(true);
+ _renderer.setColorTest(false);
+ _renderer.setUseGlobalScaler(false);
+ _renderer.setFullScreen(true); // speeds up render slightly
+
+ DEBUG_EXIT_FUNC();
+}
+
+void Overlay::setBytesPerPixel(uint32 size) {
+ DEBUG_ENTER_FUNC();
+
+ switch (size) {
+ case 1:
+ _buffer.setPixelFormat(PSPPixelFormat::Type_Palette_8bit);
+ _palette.setPixelFormats(PSPPixelFormat::Type_4444, PSPPixelFormat::Type_Palette_8bit);
+ break;
+ case 2:
+ _buffer.setPixelFormat(PSPPixelFormat::Type_4444);
+ break;
+ case 4:
+ _buffer.setPixelFormat(PSPPixelFormat::Type_8888);
+ break;
+ }
+
+ DEBUG_EXIT_FUNC();
+}
+
+void Overlay::setSize(uint32 width, uint32 height) {
+ DEBUG_ENTER_FUNC();
+ _buffer.setSize(width, height, Buffer::kSizeBySourceSize);
+ _renderer.setDrawWholeBuffer(); // We need to let the renderer know how much to draw
+ DEBUG_EXIT_FUNC();
+}
+
+void Overlay::copyToArray(OverlayColor *buf, int pitch) {
+ DEBUG_ENTER_FUNC();
+ _buffer.copyToArray((byte *)buf, pitch * sizeof(OverlayColor)); // Change to bytes
+ DEBUG_EXIT_FUNC();
+}
+
+void Overlay::copyFromRect(const OverlayColor *buf, int pitch, int x, int y, int w, int h) {
+ DEBUG_ENTER_FUNC();
+
+ _buffer.copyFromRect((byte *)buf, pitch * sizeof(OverlayColor), x, y, w, h); // Change to bytes
+ // debug
+ //_buffer.print(0xFF);
+ setDirty();
+ DEBUG_EXIT_FUNC();
+}
+
+bool Overlay::allocate() {
+ DEBUG_ENTER_FUNC();
+
+ bool ret = DefaultDisplayClient::allocate(true, false); // buffer in VRAM
+
+ DEBUG_EXIT_FUNC();
+ return ret;
+}
+
+// Class Screen -----------------------------------------------------------
+
+void Screen::init() {
+ DEBUG_ENTER_FUNC();
+
+ DefaultDisplayClient::init();
+ _renderer.setAlphaBlending(false);
+ _renderer.setColorTest(false);
+ _renderer.setUseGlobalScaler(true);
+ _renderer.setFullScreen(true);
+
+ DEBUG_EXIT_FUNC();
+}
+
+void Screen::setShakePos(int pos) {
+ _shakePos = pos;
+ _renderer.setOffsetOnScreen(0, pos);
+ setDirty();
+}
+
+void Screen::setSize(uint32 width, uint32 height) {
+ DEBUG_ENTER_FUNC();
+
+ _buffer.setSize(width, height, Buffer::kSizeBySourceSize);
+ _renderer.setDrawWholeBuffer(); // We need to let the renderer know how much to draw
+
+ DEBUG_EXIT_FUNC();
+}
+
+void Screen::setScummvmPixelFormat(const Graphics::PixelFormat *format) {
+ DEBUG_ENTER_FUNC();
+ PSP_DEBUG_PRINT("format[%p], _buffer[%p], _palette[%p]\n", format, &_buffer, &_palette);
+
+ if (!format) {
+ bzero(&_pixelFormat, sizeof(_pixelFormat));
+ _pixelFormat.bytesPerPixel = 1; // default
+ } else {
+ _pixelFormat = *format;
+ }
+
+ PSPPixelFormat::Type bufferFormat, paletteFormat;
+ bool swapRedBlue = false;
+
+ PSPPixelFormat::convertFromScummvmPixelFormat(format, bufferFormat, paletteFormat, swapRedBlue);
+ _buffer.setPixelFormat(bufferFormat, swapRedBlue);
+ _palette.setPixelFormats(paletteFormat, bufferFormat, swapRedBlue);
+
+ DEBUG_EXIT_FUNC();
+}
+
+Graphics::Surface *Screen::lockAndGetForEditing() {
+ DEBUG_ENTER_FUNC();
+
+ _frameBuffer.pixels = _buffer.getPixels();
+ _frameBuffer.w = _buffer.getSourceWidth();
+ _frameBuffer.h = _buffer.getSourceHeight();
+ _frameBuffer.pitch = _buffer.getBytesPerPixel() * _buffer.getWidth();
+ _frameBuffer.bytesPerPixel = _buffer.getBytesPerPixel();
+ // We'll set to dirty once we unlock the screen
+
+ DEBUG_EXIT_FUNC();
+
+ return &_frameBuffer;
+}
+
+bool Screen::allocate() {
+ DEBUG_ENTER_FUNC();
+
+ return DefaultDisplayClient::allocate(true, false); // buffer in VRAM
+
+ DEBUG_EXIT_FUNC();
+}
Property changes on: scummvm/trunk/backends/platform/psp/default_display_client.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: scummvm/trunk/backends/platform/psp/default_display_client.h
===================================================================
--- scummvm/trunk/backends/platform/psp/default_display_client.h (rev 0)
+++ scummvm/trunk/backends/platform/psp/default_display_client.h 2010-04-12 06:49:05 UTC (rev 48632)
@@ -0,0 +1,108 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/platform/psp/trace.h $
+ * $Id: trace.h 44276 2009-09-23 16:11:23Z joostp $
+ *
+ */
+
+#ifndef PSP_DEF_DISPLAY_CLIENT_H
+#define PSP_DEF_DISPLAY_CLIENT_H
+
+/**
+ * Default display client that is useful for most purposes.
+ */
+class DefaultDisplayClient : public DisplayClient {
+public:
+ DefaultDisplayClient() : _visible(false), _dirty(true) {}
+
+ bool isVisible() { return _visible; }
+ void setVisible(bool v) { _visible = v; setDirty(); }
+ Buffer &buffer() { return _buffer; }
+ Palette &palette() { return _palette; }
+ void init();
+ bool allocate(bool bufferInVram = false, bool paletteInVram = false);
+ void deallocate();
+ void clearBuffer();
+ void clearPalette();
+ void render() { _renderer.render(); }
+ uint32 getWidth() { return _buffer.getSourceWidth(); }
+ uint32 getHeight() { return _buffer.getSourceHeight(); }
+ void setPartialPalette(const byte *colors, uint start, uint num) { setDirty(); return _palette.setPartial(colors, start, num); }
+ void getPartialPalette(byte *colors, uint start, uint num) {
+ return _palette.getPartial(colors, start, num);
+ }
+ void copyFromRect(const byte *buf, int pitch, int destX, int destY, int recWidth, int recHeight);
+ void copyToArray(byte *dst, int pitch);
+ void setDirty() { _dirty = true; }
+ void setClean() { _dirty = false; }
+ bool isDirty() { return _dirty; }
+
+protected:
+ Buffer _buffer;
+ Palette _palette;
+ GuRenderer _renderer;
+ bool _visible;
+ bool _dirty;
+};
+
+/**
+ * Screen overlay class.
+ */
+class Overlay : public DefaultDisplayClient {
+public:
+ Overlay() {}
+ ~Overlay() { }
+
+ void init();
+ bool allocate();
+ void setBytesPerPixel(uint32 size);
+ void setSize(uint32 width, uint32 height);
+ void copyToArray(OverlayColor *buf, int pitch);
+ void copyFromRect(const OverlayColor *buf, int pitch, int x, int y, int w, int h);
+};
+
+/**
+ * Screen class.
+ */
+class Screen : public DefaultDisplayClient {
+public:
+ Screen() : _shakePos(0) {
+ memset(&_pixelFormat, 0, sizeof(_pixelFormat));
+ memset(&_frameBuffer, 0, sizeof(_frameBuffer));
+ }
+ ~Screen() {}
+
+ void init();
+ bool allocate();
+ void setShakePos(int pos);
+ void setScummvmPixelFormat(const Graphics::PixelFormat *format);
+ const Graphics::PixelFormat &getScummvmPixelFormat() const { return _pixelFormat; }
+ Graphics::Surface *lockAndGetForEditing();
+ void unlock() { setDirty(); } // set dirty here because of changes
+ void setSize(uint32 width, uint32 height);
+
+private:
+ uint32 _shakePos;
+ Graphics::PixelFormat _pixelFormat;
+ Graphics::Surface _frameBuffer;
+};
+
+#endif /* PSP_DEF_DISPLAY_CLIENT_H */
Property changes on: scummvm/trunk/backends/platform/psp/default_display_client.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: scummvm/trunk/backends/platform/psp/display_client.cpp
===================================================================
--- scummvm/trunk/backends/platform/psp/display_client.cpp (rev 0)
+++ scummvm/trunk/backends/platform/psp/display_client.cpp 2010-04-12 06:49:05 UTC (rev 48632)
@@ -0,0 +1,805 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/platform/psp/osys_psp.cpp $
+ * $Id: osys_psp.cpp 46126 2009-11-24 14:18:46Z fingolfin $
+ *
+ */
+
+#include <pspgu.h>
+#include <pspdisplay.h>
+#include <psputils.h>
+
+#include "common/scummsys.h"
+#include "backends/platform/psp/display_client.h"
+#include "backends/platform/psp/display_manager.h"
+#include "backends/platform/psp/memory.h"
+
+//#define __PSP_DEBUG_FUNCS__ /* For debugging the stack */
+//#define __PSP_DEBUG_PRINT__
+#include "backends/platform/psp/trace.h"
+
+#define PSP_BUFFER_WIDTH (512)
+#define PSP_SCREEN_WIDTH 480
+#define PSP_SCREEN_HEIGHT 272
+#define PSP_FRAME_SIZE (PSP_BUFFER_WIDTH * PSP_SCREEN_HEIGHT)
+
+DisplayManager *GuRenderer::_displayManager = 0;
+
+
+// class Palette ------------------------------------------------------------
+//
+void Palette::clear() {
+ DEBUG_ENTER_FUNC();
+
+ if (_values && _numOfEntries)
+ memset(_values, 0, getSizeInBytes());
+
+ PSP_DEBUG_PRINT("_values[%p]\n", _values);
+
+ DEBUG_EXIT_FUNC();
+}
+
+// Used to clear the specific keycolor
+//
+void Palette::setColorPositionAlpha(uint32 position, bool alpha) {
+ DEBUG_ENTER_FUNC();
+
+ assert(_values);
+ assert(position < _numOfEntries);
+
+ PSP_DEBUG_PRINT("position[%d], numofEntries[%u], bpp[%u], values[%p]\n", position, _numOfEntries,
+ _pixelFormat.bitsPerPixel, _values);
+
+ if (_numOfEntries <= 16)
+ position &= 0xF;
+ else if (_numOfEntries <= 256)
+ position &= 0xFF;
+
+ switch (_pixelFormat.bitsPerPixel) {
+ case 16: {
+ uint16 *shortVal = (uint16 *)&_values[_pixelFormat.pixelsToBytes(position)];
+ *shortVal = _pixelFormat.setColorAlpha((uint32)*shortVal, alpha ? 255 : 0);
+ }
+ break;
+ case 32: {
+ uint32 *wordVal = (uint32 *)&_values[_pixelFormat.pixelsToBytes(position)];
+ *wordVal = _pixelFormat.setColorAlpha((uint32)*wordVal, alpha ? 255 : 0);
+ }
+ break;
+ default:
+ PSP_ERROR("Incorrect bits per pixel value[%u]\n", _pixelFormat.bitsPerPixel);
+ }
+
+ DEBUG_EXIT_FUNC();
+}
+
+// Set some of the palette to color values in array
+// By default, ScummVm doesn't support alpha values in palettes
+void Palette::setPartial(const byte *colors, uint32 start, uint32 num, bool supportsAlpha /* = false */) {
+ DEBUG_ENTER_FUNC();
+
+ assert(_values);
+ assert(_numOfEntries);
+
+ const byte *src = colors;
+
+ if (start + num > _numOfEntries) // Check boundary
+ num = _numOfEntries - start;
+
+ if (_pixelFormat.bitsPerPixel == 16) {
+ uint16 *palette = (uint16 *)_values;
+ palette += start;
+
+ for (uint32 i = 0; i < num; ++i) {
+ byte alphaVal = supportsAlpha ? src[3] : 0xFF;
+ *palette = (uint16)_pixelFormat.rgbaToColor(src[0], src[1], src[2], alphaVal);
+ src += 4;
+ palette++;
+ }
+ }
+ else if (_pixelFormat.bitsPerPixel == 32) {
+ uint32 *palette = (uint32 *)_values;
+ palette += start;
+
+ for (uint32 i = 0; i < num; ++i) {
+ byte alphaVal = supportsAlpha ? src[3] : 0xFF;
+ *palette = _pixelFormat.rgbaToColor(src[0], src[1], src[2], alphaVal);
+ src += 4;
+ palette++;
+ }
+ }
+
+ DEBUG_EXIT_FUNC();
+}
+
+// Sets pixel format and number of entries by the buffer's pixel format */
+void Palette::setPixelFormats(PSPPixelFormat::Type paletteType, PSPPixelFormat::Type bufferType, bool swapRedBlue /* = false */) {
+ DEBUG_ENTER_FUNC();
+
+ if (paletteType == PSPPixelFormat::Type_Unknown)
+ PSP_ERROR("Unknown paletteType[%u]\n", paletteType);
+
+ switch (bufferType) {
+ case PSPPixelFormat::Type_Palette_8bit:
+ _numOfEntries = 256;
+ break;
+ case PSPPixelFormat::Type_Palette_4bit:
+ _numOfEntries = 16;
+ break;
+ case PSPPixelFormat::Type_Unknown:
+ case PSPPixelFormat::Type_None:
+ PSP_ERROR("Unhandled bufferType[%u]\n", bufferType);
+ break;
+ default: // No palette
+ _numOfEntries = 0;
+ break;
+ }
+
+ _pixelFormat.set(paletteType, swapRedBlue);
+
+ DEBUG_EXIT_FUNC();
+}
+
+bool Palette::allocate() {
+ DEBUG_ENTER_FUNC();
+ PSP_DEBUG_PRINT("_numOfEntries[%u]\n", _numOfEntries);
+ PSP_DEBUG_PRINT("_pixelFormat: format[%u], bpp[%u]\n", _pixelFormat.format, _pixelFormat.bitsPerPixel);
+
+ if (_values) {
+ free (CACHED(_values));
+ _values = 0;
+ }
+
+ // We allocate on 64bytes to get a cache line, and round up to 64bytes to get the full line
+ uint32 amountInBytes = getSizeInBytes();
+ if (amountInBytes < 64)
+ amountInBytes = 64;
+ _values = (byte *)memalign(64, amountInBytes);
+
+ // Use uncached memory
+ GuRenderer::cacheInvalidate(_values, amountInBytes);
+ _values = UNCACHED(_values);
+
+ if (!_values) {
+ PSP_ERROR("Couldn't allocate palette.\n");
+ DEBUG_EXIT_FUNC();
+ return false;
+ }
+
+ PSP_DEBUG_PRINT("_values[%p]\n", _values);
+ clear();
+
+ DEBUG_EXIT_FUNC();
+ return true;
+}
+
+void Palette::deallocate() {
+ DEBUG_ENTER_FUNC();
+
+ free (CACHED(_values));
+ _values = 0;
+ _numOfEntries = 0;
+
+ DEBUG_EXIT_FUNC();
+}
+
+// Copy some of the palette to an array of colors
+//
+void Palette::getPartial(byte *colors, uint start, uint num) {
+ DEBUG_ENTER_FUNC();
+
+ assert(_values);
+ assert(_numOfEntries);
+
+ uint32 r, g, b, a;
+
+ if (start + num > _numOfEntries) // Check boundary
+ num = _numOfEntries - start;
+
+ if (_pixelFormat.bitsPerPixel == 16) {
+ uint16 *palette = (uint16 *)_values;
+ palette += start;
+
+ for (uint32 i = start; i < start + num; i++) {
+ _pixelFormat.colorToRgba(*palette, r, g, b, a);
+
+ *colors++ = (byte)r;
+ *colors++ = (byte)g;
+ *colors++ = (byte)b;
+ *colors++ = (byte)a;
+ palette++;
+ }
+ } else if (_pixelFormat.bitsPerPixel == 32) {
+ uint32 *palette = (uint32 *)_values;
+ palette += start;
+
+ for (uint32 i = start; i < start + num; i++) {
+ _pixelFormat.colorToRgba(*palette, r, g, b, a);
+
+ *colors++ = (byte)r;
+ *colors++ = (byte)g;
+ *colors++ = (byte)b;
+ *colors++ = (byte)a;
+ palette++;
+ }
+ }
+
+ DEBUG_EXIT_FUNC();
+}
+
+void Palette::setSingleColorRGBA(uint32 num, byte r, byte g, byte b, byte a) {
+ // DEBUG_ENTER_FUNC();
+ uint16 *shortValues;
+ uint32 *wordValues;
+
+ assert (_values);
+ assert (num < _numOfEntries);
+
+ switch (_pixelFormat.bitsPerPixel) {
+ case 16:
+ shortValues = (uint16 *)_values;
+ shortValues[num] = _pixelFormat.rgbaToColor(r, g, b, a);
+ break;
+ case 32:
+ wordValues = (uint32 *)_values;
+ wordValues[num] = _pixelFormat.rgbaToColor(r, g, b, a);
+ break;
+ default:
+ PSP_ERROR("Incorrect bitsPerPixel[%d]\n", _pixelFormat.bitsPerPixel);
+ break;
+ }
+ // DEBUG_EXIT_FUNC();
+}
+
+// Print to screen
+void Palette::print(uint32 numToPrint /* = 0 */) {
+ if (_numOfEntries > 0) {
+ assert (_values);
+
+ if (numToPrint > _numOfEntries || numToPrint == 0)
+ numToPrint = _numOfEntries;
+
+ PSP_INFO_PRINT("cursor palette:\n");
+
+ for (unsigned int i=0; i<numToPrint; i++) {
+ byte *pcolor = &_values[_pixelFormat.pixelsToBytes(i)];
+ uint32 color = _pixelFormat.getColorValueAt(pcolor);
+
+ PSP_INFO_PRINT("[%u=%x] ", i, color);
+ }
+
+ PSP_INFO_PRINT("\n");
+ }
+}
+
+uint32 Palette::getRawColorAt(uint32 position) {
+ byte *pcolor = &_values[_pixelFormat.pixelsToBytes(position)];
+ uint32 color = _pixelFormat.getColorValueAt(pcolor);
+ return color;
+}
+
+uint32 Palette::getRGBAColorAt(uint32 position) {
+ uint32 color = getRawColorAt(position);
+ uint32 r, g, b, a;
+ _pixelFormat.colorToRgba(color, r, g, b, a);
+ return (a << 24 | b << 16 | g << 8 | r);
+}
+
+// class Buffer ---------------------------------------------------
+
+void Buffer::setPixelFormat(PSPPixelFormat::Type type, bool swapRedBlue) {
+ if (type == PSPPixelFormat::Type_None ||
+ type == PSPPixelFormat::Type_Unknown)
+ PSP_ERROR("Unhandled buffer format[%u]\n", type);
+
+ _pixelFormat.set(type, swapRedBlue);
+}
+
+bool Buffer::hasPalette() {
+ if (_pixelFormat.format == PSPPixelFormat::Type_Palette_8bit ||
+ _pixelFormat.format == PSPPixelFormat::Type_Palette_4bit)
+ return true;
+
+ return false;
+}
+
+/* pitch is in bytes */
+void Buffer::copyFromArray(const byte *buffer, int pitch) {
+ DEBUG_ENTER_FUNC();
+
+ // We use sourceSize because outside, they won't know what the true size is
+ copyFromRect(buffer, pitch, 0, 0, _sourceSize.width, _sourceSize.height);
+
+ DEBUG_EXIT_FUNC();
+}
+
+/* pitch is in bytes */
+void Buffer::copyFromRect(const byte *buf, uint32 pitch, int destX, int destY, uint32 recWidth, uint32 recHeight) {
+ // Removed silly clipping code
+ DEBUG_ENTER_FUNC();
+ assert (_pixels);
+
+ if (recWidth > _sourceSize.width - destX) {
+ recWidth = _sourceSize.width - destX;
+ }
+
+ if (recHeight > _sourceSize.height - destY) {
+ recHeight = _sourceSize.height - destY;
+ }
+
+ if (recWidth <= 0 || recHeight <= 0) {
+ DEBUG_EXIT_FUNC();
+ return;
+ }
+
+ byte *dst = _pixels + _pixelFormat.pixelsToBytes((destY * _width) + destX);
+
+ uint32 recWidthInBytes = _pixelFormat.pixelsToBytes(recWidth);
+ uint32 realWidthInBytes = _pixelFormat.pixelsToBytes(_width);
+
+ if (pitch == realWidthInBytes && pitch == recWidthInBytes) {
+ //memcpy(dst, buf, _pixelFormat.pixelsToBytes(recHeight * recWidth));
+ Copier::copy(dst, buf, _pixelFormat.pixelsToBytes(recHeight * recWidth), &_pixelFormat);
+ } else {
+ do {
+ //memcpy(dst, buf, recWidthInBytes);
+ Copier::copy(dst, buf, recWidthInBytes, &_pixelFormat);
+ buf += pitch;
+ dst += realWidthInBytes;
+ } while (--recHeight);
+ }
+
+ DEBUG_EXIT_FUNC();
+}
+
+/* pitch is in bytes */
+void Buffer::copyToArray(byte *dst, int pitch) {
+ DEBUG_ENTER_FUNC();
+ assert (_pixels);
+
+ uint32 h = _height;
+ byte *src = _pixels;
+ uint32 sourceWidthInBytes = _pixelFormat.pixelsToBytes(_sourceSize.width);
+ uint32 realWidthInBytes = _pixelFormat.pixelsToBytes(_width);
+
+ do {
+ //memcpy(dst, src, sourceWidthInBytes);
+ Copier::copy(dst, src, sourceWidthInBytes, &_pixelFormat);
+ src += realWidthInBytes;
+ dst += pitch;
+ } while (--h);
+
+ DEBUG_EXIT_FUNC();
+}
+
+/* We can size the buffer either by texture size (multiple of 2^n) or source size. The GU can
+ really handle both, but is supposed to get only 2^n size buffers */
+void Buffer::setSize(uint32 width, uint32 height, HowToSize textureOrSource/*=kSizeByTextureSize*/) {
+ DEBUG_ENTER_FUNC();
+ PSP_DEBUG_PRINT("w[%u], h[%u], %s\n", width, height, textureOrSource ? "size by source" : "size by texture");
+
+ _sourceSize.width = width;
+ _sourceSize.height = height;
+
+ _textureSize.width = scaleUpToPowerOfTwo(width);
+ _textureSize.height = scaleUpToPowerOfTwo(height);
+
+ if (textureOrSource == kSizeByTextureSize) {
+ _width = _textureSize.width;
+ _height = _textureSize.height;
+ }
+ else { /* kSizeBySourceSize */
+ _width = _sourceSize.width;
+ _height = _sourceSize.height;
+ }
+
+ DEBUG_EXIT_FUNC();
+}
+
+/* Scale a dimension (width/height) up to power of 2 for the texture */
+uint32 Buffer::scaleUpToPowerOfTwo(uint32 size) {
+
+ uint32 textureDimension = 0;
+ if (size <= 16)
+ textureDimension = 16;
+ else if (size <= 32)
+ textureDimension = 32;
+ else if (size <= 64)
+ textureDimension = 64;
+ else if (size <= 128)
+ textureDimension = 128;
+ else if (size <= 256)
+ textureDimension = 256;
+ else
+ textureDimension = 512;
+
+ PSP_DEBUG_PRINT("power of 2 = %u\n", textureDimension);
+
+ return textureDimension;
+}
+
+bool Buffer::allocate(bool inVram/*=false*/) {
+ DEBUG_ENTER_FUNC();
+
+ PSP_DEBUG_PRINT("_width[%u], _height[%u]\n", _width, _height);
+ PSP_DEBUG_PRINT("_pixelFormat: format[%u], bpp[%u]\n", _pixelFormat.format, _pixelFormat.bitsPerPixel);
+
+ if (_pixels) {
+ if (VramAllocator::isAddressInVram(_pixels)) // Check if in VRAM
+ VramAllocator::instance().deallocate(_pixels);
+ else // not in VRAM
+ free (CACHED(_pixels));
+
+ _pixels = 0;
+ }
+
+ uint32 size = getSizeInBytes();
+
+ if (inVram) {
+ _pixels = (byte *)VramAllocator::instance().allocate(size);
+ }
+
+ if (!_pixels) { // Either we are not in vram or we didn't manage to allocate in vram
+ // Align to 64 bytes. All normal buffer sizes are multiples of 64 anyway
+ _pixels = (byte *)memalign(64, size);
+ }
+
+ if (!_pixels) {
+ PSP_ERROR("couldn't allocate buffer.\n");
+ DEBUG_EXIT_FUNC();
+ return false;
+ }
+
+ // Use uncached memory
+ GuRenderer::cacheInvalidate(_pixels, size);
+ _pixels = UNCACHED(_pixels);
+
+ clear();
+ DEBUG_EXIT_FUNC();
+ return true;
+}
+
+void Buffer::deallocate() {
+ DEBUG_ENTER_FUNC();
+
+ if (!_pixels)
+ return;
+
+ if (VramAllocator::isAddressInVram(_pixels)) // Check if in VRAM
+ VramAllocator::instance().deallocate(_pixels);
+ else
+ free(CACHED(_pixels));
+
+ _pixels = 0;
+
+ DEBUG_EXIT_FUNC();
+}
+
+void Buffer::clear() {
+ DEBUG_ENTER_FUNC();
+
+ if (_pixels)
+ memset(_pixels, 0, getSizeInBytes());
+
+ DEBUG_EXIT_FUNC();
+}
+
+/* Convert 4 bit images to match weird PSP format */
+void Buffer::flipNibbles() {
+ DEBUG_ENTER_FUNC();
+
+ if (_pixelFormat.bitsPerPixel != 4)
+ return;
+
+ assert(_pixels);
+
+ uint32 *dest = (uint32 *)_pixels;
+
+ for (uint32 i = 0; i < getSourceHeight(); i++) {
+ for (uint32 j = 0; j < (getWidth() >> 3); j++) { // /8 because we do it in 32bit chunks
+ uint32 val = *dest;
+ *dest++ = ((val >> 4) & 0x0F0F0F0F) | ((val << 4) & 0xF0F0F0F0);
+ }
+ }
+
+ DEBUG_EXIT_FUNC();
+}
+
+// Print buffer contents to screen (only source size is printed out)
+void Buffer::print(uint32 mask, uint32 numToPrint /*=0*/) {
+ assert(_pixels);
+
+ if (numToPrint > _sourceSize.width * _sourceSize.height || numToPrint == 0)
+ numToPrint = _sourceSize.width * _sourceSize.height;
+
+ PSP_INFO_PRINT("buffer: \n");
+ PSP_INFO_PRINT("width[%u], height[%u]\n\n", _sourceSize.width, _sourceSize.height);
+
+ for (unsigned int i=0; i < _sourceSize.height; i++) {
+ for (unsigned int j=0; j < _sourceSize.width; j++) {
+ if (numToPrint <= 0) // check if done
+ break;
+
+ byte *pcolor = &_pixels[_pixelFormat.pixelsToBytes((i * _width) + j)];
+ uint32 color = _pixelFormat.getColorValueAt(pcolor);
+
+ //if (color != 0) PSP_INFO_PRINT("[%x] ", color);
+ PSP_INFO_PRINT("[%x] ", mask & color);
+
+ numToPrint--;
+ }
+ PSP_INFO_PRINT("\n");
+ }
+ PSP_INFO_PRINT("\n");
+}
+
+// class GuRenderer -------------------------------------------------
+//#define __PSP_DEBUG_FUNCS__ /* For debugging the stack */
+//#define __PSP_DEBUG_PRINT__
+
+#include "backends/platform/psp/trace.h"
+
+
+void GuRenderer::render() {
+ DEBUG_ENTER_FUNC();
+ PSP_DEBUG_PRINT("Buffer[%p] Palette[%p]\n", _buffer->getPixels(), _palette->getRawValues());
+
+ setMaxTextureOffsetByIndex(0, 0);
+
+ guProgramDrawBehavior();
+
+ if (_buffer->hasPalette())
+ guLoadPalette();
+
+ guProgramTextureFormat();
+ guLoadTexture();
+
+ Vertex *vertices = guGetVertices();
+ fillVertices(vertices);
+
+ guDrawVertices(vertices);
+
+ if (_buffer->getSourceWidth() > 512) {
+ setMaxTextureOffsetByIndex(1, 0);
+
+ guLoadTexture();
+
+ vertices = guGetVertices();
+ fillVertices(vertices);
+
+ guDrawVertices(vertices);
+ }
+
+ DEBUG_EXIT_FUNC();
+}
+
+inline void GuRenderer::setMaxTextureOffsetByIndex(uint32 x, uint32 y) {
+ DEBUG_ENTER_FUNC();
+ const uint32 maxTextureSizeShift = 9; /* corresponds to 512 = max texture size*/
+
+ _maxTextureOffset.x = x << maxTextureSizeShift; /* x times 512 */
+ _maxTextureOffset.y = y << maxTextureSizeShift; /* y times 512 */
+ DEBUG_EXIT_FUNC();
+}
+
+inline void GuRenderer::guProgramDrawBehavior() {
+ DEBUG_ENTER_FUNC();
+ PSP_DEBUG_PRINT("blending[%s] colorTest[%s] reverseAlpha[%s] keyColor[%u]\n", _blending ? "on" : "off", _colorTest ? "on" : "off", _alphaReverse ? "on" : "off", _keyColor);
+
+ if (_blending) {
+ sceGuEnable(GU_BLEND);
+
+ if (_alphaReverse) // Reverse the alpha value (0 is 1)
+ sceGuBlendFunc(GU_ADD, GU_ONE_MINUS_SRC_ALPHA, GU_SRC_ALPHA, 0, 0);
+ else // Normal alpha values
+ sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
+
+ } else
+ sceGuDisable(GU_BLEND);
+
+ if (_colorTest) {
+ sceGuEnable(GU_COLOR_TEST);
+ sceGuColorFunc(GU_NOTEQUAL, _keyColor, 0x00ffffff);
+ } else
+ sceGuDisable(GU_COLOR_TEST);
+
+ DEBUG_EXIT_FUNC();
+}
+
+inline void GuRenderer::guLoadPalette() {
+ DEBUG_ENTER_FUNC();
+
+ uint32 mask;
+
+ if (_buffer->getBitsPerPixel() == 4)
+ mask = 0x0F;
+ else if (_buffer->getBitsPerPixel() == 8)
+ mask = 0xFF;
+ else
+ assert(0); /* error */
+
+ PSP_DEBUG_PRINT("numOfEntries[%d]\n", _palette->getNumOfEntries());
+ PSP_DEBUG_PRINT("bpp[%d], pixelformat[%d], mask[%x]\n", _buffer->getBitsPerPixel(), _palette->getPixelFormat(), mask);
+
+ sceGuClutMode(convertToGuPixelFormat(_palette->getPixelFormat()), 0, mask, 0);
+ sceGuClutLoad(_palette->getNumOfEntries() >> 3, _palette->getRawValues());
+
+ DEBUG_EXIT_FUNC();
+}
+
+inline void GuRenderer::guProgramTextureFormat() {
+ DEBUG_ENTER_FUNC();
+ PSP_DEBUG_PRINT("pixelFormat[%d]\n", _buffer->getPixelFormat());
+
+ sceGuTexMode(convertToGuPixelFormat(_buffer->getPixelFormat()), 0, 0, 0);
+ DEBUG_EXIT_FUNC();
+}
+
+inline uint32 GuRenderer::convertToGuPixelFormat(PSPPixelFormat::Type format) {
+ DEBUG_ENTER_FUNC();
+
+ uint32 guFormat = 0;
+
+ switch (format) {
+ case PSPPixelFormat::Type_4444:
+ guFormat = GU_PSM_4444;
+ break;
+ case PSPPixelFormat::Type_5551:
+ guFormat = GU_PSM_5551;
+ break;
+ case PSPPixelFormat::Type_5650:
+ guFormat = GU_PSM_5650;
+ break;
+ case PSPPixelFormat::Type_8888:
+ guFormat = GU_PSM_8888;
+ break;
+ case PSPPixelFormat::Type_Palette_8bit:
+ guFormat = GU_PSM_T8;
+ break;
+ case PSPPixelFormat::Type_Palette_4bit:
+ guFormat = GU_PSM_T4;
+ break;
+ default:
+ break;
+ }
+
+ PSP_DEBUG_PRINT("Pixelformat[%d], guFormat[%d]\n", format, guFormat);
+
+ DEBUG_EXIT_FUNC();
+ return guFormat;
+
+}
+
+inline void GuRenderer::guLoadTexture() {
+ DEBUG_ENTER_FUNC();
+
+ sceGuTexImage(0, _buffer->getTextureWidth(), _buffer->getTextureHeight(), _buffer->getWidth(), _buffer->getPixels() + _buffer->_pixelFormat.pixelsToBytes(_maxTextureOffset.x));
+
+ DEBUG_EXIT_FUNC();
+}
+
+inline Vertex *GuRenderer::guGetVertices() {
+ DEBUG_ENTER_FUNC();
+
+ Vertex *ret = (Vertex *)sceGuGetMemory(2 * sizeof(Vertex));
+
+ DEBUG_EXIT_FUNC();
+ return ret;
+}
+
+// Fills the vertices. Most of the logic is here.
+void GuRenderer::fillVertices(Vertex *vertices) {
+ DEBUG_ENTER_FUNC();
+
+ uint32 outputWidth = _displayManager->getOutputWidth();
+ uint32 outputHeight = _displayManager->getOutputHeight();
+
+ float textureStartX, textureStartY, textureEndX, textureEndY;
+
+ // Texture adjustments for eliminating half-pixel artifacts from scaling
+ // Not necessary if we don't scale
+ float textureAdjustment = 0.0f;
+ if (_useGlobalScaler &&
+ (_displayManager->getScaleX() != 1.0f || _displayManager->getScaleX() != 1.0f))
+ textureAdjustment = 0.5f;
+
+ textureStartX = textureAdjustment + _offsetInBuffer.x; //debug
+ textureStartY = textureAdjustment + _offsetInBuffer.y;
+ // We subtract maxTextureOffset because our shifted texture starts at 512 and will go to 640
+ textureEndX = _offsetInBuffer.x + _drawSize.width - textureAdjustment - _maxTextureOffset.x;
+ textureEndY = _offsetInBuffer.y + _drawSize.height - textureAdjustment;
+
+ // For scaling to the final image size, calculate the gaps on both sides
+ uint32 gapX = _useGlobalScaler ? (PSP_SCREEN_WIDTH - outputWidth) >> 1 : 0;
+ uint32 gapY = _useGlobalScaler ? (PSP_SCREEN_HEIGHT - outputHeight) >> 1 : 0;
+
+ float imageStartX, imageStartY, imageEndX, imageEndY;
+
+ imageStartX = gapX + ( scaleSourceToOutputX(_maxTextureOffset.x) );
+ imageStartY = gapY;
+
+ imageStartX += scaleSourceToOutputX(_offsetOnScreen.x);
+ imageStartY += scaleSourceToOutputY(_offsetOnScreen.y);
+
+ if (_fullScreen) { // shortcut
+ imageEndX = PSP_SCREEN_WIDTH - gapX;
+ imageEndY = PSP_SCREEN_HEIGHT - gapY;
+ } else { /* !fullScreen */
+ imageEndX = imageStartX + scaleSourceToOutputX(_drawSize.width);
+ imageEndY = imageStartY + scaleSourceToOutputY(_drawSize.height);
+ }
+
+ vertices[0].u = textureStartX;
+ vertices[0].v = textureStartY;
+ vertices[1].u = textureEndX;
+ vertices[1].v = textureEndY;
+
+ vertices[0].x = imageStartX;
+ vertices[0].y = imageStartY;
+ vertices[0].z = 0;
+ vertices[1].x = imageEndX;
+ vertices[1].y = imageEndY;
+ vertices[1].z = 0;
+
+ PSP_DEBUG_PRINT("TextureStart: X[%f] Y[%f] TextureEnd: X[%.1f] Y[%.1f]\n", textureStartX, textureStartY, textureEndX, textureEndY);
+ PSP_DEBUG_PRINT("ImageStart: X[%f] Y[%f] ImageEnd: X[%.1f] Y[%.1f]\n", imageStartX, imageStartY, imageEndX, imageEndY);
+
+ DEBUG_EXIT_FUNC();
+}
+
+/* Scale the input X offset to appear in proper position on the screen */
+inline float GuRenderer::scaleSourceToOutputX(float offset) {
+ float result;
+
+ if (!_useGlobalScaler)
+ result = offset;
+ else if (!offset)
+ result = 0.0f;
+ else
+ result = offset * _displayManager->getScaleX();
+
+ return result;
+}
+
+/* Scale the input Y offset to appear in proper position on the screen */
+inline float GuRenderer::scaleSourceToOutputY(float offset) {
+ float result;
+
+ if (!_useGlobalScaler)
+ result = offset;
+ else if (!offset)
+ result = 0.0f;
+ else
+ result = offset * _displayManager->getScaleY();
+
+ return result;
+}
+
+inline void GuRenderer::guDrawVertices(Vertex *vertices) {
+ DEBUG_ENTER_FUNC();
+
+ sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices);
+ DEBUG_EXIT_FUNC();
+}
+
+void GuRenderer::cacheInvalidate(void *pointer, uint32 size) {
+ sceKernelDcacheWritebackInvalidateRange(pointer, size);
+}
Property changes on: scummvm/trunk/backends/platform/psp/display_client.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: scummvm/trunk/backends/platform/psp/display_client.h
===================================================================
--- scummvm/trunk/backends/platform/psp/display_client.h (rev 0)
+++ scummvm/trunk/backends/platform/psp/display_client.h 2010-04-12 06:49:05 UTC (rev 48632)
@@ -0,0 +1,238 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/platform/psp/osys_psp.cpp $
+ * $Id: osys_psp.cpp 46126 2009-11-24 14:18:46Z fingolfin $
+ *
+ */
+
+#ifndef PSP_GRAPHICS_H
+#define PSP_GRAPHICS_H
+
+#include "common/singleton.h"
+#include "graphics/surface.h"
+#include "common/system.h"
+#include "backends/platform/psp/psppixelformat.h"
+#include "backends/platform/psp/memory.h"
+
+#define MAX_TEXTURE_SIZE 512
+
+class DisplayManager;
+class GuRenderer;
+
+/**
+ * Interface to inherit for all display clients
+ * We deliberately avoid virtual functions for speed.
+ */
+class DisplayClient { // Abstract class
+public:
+ DisplayClient() {}
+ bool isVisible() { return true; }
+ bool isDirty() { return true; }
+ void setClean() {}
+ void render() {}
+ virtual ~DisplayClient() {}
+};
+
+/**
+ * Vertex used for GU rendering
+ */
+struct Vertex {
+ float u,v;
+ float x,y,z;
+};
+
+struct Point {
+ int x;
+ int y;
+ Point() : x(0), y(0) {}
+};
+
+/**
+ * Dimensions struct for simplification
+ */
+struct Dimensions {
+ uint32 width;
+ uint32 height;
+ Dimensions() : width(0), height(0) {}
+};
+
+/**
+ * Universal PSP Palette class
+ * Use this in any class that wishes to draw to the PSP screen.
+ * Use together with GuRenderer
+ */
+class Palette {
+public:
+ Palette() : _values(0), _numOfEntries(0) {}
+ virtual ~Palette() { deallocate(); }
+ bool allocate();
+ void deallocate();
+ void clear();
+ void setPixelFormats(PSPPixelFormat::Type paletteType, PSPPixelFormat::Type bufferType, bool swapRedBlue = false);
+ void setNumOfEntries(uint32 num) { _numOfEntries = num; }
+ uint32 getNumOfEntries() { return _numOfEntries; }
+ uint32 getSizeInBytes() { return _pixelFormat.pixelsToBytes(_numOfEntries); }
+ void set(byte *values) { setPartial(values, 0, _numOfEntries); }
+ void setPartial(const byte *colors, uint start, uint num, bool supportsAlpha = false);
+ void getPartial(byte *colors, uint start, uint num);
+ uint32 getRawColorAt(uint32 position);
+ uint32 getRGBAColorAt(uint32 position);
+ void setSingleColorRGBA(uint32 num, byte r, byte g, byte b, byte a);
+ void setColorPositionAlpha(uint32 position, bool alpha);
+ byte *getRawValues() { return _values; }
+ bool isAllocated() { return (_values != 0); }
+ PSPPixelFormat::Type getPixelFormat() { return _pixelFormat.format; }
+ void print(uint32 numToPrint = 0); // print to screen
+
+protected:
+ byte *_values; ///< array of palette data
+ uint32 _numOfEntries; ///< number of palette entries
+ PSPPixelFormat _pixelFormat; ///< pixel format of the palette data
+};
+
+/**
+ * Universal PSP buffer/texture object
+ * Use this in any class that wishes to draw to the PSP screen.
+ * Use together with GuRenderer
+ */
+class Buffer {
+public:
+ enum HowToSize {
+ kSizeByTextureSize, // buffer size is determined by power of 2 roundup for texture
+ kSizeBySourceSize // buffer size is determined by source size
+ };
+
+ Buffer() : _pixels(0), _width(0), _height(0) {}
+ virtual ~Buffer() { deallocate(); }
+
+ // setters
+ void setSize(uint32 width, uint32 height, HowToSize textureOrSource=kSizeByTextureSize);
+ void setBitsPerPixel(uint32 bits) { _pixelFormat.bitsPerPixel = bits; }
+ void setBytesPerPixel(uint32 bytes) { setBitsPerPixel(bytes << 3); }
+ void setPixelFormat(PSPPixelFormat::Type type, bool swapRedBlue = false);
+
+ // getters
+ uint32 getWidth() { return _width; }
+ uint32 getWidthInBytes() { return _pixelFormat.pixelsToBytes(getWidth()); }
+ uint32 getHeight() { return _height; }
+ uint32 getSourceWidth() { return _sourceSize.width; }
+ uint32 getSourceWidthInBytes() { return _pixelFormat.pixelsToBytes(_sourceSize.width); }
+ uint32 getSourceHeight() { return _sourceSize.height; }
+ uint32 getTextureWidth() { return _textureSize.width; }
+ uint32 getTextureHeight() { return _textureSize.height; }
+ PSPPixelFormat::Type getPixelFormat() { return _pixelFormat.format; }
+ uint32 getBitsPerPixel() { return _pixelFormat.bitsPerPixel; }
+ uint32 getBytesPerPixel() { return getBitsPerPixel() >> 3; } /* won't work for 4-bit */
+ byte *getPixels() { return _pixels; }
+ uint32 getSizeInBytes() { return _pixelFormat.pixelsToBytes(_width * _height); }
+
+ bool hasPalette();
+ void copyFromArray(const byte *buffer, int pitch);
+ void copyFromRect(const byte *buf, uint32 pitch, int destX, int destY, uint32 recWidth, uint32 recHeight);
+ void copyToArray(byte *dst, int pitch);
+ bool allocate(bool inVram = false);
+ void deallocate();
+ bool isAllocated() { return (_pixels != 0) ; }
+ void clear();
+ void flipNibbles(); // To handle peculiarities of PSP's 4 bit textures
+ static uint32 scaleUpToPowerOfTwo(uint32 size);
+ void print(uint32 mask, uint32 numToPrint = 0);
+
+protected:
+ friend class GuRenderer;
+ byte *_pixels;
+ uint32 _width; ///< True allocated width
+ uint32 _height; ///< True allocated height
+ Dimensions _textureSize; ///< Size rounded up to power of 2. Used for drawing
+ Dimensions _sourceSize; ///< Original size of the buffer
+ PSPPixelFormat _pixelFormat; ///< Format of the buffer
+};
+
+/**
+ * Universal rendering class for PSP
+ * Use this if you want to draw to the screen.
+ * Needs to be supplied with a Buffer and a Palette
+ */
+class GuRenderer {
+public:
+ // Constructors
+ GuRenderer() : _useGlobalScaler(false), _buffer(0), _palette(0), _blending(false), _alphaReverse(false), _colorTest(false), _keyColor(0), _fullScreen(false) {}
+ GuRenderer(Buffer *buffer, Palette *palette) : _useGlobalScaler(false), _buffer(buffer), _palette(palette), _blending(false), _alphaReverse(false), _colorTest(false), _keyColor(0), _fullScreen(false) {}
+ static void setDisplayManager(DisplayManager *dm) { _displayManager = dm; } // Called by the Display Manager
+
+ // Setters
+ void setDrawSize(uint32 width, uint32 height) { // How big of an area to draw
+ _drawSize.width = width;
+ _drawSize.height = height;
+ }
+ void setDrawWholeBuffer() { // Draw the full size of the current buffer
+ assert(_buffer);
+ _drawSize.width = _buffer->getSourceWidth();
+ _drawSize.height = _buffer->getSourceHeight();
+ }
+ void setBuffer(Buffer *buffer) { _buffer = buffer; }
+ void setPalette(Palette *palette) { _palette = palette; }
+ void setMaxTextureOffsetByIndex(uint32 x, uint32 y); // For drawing multiple textures
+ void setOffsetOnScreen(uint32 x, uint32 y) { _offsetOnScreen.x = x; _offsetOnScreen.y = y; }
+ void setOffsetInBuffer(uint32 x, uint32 y) { _offsetInBuffer.x = x; _offsetInBuffer.y = y; }
+ void setColorTest(bool value) { _colorTest = value; }
+ void setKeyColor(uint32 value) { _keyColor = _buffer->_pixelFormat.convertTo32BitColor(value); }
+ void setAlphaBlending(bool value) { _blending = value; }
+ void setAlphaReverse(bool value) { _alphaReverse = value; }
+ void setFullScreen(bool value) { _fullScreen = value; } // Shortcut for rendering
+ void setUseGlobalScaler(bool value) { _useGlobalScaler = value; } // Scale to screen
+
+ static void cacheInvalidate(void *pointer, uint32 size);
+
+ void render(); // Default rendering function. This should be good enough for most purposes
+
+protected:
+ // Gu functions
+ void fillVertices(Vertex *vertices); // Fill in vertices with coordinates
+ void guProgramDrawBehavior();
+ Vertex *guGetVertices();
+ void guLoadTexture();
+ void guLoadPalette();
+ void guProgramTextureFormat();
+ void guProgramTextureBitDepth();
+ void guDrawVertices(Vertex *vertices);
+
+ uint32 convertToGuPixelFormat(PSPPixelFormat::Type format);
+ float scaleSourceToOutputX(float offset);
+ float scaleSourceToOutputY(float offset);
+
+ friend class MasterGuRenderer;
+ Point _maxTextureOffset; ///> For rendering textures > 512 pixels
+ Point _offsetOnScreen; ///> Where on screen to draw
+ Point _offsetInBuffer; ///> Where in the texture to draw
+ bool _useGlobalScaler; ///> Scale to the output size on screen
+ Buffer *_buffer;
+ Palette *_palette;
+ static DisplayManager *_displayManager;
+ Dimensions _drawSize; ///> Actual size to draw out of the Buffer
+ bool _blending;
+ bool _alphaReverse; ///> 0 counts as full alpha
+ bool _colorTest;
+ uint32 _keyColor; ///> Color to test against for color test. in 32 bits.
+ bool _fullScreen; ///> Speeds up for fullscreen rendering
+};
+
+#endif /* PSP_SCREEN_H */
Property changes on: scummvm/trunk/backends/platform/psp/display_client.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: scummvm/trunk/backends/platform/psp/display_manager.cpp
===================================================================
--- scummvm/trunk/backends/platform/psp/display_manager.cpp (rev 0)
+++ scummvm/trunk/backends/platform/psp/display_manager.cpp 2010-04-12 06:49:05 UTC (rev 48632)
@@ -0,0 +1,336 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/platform/psp/osys_psp.cpp $
+ * $Id: osys_psp.cpp 47541 2010-01-25 01:39:44Z lordhoto $
+ *
+ */
+
+//#define __PSP_DEBUG_FUNCS__ /* For debugging function calls */
+//#define __PSP_DEBUG_PRINT__ /* For debug printouts */
+
+//#define ENABLE_RENDER_MEASURE
+
+#include "backends/platform/psp/trace.h"
+
+#include <pspgu.h>
+#include <pspdisplay.h>
+
+#include "common/scummsys.h"
+#include "backends/base-backend.h"
+#include "backends/platform/psp/display_client.h"
+#include "backends/platform/psp/default_display_client.h"
+#include "backends/platform/psp/cursor.h"
+#include "backends/platform/psp/pspkeyboard.h"
+#include "backends/platform/psp/display_manager.h"
+
+#define PSP_BUFFER_WIDTH (512)
+#define PSP_SCREEN_WIDTH 480
+#define PSP_SCREEN_HEIGHT 272
+#define PSP_FRAME_SIZE (PSP_BUFFER_WIDTH * PSP_SCREEN_HEIGHT)
+
+uint32 __attribute__((aligned(16))) MasterGuRenderer::_displayList[2048];
+
+ const OSystem::GraphicsMode DisplayManager::_supportedModes[] = {
+ { "320x200 (centered)", "320x200 16-bit centered", CENTERED_320X200 },
+ { "435x272 (best-fit, centered)", "435x272 16-bit centered", CENTERED_435X272 },
+ { "480x272 (full screen)", "480x272 16-bit stretched", STRETCHED_480X272 },
+ { "362x272 (4:3, centered)", "362x272 16-bit centered", CENTERED_362X272 },
+ {0, 0, 0}
+};
+
+
+// Class MasterGuRenderer ----------------------------------------------
+
+void MasterGuRenderer::guInit() {
+ DEBUG_ENTER_FUNC();
+
+ sceGuInit();
+ sceGuStart(0, _displayList);
+
+ guProgramDisplayBufferSizes();
+
+ sceGuOffset(2048 - (PSP_SCREEN_WIDTH/2), 2048 - (PSP_SCREEN_HEIGHT/2));
+ sceGuViewport(2048, 2048, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);
+ sceGuDepthRange(0xC350, 0x2710);
+ sceGuDisable(GU_DEPTH_TEST); // We'll use depth buffer area
+ sceGuDepthMask(GU_TRUE); // Prevent writes to depth buffer
+ 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);
+
+ DEBUG_EXIT_FUNC();
+}
+
+void MasterGuRenderer::guProgramDisplayBufferSizes() {
+ DEBUG_ENTER_FUNC();
+
+ PSP_DEBUG_PRINT("Outputbits[%u]\n", GuRenderer::_displayManager->getOutputBitsPerPixel());
+
+ switch (GuRenderer::_displayManager->getOutputBitsPerPixel()) {
+ case 16:
+ sceGuDrawBuffer(GU_PSM_4444, (void *)0, PSP_BUFFER_WIDTH);
+ sceGuDispBuffer(PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT, (void*)(PSP_FRAME_SIZE * sizeof(uint16)), PSP_BUFFER_WIDTH);
+ sceGuDepthBuffer((void*)(PSP_FRAME_SIZE * sizeof(uint16) * 2), PSP_BUFFER_WIDTH);
+ VramAllocator::instance().allocate(PSP_FRAME_SIZE * sizeof(uint16) * 2);
+ break;
+ case 32:
+ sceGuDrawBuffer(GU_PSM_8888, (void *)0, PSP_BUFFER_WIDTH);
+ sceGuDispBuffer(PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT, (void*)(PSP_FRAME_SIZE * sizeof(uint32)), PSP_BUFFER_WIDTH);
+ sceGuDepthBuffer((void*)(PSP_FRAME_SIZE * sizeof(uint32) * 2), PSP_BUFFER_WIDTH);
+ VramAllocator::instance().allocate(PSP_FRAME_SIZE * sizeof(uint32) * 2);
+ break;
+ }
+
+ DEBUG_EXIT_FUNC();
+}
+
+// These are GU commands that should always stay the same
+inline void MasterGuRenderer::guPreRender() {
+ DEBUG_ENTER_FUNC();
+
+#ifdef ENABLE_RENDER_MEASURE
+ _lastRenderTime = g_system->getMillis();
+#endif /* ENABLE_RENDER_MEASURE */
+
+ sceGuStart(0, _displayList);
+
+ sceGuClearColor(0xFF000000);
+ sceGuClear(GU_COLOR_BUFFER_BIT);
+
+ sceGuAmbientColor(0xFFFFFFFF);
+ sceGuColor(0xFFFFFFFF);
+ sceGuTexOffset(0,0);
+ sceGuTexFilter(GU_LINEAR, GU_LINEAR);
+
+ sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); // Also good enough for all purposes
+ sceGuAlphaFunc(GU_GREATER, 0, 0xFF); // Also good enough for all purposes
+
+ DEBUG_EXIT_FUNC();
+}
+
+inline void MasterGuRenderer::guPostRender() {
+ DEBUG_ENTER_FUNC();
+
+ sceGuFinish();
+ sceGuSync(0,0);
+
+#ifdef ENABLE_RENDER_MEASURE
+ uint32 now = g_system->getMillis();
+ PSP_INFO_PRINT("Render took %d milliseconds\n", now - _lastRenderTime);
+#endif /* ENABLE_RENDER_MEASURE */
+
+ sceDisplayWaitVblankStart();
+ sceGuSwapBuffers();
+
+ DEBUG_EXIT_FUNC();
+}
+
+void MasterGuRenderer::guShutDown() {
+ sceGuTerm();
+}
+
+
+// Class DisplayManager -----------------------------------------------------
+
+DisplayManager::~DisplayManager() {
+ _masterGuRenderer.guShutDown();
+}
+
+void DisplayManager::init() {
+ DEBUG_ENTER_FUNC();
+
+ _displayParams.outputBitsPerPixel = 32; // can be changed to produce 16-bit output
+
+ GuRenderer::setDisplayManager(this);
+ _screen->init();
+ _overlay->init();
+ _cursor->init();
+
+ _masterGuRenderer.guInit(); // start up the renderer
+
+ DEBUG_EXIT_FUNC();
+}
+
+void DisplayManager::setSizeAndPixelFormat(uint width, uint height, const Graphics::PixelFormat *format) {
+
+ DEBUG_ENTER_FUNC();
+ PSP_DEBUG_PRINT("w[%u], h[%u], pformat[%p]\n", width, height, format);
+
+ _overlay->deallocate();
+ _screen->deallocate();
+
+ _screen->setScummvmPixelFormat(format);
+ _screen->setSize(width, height);
+ _screen->allocate();
+
+ _cursor->setScreenPaletteScummvmPixelFormat(format);
+
+ _overlay->setBytesPerPixel(sizeof(OverlayColor));
+ _overlay->setSize(PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);
+ _overlay->allocate();
+
+ _displayParams.screenSource.width = width;
+ _displayParams.screenSource.height = height;
+ calculateScaleParams();
+
+ DEBUG_EXIT_FUNC();
+}
+
+bool DisplayManager::setGraphicsMode(const char *name) {
+ DEBUG_ENTER_FUNC();
+
+ int i = 0;
+
+ while (_supportedModes[i].name) {
+ if (!strcmpi(_supportedModes[i].name, name)) {
+ setGraphicsMode(_supportedModes[i].id);
+ DEBUG_EXIT_FUNC();
+ return true;
+ }
+ i++;
+ }
+
+ DEBUG_EXIT_FUNC();
+ return false;
+}
+
+bool DisplayManager::setGraphicsMode(int mode) {
+ DEBUG_ENTER_FUNC();
+
+ _graphicsMode = mode;
+
+ switch (_graphicsMode) {
+ case CENTERED_320X200:
+ _displayParams.screenOutput.width = 320;
+ _displayParams.screenOutput.height = 200;
+ break;
+ case CENTERED_435X272:
+ _displayParams.screenOutput.width = 435;
+ _displayParams.screenOutput.height = 272;
+ break;
+ case STRETCHED_480X272:
+ _displayParams.screenOutput.width = 480;
+ _displayParams.screenOutput.height = 272;
+ break;
+ case CENTERED_362X272:
+ _displayParams.screenOutput.width = 362;
+ _displayParams.screenOutput.height = 272;
+ break;
+ default:
+ PSP_ERROR("Unsupported graphics mode[%d].\n", _graphicsMode);
+ }
+
+ calculateScaleParams();
+
+ DEBUG_EXIT_FUNC();
+ return true;
+}
+
+void DisplayManager::calculateScaleParams() {
+ if (_displayParams.screenOutput.width && _displayParams.screenSource.width &&
+ _displayParams.screenOutput.height && _displayParams.screenSource.height) {
+ _displayParams.scaleX = ((float)_displayParams.screenOutput.width) / _displayParams.screenSource.width;
+ _displayParams.scaleY = ((float)_displayParams.screenOutput.height) / _displayParams.screenSource.height;
+ }
+}
+
+void DisplayManager::renderAll() {
+ DEBUG_ENTER_FUNC();
+
+ if (!isTimeToUpdate()) {
+ DEBUG_EXIT_FUNC();
+ return;
+ }
+
+ if (!_screen->isDirty() &&
+ (!_overlay->isDirty()) &&
+ (!_cursor->isDirty()) &&
+ (!_keyboard->isDirty())) {
+ PSP_DEBUG_PRINT("Nothing dirty\n");
+ DEBUG_EXIT_FUNC();
+ return;
+ }
+
+ PSP_DEBUG_PRINT("screen[%s], overlay[%s], cursor[%s], keyboard[%s]\n",
+ _screen->isDirty() ? "true" : "false",
+ _overlay->isDirty() ? "true" : "false",
+ _cursor->isDirty() ? "true" : "false",
+ _keyboard->isDirty() ? "true" : "false"
+ );
+
+ _masterGuRenderer.guPreRender(); // Set up rendering
+
+ _screen->render();
+
+ _screen->setClean(); // clean out dirty bit
+
+ if (_overlay->isVisible())
+ _overlay->render();
+
+ _overlay->setClean();
+
+ if (_cursor->isVisible())
+ _cursor->render();
+
+ _cursor->setClean();
+
+ if (_keyboard->isVisible())
+ _keyboard->render();
+
+ _keyboard->setClean();
+
+ _masterGuRenderer.guPostRender();
+
+ DEBUG_EXIT_FUNC();
+}
+
+inline bool DisplayManager::isTimeToUpdate() {
+
+#define MAX_FPS 30
+
+ uint32 now = g_system->getMillis();
+ if (now - _lastUpdateTime < (1000 / MAX_FPS))
+ return false;
+
+ _lastUpdateTime = now;
+ return true;
+}
+
+Common::List<Graphics::PixelFormat> DisplayManager::getSupportedPixelFormats() {
+ Common::List<Graphics::PixelFormat> list;
+
+ // In order of preference
+ list.push_back(PSPPixelFormat::convertToScummvmPixelFormat(PSPPixelFormat::Type_5650));
+ list.push_back(PSPPixelFormat::convertToScummvmPixelFormat(PSPPixelFormat::Type_5551));
+ list.push_back(PSPPixelFormat::convertToScummvmPixelFormat(PSPPixelFormat::Type_4444));
+ list.push_back(Graphics::PixelFormat::createFormatCLUT8());
+
+ return list;
+}
+
Property changes on: scummvm/trunk/backends/platform/psp/display_manager.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: scummvm/trunk/backends/platform/psp/display_manager.h
===================================================================
--- scummvm/trunk/backends/platform/psp/display_manager.h (rev 0)
+++ scummvm/trunk/backends/platform/psp/display_manager.h 2010-04-12 06:49:05 UTC (rev 48632)
@@ -0,0 +1,114 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/platform/psp/osys_psp.cpp $
+ * $Id: osys_psp.cpp 47541 2010-01-25 01:39:44Z lordhoto $
+ *
+ */
+
+#ifndef PSP_DISPLAY_MAN_H
+#define PSP_DISPLAY_MAN_H
+
+/**
+ * Class used only by DisplayManager to start/stop GU rendering
+ */
+class MasterGuRenderer {
+public:
+ MasterGuRenderer() : _lastRenderTime(0) {}
+ void guInit();
+ void guPreRender();
+ void guPostRender();
+ void guShutDown();
+private:
+ static uint32 _displayList[];
+ uint32 _lastRenderTime; // For measuring rendering
+ void guProgramDisplayBufferSizes();
+};
+
+class Screen;
+class Overlay;
+class Cursor;
+class PSPKeyboard;
+
+/**
+ * Class that manages all display clients
+ */
+class DisplayManager {
+public:
+ enum GraphicsModeID { ///> Possible output formats onscreen
+ CENTERED_320X200,
+ CENTERED_435X272,
+ STRETCHED_480X272,
+ CENTERED_362X272
+ };
+ DisplayManager() : _screen(0), _cursor(0), _overlay(0), _keyboard(0), _lastUpdateTime(0), _graphicsMode(0) {}
+ ~DisplayManager();
+
+ void init();
+ void renderAll();
+ bool setGraphicsMode(int mode);
+ bool setGraphicsMode(const char *name);
+ int getGraphicsMode() const { return _graphicsMode; }
+ uint32 getDefaultGraphicsMode() const { return STRETCHED_480X272; }
+ const OSystem::GraphicsMode* getSupportedGraphicsModes() const { return _supportedModes; }
+
+ // Setters
+ void setScreen(Screen *screen) { _screen = screen; }
+ void setCursor(Cursor *cursor) { _cursor = cursor; }
+ void setOverlay(Overlay *overlay) { _overlay = overlay; }
+ void setKeyboard(PSPKeyboard *keyboard) { _keyboard = keyboard; }
+ void setSizeAndPixelFormat(uint width, uint height, const Graphics::PixelFormat *format);
+
+ // Getters
+ float getScaleX() { return _displayParams.scaleX; }
+ float getScaleY() { return _displayParams.scaleY; }
+ uint32 getOutputWidth() { return _displayParams.screenOutput.width; }
+ uint32 getOutputHeight() { return _displayParams.screenOutput.height; }
+ uint32 getOutputBitsPerPixel() { return _displayParams.outputBitsPerPixel; }
+ Common::List<Graphics::PixelFormat> getSupportedPixelFormats();
+
+private:
+ struct GlobalDisplayParams {
+ Dimensions screenOutput;
+ Dimensions screenSource;
+ float scaleX;
+ float scaleY;
+ uint32 outputBitsPerPixel; // How many bits end up on-screen
+ GlobalDisplayParams() : scaleX(0.0f), scaleY(0.0f), outputBitsPerPixel(0) {}
+ };
+
+ // Pointers to DisplayClients
+ Screen *_screen;
+ Cursor *_cursor;
+ Overlay *_overlay;
+ PSPKeyboard *_keyboard;
+
+ MasterGuRenderer _masterGuRenderer;
+ uint32 _lastUpdateTime; // For limiting FPS
+ int _graphicsMode;
+ GlobalDisplayParams _displayParams;
+ static const OSystem::GraphicsMode _supportedModes[];
+
+ void calculateScaleParams(); // calculates scaling factor
+ bool isTimeToUpdate(); // should we update the screen now
+};
+
+
+#endif /* PSP_DISPLAY_MAN_H */
Property changes on: scummvm/trunk/backends/platform/psp/display_manager.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: scummvm/trunk/backends/platform/psp/input.cpp
===================================================================
--- scummvm/trunk/backends/platform/psp/input.cpp (rev 0)
+++ scummvm/trunk/backends/platform/psp/input.cpp 2010-04-12 06:49:05 UTC (rev 48632)
@@ -0,0 +1,317 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/platform/psp/osys_psp.cpp $
+ * $Id: osys_psp.cpp 43618 2009-08-21 22:44:49Z joostp $
+ *
+ */
+
+// Todo: handle events that should fire because of shift going off
+// Solution: handle shift on a button-by-button basis, only allowing it when the button is up. Also a inputmap-wide button. At buttonup, shiftstate is inspected per button.
+
+//#define __PSP_DEBUG_FUNCS__ /* Uncomment for debugging the stack */
+//#define __PSP_DEBUG_PRINT__ /* Uncomment for debug prints */
+
+#include "backends/platform/psp/trace.h"
+
+#include "backends/platform/psp/input.h"
+
+// Defines for working with PSP buttons
+#define CHANGED(x) (_buttonsChanged & (x))
+#define PRESSED(x) ((_buttonsChanged & (x)) && (pad.Buttons & (x)))
+#define UNPRESSED(x) ((_buttonsChanged & (x)) && !(pad.Buttons & (x)))
+#define DOWN(x) (pad.Buttons & (x))
+#define UP(x) (!(pad.Buttons & (x)))
+#define PSP_DPAD (PSP_CTRL_DOWN|PSP_CTRL_UP|PSP_CTRL_LEFT|PSP_CTRL_RIGHT)
+#define PSP_4BUTTONS (PSP_CTRL_CROSS | PSP_CTRL_CIRCLE | PSP_CTRL_TRIANGLE | PSP_CTRL_SQUARE)
+#define PSP_TRIGGERS (PSP_CTRL_LTRIGGER | PSP_CTRL_RTRIGGER)
+
+#define PAD_CHECK_TIME 53
+
+void InputHandler::init() {
+ sceCtrlSetSamplingCycle(0); // set sampling to vsync. n = n usecs
+ sceCtrlSetSamplingMode(1); // analog
+}
+
+bool InputHandler::getAllInputs(Common::Event &event) {
+ DEBUG_ENTER_FUNC();
+
+ uint32 time = g_system->getMillis(); // may not be necessary with read
+ if (time - _lastPadCheckTime < PAD_CHECK_TIME) {
+ DEBUG_EXIT_FUNC();
+ return false;
+ }
+
+ _lastPadCheckTime = time;
+ SceCtrlData pad;
+
+ sceCtrlPeekBufferPositive(&pad, 1); // Peek ignores sleep. Read sleeps thread
+
+ bool haveEvent;
+
+ memset(&event, 0, sizeof(event));
+
+ if (_keyboard->isVisible())
+ haveEvent = _keyboard->processInput(event, pad);
+ else
+ haveEvent = getEvent(event, pad);
+
+ if (haveEvent)
+ {
+ PSP_DEBUG_PRINT("Have event[%s]\n", haveEvent ? "true" : "false");
+ PSP_DEBUG_PRINT("event.type[%d]\n", event.type);
+ }
+
+ DEBUG_EXIT_FUNC();
+
+ return haveEvent;
+}
+
+bool InputHandler::getEvent(Common::Event &event, SceCtrlData &pad) {
+ DEBUG_ENTER_FUNC();
+
+ _buttonsChanged = pad.Buttons ^ _prevButtons;
+ bool haveEvent = false;
+
+ // Collect events from different sources
+ haveEvent = getDpadEvent(event, pad);
+
+ if (!haveEvent)
+ haveEvent = getButtonEvent(event, pad);
+
+ if (!haveEvent)
+ haveEvent = getNubEvent(event, pad);
+
+ _prevButtons = pad.Buttons;
+
+ DEBUG_EXIT_FUNC();
+ return haveEvent;
+}
+
+bool InputHandler::getDpadEvent(Common::Event &event, SceCtrlData &pad) {
+ DEBUG_ENTER_FUNC();
+
+ int newDpadX = 0, newDpadY = 0;
+ bool haveEvent = false;
+
+ if (DOWN(PSP_CTRL_UP)) {
+ newDpadY++;
+ if (DOWN(PSP_CTRL_RTRIGGER)) // Shifting causes diagonals
+ newDpadX++;
+ }
+ if (DOWN(PSP_CTRL_RIGHT)) {
+ newDpadX++;
+ if (DOWN(PSP_CTRL_RTRIGGER))
+ newDpadY--;
+ }
+ if (DOWN(PSP_CTRL_DOWN)) {
+ newDpadY--;
+ if (DOWN(PSP_CTRL_RTRIGGER))
+ newDpadX--;
+ }
+ if (DOWN(PSP_CTRL_LEFT)) {
+ newDpadX--;
+ if (DOWN(PSP_CTRL_RTRIGGER))
+ newDpadY++;
+ }
+
+ if (newDpadX != _dpadX || newDpadY != _dpadY) {
+ if (_dpadX == 0 && _dpadY == 0) { // We were in the middle so we pressed dpad
+ event.type = Common::EVENT_KEYDOWN;
+ event.kbd.keycode = translateDpad(newDpadX, newDpadY);
+ event.kbd.ascii = event.kbd.keycode - Common::KEYCODE_KP0 + '0'; // Get ascii
+ _dpadX = newDpadX;
+ _dpadY = newDpadY;
+ }
+ else if (newDpadX == 0 && newDpadY == 0) {// We're now centered so we unpressed dpad
+ event.type = Common::EVENT_KEYUP;
+ event.kbd.keycode = translateDpad(_dpadX, _dpadY);
+ event.kbd.ascii = event.kbd.keycode - Common::KEYCODE_KP0 + '0';
+ _dpadX = newDpadX;
+ _dpadY = newDpadY;
+ } else { // we moved from one pressed dpad direction to another one
+ event.type = Common::EVENT_KEYUP; // first release the last dpad direction
+ event.kbd.keycode = translateDpad(_dpadX, _dpadY);
+ event.kbd.ascii = event.kbd.keycode - Common::KEYCODE_KP0 + '0';
+ _dpadX = 0; // so that we'll pick up a new dpad movement the next round
+ _dpadY = 0;
+ }
+
+ PSP_DEBUG_PRINT("Keypad event. DpadX[%d], DpadY[%d]\n", _dpadX, _dpadY);
+ haveEvent = true;
+ }
+
+ DEBUG_EXIT_FUNC();
+ return haveEvent;
+}
+
+inline Common::KeyCode InputHandler::translateDpad(int x, int y) {
+ DEBUG_ENTER_FUNC();
+ Common::KeyCode key;
+
+ if (x == -1) {
+ if (y == -1)
+ key = Common::KEYCODE_KP1;
+ else if (y == 0)
+ key = Common::KEYCODE_KP4;
+ else /* y == 1 */
+ key = Common::KEYCODE_KP7;
+ } else if (x == 0) {
+ if (y == -1)
+ key = Common::KEYCODE_KP2;
+ else /* y == 1 */
+ key = Common::KEYCODE_KP8;
+ } else {/* x == 1 */
+ if (y == -1)
+ key = Common::KEYCODE_KP3;
+ else if (y == 0)
+ key = Common::KEYCODE_KP6;
+ else /* y == 1 */
+ key = Common::KEYCODE_KP9;
+ }
+
+ DEBUG_EXIT_FUNC();
+ return key;
+}
+
+
+bool InputHandler::getButtonEvent(Common::Event &event, SceCtrlData &pad) {
+ DEBUG_ENTER_FUNC();
+ bool haveEvent = false;
+
+ if (PRESSED(PSP_CTRL_SELECT))
+ _keyboard->setVisible(true);
+
+ else if (CHANGED(PSP_4BUTTONS | PSP_TRIGGERS | PSP_CTRL_START)) {
+ if (CHANGED(PSP_CTRL_CROSS)) {
+ event.type = DOWN(PSP_CTRL_CROSS) ? Common::EVENT_LBUTTONDOWN : Common::EVENT_LBUTTONUP;
+ event.mouse.x = _cursor->getX(); // Could this have to do with SCI enter problem?
+ event.mouse.y = _cursor->getY();
+ PSP_DEBUG_PRINT("%s\n", event.type == Common::EVENT_LBUTTONDOWN ? "LButtonDown" : "LButtonUp");
+ } else if (CHANGED(PSP_CTRL_CIRCLE)) {
+ event.type = DOWN(PSP_CTRL_CIRCLE) ? Common::EVENT_RBUTTONDOWN : Common::EVENT_RBUTTONUP;
+ event.mouse.x = _cursor->getX();
+ event.mouse.y = _cursor->getY();
+ PSP_DEBUG_PRINT("%s\n", event.type == Common::EVENT_LBUTTONDOWN ? "RButtonDown" : "RButtonUp");
+ } 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 (CHANGED(PSP_CTRL_LTRIGGER)) {
+ event.kbd.keycode = Common::KEYCODE_ESCAPE;
+ event.kbd.ascii = 27;
+ } else if (CHANGED(PSP_CTRL_START)) {
+ event.kbd.keycode = Common::KEYCODE_F5;
+ event.kbd.ascii = Common::ASCII_F5;
+ if (DOWN(PSP_CTRL_RTRIGGER)) {
+ event.kbd.flags |= Common::KBD_CTRL; // Main menu to allow RTL
+ }
+ } else if (CHANGED(PSP_CTRL_SQUARE)) {
+ event.kbd.keycode = Common::KEYCODE_PERIOD;
+ event.kbd.ascii = '.';
+ } else if (CHANGED(PSP_CTRL_TRIANGLE)) {
+ event.kbd.keycode = Common::KEYCODE_RETURN;
+ event.kbd.ascii = '\r';
+ } else if (DOWN(PSP_CTRL_RTRIGGER)) { // An event
+ event.kbd.flags |= Common::KBD_SHIFT;
+ }
+ PSP_DEBUG_PRINT("Ascii[%d]. Key %s.\n", event.kbd.ascii, event.type == Common::EVENT_KEYDOWN ? "down" : "up" );
+ }
+
+ haveEvent = true;
+ }
+
+ DEBUG_EXIT_FUNC();
+ return haveEvent;
+}
+
+bool InputHandler::getNubEvent(Common::Event &event, SceCtrlData &pad) {
+ DEBUG_ENTER_FUNC();
+
+ bool haveEvent = false;
+ int32 analogStepX = pad.Lx; // Goes up to 255.
+ int32 analogStepY = pad.Ly;
+
+ int32 oldX = _cursor->getX();
+ int32 oldY = _cursor->getY();
+
+ analogStepX = modifyNubAxisMotion(analogStepX);
+ analogStepY = modifyNubAxisMotion(analogStepY);
+
+ if (analogStepX != 0 || analogStepY != 0) {
+
+ PSP_DEBUG_PRINT("raw x[%d], y[%d]\n", analogStepX, analogStepY);
+
+ // If no movement then this has no effect
+ if (DOWN(PSP_CTRL_RTRIGGER)) {
+ // Fine control mode for analog
+ if (analogStepX != 0) {
+ if (analogStepX > 0)
+ _cursor->increaseXY(2, 0);
+ else
+ _cursor->increaseXY(-2, 0);
+ }
+
+ if (analogStepY != 0) {
+ if (analogStepY > 0)
+ _cursor->increaseXY(0, 2);
+ else
+ _cursor->increaseXY(0, -2);
+ }
+ } else { // Regular speed movement
+ _cursor->increaseXY(analogStepX, 0);
+ _cursor->increaseXY(0, analogStepY);
+ }
+
+ int32 newX = _cursor->getX();
+ int32 newY = _cursor->getY();
+
+ if ((oldX != newX) || (oldY != newY)) {
+ event.type = Common::EVENT_MOUSEMOVE;
+ event.mouse.x = newX;
+ event.mouse.y = newY;
+ haveEvent = true;
+
+ PSP_DEBUG_PRINT("Nub event. X[%d], Y[%d]\n", newX, newY);
+ }
+ }
+ DEBUG_EXIT_FUNC();
+ return haveEvent;
+}
+
+inline int32 InputHandler::modifyNubAxisMotion(int32 input) {
+ DEBUG_ENTER_FUNC();
+ const int MIN_NUB_MOTION = 30;
+
+ input -= 128; // Center on 0.
+
+ if (input < -MIN_NUB_MOTION - 1)
+ input += MIN_NUB_MOTION + 1; // reduce the velocity
+ else if (input > MIN_NUB_MOTION)
+ input -= MIN_NUB_MOTION; // same
+ else // between these points, dampen the response to 0
+ input = 0;
+
+
+ DEBUG_EXIT_FUNC();
+ return input;
+}
Property changes on: scummvm/trunk/backends/platform/psp/input.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: scummvm/trunk/backends/platform/psp/input.h
===================================================================
--- scummvm/trunk/backends/platform/psp/input.h (rev 0)
+++ scummvm/trunk/backends/platform/psp/input.h 2010-04-12 06:49:05 UTC (rev 48632)
@@ -0,0 +1,63 @@
+/* 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.
+ *
@@ Diff output truncated at 100000 characters. @@
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list