Skip to content

Commit

Permalink
DREAMWEB: Port 'poolguard' to C++
Browse files Browse the repository at this point in the history
This is the last of the people-related functions, so the assembly-like
wrappers of addToPeopleList() and showGameReel() have been removed. Also,
madManText() has been simplified
  • Loading branch information
bluegr committed Dec 15, 2011
1 parent 66618f4 commit 30b4037
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 157 deletions.
1 change: 1 addition & 0 deletions devtools/tasmrecover/tasm-recover
Expand Up @@ -624,6 +624,7 @@ generator = cpp(context, "DreamGen", blacklist = [
'playchannel1',
'playguitar',
'plotreel',
'poolguard',
'powerlightoff',
'powerlighton',
'priest',
Expand Down
97 changes: 0 additions & 97 deletions engines/dreamweb/dreamgen.cpp
Expand Up @@ -26,103 +26,6 @@

namespace DreamGen {

void DreamGenContext::poolGuard() {
STACK_CHECK;
ax = es.word(bx+3);
_cmp(ax, 214);
if (flags.z())
goto combatover2;
_cmp(ax, 258);
if (flags.z())
goto combatover2;
_cmp(ax, 185);
if (flags.z())
goto combatover1;
_cmp(ax, 0);
if (!flags.z())
goto notfirstpool;
al = 0;
turnPathOn();
notfirstpool:
checkSpeed();
if (!flags.z())
goto guardspeed;
ax = es.word(bx+3);
_inc(ax);
_cmp(ax, 122);
if (!flags.z())
goto notendguard1;
_dec(ax);
_cmp(data.byte(kLastweapon), 2);
if (!flags.z())
goto notaxeonpool;
data.byte(kLastweapon) = -1;
ax = 122;
goto gotguardframe;
notaxeonpool:
_inc(data.byte(kCombatcount));
_cmp(data.byte(kCombatcount), 40);
if (!flags.z())
goto gotguardframe;
data.byte(kCombatcount) = 0;
ax = 195;
goto gotguardframe;
notendguard1:
_cmp(ax, 147);
if (!flags.z())
goto gotguardframe;
_dec(ax);
_cmp(data.byte(kLastweapon), 1);
if (!flags.z())
goto notgunonpool;
data.byte(kLastweapon) = -1;
ax = 147;
goto gotguardframe;
notgunonpool:
_inc(data.byte(kCombatcount));
_cmp(data.byte(kCombatcount), 40);
if (!flags.z())
goto gotguardframe;
data.byte(kCombatcount) = 0;
ax = 220;
gotguardframe:
es.word(bx+3) = ax;
guardspeed:
showGameReel();
ax = es.word(bx+3);
_cmp(ax, 121);
if (flags.z())
goto iswaitingpool;
_cmp(ax, 146);
if (flags.z())
goto iswaitingpool;
data.byte(kPointermode) = 0;
data.word(kWatchingtime) = 2;
return;
iswaitingpool:
data.byte(kPointermode) = 2;
data.word(kWatchingtime) = 0;
return;
combatover1:
data.word(kWatchingtime) = 0;
data.byte(kPointermode) = 0;
al = 0;
turnPathOn();
al = 1;
turnPathOff();
return;
combatover2:
showGameReel();
data.word(kWatchingtime) = 2;
data.byte(kPointermode) = 0;
_inc(data.byte(kCombatcount));
_cmp(data.byte(kCombatcount), 100);
if (flags.c())
return /* (doneover2) */;
data.word(kWatchingtime) = 0;
data.byte(kMandead) = 2;
}

void DreamGenContext::checkForExit() {
STACK_CHECK;
cl = data.byte(kRyanx);
Expand Down
1 change: 0 additions & 1 deletion engines/dreamweb/dreamgen.h
Expand Up @@ -519,7 +519,6 @@ class DreamGenContext : public DreamBase, public Context {
void deleteExFrame();
void searchForSame();
void rollEm();
void poolGuard();
void lookAtPlace();
void findAllOpen();
void showSlots();
Expand Down
135 changes: 82 additions & 53 deletions engines/dreamweb/people.cpp
Expand Up @@ -24,38 +24,6 @@

namespace DreamGen {

static void (DreamGenContext::*reelCallbacks[57])() = {
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, &DreamGenContext::poolGuard,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL
};

static void (DreamGenContext::*reelCallbacksCPP[57])(ReelRoutine &) = {
&DreamGenContext::gamer, &DreamGenContext::sparkyDrip,
&DreamGenContext::eden, &DreamGenContext::edenInBath,
Expand Down Expand Up @@ -93,46 +61,37 @@ void DreamGenContext::updatePeople() {
memset(getSegment(data.word(kBuffers)).ptr(kPeoplelist, 12 * sizeof(People)), 0xff, 12 * sizeof(People));
++data.word(kMaintimer);

// The original callbacks are called with es:bx pointing to their reelRoutine entry.
// The new callbacks take a mutable ReelRoutine parameter.

es = data;
ReelRoutine *r = (ReelRoutine *)data.ptr(kReelroutines, 0);

for (int i = 0; r[i].reallocation != 255; ++i) {
bx = kReelroutines + 8*i;
if (r[i].reallocation == data.byte(kReallocation) &&
r[i].mapX == data.byte(kMapx) &&
r[i].mapY == data.byte(kMapy)) {
if (reelCallbacks[i]) {
assert(!reelCallbacksCPP[i]);
(this->*(reelCallbacks[i]))();
} else {
assert(reelCallbacksCPP[i]);
(this->*(reelCallbacksCPP[i]))(r[i]);
}
assert(reelCallbacksCPP[i]);
(this->*(reelCallbacksCPP[i]))(r[i]);
}
}
}

void DreamGenContext::madmanText() {
byte origCount;

if (isCD()) {
if (data.byte(kSpeechcount) >= 63)
return;
if (data.byte(kCh1playing) != 255)
return;
al = data.byte(kSpeechcount);
origCount = data.byte(kSpeechcount);
++data.byte(kSpeechcount);
} else {
if (data.byte(kCombatcount) >= 61)
return;
al = data.byte(kCombatcount);
_and(al, 3);
if (!flags.z())
if (data.byte(kCombatcount) & 3)
return;
al = data.byte(kCombatcount) / 4;
origCount = data.byte(kCombatcount) / 4;
}
setupTimedTemp(47 + al, 82, 72, 80, 90, 1);
setupTimedTemp(47 + origCount, 82, 72, 80, 90, 1);
}

void DreamGenContext::madman(ReelRoutine &routine) {
Expand Down Expand Up @@ -191,10 +150,6 @@ void DreamGenContext::madMode() {
data.byte(kPointermode) = 2;
}

void DreamGenContext::addToPeopleList() {
addToPeopleList((ReelRoutine *)es.ptr(bx, sizeof(ReelRoutine)));
}

void DreamGenContext::addToPeopleList(ReelRoutine *routine) {
uint16 routinePointer = (const uint8 *)routine - data.ptr(0, 0);

Expand Down Expand Up @@ -1049,4 +1004,78 @@ void DreamGenContext::endGameSeq(ReelRoutine &routine) {
}
}

void DreamGenContext::poolGuard(ReelRoutine &routine) {
if (routine.reelPointer() == 214 || routine.reelPointer() == 258) {
// Combat over 2
showGameReel(&routine);
data.word(kWatchingtime) = 2;
data.byte(kPointermode) = 0;
data.byte(kCombatcount)++;
if (data.byte(kCombatcount) < 100)
return; // doneover2
data.word(kWatchingtime) = 0;
data.byte(kMandead) = 2;
return;
} else if (routine.reelPointer() == 185) {
// Combat over 1
data.word(kWatchingtime) = 0;
data.byte(kPointermode) = 0;
turnPathOn(0);
turnPathOff(1);
return;
}

if (routine.reelPointer() == 0)
turnPathOn(0); // first pool

if (checkSpeed(routine)) {
uint16 nextReelPointer = routine.reelPointer() + 1;

if (nextReelPointer != 122) {
// Not end guard 1
if (nextReelPointer == 147) {
nextReelPointer--;
if (data.byte(kLastweapon) == 1) {
// Gun on pool
data.byte(kLastweapon) = (byte)-1;
nextReelPointer = 147;
} else {
// Gun not on pool
data.byte(kCombatcount)++;
if (data.byte(kCombatcount) == 40) {
data.byte(kCombatcount) = 0;
nextReelPointer = 220;
}
}
}
}

nextReelPointer--;

if (data.byte(kLastweapon) == 2) {
// Axe on pool
data.byte(kLastweapon) = (byte)-1;
nextReelPointer = 122;
} else {
data.byte(kCombatcount)++;
if (data.byte(kCombatcount) == 40) {
data.byte(kCombatcount) = 0;
nextReelPointer = 195;
}
}

routine.setReelPointer(nextReelPointer);
}

showGameReel(&routine);

if (routine.reelPointer() != 121 && routine.reelPointer() != 146) {
data.byte(kPointermode) = 0;
data.word(kWatchingtime) = 2;
} else {
data.byte(kPointermode) = 2;
data.word(kWatchingtime) = 0;
}
}

} // End of namespace DreamGen
4 changes: 0 additions & 4 deletions engines/dreamweb/sprite.cpp
Expand Up @@ -486,10 +486,6 @@ void DreamBase::showReelFrame(Reel *reel) {
showFrame(base, x, y, frame, 8);
}

void DreamGenContext::showGameReel() {
showGameReel((ReelRoutine *)es.ptr(bx, sizeof(ReelRoutine)));
}

void DreamGenContext::showGameReel(ReelRoutine *routine) {
uint16 reelPointer = routine->reelPointer();
if (reelPointer >= 512)
Expand Down
3 changes: 1 addition & 2 deletions engines/dreamweb/stubs.h
Expand Up @@ -92,7 +92,6 @@
void wideDoor(Sprite *sprite, SetObject *objData);
void lockedDoorway(Sprite *sprite, SetObject *objData);
void liftSprite(Sprite *sprite, SetObject *objData);
void showGameReel();
void showGameReel(ReelRoutine *routine);
void turnPathOn(uint8 param);
void turnPathOff(uint8 param);
Expand Down Expand Up @@ -176,7 +175,6 @@
void obName();
void obName(uint8 command, uint8 commandType);
void checkCoords(const RectWithCallback *rectWithCallbacks);
void addToPeopleList();
void addToPeopleList(ReelRoutine *routine);
void getExPos();
void compare();
Expand Down Expand Up @@ -385,6 +383,7 @@
void mugger(ReelRoutine &routine);
void businessMan(ReelRoutine &routine);
void endGameSeq(ReelRoutine &routine);
void poolGuard(ReelRoutine &routine);
void singleKey(uint8 key, uint16 x, uint16 y);
void loadSaveBox();
uint8 nextSymbol(uint8 symbol);
Expand Down

0 comments on commit 30b4037

Please sign in to comment.