aboutsummaryrefslogtreecommitdiff
path: root/engines/dreamweb/backdrop.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/dreamweb/backdrop.cpp')
-rw-r--r--engines/dreamweb/backdrop.cpp276
1 files changed, 113 insertions, 163 deletions
diff --git a/engines/dreamweb/backdrop.cpp b/engines/dreamweb/backdrop.cpp
index 3e005fdec9..1db2663624 100644
--- a/engines/dreamweb/backdrop.cpp
+++ b/engines/dreamweb/backdrop.cpp
@@ -22,13 +22,12 @@
#include "dreamweb/dreamweb.h"
-namespace DreamGen {
+namespace DreamWeb {
-void DreamGenContext::doBlocks() {
- uint16 dstOffset = data.word(kMapady) * 320 + data.word(kMapadx);
- uint16 mapOffset = kMap + data.byte(kMapy) * kMapwidth + data.byte(kMapx);
- const uint8 *mapData = getSegment(data.word(kMapdata)).ptr(mapOffset, 0);
- const uint8 *blocks = getSegment(data.word(kBackdrop)).ptr(kBlocks, 0);
+void DreamWebEngine::doBlocks() {
+ uint16 dstOffset = _mapAdY * 320 + _mapAdX;
+ uint16 mapOffset = _mapY * kMapWidth + _mapX;
+ const uint8 *mapData = _mapData + mapOffset;
uint8 *dstBuffer = workspace() + dstOffset;
for (size_t i = 0; i < 10; ++i) {
@@ -36,7 +35,7 @@ void DreamGenContext::doBlocks() {
uint16 blockType = mapData[j];
if (blockType != 0) {
uint8 *dst = dstBuffer + i * 320 * 16 + j * 16;
- const uint8 *block = blocks + blockType * 256;
+ const uint8 *block = _backdropBlocks + blockType * 256;
for (size_t k = 0; k < 4; ++k) {
memcpy(dst, block, 16);
block += 16;
@@ -49,7 +48,6 @@ void DreamGenContext::doBlocks() {
dst += 320;
}
dst += 4;
- ax = 0x0dfdf;
memset(dst, 0xdf, 16);
dst += 320;
memset(dst, 0xdf, 16);
@@ -59,271 +57,223 @@ void DreamGenContext::doBlocks() {
memset(dst, 0xdf, 16);
}
}
- mapData += kMapwidth;
+ mapData += kMapWidth;
}
}
-uint8 DreamGenContext::getXAd(const uint8 *setData, uint8 *result) {
+uint8 DreamWebEngine::getXAd(const uint8 *setData, uint8 *result) {
uint8 v0 = setData[0];
uint8 v1 = setData[1];
uint8 v2 = setData[2];
if (v0 != 0)
return 0;
- if (v1 < data.byte(kMapx))
+ if (v1 < _mapX)
return 0;
- v1 -= data.byte(kMapx);
+ v1 -= _mapX;
if (v1 >= 11)
return 0;
*result = (v1 << 4) | v2;
return 1;
}
-uint8 DreamGenContext::getYAd(const uint8 *setData, uint8 *result) {
+uint8 DreamWebEngine::getYAd(const uint8 *setData, uint8 *result) {
uint8 v0 = setData[3];
uint8 v1 = setData[4];
- if (v0 < data.byte(kMapy))
+ if (v0 < _mapY)
return 0;
- v0 -= data.byte(kMapy);
+ v0 -= _mapY;
if (v0 >= 10)
return 0;
*result = (v0 << 4) | v1;
return 1;
}
-void DreamGenContext::getMapAd() {
- ch = getMapAd((const uint8 *)es.ptr(si, 5));
-}
-
-uint8 DreamGenContext::getMapAd(const uint8 *setData) {
+uint8 DreamWebEngine::getMapAd(const uint8 *setData, uint16 *x, uint16 *y) {
uint8 xad, yad;
if (getXAd(setData, &xad) == 0)
return 0;
- data.word(kObjectx) = xad;
+ *x = xad;
if (getYAd(setData, &yad) == 0)
return 0;
- data.word(kObjecty) = yad;
+ *y = yad;
return 1;
}
-void DreamGenContext::calcFrFrame(uint16 frame) {
- uint8 width, height;
- calcFrFrame(frame, &width, &height);
- cl = width;
- ch = height;
-}
-
-void DreamGenContext::calcFrFrame(uint16 frameNum, uint8* width, uint8* height) {
- const Frame *frame = (const Frame *)getSegment(data.word(kFrsegment)).ptr(frameNum * sizeof(Frame), sizeof(Frame));
- data.word(kSavesource) = data.word(kFramesad) + frame->ptr();
- data.byte(kSavesize+0) = frame->width;
- data.byte(kSavesize+1) = frame->height;
- data.word(kOffsetx) = frame->x;
- data.word(kOffsety) = frame->y;
- *width = frame->width;
- *height = frame->height;
-}
+void DreamWebEngine::calcFrFrame(const Frame &frame, uint8 *width, uint8 *height, uint16 x, uint16 y, ObjPos *objPos) {
+ *width = frame.width;
+ *height = frame.height;
-void DreamGenContext::finalFrame() {
- uint16 x, y;
- finalFrame(&x, &y);
- di = x;
- bx = y;
+ objPos->xMin = (x + frame.x) & 0xff;
+ objPos->yMin = (y + frame.y) & 0xff;
+ objPos->xMax = objPos->xMin + frame.width;
+ objPos->yMax = objPos->yMin + frame.height;
}
-void DreamGenContext::finalFrame(uint16 *x, uint16 *y) {
- data.byte(kSavex) = (data.word(kObjectx) + data.word(kOffsetx)) & 0xff;
- data.byte(kSavey) = (data.word(kObjecty) + data.word(kOffsety)) & 0xff;
- *x = data.word(kObjectx);
- *y = data.word(kObjecty);
+void DreamWebEngine::makeBackOb(SetObject *objData, uint16 x, uint16 y) {
+ if (_vars._newObs == 0)
+ return;
+ uint8 priority = objData->priority;
+ uint8 type = objData->type;
+ Sprite *sprite = makeSprite(x, y, false, &_setFrames);
+
+ sprite->_objData = objData;
+ if (priority == 255)
+ priority = 0;
+ sprite->priority = priority;
+ sprite->type = type;
+ sprite->delay = 0;
+ sprite->animFrame = 0;
}
-void DreamGenContext::showAllObs() {
- data.word(kListpos) = kSetlist;
- memset(getSegment(data.word(kBuffers)).ptr(kSetlist, 0), 0xff, 128 * 5);
- data.word(kFrsegment) = data.word(kSetframes);
- data.word(kDataad) = kFramedata;
- data.word(kFramesad) = kFrames;
+void DreamWebEngine::showAllObs() {
+ _setList.clear();
- const Frame *frames = (const Frame *)getSegment(data.word(kFrsegment)).ptr(0, 0);
- SetObject *setEntries = (SetObject *)getSegment(data.word(kSetdat)).ptr(0, 128 * sizeof(SetObject));
+ const GraphicsFile &frameBase = _setFrames;
for (size_t i = 0; i < 128; ++i) {
- SetObject *setEntry = setEntries + i;
- if (getMapAd(setEntry->mapad) == 0)
+ SetObject *setEntry = &_setDat[i];
+ uint16 x, y;
+ if (getMapAd(setEntry->mapad, &x, &y) == 0)
continue;
uint8 currentFrame = setEntry->frames[0];
if (currentFrame == 0xff)
continue;
- calcFrFrame(currentFrame);
- uint16 x, y;
- finalFrame(&x, &y);
+ uint8 width, height;
+ ObjPos objPos;
+ calcFrFrame(frameBase._frames[currentFrame], &width, &height, x, y, &objPos);
setEntry->index = setEntry->frames[0];
if ((setEntry->type == 0) && (setEntry->priority != 5) && (setEntry->priority != 6)) {
- x += data.word(kMapadx);
- y += data.word(kMapady);
- showFrame(frames, x, y, currentFrame, 0);
+ x += _mapAdX;
+ y += _mapAdY;
+ showFrame(frameBase, x, y, currentFrame, 0);
} else
- makeBackOb(setEntry);
-
- ObjPos *objPos = (ObjPos *)getSegment(data.word(kBuffers)).ptr(data.word(kListpos), sizeof(ObjPos));
- objPos->xMin = data.byte(kSavex);
- objPos->yMin = data.byte(kSavey);
- objPos->xMax = data.byte(kSavex) + data.byte(kSavesize+0);
- objPos->yMax = data.byte(kSavey) + data.byte(kSavesize+1);
- objPos->index = i;
- data.word(kListpos) += sizeof(ObjPos);
- }
-}
+ makeBackOb(setEntry, x, y);
-void DreamGenContext::getDimension() {
- uint8 mapXstart, mapYstart;
- uint8 mapXsize, mapYsize;
- getDimension(&mapXstart, &mapYstart, &mapXsize, &mapYsize);
- cl = mapXstart;
- ch = mapYstart;
- dl = mapXsize;
- dh = mapYsize;
+ objPos.index = i;
+ _setList.push_back(objPos);
+ }
}
-bool DreamGenContext::addAlong(const uint8 *mapFlags) {
+static bool addAlong(const MapFlag *mapFlags) {
for (size_t i = 0; i < 11; ++i) {
- if (mapFlags[3 * i] != 0)
+ if (mapFlags[i]._flag != 0)
return true;
}
return false;
}
-bool DreamGenContext::addLength(const uint8 *mapFlags) {
+static bool addLength(const MapFlag *mapFlags) {
for (size_t i = 0; i < 10; ++i) {
- if (mapFlags[3 * 11 * i] != 0)
+ if (mapFlags[11 * i]._flag != 0)
return true;
}
return false;
}
-void DreamGenContext::getDimension(uint8 *mapXstart, uint8 *mapYstart, uint8 *mapXsize, uint8 *mapYsize) {
- const uint8 *mapFlags = getSegment(data.word(kBuffers)).ptr(kMapflags, 0);
-
+void DreamWebEngine::getDimension(uint8 *mapXstart, uint8 *mapYstart, uint8 *mapXsize, uint8 *mapYsize) {
uint8 yStart = 0;
- while (! addAlong(mapFlags + 3 * 11 * yStart))
+ while (! addAlong(_mapFlags + 11 * yStart))
++yStart;
uint8 xStart = 0;
- while (! addLength(mapFlags + 3 * xStart))
+ while (! addLength(_mapFlags + xStart))
++xStart;
uint8 yEnd = 10;
- while (! addAlong(mapFlags + 3 * 11 * (yEnd - 1)))
+ while (! addAlong(_mapFlags + 11 * (yEnd - 1)))
--yEnd;
uint8 xEnd = 11;
- while (! addLength(mapFlags + 3 * (xEnd - 1)))
+ while (! addLength(_mapFlags + (xEnd - 1)))
--xEnd;
*mapXstart = xStart;
*mapYstart = yStart;
*mapXsize = xEnd - xStart;
*mapYsize = yEnd - yStart;
- data.word(kMapxstart) = xStart << 4;
- data.word(kMapystart) = yStart << 4;
- data.byte(kMapxsize) = *mapXsize << 4;
- data.byte(kMapysize) = *mapYsize << 4;
+ _mapXStart = xStart << 4;
+ _mapYStart = yStart << 4;
+ _mapXSize = *mapXsize << 4;
+ _mapYSize = *mapYsize << 4;
}
-void DreamGenContext::calcMapAd() {
+void DreamWebEngine::calcMapAd() {
uint8 mapXstart, mapYstart;
uint8 mapXsize, mapYsize;
getDimension(&mapXstart, &mapYstart, &mapXsize, &mapYsize);
- data.word(kMapadx) = data.word(kMapoffsetx) - 8 * (mapXsize + 2 * mapXstart - 11);
- data.word(kMapady) = data.word(kMapoffsety) - 8 * (mapYsize + 2 * mapYstart - 10);
+ _mapAdX = _mapOffsetX - 8 * (mapXsize + 2 * mapXstart - 11);
+ _mapAdY = _mapOffsetY - 8 * (mapYsize + 2 * mapYstart - 10);
}
-void DreamGenContext::showAllFree() {
- data.word(kListpos) = kFreelist;
- ObjPos *listPos = (ObjPos *)getSegment(data.word(kBuffers)).ptr(kFreelist, 80 * sizeof(ObjPos));
- memset(listPos, 0xff, 80 * sizeof(ObjPos));
-
- data.word(kFrsegment) = data.word(kFreeframes);
- data.word(kDataad) = kFrframedata;
- 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) {
- uint8 mapAd = getMapAd(freeObjects[i].mapad);
+void DreamWebEngine::showAllFree() {
+ const unsigned int count = 80;
+
+ _freeList.clear();
+
+ const DynObject *freeObjects = _freeDat;
+ const GraphicsFile &frameBase = _freeFrames;
+ for (size_t i = 0; i < count; ++i) {
+ uint16 x, y;
+ uint8 mapAd = getMapAd(freeObjects[i].mapad, &x, &y);
if (mapAd != 0) {
uint8 width, height;
- uint16 currentFrame = 3 * data.byte(kCurrentfree);
- calcFrFrame(currentFrame, &width, &height);
- uint16 x, y;
- finalFrame(&x, &y);
+ ObjPos objPos;
+ uint16 currentFrame = 3 * i;
+ calcFrFrame(frameBase._frames[currentFrame], &width, &height, x, y, &objPos);
if ((width != 0) || (height != 0)) {
- x += data.word(kMapadx);
- y += data.word(kMapady);
+ x += _mapAdX;
+ y += _mapAdY;
assert(currentFrame < 256);
- showFrame((Frame *)getSegment(data.word(kFrsegment)).ptr(0, 0), x, y, currentFrame, 0);
- ObjPos *objPos = (ObjPos *)getSegment(data.word(kBuffers)).ptr(data.word(kListpos), sizeof(ObjPos));
- objPos->xMin = data.byte(kSavex);
- objPos->yMin = data.byte(kSavey);
- objPos->xMax = data.byte(kSavex) + data.byte(kSavesize+0);
- objPos->yMax = data.byte(kSavey) + data.byte(kSavesize+1);
- objPos->index = i;
- data.word(kListpos) += sizeof(ObjPos);
+ showFrame(frameBase, x, y, currentFrame, 0);
+ objPos.index = i;
+ _freeList.push_back(objPos);
}
}
-
- ++data.byte(kCurrentfree);
}
}
-void DreamGenContext::drawFlags() {
- uint8 *mapFlags = getSegment(data.word(kBuffers)).ptr(kMapflags, 0);
- const uint8 *mapData = getSegment(data.word(kMapdata)).ptr(kMap + data.byte(kMapy) * kMapwidth + data.byte(kMapx), 0);
- const uint8 *backdropFlags = getSegment(data.word(kBackdrop)).ptr(kFlags, 0);
+void DreamWebEngine::drawFlags() {
+ MapFlag *mapFlag = _mapFlags;
+ uint16 mapOffset = _mapY * kMapWidth + _mapX;
+ const uint8 *mapData = _mapData + mapOffset;
for (size_t i = 0; i < 10; ++i) {
for (size_t j = 0; j < 11; ++j) {
- uint8 tile = mapData[i * kMapwidth + j];
- mapFlags[0] = backdropFlags[2 * tile + 0];
- mapFlags[1] = backdropFlags[2 * tile + 1];
- mapFlags[2] = tile;
- mapFlags += 3;
+ uint8 tile = mapData[i * kMapWidth + j];
+ mapFlag->_flag = _backdropFlags[tile]._flag;
+ mapFlag->_flagEx = _backdropFlags[tile]._flagEx;
+ mapFlag->_type = tile;
+ mapFlag++;
}
}
}
-void DreamGenContext::showAllEx() {
- data.word(kListpos) = kExlist;
- memset(getSegment(data.word(kBuffers)).ptr(kExlist, 100 * 5), 0xff, 100 * 5);
+void DreamWebEngine::showAllEx() {
+ const unsigned int count = 100;
+
+ _exList.clear();
- data.word(kFrsegment) = data.word(kExtras);
- data.word(kDataad) = kExframedata;
- data.word(kFramesad) = kExframes;
- data.byte(kCurrentex) = 0;
- DynObject *objects = (DynObject *)getSegment(data.word(kExtras)).ptr(kExdata, sizeof(DynObject));
- for (size_t i = 0; i < 100; ++i, ++data.byte(kCurrentex)) {
+ DynObject *objects = _exData;
+ const GraphicsFile &frameBase = _exFrames;
+ for (size_t i = 0; i < count; ++i) {
DynObject *object = objects + i;
if (object->mapad[0] == 0xff)
continue;
- if (object->currentLocation != data.byte(kReallocation))
+ if (object->currentLocation != _realLocation)
continue;
- if (getMapAd(object->mapad) == 0)
+ uint16 x, y;
+ if (getMapAd(object->mapad, &x, &y) == 0)
continue;
uint8 width, height;
- uint16 currentFrame = 3 * data.byte(kCurrentex);
- calcFrFrame(currentFrame, &width, &height);
- uint16 x, y;
- finalFrame(&x, &y);
+ ObjPos objPos;
+ uint16 currentFrame = 3 * i;
+ calcFrFrame(frameBase._frames[currentFrame], &width, &height, x, y, &objPos);
if ((width != 0) || (height != 0)) {
assert(currentFrame < 256);
- showFrame((Frame *)getSegment(data.word(kFrsegment)).ptr(0, 0), x + data.word(kMapadx), y + data.word(kMapady), currentFrame, 0);
- ObjPos *objPos = (ObjPos *)getSegment(data.word(kBuffers)).ptr(data.word(kListpos), sizeof(ObjPos));
- objPos->xMin = data.byte(kSavex);
- objPos->yMin = data.byte(kSavey);
- objPos->xMax = data.byte(kSavesize + 0) + data.byte(kSavex);
- objPos->yMax = data.byte(kSavesize + 1) + data.byte(kSavey);
- objPos->index = i;
- data.word(kListpos) += sizeof(ObjPos);
+ showFrame(frameBase, x + _mapAdX, y + _mapAdY, currentFrame, 0);
+ objPos.index = i;
+ _exList.push_back(objPos);
}
}
}
-} // End of namespace DreamGen
+} // End of namespace DreamWeb