Skip to content

Commit

Permalink
DREAMWEB: Convert getObTextStart
Browse files Browse the repository at this point in the history
  • Loading branch information
wjp committed Dec 24, 2011
1 parent 0133ca8 commit b983963
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 64 deletions.
2 changes: 2 additions & 0 deletions devtools/tasmrecover/tasm-recover
Expand Up @@ -479,6 +479,7 @@ generator = cpp(context, "DreamGen", blacklist = [
'getnamepos',
'getnextword',
'getnumber',
'getobtextstart',
'getopenedsize',
'getpersframe',
'getreelframeax',
Expand Down Expand Up @@ -748,6 +749,7 @@ generator = cpp(context, "DreamGen", blacklist = [
'saveposition',
'saveseg',
'scanfornames',
'scanforsame',
'screenupdate',
'scrollmonitor',
'security',
Expand Down
1 change: 1 addition & 0 deletions engines/dreamweb/dreambase.h
Expand Up @@ -188,6 +188,7 @@ class DreamBase : public SegmentManager {
void deleteExFrame(uint8 frameNum);
void deleteExText(uint8 textNum);
void purgeALocation(uint8 index);
const uint8 *getObTextStart();

// from pathfind.cpp
void turnPathOn(uint8 param);
Expand Down
47 changes: 0 additions & 47 deletions engines/dreamweb/dreamgen.cpp
Expand Up @@ -284,53 +284,6 @@ void DreamGenContext::findAllOpen() {
goto findopen1a;
}

void DreamGenContext::getObTextStart() {
STACK_CHECK;
es = data.word(kFreedesc);
si = (0);
cx = (0+(82*2));
_cmp(data.byte(kObjecttype), 2);
if (flags.z())
goto describe;
es = data.word(kSetdesc);
si = (0);
cx = (0+(130*2));
_cmp(data.byte(kObjecttype), 1);
if (flags.z())
goto describe;
es = data.word(kExtras);
si = (0+2080+30000+(16*114));
cx = (0+2080+30000+(16*114)+((114+2)*2));
describe:
al = data.byte(kCommand);
ah = 0;
_add(ax, ax);
_add(si, ax);
ax = es.word(si);
_add(ax, cx);
si = ax;
bx = ax;
tryagain:
push(si);
findNextColon();
al = es.byte(si);
cx = si;
si = pop();
_cmp(data.byte(kObjecttype), 1);
if (!flags.z())
return /* (cantmakeoneup) */;
_cmp(al, 0);
if (flags.z())
goto findsometext;
_cmp(al, ':');
if (flags.z())
goto findsometext;
return;
findsometext:
searchForSame();
goto tryagain;
}

void DreamGenContext::searchForSame() {
STACK_CHECK;
si = cx;
Expand Down
1 change: 0 additions & 1 deletion engines/dreamweb/dreamgen.h
Expand Up @@ -455,7 +455,6 @@ class DreamGenContext : public DreamBase, public Context {
#include "stubs.h" // Allow hand-reversed functions to have a signature different than void f()

void getPersonText();
void getObTextStart();
void checkObjectSize();
void doSomeTalk();
void outOfOpen();
Expand Down
69 changes: 69 additions & 0 deletions engines/dreamweb/object.cpp
Expand Up @@ -636,4 +636,73 @@ void DreamBase::purgeALocation(uint8 index) {
}
}

const uint8 *DreamBase::getObTextStart() {
uint16 textSeg, textDatOff, textOff;
if (data.byte(kObjecttype) == kFreeObjectType) {
textSeg = data.word(kFreedesc);
textDatOff = kFreetextdat;
textOff = kFreetext;
} else if (data.byte(kObjecttype) == kSetObjectType1) {
textSeg = data.word(kSetdesc);
textDatOff = kSettextdat;
textOff = kSettext;
} else {
textSeg = data.word(kExtras);
textDatOff = kExtextdat;
textOff = kExtext;
}
const uint8 *textBase = getSegment(textSeg).ptr(textOff, 0);
const uint8 *text = textBase + getSegment(textSeg).word(textDatOff + 2*data.byte(kCommand));

if (data.byte(kObjecttype) != kSetObjectType1)
return text;

const uint8 *obname = text;
while (true) {
const uint8 *start = text;
findNextColon(&text);

// Not an empty description string?
if (*text != 0 && *text != ':')
return start;

// If the description string (of a SetObjectType1 object) is empty,
// look for an object with the same name.
// Example: Eden's garage door outside has two parts. The right part
// has no description of its own but uses that of the left part.

bool found = false;
do {
text++;
uint8 c = *obname;

// scan for matching first character
while (*text != c) {
text++;

// arbitrary give-up counter
if (text - (textBase - textOff) >= 8000) {
warning("Object description for %d/%d not found", data.byte(kObjecttype), data.byte(kCommand));
return obname;
}
}

// found matching first character, so match the rest
const uint8 *s1 = obname;
const uint8 *s2 = text;
do {
s1++;
s2++;
} while (*s1 != ':' && *s1 != 0 && *s1 == *s2);

if (*s1 == ':' || *s1 == 0)
found = true; // (prefix) matched the entire object name
} while (!found);

// We found an object with the same name. The next loop iteration
// will check if this one again has an empty description.
}
}


} // End of namespace DreamGen
14 changes: 2 additions & 12 deletions engines/dreamweb/stubs.cpp
Expand Up @@ -1875,16 +1875,6 @@ uint8 DreamBase::findNextColon(const uint8 **string) {
return c;
}

const uint8 *DreamGenContext::getObTextStartCPP() {
push(es);
push(si);
getObTextStart();
const uint8 *result = es.ptr(si, 0);
si = pop();
es = pop();
return result;
}

void DreamGenContext::enterSymbol() {
data.byte(kManisoffscreen) = 1;
getRidOfReels();
Expand Down Expand Up @@ -2906,7 +2896,7 @@ void DreamGenContext::obsThatDoThings() {
}

void DreamGenContext::describeOb() {
const uint8 *obText = getObTextStartCPP();
const uint8 *obText = getObTextStart();
uint16 y = 92;
if (data.byte(kForeignrelease) && data.byte(kObjecttype) == kSetObjectType1)
y = 82;
Expand Down Expand Up @@ -3673,7 +3663,7 @@ void DreamGenContext::lookAtCard() {
loadKeypad();
createPanel2();
showFrame(tempGraphics(), 160, 80, 42, 128);
const uint8 *obText = getObTextStartCPP();
const uint8 *obText = getObTextStart();
findNextColon(&obText);
findNextColon(&obText);
findNextColon(&obText);
Expand Down
8 changes: 4 additions & 4 deletions engines/dreamweb/use.cpp
Expand Up @@ -140,7 +140,7 @@ void DreamGenContext::useRoutine() {
}

delPointer();
const uint8 *obText = getObTextStartCPP();
const uint8 *obText = getObTextStart();
if (findNextColon(&obText) != 0) {
if (findNextColon(&obText) != 0) {
if (*obText != 0) {
Expand Down Expand Up @@ -175,15 +175,15 @@ void DreamGenContext::useText(const uint8 *string) {
}

void DreamGenContext::showFirstUse() {
const uint8 *obText = getObTextStartCPP();
const uint8 *obText = getObTextStart();
findNextColon(&obText);
findNextColon(&obText);
useText(obText);
hangOnP(400);
}

void DreamGenContext::showSecondUse() {
const uint8 *obText = getObTextStartCPP();
const uint8 *obText = getObTextStart();
findNextColon(&obText);
findNextColon(&obText);
findNextColon(&obText);
Expand Down Expand Up @@ -1611,7 +1611,7 @@ void DreamGenContext::useCashCard() {
showMan();
uint16 y = (!data.byte(kForeignrelease)) ? 120 : 120 - 3;
showFrame(tempGraphics(), 114, y, 39, 0);
const uint8 *obText = getObTextStartCPP();
const uint8 *obText = getObTextStart();
findNextColon(&obText);
findNextColon(&obText);
y = 98;
Expand Down

0 comments on commit b983963

Please sign in to comment.