Skip to content

Commit

Permalink
TEENAGENT: Add Resource code to precompute Dialog Offsets.
Browse files Browse the repository at this point in the history
This should allow the removal of most/all of the hardcoded eseg
addresses in the Dialog calls.
  • Loading branch information
digitall committed Jul 11, 2012
1 parent 7831254 commit c05dfdd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
28 changes: 28 additions & 0 deletions engines/teenagent/resources.cpp
Expand Up @@ -57,6 +57,32 @@ quick note on varia resources:
#define DSEG_SIZE 59280 // 0xe790
#define ESEG_SIZE 35810 // 0x8be2

void Resources::precomputeDialogOffsets() {
dialogOffsets.push_back(0);
int n = 0;
uint8 current, last = 0xff;
for (uint i = 0; i < eseg.size(); i++) {
current = eseg.get_byte(i);

if (n == 4) {
dialogOffsets.push_back(i);
n = 0;
}

if (current != 0x00 && last == 0x00)
n = 0;

if (current == 0x00)
n++;

last = current;
}

debug(1, "Resources::precomputeDialogOffsets() - Found %d dialogs", dialogOffsets.size());
for (uint i = 0; i < dialogOffsets.size(); i++)
debug(1, "\tDialog #%d: Offset 0x%04x", i, dialogOffsets[i]);
}

bool Resources::loadArchives(const ADGameDescription *gd) {
Common::File *dat_file = new Common::File();
if (!dat_file->open("teenagent.dat")) {
Expand All @@ -73,6 +99,8 @@ bool Resources::loadArchives(const ADGameDescription *gd) {

delete dat;

precomputeDialogOffsets();

FilePack varia;
varia.open("varia.res");
font7.load(varia, 7);
Expand Down
10 changes: 9 additions & 1 deletion engines/teenagent/resources.h
Expand Up @@ -52,8 +52,16 @@ class Resources {
FilePack off, on, ons, lan000, lan500, sam_mmm, sam_sam, mmm, voices;
#endif

Segment cseg, dseg, eseg;
Segment cseg, dseg;
Font font7, font8;

const byte *getDialog(uint16 dialogNum) { return eseg.ptr(dialogOffsets[dialogNum]); }

Segment eseg;
private:
void precomputeDialogOffsets();

Common::Array<uint16> dialogOffsets;
};

} // End of namespace TeenAgent
Expand Down

0 comments on commit c05dfdd

Please sign in to comment.