DREAMWEB: Convert room text into TextFiles

This commit is contained in:
Willem Jan Palenstijn 2011-12-27 22:21:43 +01:00
parent a7cdc342b3
commit d9aed2e00b
9 changed files with 77 additions and 105 deletions

View file

@ -261,6 +261,11 @@ p = parser(skip_binary_data = [
'reel1', 'reel1',
'reel2', 'reel2',
'reel3', 'reel3',
'setdesc',
'blockdesc',
'roomdesc',
'freedesc',
'people',
# vars.asm - constants # vars.asm - constants
'openinvlist', 'openinvlist',
'ryaninvlist', 'ryaninvlist',

View file

@ -143,12 +143,18 @@ protected:
GraphicsFile _mainSprites; GraphicsFile _mainSprites;
const GraphicsFile *_currentCharset; const GraphicsFile *_currentCharset;
// room graphics files // room files
GraphicsFile _setFrames; GraphicsFile _setFrames;
GraphicsFile _freeFrames; GraphicsFile _freeFrames;
GraphicsFile _reel1; GraphicsFile _reel1;
GraphicsFile _reel2; GraphicsFile _reel2;
GraphicsFile _reel3; GraphicsFile _reel3;
TextFile _setDesc;
TextFile _blockDesc;
TextFile _roomDesc;
TextFile _freeDesc;
TextFile _personText;
uint16 _personFramesLE[12];
// Extras segment (NB: this is saved) // Extras segment (NB: this is saved)
GraphicsFile _exFrames; GraphicsFile _exFrames;
@ -516,8 +522,6 @@ public:
void loadGraphicsFile(GraphicsFile &file, const char *fileName); void loadGraphicsFile(GraphicsFile &file, const char *fileName);
void loadGraphicsSegment(GraphicsFile &file, unsigned int len); void loadGraphicsSegment(GraphicsFile &file, unsigned int len);
void loadTextSegment(TextFile &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 loadIntoTemp(const char *fileName);
void loadIntoTemp2(const char *fileName); void loadIntoTemp2(const char *fileName);
void loadIntoTemp3(const char *fileName); void loadIntoTemp3(const char *fileName);

View file

@ -65,11 +65,9 @@ void DreamGenContext::__start() {
//0x0100: .... .... .... .... //0x0100: .... .... .... ....
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, 0x00,
//0x0110: .... .... .... .... //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: .... .... .... .... //0x0120: .... .... .... ....
0x17, 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, };
//0x0130: .... .... .... ....
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, };
ds.assign(src, src + sizeof(src)); ds.assign(src, src + sizeof(src));
dreamweb(); dreamweb();
} }

View file

@ -255,30 +255,25 @@ static const uint16 kBackdrop = 284;
static const uint16 kRecordspace = 286; static const uint16 kRecordspace = 286;
static const uint16 kFreedat = 288; static const uint16 kFreedat = 288;
static const uint16 kSetdat = 290; static const uint16 kSetdat = 290;
static const uint16 kRoomdesc = 292; static const uint16 kReels = 292;
static const uint16 kFreedesc = 294; static const uint16 kBlinkframe = 294;
static const uint16 kSetdesc = 296; static const uint16 kBlinkcount = 295;
static const uint16 kBlockdesc = 298; static const uint16 kReasseschanges = 296;
static const uint16 kPeople = 300; static const uint16 kPointerspath = 297;
static const uint16 kReels = 302; static const uint16 kManspath = 298;
static const uint16 kBlinkframe = 304; static const uint16 kPointerfirstpath = 299;
static const uint16 kBlinkcount = 305; static const uint16 kFinaldest = 300;
static const uint16 kReasseschanges = 306; static const uint16 kDestination = 301;
static const uint16 kPointerspath = 307; static const uint16 kLinestartx = 302;
static const uint16 kManspath = 308; static const uint16 kLinestarty = 304;
static const uint16 kPointerfirstpath = 309; static const uint16 kLineendx = 306;
static const uint16 kFinaldest = 310; static const uint16 kLineendy = 308;
static const uint16 kDestination = 311; static const uint16 kLinepointer = 310;
static const uint16 kLinestartx = 312; static const uint16 kLinedirection = 311;
static const uint16 kLinestarty = 314; static const uint16 kLinelength = 312;
static const uint16 kLineendx = 316; static const uint16 kCh0playing = 313;
static const uint16 kLineendy = 318; static const uint16 kCh0repeat = 314;
static const uint16 kLinepointer = 320; static const uint16 kCh1playing = 315;
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 kBlocktextdat = (0); static const uint16 kBlocktextdat = (0);
static const uint16 kPersonframes = (0); static const uint16 kPersonframes = (0);
static const uint16 kDebuglevel1 = (0); static const uint16 kDebuglevel1 = (0);

View file

@ -407,7 +407,10 @@ uint8 DreamWebEngine::modifyChar(uint8 c) const {
namespace DreamGen { namespace DreamGen {
// FIXME/TODO: Move this to a better place. // 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); _openChangeSize = kInventx+(4*kItempicsize);
_quitRequested = false; _quitRequested = false;

View file

@ -252,10 +252,7 @@ void DreamBase::inventory() {
void DreamBase::transferText(uint8 from, uint8 to) { void DreamBase::transferText(uint8 from, uint8 to) {
_exText.setOffset(to, data.word(kExtextpos)); _exText.setOffset(to, data.word(kExtextpos));
uint16 freeTextOffset = 2*from; const char *src = _freeDesc.getString(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 = _exText._text + data.word(kExtextpos); char *dst = _exText._text + data.word(kExtextpos);
size_t len = strlen(src); size_t len = strlen(src);
@ -592,17 +589,13 @@ const uint8 *DreamBase::getObTextStart() {
const uint8 *text; const uint8 *text;
uint16 textOff; uint16 textOff;
if (data.byte(kObjecttype) == kFreeObjectType) { if (data.byte(kObjecttype) == kFreeObjectType) {
uint16 textSeg = data.word(kFreedesc); textBase = (const uint8 *)_freeDesc._text;
uint16 textDatOff = kFreetextdat;
textOff = kFreetext; textOff = kFreetext;
textBase = getSegment(textSeg).ptr(textOff, 0); text = (const uint8 *)_freeDesc.getString(data.byte(kCommand));
text = textBase + getSegment(textSeg).word(textDatOff + 2*data.byte(kCommand));
} else if (data.byte(kObjecttype) == kSetObjectType1) { } else if (data.byte(kObjecttype) == kSetObjectType1) {
uint16 textSeg = data.word(kSetdesc); textBase = (const uint8 *)_setDesc._text;
uint16 textDatOff = kSettextdat;
textOff = kSettext; textOff = kSettext;
textBase = getSegment(textSeg).ptr(textOff, 0); text = (const uint8 *)_setDesc.getString(data.byte(kCommand));
text = textBase + getSegment(textSeg).word(textDatOff + 2*data.byte(kCommand));
} else { } else {
textBase = (const uint8 *)_exText._text; textBase = (const uint8 *)_exText._text;
textOff = kExtext; textOff = kExtext;

View file

@ -1102,12 +1102,12 @@ void DreamBase::clearBeforeLoad() {
_backdropBlocks = 0; _backdropBlocks = 0;
_setFrames.clear(); _setFrames.clear();
deallocateMem(data.word(kReels)); deallocateMem(data.word(kReels));
deallocateMem(data.word(kPeople)); _personText.clear();
deallocateMem(data.word(kSetdesc)); _setDesc.clear();
deallocateMem(data.word(kBlockdesc)); _blockDesc.clear();
deallocateMem(data.word(kRoomdesc)); _roomDesc.clear();
_freeFrames.clear(); _freeFrames.clear();
deallocateMem(data.word(kFreedesc)); _freeDesc.clear();
data.byte(kRoomloaded) = 0; data.byte(kRoomloaded) = 0;
} }

View file

@ -658,6 +658,11 @@ done: // The engine will need some cleaner finalization, let's put it here for n
_reel1.clear(); _reel1.clear();
_reel2.clear(); _reel2.clear();
_reel3.clear(); _reel3.clear();
_setDesc.clear();
_blockDesc.clear();
_roomDesc.clear();
_freeDesc.clear();
_personText.clear();
_textFile1.clear(); _textFile1.clear();
_textFile2.clear(); _textFile2.clear();
@ -773,31 +778,6 @@ void DreamBase::switchRyanOff() {
data.byte(kRyanon) = 1; 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) { void DreamBase::loadGraphicsFile(GraphicsFile &file, const char *fileName) {
FileHeader header; FileHeader header;
@ -1248,20 +1228,16 @@ bool DreamBase::checkIfEx(uint8 x, uint8 y) {
const uint8 *DreamBase::findObName(uint8 type, uint8 index) { const uint8 *DreamBase::findObName(uint8 type, uint8 index) {
if (type == 5) { if (type == 5) {
uint16 i = 64 * 2 * (index & 127); uint16 i = 64 * (index & 127);
uint16 offset = getSegment(data.word(kPeople)).word(kPersontxtdat + i) + kPersontext; return (const uint8 *)_personText.getString(i);
return getSegment(data.word(kPeople)).ptr(offset, 0);
} else if (type == 4) { } else if (type == 4) {
return (const uint8 *)_exText.getString(index); return (const uint8 *)_exText.getString(index);
} else if (type == 2) { } else if (type == 2) {
uint16 offset = getSegment(data.word(kFreedesc)).word(kFreetextdat + index * 2) + kFreetext; return (const uint8 *)_freeDesc.getString(index);
return getSegment(data.word(kFreedesc)).ptr(offset, 0);
} else if (type == 1) { } else if (type == 1) {
uint16 offset = getSegment(data.word(kSetdesc)).word(kSettextdat + index * 2) + kSettext; return (const uint8 *)_setDesc.getString(index);
return getSegment(data.word(kSetdesc)).ptr(offset, 0);
} else { } else {
uint16 offset = getSegment(data.word(kBlockdesc)).word(kBlocktextdat + index * 2) + kBlocktext; return (const uint8 *)_blockDesc.getString(index);
return getSegment(data.word(kBlockdesc)).ptr(offset, 0);
} }
} }
@ -1736,9 +1712,8 @@ bool DreamBase::isRyanHolding(const char *id) {
} }
bool DreamBase::isItDescribed(const ObjPos *pos) { bool DreamBase::isItDescribed(const ObjPos *pos) {
uint16 offset = getSegment(data.word(kSetdesc)).word(kSettextdat + pos->index * 2); const char *string = _setDesc.getString(pos->index);
uint8 result = getSegment(data.word(kSetdesc)).byte(kSettext + offset); return string[0] != 0;
return result != 0;
} }
bool DreamBase::isCD() { bool DreamBase::isCD() {
@ -2050,8 +2025,7 @@ void DreamBase::roomName() {
textIndex -= 32; textIndex -= 32;
data.word(kLinespacing) = 7; data.word(kLinespacing) = 7;
uint8 maxWidth = (data.byte(kWatchon) == 1) ? 120 : 160; uint8 maxWidth = (data.byte(kWatchon) == 1) ? 120 : 160;
uint16 descOffset = getSegment(data.word(kRoomdesc)).word(kIntextdat + textIndex * 2); const uint8 *string = (const uint8 *)_roomDesc.getString(textIndex);
const uint8 *string = getSegment(data.word(kRoomdesc)).ptr(kIntext + descOffset, 0);
printDirect(string, 88, 25, maxWidth, false); printDirect(string, 88, 25, maxWidth, false);
data.word(kLinespacing) = 10; data.word(kLinespacing) = 10;
useCharset1(); useCharset1();
@ -2142,8 +2116,7 @@ void DreamBase::doLook() {
data.byte(kCommandtype) = 255; data.byte(kCommandtype) = 255;
dumpTextLine(); dumpTextLine();
uint8 index = data.byte(kRoomnum) & 31; uint8 index = data.byte(kRoomnum) & 31;
uint16 offset = getSegment(data.word(kRoomdesc)).word(kIntextdat + index * 2); const uint8 *string = (const uint8 *)_roomDesc.getString(index);
const uint8 *string = getSegment(data.word(kRoomdesc)).ptr(kIntext, 0) + offset;
findNextColon(&string); findNextColon(&string);
uint16 x; uint16 x;
if (data.byte(kReallocation) < 50) if (data.byte(kReallocation) < 50)
@ -2196,12 +2169,12 @@ void DreamBase::getRidOfAll() {
_reel2.clear(); _reel2.clear();
_reel3.clear(); _reel3.clear();
deallocateMem(data.word(kReels)); deallocateMem(data.word(kReels));
deallocateMem(data.word(kPeople)); _personText.clear();
deallocateMem(data.word(kSetdesc)); _setDesc.clear();
deallocateMem(data.word(kBlockdesc)); _blockDesc.clear();
deallocateMem(data.word(kRoomdesc)); _roomDesc.clear();
_freeFrames.clear(); _freeFrames.clear();
deallocateMem(data.word(kFreedesc)); _freeDesc.clear();
} }
// if skipDat, skip clearing and loading Setdat and Freedat // if skipDat, skip clearing and loading Setdat and Freedat
@ -2236,18 +2209,20 @@ void DreamBase::loadRoomData(const Room &room, bool skipDat) {
loadGraphicsSegment(_reel2, len[5]); loadGraphicsSegment(_reel2, len[5]);
loadGraphicsSegment(_reel3, len[6]); loadGraphicsSegment(_reel3, len[6]);
data.word(kReels) = allocateAndLoad(len[7]); data.word(kReels) = allocateAndLoad(len[7]);
data.word(kPeople) = allocateAndLoad(len[8]);
// TODO: kSetdesc, kBlockdesc, kRoomdesc are also TextFiles? // segment 8 consists of 12 personFrames followed by a TextFile
data.word(kSetdesc) = allocateAndLoad(len[9]); engine->readFromFile((uint8 *)_personFramesLE, 24);
data.word(kBlockdesc) = allocateAndLoad(len[10]); loadTextSegment(_personText, len[8] - 24);
data.word(kRoomdesc) = allocateAndLoad(len[11]);
loadTextSegment(_setDesc, len[9]);
loadTextSegment(_blockDesc, len[10]);
loadTextSegment(_roomDesc, len[11]);
loadGraphicsSegment(_freeFrames, len[12]); loadGraphicsSegment(_freeFrames, len[12]);
if (!skipDat) if (!skipDat)
clearAndLoad(data.word(kFreedat), 255, len[13], kFreedatlen); clearAndLoad(data.word(kFreedat), 255, len[13], kFreedatlen);
else else
engine->skipBytes(len[13]); engine->skipBytes(len[13]);
// TODO: kFreedesc is also a TextFile? loadTextSegment(_freeDesc, len[14]);
data.word(kFreedesc) = allocateAndLoad(len[14]);
engine->closeFile(); engine->closeFile();
} }

View file

@ -81,7 +81,7 @@ void DreamBase::convIcons() {
} }
uint16 DreamBase::getPersFrame(uint8 index) { uint16 DreamBase::getPersFrame(uint8 index) {
return getSegment(data.word(kPeople)).word(kPersonframes + index * 2); return READ_LE_UINT16(&_personFramesLE[index]);
} }
void DreamBase::startTalk() { void DreamBase::startTalk() {
@ -108,8 +108,7 @@ void DreamBase::startTalk() {
} }
const uint8 *DreamBase::getPersonText(uint8 index, uint8 talkPos) { const uint8 *DreamBase::getPersonText(uint8 index, uint8 talkPos) {
uint16 offset = kPersontext + getSegment(data.word(kPeople)).word(((index * 64 + talkPos) * 2) + kPersontxtdat); return (const uint8 *)_personText.getString(index*64 + talkPos);
return getSegment(data.word(kPeople)).ptr(offset, 0);
} }
void DreamBase::moreTalk() { void DreamBase::moreTalk() {