diff options
author | Willem Jan Palenstijn | 2011-12-03 15:47:24 +0100 |
---|---|---|
committer | Willem Jan Palenstijn | 2011-12-03 15:47:33 +0100 |
commit | 15856843a49db4ca29c974ab071b3118528c93a7 (patch) | |
tree | 64226d793eee074cf10faf5a9d9e4ad281901c4c /engines/dreamweb | |
parent | 85c6efe5c544993724ba027022adebe6b08bf6be (diff) | |
download | scummvm-rg350-15856843a49db4ca29c974ab071b3118528c93a7.tar.gz scummvm-rg350-15856843a49db4ca29c974ab071b3118528c93a7.tar.bz2 scummvm-rg350-15856843a49db4ca29c974ab071b3118528c93a7.zip |
DREAMWEB: Create and use FileHeader struct
Diffstat (limited to 'engines/dreamweb')
-rw-r--r-- | engines/dreamweb/dreamweb.h | 4 | ||||
-rw-r--r-- | engines/dreamweb/saveload.cpp | 26 | ||||
-rw-r--r-- | engines/dreamweb/structs.h | 14 | ||||
-rw-r--r-- | engines/dreamweb/stubs.cpp | 12 |
4 files changed, 43 insertions, 13 deletions
diff --git a/engines/dreamweb/dreamweb.h b/engines/dreamweb/dreamweb.h index b20b4c9258..8181d04706 100644 --- a/engines/dreamweb/dreamweb.h +++ b/engines/dreamweb/dreamweb.h @@ -42,9 +42,7 @@ namespace DreamGen { -// TODO: Unsure if these values are constant or -// should be replaced with &backObject() and &mainMan() -// or some kind of enum... +// These are for ReelRoutine::reelPointer, which is a callback field. const uint16 addr_backobject = 0xc170; const uint16 addr_mainman = 0xc138; diff --git a/engines/dreamweb/saveload.cpp b/engines/dreamweb/saveload.cpp index 2e79d1dbed..79f6caeb31 100644 --- a/engines/dreamweb/saveload.cpp +++ b/engines/dreamweb/saveload.cpp @@ -321,13 +321,23 @@ void DreamGenContext::savePosition(unsigned int slot, const uint8 *descbuf) { openForSave(slot); + // Initialize new header + FileHeader header; + + // Note: _desc is not zero-terminated + const char *desc = "DREAMWEB DATA FILE COPYRIGHT 1992 CREATIVE REALITY"; + assert(strlen(desc) == sizeof(header._desc)); + memcpy(header._desc, desc, sizeof(header._desc)); + memset(&header._len[0], 0, sizeof(header._len)); + memset(&header._padding[0], 0, sizeof(header._padding)); + // fill length fields in savegame file header uint16 len[6] = { 17, kLengthofvars, kLengthofextra, 4*kNumchanges, 48, kLenofreelrouts }; for (int i = 0; i < 6; ++i) - data.word(kFiledata + 2*i) = len[i]; + header.setLen(i, len[i]); - engine->writeToSaveFile(data.ptr(kFileheader, kHeaderlen), kHeaderlen); + engine->writeToSaveFile((const uint8 *)&header, kHeaderlen); engine->writeToSaveFile(descbuf, len[0]); engine->writeToSaveFile(data.ptr(kStartvars, len[1]), len[1]); engine->writeToSaveFile(getSegment(data.word(kExtras)).ptr(kExframedata, len[2]), len[2]); @@ -343,12 +353,14 @@ void DreamGenContext::loadPosition(unsigned int slot) { openForLoad(slot); - engine->readFromSaveFile(cs.ptr(kFileheader, kHeaderlen), kHeaderlen); + FileHeader header; + + engine->readFromSaveFile((uint8 *)&header, kHeaderlen); // read segment lengths from savegame file header int len[6]; for (int i = 0; i < 6; ++i) - len[i] = cs.word(kFiledata + 2*i); + len[i] = header.len(i); if (len[0] != 17) ::error("Error loading save: description buffer isn't 17 bytes"); @@ -372,15 +384,17 @@ void DreamGenContext::loadPosition(unsigned int slot) { unsigned int DreamGenContext::scanForNames() { unsigned int count = 0; + FileHeader header; + for (unsigned int slot = 0; slot < 7; ++slot) { if (!openForLoad(slot)) continue; ++count; - engine->readFromSaveFile(cs.ptr(kFileheader, kHeaderlen), kHeaderlen); + engine->readFromSaveFile((uint8 *)&header, kHeaderlen); - if (cs.word(kFiledata) != 17) { + if (header.len(0) != 17) { ::warning("Error loading save: description buffer isn't 17 bytes"); closeFile(); continue; diff --git a/engines/dreamweb/structs.h b/engines/dreamweb/structs.h index 2440d182be..106b27ea84 100644 --- a/engines/dreamweb/structs.h +++ b/engines/dreamweb/structs.h @@ -262,3 +262,17 @@ struct Sound { uint8 b5; }; +struct FileHeader { + char _desc[50]; + uint16 _len[20]; + uint8 _padding[6]; + + uint16 len(unsigned int i) const { + assert(i < 20); + return READ_LE_UINT16(&_len[i]); + } + void setLen(unsigned int i, uint16 length) { + assert(i < 20); + WRITE_LE_UINT16(&_len[i], length); + } +}; diff --git a/engines/dreamweb/stubs.cpp b/engines/dreamweb/stubs.cpp index 4c36e5e1c5..4b3428e47d 100644 --- a/engines/dreamweb/stubs.cpp +++ b/engines/dreamweb/stubs.cpp @@ -580,9 +580,11 @@ uint8 *DreamGenContext::textUnder() { } uint16 DreamGenContext::standardLoad(const char *fileName) { + FileHeader header; + engine->openFile(fileName); - engine->readFromFile(cs.ptr(kFileheader, kHeaderlen), kHeaderlen); - uint16 sizeInBytes = cs.word(kFiledata); + engine->readFromFile((uint8 *)&header, kHeaderlen); + uint16 sizeInBytes = header.len(0); uint16 result = allocateMem((sizeInBytes + 15) / 16); engine->readFromFile(getSegment(result).ptr(0, 0), sizeInBytes); engine->closeFile(); @@ -2421,12 +2423,14 @@ void DreamGenContext::loadRoomData(const Room &room, bool skipDat) { engine->openFile(room.name); cs.word(kHandle) = 1; //only one handle flags._c = false; - readHeader(); + + FileHeader header; + engine->readFromFile((uint8 *)&header, kHeaderlen); // read segment lengths from room file header int len[15]; for (int i = 0; i < 15; ++i) - len[i] = cs.word(kFiledata + 2*i); + len[i] = header.len(i); data.word(kBackdrop) = allocateAndLoad(len[0]); clearAndLoad(data.word(kWorkspace), 0, len[1], 132*66); // 132*66 = maplen |