mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-29 14:42:26 +00:00
remove bad hackery caused by n64 port and avoid polluting StdioStream using a custom Stream subclass
svn-id: r46777
This commit is contained in:
parent
dc5524bda5
commit
3a418c13a7
@ -23,12 +23,10 @@
|
||||
#ifdef __N64__
|
||||
|
||||
#include "backends/fs/abstract-fs.h"
|
||||
#include "backends/fs/stdiostream.h"
|
||||
#include "backends/fs/n64/romfsstream.h"
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <n64utils.h>
|
||||
|
||||
#define ROOT_PATH "/"
|
||||
@ -202,11 +200,11 @@ AbstractFSNode *N64FilesystemNode::getParent() const {
|
||||
}
|
||||
|
||||
Common::SeekableReadStream *N64FilesystemNode::createReadStream() {
|
||||
return StdioStream::makeFromPath(getPath(), false);
|
||||
return RomfsStream::makeFromPath(getPath(), false);
|
||||
}
|
||||
|
||||
Common::WriteStream *N64FilesystemNode::createWriteStream() {
|
||||
return StdioStream::makeFromPath(getPath(), true);
|
||||
return RomfsStream::makeFromPath(getPath(), true);
|
||||
}
|
||||
|
||||
#endif //#ifdef __N64__
|
||||
|
86
backends/fs/n64/romfsstream.cpp
Normal file
86
backends/fs/n64/romfsstream.cpp
Normal file
@ -0,0 +1,86 @@
|
||||
/* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __N64__
|
||||
|
||||
#include <romfs.h>
|
||||
#include "backends/fs/n64/romfsstream.h"
|
||||
|
||||
RomfsStream::RomfsStream(void *handle) : _handle(handle) {
|
||||
assert(handle);
|
||||
}
|
||||
|
||||
RomfsStream::~RomfsStream() {
|
||||
romfs_close((ROMFILE *)_handle);
|
||||
}
|
||||
|
||||
bool RomfsStream::err() const {
|
||||
return romfs_error((ROMFILE *)_handle) != 0;
|
||||
}
|
||||
|
||||
void RomfsStream::clearErr() {
|
||||
romfs_clearerr((ROMFILE *)_handle);
|
||||
}
|
||||
|
||||
bool RomfsStream::eos() const {
|
||||
return romfs_eof((ROMFILE *)_handle) != 0;
|
||||
}
|
||||
|
||||
int32 RomfsStream::pos() const {
|
||||
return romfs_tell((ROMFILE *)_handle);
|
||||
}
|
||||
|
||||
int32 RomfsStream::size() const {
|
||||
int32 oldPos = romfs_tell((ROMFILE *)_handle);
|
||||
romfs_seek((ROMFILE *)_handle, 0, SEEK_END);
|
||||
int32 length = romfs_tell((ROMFILE *)_handle);
|
||||
romfs_seek((ROMFILE *)_handle, oldPos, SEEK_SET);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
bool RomfsStream::seek(int32 offs, int whence) {
|
||||
return romfs_seek((ROMFILE *)_handle, offs, whence) == 0;
|
||||
}
|
||||
|
||||
uint32 RomfsStream::read(void *ptr, uint32 len) {
|
||||
return romfs_read((byte *)ptr, 1, len, (ROMFILE *)_handle);
|
||||
}
|
||||
|
||||
uint32 RomfsStream::write(const void *ptr, uint32 len) {
|
||||
return romfs_write(ptr, 1, len, (ROMFILE *)_handle);
|
||||
}
|
||||
|
||||
bool RomfsStream::flush() {
|
||||
return romfs_flush((ROMFILE *)_handle) == 0;
|
||||
}
|
||||
|
||||
RomfsStream *RomfsStream::makeFromPath(const Common::String &path, bool writeMode) {
|
||||
ROMFILE *handle = romfs_open(path.c_str(), writeMode ? "wb" : "rb");
|
||||
|
||||
if (handle)
|
||||
return new RomfsStream(handle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* __N64__ */
|
||||
|
59
backends/fs/n64/romfsstream.h
Normal file
59
backends/fs/n64/romfsstream.h
Normal file
@ -0,0 +1,59 @@
|
||||
/* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BACKENDS_FS_ROMFSSTREAM_H
|
||||
#define BACKENDS_FS_ROMFSSTREAM_H
|
||||
|
||||
#include "common/scummsys.h"
|
||||
#include "common/noncopyable.h"
|
||||
#include "common/stream.h"
|
||||
#include "common/str.h"
|
||||
|
||||
class RomfsStream : public Common::SeekableReadStream, public Common::WriteStream, public Common::NonCopyable {
|
||||
protected:
|
||||
/** File handle to the actual file. */
|
||||
void *_handle;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Given a path, invokes fopen on that path and wrap the result in a
|
||||
* RomfsStream instance.
|
||||
*/
|
||||
static RomfsStream *makeFromPath(const Common::String &path, bool writeMode);
|
||||
|
||||
RomfsStream(void *handle);
|
||||
virtual ~RomfsStream();
|
||||
|
||||
virtual bool err() const;
|
||||
virtual void clearErr();
|
||||
virtual bool eos() const;
|
||||
|
||||
virtual uint32 write(const void *dataPtr, uint32 dataSize);
|
||||
virtual bool flush();
|
||||
|
||||
virtual int32 pos() const;
|
||||
virtual int32 size() const;
|
||||
virtual bool seek(int32 offs, int whence = SEEK_SET);
|
||||
virtual uint32 read(void *dataPtr, uint32 dataSize);
|
||||
};
|
||||
|
||||
#endif
|
@ -25,28 +25,6 @@
|
||||
|
||||
#include "backends/fs/stdiostream.h"
|
||||
|
||||
#ifdef __N64__
|
||||
#include <romfs.h>
|
||||
|
||||
#undef feof
|
||||
#undef clearerr
|
||||
#undef ferror
|
||||
|
||||
#undef FILE
|
||||
#define FILE ROMFILE
|
||||
|
||||
#define fopen(name, mode) romfs_open(name, mode)
|
||||
#define fclose(handle) romfs_close(handle)
|
||||
#define fread(ptr, size, items, file) romfs_read(ptr, size, items, file)
|
||||
#define fwrite(ptr, size, items, file) romfs_write(ptr, size, items, file)
|
||||
#define feof(handle) romfs_eof(handle)
|
||||
#define ftell(handle) romfs_tell(handle)
|
||||
#define fseek(handle, offset, whence) romfs_seek(handle, offset, whence)
|
||||
#define clearerr(handle) romfs_clearerr(handle)
|
||||
#define fflush(file) romfs_flush(file)
|
||||
#define ferror(handle) romfs_error(handle)
|
||||
#endif
|
||||
|
||||
StdioStream::StdioStream(void *handle) : _handle(handle) {
|
||||
assert(handle);
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ MODULE_OBJS := \
|
||||
fs/windows/windows-fs-factory.o \
|
||||
fs/wii/wii-fs-factory.o \
|
||||
fs/n64/n64-fs-factory.o \
|
||||
fs/n64/romfsstream.o \
|
||||
keymapper/action.o \
|
||||
keymapper/keymap.o \
|
||||
keymapper/keymapper.o \
|
||||
|
@ -52,7 +52,7 @@ USE_RGB_COLOR=0
|
||||
|
||||
ENABLED=STATIC_PLUGIN
|
||||
|
||||
#ENABLE_SCUMM=$(ENABLED)
|
||||
ENABLE_SCUMM=$(ENABLED)
|
||||
#ENABLE_SKY=$(ENABLED)
|
||||
#ENABLE_SCI=$(ENABLED)
|
||||
#ENABLE_GOB=$(ENABLED)
|
||||
@ -62,7 +62,7 @@ ENABLED=STATIC_PLUGIN
|
||||
#ENABLE_AGI = $(ENABLED)
|
||||
#ENABLE_QUEEN = $(ENABLED)
|
||||
#ENABLE_MADE = $(ENABLED)
|
||||
ENABLE_SAGA = $(ENABLED)
|
||||
#ENABLE_SAGA = $(ENABLED)
|
||||
|
||||
OBJS := nintendo64.o osys_n64_base.o osys_n64_events.o osys_n64_utilities.o pakfs_save_manager.o
|
||||
|
||||
|
@ -22,6 +22,8 @@
|
||||
|
||||
#include <romfs.h>
|
||||
|
||||
#include <malloc.h> // Required for memalign
|
||||
|
||||
#include "osys_n64.h"
|
||||
#include "pakfs_save_manager.h"
|
||||
#include "backends/fs/n64/n64-fs-factory.h"
|
||||
|
@ -21,9 +21,8 @@
|
||||
*/
|
||||
|
||||
#include <n64utils.h>
|
||||
#include "pakfs_save_manager.h"
|
||||
|
||||
static bool matches(const char *glob, const char *name);
|
||||
#include "pakfs_save_manager.h"
|
||||
|
||||
bool deleteSaveGame(const char *filename) {
|
||||
int res = removeFileOnPak(filename);
|
||||
@ -56,11 +55,14 @@ Common::StringList PAKSaveManager::listSavefiles(const Common::String &pattern)
|
||||
PAKDIR *dirp = pakfs_opendir();
|
||||
pakfs_dirent *dp;
|
||||
Common::StringList list;
|
||||
Common::String *fname;
|
||||
|
||||
while ((dp = pakfs_readdir(dirp)) != NULL) {
|
||||
if (matches(pattern.c_str(), dp->entryname))
|
||||
fname = new Common::String(dp->entryname);
|
||||
if (fname->matchString(pattern, false, false))
|
||||
list.push_back(dp->entryname);
|
||||
|
||||
delete fname;
|
||||
free(dp);
|
||||
}
|
||||
|
||||
@ -69,24 +71,3 @@ Common::StringList PAKSaveManager::listSavefiles(const Common::String &pattern)
|
||||
return list;
|
||||
}
|
||||
|
||||
static bool matches(const char *glob, const char *name) {
|
||||
while (*glob)
|
||||
if (*glob == '*') {
|
||||
while (*glob == '*')
|
||||
glob++;
|
||||
do {
|
||||
if ((*name == *glob || *glob == '?') &&
|
||||
matches(glob, name))
|
||||
return true;
|
||||
} while (*name++);
|
||||
return false;
|
||||
} else if (!*name)
|
||||
return false;
|
||||
else if (*glob == '?' || *glob == *name) {
|
||||
glob++;
|
||||
name++;
|
||||
} else
|
||||
return false;
|
||||
return !*name;
|
||||
}
|
||||
|
||||
|
@ -29,15 +29,11 @@
|
||||
#include <n64utils.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#undef assert
|
||||
#define assert(x) ((x) ? 0 : (print_error("["#x"] (%s:%d)", __FILE__, __LINE__)))
|
||||
|
@ -45,15 +45,6 @@
|
||||
#define fflush(file) DS::std_fflush(file)
|
||||
#endif
|
||||
|
||||
#ifdef __N64__
|
||||
#include <n64utils.h>
|
||||
|
||||
#define fputs(str, file) asm("nop");
|
||||
#define fflush(a) asm("nop");
|
||||
#define OutputDebugString addLineTextLayer
|
||||
#endif
|
||||
|
||||
|
||||
// TODO: Move gDebugLevel into namespace Common.
|
||||
int gDebugLevel = -1;
|
||||
|
||||
|
@ -46,10 +46,6 @@ extern bool isSmartphone();
|
||||
#define fputs(str, file) DS::std_fwrite(str, strlen(str), 1, file)
|
||||
#endif
|
||||
|
||||
#ifdef __N64__
|
||||
#define fputs(str, file) asm("nop");
|
||||
#endif
|
||||
|
||||
namespace Common {
|
||||
|
||||
StringTokenizer::StringTokenizer(const String &str, const String &delimiters) : _str(str), _delimiters(delimiters) {
|
||||
|
@ -118,11 +118,12 @@ struct ColorMasks<555> {
|
||||
kBlueBits = 5,
|
||||
|
||||
#ifdef __N64__
|
||||
/* Nintendo 64 uses a BGR555 color format for 16bit display */
|
||||
kAlphaShift = 0,
|
||||
kRedShift = kBlueBits+kGreenBits+1,
|
||||
kGreenShift = kBlueBits + 1,
|
||||
kBlueShift = 1,
|
||||
#else
|
||||
#else /* RGB555 */
|
||||
kAlphaShift = 0,
|
||||
kRedShift = kGreenBits+kBlueBits,
|
||||
kGreenShift = kBlueBits,
|
||||
|
Loading…
x
Reference in New Issue
Block a user