Skip to content

Commit

Permalink
DREAMWEB: Convert 'saveposition'
Browse files Browse the repository at this point in the history
Also inline and remove 'saveseg', 'savefilewrite', 'makeheader'.
  • Loading branch information
wjp committed Nov 26, 2011
1 parent de40ec5 commit c22ed1d
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 135 deletions.
4 changes: 4 additions & 0 deletions devtools/tasmrecover/tasm-recover
Expand Up @@ -293,6 +293,10 @@ generator = cpp(context, "DreamGen", blacklist = [
'actualsave',
'loadposition',
'saveposition',
'saveseg',
'openforsave',
'makeheader',
'savefilewrite',
], skip_output = [
# These functions are processed but not output
'dreamweb',
Expand Down
19 changes: 0 additions & 19 deletions engines/dreamweb/dreamgen.cpp
Expand Up @@ -11199,25 +11199,6 @@ void DreamGenContext::shownames() {
goto shownameloop;
}

void DreamGenContext::makeheader() {
STACK_CHECK;
dx = data;
es = dx;
di = 6141;
ax = 17;
storeit();
ax = (68-0);
storeit();
ax = (0+2080+30000+(16*114)+((114+2)*2)+18000);
storeit();
ax = (250)*4;
storeit();
ax = 48;
storeit();
ax = (991-534);
storeit();
}

void DreamGenContext::storeit() {
STACK_CHECK;
_cmp(ax, 0);
Expand Down
16 changes: 6 additions & 10 deletions engines/dreamweb/dreamgen.h
Expand Up @@ -43,7 +43,6 @@ class DreamGenContext : public Context {
static const uint16 addr_setkeyboardint = 0xcbac;
static const uint16 addr_readfromfile = 0xcba8;
static const uint16 addr_closefile = 0xcba4;
static const uint16 addr_openforsave = 0xcba0;
static const uint16 addr_openfilenocheck = 0xcb9c;
static const uint16 addr_openfilefromc = 0xcb94;
static const uint16 addr_openfile = 0xcb90;
Expand Down Expand Up @@ -138,12 +137,9 @@ class DreamGenContext : public Context {
static const uint16 addr_showdecisions = 0xc8bc;
static const uint16 addr_decide = 0xc8b8;
static const uint16 addr_scanfornames = 0xc8b4;
static const uint16 addr_saveseg = 0xc8ac;
static const uint16 addr_storeit = 0xc8a8;
static const uint16 addr_makeheader = 0xc8a4;
static const uint16 addr_loadseg = 0xc8a0;
static const uint16 addr_savefileread = 0xc894;
static const uint16 addr_savefilewrite = 0xc890;
static const uint16 addr_error = 0xc884;
static const uint16 addr_generalerror = 0xcbbc;
static const uint16 addr_dosreturn = 0xc880;
Expand Down Expand Up @@ -1265,7 +1261,7 @@ class DreamGenContext : public Context {
void slabdoorf();
//void loadintotemp();
void loadintroroom();
void saveseg();
//void saveseg();
//void showblink();
void mousecall();
void train();
Expand Down Expand Up @@ -1377,7 +1373,7 @@ class DreamGenContext : public Context {
void getridoftempcharset();
void heavy();
//void endpaltostart();
void showkeys();
//void makeheader();
void usekey();
void locklighton();
void useladderb();
Expand All @@ -1398,7 +1394,7 @@ class DreamGenContext : public Context {
//void showword();
void dirfile();
//void bresenhams();
//void walktotext();
//void savefilewrite();
void pickupconts();
void locklightoff();
void wearwatch();
Expand Down Expand Up @@ -1546,12 +1542,12 @@ class DreamGenContext : public Context {
void getundercentre();
void checkforexit();
void loadseg();
void makeheader();
void showkeys();
void setkeyboardint();
void priest();
//void readmouse();
//void addtopeoplelist();
void savefilewrite();
//void walktotext();
void printmessage2();
//void showallfree();
void loadnews();
Expand Down Expand Up @@ -1794,7 +1790,7 @@ class DreamGenContext : public Context {
void keeper();
void afternewroom();
void getexad();
void openforsave();
//void openforsave();
void closefile();
//void delcurs();
//void randomaccess();
Expand Down
124 changes: 32 additions & 92 deletions engines/dreamweb/saveload.cpp
Expand Up @@ -261,22 +261,15 @@ void DreamGenContext::savegame() {
madeUpRoom->b27 = 255;

// TODO: The below is copied from saveposition
makeheader();

//Common::String filename = ConfMan.getActiveDomainName() + Common::String::format(".d%02d", savegameId);
Common::String filename = Common::String::format("DREAMWEB.D%02d", savegameId);
debug(1, "Saving to filename: %s (%s)", filename.c_str(), game_description.c_str());

engine->openSaveFileForWriting(filename.c_str());

dx = data;
ds = dx;
dx = kFileheader;
cx = kHeaderlen;
savefilewrite();
dx = data;
es = dx;
di = kFiledata;
openforsave(savegameId);
// 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];
engine->writeToSaveFile(data.ptr(kFileheader, kHeaderlen), kHeaderlen);

// TODO: Check if this 2 is a constant
uint8 descbuf[17] = { 2, 0 };
Expand All @@ -288,38 +281,14 @@ void DreamGenContext::savegame() {
descbuf[++desclen] = 0;
while (desclen < 17)
descbuf[++desclen] = 1;
if (savegameId < 7) {
ax = savegameId;
cx = 17;
_mul(cx);
ds = data;
dx = kSavenames;
_add(dx, ax);
memcpy(data.ptr(dx,17), descbuf, 17);
saveseg();
} else {
// savenames only has room for descriptions for 7 slots
uint16 len = es.word(di);
_add(di, 2);
assert(len == 17);
engine->writeToSaveFile(descbuf, len);
}

ds = data;
dx = kStartvars;
saveseg();
ds = data.word(kExtras);
dx = kExframedata;
saveseg();
ds = data.word(kBuffers);
dx = kListofchanges;
saveseg();
ds = data;
dx = kMadeuproomdat;
saveseg();
ds = data;
dx = kReelroutines;
saveseg();
if (savegameId < 7)
memcpy(data.ptr(kSavenames + 17*savegameId, 17), descbuf, 17);
engine->writeToSaveFile(descbuf, len[0]);
engine->writeToSaveFile(data.ptr(kStartvars, len[1]), len[1]);
engine->writeToSaveFile(segRef(data.word(kExtras)).ptr(kExframedata, len[2]), len[2]);
engine->writeToSaveFile(segRef(data.word(kBuffers)).ptr(kListofchanges, len[3]), len[3]);
engine->writeToSaveFile(data.ptr(kMadeuproomdat, len[4]), len[4]);
engine->writeToSaveFile(data.ptr(kReelroutines, len[5]), len[5]);
closefile();

getridoftemp();
Expand Down Expand Up @@ -428,52 +397,23 @@ void DreamGenContext::actualload() {
}

void DreamGenContext::saveposition() {
STACK_CHECK;
makeheader();
al = data.byte(kCurrentslot);
ah = 0;
push(ax);
cx = 13;
_mul(cx);
dx = data;
ds = dx;
dx = 8698;
_add(dx, ax);
openforsave();
dx = data;
ds = dx;
dx = 6091;
cx = (6187-6091);
savefilewrite();
dx = data;
es = dx;
di = 6141;
ax = pop();
cx = 17;
_mul(cx);
dx = data;
ds = dx;
dx = 8579;
_add(dx, ax);
saveseg();
dx = data;
ds = dx;
dx = 0;
saveseg();
ds = data.word(kExtras);
dx = (0);
saveseg();
ds = data.word(kBuffers);
dx = (0+(228*13)+32+60+(32*32)+(11*10*3)+768+768+768+(32*32)+(128*5)+(80*5)+(100*5)+(12*5)+(46*40)+(5*80));
saveseg();
dx = data;
ds = dx;
dx = 7979;
saveseg();
dx = data;
ds = dx;
dx = 534;
saveseg();
unsigned int slot = data.byte(kCurrentslot);

openforsave(slot);

// 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];

engine->writeToSaveFile(data.ptr(kFileheader, kHeaderlen), kHeaderlen);
engine->writeToSaveFile(data.ptr(kSavenames + 17*slot, len[0]), len[0]);
engine->writeToSaveFile(data.ptr(kStartvars, len[1]), len[1]);
engine->writeToSaveFile(segRef(data.word(kExtras)).ptr(kExframedata, len[2]), len[2]);
engine->writeToSaveFile(segRef(data.word(kBuffers)).ptr(kListofchanges, len[3]), len[3]);
engine->writeToSaveFile(data.ptr(kMadeuproomdat, len[4]), len[4]);
engine->writeToSaveFile(data.ptr(kReelroutines, len[5]), len[5]);
closefile();
}

Expand Down
19 changes: 5 additions & 14 deletions engines/dreamweb/stubs.cpp
Expand Up @@ -406,10 +406,11 @@ void DreamGenContext::closefile() {
data.byte(kHandle) = 0;
}

void DreamGenContext::openforsave() {
const char *name = (const char *)ds.ptr(dx, 13);
debug(1, "openforsave(%s)", name);
engine->openSaveFileForWriting(name);
void DreamGenContext::openforsave(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, "openforsave(%s)", filename.c_str());
engine->openSaveFileForWriting(filename);
}

void DreamGenContext::openfilenocheck() {
Expand Down Expand Up @@ -721,16 +722,6 @@ void DreamGenContext::loadspeech() {
data.byte(kSpeechloaded) = 1;
}

void DreamGenContext::saveseg() {
cx = es.word(di);
_add(di, 2);
savefilewrite();
}

void DreamGenContext::savefilewrite() {
ax = engine->writeToSaveFile(ds.ptr(dx, cx), cx);
}

void DreamGenContext::savefileread() {
ax = engine->readFromSaveFile(ds.ptr(dx, cx), cx);
}
Expand Down
1 change: 1 addition & 0 deletions engines/dreamweb/stubs.h
Expand Up @@ -347,4 +347,5 @@
void actualload();
void loadposition();
void saveposition();
void openforsave(unsigned int slot);

0 comments on commit c22ed1d

Please sign in to comment.