aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Battaglia2009-12-30 22:56:19 +0000
committerFabio Battaglia2009-12-30 22:56:19 +0000
commit3a418c13a7ab9790bb9b43bfc435056827a79e64 (patch)
tree14fbf03424597cd89b98b10f189e0b54c97f3326
parentdc5524bda56007c4ea2006bf5f970f35392beb82 (diff)
downloadscummvm-rg350-3a418c13a7ab9790bb9b43bfc435056827a79e64.tar.gz
scummvm-rg350-3a418c13a7ab9790bb9b43bfc435056827a79e64.tar.bz2
scummvm-rg350-3a418c13a7ab9790bb9b43bfc435056827a79e64.zip
remove bad hackery caused by n64 port and avoid polluting StdioStream using a custom Stream subclass
svn-id: r46777
-rw-r--r--backends/fs/n64/n64-fs.cpp8
-rw-r--r--backends/fs/n64/romfsstream.cpp86
-rw-r--r--backends/fs/n64/romfsstream.h59
-rw-r--r--backends/fs/stdiostream.cpp22
-rw-r--r--backends/module.mk1
-rw-r--r--backends/platform/n64/Makefile4
-rw-r--r--backends/platform/n64/osys_n64_base.cpp2
-rw-r--r--backends/platform/n64/pakfs_save_manager.cpp29
-rw-r--r--backends/platform/n64/portdefs.h8
-rw-r--r--common/debug.cpp9
-rw-r--r--common/util.cpp4
-rw-r--r--graphics/colormasks.h3
12 files changed, 162 insertions, 73 deletions
diff --git a/backends/fs/n64/n64-fs.cpp b/backends/fs/n64/n64-fs.cpp
index 514e3be02d..4def84afcd 100644
--- a/backends/fs/n64/n64-fs.cpp
+++ b/backends/fs/n64/n64-fs.cpp
@@ -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__
diff --git a/backends/fs/n64/romfsstream.cpp b/backends/fs/n64/romfsstream.cpp
new file mode 100644
index 0000000000..2d30f852ca
--- /dev/null
+++ b/backends/fs/n64/romfsstream.cpp
@@ -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__ */
+
diff --git a/backends/fs/n64/romfsstream.h b/backends/fs/n64/romfsstream.h
new file mode 100644
index 0000000000..b0f27db13e
--- /dev/null
+++ b/backends/fs/n64/romfsstream.h
@@ -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
diff --git a/backends/fs/stdiostream.cpp b/backends/fs/stdiostream.cpp
index 73796a31ea..8845d796c6 100644
--- a/backends/fs/stdiostream.cpp
+++ b/backends/fs/stdiostream.cpp
@@ -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);
}
diff --git a/backends/module.mk b/backends/module.mk
index a902858b22..257ae0db9c 100644
--- a/backends/module.mk
+++ b/backends/module.mk
@@ -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 \
diff --git a/backends/platform/n64/Makefile b/backends/platform/n64/Makefile
index 833f660a49..8aa0a1e145 100644
--- a/backends/platform/n64/Makefile
+++ b/backends/platform/n64/Makefile
@@ -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
diff --git a/backends/platform/n64/osys_n64_base.cpp b/backends/platform/n64/osys_n64_base.cpp
index 65290c5c6e..558a8642e6 100644
--- a/backends/platform/n64/osys_n64_base.cpp
+++ b/backends/platform/n64/osys_n64_base.cpp
@@ -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"
diff --git a/backends/platform/n64/pakfs_save_manager.cpp b/backends/platform/n64/pakfs_save_manager.cpp
index 3fbf55a199..5499462d68 100644
--- a/backends/platform/n64/pakfs_save_manager.cpp
+++ b/backends/platform/n64/pakfs_save_manager.cpp
@@ -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;
-}
-
diff --git a/backends/platform/n64/portdefs.h b/backends/platform/n64/portdefs.h
index fd6d295b0c..942d807a91 100644
--- a/backends/platform/n64/portdefs.h
+++ b/backends/platform/n64/portdefs.h
@@ -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__)))
diff --git a/common/debug.cpp b/common/debug.cpp
index afdb794273..f6dc065c88 100644
--- a/common/debug.cpp
+++ b/common/debug.cpp
@@ -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;
diff --git a/common/util.cpp b/common/util.cpp
index d131064e6c..da6e41544f 100644
--- a/common/util.cpp
+++ b/common/util.cpp
@@ -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) {
diff --git a/graphics/colormasks.h b/graphics/colormasks.h
index b6cd9dcee4..1ab78fccc5 100644
--- a/graphics/colormasks.h
+++ b/graphics/colormasks.h
@@ -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,