aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsluicebox2019-10-11 14:10:16 -0700
committersluicebox2019-10-11 14:14:15 -0700
commitea01e42918b1582f774727fd0fceb0672762af45 (patch)
tree4a8373e643fe0d16e44aec3429fdd2355d5f21e0
parentc964ed2b0bc9c38ea4f73abe982dff144e36a331 (diff)
downloadscummvm-rg350-ea01e42918b1582f774727fd0fceb0672762af45.tar.gz
scummvm-rg350-ea01e42918b1582f774727fd0fceb0672762af45.tar.bz2
scummvm-rg350-ea01e42918b1582f774727fd0fceb0672762af45.zip
SCI: Fix more kFileIO return values
Fix a number of incorrect return values from file IO functions, continuing the kFileIOWriteString fix from 7c1fb8bee1890f831adde61a98d94a563f9d14fa One of the misconceptions was that these functions return DOS error error codes on failure. Instead, SCI16 immediately zeros those out.
-rw-r--r--engines/sci/engine/kfile.cpp45
1 files changed, 13 insertions, 32 deletions
diff --git a/engines/sci/engine/kfile.cpp b/engines/sci/engine/kfile.cpp
index 156d294ab4..f364e9d79f 100644
--- a/engines/sci/engine/kfile.cpp
+++ b/engines/sci/engine/kfile.cpp
@@ -566,7 +566,7 @@ reg_t kFileIOClose(EngineState *s, int argc, reg_t *argv) {
if (handle >= kVirtualFileHandleStart) {
// it's a virtual handle? ignore it
- return getSciVersion() >= SCI_VERSION_2 ? TRUE_REG : SIGNAL_REG;
+ return TRUE_REG;
}
FileHandle *f = getFileFromHandle(s, handle);
@@ -574,7 +574,7 @@ reg_t kFileIOClose(EngineState *s, int argc, reg_t *argv) {
f->close();
if (getSciVersion() <= SCI_VERSION_0_LATE)
return s->r_acc; // SCI0 semantics: no value returned
- return getSciVersion() >= SCI_VERSION_2 ? TRUE_REG : SIGNAL_REG;
+ return TRUE_REG;
}
if (getSciVersion() <= SCI_VERSION_0_LATE)
@@ -628,19 +628,10 @@ reg_t kFileIOWriteRaw(EngineState *s, int argc, reg_t *argv) {
delete[] buf;
-#ifdef ENABLE_SCI32
- if (getSciVersion() >= SCI_VERSION_2) {
- if (!success) {
- return SIGNAL_REG;
- }
-
+ if (success) {
return make_reg(0, bytesWritten);
}
-#endif
-
- if (success)
- return NULL_REG;
- return make_reg(0, 6); // DOS - invalid handle
+ return getSciVersion() >= SCI_VERSION_2 ? SIGNAL_REG : NULL_REG;
}
reg_t kFileIOUnlink(EngineState *s, int argc, reg_t *argv) {
@@ -694,15 +685,7 @@ reg_t kFileIOUnlink(EngineState *s, int argc, reg_t *argv) {
debugC(kDebugLevelFile, "kFileIO(unlink): %s", name.c_str());
-#ifdef ENABLE_SCI32
- if (getSciVersion() >= SCI_VERSION_2) {
- return make_reg(0, result);
- }
-#endif
-
- if (result)
- return NULL_REG;
- return make_reg(0, 2); // DOS - file not found error code
+ return make_reg(0, result);
}
reg_t kFileIOReadString(EngineState *s, int argc, reg_t *argv) {
@@ -758,14 +741,10 @@ reg_t kFileIOWriteString(EngineState *s, int argc, reg_t *argv) {
if (f && f->_out) {
uint32 bytesWritten = f->_out->write(str.c_str(), str.size());
- if (getSciVersion() <= SCI_VERSION_0_LATE)
- return s->r_acc; // SCI0 semantics: no value returned
return make_reg(0, bytesWritten);
}
- if (getSciVersion() <= SCI_VERSION_0_LATE)
- return s->r_acc; // SCI0 semantics: no value returned
- return make_reg(0, 6); // DOS - invalid handle
+ return getSciVersion() >= SCI_VERSION_2 ? SIGNAL_REG : NULL_REG;
}
reg_t kFileIOSeek(EngineState *s, int argc, reg_t *argv) {
@@ -943,9 +922,11 @@ reg_t kFileIOReadByte(EngineState *s, int argc, reg_t *argv) {
reg_t kFileIOWriteByte(EngineState *s, int argc, reg_t *argv) {
FileHandle *f = getFileFromHandle(s, argv[0].toUint16());
- if (f)
+ if (f) {
f->_out->writeByte(argv[1].toUint16() & 0xff);
- return s->r_acc;
+ return make_reg(0, 1); // bytesWritten
+ }
+ return SIGNAL_REG;
}
reg_t kFileIOReadWord(EngineState *s, int argc, reg_t *argv) {
@@ -972,12 +953,12 @@ reg_t kFileIOWriteWord(EngineState *s, int argc, reg_t *argv) {
const uint16 handle = argv[0].toUint16();
if (handle == kVirtualFileHandleSci32Save) {
- return s->r_acc;
+ return make_reg(0, 2); // bytesWritten
}
FileHandle *f = getFileFromHandle(s, handle);
if (!f) {
- return s->r_acc;
+ return SIGNAL_REG;
}
if (f->_name == "-scummvm-save-") {
@@ -990,7 +971,7 @@ reg_t kFileIOWriteWord(EngineState *s, int argc, reg_t *argv) {
f->_out->writeUint16LE(argv[1].toUint16());
}
- return s->r_acc;
+ return make_reg(0, 2); // bytesWritten
}
reg_t kFileIOGetCWD(EngineState *s, int argc, reg_t *argv) {