aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/dreamweb/saveload.cpp75
-rw-r--r--engines/dreamweb/stubs.cpp8
-rw-r--r--engines/dreamweb/stubs.h4
3 files changed, 33 insertions, 54 deletions
diff --git a/engines/dreamweb/saveload.cpp b/engines/dreamweb/saveload.cpp
index b74fd68d0c..2e79d1dbed 100644
--- a/engines/dreamweb/saveload.cpp
+++ b/engines/dreamweb/saveload.cpp
@@ -368,54 +368,33 @@ void DreamGenContext::loadPosition(unsigned int slot) {
closeFile();
}
-void DreamGenContext::scanForNames() {
- STACK_CHECK;
- dx = data;
- es = dx;
- di = 8579;
- dx = data;
- ds = dx;
- dx = 8698;
- cx = 7;
-scanloop:
- push(es);
- push(ds);
- push(di);
- push(dx);
- push(cx);
- openFileFromC();
- if (flags.c())
- goto notexist;
- cx = pop();
- _inc(ch);
- push(cx);
- push(di);
- push(es);
- dx = data;
- ds = dx;
- dx = 6091;
- cx = (6187-6091);
- saveFileRead();
- dx = data;
- es = dx;
- di = 6141;
- ds = pop();
- dx = pop();
- loadSeg();
- bx = data.word(kHandle);
- closeFile();
-notexist:
- cx = pop();
- dx = pop();
- di = pop();
- ds = pop();
- es = pop();
- _add(dx, 13);
- _add(di, 17);
- _dec(cl);
- if (!flags.z())
- goto scanloop;
- al = ch;
+// Count number of save files, and load their descriptions into kSavenames
+unsigned int DreamGenContext::scanForNames() {
+ unsigned int count = 0;
+
+ for (unsigned int slot = 0; slot < 7; ++slot) {
+
+ if (!openForLoad(slot)) continue;
+
+ ++count;
+
+ engine->readFromSaveFile(cs.ptr(kFileheader, kHeaderlen), kHeaderlen);
+
+ if (cs.word(kFiledata) != 17) {
+ ::warning("Error loading save: description buffer isn't 17 bytes");
+ closeFile();
+ continue;
+ }
+
+ // NB: Only possible if slot < 7
+ engine->readFromSaveFile(data.ptr(kSavenames + 17*slot, 17), 17);
+
+ closeFile();
+ }
+
+ al = (uint8)count;
+
+ return count;
}
} /*namespace dreamgen */
diff --git a/engines/dreamweb/stubs.cpp b/engines/dreamweb/stubs.cpp
index 6dec0c1325..4c36e5e1c5 100644
--- a/engines/dreamweb/stubs.cpp
+++ b/engines/dreamweb/stubs.cpp
@@ -335,7 +335,7 @@ void DreamGenContext::dreamweb() {
while (true) {
- scanForNames();
+ unsigned int count = scanForNames();
bool startNewGame = true;
@@ -354,7 +354,7 @@ void DreamGenContext::dreamweb() {
fadeScreenUp();
startNewGame = false;
- } else if (al == 0 && firstLoop) {
+ } else if (count == 0 && firstLoop) {
// no savegames found, and we're not restarting.
@@ -687,11 +687,11 @@ void DreamGenContext::openForSave(unsigned int slot) {
engine->openSaveFileForWriting(filename);
}
-void DreamGenContext::openForLoad(unsigned int slot) {
+bool DreamGenContext::openForLoad(unsigned int slot) {
//Common::String filename = ConfMan.getActiveDomainName() + Common::String::format(".d%02d", savegameId);
Common::String filename = Common::String::format("DREAMWEB.D%02d", slot);
debug(1, "openForLoad(%s)", filename.c_str());
- engine->openSaveFileForReading(filename);
+ return engine->openSaveFileForReading(filename);
}
void DreamGenContext::openFileNoCheck() {
diff --git a/engines/dreamweb/stubs.h b/engines/dreamweb/stubs.h
index ea990d69a7..c8532f82d4 100644
--- a/engines/dreamweb/stubs.h
+++ b/engines/dreamweb/stubs.h
@@ -350,7 +350,7 @@
void loadPosition(unsigned int slot);
void savePosition(unsigned int slot, const uint8 *descbuf);
void openForSave(unsigned int slot);
- void openForLoad(unsigned int slot);
+ bool openForLoad(unsigned int slot);
uint16 allocateAndLoad(unsigned int size);
void clearAndLoad(uint16 seg, uint8 c, unsigned int size, unsigned int maxSize);
void loadRoomData(const Room &room, bool skipDat);
@@ -403,5 +403,5 @@
bool isItRight(uint8 digit0, uint8 digit1, uint8 digit2, uint8 digit3);
void enterCode(uint8 digit0, uint8 digit1, uint8 digit2, uint8 digit3);
void enterCode();
- void scanForNames();
+ unsigned int scanForNames();