Skip to content

Commit

Permalink
Merge pull request #130 from fingolfin/dreamweb-misc
Browse files Browse the repository at this point in the history
Dreamweb: convert workoutFrames to c++, some cleanup
  • Loading branch information
bluegr committed Dec 8, 2011
2 parents 96360bb + c8d4f60 commit 05fff73
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 138 deletions.
2 changes: 1 addition & 1 deletion devtools/tasmrecover/tasm-recover
Expand Up @@ -725,6 +725,7 @@ generator = cpp(context, "DreamGen", blacklist = [
'wheelsound',
'widedoor',
'width160',
'workoutframes',
'worktoscreen',
'worktoscreenm',
'wornerror',
Expand Down Expand Up @@ -913,7 +914,6 @@ generator = cpp(context, "DreamGen", blacklist = [
'findinvpos' : 'findInvPos',
'dumpmenu' : 'dumpMenu',
'liftnoise' : 'liftNoise',
'workoutframes' : 'workoutFrames',
'dumpsymbox' : 'dumpSymBox',
'loadgame' : 'loadGame',
'getridoftemp' : 'getRidOfTemp',
Expand Down
2 changes: 1 addition & 1 deletion engines/dreamweb/backdrop.cpp
Expand Up @@ -247,7 +247,7 @@ void DreamGenContext::showAllFree() {
data.word(kFramesad) = kFrframes;
data.byte(kCurrentfree) = 0;
const DynObject *freeObjects = (const DynObject *)getSegment(data.word(kFreedat)).ptr(0, 0);
for(size_t i = 0; i < 80; ++i) {
for (size_t i = 0; i < 80; ++i) {
uint8 mapAd = getMapAd(freeObjects[i].mapad);
if (mapAd != 0) {
uint8 width, height;
Expand Down
2 changes: 1 addition & 1 deletion engines/dreamweb/detection.cpp
Expand Up @@ -95,7 +95,7 @@ SaveStateList DreamWebMetaEngine::listSaves(const char *target) const {
Common::sort(files.begin(), files.end());

SaveStateList saveList;
for(uint i = 0; i < files.size(); ++i) {
for (uint i = 0; i < files.size(); ++i) {
const Common::String &file = files[i];
Common::InSaveFile *stream = saveFileMan->openForLoading(file);
if (!stream)
Expand Down
6 changes: 6 additions & 0 deletions engines/dreamweb/dreambase.h
Expand Up @@ -69,6 +69,12 @@ class DreamBase : public SegmentManager {
Common::Point _lineData[200]; // Output of Bresenham
void checkDest(const RoomPaths *roomsPaths);
RoomPaths *getRoomsPaths();
void faceRightWay();
void setWalk();
void autoSetWalk();
void findXYFromPath();
void bresenhams();
void workoutFrames();

// from print.cpp
uint8 getNextWord(const Frame *charSet, const uint8 *string, uint8 *totalWidth, uint8 *charCount);
Expand Down
87 changes: 0 additions & 87 deletions engines/dreamweb/dreamgen.cpp
Expand Up @@ -6849,93 +6849,6 @@ void DreamGenContext::printmessage2() {
printDirect();
}

void DreamGenContext::workoutFrames() {
STACK_CHECK;
bx = data.word(kLinestartx);
_add(bx, 32);
ax = data.word(kLineendx);
_add(ax, 32);
_sub(bx, ax);
if (!flags.c())
goto notneg1;
_neg(bx);
notneg1:
cx = data.word(kLinestarty);
_add(cx, 32);
ax = data.word(kLineendy);
_add(ax, 32);
_sub(cx, ax);
if (!flags.c())
goto notneg2;
_neg(cx);
notneg2:
_cmp(bx, cx);
if (!flags.c())
goto tendstohoriz;
dl = 2;
ax = cx;
_shr(ax, 1);
_cmp(bx, ax);
if (flags.c())
goto gotquad;
dl = 1;
goto gotquad;
tendstohoriz:
dl = 0;
ax = bx;
_shr(ax, 1);
_cmp(cx, ax);
if (flags.c())
goto gotquad;
dl = 1;
goto gotquad;
gotquad:
bx = data.word(kLinestartx);
_add(bx, 32);
ax = data.word(kLineendx);
_add(ax, 32);
_sub(bx, ax);
if (flags.c())
goto isinright;
cx = data.word(kLinestarty);
_add(cx, 32);
ax = data.word(kLineendy);
_add(ax, 32);
_sub(cx, ax);
if (!flags.c())
goto topleft;
_cmp(dl, 1);
if (flags.z())
goto noswap1;
_xor(dl, 2);
noswap1:
_add(dl, 4);
goto success;
topleft:
_add(dl, 6);
goto success;
isinright:
cx = data.word(kLinestarty);
_add(cx, 32);
ax = data.word(kLineendy);
_add(ax, 32);
_sub(cx, ax);
if (!flags.c())
goto botright;
_add(dl, 2);
goto success;
botright:
_cmp(dl, 1);
if (flags.z())
goto noswap2;
_xor(dl, 2);
noswap2:
success:
_and(dl, 7);
data.byte(kTurntoface) = dl;
data.byte(kTurndirection) = 0;
}

void DreamGenContext::getUnderZoom() {
STACK_CHECK;
di = (8)+5;
Expand Down
1 change: 0 additions & 1 deletion engines/dreamweb/dreamgen.h
Expand Up @@ -599,7 +599,6 @@ class DreamGenContext : public DreamBase, public Context {
void cantDrop();
void putUnderZoom();
void findInvPos();
void workoutFrames();
void rollEndCredits();
void getKeyAndLogo();
void selectOb();
Expand Down
8 changes: 4 additions & 4 deletions engines/dreamweb/dreamweb.cpp
Expand Up @@ -326,14 +326,14 @@ void DreamWebEngine::mouseCall(uint16 *x, uint16 *y, uint16 *state) {

void DreamWebEngine::getPalette(uint8 *data, uint start, uint count) {
_system->getPaletteManager()->grabPalette(data, start, count);
while(count--)
while (count--)
*data++ >>= 2;
}

void DreamWebEngine::setPalette(const uint8 *data, uint start, uint count) {
assert(start + count <= 256);
uint8 fixed[768];
for(uint i = 0; i < count * 3; ++i) {
for (uint i = 0; i < count * 3; ++i) {
fixed[i] = data[i] << 2;
}
_system->getPaletteManager()->setPalette(fixed, start, count);
Expand All @@ -356,9 +356,9 @@ void DreamWebEngine::printUnderMonitor() {
if (!s)
error("lockScreen failed");

for(uint y = 0; y < 104; ++y) {
for (uint y = 0; y < 104; ++y) {
uint8 *src = (uint8 *)s->getBasePtr(76, 43 + 8 + y);
for(uint x = 0; x < 170; ++x) {
for (uint x = 0; x < 170; ++x) {
if (*src < 231)
*dst++ = *src++;
else {
Expand Down
70 changes: 66 additions & 4 deletions engines/dreamweb/pathfind.cpp
Expand Up @@ -73,7 +73,14 @@ RoomPaths *DreamBase::getRoomsPaths() {
return (RoomPaths *)result;
}

void DreamGenContext::setWalk() {
void DreamBase::faceRightWay() {
PathNode *paths = getRoomsPaths()->nodes;
uint8 dir = paths[data.byte(kManspath)].dir;
data.byte(kTurntoface) = dir;
data.byte(kLeavedirection) = dir;
}

void DreamBase::setWalk() {
if (data.byte(kLinepointer) != 254) {
// Already walking
data.byte(kFinaldest) = data.byte(kPointerspath);
Expand All @@ -100,7 +107,7 @@ void DreamGenContext::setWalk() {
}
}

void DreamGenContext::autoSetWalk() {
void DreamBase::autoSetWalk() {
if (data.byte(kFinaldest) == data.byte(kManspath))
return;
const RoomPaths *roomsPaths = getRoomsPaths();
Expand Down Expand Up @@ -137,7 +144,7 @@ void DreamBase::checkDest(const RoomPaths *roomsPaths) {
data.byte(kDestination) = destination;
}

void DreamGenContext::findXYFromPath() {
void DreamBase::findXYFromPath() {
const PathNode *roomsPaths = getRoomsPaths()->nodes;
data.byte(kRyanx) = roomsPaths[data.byte(kManspath)].x - 12;
data.byte(kRyany) = roomsPaths[data.byte(kManspath)].y - 12;
Expand All @@ -153,7 +160,7 @@ bool DreamGenContext::checkIfPathIsOn(uint8 index) {
return pathOn == 0xff;
}

void DreamGenContext::bresenhams() {
void DreamBase::bresenhams() {
workoutFrames();
Common::Point *lineData = &_lineData[0];
int16 startX = (int16)data.word(kLinestartx);
Expand Down Expand Up @@ -269,4 +276,59 @@ void DreamGenContext::bresenhams() {
}
}

void DreamBase::workoutFrames() {
byte tmp;
uint16 diffx, diffy;

// FIXME: Paranoia asserts, to be removed after sufficient play
// testing has happened. Background: The original code used to add
// 32 to the four values listed in the asserts below. Which seems
// nonsensical, as only the differences of the values matter, so the
// +32 cancels out. Unless there is an overflow somewhere... So we
// check for that here.
assert(data.word(kLinestartx) < 0xFFFF - 32);
assert(data.word(kLineendx) < 0xFFFF - 32);
assert(data.word(kLinestarty) < 0xFFFF - 32);
assert(data.word(kLineendy) < 0xFFFF - 32);


diffx = ABS(data.word(kLinestartx) - data.word(kLineendx));
diffy = ABS(data.word(kLinestarty) - data.word(kLineendy));

if (diffx < diffy) {
tmp = 2;
if (diffx >= (diffy >> 1))
tmp = 1;
} else {
// tendstohoriz
tmp = 0;
if (diffy >= (diffx >> 1))
tmp = 1;
}

if (data.word(kLinestartx) >= data.word(kLineendx)) {
// isinleft
if (data.word(kLinestarty) < data.word(kLineendy)) {
if (tmp != 1)
tmp ^= 2;
tmp += 4;
} else {
// topleft
tmp += 6;
}
} else {
// isinright
if (data.word(kLinestarty) < data.word(kLineendy)) {
tmp += 2;
} else {
// botright
if (tmp != 1)
tmp ^= 2;
}
}

data.byte(kTurntoface) = tmp & 7;
data.byte(kTurndirection) = 0;
}

} // End of namespace DreamGen
4 changes: 2 additions & 2 deletions engines/dreamweb/print.cpp
Expand Up @@ -35,7 +35,7 @@ void DreamBase::printBoth(const Frame *charSet, uint16 *x, uint16 y, uint8 c, ui
uint8 DreamBase::getNextWord(const Frame *charSet, const uint8 *string, uint8 *totalWidth, uint8 *charCount) {
*totalWidth = 0;
*charCount = 0;
while(true) {
while (true) {
uint8 firstChar = *string;
++string;
++*charCount;
Expand Down Expand Up @@ -153,7 +153,7 @@ uint8 DreamBase::printDirect(const uint8** string, uint16 x, uint16 *y, uint8 ma
printChar(charSet, &i, *y, c, nextChar, &width, &height);
data.word(kLastxpos) = i;
--charCount;
} while(charCount);
} while (charCount);
*y += data.word(kLinespacing);
}
}
Expand Down
6 changes: 0 additions & 6 deletions engines/dreamweb/runtime.h
Expand Up @@ -40,12 +40,6 @@ struct Register {
inline Register(): _value() {}
inline Register& operator=(uint16 v) { _value = v; return *this; }
inline operator uint16&() { return _value; }
inline void cbw() {
if (_value & 0x80)
_value |= 0xff00;
else
_value &= 0x7f;
}
};

template<int kIndex> //from low to high
Expand Down
2 changes: 1 addition & 1 deletion engines/dreamweb/sound.cpp
Expand Up @@ -289,7 +289,7 @@ void DreamWebEngine::loadSounds(uint bank, const Common::String &filename) {
SoundData &soundData = _soundData[bank];
soundData.samples.resize(tablesize / 6);
uint total = 0;
for(uint i = 0; i < tablesize / 6; ++i) {
for (uint i = 0; i < tablesize / 6; ++i) {
uint8 entry[6];
Sample &sample = soundData.samples[i];
file.read(entry, sizeof(entry));
Expand Down
9 changes: 1 addition & 8 deletions engines/dreamweb/sprite.cpp
Expand Up @@ -457,13 +457,6 @@ void DreamGenContext::liftSprite(Sprite *sprite, SetObject *objData) {
}
}

void DreamGenContext::faceRightWay() {
PathNode *paths = getRoomsPaths()->nodes;
uint8 dir = paths[data.byte(kManspath)].dir;
data.byte(kTurntoface) = dir;
data.byte(kLeavedirection) = dir;
}

Reel *DreamBase::getReelStart(uint16 reelPointer) {
Reel *reel = (Reel *)getSegment(data.word(kReels)).ptr(kReellist + reelPointer * sizeof(Reel) * 8, sizeof(Reel));
return reel;
Expand Down Expand Up @@ -530,7 +523,7 @@ void DreamGenContext::showRain() {
rain->setW3(ax);
const uint8 *src = ds.ptr(si, 0) + ax;
uint8 *dst = workspace() + y * 320 + x;
for(uint16 i = 0; i < size; ++i) {
for (uint16 i = 0; i < size; ++i) {
uint8 v = src[i];
if (v != 0)
*dst = v;
Expand Down
14 changes: 7 additions & 7 deletions engines/dreamweb/stubs.cpp
Expand Up @@ -993,7 +993,7 @@ void DreamGenContext::deallocateMem(uint16 segment) {
MutableSegmentRef buffers(this);
buffers = bseg;
uint8 *ptr = buffers.ptr(kSpritetable, tsize);
for(uint i = 0; i < tsize; i += 32) {
for (uint i = 0; i < tsize; i += 32) {
uint16 seg = READ_LE_UINT16(ptr + i + 6);
//debug(1, "sprite segment = %04x", seg);
if (seg == segment)
Expand Down Expand Up @@ -1032,8 +1032,8 @@ void DreamGenContext::fadeDOS() {
//processEvents will be called from vsync
uint8 *dst = es.ptr(kStartpal, 768);
engine->getPalette(dst, 0, 64);
for(int fade = 0; fade < 64; ++fade) {
for(int c = 0; c < 768; ++c) { //original sources decrement 768 values -> 256 colors
for (int fade = 0; fade < 64; ++fade) {
for (int c = 0; c < 768; ++c) { //original sources decrement 768 values -> 256 colors
if (dst[c]) {
--dst[c];
}
Expand Down Expand Up @@ -1475,7 +1475,7 @@ void DreamGenContext::doChange(uint8 index, uint8 value, uint8 type) {
void DreamGenContext::deleteTaken() {
const DynObject *extraObjects = (const DynObject *)getSegment(data.word(kExtras)).ptr(kExdata, 0);
DynObject *freeObjects = (DynObject *)getSegment(data.word(kFreedat)).ptr(0, 0);
for(size_t i = 0; i < kNumexobjects; ++i) {
for (size_t i = 0; i < kNumexobjects; ++i) {
uint8 location = extraObjects[i].initialLocation;
if (location == data.byte(kReallocation)) {
uint8 index = extraObjects[i].index;
Expand Down Expand Up @@ -1873,7 +1873,7 @@ bool DreamGenContext::compare(uint8 index, uint8 flag, const char id[4]) {
void *ptr = getAnyAdDir(index, flag);
const char *objId = (const char *)(((const uint8 *)ptr) + 12); // whether it is a DynObject or a SetObject
for (size_t i = 0; i < 4; ++i) {
if(id[i] != objId[i] + 'A')
if (id[i] != objId[i] + 'A')
return false;
}
return true;
Expand Down Expand Up @@ -3549,7 +3549,7 @@ void DreamGenContext::nextDest() {
data.byte(kDestpos) = 0; // last destination

getDestInfo();
} while(al == 0);
} while (al == 0);

data.byte(kNewtextline) = 1;
delTextLine();
Expand Down Expand Up @@ -3580,7 +3580,7 @@ void DreamGenContext::lastDest() {
data.byte(kDestpos) = 15; // first destination

getDestInfo();
} while(al == 0);
} while (al == 0);

data.byte(kNewtextline) = 1;
delTextLine();
Expand Down

0 comments on commit 05fff73

Please sign in to comment.