Skip to content

Commit

Permalink
DREAMWEB: Convert room text into TextFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
wjp committed Dec 27, 2011
1 parent a7cdc34 commit d9aed2e
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 105 deletions.
5 changes: 5 additions & 0 deletions devtools/tasmrecover/tasm-recover
Expand Up @@ -261,6 +261,11 @@ p = parser(skip_binary_data = [
'reel1',
'reel2',
'reel3',
'setdesc',
'blockdesc',
'roomdesc',
'freedesc',
'people',
# vars.asm - constants
'openinvlist',
'ryaninvlist',
Expand Down
10 changes: 7 additions & 3 deletions engines/dreamweb/dreambase.h
Expand Up @@ -143,12 +143,18 @@ class DreamBase : public SegmentManager {
GraphicsFile _mainSprites;
const GraphicsFile *_currentCharset;

// room graphics files
// room files
GraphicsFile _setFrames;
GraphicsFile _freeFrames;
GraphicsFile _reel1;
GraphicsFile _reel2;
GraphicsFile _reel3;
TextFile _setDesc;
TextFile _blockDesc;
TextFile _roomDesc;
TextFile _freeDesc;
TextFile _personText;
uint16 _personFramesLE[12];

// Extras segment (NB: this is saved)
GraphicsFile _exFrames;
Expand Down Expand Up @@ -516,8 +522,6 @@ class DreamBase : public SegmentManager {
void loadGraphicsFile(GraphicsFile &file, const char *fileName);
void loadGraphicsSegment(GraphicsFile &file, unsigned int len);
void loadTextSegment(TextFile &file, unsigned int len);
uint16 standardLoad(const char *fileName, uint16 *outSizeInBytes = NULL); // Returns a segment handle which needs to be freed with deallocatemem for symmetry
void *standardLoadCPP(const char *fileName, uint16 *outSizeInBytes = NULL); // And this one should be 'free'd
void loadIntoTemp(const char *fileName);
void loadIntoTemp2(const char *fileName);
void loadIntoTemp3(const char *fileName);
Expand Down
6 changes: 2 additions & 4 deletions engines/dreamweb/dreamgen.cpp
Expand Up @@ -65,11 +65,9 @@ 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, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
//0x0120: .... .... .... ....
0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
//0x0130: .... .... .... ....
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, };
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, };
ds.assign(src, src + sizeof(src));
dreamweb();
}
Expand Down
43 changes: 19 additions & 24 deletions engines/dreamweb/dreamgen.h
Expand Up @@ -255,30 +255,25 @@ static const uint16 kBackdrop = 284;
static const uint16 kRecordspace = 286;
static const uint16 kFreedat = 288;
static const uint16 kSetdat = 290;
static const uint16 kRoomdesc = 292;
static const uint16 kFreedesc = 294;
static const uint16 kSetdesc = 296;
static const uint16 kBlockdesc = 298;
static const uint16 kPeople = 300;
static const uint16 kReels = 302;
static const uint16 kBlinkframe = 304;
static const uint16 kBlinkcount = 305;
static const uint16 kReasseschanges = 306;
static const uint16 kPointerspath = 307;
static const uint16 kManspath = 308;
static const uint16 kPointerfirstpath = 309;
static const uint16 kFinaldest = 310;
static const uint16 kDestination = 311;
static const uint16 kLinestartx = 312;
static const uint16 kLinestarty = 314;
static const uint16 kLineendx = 316;
static const uint16 kLineendy = 318;
static const uint16 kLinepointer = 320;
static const uint16 kLinedirection = 321;
static const uint16 kLinelength = 322;
static const uint16 kCh0playing = 323;
static const uint16 kCh0repeat = 324;
static const uint16 kCh1playing = 325;
static const uint16 kReels = 292;
static const uint16 kBlinkframe = 294;
static const uint16 kBlinkcount = 295;
static const uint16 kReasseschanges = 296;
static const uint16 kPointerspath = 297;
static const uint16 kManspath = 298;
static const uint16 kPointerfirstpath = 299;
static const uint16 kFinaldest = 300;
static const uint16 kDestination = 301;
static const uint16 kLinestartx = 302;
static const uint16 kLinestarty = 304;
static const uint16 kLineendx = 306;
static const uint16 kLineendy = 308;
static const uint16 kLinepointer = 310;
static const uint16 kLinedirection = 311;
static const uint16 kLinelength = 312;
static const uint16 kCh0playing = 313;
static const uint16 kCh0repeat = 314;
static const uint16 kCh1playing = 315;
static const uint16 kBlocktextdat = (0);
static const uint16 kPersonframes = (0);
static const uint16 kDebuglevel1 = (0);
Expand Down
5 changes: 4 additions & 1 deletion engines/dreamweb/dreamweb.cpp
Expand Up @@ -407,7 +407,10 @@ uint8 DreamWebEngine::modifyChar(uint8 c) const {
namespace DreamGen {

// FIXME/TODO: Move this to a better place.
DreamBase::DreamBase(DreamWeb::DreamWebEngine *en) : engine(en), _exText(kNumExObjects+2) {
DreamBase::DreamBase(DreamWeb::DreamWebEngine *en) :
engine(en), _exText(kNumExObjects+2),
_setDesc(130), _blockDesc(98), _roomDesc(38), _freeDesc(82), _personText(1026) {

_openChangeSize = kInventx+(4*kItempicsize);
_quitRequested = false;

Expand Down
17 changes: 5 additions & 12 deletions engines/dreamweb/object.cpp
Expand Up @@ -252,10 +252,7 @@ void DreamBase::inventory() {

void DreamBase::transferText(uint8 from, uint8 to) {
_exText.setOffset(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);
const char *src = _freeDesc.getString(from);
char *dst = _exText._text + data.word(kExtextpos);

size_t len = strlen(src);
Expand Down Expand Up @@ -592,17 +589,13 @@ const uint8 *DreamBase::getObTextStart() {
const uint8 *text;
uint16 textOff;
if (data.byte(kObjecttype) == kFreeObjectType) {
uint16 textSeg = data.word(kFreedesc);
uint16 textDatOff = kFreetextdat;
textBase = (const uint8 *)_freeDesc._text;
textOff = kFreetext;
textBase = getSegment(textSeg).ptr(textOff, 0);
text = textBase + getSegment(textSeg).word(textDatOff + 2*data.byte(kCommand));
text = (const uint8 *)_freeDesc.getString(data.byte(kCommand));
} else if (data.byte(kObjecttype) == kSetObjectType1) {
uint16 textSeg = data.word(kSetdesc);
uint16 textDatOff = kSettextdat;
textBase = (const uint8 *)_setDesc._text;
textOff = kSettext;
textBase = getSegment(textSeg).ptr(textOff, 0);
text = textBase + getSegment(textSeg).word(textDatOff + 2*data.byte(kCommand));
text = (const uint8 *)_setDesc.getString(data.byte(kCommand));
} else {
textBase = (const uint8 *)_exText._text;
textOff = kExtext;
Expand Down
10 changes: 5 additions & 5 deletions engines/dreamweb/sprite.cpp
Expand Up @@ -1102,12 +1102,12 @@ void DreamBase::clearBeforeLoad() {
_backdropBlocks = 0;
_setFrames.clear();
deallocateMem(data.word(kReels));
deallocateMem(data.word(kPeople));
deallocateMem(data.word(kSetdesc));
deallocateMem(data.word(kBlockdesc));
deallocateMem(data.word(kRoomdesc));
_personText.clear();
_setDesc.clear();
_blockDesc.clear();
_roomDesc.clear();
_freeFrames.clear();
deallocateMem(data.word(kFreedesc));
_freeDesc.clear();

data.byte(kRoomloaded) = 0;
}
Expand Down
81 changes: 28 additions & 53 deletions engines/dreamweb/stubs.cpp
Expand Up @@ -658,6 +658,11 @@ void DreamBase::dreamweb() {
_reel1.clear();
_reel2.clear();
_reel3.clear();
_setDesc.clear();
_blockDesc.clear();
_roomDesc.clear();
_freeDesc.clear();
_personText.clear();

_textFile1.clear();
_textFile2.clear();
Expand Down Expand Up @@ -773,31 +778,6 @@ void DreamBase::switchRyanOff() {
data.byte(kRyanon) = 1;
}

uint16 DreamBase::standardLoad(const char *fileName, uint16 *outSizeInBytes) {
FileHeader header;

Common::File file;
file.open(fileName);
file.read((uint8 *)&header, sizeof(FileHeader));
uint16 sizeInBytes = header.len(0);
if (outSizeInBytes)
*outSizeInBytes = sizeInBytes;
uint16 result = allocateMem((sizeInBytes + 15) / 16);
file.read(getSegment(result).ptr(0, 0), sizeInBytes);
return result;
}

void *DreamBase::standardLoadCPP(const char *fileName, uint16 *outSizeInBytes) {
uint16 sizeInBytes;
uint16 seg = standardLoad(fileName, &sizeInBytes);
void *buffer = malloc(sizeInBytes);
memcpy(buffer, getSegment(seg).ptr(0, 0), sizeInBytes);
deallocateMem(seg);
if (outSizeInBytes)
*outSizeInBytes = sizeInBytes;
return buffer;
}

void DreamBase::loadGraphicsFile(GraphicsFile &file, const char *fileName) {
FileHeader header;

Expand Down Expand Up @@ -1248,20 +1228,16 @@ bool DreamBase::checkIfEx(uint8 x, uint8 y) {

const uint8 *DreamBase::findObName(uint8 type, uint8 index) {
if (type == 5) {
uint16 i = 64 * 2 * (index & 127);
uint16 offset = getSegment(data.word(kPeople)).word(kPersontxtdat + i) + kPersontext;
return getSegment(data.word(kPeople)).ptr(offset, 0);
uint16 i = 64 * (index & 127);
return (const uint8 *)_personText.getString(i);
} else if (type == 4) {
return (const uint8 *)_exText.getString(index);
} else if (type == 2) {
uint16 offset = getSegment(data.word(kFreedesc)).word(kFreetextdat + index * 2) + kFreetext;
return getSegment(data.word(kFreedesc)).ptr(offset, 0);
return (const uint8 *)_freeDesc.getString(index);
} else if (type == 1) {
uint16 offset = getSegment(data.word(kSetdesc)).word(kSettextdat + index * 2) + kSettext;
return getSegment(data.word(kSetdesc)).ptr(offset, 0);
return (const uint8 *)_setDesc.getString(index);
} else {
uint16 offset = getSegment(data.word(kBlockdesc)).word(kBlocktextdat + index * 2) + kBlocktext;
return getSegment(data.word(kBlockdesc)).ptr(offset, 0);
return (const uint8 *)_blockDesc.getString(index);
}
}

Expand Down Expand Up @@ -1736,9 +1712,8 @@ bool DreamBase::isRyanHolding(const char *id) {
}

bool DreamBase::isItDescribed(const ObjPos *pos) {
uint16 offset = getSegment(data.word(kSetdesc)).word(kSettextdat + pos->index * 2);
uint8 result = getSegment(data.word(kSetdesc)).byte(kSettext + offset);
return result != 0;
const char *string = _setDesc.getString(pos->index);
return string[0] != 0;
}

bool DreamBase::isCD() {
Expand Down Expand Up @@ -2050,8 +2025,7 @@ void DreamBase::roomName() {
textIndex -= 32;
data.word(kLinespacing) = 7;
uint8 maxWidth = (data.byte(kWatchon) == 1) ? 120 : 160;
uint16 descOffset = getSegment(data.word(kRoomdesc)).word(kIntextdat + textIndex * 2);
const uint8 *string = getSegment(data.word(kRoomdesc)).ptr(kIntext + descOffset, 0);
const uint8 *string = (const uint8 *)_roomDesc.getString(textIndex);
printDirect(string, 88, 25, maxWidth, false);
data.word(kLinespacing) = 10;
useCharset1();
Expand Down Expand Up @@ -2142,8 +2116,7 @@ void DreamBase::doLook() {
data.byte(kCommandtype) = 255;
dumpTextLine();
uint8 index = data.byte(kRoomnum) & 31;
uint16 offset = getSegment(data.word(kRoomdesc)).word(kIntextdat + index * 2);
const uint8 *string = getSegment(data.word(kRoomdesc)).ptr(kIntext, 0) + offset;
const uint8 *string = (const uint8 *)_roomDesc.getString(index);
findNextColon(&string);
uint16 x;
if (data.byte(kReallocation) < 50)
Expand Down Expand Up @@ -2196,12 +2169,12 @@ void DreamBase::getRidOfAll() {
_reel2.clear();
_reel3.clear();
deallocateMem(data.word(kReels));
deallocateMem(data.word(kPeople));
deallocateMem(data.word(kSetdesc));
deallocateMem(data.word(kBlockdesc));
deallocateMem(data.word(kRoomdesc));
_personText.clear();
_setDesc.clear();
_blockDesc.clear();
_roomDesc.clear();
_freeFrames.clear();
deallocateMem(data.word(kFreedesc));
_freeDesc.clear();
}

// if skipDat, skip clearing and loading Setdat and Freedat
Expand Down Expand Up @@ -2236,18 +2209,20 @@ void DreamBase::loadRoomData(const Room &room, bool skipDat) {
loadGraphicsSegment(_reel2, len[5]);
loadGraphicsSegment(_reel3, len[6]);
data.word(kReels) = allocateAndLoad(len[7]);
data.word(kPeople) = allocateAndLoad(len[8]);
// TODO: kSetdesc, kBlockdesc, kRoomdesc are also TextFiles?
data.word(kSetdesc) = allocateAndLoad(len[9]);
data.word(kBlockdesc) = allocateAndLoad(len[10]);
data.word(kRoomdesc) = allocateAndLoad(len[11]);

// segment 8 consists of 12 personFrames followed by a TextFile
engine->readFromFile((uint8 *)_personFramesLE, 24);
loadTextSegment(_personText, len[8] - 24);

loadTextSegment(_setDesc, len[9]);
loadTextSegment(_blockDesc, len[10]);
loadTextSegment(_roomDesc, len[11]);
loadGraphicsSegment(_freeFrames, len[12]);
if (!skipDat)
clearAndLoad(data.word(kFreedat), 255, len[13], kFreedatlen);
else
engine->skipBytes(len[13]);
// TODO: kFreedesc is also a TextFile?
data.word(kFreedesc) = allocateAndLoad(len[14]);
loadTextSegment(_freeDesc, len[14]);

engine->closeFile();
}
Expand Down
5 changes: 2 additions & 3 deletions engines/dreamweb/talk.cpp
Expand Up @@ -81,7 +81,7 @@ void DreamBase::convIcons() {
}

uint16 DreamBase::getPersFrame(uint8 index) {
return getSegment(data.word(kPeople)).word(kPersonframes + index * 2);
return READ_LE_UINT16(&_personFramesLE[index]);
}

void DreamBase::startTalk() {
Expand All @@ -108,8 +108,7 @@ void DreamBase::startTalk() {
}

const uint8 *DreamBase::getPersonText(uint8 index, uint8 talkPos) {
uint16 offset = kPersontext + getSegment(data.word(kPeople)).word(((index * 64 + talkPos) * 2) + kPersontxtdat);
return getSegment(data.word(kPeople)).ptr(offset, 0);
return (const uint8 *)_personText.getString(index*64 + talkPos);
}

void DreamBase::moreTalk() {
Expand Down

0 comments on commit d9aed2e

Please sign in to comment.