[Scummvm-cvs-logs] SF.net SVN: scummvm: [28791] scummvm/trunk/engines/agi
sev at users.sourceforge.net
sev at users.sourceforge.net
Sat Sep 1 19:28:15 CEST 2007
Revision: 28791
http://scummvm.svn.sourceforge.net/scummvm/?rev=28791&view=rev
Author: sev
Date: 2007-09-01 10:28:15 -0700 (Sat, 01 Sep 2007)
Log Message:
-----------
GIve some files more logical names
Modified Paths:
--------------
scummvm/trunk/engines/agi/agi.h
scummvm/trunk/engines/agi/module.mk
Added Paths:
-----------
scummvm/trunk/engines/agi/loader_preagi.cpp
scummvm/trunk/engines/agi/loader_v2.cpp
scummvm/trunk/engines/agi/loader_v3.cpp
scummvm/trunk/engines/agi/preagi_input.cpp
Removed Paths:
-------------
scummvm/trunk/engines/agi/agi_preagi.cpp
scummvm/trunk/engines/agi/agi_v2.cpp
scummvm/trunk/engines/agi/agi_v3.cpp
scummvm/trunk/engines/agi/preagi_keyboard.cpp
Modified: scummvm/trunk/engines/agi/agi.h
===================================================================
--- scummvm/trunk/engines/agi/agi.h 2007-09-01 17:18:17 UTC (rev 28790)
+++ scummvm/trunk/engines/agi/agi.h 2007-09-01 17:28:15 UTC (rev 28791)
@@ -849,7 +849,6 @@
int decodeLogic(int);
void unloadLogic(int);
int runLogic(int);
- void patchLogic(int n); // DELETE THIS
void debugConsole(int, int, const char *);
int testIfCode(int);
void executeAgiCommand(uint8, uint8 *);
Deleted: scummvm/trunk/engines/agi/agi_preagi.cpp
===================================================================
--- scummvm/trunk/engines/agi/agi_preagi.cpp 2007-09-01 17:18:17 UTC (rev 28790)
+++ scummvm/trunk/engines/agi/agi_preagi.cpp 2007-09-01 17:28:15 UTC (rev 28791)
@@ -1,215 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * $URL$
- * $Id$
- *
- */
-
-#include "common/stdafx.h"
-
-#include "agi/agi.h"
-#include "agi/lzw.h"
-#include "agi/preagi_mickey.h"
-
-#include "common/config-manager.h"
-#include "common/fs.h"
-
-namespace Agi {
-
-int AgiLoader_preagi::version() {
- return 0;
-}
-
-void AgiLoader_preagi::setIntVersion(int ver) {
- _intVersion = ver;
-}
-
-int AgiLoader_preagi::getIntVersion() {
- return _intVersion;
-}
-
-int AgiLoader_preagi::detectGame() {
- // TODO: Only Mickey is detected for now
- if (!Common::File::exists("1.pic"))
- return errInvalidAGIFile;
-
- _intVersion = 0x0000;
- return errOK;
-}
-
-int AgiLoader_preagi::loadDir(struct AgiDir *agid, Common::File *fp,
- uint32 offs, uint32 len) {
- int ec = errOK;
-/* uint8 *mem;
- unsigned int i;
-
- fp->seek(offs, SEEK_SET);
- if ((mem = (uint8 *)malloc(len + 32)) != NULL) {
- fp->read(mem, len);
-
- // set all directory resources to gone
- for (i = 0; i < MAX_DIRS; i++) {
- agid[i].volume = 0xff;
- agid[i].offset = _EMPTY;
- }
-
- // build directory entries
- for (i = 0; i < len; i += 3) {
- agid[i / 3].volume = *(mem + i) >> 4;
- agid[i / 3].offset = READ_BE_UINT24(mem + i) & (uint32) _EMPTY;
- }
-
- free(mem);
- } else {
- ec = errNotEnoughMemory;
- }
-*/
- return ec;
-}
-
-int AgiLoader_preagi::init() {
- int ec = errOK;
- //int i;
- //uint16 xd[4];
- Common::File fp;
- Common::String path;
-
- // TODO : load all preagi resources here
-
- return ec;
-}
-
-int AgiLoader_preagi::deinit() {
- int ec = errOK;
- return ec;
-}
-
-int AgiLoader_preagi::unloadResource(int t, int n) {
- switch (t) {
- case rLOGIC:
- //_vm->unloadLogic(n);
- break;
- case rPICTURE:
- _vm->_picture->unloadPicture(n);
- break;
- case rVIEW:
- //_vm->unloadView(n);
- break;
- case rSOUND:
- //_vm->_sound->unloadSound(n);
- break;
- }
-
- return errOK;
-}
-
-/*
- * This function does noting but load a raw resource into memory.
- * If further decoding is required, it must be done by another
- * routine.
- *
- * NULL is returned if unsucsessful.
- */
-uint8 *AgiLoader_preagi::loadVolRes(AgiDir *agid) {
-
- return NULL;
-}
-
-/*
- * Loads a resource into memory, a raw resource is loaded in
- * with above routine, then further decoded here.
- */
-int AgiLoader_preagi::loadResource(int t, int n) {
- int ec = errOK;
- uint8 *data = NULL;
-
- if (n > MAX_DIRS)
- return errBadResource;
-
- switch (t) {
- case rLOGIC:
- // The logic in preagi games is hardcoded
- break;
- case rPICTURE:
- /* if picture is currently NOT loaded *OR* cacheing is off,
- * unload the resource (caching==off) and reload it
- */
- if (true) { //(~_vm->_game.dirPic[n].flags & RES_LOADED) {
- unloadResource(rPICTURE, n);
- //data = loadVolRes(&_vm->_game.dirPic[n]);
-
- data = new uint8[4096];
- char szFile[255] = {0};
-
- sprintf(szFile, IDS_MSA_PATH_PIC, n);
- Common::File infile;
- if (!infile.open(szFile))
- return errBadResource;
- infile.read(data, infile.size());
-
- if (data != NULL) {
- _vm->_game.pictures[n].rdata = data;
- _vm->_game.dirPic[n].len = infile.size();
- _vm->_game.dirPic[n].flags |= RES_LOADED;
- } else {
- ec = errBadResource;
- }
-
- infile.close();
- }
- break;
- case rSOUND:
- /*
- if (_vm->_game.dirSound[n].flags & RES_LOADED)
- break;
-
- data = loadVolRes(&_vm->_game.dirSound[n]);
- if (data != NULL) {
- // Freeing of the raw resource from memory is delegated to the createFromRawResource-function
- _vm->_game.sounds[n] = AgiSound::createFromRawResource(data, _vm->_game.dirSound[n].len, n, *_vm->_sound);
- _vm->_game.dirSound[n].flags |= RES_LOADED;
- } else {
- ec = errBadResource;
- }
- */
- break;
- case rVIEW:
- //
- break;
- default:
- ec = errBadResource;
- break;
- }
-
- return ec;
-}
-
-int AgiLoader_preagi::loadObjects(const char *fname) {
- return 0;
- //return _vm->loadObjects(fname);
-}
-
-int AgiLoader_preagi::loadWords(const char *fname) {
- return 0;
- //return _vm->loadWords(fname);
-}
-
-} // End of namespace Agi
Deleted: scummvm/trunk/engines/agi/agi_v2.cpp
===================================================================
--- scummvm/trunk/engines/agi/agi_v2.cpp 2007-09-01 17:18:17 UTC (rev 28790)
+++ scummvm/trunk/engines/agi/agi_v2.cpp 2007-09-01 17:28:15 UTC (rev 28791)
@@ -1,300 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * $URL$
- * $Id$
- *
- */
-
-#include "common/stdafx.h"
-#include "common/file.h"
-
-#include "agi/agi.h"
-
-namespace Agi {
-
-int AgiLoader_v2::version() {
- return 2;
-}
-
-void AgiLoader_v2::setIntVersion(int ver) {
- _intVersion = ver;
-}
-
-int AgiLoader_v2::getIntVersion() {
- return _intVersion;
-}
-
-int AgiLoader_v2::detectGame() {
- if (!Common::File::exists(LOGDIR) ||
- !Common::File::exists(PICDIR) ||
- !Common::File::exists(SNDDIR) ||
- !Common::File::exists(VIEWDIR))
- return errInvalidAGIFile;
-
- _intVersion = 0x2917; /* setup for 2.917 */
- return _vm->v2IdGame();
-}
-
-int AgiLoader_v2::loadDir(AgiDir *agid, const char *fname) {
- Common::File fp;
- uint8 *mem;
- uint32 flen;
- uint i;
-
- report("Loading directory: %s\n", fname);
-
- if (!fp.open(fname)) {
- return errBadFileOpen;
- }
-
- fp.seek(0, SEEK_END);
- flen = fp.pos();
- fp.seek(0, SEEK_SET);
-
- if ((mem = (uint8 *)malloc(flen + 32)) == NULL) {
- fp.close();
- return errNotEnoughMemory;
- }
-
- fp.read(mem, flen);
-
- /* set all directory resources to gone */
- for (i = 0; i < MAX_DIRS; i++) {
- agid[i].volume = 0xff;
- agid[i].offset = _EMPTY;
- }
-
- /* build directory entries */
- for (i = 0; i < flen; i += 3) {
- agid[i / 3].volume = *(mem + i) >> 4;
- agid[i / 3].offset = READ_BE_UINT24(mem + i) & (uint32) _EMPTY;
- debugC(3, kDebugLevelResources, "%d: volume %d, offset 0x%05x", i / 3, agid[i / 3].volume, agid[i / 3].offset);
- }
-
- free(mem);
- fp.close();
-
- return errOK;
-}
-
-int AgiLoader_v2::init() {
- int ec = errOK;
-
- /* load directory files */
- ec = loadDir(_vm->_game.dirLogic, LOGDIR);
- if (ec == errOK)
- ec = loadDir(_vm->_game.dirPic, PICDIR);
- if (ec == errOK)
- ec = loadDir(_vm->_game.dirView, VIEWDIR);
- if (ec == errOK)
- ec = loadDir(_vm->_game.dirSound, SNDDIR);
-
- return ec;
-}
-
-int AgiLoader_v2::deinit() {
- int ec = errOK;
-
-#if 0
- /* unload words */
- agiV2UnloadWords();
-
- /* unload objects */
- agiV2UnloadObjects();
-#endif
-
- return ec;
-}
-
-int AgiLoader_v2::unloadResource(int t, int n) {
- debugC(3, kDebugLevelResources, "unload resource");
-
- switch (t) {
- case rLOGIC:
- _vm->unloadLogic(n);
- break;
- case rPICTURE:
- _vm->_picture->unloadPicture(n);
- break;
- case rVIEW:
- _vm->unloadView(n);
- break;
- case rSOUND:
- _vm->_sound->unloadSound(n);
- break;
- }
-
- return errOK;
-}
-
-/*
- * This function does noting but load a raw resource into memory,
- * if further decoding is required, it must be done by another
- * routine. NULL is returned if unsucsessfull.
- */
-uint8 *AgiLoader_v2::loadVolRes(struct AgiDir *agid) {
- uint8 *data = NULL;
- char x[MAX_PATH], *path;
- Common::File fp;
- unsigned int sig;
-
- sprintf(x, "vol.%i", agid->volume);
- path = x;
- debugC(3, kDebugLevelResources, "Vol res: path = %s", path);
-
- if (agid->offset != _EMPTY && fp.open(path)) {
- debugC(3, kDebugLevelResources, "loading resource at offset %d", agid->offset);
- fp.seek(agid->offset, SEEK_SET);
- fp.read(&x, 5);
- if ((sig = READ_BE_UINT16((uint8 *) x)) == 0x1234) {
- agid->len = READ_LE_UINT16((uint8 *) x + 3);
- data = (uint8 *) calloc(1, agid->len + 32);
- if (data != NULL) {
- fp.read(data, agid->len);
- } else {
- abort();
- }
- } else {
-#if 0
- /* FIXME: call some panic handler instead of
- * deiniting directly
- */
- deinitVideoMode();
-#endif
- report("Error: bad signature %04x\n", sig);
- // fprintf (stderr, "ACK! BAD RESOURCE!!!\n");
- return 0;
- }
- fp.close();
- } else {
- /* we have a bad volume resource */
- /* set that resource to NA */
- agid->offset = _EMPTY;
- }
-
- return data;
-}
-
-/*
- * Loads a resource into memory, a raw resource is loaded in
- * with above routine, then further decoded here.
- */
-int AgiLoader_v2::loadResource(int t, int n) {
- int ec = errOK;
- uint8 *data = NULL;
-
- debugC(3, kDebugLevelResources, "(t = %d, n = %d)", t, n);
- if (n > MAX_DIRS)
- return errBadResource;
-
- switch (t) {
- case rLOGIC:
- if (~_vm->_game.dirLogic[n].flags & RES_LOADED) {
- debugC(3, kDebugLevelResources, "loading logic resource %d", n);
- unloadResource(rLOGIC, n);
-
- /* load raw resource into data */
- data = loadVolRes(&_vm->_game.dirLogic[n]);
-
- _vm->_game.logics[n].data = data;
- ec = data ? _vm->decodeLogic(n) : errBadResource;
-
- _vm->_game.logics[n].sIP = 2;
- }
-
- /* if logic was cached, we get here */
- /* reset code pointers incase it was cached */
-
- _vm->_game.logics[n].cIP = _vm->_game.logics[n].sIP;
- break;
- case rPICTURE:
- /* if picture is currently NOT loaded *OR* cacheing is off,
- * unload the resource (caching == off) and reload it
- */
-
- debugC(3, kDebugLevelResources, "loading picture resource %d", n);
- if (_vm->_game.dirPic[n].flags & RES_LOADED)
- break;
-
- /* if loaded but not cached, unload it */
- /* if cached but not loaded, etc */
- unloadResource(rPICTURE, n);
- data = loadVolRes(&_vm->_game.dirPic[n]);
-
- if (data != NULL) {
- _vm->_game.pictures[n].rdata = data;
- _vm->_game.dirPic[n].flags |= RES_LOADED;
- } else {
- ec = errBadResource;
- }
- break;
- case rSOUND:
- debugC(3, kDebugLevelResources, "loading sound resource %d", n);
- if (_vm->_game.dirSound[n].flags & RES_LOADED)
- break;
-
- data = loadVolRes(&_vm->_game.dirSound[n]);
-
- if (data != NULL) {
- // Freeing of the raw resource from memory is delegated to the createFromRawResource-function
- _vm->_game.sounds[n] = AgiSound::createFromRawResource(data, _vm->_game.dirSound[n].len, n, *_vm->_sound);
- _vm->_game.dirSound[n].flags |= RES_LOADED;
- } else {
- ec = errBadResource;
- }
- break;
- case rVIEW:
- /* Load a VIEW resource into memory...
- * Since VIEWS alter the view table ALL the time
- * can we cache the view? or must we reload it all
- * the time?
- */
- if (_vm->_game.dirView[n].flags & RES_LOADED)
- break;
-
- debugC(3, kDebugLevelResources, "loading view resource %d", n);
- unloadResource(rVIEW, n);
- data = loadVolRes(&_vm->_game.dirView[n]);
- if (data) {
- _vm->_game.views[n].rdata = data;
- _vm->_game.dirView[n].flags |= RES_LOADED;
- ec = _vm->decodeView(n);
- } else {
- ec = errBadResource;
- }
- break;
- default:
- ec = errBadResource;
- break;
- }
-
- return ec;
-}
-
-int AgiLoader_v2::loadObjects(const char *fname) {
- return _vm->loadObjects(fname);
-}
-
-int AgiLoader_v2::loadWords(const char *fname) {
- return _vm->loadWords(fname);
-}
-
-} // End of namespace Agi
Deleted: scummvm/trunk/engines/agi/agi_v3.cpp
===================================================================
--- scummvm/trunk/engines/agi/agi_v3.cpp 2007-09-01 17:18:17 UTC (rev 28790)
+++ scummvm/trunk/engines/agi/agi_v3.cpp 2007-09-01 17:28:15 UTC (rev 28791)
@@ -1,390 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * $URL$
- * $Id$
- *
- */
-
-#include "common/stdafx.h"
-
-#include "agi/agi.h"
-#include "agi/lzw.h"
-
-#include "common/config-manager.h"
-#include "common/fs.h"
-
-namespace Agi {
-
-int AgiLoader_v3::version() {
- return 3;
-}
-
-void AgiLoader_v3::setIntVersion(int ver) {
- _intVersion = ver;
-}
-
-int AgiLoader_v3::getIntVersion() {
- return _intVersion;
-}
-
-int AgiLoader_v3::detectGame() {
- int ec = errUnk;
- bool found = false;
-
- FSList fslist;
- FilesystemNode dir(ConfMan.get("path"));
-
- if (!dir.listDir(fslist, FilesystemNode::kListFilesOnly)) {
- warning("AgiEngine: invalid game path '%s'", dir.path().c_str());
- return errInvalidAGIFile;
- }
-
- for (FSList::const_iterator file = fslist.begin();
- file != fslist.end() && !found; ++file) {
- Common::String f = file->name();
- f.toLowercase();
-
- if (f.hasSuffix("vol.0")) {
- memset(_vm->_game.name, 0, 8);
- strncpy(_vm->_game.name, f.c_str(), MIN((uint)8, f.size() > 5 ? f.size() - 5 : f.size()));
- debugC(3, kDebugLevelMain, "game.name = %s", _vm->_game.name);
- _intVersion = 0x3149; // setup for 3.002.149
- ec = _vm->v3IdGame();
-
- found = true;
- }
- }
-
- if (!found) {
- debugC(3, kDebugLevelMain, "not found");
- ec = errInvalidAGIFile;
- }
-
- return ec;
-}
-
-int AgiLoader_v3::loadDir(struct AgiDir *agid, Common::File *fp,
- uint32 offs, uint32 len) {
- int ec = errOK;
- uint8 *mem;
- unsigned int i;
-
- fp->seek(offs, SEEK_SET);
- if ((mem = (uint8 *)malloc(len + 32)) != NULL) {
- fp->read(mem, len);
-
- /* set all directory resources to gone */
- for (i = 0; i < MAX_DIRS; i++) {
- agid[i].volume = 0xff;
- agid[i].offset = _EMPTY;
- }
-
- /* build directory entries */
- for (i = 0; i < len; i += 3) {
- agid[i / 3].volume = *(mem + i) >> 4;
- agid[i / 3].offset = READ_BE_UINT24(mem + i) & (uint32) _EMPTY;
- }
-
- free(mem);
- } else {
- ec = errNotEnoughMemory;
- }
-
- return ec;
-}
-
-struct agi3vol {
- uint32 sddr;
- uint32 len;
-};
-
-int AgiLoader_v3::init() {
- int ec = errOK;
- struct agi3vol agiVol3[4];
- int i;
- uint16 xd[4];
- Common::File fp;
- Common::String path;
-
- if (_vm->getPlatform() == Common::kPlatformAmiga) {
- path = Common::String("dirs");
- _vm->_game.name[0] = 0; // Empty prefix
- } else if (_vm->getFeatures() & GF_MACGOLDRUSH) {
- path = "grdir";
- _vm->_game.name[0] = 0; // Empty prefix
- } else {
- path = Common::String(_vm->_game.name) + DIR_;
- }
-
- if (!fp.open(path)) {
- printf("Failed to open \"%s\"\n", path.c_str());
- return errBadFileOpen;
- }
- /* build offset table for v3 directory format */
- fp.read(&xd, 8);
- fp.seek(0, SEEK_END);
-
- for (i = 0; i < 4; i++)
- agiVol3[i].sddr = READ_LE_UINT16((uint8 *) & xd[i]);
-
- agiVol3[0].len = agiVol3[1].sddr - agiVol3[0].sddr;
- agiVol3[1].len = agiVol3[2].sddr - agiVol3[1].sddr;
- agiVol3[2].len = agiVol3[3].sddr - agiVol3[2].sddr;
- agiVol3[3].len = fp.pos() - agiVol3[3].sddr;
-
- if (agiVol3[3].len > 256 * 3)
- agiVol3[3].len = 256 * 3;
-
- fp.seek(0, SEEK_SET);
-
- /* read in directory files */
- ec = loadDir(_vm->_game.dirLogic, &fp, agiVol3[0].sddr, agiVol3[0].len);
-
- if (ec == errOK) {
- ec = loadDir(_vm->_game.dirPic, &fp, agiVol3[1].sddr, agiVol3[1].len);
- }
-
- if (ec == errOK) {
- ec = loadDir(_vm->_game.dirView, &fp, agiVol3[2].sddr, agiVol3[2].len);
- }
-
- if (ec == errOK) {
- ec = loadDir(_vm->_game.dirSound, &fp, agiVol3[3].sddr, agiVol3[3].len);
- }
-
- return ec;
-}
-
-int AgiLoader_v3::deinit() {
- int ec = errOK;
-
-#if 0
- /* unload words */
- agiV3UnloadWords();
-
- /* unload objects */
- agiV3UnloadObjects();
-#endif
-
- return ec;
-}
-
-int AgiLoader_v3::unloadResource(int t, int n) {
- switch (t) {
- case rLOGIC:
- _vm->unloadLogic(n);
- break;
- case rPICTURE:
- _vm->_picture->unloadPicture(n);
- break;
- case rVIEW:
- _vm->unloadView(n);
- break;
- case rSOUND:
- _vm->_sound->unloadSound(n);
- break;
- }
-
- return errOK;
-}
-
-/*
- * This function does noting but load a raw resource into memory.
- * If further decoding is required, it must be done by another
- * routine.
- *
- * NULL is returned if unsucsessful.
- */
-uint8 *AgiLoader_v3::loadVolRes(AgiDir *agid) {
- char x[MAX_PATH];
- uint8 *data = NULL, *compBuffer;
- Common::File fp;
- Common::String path;
-
- debugC(3, kDebugLevelResources, "(%p)", (void *)agid);
- sprintf(x, "vol.%i", agid->volume);
- path = Common::String(_vm->_game.name) + x;
-
- if (agid->offset != _EMPTY && fp.open(path)) {
- fp.seek(agid->offset, SEEK_SET);
- fp.read(&x, 7);
-
- if (READ_BE_UINT16((uint8 *) x) != 0x1234) {
-#if 0
- /* FIXME */
- deinitVideoMode();
-#endif
- debugC(3, kDebugLevelResources, "path = %s", path.c_str());
- debugC(3, kDebugLevelResources, "offset = %d", agid->offset);
- debugC(3, kDebugLevelResources, "x = %x %x", x[0], x[1]);
- error("ACK! BAD RESOURCE");
-
- g_system->quit();
- }
-
- agid->len = READ_LE_UINT16((uint8 *) x + 3); /* uncompressed size */
- agid->clen = READ_LE_UINT16((uint8 *) x + 5); /* compressed len */
-
- compBuffer = (uint8 *)calloc(1, agid->clen + 32);
- fp.read(compBuffer, agid->clen);
-
- if (x[2] & 0x80 || agid->len == agid->clen) {
- /* do not decompress */
- data = compBuffer;
-
-#if 0
- /* CM: added to avoid problems in
- * convert_v2_v3_pic() when clen > len
- * e.g. Sierra demo 4, first picture
- * (Tue Mar 16 13:13:43 EST 1999)
- */
- agid->len = agid->clen;
-
- /* Now removed to fix Gold Rush! in demo4 */
-#endif
- } else {
- /* it is compressed */
- data = (uint8 *)calloc(1, agid->len + 32);
- lzwExpand(compBuffer, data, agid->len);
- free(compBuffer);
- agid->flags |= RES_COMPRESSED;
- }
-
- fp.close();
- } else {
- /* we have a bad volume resource */
- /* set that resource to NA */
- agid->offset = _EMPTY;
- }
-
- return data;
-}
-
-/*
- * Loads a resource into memory, a raw resource is loaded in
- * with above routine, then further decoded here.
- */
-int AgiLoader_v3::loadResource(int t, int n) {
- int ec = errOK;
- uint8 *data = NULL;
-
- if (n > MAX_DIRS)
- return errBadResource;
-
- switch (t) {
- case rLOGIC:
- /* load resource into memory, decrypt messages at the end
- * and build the message list (if logic is in memory)
- */
- if (~_vm->_game.dirLogic[n].flags & RES_LOADED) {
- /* if logic is already in memory, unload it */
- unloadResource(rLOGIC, n);
-
- /* load raw resource into data */
- data = loadVolRes(&_vm->_game.dirLogic[n]);
- _vm->_game.logics[n].data = data;
-
- /* uncompressed logic files need to be decrypted */
- if (data != NULL) {
- /* resloaded flag gets set by decode logic */
- /* needed to build string table */
- ec = _vm->decodeLogic(n);
- _vm->_game.logics[n].sIP = 2;
- } else {
- ec = errBadResource;
- }
-
- /*logics[n].sIP=2; *//* saved IP = 2 */
- /*logics[n].cIP=2; *//* current IP = 2 */
-
- _vm->_game.logics[n].cIP = _vm->_game.logics[n].sIP;
- }
-
- /* if logic was cached, we get here */
- /* reset code pointers incase it was cached */
-
- _vm->_game.logics[n].cIP = _vm->_game.logics[n].sIP;
- break;
- case rPICTURE:
- /* if picture is currently NOT loaded *OR* cacheing is off,
- * unload the resource (caching==off) and reload it
- */
- if (~_vm->_game.dirPic[n].flags & RES_LOADED) {
- unloadResource(rPICTURE, n);
- data = loadVolRes(&_vm->_game.dirPic[n]);
- if (data != NULL) {
- data = _vm->_picture->convertV3Pic(data, _vm->_game.dirPic[n].len);
- _vm->_game.pictures[n].rdata = data;
- _vm->_game.dirPic[n].flags |= RES_LOADED;
- } else {
- ec = errBadResource;
- }
- }
- break;
- case rSOUND:
- if (_vm->_game.dirSound[n].flags & RES_LOADED)
- break;
-
- data = loadVolRes(&_vm->_game.dirSound[n]);
- if (data != NULL) {
- // Freeing of the raw resource from memory is delegated to the createFromRawResource-function
- _vm->_game.sounds[n] = AgiSound::createFromRawResource(data, _vm->_game.dirSound[n].len, n, *_vm->_sound);
- _vm->_game.dirSound[n].flags |= RES_LOADED;
- } else {
- ec = errBadResource;
- }
- break;
- case rVIEW:
- /* Load a VIEW resource into memory...
- * Since VIEWS alter the view table ALL the time can we
- * cache the view? or must we reload it all the time?
- */
- /* load a raw view from a VOL file into data */
- if (_vm->_game.dirView[n].flags & RES_LOADED)
- break;
-
- unloadResource(rVIEW, n);
- data = loadVolRes(&_vm->_game.dirView[n]);
- if (data != NULL) {
- _vm->_game.views[n].rdata = data;
- _vm->_game.dirView[n].flags |= RES_LOADED;
- ec = _vm->decodeView(n);
- } else {
- ec = errBadResource;
- }
- break;
- default:
- ec = errBadResource;
- break;
- }
-
- return ec;
-}
-
-int AgiLoader_v3::loadObjects(const char *fname) {
- return _vm->loadObjects(fname);
-}
-
-int AgiLoader_v3::loadWords(const char *fname) {
- return _vm->loadWords(fname);
-}
-
-} // End of namespace Agi
Copied: scummvm/trunk/engines/agi/loader_preagi.cpp (from rev 28787, scummvm/trunk/engines/agi/agi_preagi.cpp)
===================================================================
--- scummvm/trunk/engines/agi/loader_preagi.cpp (rev 0)
+++ scummvm/trunk/engines/agi/loader_preagi.cpp 2007-09-01 17:28:15 UTC (rev 28791)
@@ -0,0 +1,215 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "common/stdafx.h"
+
+#include "agi/agi.h"
+#include "agi/lzw.h"
+#include "agi/preagi_mickey.h"
+
+#include "common/config-manager.h"
+#include "common/fs.h"
+
+namespace Agi {
+
+int AgiLoader_preagi::version() {
+ return 0;
+}
+
+void AgiLoader_preagi::setIntVersion(int ver) {
+ _intVersion = ver;
+}
+
+int AgiLoader_preagi::getIntVersion() {
+ return _intVersion;
+}
+
+int AgiLoader_preagi::detectGame() {
+ // TODO: Only Mickey is detected for now
+ if (!Common::File::exists("1.pic"))
+ return errInvalidAGIFile;
+
+ _intVersion = 0x0000;
+ return errOK;
+}
+
+int AgiLoader_preagi::loadDir(struct AgiDir *agid, Common::File *fp,
+ uint32 offs, uint32 len) {
+ int ec = errOK;
+/* uint8 *mem;
+ unsigned int i;
+
+ fp->seek(offs, SEEK_SET);
+ if ((mem = (uint8 *)malloc(len + 32)) != NULL) {
+ fp->read(mem, len);
+
+ // set all directory resources to gone
+ for (i = 0; i < MAX_DIRS; i++) {
+ agid[i].volume = 0xff;
+ agid[i].offset = _EMPTY;
+ }
+
+ // build directory entries
+ for (i = 0; i < len; i += 3) {
+ agid[i / 3].volume = *(mem + i) >> 4;
+ agid[i / 3].offset = READ_BE_UINT24(mem + i) & (uint32) _EMPTY;
+ }
+
+ free(mem);
+ } else {
+ ec = errNotEnoughMemory;
+ }
+*/
+ return ec;
+}
+
+int AgiLoader_preagi::init() {
+ int ec = errOK;
+ //int i;
+ //uint16 xd[4];
+ Common::File fp;
+ Common::String path;
+
+ // TODO : load all preagi resources here
+
+ return ec;
+}
+
+int AgiLoader_preagi::deinit() {
+ int ec = errOK;
+ return ec;
+}
+
+int AgiLoader_preagi::unloadResource(int t, int n) {
+ switch (t) {
+ case rLOGIC:
+ //_vm->unloadLogic(n);
+ break;
+ case rPICTURE:
+ _vm->_picture->unloadPicture(n);
+ break;
+ case rVIEW:
+ //_vm->unloadView(n);
+ break;
+ case rSOUND:
+ //_vm->_sound->unloadSound(n);
+ break;
+ }
+
+ return errOK;
+}
+
+/*
+ * This function does noting but load a raw resource into memory.
+ * If further decoding is required, it must be done by another
+ * routine.
+ *
+ * NULL is returned if unsucsessful.
+ */
+uint8 *AgiLoader_preagi::loadVolRes(AgiDir *agid) {
+
+ return NULL;
+}
+
+/*
+ * Loads a resource into memory, a raw resource is loaded in
+ * with above routine, then further decoded here.
+ */
+int AgiLoader_preagi::loadResource(int t, int n) {
+ int ec = errOK;
+ uint8 *data = NULL;
+
+ if (n > MAX_DIRS)
+ return errBadResource;
+
+ switch (t) {
+ case rLOGIC:
+ // The logic in preagi games is hardcoded
+ break;
+ case rPICTURE:
+ /* if picture is currently NOT loaded *OR* cacheing is off,
+ * unload the resource (caching==off) and reload it
+ */
+ if (true) { //(~_vm->_game.dirPic[n].flags & RES_LOADED) {
+ unloadResource(rPICTURE, n);
+ //data = loadVolRes(&_vm->_game.dirPic[n]);
+
+ data = new uint8[4096];
+ char szFile[255] = {0};
+
+ sprintf(szFile, IDS_MSA_PATH_PIC, n);
+ Common::File infile;
+ if (!infile.open(szFile))
+ return errBadResource;
+ infile.read(data, infile.size());
+
+ if (data != NULL) {
+ _vm->_game.pictures[n].rdata = data;
+ _vm->_game.dirPic[n].len = infile.size();
+ _vm->_game.dirPic[n].flags |= RES_LOADED;
+ } else {
+ ec = errBadResource;
+ }
+
+ infile.close();
+ }
+ break;
+ case rSOUND:
+ /*
+ if (_vm->_game.dirSound[n].flags & RES_LOADED)
+ break;
+
+ data = loadVolRes(&_vm->_game.dirSound[n]);
+ if (data != NULL) {
+ // Freeing of the raw resource from memory is delegated to the createFromRawResource-function
+ _vm->_game.sounds[n] = AgiSound::createFromRawResource(data, _vm->_game.dirSound[n].len, n, *_vm->_sound);
+ _vm->_game.dirSound[n].flags |= RES_LOADED;
+ } else {
+ ec = errBadResource;
+ }
+ */
+ break;
+ case rVIEW:
+ //
+ break;
+ default:
+ ec = errBadResource;
+ break;
+ }
+
+ return ec;
+}
+
+int AgiLoader_preagi::loadObjects(const char *fname) {
+ return 0;
+ //return _vm->loadObjects(fname);
+}
+
+int AgiLoader_preagi::loadWords(const char *fname) {
+ return 0;
+ //return _vm->loadWords(fname);
+}
+
+} // End of namespace Agi
Copied: scummvm/trunk/engines/agi/loader_v2.cpp (from rev 28773, scummvm/trunk/engines/agi/agi_v2.cpp)
===================================================================
--- scummvm/trunk/engines/agi/loader_v2.cpp (rev 0)
+++ scummvm/trunk/engines/agi/loader_v2.cpp 2007-09-01 17:28:15 UTC (rev 28791)
@@ -0,0 +1,300 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "common/stdafx.h"
+#include "common/file.h"
+
+#include "agi/agi.h"
+
+namespace Agi {
+
+int AgiLoader_v2::version() {
+ return 2;
+}
+
+void AgiLoader_v2::setIntVersion(int ver) {
+ _intVersion = ver;
+}
+
+int AgiLoader_v2::getIntVersion() {
+ return _intVersion;
+}
+
+int AgiLoader_v2::detectGame() {
+ if (!Common::File::exists(LOGDIR) ||
+ !Common::File::exists(PICDIR) ||
+ !Common::File::exists(SNDDIR) ||
+ !Common::File::exists(VIEWDIR))
+ return errInvalidAGIFile;
+
+ _intVersion = 0x2917; /* setup for 2.917 */
+ return _vm->v2IdGame();
+}
+
+int AgiLoader_v2::loadDir(AgiDir *agid, const char *fname) {
+ Common::File fp;
+ uint8 *mem;
+ uint32 flen;
+ uint i;
+
+ report("Loading directory: %s\n", fname);
+
+ if (!fp.open(fname)) {
+ return errBadFileOpen;
+ }
+
+ fp.seek(0, SEEK_END);
+ flen = fp.pos();
+ fp.seek(0, SEEK_SET);
+
+ if ((mem = (uint8 *)malloc(flen + 32)) == NULL) {
+ fp.close();
+ return errNotEnoughMemory;
+ }
+
+ fp.read(mem, flen);
+
+ /* set all directory resources to gone */
+ for (i = 0; i < MAX_DIRS; i++) {
+ agid[i].volume = 0xff;
+ agid[i].offset = _EMPTY;
+ }
+
+ /* build directory entries */
+ for (i = 0; i < flen; i += 3) {
+ agid[i / 3].volume = *(mem + i) >> 4;
+ agid[i / 3].offset = READ_BE_UINT24(mem + i) & (uint32) _EMPTY;
+ debugC(3, kDebugLevelResources, "%d: volume %d, offset 0x%05x", i / 3, agid[i / 3].volume, agid[i / 3].offset);
+ }
+
+ free(mem);
+ fp.close();
+
+ return errOK;
+}
+
+int AgiLoader_v2::init() {
+ int ec = errOK;
+
+ /* load directory files */
+ ec = loadDir(_vm->_game.dirLogic, LOGDIR);
+ if (ec == errOK)
+ ec = loadDir(_vm->_game.dirPic, PICDIR);
+ if (ec == errOK)
+ ec = loadDir(_vm->_game.dirView, VIEWDIR);
+ if (ec == errOK)
+ ec = loadDir(_vm->_game.dirSound, SNDDIR);
+
+ return ec;
+}
+
+int AgiLoader_v2::deinit() {
+ int ec = errOK;
+
+#if 0
+ /* unload words */
+ agiV2UnloadWords();
+
+ /* unload objects */
+ agiV2UnloadObjects();
+#endif
+
+ return ec;
+}
+
+int AgiLoader_v2::unloadResource(int t, int n) {
+ debugC(3, kDebugLevelResources, "unload resource");
+
+ switch (t) {
+ case rLOGIC:
+ _vm->unloadLogic(n);
+ break;
+ case rPICTURE:
+ _vm->_picture->unloadPicture(n);
+ break;
+ case rVIEW:
+ _vm->unloadView(n);
+ break;
+ case rSOUND:
+ _vm->_sound->unloadSound(n);
+ break;
+ }
+
+ return errOK;
+}
+
+/*
+ * This function does noting but load a raw resource into memory,
+ * if further decoding is required, it must be done by another
+ * routine. NULL is returned if unsucsessfull.
+ */
+uint8 *AgiLoader_v2::loadVolRes(struct AgiDir *agid) {
+ uint8 *data = NULL;
+ char x[MAX_PATH], *path;
+ Common::File fp;
+ unsigned int sig;
+
+ sprintf(x, "vol.%i", agid->volume);
+ path = x;
+ debugC(3, kDebugLevelResources, "Vol res: path = %s", path);
+
+ if (agid->offset != _EMPTY && fp.open(path)) {
+ debugC(3, kDebugLevelResources, "loading resource at offset %d", agid->offset);
+ fp.seek(agid->offset, SEEK_SET);
+ fp.read(&x, 5);
+ if ((sig = READ_BE_UINT16((uint8 *) x)) == 0x1234) {
+ agid->len = READ_LE_UINT16((uint8 *) x + 3);
+ data = (uint8 *) calloc(1, agid->len + 32);
+ if (data != NULL) {
+ fp.read(data, agid->len);
+ } else {
+ abort();
+ }
+ } else {
+#if 0
+ /* FIXME: call some panic handler instead of
+ * deiniting directly
+ */
+ deinitVideoMode();
+#endif
+ report("Error: bad signature %04x\n", sig);
+ // fprintf (stderr, "ACK! BAD RESOURCE!!!\n");
+ return 0;
+ }
+ fp.close();
+ } else {
+ /* we have a bad volume resource */
+ /* set that resource to NA */
+ agid->offset = _EMPTY;
+ }
+
+ return data;
+}
+
+/*
+ * Loads a resource into memory, a raw resource is loaded in
+ * with above routine, then further decoded here.
+ */
+int AgiLoader_v2::loadResource(int t, int n) {
+ int ec = errOK;
+ uint8 *data = NULL;
+
+ debugC(3, kDebugLevelResources, "(t = %d, n = %d)", t, n);
+ if (n > MAX_DIRS)
+ return errBadResource;
+
+ switch (t) {
+ case rLOGIC:
+ if (~_vm->_game.dirLogic[n].flags & RES_LOADED) {
+ debugC(3, kDebugLevelResources, "loading logic resource %d", n);
+ unloadResource(rLOGIC, n);
+
+ /* load raw resource into data */
+ data = loadVolRes(&_vm->_game.dirLogic[n]);
+
+ _vm->_game.logics[n].data = data;
+ ec = data ? _vm->decodeLogic(n) : errBadResource;
+
+ _vm->_game.logics[n].sIP = 2;
+ }
+
+ /* if logic was cached, we get here */
+ /* reset code pointers incase it was cached */
+
+ _vm->_game.logics[n].cIP = _vm->_game.logics[n].sIP;
+ break;
+ case rPICTURE:
+ /* if picture is currently NOT loaded *OR* cacheing is off,
+ * unload the resource (caching == off) and reload it
+ */
+
+ debugC(3, kDebugLevelResources, "loading picture resource %d", n);
+ if (_vm->_game.dirPic[n].flags & RES_LOADED)
+ break;
+
+ /* if loaded but not cached, unload it */
+ /* if cached but not loaded, etc */
+ unloadResource(rPICTURE, n);
+ data = loadVolRes(&_vm->_game.dirPic[n]);
+
+ if (data != NULL) {
+ _vm->_game.pictures[n].rdata = data;
+ _vm->_game.dirPic[n].flags |= RES_LOADED;
+ } else {
+ ec = errBadResource;
+ }
+ break;
+ case rSOUND:
+ debugC(3, kDebugLevelResources, "loading sound resource %d", n);
+ if (_vm->_game.dirSound[n].flags & RES_LOADED)
+ break;
+
+ data = loadVolRes(&_vm->_game.dirSound[n]);
+
+ if (data != NULL) {
+ // Freeing of the raw resource from memory is delegated to the createFromRawResource-function
+ _vm->_game.sounds[n] = AgiSound::createFromRawResource(data, _vm->_game.dirSound[n].len, n, *_vm->_sound);
+ _vm->_game.dirSound[n].flags |= RES_LOADED;
+ } else {
+ ec = errBadResource;
+ }
+ break;
+ case rVIEW:
+ /* Load a VIEW resource into memory...
+ * Since VIEWS alter the view table ALL the time
+ * can we cache the view? or must we reload it all
+ * the time?
+ */
+ if (_vm->_game.dirView[n].flags & RES_LOADED)
+ break;
+
+ debugC(3, kDebugLevelResources, "loading view resource %d", n);
+ unloadResource(rVIEW, n);
+ data = loadVolRes(&_vm->_game.dirView[n]);
+ if (data) {
+ _vm->_game.views[n].rdata = data;
+ _vm->_game.dirView[n].flags |= RES_LOADED;
+ ec = _vm->decodeView(n);
+ } else {
+ ec = errBadResource;
+ }
+ break;
+ default:
+ ec = errBadResource;
+ break;
+ }
+
+ return ec;
+}
+
+int AgiLoader_v2::loadObjects(const char *fname) {
+ return _vm->loadObjects(fname);
+}
+
+int AgiLoader_v2::loadWords(const char *fname) {
+ return _vm->loadWords(fname);
+}
+
+} // End of namespace Agi
Copied: scummvm/trunk/engines/agi/loader_v3.cpp (from rev 28773, scummvm/trunk/engines/agi/agi_v3.cpp)
===================================================================
--- scummvm/trunk/engines/agi/loader_v3.cpp (rev 0)
+++ scummvm/trunk/engines/agi/loader_v3.cpp 2007-09-01 17:28:15 UTC (rev 28791)
@@ -0,0 +1,390 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "common/stdafx.h"
+
+#include "agi/agi.h"
+#include "agi/lzw.h"
+
+#include "common/config-manager.h"
+#include "common/fs.h"
+
+namespace Agi {
+
+int AgiLoader_v3::version() {
+ return 3;
+}
+
+void AgiLoader_v3::setIntVersion(int ver) {
+ _intVersion = ver;
+}
+
+int AgiLoader_v3::getIntVersion() {
+ return _intVersion;
+}
+
+int AgiLoader_v3::detectGame() {
+ int ec = errUnk;
+ bool found = false;
+
+ FSList fslist;
+ FilesystemNode dir(ConfMan.get("path"));
+
+ if (!dir.listDir(fslist, FilesystemNode::kListFilesOnly)) {
+ warning("AgiEngine: invalid game path '%s'", dir.path().c_str());
+ return errInvalidAGIFile;
+ }
+
+ for (FSList::const_iterator file = fslist.begin();
+ file != fslist.end() && !found; ++file) {
+ Common::String f = file->name();
+ f.toLowercase();
+
+ if (f.hasSuffix("vol.0")) {
+ memset(_vm->_game.name, 0, 8);
+ strncpy(_vm->_game.name, f.c_str(), MIN((uint)8, f.size() > 5 ? f.size() - 5 : f.size()));
+ debugC(3, kDebugLevelMain, "game.name = %s", _vm->_game.name);
+ _intVersion = 0x3149; // setup for 3.002.149
+ ec = _vm->v3IdGame();
+
+ found = true;
+ }
+ }
+
+ if (!found) {
+ debugC(3, kDebugLevelMain, "not found");
+ ec = errInvalidAGIFile;
+ }
+
+ return ec;
+}
+
+int AgiLoader_v3::loadDir(struct AgiDir *agid, Common::File *fp,
+ uint32 offs, uint32 len) {
+ int ec = errOK;
+ uint8 *mem;
+ unsigned int i;
+
+ fp->seek(offs, SEEK_SET);
+ if ((mem = (uint8 *)malloc(len + 32)) != NULL) {
+ fp->read(mem, len);
+
+ /* set all directory resources to gone */
+ for (i = 0; i < MAX_DIRS; i++) {
+ agid[i].volume = 0xff;
+ agid[i].offset = _EMPTY;
+ }
+
+ /* build directory entries */
+ for (i = 0; i < len; i += 3) {
+ agid[i / 3].volume = *(mem + i) >> 4;
+ agid[i / 3].offset = READ_BE_UINT24(mem + i) & (uint32) _EMPTY;
+ }
+
+ free(mem);
+ } else {
+ ec = errNotEnoughMemory;
+ }
+
+ return ec;
+}
+
+struct agi3vol {
+ uint32 sddr;
+ uint32 len;
+};
+
+int AgiLoader_v3::init() {
+ int ec = errOK;
+ struct agi3vol agiVol3[4];
+ int i;
+ uint16 xd[4];
+ Common::File fp;
+ Common::String path;
+
+ if (_vm->getPlatform() == Common::kPlatformAmiga) {
+ path = Common::String("dirs");
+ _vm->_game.name[0] = 0; // Empty prefix
+ } else if (_vm->getFeatures() & GF_MACGOLDRUSH) {
+ path = "grdir";
+ _vm->_game.name[0] = 0; // Empty prefix
+ } else {
+ path = Common::String(_vm->_game.name) + DIR_;
+ }
+
+ if (!fp.open(path)) {
+ printf("Failed to open \"%s\"\n", path.c_str());
+ return errBadFileOpen;
+ }
+ /* build offset table for v3 directory format */
+ fp.read(&xd, 8);
+ fp.seek(0, SEEK_END);
+
+ for (i = 0; i < 4; i++)
+ agiVol3[i].sddr = READ_LE_UINT16((uint8 *) & xd[i]);
+
+ agiVol3[0].len = agiVol3[1].sddr - agiVol3[0].sddr;
+ agiVol3[1].len = agiVol3[2].sddr - agiVol3[1].sddr;
+ agiVol3[2].len = agiVol3[3].sddr - agiVol3[2].sddr;
+ agiVol3[3].len = fp.pos() - agiVol3[3].sddr;
+
+ if (agiVol3[3].len > 256 * 3)
+ agiVol3[3].len = 256 * 3;
+
+ fp.seek(0, SEEK_SET);
+
+ /* read in directory files */
+ ec = loadDir(_vm->_game.dirLogic, &fp, agiVol3[0].sddr, agiVol3[0].len);
+
+ if (ec == errOK) {
+ ec = loadDir(_vm->_game.dirPic, &fp, agiVol3[1].sddr, agiVol3[1].len);
+ }
+
+ if (ec == errOK) {
+ ec = loadDir(_vm->_game.dirView, &fp, agiVol3[2].sddr, agiVol3[2].len);
+ }
+
+ if (ec == errOK) {
+ ec = loadDir(_vm->_game.dirSound, &fp, agiVol3[3].sddr, agiVol3[3].len);
+ }
+
+ return ec;
+}
+
+int AgiLoader_v3::deinit() {
+ int ec = errOK;
+
+#if 0
+ /* unload words */
+ agiV3UnloadWords();
+
+ /* unload objects */
+ agiV3UnloadObjects();
+#endif
+
+ return ec;
+}
+
+int AgiLoader_v3::unloadResource(int t, int n) {
+ switch (t) {
+ case rLOGIC:
+ _vm->unloadLogic(n);
+ break;
+ case rPICTURE:
+ _vm->_picture->unloadPicture(n);
+ break;
+ case rVIEW:
+ _vm->unloadView(n);
+ break;
+ case rSOUND:
+ _vm->_sound->unloadSound(n);
+ break;
+ }
+
+ return errOK;
+}
+
+/*
+ * This function does noting but load a raw resource into memory.
+ * If further decoding is required, it must be done by another
+ * routine.
+ *
+ * NULL is returned if unsucsessful.
+ */
+uint8 *AgiLoader_v3::loadVolRes(AgiDir *agid) {
+ char x[MAX_PATH];
+ uint8 *data = NULL, *compBuffer;
+ Common::File fp;
+ Common::String path;
+
+ debugC(3, kDebugLevelResources, "(%p)", (void *)agid);
+ sprintf(x, "vol.%i", agid->volume);
+ path = Common::String(_vm->_game.name) + x;
+
+ if (agid->offset != _EMPTY && fp.open(path)) {
+ fp.seek(agid->offset, SEEK_SET);
+ fp.read(&x, 7);
+
+ if (READ_BE_UINT16((uint8 *) x) != 0x1234) {
+#if 0
+ /* FIXME */
+ deinitVideoMode();
+#endif
+ debugC(3, kDebugLevelResources, "path = %s", path.c_str());
+ debugC(3, kDebugLevelResources, "offset = %d", agid->offset);
+ debugC(3, kDebugLevelResources, "x = %x %x", x[0], x[1]);
+ error("ACK! BAD RESOURCE");
+
+ g_system->quit();
+ }
+
+ agid->len = READ_LE_UINT16((uint8 *) x + 3); /* uncompressed size */
+ agid->clen = READ_LE_UINT16((uint8 *) x + 5); /* compressed len */
+
+ compBuffer = (uint8 *)calloc(1, agid->clen + 32);
+ fp.read(compBuffer, agid->clen);
+
+ if (x[2] & 0x80 || agid->len == agid->clen) {
+ /* do not decompress */
+ data = compBuffer;
+
+#if 0
+ /* CM: added to avoid problems in
+ * convert_v2_v3_pic() when clen > len
+ * e.g. Sierra demo 4, first picture
+ * (Tue Mar 16 13:13:43 EST 1999)
+ */
+ agid->len = agid->clen;
+
+ /* Now removed to fix Gold Rush! in demo4 */
+#endif
+ } else {
+ /* it is compressed */
+ data = (uint8 *)calloc(1, agid->len + 32);
+ lzwExpand(compBuffer, data, agid->len);
+ free(compBuffer);
+ agid->flags |= RES_COMPRESSED;
+ }
+
+ fp.close();
+ } else {
+ /* we have a bad volume resource */
+ /* set that resource to NA */
+ agid->offset = _EMPTY;
+ }
+
+ return data;
+}
+
+/*
+ * Loads a resource into memory, a raw resource is loaded in
+ * with above routine, then further decoded here.
+ */
+int AgiLoader_v3::loadResource(int t, int n) {
+ int ec = errOK;
+ uint8 *data = NULL;
+
+ if (n > MAX_DIRS)
+ return errBadResource;
+
+ switch (t) {
+ case rLOGIC:
+ /* load resource into memory, decrypt messages at the end
+ * and build the message list (if logic is in memory)
+ */
+ if (~_vm->_game.dirLogic[n].flags & RES_LOADED) {
+ /* if logic is already in memory, unload it */
+ unloadResource(rLOGIC, n);
+
+ /* load raw resource into data */
+ data = loadVolRes(&_vm->_game.dirLogic[n]);
+ _vm->_game.logics[n].data = data;
+
+ /* uncompressed logic files need to be decrypted */
+ if (data != NULL) {
+ /* resloaded flag gets set by decode logic */
+ /* needed to build string table */
+ ec = _vm->decodeLogic(n);
+ _vm->_game.logics[n].sIP = 2;
+ } else {
+ ec = errBadResource;
+ }
+
+ /*logics[n].sIP=2; *//* saved IP = 2 */
+ /*logics[n].cIP=2; *//* current IP = 2 */
+
+ _vm->_game.logics[n].cIP = _vm->_game.logics[n].sIP;
+ }
+
+ /* if logic was cached, we get here */
+ /* reset code pointers incase it was cached */
+
+ _vm->_game.logics[n].cIP = _vm->_game.logics[n].sIP;
+ break;
+ case rPICTURE:
+ /* if picture is currently NOT loaded *OR* cacheing is off,
+ * unload the resource (caching==off) and reload it
+ */
+ if (~_vm->_game.dirPic[n].flags & RES_LOADED) {
+ unloadResource(rPICTURE, n);
+ data = loadVolRes(&_vm->_game.dirPic[n]);
+ if (data != NULL) {
+ data = _vm->_picture->convertV3Pic(data, _vm->_game.dirPic[n].len);
+ _vm->_game.pictures[n].rdata = data;
+ _vm->_game.dirPic[n].flags |= RES_LOADED;
+ } else {
+ ec = errBadResource;
+ }
+ }
+ break;
+ case rSOUND:
+ if (_vm->_game.dirSound[n].flags & RES_LOADED)
+ break;
+
+ data = loadVolRes(&_vm->_game.dirSound[n]);
+ if (data != NULL) {
+ // Freeing of the raw resource from memory is delegated to the createFromRawResource-function
+ _vm->_game.sounds[n] = AgiSound::createFromRawResource(data, _vm->_game.dirSound[n].len, n, *_vm->_sound);
+ _vm->_game.dirSound[n].flags |= RES_LOADED;
+ } else {
+ ec = errBadResource;
+ }
+ break;
+ case rVIEW:
+ /* Load a VIEW resource into memory...
+ * Since VIEWS alter the view table ALL the time can we
+ * cache the view? or must we reload it all the time?
+ */
+ /* load a raw view from a VOL file into data */
+ if (_vm->_game.dirView[n].flags & RES_LOADED)
+ break;
+
+ unloadResource(rVIEW, n);
+ data = loadVolRes(&_vm->_game.dirView[n]);
+ if (data != NULL) {
+ _vm->_game.views[n].rdata = data;
+ _vm->_game.dirView[n].flags |= RES_LOADED;
+ ec = _vm->decodeView(n);
+ } else {
+ ec = errBadResource;
+ }
+ break;
+ default:
+ ec = errBadResource;
+ break;
+ }
+
+ return ec;
+}
+
+int AgiLoader_v3::loadObjects(const char *fname) {
+ return _vm->loadObjects(fname);
+}
+
+int AgiLoader_v3::loadWords(const char *fname) {
+ return _vm->loadWords(fname);
+}
+
+} // End of namespace Agi
Modified: scummvm/trunk/engines/agi/module.mk
===================================================================
--- scummvm/trunk/engines/agi/module.mk 2007-09-01 17:18:17 UTC (rev 28790)
+++ scummvm/trunk/engines/agi/module.mk 2007-09-01 17:28:15 UTC (rev 28791)
@@ -2,9 +2,6 @@
MODULE_OBJS = \
agi.o \
- agi_v2.o \
- agi_v3.o \
- agi_preagi.o \
checks.o \
console.o \
cycle.o \
@@ -14,6 +11,9 @@
id.o \
inv.o \
keyboard.o \
+ loader_preagi.o \
+ loader_v2.o \
+ loader_v3.o \
logic.o \
lzw.o \
menu.o \
@@ -24,7 +24,7 @@
op_test.o \
picture.o \
preagi.o \
- preagi_keyboard.o \
+ preagi_input.o \
preagi_mickey.o \
predictive.o \
saveload.o \
Copied: scummvm/trunk/engines/agi/preagi_input.cpp (from rev 28787, scummvm/trunk/engines/agi/preagi_keyboard.cpp)
===================================================================
--- scummvm/trunk/engines/agi/preagi_input.cpp (rev 0)
+++ scummvm/trunk/engines/agi/preagi_input.cpp 2007-09-01 17:28:15 UTC (rev 28791)
@@ -0,0 +1,146 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "common/stdafx.h"
+#include "common/events.h"
+
+#include "agi/agi.h"
+#include "agi/graphics.h"
+#include "agi/keyboard.h"
+
+namespace Agi {
+
+// Input
+
+void PreAgiEngine::waitAnyKeyAnim() {
+ waitAnyKey(true);
+}
+
+int PreAgiEngine::getSelection(int type) {
+ Common::Event event;
+
+ // Selection types:
+ // 0: Y/N
+ // 1: 1-9
+ for (;;) {
+ while (_eventMan->pollEvent(event)) {
+ switch(event.type) {
+ case Common::EVENT_QUIT:
+ _system->quit();
+ case Common::EVENT_LBUTTONUP:
+ if (type == 0)
+ return 1;
+ case Common::EVENT_RBUTTONUP:
+ return 0;
+ case Common::EVENT_KEYDOWN:
+ switch (event.kbd.keycode) {
+ case Common::KEYCODE_y:
+ if (type == 0)
+ return 1;
+ case Common::KEYCODE_n:
+ if (type == 0)
+ return 0;
+ case Common::KEYCODE_ESCAPE:
+ if (type == 1)
+ return 0;
+ case Common::KEYCODE_1:
+ case Common::KEYCODE_2:
+ case Common::KEYCODE_3:
+ case Common::KEYCODE_4:
+ case Common::KEYCODE_5:
+ case Common::KEYCODE_6:
+ case Common::KEYCODE_7:
+ case Common::KEYCODE_8:
+ case Common::KEYCODE_9:
+ if (type == 1)
+ return event.kbd.keycode - Common::KEYCODE_1 + 1;
+ default:
+ if (type == 0) {
+ return 2;
+ } else {
+ return 10;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ return 0;
+}
+
+bool PreAgiEngine::waitAnyKeyChoice() {
+ Common::Event event;
+
+ for (;;) {
+ while (_eventMan->pollEvent(event)) {
+ switch(event.type) {
+ case Common::EVENT_QUIT:
+ _system->quit();
+ case Common::EVENT_LBUTTONUP:
+ return true;
+ case Common::EVENT_RBUTTONUP:
+ return false;
+ case Common::EVENT_KEYDOWN:
+ switch (event.kbd.keycode) {
+ case Common::KEYCODE_ESCAPE: //Escape
+ return false;
+ default:
+ return true;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+}
+
+void PreAgiEngine::waitAnyKey(bool anim) {
+ Common::Event event;
+
+ for (;;) {
+ while (_eventMan->pollEvent(event)) {
+ switch(event.type) {
+ case Common::EVENT_QUIT:
+ _system->quit();
+ case Common::EVENT_KEYDOWN:
+ case Common::EVENT_LBUTTONUP:
+ case Common::EVENT_RBUTTONUP:
+ return;
+ default:
+ break;
+ }
+ }
+ // TODO
+ /*if (anim) {
+ _game->Animate();
+ UpdateScreen();
+ }*/
+ }
+}
+
+}
Deleted: scummvm/trunk/engines/agi/preagi_keyboard.cpp
===================================================================
--- scummvm/trunk/engines/agi/preagi_keyboard.cpp 2007-09-01 17:18:17 UTC (rev 28790)
+++ scummvm/trunk/engines/agi/preagi_keyboard.cpp 2007-09-01 17:28:15 UTC (rev 28791)
@@ -1,146 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * $URL$
- * $Id$
- *
- */
-
-#include "common/stdafx.h"
-#include "common/events.h"
-
-#include "agi/agi.h"
-#include "agi/graphics.h"
-#include "agi/keyboard.h"
-
-namespace Agi {
-
-// Input
-
-void PreAgiEngine::waitAnyKeyAnim() {
- waitAnyKey(true);
-}
-
-int PreAgiEngine::getSelection(int type) {
- Common::Event event;
-
- // Selection types:
- // 0: Y/N
- // 1: 1-9
- for (;;) {
- while (_eventMan->pollEvent(event)) {
- switch(event.type) {
- case Common::EVENT_QUIT:
- _system->quit();
- case Common::EVENT_LBUTTONUP:
- if (type == 0)
- return 1;
- case Common::EVENT_RBUTTONUP:
- return 0;
- case Common::EVENT_KEYDOWN:
- switch (event.kbd.keycode) {
- case Common::KEYCODE_y:
- if (type == 0)
- return 1;
- case Common::KEYCODE_n:
- if (type == 0)
- return 0;
- case Common::KEYCODE_ESCAPE:
- if (type == 1)
- return 0;
- case Common::KEYCODE_1:
- case Common::KEYCODE_2:
- case Common::KEYCODE_3:
- case Common::KEYCODE_4:
- case Common::KEYCODE_5:
- case Common::KEYCODE_6:
- case Common::KEYCODE_7:
- case Common::KEYCODE_8:
- case Common::KEYCODE_9:
- if (type == 1)
- return event.kbd.keycode - Common::KEYCODE_1 + 1;
- default:
- if (type == 0) {
- return 2;
- } else {
- return 10;
- }
- }
- break;
- default:
- break;
- }
- }
- }
- return 0;
-}
-
-bool PreAgiEngine::waitAnyKeyChoice() {
- Common::Event event;
-
- for (;;) {
- while (_eventMan->pollEvent(event)) {
- switch(event.type) {
- case Common::EVENT_QUIT:
- _system->quit();
- case Common::EVENT_LBUTTONUP:
- return true;
- case Common::EVENT_RBUTTONUP:
- return false;
- case Common::EVENT_KEYDOWN:
- switch (event.kbd.keycode) {
- case Common::KEYCODE_ESCAPE: //Escape
- return false;
- default:
- return true;
- }
- break;
- default:
- break;
- }
- }
- }
-}
-
-void PreAgiEngine::waitAnyKey(bool anim) {
- Common::Event event;
-
- for (;;) {
- while (_eventMan->pollEvent(event)) {
- switch(event.type) {
- case Common::EVENT_QUIT:
- _system->quit();
- case Common::EVENT_KEYDOWN:
- case Common::EVENT_LBUTTONUP:
- case Common::EVENT_RBUTTONUP:
- return;
- default:
- break;
- }
- }
- // TODO
- /*if (anim) {
- _game->Animate();
- UpdateScreen();
- }*/
- }
-}
-
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list