aboutsummaryrefslogtreecommitdiff
path: root/engines/glk/alan2
diff options
context:
space:
mode:
authorPaul Gilbert2019-06-20 21:20:22 -0700
committerPaul Gilbert2019-06-22 14:40:49 -0700
commitad1cecaeac5d54b0973d6c7edce8181cb965ff68 (patch)
tree9ffc7a6a3f6e5e1e6f33ce997662a486fd122be4 /engines/glk/alan2
parentdf7465232108c15ca613db0b5e709e34378dbd8c (diff)
downloadscummvm-rg350-ad1cecaeac5d54b0973d6c7edce8181cb965ff68.tar.gz
scummvm-rg350-ad1cecaeac5d54b0973d6c7edce8181cb965ff68.tar.bz2
scummvm-rg350-ad1cecaeac5d54b0973d6c7edce8181cb965ff68.zip
GLK: ALAN2: Added savegame code
Diffstat (limited to 'engines/glk/alan2')
-rw-r--r--engines/glk/alan2/alan2.cpp69
-rw-r--r--engines/glk/alan2/alan2.h6
-rw-r--r--engines/glk/alan2/exe.h2
-rw-r--r--engines/glk/alan2/types.h12
4 files changed, 84 insertions, 5 deletions
diff --git a/engines/glk/alan2/alan2.cpp b/engines/glk/alan2/alan2.cpp
index c9625a7076..73b8a5e1a3 100644
--- a/engines/glk/alan2/alan2.cpp
+++ b/engines/glk/alan2/alan2.cpp
@@ -21,13 +21,15 @@
*/
#include "glk/alan2/alan2.h"
+#include "glk/alan2/exe.h"
#include "glk/alan2/main.h"
#include "glk/alan2/glkio.h"
+#include "common/system.h"
#include "common/config-manager.h"
#include "common/translation.h"
#include "common/error.h"
#include "common/scummsys.h"
-#include "common/system.h"
+#include "common/serializer.h"
#include "glk/glk.h"
#include "glk/streams.h"
@@ -75,13 +77,70 @@ void Alan2::initialize() {
}
Common::Error Alan2::readSaveData(Common::SeekableReadStream *rs) {
- // TODO
- return Common::kReadingFailed;
+ Common::Serializer s(rs, nullptr);
+ synchronizeSave(s);
+
+ return Common::kNoError;
}
Common::Error Alan2::writeGameData(Common::WriteStream *ws) {
- // TODO
- return Common::kWritingFailed;
+ Common::Serializer s(nullptr, ws);
+ synchronizeSave(s);
+
+ ws->flush();
+ return Common::kNoError;
+}
+
+void Alan2::synchronizeSave(Common::Serializer &s) {
+ AtrElem *atr;
+ int i;
+
+ // Sync current values
+ cur.synchronize(s);
+
+ // Save actors
+ for (i = ACTMIN; i <= ACTMAX; ++i) {
+ s.syncAsSint32LE(acts[i-ACTMIN].loc);
+ s.syncAsSint32LE(acts[i-ACTMIN].script);
+ s.syncAsSint32LE(acts[i-ACTMIN].step);
+ s.syncAsSint32LE(acts[i-ACTMIN].count);
+
+ if (acts[i-ACTMIN].atrs) {
+ for (atr = (AtrElem *)addrTo(acts[i-ACTMIN].atrs); !endOfTable(atr); ++atr)
+ s.syncAsSint32LE(atr->val);
+ }
+ }
+
+ // Sync locations
+ for (i = LOCMIN; i <= LOCMAX; ++i) {
+ s.syncAsSint32LE(locs[i-LOCMIN].describe);
+ if (locs[i-LOCMIN].atrs)
+ for (atr = (AtrElem *)addrTo(locs[i-LOCMIN].atrs); !endOfTable(atr); atr++)
+ s.syncAsSint32LE(atr->val);
+ }
+
+ // Sync objects
+ for (i = OBJMIN; i <= OBJMAX; ++i) {
+ s.syncAsSint32LE(objs[i-OBJMIN].loc);
+ if (objs[i-OBJMIN].atrs)
+ for (atr = (AtrElem *)addrTo(objs[i-OBJMIN].atrs); !endOfTable(atr); atr++)
+ s.syncAsSint32LE(atr->val);
+ }
+
+ // Sync the event queue
+ if (s.isSaving()) {
+ eventq[etop].time = 0; // Mark the top
+ for (i = 0; i <= etop; ++i)
+ eventq[i].synchronize(s);
+ } else {
+ for (etop = 0; eventq[etop - 1].time; ++etop)
+ eventq[etop].synchronize(s);
+ --etop;
+ }
+
+ // Sync scores
+ for (i = 0; scores[i] != EOF; i++)
+ s.syncAsSint32LE(scores[i]);
}
bool Alan2::is_gamefile_valid() {
diff --git a/engines/glk/alan2/alan2.h b/engines/glk/alan2/alan2.h
index 78c5107406..8960648dd7 100644
--- a/engines/glk/alan2/alan2.h
+++ b/engines/glk/alan2/alan2.h
@@ -24,6 +24,7 @@
#define GLK_ALAN2
#include "common/scummsys.h"
+#include "common/serializer.h"
#include "common/stack.h"
#include "glk/glk_api.h"
@@ -47,6 +48,11 @@ private:
* Initialization
*/
void initialize();
+
+ /**
+ * Synchronize data to or from a save file
+ */
+ void synchronizeSave(Common::Serializer &s);
public:
/**
* Constructor
diff --git a/engines/glk/alan2/exe.h b/engines/glk/alan2/exe.h
index 0acfdda6eb..fbecac5975 100644
--- a/engines/glk/alan2/exe.h
+++ b/engines/glk/alan2/exe.h
@@ -26,6 +26,8 @@
/* Header file for instruction execution unit in Alan interpreter
*/
+#include "glk/alan2/types.h"
+
namespace Glk {
namespace Alan2 {
diff --git a/engines/glk/alan2/types.h b/engines/glk/alan2/types.h
index 11a17a539d..699dd0e149 100644
--- a/engines/glk/alan2/types.h
+++ b/engines/glk/alan2/types.h
@@ -25,6 +25,8 @@
#include "glk/alan2/sysdep.h"
#include "glk/alan2/acode.h"
+#include "common/serializer.h"
+#include "common/stream.h"
namespace Glk {
namespace Alan2 {
@@ -89,6 +91,11 @@ struct CurVars {
tick,
score,
visits;
+
+ /**
+ * Read or write data to/from a save file
+ */
+ void synchronize(Common::Serializer &s);
};
#include "common/pack-start.h" // START STRUCT PACKING
@@ -246,6 +253,11 @@ struct EvtqElem { /* EVENT QUEUE ELEMENT */
int time;
int event;
int where;
+
+ /**
+ * Read or write data to/from a save file
+ */
+ void synchronize(Common::Serializer &s);
} PACKED_STRUCT;
struct IniElem { /* STRING INITIALISATION TABLE */