aboutsummaryrefslogtreecommitdiff
path: root/engines/glk/glulxe
diff options
context:
space:
mode:
authorPaul Gilbert2019-05-03 19:49:21 +1000
committerPaul Gilbert2019-05-03 19:49:21 +1000
commita6b1bc98ae21348c8492c62d07fed738357777d6 (patch)
treedaef3fcbec2c605111bdeff5dab22ee3f3decd07 /engines/glk/glulxe
parentae7acf109992627e4627dabe1a25f815f8a7467b (diff)
downloadscummvm-rg350-a6b1bc98ae21348c8492c62d07fed738357777d6.tar.gz
scummvm-rg350-a6b1bc98ae21348c8492c62d07fed738357777d6.tar.bz2
scummvm-rg350-a6b1bc98ae21348c8492c62d07fed738357777d6.zip
GLK: GLULXE: Move savegame code into loadGameData/saveGameData
Diffstat (limited to 'engines/glk/glulxe')
-rw-r--r--engines/glk/glulxe/exec.cpp4
-rw-r--r--engines/glk/glulxe/glulxe.cpp10
-rw-r--r--engines/glk/glulxe/glulxe.h18
-rw-r--r--engines/glk/glulxe/serial.cpp25
4 files changed, 17 insertions, 40 deletions
diff --git a/engines/glk/glulxe/exec.cpp b/engines/glk/glulxe/exec.cpp
index 01faad888f..5fd15a3be6 100644
--- a/engines/glk/glulxe/exec.cpp
+++ b/engines/glk/glulxe/exec.cpp
@@ -681,12 +681,12 @@ PerformJump: /* goto label for successful jumping... ironic, no? */
case op_save:
push_callstub(inst[1].desttype, inst[1].value);
- value = perform_save(find_stream_by_id(inst[0].value));
+ value = saveGameData(find_stream_by_id(inst[0].value), "Savegame").getCode() == Common::kNoError ? 0 : 1;
pop_callstub(value);
break;
case op_restore:
- value = perform_restore(find_stream_by_id(inst[0].value), false);
+ value = loadGameData(find_stream_by_id(inst[0].value)).getCode() == Common::kNoError ? 0 : 1;
if (value == 0) {
/* We've succeeded, and the stack now contains the callstub
saved during saveundo. Ignore this opcode's operand. */
diff --git a/engines/glk/glulxe/glulxe.cpp b/engines/glk/glulxe/glulxe.cpp
index 5251b30d46..cbe09cef07 100644
--- a/engines/glk/glulxe/glulxe.cpp
+++ b/engines/glk/glulxe/glulxe.cpp
@@ -74,16 +74,6 @@ void Glulxe::runGame() {
profile_quit();
}
-Common::Error Glulxe::loadGameData(strid_t file) {
- // TODO
- return Common::kNoError;
-}
-
-Common::Error Glulxe::saveGameData(strid_t file, const Common::String &desc) {
- // TODO
- return Common::kNoError;
-}
-
bool Glulxe::is_gamefile_valid() {
if (_gameFile.size() < 8) {
GUIErrorMessage(_("This is too short to be a valid Glulx file."));
diff --git a/engines/glk/glulxe/glulxe.h b/engines/glk/glulxe/glulxe.h
index b5f13dc492..13a82b78be 100644
--- a/engines/glk/glulxe/glulxe.h
+++ b/engines/glk/glulxe/glulxe.h
@@ -411,12 +411,12 @@ public:
/**
* Load a savegame from the passed stream
*/
- virtual Common::Error loadGameData(strid_t file) override;
+ virtual Common::Error loadGameData(strid_t str) override;
/**
* Save the game to the passed stream
*/
- virtual Common::Error saveGameData(strid_t file, const Common::String &desc) override;
+ virtual Common::Error saveGameData(strid_t str, const Common::String &desc) override;
/**
* \defgroup Main access methods
@@ -935,20 +935,6 @@ public:
void final_serial();
/**
- * Write the state to the output stream. This returns 0 on success, 1 on failure.
- */
- uint perform_save(strid_t str);
-
- /**
- * Pull a state pointer from a stream. This returns 0 on success, 1 on failure. Note that if it succeeds,
- * the frameptr, localsbase, and valstackbase registers are invalid; they must be rebuilt from the stack.
- *
- * If fromshell is true, the restore is being invoked by the library shell (an autorestore of some kind).
- * This currently happens only in iosglk.
- */
- uint perform_restore(strid_t str, int fromshell);
-
- /**
* Add a state pointer to the undo chain. This returns 0 on success, 1 on failure.
*/
uint perform_saveundo();
diff --git a/engines/glk/glulxe/serial.cpp b/engines/glk/glulxe/serial.cpp
index d138027bdb..d485160302 100644
--- a/engines/glk/glulxe/serial.cpp
+++ b/engines/glk/glulxe/serial.cpp
@@ -232,7 +232,7 @@ uint Glulxe::perform_restoreundo() {
return res;
}
-uint Glulxe::perform_save(strid_t str) {
+Common::Error Glulxe::saveGameData(strid_t str, const Common::String &desc) {
dest_t dest;
int ix;
uint res, lx, val;
@@ -246,8 +246,8 @@ uint Glulxe::perform_save(strid_t str) {
fatal_error("Streams are only available in Glk I/O system.");
}
- if (str == 0)
- return 1;
+ if (str == nullptr)
+ return Common::kUnknownError;
dest.ismem = false;
dest.size = 0;
@@ -358,16 +358,17 @@ uint Glulxe::perform_save(strid_t str) {
/* All done. */
- return res;
+ return res ? Common::kUnknownError : Common::kNoError;
}
-uint Glulxe::perform_restore(strid_t str, int fromshell) {
+Common::Error Glulxe::loadGameData(strid_t str) {
dest_t dest;
int ix;
uint lx, res, val;
uint filestart, filelen = 0;
uint heapsumlen = 0;
uint *heapsumarr = nullptr;
+ bool fromshell = false;
/* If profiling is enabled and active then fail. */
#if VM_PROFILING
@@ -384,7 +385,7 @@ uint Glulxe::perform_restore(strid_t str, int fromshell) {
}
if (str == 0)
- return 1;
+ return Common::kUnknownError;
dest.ismem = false;
dest.size = 0;
@@ -402,7 +403,7 @@ uint Glulxe::perform_restore(strid_t str, int fromshell) {
}
if (res == 0 && val != IFFID('F', 'O', 'R', 'M')) {
/* ### bad header */
- return 1;
+ return Common::kUnknownError;
}
if (res == 0) {
res = read_long(&dest, &filelen);
@@ -414,7 +415,7 @@ uint Glulxe::perform_restore(strid_t str, int fromshell) {
}
if (res == 0 && val != IFFID('I', 'F', 'Z', 'S')) { /* ### ? */
/* ### bad header */
- return 1;
+ return Common::kUnknownError;
}
while (res == 0 && dest.pos < filestart + filelen) {
@@ -435,7 +436,7 @@ uint Glulxe::perform_restore(strid_t str, int fromshell) {
res = read_byte(&dest, &dummy);
if (res == 0 && Mem1(ix) != dummy) {
/* ### non-matching header */
- return 1;
+ return Common::kUnknownError;
}
}
} else if (chunktype == IFFID('C', 'M', 'e', 'm')) {
@@ -453,7 +454,7 @@ uint Glulxe::perform_restore(strid_t str, int fromshell) {
if (chunkstart + chunklen != dest.pos) {
/* ### funny chunk length */
- return 1;
+ return Common::kUnknownError;
}
if ((chunklen & 1) != 0) {
@@ -473,9 +474,9 @@ uint Glulxe::perform_restore(strid_t str, int fromshell) {
}
if (res)
- return 1;
+ return Common::kUnknownError;
- return 0;
+ return Common::kNoError;
}
int Glulxe::reposition_write(dest_t *dest, uint pos) {