aboutsummaryrefslogtreecommitdiff
path: root/saveload.cpp
diff options
context:
space:
mode:
authorJames Brown2002-03-14 14:45:04 +0000
committerJames Brown2002-03-14 14:45:04 +0000
commitd8adad386fd4a59b484534e48be5739705b65897 (patch)
tree9489f4f07b4393adfdb841fc6448f17cf4285253 /saveload.cpp
parentd8ca3d29875813733996c079147a092fd3ead359 (diff)
downloadscummvm-rg350-d8adad386fd4a59b484534e48be5739705b65897.tar.gz
scummvm-rg350-d8adad386fd4a59b484534e48be5739705b65897.tar.bz2
scummvm-rg350-d8adad386fd4a59b484534e48be5739705b65897.zip
winCE part 2 - still gui.cpp and scummvm.cpp left
svn-id: r3752
Diffstat (limited to 'saveload.cpp')
-rw-r--r--saveload.cpp227
1 files changed, 224 insertions, 3 deletions
diff --git a/saveload.cpp b/saveload.cpp
index b28c5a29bf..6eb17e6b0f 100644
--- a/saveload.cpp
+++ b/saveload.cpp
@@ -30,8 +30,24 @@ struct SaveGameHeader {
char name[32];
};
+#ifdef _WIN32_WCE
+
+// Support for "old" savegames (made with 2501 CVS build)
+// Can be useful for other ports too :)
+
+#define VER_V8 8
+#define VER_V7 7
+
+#define CURRENT_VER VER_V8
+
+static uint32 _current_version = CURRENT_VER;
+
+#else
+
#define CURRENT_VER 7
+#endif
+
bool Scumm::saveState(int slot, bool compat) {
char filename[256];
SerializerStream out;
@@ -47,7 +63,16 @@ bool Scumm::saveState(int slot, bool compat) {
hdr.type = MKID('SCVM');
hdr.size = 0;
+
+#ifdef _WIN32_WCE
+
+ hdr.ver = _current_version;
+
+#else
+
hdr.ver = CURRENT_VER;
+
+#endif
out.fwrite(&hdr, sizeof(hdr), 1);
@@ -79,12 +104,27 @@ bool Scumm::loadState(int slot, bool compat) {
return false;
}
+#ifdef _WIN32_WCE
+
+ if (hdr.ver != VER_V8 && hdr.ver != VER_V7) {
+
+#else
+
if (hdr.ver != CURRENT_VER) {
+
+#endif
+
warning("Invalid version of '%s'", filename);
out.fclose();
return false;
}
+#ifdef _WIN32_WCE
+
+ _current_version = hdr.ver;
+
+#endif
+
memcpy(_saveLoadName, hdr.name, sizeof(hdr.name));
pauseSounds(true);
@@ -144,14 +184,24 @@ bool Scumm::loadState(int slot, bool compat) {
}
void Scumm::makeSavegameName(char *out, int slot, bool compatible) {
+
+#ifndef _WIN32_WCE
+
#if !defined(__APPLE__CW)
const char *dir = getenv("SCUMMVM_SAVEPATH");
if (dir==NULL) dir="";
#else
const char *dir = "";
#endif
+
/* snprintf should be used here, but it's not portable enough */
sprintf(out, "%s%s.%c%.2d", dir, _exe_name, compatible ? 'c': 's', slot);
+
+#else
+
+ sprintf(out, "%s%s.%c%.2d", _savegame_dir, _exe_name, compatible ? 'c': 's', slot);
+
+#endif
}
bool Scumm::getSavegameName(int slot, char *desc) {
@@ -172,8 +222,17 @@ bool Scumm::getSavegameName(int slot, char *desc) {
strcpy(desc, "Invalid savegame");
return false;
}
-
- if (hdr.ver != CURRENT_VER) {
+
+#ifdef _WIN32_WCE
+
+ if (hdr.ver != VER_V8 && hdr.ver != VER_V7) {
+
+#else
+
+ if (hdr.ver != CURRENT_VER) {
+
+#endif
+
strcpy(desc, "Invalid version");
return false;
}
@@ -306,7 +365,130 @@ void Scumm::saveOrLoad(Serializer *s) {
MKEND()
};
- const SaveLoadEntry mainEntries[] = {
+#ifdef _WIN32_WCE
+
+ const SaveLoadEntry mainEntries1[] = {
+ MKLINE(Scumm,_scrWidth,sleUint16),
+ MKLINE(Scumm,_scrHeight,sleUint16),
+ MKLINE(Scumm,_ENCD_offs,sleUint32),
+ MKLINE(Scumm,_EXCD_offs,sleUint32),
+ MKLINE(Scumm,_IM00_offs,sleUint32),
+ MKLINE(Scumm,_CLUT_offs,sleUint32),
+ MKLINE(Scumm,_EPAL_offs,sleUint32),
+ MKLINE(Scumm,_PALS_offs,sleUint32),
+ MKLINE(Scumm,_curPalIndex,sleByte),
+ MKLINE(Scumm,_currentRoom,sleByte),
+ MKLINE(Scumm,_roomResource,sleByte),
+ MKLINE(Scumm,_numObjectsInRoom,sleByte),
+ MKLINE(Scumm,_currentScript,sleByte),
+ MKARRAY(Scumm,_localScriptList[0],sleUint32,NUM_LOCALSCRIPT),
+ MKARRAY(Scumm,vm.localvar[0][0],sleUint16,NUM_SCRIPT_SLOT*17),
+ MKARRAY(Scumm,_resourceMapper[0],sleByte,128),
+ MKARRAY(Scumm,charset._colorMap[0],sleByte,16),
+ MKARRAY(Scumm,_charsetData[0][0],sleByte,10*16),
+ MKLINE(Scumm,_curExecScript,sleUint16),
+ MKEND()
+ };
+
+ const SaveLoadEntry mainEntries2V8[] = {
+
+ MKLINE(Scumm,camera._dest.x,sleInt16),
+ MKLINE(Scumm,camera._dest.y,sleInt16),
+ MKLINE(Scumm,camera._cur.x,sleInt16),
+ MKLINE(Scumm,camera._cur.y,sleInt16),
+ MKLINE(Scumm,camera._last.x,sleInt16),
+ MKLINE(Scumm,camera._last.y,sleInt16),
+ MKLINE(Scumm,camera._accel.x,sleInt16),
+ MKLINE(Scumm,camera._accel.y,sleInt16),
+ MKLINE(Scumm,_screenStartStrip,sleInt16),
+ MKLINE(Scumm,_screenEndStrip,sleInt16),
+ MKLINE(Scumm,camera._mode,sleByte),
+ MKLINE(Scumm,camera._follows,sleByte),
+ MKLINE(Scumm,camera._leftTrigger,sleInt16),
+ MKLINE(Scumm,camera._rightTrigger,sleInt16),
+ MKLINE(Scumm,camera._movingToActor,sleUint16),
+ MKEND()
+ };
+
+ const SaveLoadEntry mainEntries2V7[] = {
+ MKLINE(Scumm,camera._dest.x,sleInt16),
+ MKLINE(Scumm,camera._cur.x,sleInt16),
+ MKLINE(Scumm,camera._last.x,sleInt16),
+ MKLINE(Scumm,_screenStartStrip,sleInt16),
+ MKLINE(Scumm,_screenEndStrip,sleInt16),
+ MKLINE(Scumm,camera._mode,sleByte),
+ MKLINE(Scumm,camera._follows,sleByte),
+ MKLINE(Scumm,camera._leftTrigger,sleInt16),
+ MKLINE(Scumm,camera._rightTrigger,sleInt16),
+ MKLINE(Scumm,camera._movingToActor,sleUint16),
+ MKEND()
+ };
+
+ const SaveLoadEntry mainEntries3[] = {
+
+ MKLINE(Scumm,_actorToPrintStrFor,sleByte),
+ MKLINE(Scumm,_charsetColor,sleByte),
+ /* XXX Convert into word next time format changes */
+ MKLINE(Scumm,charset._bufPos,sleByte),
+ MKLINE(Scumm,_haveMsg,sleByte),
+ MKLINE(Scumm,_useTalkAnims,sleByte),
+
+ MKLINE(Scumm,_talkDelay,sleInt16),
+ MKLINE(Scumm,_defaultTalkDelay,sleInt16),
+ MKLINE(Scumm,_numInMsgStack,sleInt16),
+ MKLINE(Scumm,_sentenceNum,sleByte),
+
+ MKLINE(Scumm,vm.cutSceneStackPointer,sleByte),
+ MKARRAY(Scumm,vm.cutScenePtr[0],sleUint32,5),
+ MKARRAY(Scumm,vm.cutSceneScript[0],sleByte,5),
+ MKARRAY(Scumm,vm.cutSceneData[0],sleInt16,5),
+ MKLINE(Scumm,vm.cutSceneScriptIndex,sleInt16),
+
+ /* nest */
+ MKLINE(Scumm,_numNestedScripts,sleByte),
+ MKLINE(Scumm,_userPut,sleByte),
+ MKLINE(Scumm,_cursorState,sleByte),
+ MKLINE(Scumm,gdi._cursorActive,sleByte),
+ MKLINE(Scumm,gdi._currentCursor,sleByte),
+
+ MKLINE(Scumm,_doEffect,sleByte),
+ MKLINE(Scumm,_switchRoomEffect,sleByte),
+ MKLINE(Scumm,_newEffect,sleByte),
+ MKLINE(Scumm,_switchRoomEffect2,sleByte),
+ MKLINE(Scumm,_BgNeedsRedraw,sleByte),
+
+ MKARRAY(Scumm,gfxUsageBits[0],sleUint32,200),
+ MKLINE(Scumm,gdi._transparency,sleByte),
+ MKARRAY(Scumm,_currentPalette[0],sleByte,768),
+ /* virtscr */
+
+ MKARRAY(Scumm,charset._buffer[0],sleByte,256),
+
+ MKLINE(Scumm,_egoPositioned,sleByte),
+
+ MKARRAY(Scumm,gdi._imgBufOffs[0],sleUint16,4),
+ MKLINE(Scumm,gdi._numZBuffer,sleByte),
+
+ MKLINE(Scumm,_screenEffectFlag,sleByte),
+
+ MKLINE(Scumm,_randSeed1,sleUint32),
+ MKLINE(Scumm,_randSeed2,sleUint32),
+
+ /* XXX: next time the save game format changes,
+ * convert _shakeEnabled to boolean and add a _shakeFrame field */
+ MKLINE(Scumm,_shakeEnabled,sleInt16),
+
+ MKLINE(Scumm,_keepText,sleByte),
+
+ MKLINE(Scumm,_screenB,sleUint16),
+ MKLINE(Scumm,_screenH,sleUint16),
+
+ MKEND()
+ };
+
+#else
+
+ const SaveLoadEntry mainEntries[] = {
MKLINE(Scumm,_scrWidth,sleUint16),
MKLINE(Scumm,_scrHeight,sleUint16),
MKLINE(Scumm,_ENCD_offs,sleUint32),
@@ -403,6 +585,8 @@ void Scumm::saveOrLoad(Serializer *s) {
MKEND()
};
+#endif
+
const SaveLoadEntry scriptSlotEntries[] = {
MKLINE(ScriptSlot,offs,sleUint32),
MKLINE(ScriptSlot,delay,sleInt32),
@@ -468,9 +652,30 @@ void Scumm::saveOrLoad(Serializer *s) {
int var120Backup;
int var98Backup;
+#ifdef _WIN32_WCE
+
+ s->saveLoadEntries(this, mainEntries1);
+ s->saveLoadEntries(this, (_current_version == VER_V8 ? mainEntries2V8 : mainEntries2V7));
+ s->saveLoadEntries(this, mainEntries3);
+
+#else
+
s->saveLoadEntries(this,mainEntries);
+#endif
+
+#ifdef _WIN32_WCE
+
+ // Probably not necessary anymore with latest NUM_ACTORS values
+
+ s->saveLoadArrayOf(actor, (_current_version == VER_V8 ? NUM_ACTORS : 13), sizeof(actor[0]), actorEntries);
+
+#else
+
s->saveLoadArrayOf(actor, NUM_ACTORS, sizeof(actor[0]), actorEntries);
+
+#endif
+
s->saveLoadArrayOf(vm.slot, NUM_SCRIPT_SLOT, sizeof(vm.slot[0]), scriptSlotEntries);
s->saveLoadArrayOf(_objs, _numLocalObjects, sizeof(_objs[0]), objectEntries);
s->saveLoadArrayOf(_verbs, _numVerbs, sizeof(_verbs[0]), verbEntries);
@@ -570,6 +775,22 @@ void Serializer::saveLoadBytes(void *b, int len) {
_saveLoadStream.fread(b, 1, len);
}
+#ifdef _WIN32_WCE
+
+// Perhaps not necessary anymore with latest checks
+
+bool Serializer::checkEOFLoadStream() {
+ if (!fseek(_saveLoadStream.out, 1, SEEK_CUR))
+ return true;
+ if (feof(_saveLoadStream.out))
+ return true;
+ fseek(_saveLoadStream.out, -1, SEEK_CUR);
+ return false;
+}
+
+#endif
+
+
void Serializer::saveUint32(uint32 d) {
uint32 e = FROM_LE_32(d);
saveLoadBytes(&e,4);