AGI: Implement loader for V1 words.tok dictionary

This commit is contained in:
Jussi Pitkanen 2011-06-16 12:34:40 +03:00 committed by Eugene Sandulenko
parent c731f1f48c
commit 368a3722a3
3 changed files with 37 additions and 13 deletions

View File

@ -1024,6 +1024,7 @@ public:
public:
int showWords();
int loadWords(const char *);
int loadWords_v1(Common::File &f);
void unloadWords();
int findWord(const char *word, int *flen);
void dictionaryWords(char *);

View File

@ -26,33 +26,25 @@
#define IMAGE_SIZE 368640 // = 40 * 2 * 9 * 512 = tracks * sides * sectors * sector size
#define SECTOR_OFFSET(s) ((s) * 512)
#define DDP_BASE_SECTOR 0x1C2
#define DDP_LOGDIR_SEC SECTOR_OFFSET(171) + 5
#define DDP_LOGDIR_MAX 43
#define DDP_PICDIR_SEC SECTOR_OFFSET(180) + 5
#define DDP_PICDIR_MAX 30
#define DDP_VIEWDIR_SEC SECTOR_OFFSET(189) + 5
#define DDP_VIEWDIR_MAX 171
#define DDP_SNDDIR_SEC SECTOR_OFFSET(198) + 5
#define DDP_SNDDIR_MAX 64
#define BC_LOGDIR_SEC SECTOR_OFFSET(90) + 5
#define BC_LOGDIR_MAX 118
#define BC_VIEWDIR_SEC SECTOR_OFFSET(96) + 5
#define BC_VIEWDIR_MAX 180
#define BC_PICDIR_SEC SECTOR_OFFSET(93) + 8
#define BC_PICDIR_MAX 117
#define BC_SNDDIR_SEC SECTOR_OFFSET(99) + 5
#define BC_SNDDIR_MAX 29
#define BC_WORDS SECTOR_OFFSET(0x26D) + 5
namespace Agi {
@ -321,9 +313,14 @@ int AgiLoader_v1::loadObjects(const char *fname) {
return _vm->loadObjects(fname);
}
// TODO: Find the disk image equivalent.
int AgiLoader_v1::loadWords(const char *fname) {
return _vm->loadWords(fname);
if (_vm->getGameID() == GID_BC) {
Common::File f;
f.open(_filenameDisk0);
f.seek(BC_WORDS, SEEK_SET);
return _vm->loadWords_v1(f);
}
return errOK;
}
}

View File

@ -36,6 +36,33 @@ static char *myStrndup(const char *src, int n) {
return tmp;
}
int AgiEngine::loadWords_v1(Common::File &f) {
char str[64];
int k;
// Loop through alphabet, as words in the dictionary file are sorted by
// first character
f.seek(f.pos() + 26 * 2, SEEK_SET);
do {
// Read next word
for (k = 0; k < (int)sizeof(str) - 1; k++) {
str[k] = f.readByte();
if (str[k] == 0 || (uint8)str[k] == 0xFF)
break;
}
// And store it in our internal dictionary
if (k > 0) {
AgiWord *w = new AgiWord;
w->word = myStrndup(str, k + 1);
w->id = f.readUint16LE();
_game.words[str[0] - 'a'].push_back(w);
}
} while((uint8)str[0] != 0xFF);
return errOK;
}
int AgiEngine::loadWords(const char *fname) {
Common::File fp;
@ -50,8 +77,7 @@ int AgiEngine::loadWords(const char *fname) {
for (int i = 0; i < 26; i++) {
fp.seek(i * 2, SEEK_SET);
int offset = fp.readUint16BE();
if (offset == 0)
continue;
if (offset == 0) continue;
fp.seek(offset, SEEK_SET);
int k = fp.readByte();
while (!fp.eos() && !fp.err()) {