Skip to content

Commit

Permalink
DREAMWEB: Remove Extras segment
Browse files Browse the repository at this point in the history
  • Loading branch information
wjp committed Dec 27, 2011
1 parent 90cb52b commit e54196f
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 105 deletions.
1 change: 1 addition & 0 deletions devtools/tasmrecover/tasm-recover
Expand Up @@ -255,6 +255,7 @@ p = parser(skip_binary_data = [
'tempgraphics3',
'tempsprites',
'charset1',
'extras',
# vars.asm - constants
'openinvlist',
'ryaninvlist',
Expand Down
6 changes: 3 additions & 3 deletions engines/dreamweb/backdrop.cpp
Expand Up @@ -259,8 +259,8 @@ void DreamBase::showAllEx() {

_exList.clear();

DynObject *objects = (DynObject *)getSegment(data.word(kExtras)).ptr(kExdata, sizeof(DynObject));
const Frame *frameBase = (const Frame *)getSegment(data.word(kExtras)).ptr(0, 0);
DynObject *objects = _exData;
const GraphicsFile &frameBase = _exFrames;
for (size_t i = 0; i < count; ++i) {
DynObject *object = objects + i;
if (object->mapad[0] == 0xff)
Expand All @@ -273,7 +273,7 @@ void DreamBase::showAllEx() {
uint8 width, height;
ObjPos objPos;
uint16 currentFrame = 3 * i;
calcFrFrame(frameBase[currentFrame], &width, &height, x, y, &objPos);
calcFrFrame(frameBase._frames[currentFrame], &width, &height, x, y, &objPos);
if ((width != 0) || (height != 0)) {
assert(currentFrame < 256);
showFrame(frameBase, x + data.word(kMapadx), y + data.word(kMapady), currentFrame, 0);
Expand Down
11 changes: 9 additions & 2 deletions engines/dreamweb/dreambase.h
Expand Up @@ -51,6 +51,7 @@ const unsigned int kLenOfMapStore = 22*8*20*8;
const unsigned int kMapWidth = 66;
const unsigned int kMapHeight = 60;
const unsigned int kLengthOfMap = kMapWidth * kMapHeight;
const unsigned int kNumExObjects = 114;

/**
* This class is one of the parent classes of DreamGenContext. Its sole purpose
Expand Down Expand Up @@ -146,6 +147,12 @@ class DreamBase : public SegmentManager {
GraphicsFile _setFrames;
GraphicsFile _freeFrames;

// Extras segment (NB: this is saved)
GraphicsFile _exFrames;
DynObject _exData[kNumExObjects];
uint16 _exTextdatLE[kNumExObjects+2]; // TODO: Convert into TextFile
char _exText[18000];

public:
DreamBase(DreamWeb::DreamWebEngine *en);

Expand Down Expand Up @@ -845,10 +852,10 @@ class DreamBase : public SegmentManager {
void setMode();
void showPCX(const Common::String &name);
void showFrameInternal(const uint8 *pSrc, uint16 x, uint16 y, uint8 effectsFlag, uint8 width, uint8 height);
void showFrame(const GraphicsFile &frameData, uint16 x, uint16 y, uint16 frameNumber, uint8 effectsFlag, uint8 *width, uint8 *height);
void showFrame(const GraphicsFile &frameData, uint16 x, uint16 y, uint16 frameNumber, uint8 effectsFlag);
void showFrame(const Frame *frameData, uint16 x, uint16 y, uint16 frameNumber, uint8 effectsFlag, uint8 *width, uint8 *height);
void showFrame(const Frame *frameData, uint16 x, uint16 y, uint16 frameNumber, uint8 effectsFlag);
void showFrame(const GraphicsFile &frameData, uint16 x, uint16 y, uint16 frameNumber, uint8 effectsFlag, uint8 *width, uint8 *height);
void showFrame(const GraphicsFile &frameData, uint16 x, uint16 y, uint16 frameNumber, uint8 effectsFlag);
bool pixelCheckSet(const ObjPos *pos, uint8 x, uint8 y);
void loadPalFromIFF();
void createPanel();
Expand Down
8 changes: 4 additions & 4 deletions engines/dreamweb/dreamgen.cpp
Expand Up @@ -65,13 +65,13 @@ void DreamGenContext::__start() {
//0x0100: .... .... .... ....
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
//0x0110: .... .... .... ....
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
//0x0120: .... .... .... ....
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x17, 0x00, 0x00, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00,
//0x0130: .... .... .... ....
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
//0x0140: .... .... .... ....
0x00, 0xff, };
};
ds.assign(src, src + sizeof(src));
dreamweb();
}
Expand Down
71 changes: 35 additions & 36 deletions engines/dreamweb/dreamgen.h
Expand Up @@ -249,42 +249,41 @@ static const uint16 kWongame = 274;
static const uint16 kLasthardkey = 275;
static const uint16 kBufferin = 276;
static const uint16 kBufferout = 278;
static const uint16 kExtras = 280;
static const uint16 kWorkspace = 282;
static const uint16 kMainsprites = 284;
static const uint16 kBackdrop = 286;
static const uint16 kRecordspace = 288;
static const uint16 kFreedat = 290;
static const uint16 kSetdat = 292;
static const uint16 kReel1 = 294;
static const uint16 kReel2 = 296;
static const uint16 kReel3 = 298;
static const uint16 kRoomdesc = 300;
static const uint16 kFreedesc = 302;
static const uint16 kSetdesc = 304;
static const uint16 kBlockdesc = 306;
static const uint16 kSetframes = 308;
static const uint16 kFreeframes = 310;
static const uint16 kPeople = 312;
static const uint16 kReels = 314;
static const uint16 kBlinkframe = 316;
static const uint16 kBlinkcount = 317;
static const uint16 kReasseschanges = 318;
static const uint16 kPointerspath = 319;
static const uint16 kManspath = 320;
static const uint16 kPointerfirstpath = 321;
static const uint16 kFinaldest = 322;
static const uint16 kDestination = 323;
static const uint16 kLinestartx = 324;
static const uint16 kLinestarty = 326;
static const uint16 kLineendx = 328;
static const uint16 kLineendy = 330;
static const uint16 kLinepointer = 332;
static const uint16 kLinedirection = 333;
static const uint16 kLinelength = 334;
static const uint16 kCh0playing = 335;
static const uint16 kCh0repeat = 336;
static const uint16 kCh1playing = 337;
static const uint16 kWorkspace = 280;
static const uint16 kMainsprites = 282;
static const uint16 kBackdrop = 284;
static const uint16 kRecordspace = 286;
static const uint16 kFreedat = 288;
static const uint16 kSetdat = 290;
static const uint16 kReel1 = 292;
static const uint16 kReel2 = 294;
static const uint16 kReel3 = 296;
static const uint16 kRoomdesc = 298;
static const uint16 kFreedesc = 300;
static const uint16 kSetdesc = 302;
static const uint16 kBlockdesc = 304;
static const uint16 kSetframes = 306;
static const uint16 kFreeframes = 308;
static const uint16 kPeople = 310;
static const uint16 kReels = 312;
static const uint16 kBlinkframe = 314;
static const uint16 kBlinkcount = 315;
static const uint16 kReasseschanges = 316;
static const uint16 kPointerspath = 317;
static const uint16 kManspath = 318;
static const uint16 kPointerfirstpath = 319;
static const uint16 kFinaldest = 320;
static const uint16 kDestination = 321;
static const uint16 kLinestartx = 322;
static const uint16 kLinestarty = 324;
static const uint16 kLineendx = 326;
static const uint16 kLineendy = 328;
static const uint16 kLinepointer = 330;
static const uint16 kLinedirection = 331;
static const uint16 kLinelength = 332;
static const uint16 kCh0playing = 333;
static const uint16 kCh0repeat = 334;
static const uint16 kCh1playing = 335;
static const uint16 kBlocktextdat = (0);
static const uint16 kPersonframes = (0);
static const uint16 kDebuglevel1 = (0);
Expand Down
64 changes: 33 additions & 31 deletions engines/dreamweb/object.cpp
Expand Up @@ -83,12 +83,11 @@ void DreamBase::obToInv(uint8 index, uint8 flag, uint16 x, uint16 y) {
if (index == 0xff)
return;

if (flag == kExObjectType) {
Frame *extras = (Frame *)getSegment(data.word(kExtras)).ptr(0, 0);
showFrame(extras, x + 18, y + 19, 3 * index + 1, 128);
} else {
if (flag == kExObjectType)
showFrame(_exFrames, x + 18, y + 19, 3 * index + 1, 128);
else
showFrame(_freeFrames, x + 18, y + 19, 3 * index + 1, 128);
}

const DynObject *object = (const DynObject *)getAnyAdDir(index, flag);
bool worn = isItWorn(object);
if (worn)
Expand All @@ -99,12 +98,10 @@ void DreamBase::obPicture() {
if (data.byte(kObjecttype) == kSetObjectType1)
return;
uint8 frame = 3 * data.byte(kCommand) + 1;
if (data.byte(kObjecttype) == kExObjectType) {
const Frame *frames = (const Frame *)getSegment(data.word(kExtras)).ptr(0, 0);
showFrame(frames, 160, 68, frame, 0x80);
} else {
if (data.byte(kObjecttype) == kExObjectType)
showFrame(_exFrames, 160, 68, frame, 0x80);
else
showFrame(_freeFrames, 160, 68, frame, 0x80);
}
}

void DreamBase::obIcons() {
Expand Down Expand Up @@ -254,12 +251,12 @@ void DreamBase::inventory() {
}

void DreamBase::transferText(uint8 from, uint8 to) {
getSegment(data.word(kExtras)).word(kExtextdat + 2*to) = data.word(kExtextpos);
WRITE_LE_UINT16(&_exTextdatLE[to], data.word(kExtextpos));
uint16 freeTextOffset = 2*from;
uint16 srcOffset = getSegment(data.word(kFreedesc)).word(kFreetextdat + freeTextOffset);

const char *src = (const char *)getSegment(data.word(kFreedesc)).ptr(kFreetext + srcOffset, 0);
char *dst = (char *)getSegment(data.word(kExtras)).ptr(kExtext + data.word(kExtextpos), 0);
char *dst = _exText + data.word(kExtextpos);

size_t len = strlen(src);
memcpy(dst, src, len + 1);
Expand Down Expand Up @@ -429,47 +426,47 @@ void DreamBase::setPickup() {
}

void DreamBase::deleteExFrame(uint8 frameNum) {
Frame *frame = (Frame *)getSegment(data.word(kExtras)).ptr(kExframedata + sizeof(Frame)*frameNum, sizeof(Frame));
Frame *frame = &_exFrames._frames[frameNum];

uint16 frameSize = frame->width * frame->height;
// Note: the original asm didn't subtract frameSize from remainder
uint16 remainder = kExframeslen - frame->ptr() - frameSize;
uint16 startOff = kExframes + frame->ptr();
uint16 startOff = frame->ptr();
uint16 endOff = startOff + frameSize;

// Shift frame data after this one down
memmove(getSegment(data.word(kExtras)).ptr(startOff, remainder), getSegment(data.word(kExtras)).ptr(endOff, remainder), remainder);
memmove(&_exFrames._data[startOff], &_exFrames._data[endOff], remainder);

// Combined frame data is now frameSize smaller
data.word(kExframepos) -= frameSize;

// Adjust all frame pointers pointing into the shifted data
for (unsigned int i = 0; i < 3*kNumexobjects; ++i) {
frame = (Frame *)getSegment(data.word(kExtras)).ptr(kExframedata + sizeof(Frame)*i, sizeof(Frame));
frame = &_exFrames._frames[i];
if (frame->ptr() >= startOff)
frame->setPtr(frame->ptr() - frameSize);
}
}

void DreamBase::deleteExText(uint8 textNum) {
uint16 offset = getSegment(data.word(kExtras)).word(kExtextdat + 2*textNum);
uint16 offset = READ_LE_UINT16(&_exTextdatLE[textNum]);

uint16 startOff = kExtext + offset;
uint16 textSize = strlen((char *)getSegment(data.word(kExtras)).ptr(startOff, 0)) + 1;
uint16 startOff = offset;
uint16 textSize = strlen(&_exText[startOff]) + 1;
uint16 endOff = startOff + textSize;
uint16 remainder = kExtextlen - offset - textSize;

// Shift text data after this one down
memmove(getSegment(data.word(kExtras)).ptr(startOff, remainder), getSegment(data.word(kExtras)).ptr(endOff, remainder), remainder);
memmove(&_exText[startOff], &_exText[endOff], remainder);

// Combined text data is now frameSize smaller
data.word(kExtextpos) -= textSize;

// Adjust all text pointers pointing into the shifted data
for (unsigned int i = 0; i < kNumexobjects; ++i) {
uint16 t = getSegment(data.word(kExtras)).word(kExtextdat + 2*i);
uint16 t = READ_LE_UINT16(&_exTextdatLE[i]);
if (t >= offset + textSize)
getSegment(data.word(kExtras)).word(kExtextdat + 2*i) = t - textSize;
WRITE_LE_UINT16(&_exTextdatLE[i], t - textSize);
}
}

Expand Down Expand Up @@ -591,22 +588,26 @@ void DreamBase::purgeALocation(uint8 index) {
}

const uint8 *DreamBase::getObTextStart() {
uint16 textSeg, textDatOff, textOff;
const uint8 *textBase;
const uint8 *text;
uint16 textOff;
if (data.byte(kObjecttype) == kFreeObjectType) {
textSeg = data.word(kFreedesc);
textDatOff = kFreetextdat;
uint16 textSeg = data.word(kFreedesc);
uint16 textDatOff = kFreetextdat;
textOff = kFreetext;
textBase = getSegment(textSeg).ptr(textOff, 0);
text = textBase + getSegment(textSeg).word(textDatOff + 2*data.byte(kCommand));
} else if (data.byte(kObjecttype) == kSetObjectType1) {
textSeg = data.word(kSetdesc);
textDatOff = kSettextdat;
uint16 textSeg = data.word(kSetdesc);
uint16 textDatOff = kSettextdat;
textOff = kSettext;
textBase = getSegment(textSeg).ptr(textOff, 0);
text = textBase + getSegment(textSeg).word(textDatOff + 2*data.byte(kCommand));
} else {
textSeg = data.word(kExtras);
textDatOff = kExtextdat;
textBase = (const uint8 *)_exText;
textOff = kExtext;
text = textBase + READ_LE_UINT16(&_exTextdatLE[data.byte(kCommand)]);
}
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;
Expand Down Expand Up @@ -635,6 +636,7 @@ const uint8 *DreamBase::getObTextStart() {
text++;

// arbitrary give-up counter
// FIXME: Make this more precise to avoid reading out of bounds
if (text - (textBase - textOff) >= 8000) {
warning("Object description for %d/%d not found", data.byte(kObjecttype), data.byte(kCommand));
return obname;
Expand Down
18 changes: 16 additions & 2 deletions engines/dreamweb/saveload.cpp
Expand Up @@ -476,7 +476,14 @@ void DreamBase::savePosition(unsigned int slot, const char *descbuf) {
outSaveFile->write((const uint8 *)&header, sizeof(FileHeader));
outSaveFile->write(descbuf, len[0]);
outSaveFile->write(data.ptr(kStartvars, len[1]), len[1]);
outSaveFile->write(getSegment(data.word(kExtras)).ptr(kExframedata, len[2]), len[2]);

// the Extras segment:
outSaveFile->write((const uint8 *)_exFrames._frames, 2080);
outSaveFile->write((const uint8 *)_exFrames._data, kExframeslen);
outSaveFile->write((const uint8 *)_exData, sizeof(DynObject)*kNumexobjects);
outSaveFile->write((const uint8 *)_exTextdatLE, 2*(kNumExObjects+2));
outSaveFile->write((const uint8 *)_exText, kExtextlen);

outSaveFile->write(_listOfChanges, len[3]);

// len[4] == 48, which is sizeof(Room) plus 16 for 'Roomscango'
Expand Down Expand Up @@ -542,7 +549,14 @@ void DreamBase::loadPosition(unsigned int slot) {
inSaveFile->read(namebuf, 17);
}
inSaveFile->read(data.ptr(kStartvars, len[1]), len[1]);
inSaveFile->read(getSegment(data.word(kExtras)).ptr(kExframedata, len[2]), len[2]);

// the Extras segment:
inSaveFile->read((uint8 *)_exFrames._frames, 2080);
inSaveFile->read((uint8 *)_exFrames._data, kExframeslen);
inSaveFile->read((uint8 *)_exData, sizeof(DynObject)*kNumexobjects);
inSaveFile->read((uint8 *)_exTextdatLE, 2*(kNumExObjects+2));
inSaveFile->read((uint8 *)_exText, kExtextlen);

inSaveFile->read(_listOfChanges, len[3]);

// len[4] == 48, which is sizeof(Room) plus 16 for 'Roomscango'
Expand Down

0 comments on commit e54196f

Please sign in to comment.