aboutsummaryrefslogtreecommitdiff
path: root/engines/glk/agt
diff options
context:
space:
mode:
authorPaul Gilbert2019-11-27 21:04:29 -0800
committerPaul Gilbert2019-11-27 21:10:29 -0800
commitc3dbc2c40f68aebf04fa76cbb225bf81f43a8c41 (patch)
tree79425ed4970a5930b8cec5537eee06ddbf940d35 /engines/glk/agt
parent43579347eb7b852fb947f44d30e95450fd247936 (diff)
downloadscummvm-rg350-c3dbc2c40f68aebf04fa76cbb225bf81f43a8c41.tar.gz
scummvm-rg350-c3dbc2c40f68aebf04fa76cbb225bf81f43a8c41.tar.bz2
scummvm-rg350-c3dbc2c40f68aebf04fa76cbb225bf81f43a8c41.zip
GLK: AGT: Route savegames through the engine
Diffstat (limited to 'engines/glk/agt')
-rw-r--r--engines/glk/agt/agil.cpp8
-rw-r--r--engines/glk/agt/agt.cpp7
-rw-r--r--engines/glk/agt/interface.cpp2
-rw-r--r--engines/glk/agt/interp.h4
-rw-r--r--engines/glk/agt/runverb.cpp2
-rw-r--r--engines/glk/agt/savegame.cpp55
-rw-r--r--engines/glk/agt/util.cpp3
7 files changed, 43 insertions, 38 deletions
diff --git a/engines/glk/agt/agil.cpp b/engines/glk/agt/agil.cpp
index b1fbcb7c2c..23bc2fb652 100644
--- a/engines/glk/agt/agil.cpp
+++ b/engines/glk/agt/agil.cpp
@@ -494,7 +494,7 @@ static void game_end(void) {
done_flag = 1;
} else writeln("Sorry, I'm unable to do that because of limited memory.");
else if (strncasecmp(s, "RESTORE", 7) == 0)
- if (loadgame()) {
+ if (g_vm->loadGame().getCode() == Common::kNoError) {
done_flag = 1;
} else writeln("(RESTORE failed)");
else if (strncasecmp(s, "UNDO", 4) == 0)
@@ -556,8 +556,10 @@ static void mainloop(void) {
} else
menu_cmd();
if (doing_restore) {
- if (doing_restore == 1) loadgame();
- else if (doing_restore == 2) restart_game();
+ if (doing_restore == 1)
+ g_vm->loadGame();
+ else if (doing_restore == 2)
+ restart_game();
else if (doing_restore == 3 || doing_restore == 4)
return; /* Quit or New game requested */
doing_restore = 0;
diff --git a/engines/glk/agt/agt.cpp b/engines/glk/agt/agt.cpp
index 1f0766f794..37d1d77846 100644
--- a/engines/glk/agt/agt.cpp
+++ b/engines/glk/agt/agt.cpp
@@ -23,6 +23,9 @@
#include "glk/agt/agt.h"
#include "glk/quetzal.h"
#include "common/config-manager.h"
+#include "glk/agt/agility.h"
+#include "glk/agt/interp.h"
+#include "glk/agt/exec.h"
namespace Glk {
namespace AGT {
@@ -93,11 +96,11 @@ void AGT::initializeSettings() {
}
Common::Error AGT::readSaveData(Common::SeekableReadStream *rs) {
- return Common::kReadingFailed;
+ return loadgame(rs);
}
Common::Error AGT::writeGameData(Common::WriteStream *ws) {
- return Common::kWritingFailed;
+ return savegame(ws);
}
} // End of namespace AGT
diff --git a/engines/glk/agt/interface.cpp b/engines/glk/agt/interface.cpp
index 75763d3fb0..1e4debd7e0 100644
--- a/engines/glk/agt/interface.cpp
+++ b/engines/glk/agt/interface.cpp
@@ -1000,7 +1000,7 @@ void replay(int delay) {
/* They're never called from the rest of the code */
void agt_save(void) {
- savegame();
+ g_vm->saveGame();
}
void agt_restore(void) {
diff --git a/engines/glk/agt/interp.h b/engines/glk/agt/interp.h
index 9bf5d65dcb..3794a09794 100644
--- a/engines/glk/agt/interp.h
+++ b/engines/glk/agt/interp.h
@@ -435,8 +435,8 @@ extern void debug_newline(integer op, rbool first_nl);
/* -------------------------------------------------------------------- */
/* In SAVEGAME.C */
/* -------------------------------------------------------------------- */
-extern void savegame(void);
-extern rbool loadgame(void);
+extern Common::Error savegame(Common::WriteStream *savefile);
+extern Common::Error loadgame(Common::SeekableReadStream *loadfile);
extern void init_state_sys(void); /* Must be called before either of the following */
extern uchar *getstate(uchar *gs);
/* Returns malloc'd block containing game state. */
diff --git a/engines/glk/agt/runverb.cpp b/engines/glk/agt/runverb.cpp
index 9f2144deb4..4ee3fa5c46 100644
--- a/engines/glk/agt/runverb.cpp
+++ b/engines/glk/agt/runverb.cpp
@@ -1393,7 +1393,7 @@ void exec_verb(void)
break;
case 45:
cmd_saveable = 0;
- savegame();
+ g_vm->saveGame();
break;
case 46:
cmd_saveable = 0;
diff --git a/engines/glk/agt/savegame.cpp b/engines/glk/agt/savegame.cpp
index 68285d2575..65c4ed9c95 100644
--- a/engines/glk/agt/savegame.cpp
+++ b/engines/glk/agt/savegame.cpp
@@ -21,9 +21,9 @@
*/
-#include "agility.h"
-#include "interp.h"
-#include "exec.h"
+#include "glk/agt/agility.h"
+#include "glk/agt/interp.h"
+#include "glk/agt/exec.h"
namespace Glk {
namespace AGT {
@@ -337,8 +337,7 @@ void init_state_sys(void)
/*-------------------------------------------------------------------*/
/* SAVE FILE ROUTINES */
-void savegame(void) {
- genfile savefile;
+extern Common::Error savegame(Common::WriteStream *savefile) {
uchar *gs;
long size;
@@ -349,50 +348,49 @@ void savegame(void) {
#endif
if (gs == NULL) {
writeln("Insufficiant memory to support SAVE.");
- return;
+ return Common::kWritingFailed;
}
- savefile = get_user_file(1);
+
if (!filevalid(savefile, fSAV)) {
writeln("That is not a valid save file.");
- return;
+ return Common::kWritingFailed;
}
size = gs[0] + (((long)gs[1]) << 8) + (((long)gs[2]) << 16) + (((long)gs[3]) << 24);
- if (!binwrite(savefile, gs, size, 1, 0))
- writeln("Error writing save file.");
+ bool result = binwrite(savefile, gs, size, 1, 0);
#ifndef UNDO_SAVE
rfree(gs);
#endif
- writeclose(savefile, NO_FILE_ID);
+ if (!result) {
+ warning("Error writing save file.");
+ return Common::kWritingFailed;
+ } else {
+ return Common::kNoError;
+ }
}
-
-rbool loadgame(void)
/* 1=success, 0=failure */
-{
- genfile loadfile;
+Common::Error loadgame(Common::SeekableReadStream *loadfile) {
long size;
uchar *gs;
const char *errstr;
- loadfile = get_user_file(2);
if (!filevalid(loadfile, fSAV)) {
- writeln("Unable to open file.");
- return 0;
+ warning("Unable to open file.");
+ return Common::kReadingFailed;
}
size = binsize(loadfile);
if (size == -1) {
- writeln("Could not access file.");
- readclose(loadfile);
- return 0;
+ warning("Could not access file.");
+ return Common::kReadingFailed;
}
+
gs = (uchar *)rmalloc(size);
if (!binread(loadfile, gs, size, 1, &errstr)) {
- writeln("Error reading file.");
+ warning("Error reading file.");
rfree(gs);
- readclose(loadfile);
- return 0;
+ return Common::kReadingFailed;
}
- readclose(loadfile);
+
if (size != gs[0] + (((long)gs[1]) << 8) + (((long)gs[2]) << 16) + (((long)gs[3]) << 24)) {
if (size == gs[0] + (((long)gs[1]) << 8)) {
/* Old save file format; patch to look like new format */
@@ -400,16 +398,17 @@ rbool loadgame(void)
memmove(gs + 4, gs + 2, size - 2);
gs[2] = gs[3] = 0;
} else {
- writeln("Save file corrupted or invalid.");
+ warning("Save file corrupted or invalid.");
rfree(gs);
- return 0;
+ return Common::kReadingFailed;
}
}
+
putstate(gs);
rfree(gs);
set_statline();
look_room();
- return 1;
+ return Common::kNoError;
}
void restart_game(void) {
diff --git a/engines/glk/agt/util.cpp b/engines/glk/agt/util.cpp
index c91e47a74f..47900fc74e 100644
--- a/engines/glk/agt/util.cpp
+++ b/engines/glk/agt/util.cpp
@@ -376,7 +376,8 @@ size_t fread(void *ptr, size_t size, size_t nmemb, genfile stream) {
size_t fwrite(const void *ptr, size_t size, size_t nmemb, genfile stream) {
Common::WriteStream *ws = dynamic_cast<Common::WriteStream *>(stream);
assert(ws);
- return ws->write(ptr, size * nmemb);
+ size_t bytesWritten = ws->write(ptr, size * nmemb);
+ return bytesWritten / size;
}
size_t ftell(genfile f) {