aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorFilippos Karapetis2012-06-13 12:19:18 +0300
committerFilippos Karapetis2012-06-13 12:26:57 +0300
commit098f162ecc4951873909e9815506d4053178b6f9 (patch)
treea69799c1675204e5e53cb40c789f0ff43663044d /engines
parent944a774e6a7fd604b0754569007e5e34d1be915f (diff)
downloadscummvm-rg350-098f162ecc4951873909e9815506d4053178b6f9.tar.gz
scummvm-rg350-098f162ecc4951873909e9815506d4053178b6f9.tar.bz2
scummvm-rg350-098f162ecc4951873909e9815506d4053178b6f9.zip
SCI: Use the later SCI file functions for the SCI0 ones
They are essentially the same (with the exception of the return values), so unifying them reduces code duplication
Diffstat (limited to 'engines')
-rw-r--r--engines/sci/engine/kernel.h4
-rw-r--r--engines/sci/engine/kernel_tables.h8
-rw-r--r--engines/sci/engine/kfile.cpp65
3 files changed, 22 insertions, 55 deletions
diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h
index d64bc42841..677b790f93 100644
--- a/engines/sci/engine/kernel.h
+++ b/engines/sci/engine/kernel.h
@@ -323,10 +323,6 @@ reg_t kTimesCot(EngineState *s, int argc, reg_t *argv);
reg_t kCosDiv(EngineState *s, int argc, reg_t *argv);
reg_t kSinDiv(EngineState *s, int argc, reg_t *argv);
reg_t kValidPath(EngineState *s, int argc, reg_t *argv);
-reg_t kFOpen(EngineState *s, int argc, reg_t *argv);
-reg_t kFPuts(EngineState *s, int argc, reg_t *argv);
-reg_t kFGets(EngineState *s, int argc, reg_t *argv);
-reg_t kFClose(EngineState *s, int argc, reg_t *argv);
reg_t kMapKeyToDir(EngineState *s, int argc, reg_t *argv);
reg_t kGlobalToLocal(EngineState *s, int argc, reg_t *argv);
reg_t kLocalToGlobal(EngineState *s, int argc, reg_t *argv);
diff --git a/engines/sci/engine/kernel_tables.h b/engines/sci/engine/kernel_tables.h
index cdc810eef0..d093310139 100644
--- a/engines/sci/engine/kernel_tables.h
+++ b/engines/sci/engine/kernel_tables.h
@@ -350,10 +350,10 @@ static SciKernelMapEntry s_kernelMap[] = {
{ MAP_CALL(EditControl), SIG_EVERYWHERE, "[o0][o0]", NULL, NULL },
{ MAP_CALL(Empty), SIG_EVERYWHERE, "(.*)", NULL, NULL },
{ MAP_CALL(EmptyList), SIG_EVERYWHERE, "l", NULL, NULL },
- { MAP_CALL(FClose), SIG_EVERYWHERE, "i", NULL, NULL },
- { MAP_CALL(FGets), SIG_EVERYWHERE, "rii", NULL, NULL },
- { MAP_CALL(FOpen), SIG_EVERYWHERE, "ri", NULL, NULL },
- { MAP_CALL(FPuts), SIG_EVERYWHERE, "ir", NULL, NULL },
+ { "FClose", kFileIOClose, SIG_EVERYWHERE, "i", NULL, NULL },
+ { "FGets", kFileIOReadString, SIG_EVERYWHERE, "rii", NULL, NULL },
+ { "FOpen", kFileIOOpen, SIG_EVERYWHERE, "ri", NULL, NULL },
+ { "FPuts", kFileIOWriteString, SIG_EVERYWHERE, "ir", NULL, NULL },
{ MAP_CALL(FileIO), SIG_EVERYWHERE, "i(.*)", kFileIO_subops, NULL },
{ MAP_CALL(FindKey), SIG_EVERYWHERE, "l.", NULL, kFindKey_workarounds },
{ MAP_CALL(FirstNode), SIG_EVERYWHERE, "[l0]", NULL, NULL },
diff --git a/engines/sci/engine/kfile.cpp b/engines/sci/engine/kfile.cpp
index fe54987e47..052332957b 100644
--- a/engines/sci/engine/kfile.cpp
+++ b/engines/sci/engine/kfile.cpp
@@ -47,47 +47,6 @@ extern int fgets_wrapper(EngineState *s, char *dest, int maxsize, int handle);
extern void listSavegames(Common::Array<SavegameDesc> &saves);
extern int findSavegame(Common::Array<SavegameDesc> &saves, int16 savegameId);
-reg_t kFOpen(EngineState *s, int argc, reg_t *argv) {
- Common::String name = s->_segMan->getString(argv[0]);
- int mode = argv[1].toUint16();
-
- debugC(kDebugLevelFile, "kFOpen(%s,0x%x)", name.c_str(), mode);
- return file_open(s, name, mode, true);
-}
-
-reg_t kFClose(EngineState *s, int argc, reg_t *argv) {
- debugC(kDebugLevelFile, "kFClose(%d)", argv[0].toUint16());
- if (argv[0] != SIGNAL_REG) {
- FileHandle *f = getFileFromHandle(s, argv[0].toUint16());
- if (f)
- f->close();
- }
- return s->r_acc;
-}
-
-reg_t kFPuts(EngineState *s, int argc, reg_t *argv) {
- int handle = argv[0].toUint16();
- Common::String data = s->_segMan->getString(argv[1]);
-
- FileHandle *f = getFileFromHandle(s, handle);
- if (f)
- f->_out->write(data.c_str(), data.size());
-
- return s->r_acc;
-}
-
-reg_t kFGets(EngineState *s, int argc, reg_t *argv) {
- int maxsize = argv[1].toUint16();
- char *buf = new char[maxsize];
- int handle = argv[2].toUint16();
-
- debugC(kDebugLevelFile, "kFGets(%d, %d)", handle, maxsize);
- int readBytes = fgets_wrapper(s, buf, maxsize, handle);
- s->_segMan->memcpy(argv[0], (const byte*)buf, maxsize);
- delete[] buf;
- return readBytes ? argv[0] : NULL_REG;
-}
-
/**
* Writes the cwd to the supplied address and returns the address in acc.
*/
@@ -559,6 +518,9 @@ reg_t kFileIOOpen(EngineState *s, int argc, reg_t *argv) {
reg_t kFileIOClose(EngineState *s, int argc, reg_t *argv) {
debugC(kDebugLevelFile, "kFileIO(close): %d", argv[0].toUint16());
+ if (argv[0] == SIGNAL_REG)
+ return s->r_acc;
+
uint16 handle = argv[0].toUint16();
#ifdef ENABLE_SCI32
@@ -571,8 +533,13 @@ reg_t kFileIOClose(EngineState *s, int argc, reg_t *argv) {
FileHandle *f = getFileFromHandle(s, handle);
if (f) {
f->close();
+ if (getSciVersion() <= SCI_VERSION_0_LATE)
+ return s->r_acc; // SCI0 semantics: no value returned
return SIGNAL_REG;
}
+
+ if (getSciVersion() <= SCI_VERSION_0_LATE)
+ return s->r_acc; // SCI0 semantics: no value returned
return NULL_REG;
}
@@ -635,20 +602,20 @@ reg_t kFileIOWriteRaw(EngineState *s, int argc, reg_t *argv) {
}
reg_t kFileIOReadString(EngineState *s, int argc, reg_t *argv) {
- uint16 size = argv[1].toUint16();
- char *buf = new char[size];
+ uint16 maxsize = argv[1].toUint16();
+ char *buf = new char[maxsize];
uint16 handle = argv[2].toUint16();
- debugC(kDebugLevelFile, "kFileIO(readString): %d, %d", handle, size);
+ debugC(kDebugLevelFile, "kFileIO(readString): %d, %d", handle, maxsize);
uint32 bytesRead;
#ifdef ENABLE_SCI32
if (handle == VIRTUALFILE_HANDLE)
- bytesRead = s->_virtualIndexFile->readLine(buf, size);
+ bytesRead = s->_virtualIndexFile->readLine(buf, maxsize);
else
#endif
- bytesRead = fgets_wrapper(s, buf, size, handle);
+ bytesRead = fgets_wrapper(s, buf, maxsize, handle);
- s->_segMan->memcpy(argv[0], (const byte*)buf, size);
+ s->_segMan->memcpy(argv[0], (const byte*)buf, maxsize);
delete[] buf;
return bytesRead ? argv[0] : NULL_REG;
}
@@ -669,9 +636,13 @@ reg_t kFileIOWriteString(EngineState *s, int argc, reg_t *argv) {
if (f) {
f->_out->write(str.c_str(), str.size());
+ if (getSciVersion() <= SCI_VERSION_0_LATE)
+ return s->r_acc; // SCI0 semantics: no value returned
return NULL_REG;
}
+ if (getSciVersion() <= SCI_VERSION_0_LATE)
+ return s->r_acc; // SCI0 semantics: no value returned
return make_reg(0, 6); // DOS - invalid handle
}