2007-05-30 21:56:52 +00:00
|
|
|
/* 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.
|
2002-03-25 08:51:34 +00:00
|
|
|
*
|
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-03-25 08:51:34 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2009-03-20 16:33:58 +00:00
|
|
|
#include "scumm/scumm_v4.h"
|
2006-03-03 15:16:02 +00:00
|
|
|
#include "scumm/file.h"
|
2005-04-03 15:06:08 +00:00
|
|
|
#include "scumm/resource.h"
|
2005-04-10 12:59:17 +00:00
|
|
|
#include "scumm/util.h"
|
2003-10-03 18:33:57 +00:00
|
|
|
|
|
|
|
namespace Scumm {
|
2002-03-25 02:09:05 +00:00
|
|
|
|
2011-05-13 12:04:59 +00:00
|
|
|
extern const char *nameOfResType(ResType type);
|
2007-02-24 19:20:15 +00:00
|
|
|
|
2011-05-13 12:02:53 +00:00
|
|
|
int ScummEngine_v4::readResTypeList(ResType type) {
|
|
|
|
uint num;
|
2007-02-24 19:20:15 +00:00
|
|
|
|
2011-05-13 12:04:59 +00:00
|
|
|
debug(9, "readResTypeList(%s)", nameOfResType(type));
|
2007-02-24 19:20:15 +00:00
|
|
|
|
|
|
|
num = _fileHandle->readUint16LE();
|
|
|
|
|
2011-05-13 12:48:01 +00:00
|
|
|
if (num != _res->_types[type].size()) {
|
2011-05-13 12:04:59 +00:00
|
|
|
error("Invalid number of %ss (%d) in directory", nameOfResType(type), num);
|
2007-02-24 19:20:15 +00:00
|
|
|
}
|
|
|
|
|
2011-05-13 12:02:53 +00:00
|
|
|
for (ResId idx = 0; idx < num; idx++) {
|
2011-05-13 12:48:01 +00:00
|
|
|
_res->_types[type][idx]._roomno = _fileHandle->readByte();
|
|
|
|
_res->_types[type][idx]._roomoffs = _fileHandle->readUint32LE();
|
2007-02-24 19:20:15 +00:00
|
|
|
}
|
2011-04-05 11:44:50 +00:00
|
|
|
|
|
|
|
return num;
|
2007-02-24 19:20:15 +00:00
|
|
|
}
|
|
|
|
|
2005-04-03 15:06:08 +00:00
|
|
|
void ScummEngine_v4::readIndexFile() {
|
|
|
|
uint16 blocktype;
|
|
|
|
uint32 itemsize;
|
|
|
|
int numblock = 0;
|
|
|
|
|
|
|
|
debug(9, "readIndexFile()");
|
|
|
|
|
|
|
|
closeRoom();
|
|
|
|
openRoom(0);
|
|
|
|
|
2009-07-20 20:55:28 +00:00
|
|
|
while (true) {
|
2005-04-10 00:33:31 +00:00
|
|
|
// Figure out the sizes of various resources
|
2005-04-03 15:06:08 +00:00
|
|
|
itemsize = _fileHandle->readUint32LE();
|
|
|
|
blocktype = _fileHandle->readUint16LE();
|
2009-07-20 20:55:28 +00:00
|
|
|
if (_fileHandle->eos() || _fileHandle->err())
|
2005-04-03 15:06:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
switch (blocktype) {
|
|
|
|
case 0x4E52: // 'NR'
|
|
|
|
_fileHandle->readUint16LE();
|
|
|
|
break;
|
|
|
|
case 0x5230: // 'R0'
|
|
|
|
_numRooms = _fileHandle->readUint16LE();
|
|
|
|
break;
|
|
|
|
case 0x5330: // 'S0'
|
|
|
|
_numScripts = _fileHandle->readUint16LE();
|
|
|
|
break;
|
|
|
|
case 0x4E30: // 'N0'
|
|
|
|
_numSounds = _fileHandle->readUint16LE();
|
|
|
|
break;
|
|
|
|
case 0x4330: // 'C0'
|
|
|
|
_numCostumes = _fileHandle->readUint16LE();
|
|
|
|
break;
|
|
|
|
case 0x4F30: // 'O0'
|
|
|
|
_numGlobalObjects = _fileHandle->readUint16LE();
|
2006-07-05 22:27:11 +00:00
|
|
|
|
|
|
|
// Indy3 FM-TOWNS has 32 extra bytes of unknown meaning
|
|
|
|
if (_game.id == GID_INDY3 && _game.platform == Common::kPlatformFMTowns)
|
|
|
|
itemsize += 32;
|
2005-04-03 15:06:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
_fileHandle->seek(itemsize - 8, SEEK_CUR);
|
|
|
|
}
|
|
|
|
|
|
|
|
_fileHandle->seek(0, SEEK_SET);
|
|
|
|
|
2005-04-03 23:53:34 +00:00
|
|
|
readMAXS(0);
|
2005-04-10 00:51:47 +00:00
|
|
|
allocateArrays();
|
2005-04-03 15:06:08 +00:00
|
|
|
|
2009-07-20 20:55:28 +00:00
|
|
|
while (true) {
|
2005-04-03 15:06:08 +00:00
|
|
|
itemsize = _fileHandle->readUint32LE();
|
|
|
|
|
2009-07-20 20:55:28 +00:00
|
|
|
if (_fileHandle->eos() || _fileHandle->err())
|
2005-04-03 15:06:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
blocktype = _fileHandle->readUint16LE();
|
|
|
|
|
|
|
|
numblock++;
|
|
|
|
|
|
|
|
switch (blocktype) {
|
|
|
|
|
|
|
|
case 0x4E52: // 'NR'
|
2005-04-10 13:16:49 +00:00
|
|
|
// Names of rooms. Maybe we should put them into a table, for use by the debugger?
|
|
|
|
for (int room; (room = _fileHandle->readByte()); ) {
|
|
|
|
char buf[10];
|
|
|
|
_fileHandle->read(buf, 9);
|
|
|
|
buf[9] = 0;
|
|
|
|
for (int i = 0; i < 9; i++)
|
|
|
|
buf[i] ^= 0xFF;
|
2005-10-28 04:27:54 +00:00
|
|
|
debug(5, "Room %d: '%s'", room, buf);
|
2005-04-10 13:16:49 +00:00
|
|
|
}
|
2005-04-03 15:06:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x5230: // 'R0'
|
2007-02-24 19:29:40 +00:00
|
|
|
readResTypeList(rtRoom);
|
2005-04-03 15:06:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x5330: // 'S0'
|
2007-02-24 19:29:40 +00:00
|
|
|
readResTypeList(rtScript);
|
2005-04-03 15:06:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x4E30: // 'N0'
|
2007-02-24 19:29:40 +00:00
|
|
|
readResTypeList(rtSound);
|
2005-04-03 15:06:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x4330: // 'C0'
|
2007-02-24 19:29:40 +00:00
|
|
|
readResTypeList(rtCostume);
|
2005-04-03 15:06:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x4F30: // 'O0'
|
|
|
|
readGlobalObjects();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-05-31 10:02:16 +00:00
|
|
|
error("Bad ID %c%c found in directory", blocktype & 0xFF, blocktype >> 8);
|
2005-04-03 15:06:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
closeRoom();
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine_v4::loadCharset(int no) {
|
2002-03-25 02:09:05 +00:00
|
|
|
uint32 size;
|
2002-04-20 04:09:02 +00:00
|
|
|
memset(_charsetData, 0, sizeof(_charsetData));
|
2002-04-04 23:02:02 +00:00
|
|
|
|
2006-09-16 13:38:43 +00:00
|
|
|
assertRange(0, no, 4, "charset");
|
2002-12-22 21:58:16 +00:00
|
|
|
closeRoom();
|
2002-03-25 02:09:05 +00:00
|
|
|
|
2005-05-10 22:56:25 +00:00
|
|
|
Common::File file;
|
2005-04-04 00:12:41 +00:00
|
|
|
char buf[20];
|
2002-03-25 02:09:05 +00:00
|
|
|
|
2005-04-04 00:12:41 +00:00
|
|
|
sprintf(buf, "%03d.LFL", 900 + no);
|
|
|
|
file.open(buf);
|
2002-03-25 02:09:05 +00:00
|
|
|
|
2005-04-04 00:12:41 +00:00
|
|
|
if (file.isOpen() == false) {
|
|
|
|
error("loadCharset(%d): Missing file charset: %s", no, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
size = file.readUint32LE() + 11;
|
2006-09-17 20:36:48 +00:00
|
|
|
file.read(_res->createResource(rtCharset, no, size), size);
|
2002-03-25 02:09:05 +00:00
|
|
|
}
|
2003-10-03 18:33:57 +00:00
|
|
|
|
2005-04-03 23:53:34 +00:00
|
|
|
void ScummEngine_v4::readMAXS(int blockSize) {
|
2005-04-03 15:06:08 +00:00
|
|
|
// FIXME - I'm not sure for those values yet, they will have to be rechecked
|
|
|
|
|
|
|
|
_numVariables = 800; // 800
|
|
|
|
_numBitVariables = 4096; // 2048
|
|
|
|
_numLocalObjects = 200; // 200
|
|
|
|
_numArray = 50;
|
|
|
|
_numVerbs = 100;
|
|
|
|
_numNewNames = 50;
|
|
|
|
_objectRoomTable = NULL;
|
|
|
|
_numCharsets = 9; // 9
|
|
|
|
_numInventory = 80; // 80
|
|
|
|
_numGlobalScripts = 200;
|
|
|
|
_numFlObject = 50;
|
|
|
|
|
|
|
|
_shadowPaletteSize = 256;
|
|
|
|
|
|
|
|
_shadowPalette = (byte *) calloc(_shadowPaletteSize, 1); // FIXME - needs to be removed later
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScummEngine_v4::readGlobalObjects() {
|
2005-04-03 23:53:34 +00:00
|
|
|
int i;
|
2005-04-03 15:06:08 +00:00
|
|
|
int num = _fileHandle->readUint16LE();
|
|
|
|
assert(num == _numGlobalObjects);
|
2005-04-03 23:53:34 +00:00
|
|
|
|
|
|
|
uint32 bits;
|
|
|
|
byte tmp;
|
2009-10-08 09:33:20 +00:00
|
|
|
if (_game.id == GID_LOOM && _game.platform == Common::kPlatformPCEngine) {
|
|
|
|
for (i = 0; i != num; i++) {
|
|
|
|
bits = _fileHandle->readByte();
|
|
|
|
bits |= _fileHandle->readByte() << 8;
|
|
|
|
bits |= _fileHandle->readByte() << 16;
|
|
|
|
_classData[i] = bits;
|
|
|
|
}
|
|
|
|
for (i = 0; i != num; i++) {
|
|
|
|
tmp = _fileHandle->readByte();
|
|
|
|
_objectOwnerTable[i] = tmp & OF_OWNER_MASK;
|
|
|
|
_objectStateTable[i] = tmp >> OF_STATE_SHL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; i != num; i++) {
|
|
|
|
bits = _fileHandle->readByte();
|
|
|
|
bits |= _fileHandle->readByte() << 8;
|
|
|
|
bits |= _fileHandle->readByte() << 16;
|
|
|
|
_classData[i] = bits;
|
|
|
|
tmp = _fileHandle->readByte();
|
|
|
|
_objectOwnerTable[i] = tmp & OF_OWNER_MASK;
|
|
|
|
_objectStateTable[i] = tmp >> OF_STATE_SHL;
|
|
|
|
}
|
2005-04-03 15:06:08 +00:00
|
|
|
}
|
2006-07-05 22:27:11 +00:00
|
|
|
|
|
|
|
// FIXME: Indy3 FM-TOWNS has 32 extra bytes of unknown meaning
|
|
|
|
if (_game.id == GID_INDY3 && _game.platform == Common::kPlatformFMTowns)
|
|
|
|
_fileHandle->seek(32, SEEK_CUR);
|
2005-04-03 15:06:08 +00:00
|
|
|
}
|
|
|
|
|
2005-04-03 23:53:34 +00:00
|
|
|
|
2003-10-03 18:33:57 +00:00
|
|
|
} // End of namespace Scumm
|