Initial commit

This commit is contained in:
2026-02-02 04:50:13 +01:00
commit 5b11698731
22592 changed files with 7677434 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#if defined(__PSP__)
// Disable printf override in common/forbidden.h to avoid
// clashes with pspdebug.h from the PSP SDK.
// That header file uses
// __attribute__((format(printf,1,2)));
// which gets messed up by our override mechanism; this could
// be avoided by either changing the PSP SDK to use the equally
// legal and valid
// __attribute__((format(__printf__,1,2)));
// or by refining our printf override to use a varadic macro
// (which then wouldn't be portable, though).
// Anyway, for now we just disable the printf override globally
// for the PSP port
#define FORBIDDEN_SYMBOL_EXCEPTION_printf
#define FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
#include "backends/fs/psp/psp-fs-factory.h"
#include "backends/fs/psp/psp-fs.h"
#include "backends/platform/psp/powerman.h"
#include <unistd.h>
namespace Common {
DECLARE_SINGLETON(PSPFilesystemFactory);
}
AbstractFSNode *PSPFilesystemFactory::makeRootFileNode() const {
return new PSPFilesystemNode();
}
AbstractFSNode *PSPFilesystemFactory::makeCurrentDirectoryFileNode() const {
char buf[MAXPATHLEN];
char *ret = 0;
PowerMan.beginCriticalSection();
ret = getcwd(buf, MAXPATHLEN);
PowerMan.endCriticalSection();
return (ret ? new PSPFilesystemNode(buf) : NULL);
}
AbstractFSNode *PSPFilesystemFactory::makeFileNodePath(const Common::String &path) const {
return new PSPFilesystemNode(path, true);
}
#endif

View File

@@ -0,0 +1,46 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PSP_FILESYSTEM_FACTORY_H
#define PSP_FILESYSTEM_FACTORY_H
#include "common/singleton.h"
#include "backends/fs/fs-factory.h"
/**
* Creates PSPFilesystemNode objects.
*
* Parts of this class are documented in the base interface class, FilesystemFactory.
*/
class PSPFilesystemFactory final : public FilesystemFactory, public Common::Singleton<PSPFilesystemFactory> {
public:
AbstractFSNode *makeRootFileNode() const override;
AbstractFSNode *makeCurrentDirectoryFileNode() const override;
AbstractFSNode *makeFileNodePath(const Common::String &path) const override;
protected:
PSPFilesystemFactory() {}
private:
friend class Common::Singleton<SingletonBaseType>;
};
#endif /*PSP_FILESYSTEM_FACTORY_H*/

261
backends/fs/psp/psp-fs.cpp Normal file
View File

@@ -0,0 +1,261 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#if defined(__PSP__)
// Disable printf override in common/forbidden.h to avoid
// clashes with pspdebug.h from the PSP SDK.
// That header file uses
// __attribute__((format(printf,1,2)));
// which gets messed up by our override mechanism; this could
// be avoided by either changing the PSP SDK to use the equally
// legal and valid
// __attribute__((format(__printf__,1,2)));
// or by refining our printf override to use a varadic macro
// (which then wouldn't be portable, though).
// Anyway, for now we just disable the printf override globally
// for the PSP port
#define FORBIDDEN_SYMBOL_EXCEPTION_printf
#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
#define FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
#define FORBIDDEN_SYMBOL_EXCEPTION_mkdir
#include "backends/fs/psp/psp-fs.h"
#include "backends/fs/psp/psp-stream.h"
#include "common/bufferedstream.h"
#include "engines/engine.h"
#include <sys/stat.h>
#include <unistd.h>
#include <pspkernel.h>
#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"
PSPFilesystemNode::PSPFilesystemNode() {
_isDirectory = true;
_displayName = "Root";
_isValid = true;
_path = ROOT_PATH;
}
PSPFilesystemNode::PSPFilesystemNode(const Common::String &p, bool verify) {
DEBUG_ENTER_FUNC();
assert(p.size() > 0);
_path = p;
_displayName = lastPathComponent(_path, '/');
_isValid = true;
_isDirectory = true;
PSP_DEBUG_PRINT_FUNC("path [%s]\n", _path.c_str());
if (verify) {
struct stat st;
if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
PSP_DEBUG_PRINT_FUNC("Suspended\n");
_isValid = (0 == stat(_path.c_str(), &st));
PowerMan.endCriticalSection();
_isDirectory = S_ISDIR(st.st_mode);
}
}
bool PSPFilesystemNode::exists() const {
DEBUG_ENTER_FUNC();
int ret = 0;
if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
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);
}
bool PSPFilesystemNode::isReadable() const {
DEBUG_ENTER_FUNC();
int ret = 0;
if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
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);
}
bool PSPFilesystemNode::isWritable() const {
DEBUG_ENTER_FUNC();
int ret = 0;
if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
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();
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);
Common::String newPath(_path);
if (_path.lastChar() != '/')
newPath += '/';
newPath += n;
PSP_DEBUG_PRINT_FUNC("child [%s]\n", newPath.c_str());
AbstractFSNode *node = new PSPFilesystemNode(newPath, true);
return node;
}
bool PSPFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const {
DEBUG_ENTER_FUNC();
assert(_isDirectory);
//TODO: honor the hidden flag
bool ret = true;
if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
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;
memset(&dir, 0, sizeof(dir));
while (sceIoDread(dfd, &dir) > 0) {
// Skip 'invisible files
if (dir.d_name[0] == '.')
continue;
PSPFilesystemNode entry;
entry._isValid = true;
entry._displayName = dir.d_name;
Common::String newPath(_path);
if (newPath.lastChar() != '/')
newPath += '/';
newPath += dir.d_name;
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))
continue;
myList.push_back(new PSPFilesystemNode(entry));
}
sceIoDclose(dfd);
ret = true;
} else { // dfd <= 0
ret = false;
}
PowerMan.endCriticalSection();
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, '/');
AbstractFSNode *node = new PSPFilesystemNode(Common::String(start, end - start), false);
return node;
}
Common::SeekableReadStream *PSPFilesystemNode::createReadStream() {
const uint32 READ_BUFFER_SIZE = 1024;
Common::SeekableReadStream *stream = PspIoStream::makeFromPath(getPath(), false);
return Common::wrapBufferedSeekableReadStream(stream, READ_BUFFER_SIZE, DisposeAfterUse::YES);
}
Common::SeekableWriteStream *PSPFilesystemNode::createWriteStream(bool atomic) {
const uint32 WRITE_BUFFER_SIZE = 1024;
// TODO: Add atomic support if possible
Common::SeekableWriteStream *stream = PspIoStream::makeFromPath(getPath(), true);
return Common::wrapBufferedWriteStream(stream, WRITE_BUFFER_SIZE);
}
bool PSPFilesystemNode::createDirectory() {
DEBUG_ENTER_FUNC();
if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
PSP_DEBUG_PRINT_FUNC("Suspended\n"); // Make sure to block in case of suspend
PSP_DEBUG_PRINT_FUNC("path [%s]\n", _path.c_str());
if (sceIoMkdir(_path.c_str(), 0777) == 0) {
struct stat st;
_isValid = (0 == stat(_path.c_str(), &st));
_isDirectory = S_ISDIR(st.st_mode);
}
PowerMan.endCriticalSection();
return _isValid && _isDirectory;
}
#endif //#ifdef __PSP__

70
backends/fs/psp/psp-fs.h Normal file
View File

@@ -0,0 +1,70 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PSP_FILESYSTEM_H
#define PSP_FILESYSTEM_H
#include "backends/fs/abstract-fs.h"
/**
* Implementation of the ScummVM file system API based on PSPSDK API.
*
* Parts of this class are documented in the base interface class, AbstractFSNode.
*/
class PSPFilesystemNode : public AbstractFSNode {
protected:
Common::String _displayName;
Common::String _path;
bool _isDirectory;
bool _isValid;
public:
/**
* Creates a PSPFilesystemNode with the root node as path.
*/
PSPFilesystemNode();
/**
* Creates a PSPFilesystemNode for a given path.
*
* @param path Common::String with the path the new node should point to.
* @param verify true if the isValid and isDirectory flags should be verified during the construction.
*/
PSPFilesystemNode(const Common::String &p, bool verify = true);
virtual bool exists() const;
virtual Common::U32String getDisplayName() const { return _displayName; }
virtual Common::String getName() const { return _displayName; }
virtual Common::String getPath() const { return _path; }
virtual bool isDirectory() const { return _isDirectory; }
virtual bool isReadable() const;
virtual bool isWritable() const;
virtual AbstractFSNode *getChild(const Common::String &n) const;
virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const;
virtual AbstractFSNode *getParent() const;
virtual Common::SeekableReadStream *createReadStream();
virtual Common::SeekableWriteStream *createWriteStream(bool atomic);
virtual bool createDirectory();
};
#endif

View File

@@ -0,0 +1,335 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifdef __PSP__
#include <pspiofilemgr.h>
#include "backends/platform/psp/powerman.h"
#include "backends/fs/psp/psp-stream.h"
#define MIN2(a,b) ((a < b) ? a : b)
#define MIN3(a,b,c) ( (a < b) ? (a < c ? a : c) : (b < c ? b : c) )
//#define __PSP_PRINT_TO_FILE__ /* For debugging suspend stuff, we have no screen output */
//#define __PSP_DEBUG_FUNCS__ /* For debugging function calls */
//#define __PSP_DEBUG_PRINT__ /* For debug printouts */
#include "backends/platform/psp/trace.h"
//#define DEBUG_BUFFERS /* to see the contents of the buffers being read */
#ifdef DEBUG_BUFFERS
void printBuffer(byte *ptr, uint32 len) {
uint32 printLen = len <= 10 ? len : 10;
for (int i = 0; i < printLen; i++) {
PSP_INFO_PRINT("%x ", ptr[i]);
}
if (len > 10) {
PSP_INFO_PRINT("... ");
for (int i = len - 10; i < len; i++)
PSP_INFO_PRINT("%x ", ptr[i]);
}
PSP_INFO_PRINT("\n");
}
#endif
// Class PspIoStream ------------------------------------------------
PspIoStream::PspIoStream(const Common::String &path, bool writeMode)
: _handle(0), _path(path), _fileSize(0), _writeMode(writeMode),
_physicalPos(0), _pos(0), _eos(false), _error(false),
_errorSuspend(0), _errorSource(0), _errorPos(0), _errorHandle(0), _suspendCount(0) {
DEBUG_ENTER_FUNC();
//assert(!path.empty()); // do we need this?
}
PspIoStream::~PspIoStream() {
DEBUG_ENTER_FUNC();
if (PowerMan.beginCriticalSection())
PSP_DEBUG_PRINT_FUNC("suspended\n");
PowerMan.unregisterForSuspend(this); // Unregister with powermanager to be suspended
// Must do this before fclose() or resume() will reopen.
sceIoClose(_handle);
PowerMan.endCriticalSection();
}
/* Function to open the file pointed to by the path.
*
*/
SceUID PspIoStream::open() {
DEBUG_ENTER_FUNC();
if (PowerMan.beginCriticalSection()) {
// No need to open? Just return the _handle resume() already opened
PSP_DEBUG_PRINT_FUNC("suspended\n");
}
_handle = sceIoOpen(_path.c_str(), _writeMode ? PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC : PSP_O_RDONLY, 0777);
if (_handle <= 0) {
_error = true;
_handle = 0;
}
// Get the file size. This way is much faster than going to the end of the file and back
SceIoStat stat;
sceIoGetstat(_path.c_str(), &stat);
_fileSize = stat.st_size; // 4GB file (32 bits) is big enough for us
PSP_DEBUG_PRINT("%s filesize[%d]\n", _path.c_str(), _fileSize);
PowerMan.registerForSuspend(this); // Register with the powermanager to be suspended
PowerMan.endCriticalSection();
return _handle;
}
bool PspIoStream::err() const {
DEBUG_ENTER_FUNC();
if (_error) // We dump since no printing to screen with suspend callback
PSP_ERROR("mem_error[%d], source[%d], suspend error[%d], pos[%d],"
"_errorPos[%d], _errorHandle[%p], suspendCount[%d]\n",
_error, _errorSource, _errorSuspend, _pos,
_errorPos, _errorHandle, _suspendCount);
return _error;
}
void PspIoStream::clearErr() {
_error = false;
}
bool PspIoStream::eos() const {
return _eos;
}
int64 PspIoStream::pos() const {
return _pos;
}
int64 PspIoStream::size() const {
return _fileSize;
}
bool PspIoStream::physicalSeekFromCur(int32 offset) {
int ret = sceIoLseek32(_handle, offset, PSP_SEEK_CUR);
if (ret < 0) {
_error = true;
PSP_ERROR("failed to seek in file[%s] to [%x]. Error[%x]\n", _path.c_str(), offset, ret);
return false;
}
_physicalPos += offset;
return true;
}
bool PspIoStream::seek(int64 offs, int whence) {
DEBUG_ENTER_FUNC();
PSP_DEBUG_PRINT_FUNC("offset[0x%x], whence[%d], _pos[0x%x], _physPos[0x%x]\n", offs, whence, _pos, _physicalPos);
_eos = false;
int32 posToSearchFor = 0;
switch (whence) {
case SEEK_CUR:
posToSearchFor = _pos;
break;
case SEEK_END:
posToSearchFor = _fileSize;
break;
}
posToSearchFor += offs;
// Check for bad values
if (posToSearchFor < 0) {
_error = true;
return false;
} else if (posToSearchFor > _fileSize) {
_error = true;
_eos = true;
return false;
}
_pos = posToSearchFor;
return true;
}
uint32 PspIoStream::read(void *ptr, uint32 len) {
DEBUG_ENTER_FUNC();
PSP_DEBUG_PRINT_FUNC("filename[%s], len[0x%x], ptr[%p], _pos[%x], _physPos[%x]\n", _path.c_str(), len, ptr, _pos, _physicalPos);
if (_error || _eos || len <= 0)
return 0;
uint32 lenRemainingInFile = _fileSize - _pos;
// check for getting EOS
if (len > lenRemainingInFile) {
len = lenRemainingInFile;
_eos = true;
}
if (PowerMan.beginCriticalSection())
PSP_DEBUG_PRINT_FUNC("suspended\n");
// check if we need to seek
if (_pos != _physicalPos) {
PSP_DEBUG_PRINT("seeking from %x to %x\n", _physicalPos, _pos);
if (!physicalSeekFromCur(_pos - _physicalPos)) {
_error = true;
return 0;
}
}
int ret = sceIoRead(_handle, ptr, len);
PowerMan.endCriticalSection();
_physicalPos += ret; // Update position
_pos = _physicalPos;
if (ret != (int)len) { // error
PSP_ERROR("sceIoRead returned [0x%x] instead of len[0x%x]\n", ret, len);
_error = true;
_errorSource = 4;
}
return ret;
}
uint32 PspIoStream::write(const void *ptr, uint32 len) {
DEBUG_ENTER_FUNC();
PSP_DEBUG_PRINT_FUNC("filename[%s], len[0x%x], ptr[%p], _pos[%x], _physPos[%x]\n", _path.c_str(), len, ptr, _pos, _physicalPos);
if (!len || _error) // we actually get some calls with len == 0!
return 0;
_eos = false; // we can't have eos with write
if (PowerMan.beginCriticalSection())
PSP_DEBUG_PRINT_FUNC("suspended\n");
// check if we need to seek
if (_pos != _physicalPos)
if (!physicalSeekFromCur(_pos - _physicalPos)) {
_error = true;
return 0;
}
int ret = sceIoWrite(_handle, ptr, len);
PowerMan.endCriticalSection();
if (ret != (int)len) {
_error = true;
_errorSource = 5;
PSP_ERROR("sceIoWrite returned[0x%x] instead of len[0x%x]\n", ret, len);
}
_physicalPos += ret;
_pos = _physicalPos;
if (_pos > _fileSize)
_fileSize = _pos;
return ret;
}
bool PspIoStream::flush() {
return true;
}
// 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) {
delete stream;
stream = 0;
}
return stream;
}
/*
* Function to suspend the IO stream (called by PowerManager)
* we can have no output here
*/
int PspIoStream::suspend() {
DEBUG_ENTER_FUNC();
_suspendCount++;
if (_handle > 0 && _pos < 0) { /* check for error */
_errorSuspend = SuspendError;
_errorPos = _pos;
_errorHandle = _handle;
}
if (_handle > 0) {
sceIoClose(_handle); // close our file descriptor
_handle = 0xFFFFFFFF; // Set handle to non-null invalid value so makeFromPath doesn't return error
}
return 0;
}
/*
* Function to resume the IO stream (called by Power Manager)
*/
int PspIoStream::resume() {
DEBUG_ENTER_FUNC();
int ret = 0;
_suspendCount--;
// We reopen our file descriptor
_handle = sceIoOpen(_path.c_str(), _writeMode ? PSP_O_RDWR | PSP_O_CREAT : PSP_O_RDONLY, 0777); // open
if (_handle <= 0) {
_errorSuspend = ResumeError;
_errorPos = _pos;
}
// Resume our previous position if needed
if (_handle > 0 && _pos > 0) {
ret = sceIoLseek32(_handle, _pos, PSP_SEEK_SET);
_physicalPos = _pos;
if (ret < 0) { // Check for problem
_errorSuspend = ResumeError;
_errorPos = _pos;
_errorHandle = _handle;
}
}
return ret;
}
#endif /* __PSP__ */

View File

@@ -0,0 +1,90 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PSPSTREAM_H_
#define PSPSTREAM_H_
#include <pspkerneltypes.h>
#include "backends/platform/psp/powerman.h"
//#include "common/list.h"
#include "common/noncopyable.h"
#include "common/stream.h"
#include "common/str.h"
/**
* Class to handle special suspend/resume needs of PSP IO Streams
*/
class PspIoStream final : public Common::SeekableReadStream, public Common::SeekableWriteStream, public Common::NonCopyable, public Suspendable {
protected:
SceUID _handle; // file handle
Common::String _path;
int _fileSize;
bool _writeMode; // for resuming in the right mode
int _physicalPos; // physical position in file
int _pos; // position. Sometimes virtual
bool _eos; // EOS flag
enum {
SuspendError = 2,
ResumeError = 3
};
// debug stuff
mutable int _error; // file error state
int _errorSuspend; // for debugging
mutable int _errorSource;
int _errorPos;
SceUID _errorHandle;
int _suspendCount;
bool physicalSeekFromCur(int32 offset);
public:
/**
* Given a path, invoke fopen on that path and wrap the result in a
* PspIoStream instance.
*/
static PspIoStream *makeFromPath(const Common::String &path, bool writeMode);
PspIoStream(const Common::String &path, bool writeMode);
~PspIoStream() override;
SceUID open(); // open the file pointed to by the file path
bool err() const override;
void clearErr() override;
bool eos() const override;
uint32 write(const void *dataPtr, uint32 dataSize) override;
bool flush() override;
int64 pos() const override;
int64 size() const override;
bool seek(int64 offs, int whence = SEEK_SET) override;
uint32 read(void *dataPtr, uint32 dataSize) override;
// for suspending
int suspend() override; /* Suspendable interface (power manager) */
int resume() override; /* " " */
};
#endif /* PSPSTREAM_H_ */