From 1dbe5bfccfb3d10b31ea9b5ac567165c650b3f98 Mon Sep 17 00:00:00 2001 From: Jussi Pitkanen Date: Sun, 19 Jun 2011 17:46:23 +0300 Subject: AGI: Implement loader for V1 "object" file --- engines/agi/agi.h | 9 +++++++-- engines/agi/loader_v1.cpp | 10 ++++++++-- engines/agi/objects.cpp | 36 +++++++++++++++++++++++++----------- 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/engines/agi/agi.h b/engines/agi/agi.h index 48a9aa5fbd..1c89718a6e 100644 --- a/engines/agi/agi.h +++ b/engines/agi/agi.h @@ -969,16 +969,21 @@ public: void checkQuickLoad(); // Objects +public: int showObjects(); - int decodeObjects(uint8 *mem, uint32 flen); int loadObjects(const char *fname); - int allocObjects(int); + int loadObjects(Common::File &fp); void unloadObjects(); const char *objectName(unsigned int); int objectGetLocation(unsigned int); void objectSetLocation(unsigned int, int); +private: + int decodeObjects(uint8 *mem, uint32 flen); + int readObjects(Common::File &fp, int flen); + int allocObjects(int); // Logic +public: int decodeLogic(int); void unloadLogic(int); int runLogic(int); diff --git a/engines/agi/loader_v1.cpp b/engines/agi/loader_v1.cpp index 02a20c9bc8..8da74cefed 100644 --- a/engines/agi/loader_v1.cpp +++ b/engines/agi/loader_v1.cpp @@ -45,6 +45,7 @@ #define BC_SNDDIR_SEC SECTOR_OFFSET(99) + 5 #define BC_SNDDIR_MAX 29 #define BC_WORDS SECTOR_OFFSET(0x26D) + 5 +#define BC_OBJECTS SECTOR_OFFSET(0x1E6) + 3 namespace Agi { @@ -308,9 +309,14 @@ int AgiLoader_v1::unloadResource(int t, int n) { return errOK; } -// TODO: Find the disk image equivalent. int AgiLoader_v1::loadObjects(const char *fname) { - return _vm->loadObjects(fname); + if (_vm->getGameID() == GID_BC) { + Common::File f; + f.open(_filenameDisk0); + f.seek(BC_OBJECTS, SEEK_SET); + return _vm->loadObjects(f); + } + return errOK; } int AgiLoader_v1::loadWords(const char *fname) { diff --git a/engines/agi/objects.cpp b/engines/agi/objects.cpp index e04c9742f3..efc8645287 100644 --- a/engines/agi/objects.cpp +++ b/engines/agi/objects.cpp @@ -34,7 +34,7 @@ int AgiEngine::allocObjects(int n) { } int AgiEngine::decodeObjects(uint8 *mem, uint32 flen) { - unsigned int i, so, padsize; + unsigned int i, so, padsize, spos; padsize = _game.gameFlags & ID_AMIGA ? 4 : 3; @@ -64,11 +64,12 @@ int AgiEngine::decodeObjects(uint8 *mem, uint32 flen) { return errNotEnoughMemory; // build the object list - for (i = 0, so = padsize; i < _game.numObjects; i++, so += padsize) { + spos = getVersion() >= 0x2000 ? padsize : 0; + for (i = 0, so = spos; i < _game.numObjects; i++, so += padsize) { int offset; (_objects + i)->location = *(mem + so + 2); - offset = READ_LE_UINT16(mem + so) + padsize; + offset = READ_LE_UINT16(mem + so) + spos; if ((uint) offset < flen) { (_objects + i)->name = (char *)strdup((const char *)mem + offset); @@ -84,20 +85,33 @@ int AgiEngine::decodeObjects(uint8 *mem, uint32 flen) { int AgiEngine::loadObjects(const char *fname) { Common::File fp; - uint32 flen; - uint8 *mem; - - _objects = NULL; - _game.numObjects = 0; debugC(5, kDebugLevelResources, "(Loading objects '%s')", fname); if (!fp.open(fname)) return errBadFileOpen; - fp.seek(0, SEEK_END); - flen = fp.pos(); - fp.seek(0, SEEK_SET); + return readObjects(fp, fp.size()); +} + +/** + * Loads an object file that is in the common VOL resource format. Expects + * the file pointer to point to the last field in header, ie. file length. + * This is used at least by the V1 booter games. + */ +int AgiEngine::loadObjects(Common::File &fp) { + int flen = fp.readUint16LE(); + return readObjects(fp, flen); +} + +/** + * Read and decode objects, and store them in the internal structure. + * + * @param fp File pointer + * @param flen File length + */ +int AgiEngine::readObjects(Common::File &fp, int flen) { + uint8 *mem; if ((mem = (uint8 *)calloc(1, flen + 32)) == NULL) { fp.close(); -- cgit v1.2.3