2002-05-22 12:20:36 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2001-10-09 14:30:12 +00:00
|
|
|
* Copyright (C) 2001 Ludvig Strigeus
|
2002-03-20 17:51:07 +00:00
|
|
|
* Copyright (C) 2001/2002 The ScummVM project
|
2001-10-09 14:30:12 +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
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
2001-11-06 20:00:47 +00:00
|
|
|
* $Header$
|
2001-10-09 14:30:12 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "scumm.h"
|
2002-07-16 21:03:14 +00:00
|
|
|
#include "resource.h"
|
|
|
|
|
2002-07-09 14:31:00 +00:00
|
|
|
#include <stdio.h>
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-07-16 21:03:14 +00:00
|
|
|
|
|
|
|
uint16 newTag2Old(uint32 oldTag);
|
|
|
|
|
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
/* Open a room */
|
2002-04-11 17:19:16 +00:00
|
|
|
void Scumm::openRoom(int room)
|
|
|
|
{
|
2002-02-24 17:25:03 +00:00
|
|
|
int room_offs, roomlimit;
|
2001-10-09 14:30:12 +00:00
|
|
|
char buf[256];
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
debug(9, "openRoom(%d)", room);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
/* Don't load the same room again */
|
|
|
|
if (_lastLoadedRoom == room)
|
|
|
|
return;
|
|
|
|
_lastLoadedRoom = room;
|
|
|
|
|
|
|
|
/* Room -1 means close file */
|
2002-04-11 17:19:16 +00:00
|
|
|
if (room == -1) {
|
2001-10-09 14:30:12 +00:00
|
|
|
_encbyte = 0;
|
|
|
|
deleteRoomOffsets();
|
|
|
|
fileClose(_fileHandle);
|
|
|
|
_fileHandle = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Either xxx.lfl or monkey.xxx file name */
|
|
|
|
while (!_resFilePrefix) {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (_features & GF_SMALL_NAMES)
|
|
|
|
roomlimit = 98;
|
|
|
|
else
|
|
|
|
roomlimit = 900;
|
|
|
|
if (_features & GF_EXTERNAL_CHARSET && room >= roomlimit)
|
|
|
|
room_offs = 0;
|
|
|
|
else
|
|
|
|
room_offs = room ? _roomFileOffsets[room] : 0;
|
|
|
|
|
2002-03-10 17:33:04 +00:00
|
|
|
if (room_offs == (int)0xFFFFFFFF)
|
2001-10-09 14:30:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (room_offs != 0 && room != 0) {
|
|
|
|
_fileOffset = _roomFileOffsets[room];
|
|
|
|
return;
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
if (!(_features & GF_SMALL_HEADER)) {
|
2002-06-27 10:40:37 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (_features & GF_AFTER_V7)
|
2002-07-07 20:32:26 +00:00
|
|
|
sprintf(buf, "%s%s.la%d", _gameDataPath, _exe_name, room == 0 ? 0 : res.roomno[rtRoom][room]);
|
2002-06-27 10:40:37 +00:00
|
|
|
else if (_features & GF_HUMONGOUS)
|
2002-07-07 20:32:26 +00:00
|
|
|
sprintf(buf, "%s%s.he%.1d", _gameDataPath, _exe_name, room == 0 ? 0 : res.roomno[rtRoom][room]);
|
2002-02-23 23:23:28 +00:00
|
|
|
else
|
2002-07-07 20:32:26 +00:00
|
|
|
sprintf(buf, "%s%s.%.3d", _gameDataPath, _exe_name, room == 0 ? 0 : res.roomno[rtRoom][room]);
|
2002-06-27 10:40:37 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
_encbyte = (_features & GF_USE_KEY) ? 0x69 : 0;
|
|
|
|
} else if (!(_features & GF_SMALL_NAMES)) {
|
|
|
|
if (room == 0 || room >= 900) {
|
|
|
|
sprintf(buf, "%s%.3d.lfl", _gameDataPath, room);
|
2002-02-12 21:28:07 +00:00
|
|
|
_encbyte = 0;
|
|
|
|
if (openResourceFile(buf)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
askForDisk(buf);
|
|
|
|
|
|
|
|
} else {
|
2002-07-07 20:32:26 +00:00
|
|
|
sprintf(buf, "%sdisk%.2d.lec", _gameDataPath, res.roomno[rtRoom][room]);
|
2002-02-12 21:28:07 +00:00
|
|
|
_encbyte = 0x69;
|
|
|
|
}
|
|
|
|
} else {
|
2002-04-11 17:19:16 +00:00
|
|
|
sprintf(buf, "%s%.2d.lfl", _gameDataPath, room);
|
|
|
|
if (_features & GF_OLD_BUNDLE)
|
|
|
|
_encbyte = 0xFF;
|
|
|
|
else
|
|
|
|
_encbyte = 0;
|
2002-02-12 21:28:07 +00:00
|
|
|
}
|
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
if (openResourceFile(buf)) {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (room == 0)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
2002-04-11 17:19:16 +00:00
|
|
|
if (_features & GF_EXTERNAL_CHARSET && room >= roomlimit)
|
2002-02-20 21:56:38 +00:00
|
|
|
return;
|
2001-10-09 14:30:12 +00:00
|
|
|
readRoomsOffsets();
|
|
|
|
_fileOffset = _roomFileOffsets[room];
|
|
|
|
|
|
|
|
if (_fileOffset != 8)
|
|
|
|
return;
|
|
|
|
|
|
|
|
error("Room %d not in %s", room, buf);
|
|
|
|
return;
|
|
|
|
}
|
2001-10-23 19:51:50 +00:00
|
|
|
askForDisk(buf);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
sprintf(buf, "%.3d.lfl", room);
|
|
|
|
_encbyte = 0;
|
2002-04-11 17:19:16 +00:00
|
|
|
if (openResourceFile(buf))
|
2001-10-09 14:30:12 +00:00
|
|
|
break;
|
2001-10-23 19:51:50 +00:00
|
|
|
askForDisk(buf);
|
2002-04-11 17:19:16 +00:00
|
|
|
} while (1);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
deleteRoomOffsets();
|
2002-04-11 17:19:16 +00:00
|
|
|
_fileOffset = 0; /* start of file */
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete the currently loaded room offsets */
|
2002-04-11 17:19:16 +00:00
|
|
|
void Scumm::deleteRoomOffsets()
|
|
|
|
{
|
|
|
|
if (!(_features & GF_SMALL_HEADER) && !_dynamicRoomOffsets)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < _maxRooms; i++) {
|
|
|
|
if (_roomFileOffsets[i] != 0xFFFFFFFF)
|
2001-10-09 14:30:12 +00:00
|
|
|
_roomFileOffsets[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read room offsets */
|
2002-04-11 17:19:16 +00:00
|
|
|
void Scumm::readRoomsOffsets()
|
|
|
|
{
|
|
|
|
int num, room;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
debug(9, "readRoomOffsets()");
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
deleteRoomOffsets();
|
|
|
|
if (_features & GF_SMALL_NAMES)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!(_features & GF_SMALL_HEADER)) {
|
|
|
|
if (!_dynamicRoomOffsets)
|
|
|
|
return;
|
2002-02-12 21:28:07 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
fileSeek(_fileHandle, 16, SEEK_SET);
|
|
|
|
} else {
|
|
|
|
fileSeek(_fileHandle, 12, SEEK_SET); // Directlry searching for the room offset block would be more generic...
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
num = fileReadByte();
|
|
|
|
while (num) {
|
|
|
|
num--;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
room = fileReadByte();
|
2002-04-11 17:19:16 +00:00
|
|
|
if (_roomFileOffsets[room] != 0xFFFFFFFF) {
|
2001-10-09 14:30:12 +00:00
|
|
|
_roomFileOffsets[room] = fileReadDwordLE();
|
|
|
|
} else {
|
|
|
|
fileReadDwordLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
bool Scumm::openResourceFile(const char *filename)
|
|
|
|
{
|
2001-10-09 14:30:12 +00:00
|
|
|
char buf[256];
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
debug(9, "openResourceFile(%s)", filename);
|
2002-07-10 16:38:38 +00:00
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
if (_fileHandle != NULL) {
|
|
|
|
fileClose(_fileHandle);
|
|
|
|
_fileHandle = NULL;
|
|
|
|
}
|
|
|
|
|
2002-07-10 16:38:38 +00:00
|
|
|
strcpy(buf, filename);
|
2001-10-09 14:30:12 +00:00
|
|
|
_fileHandle = fileOpen(buf, 1);
|
2002-06-25 12:43:15 +00:00
|
|
|
if (!_fileHandle) {
|
2002-07-10 16:38:38 +00:00
|
|
|
char *e = strrchr(buf, '/');
|
|
|
|
if (!e)
|
|
|
|
e = buf;
|
2002-07-07 20:32:26 +00:00
|
|
|
do
|
|
|
|
*e = tolower(*e);
|
|
|
|
while (*e++);
|
2002-06-25 12:43:15 +00:00
|
|
|
_fileHandle = fileOpen(buf, 1);
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-07-09 14:31:00 +00:00
|
|
|
if (!_fileHandle) {
|
2002-07-10 16:38:38 +00:00
|
|
|
char *e = strrchr(buf, '/');
|
|
|
|
if (!e)
|
|
|
|
e = buf;
|
2002-07-09 14:31:00 +00:00
|
|
|
do
|
|
|
|
*e = toupper(*e);
|
|
|
|
while (*e++);
|
|
|
|
_fileHandle = fileOpen(buf, 1);
|
|
|
|
}
|
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
return _fileHandle != NULL;
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
void Scumm::askForDisk(const char *filename)
|
|
|
|
{
|
2002-06-18 01:23:24 +00:00
|
|
|
error("ask Cannot find '%s'", filename);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
void Scumm::readIndexFile()
|
|
|
|
{
|
|
|
|
uint32 blocktype, itemsize;
|
2001-10-09 14:30:12 +00:00
|
|
|
int numblock = 0;
|
2001-11-26 19:57:57 +00:00
|
|
|
int num, i;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-11-26 19:57:57 +00:00
|
|
|
debug(9, "readIndexFile()");
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
openRoom(-1);
|
|
|
|
openRoom(0);
|
|
|
|
|
2001-11-26 19:57:57 +00:00
|
|
|
if (!(_features & GF_AFTER_V6)) {
|
|
|
|
/* Figure out the sizes of various resources */
|
|
|
|
while (!fileEof(_fileHandle)) {
|
|
|
|
blocktype = fileReadDword();
|
|
|
|
itemsize = fileReadDwordBE();
|
|
|
|
if (fileReadFailed(_fileHandle))
|
|
|
|
break;
|
2002-04-11 17:19:16 +00:00
|
|
|
switch (blocktype) {
|
2001-11-26 19:57:57 +00:00
|
|
|
case MKID('DOBJ'):
|
|
|
|
_numGlobalObjects = fileReadWordLE();
|
2002-04-11 17:19:16 +00:00
|
|
|
itemsize -= 2;
|
2001-11-26 19:57:57 +00:00
|
|
|
break;
|
|
|
|
case MKID('DROO'):
|
|
|
|
_numRooms = fileReadWordLE();
|
2002-04-11 17:19:16 +00:00
|
|
|
itemsize -= 2;
|
2001-11-26 19:57:57 +00:00
|
|
|
break;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-11-26 19:57:57 +00:00
|
|
|
case MKID('DSCR'):
|
|
|
|
_numScripts = fileReadWordLE();
|
2002-04-11 17:19:16 +00:00
|
|
|
itemsize -= 2;
|
2001-11-26 19:57:57 +00:00
|
|
|
break;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-11-26 19:57:57 +00:00
|
|
|
case MKID('DCOS'):
|
|
|
|
_numCostumes = fileReadWordLE();
|
2002-04-11 17:19:16 +00:00
|
|
|
itemsize -= 2;
|
2001-11-26 19:57:57 +00:00
|
|
|
break;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-11-26 19:57:57 +00:00
|
|
|
case MKID('DSOU'):
|
|
|
|
_numSounds = fileReadWordLE();
|
2002-04-11 17:19:16 +00:00
|
|
|
itemsize -= 2;
|
2001-10-09 14:30:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
fileSeek(_fileHandle, itemsize - 8, SEEK_CUR);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2001-11-26 19:57:57 +00:00
|
|
|
clearFileReadFailed(_fileHandle);
|
|
|
|
fileSeek(_fileHandle, 0, SEEK_SET);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
while (1) {
|
|
|
|
blocktype = fileReadDword();
|
|
|
|
|
|
|
|
if (fileReadFailed(_fileHandle))
|
|
|
|
break;
|
|
|
|
itemsize = fileReadDwordBE();
|
|
|
|
|
|
|
|
numblock++;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
switch (blocktype) {
|
2001-10-16 10:01:48 +00:00
|
|
|
case MKID('DCHR'):
|
2002-04-11 17:19:16 +00:00
|
|
|
readResTypeList(rtCharset, MKID('CHAR'), "charset");
|
2001-10-16 10:01:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MKID('DOBJ'):
|
2002-07-04 15:48:17 +00:00
|
|
|
if (_features & GF_AFTER_V8)
|
|
|
|
num = fileReadDwordLE();
|
|
|
|
else
|
|
|
|
num = fileReadWordLE();
|
2001-11-26 19:57:57 +00:00
|
|
|
assert(num == _numGlobalObjects);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-07-07 20:32:26 +00:00
|
|
|
if (_features & GF_AFTER_V8) { /* FIXME: Not sure.. */
|
|
|
|
for (i = 0; i < num; i++) {
|
2002-07-04 15:48:17 +00:00
|
|
|
fileSeek(_fileHandle, 40, SEEK_CUR);
|
|
|
|
_objectStateTable[i] = fileReadByte();
|
|
|
|
_objectRoomTable[i] = fileReadByte();
|
|
|
|
_classData[i] = fileReadDwordLE();
|
|
|
|
}
|
|
|
|
memset(_objectOwnerTable, 0xFF, num);
|
|
|
|
} else if (_features & GF_AFTER_V7) {
|
2001-11-26 19:57:57 +00:00
|
|
|
fileRead(_fileHandle, _objectStateTable, num);
|
|
|
|
fileRead(_fileHandle, _objectRoomTable, num);
|
|
|
|
memset(_objectOwnerTable, 0xFF, num);
|
|
|
|
} else {
|
|
|
|
fileRead(_fileHandle, _objectOwnerTable, num);
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
_objectStateTable[i] = _objectOwnerTable[i] >> OF_STATE_SHL;
|
2001-11-26 19:57:57 +00:00
|
|
|
_objectOwnerTable[i] &= OF_OWNER_MASK;
|
|
|
|
}
|
|
|
|
}
|
2002-04-11 15:22:02 +00:00
|
|
|
|
2002-07-04 15:48:17 +00:00
|
|
|
if (!(_features & GF_AFTER_V8)) {
|
|
|
|
fileRead(_fileHandle, _classData, num * sizeof(uint32));
|
|
|
|
|
|
|
|
// Swap flag endian where applicable
|
2002-04-11 15:22:02 +00:00
|
|
|
#if defined(SCUMM_BIG_ENDIAN)
|
2002-07-04 15:48:17 +00:00
|
|
|
for (i = 0; i != num; i++)
|
|
|
|
_classData[i] = FROM_LE_32(_classData[i]);
|
2002-04-11 15:22:02 +00:00
|
|
|
#endif
|
2002-07-04 15:48:17 +00:00
|
|
|
}
|
2001-10-16 10:01:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MKID('RNAM'):
|
2001-11-26 19:57:57 +00:00
|
|
|
case MKID('ANAM'):
|
2002-04-11 17:19:16 +00:00
|
|
|
fileSeek(_fileHandle, itemsize - 8, SEEK_CUR);
|
2001-10-16 10:01:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MKID('DROO'):
|
2002-04-11 17:19:16 +00:00
|
|
|
readResTypeList(rtRoom, MKID('ROOM'), "room");
|
2001-10-16 10:01:48 +00:00
|
|
|
break;
|
|
|
|
|
2002-07-07 20:32:26 +00:00
|
|
|
case MKID('DRSC'): // FIXME: Verify
|
|
|
|
readResTypeList(rtRoomScripts, MKID('RMSC'), "room script");
|
2002-07-04 15:48:17 +00:00
|
|
|
break;
|
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
case MKID('DSCR'):
|
2002-04-11 17:19:16 +00:00
|
|
|
readResTypeList(rtScript, MKID('SCRP'), "script");
|
2001-10-16 10:01:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MKID('DCOS'):
|
2002-04-11 17:19:16 +00:00
|
|
|
readResTypeList(rtCostume, MKID('COST'), "costume");
|
2001-10-16 10:01:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MKID('MAXS'):
|
|
|
|
readMAXS();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MKID('DSOU'):
|
2002-04-11 17:19:16 +00:00
|
|
|
readResTypeList(rtSound, MKID('SOUN'), "sound");
|
2001-10-16 10:01:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MKID('AARY'):
|
|
|
|
readArrayFromIndexFile();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2002-04-11 17:19:16 +00:00
|
|
|
error("Bad ID %c%c%c%c found in directory!", blocktype & 0xFF,
|
|
|
|
blocktype >> 8, blocktype >> 16, blocktype >> 24);
|
2001-10-16 10:01:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
// if (numblock!=9)
|
|
|
|
// error("Not enough blocks read from directory");
|
2001-10-16 10:01:48 +00:00
|
|
|
|
|
|
|
openRoom(-1);
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
void Scumm::readArrayFromIndexFile()
|
|
|
|
{
|
2001-10-16 10:01:48 +00:00
|
|
|
int num;
|
2002-04-11 17:19:16 +00:00
|
|
|
int a, b, c;
|
2001-10-16 10:01:48 +00:00
|
|
|
|
|
|
|
while ((num = fileReadWordLE()) != 0) {
|
|
|
|
a = fileReadWordLE();
|
|
|
|
b = fileReadWordLE();
|
|
|
|
c = fileReadWordLE();
|
2002-04-11 17:19:16 +00:00
|
|
|
if (c == 1)
|
2001-10-16 10:01:48 +00:00
|
|
|
defineArray(num, 1, a, b);
|
|
|
|
else
|
|
|
|
defineArray(num, 5, a, b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
void Scumm::readResTypeList(int id, uint32 tag, const char *name)
|
|
|
|
{
|
2001-10-16 10:01:48 +00:00
|
|
|
int num;
|
|
|
|
int i;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-04-26 14:13:39 +00:00
|
|
|
debug(9, "readResTypeList(%s,%x,%s)", resTypeFromId(id), FROM_LE_32(tag), name);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-07-04 15:48:17 +00:00
|
|
|
if (_features & GF_AFTER_V8)
|
|
|
|
num = fileReadDwordLE();
|
|
|
|
else
|
|
|
|
num = fileReadWordLE();
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (1 || _features & GF_AFTER_V6) {
|
2001-10-23 19:51:50 +00:00
|
|
|
if (num != res.num[id]) {
|
2002-04-11 17:19:16 +00:00
|
|
|
error("Invalid number of %ss (%d) in directory", name, num);
|
2001-10-23 19:51:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (num >= 0xFF) {
|
2001-10-23 19:51:50 +00:00
|
|
|
error("Too many %ss (%d) in directory", name, num);
|
|
|
|
}
|
|
|
|
allocResTypeData(id, tag, num, name, 1);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2002-02-12 21:28:07 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (_features & GF_SMALL_HEADER) {
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
res.roomno[id][i] = fileReadByte();
|
|
|
|
res.roomoffs[id][i] = fileReadDword();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fileRead(_fileHandle, res.roomno[id], num * sizeof(uint8));
|
|
|
|
fileRead(_fileHandle, res.roomoffs[id], num * sizeof(uint32));
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
#if defined(SCUMM_BIG_ENDIAN)
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < num; i++)
|
2001-10-09 14:30:12 +00:00
|
|
|
res.roomoffs[id][i] = FROM_LE_32(res.roomoffs[id][i]);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
|
2002-07-07 20:32:26 +00:00
|
|
|
void Scumm::allocResTypeData(int id, uint32 tag, int num, const char *name, int mode)
|
2002-04-11 17:19:16 +00:00
|
|
|
{
|
2002-04-26 14:13:39 +00:00
|
|
|
debug(9, "allocResTypeData(%s/%s,%x,%d,%d)", resTypeFromId(id), name, FROM_LE_32(tag), num, mode);
|
2002-04-11 17:19:16 +00:00
|
|
|
assert(id >= 0 && id < (int)(sizeof(res.mode) / sizeof(res.mode[0])));
|
2001-10-16 10:01:48 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (num >= 2000) {
|
2001-10-16 10:01:48 +00:00
|
|
|
error("Too many %ss (%d) in directory", name, num);
|
|
|
|
}
|
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
res.mode[id] = mode;
|
|
|
|
res.num[id] = num;
|
|
|
|
res.tags[id] = tag;
|
|
|
|
res.name[id] = name;
|
2002-05-01 17:16:47 +00:00
|
|
|
res.address[id] = (byte **)calloc(num, sizeof(void *));
|
|
|
|
res.flags[id] = (byte *)calloc(num, sizeof(byte));
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
if (mode) {
|
2002-05-01 17:16:47 +00:00
|
|
|
res.roomno[id] = (byte *)calloc(num, sizeof(byte));
|
|
|
|
res.roomoffs[id] = (uint32 *)calloc(num, sizeof(uint32));
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
void Scumm::loadCharset(int no)
|
|
|
|
{
|
2002-04-13 04:39:04 +00:00
|
|
|
int i;
|
2001-10-09 14:30:12 +00:00
|
|
|
byte *ptr;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
debug(9, "loadCharset(%d)", no);
|
2002-03-31 09:06:51 +00:00
|
|
|
|
2002-05-11 20:00:32 +00:00
|
|
|
/* FIXME - hack around crash in Indy4 (occurs if you try to load after dieing) */
|
|
|
|
if (_gameId == GID_INDY4 && no == 0)
|
|
|
|
no = 1;
|
2002-04-11 15:22:02 +00:00
|
|
|
|
2002-03-31 09:06:51 +00:00
|
|
|
memset(_charsetData, 0, sizeof(_charsetData));
|
2002-03-16 18:03:28 +00:00
|
|
|
|
2002-07-07 20:32:26 +00:00
|
|
|
assert(no < (int)sizeof(_charsetData) / 16);
|
2002-04-11 17:19:16 +00:00
|
|
|
checkRange(_maxCharsets - 1, 1, no, "Loading illegal charset %d");
|
|
|
|
|
|
|
|
// ensureResourceLoaded(6, no);
|
2001-10-09 14:30:12 +00:00
|
|
|
ptr = getResourceAddress(6, no);
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < 15; i++) {
|
|
|
|
_charsetData[no][i + 1] = ptr[i + 14];
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
void Scumm::nukeCharset(int i)
|
|
|
|
{
|
|
|
|
checkRange(_maxCharsets - 1, 1, i, "Nuking illegal charset %d");
|
2001-11-05 19:21:49 +00:00
|
|
|
nukeResource(rtCharset, i);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
void Scumm::ensureResourceLoaded(int type, int i)
|
|
|
|
{
|
2001-10-09 14:30:12 +00:00
|
|
|
void *addr;
|
|
|
|
|
2002-04-26 14:13:39 +00:00
|
|
|
debug(9, "ensureResourceLoaded(%s,%d)", resTypeFromId(type), i);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (type == rtRoom && i > 127) {
|
|
|
|
i = _resourceMapper[i & 127];
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (i == 0)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
addr = res.address[type][i];
|
|
|
|
if (addr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
loadResource(type, i);
|
|
|
|
|
2002-07-07 20:32:26 +00:00
|
|
|
if (!(_features & GF_AFTER_V7) && !(_features & GF_SMALL_HEADER))
|
2002-04-11 17:19:16 +00:00
|
|
|
if (type == rtRoom && i == _roomResource)
|
2002-03-05 23:05:55 +00:00
|
|
|
_vars[VAR_ROOM_FLAG] = 1;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
int Scumm::loadResource(int type, int idx)
|
|
|
|
{
|
2001-10-09 14:30:12 +00:00
|
|
|
int roomNr, i;
|
|
|
|
uint32 fileOffs;
|
|
|
|
uint32 size, tag;
|
|
|
|
|
2002-07-07 20:32:26 +00:00
|
|
|
// debug(1, "loadResource(%s,%d)", resTypeFromId(type),idx);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
if (type == rtCharset && (_features & GF_SMALL_HEADER)) {
|
|
|
|
loadCharset(idx);
|
|
|
|
return (1);
|
|
|
|
}
|
2002-02-12 21:28:07 +00:00
|
|
|
|
2002-03-08 08:42:11 +00:00
|
|
|
roomNr = getResourceRoomNr(type, idx);
|
2002-05-08 06:57:27 +00:00
|
|
|
|
|
|
|
if (idx >= res.num[type])
|
|
|
|
error("%s %d undefined %d %d", res.name[type], idx, res.num[type], roomNr);
|
|
|
|
|
|
|
|
if (roomNr == 0)
|
|
|
|
roomNr = _roomResource;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (type == rtRoom) {
|
2001-10-09 14:30:12 +00:00
|
|
|
fileOffs = 0;
|
|
|
|
} else {
|
2002-03-08 08:42:11 +00:00
|
|
|
fileOffs = res.roomoffs[type][idx];
|
2002-04-11 17:19:16 +00:00
|
|
|
if (fileOffs == 0xFFFFFFFF)
|
2001-10-09 14:30:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
do {
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < 5; i++) {
|
2001-10-09 14:30:12 +00:00
|
|
|
openRoom(roomNr);
|
|
|
|
|
|
|
|
fileSeek(_fileHandle, fileOffs + _fileOffset, SEEK_SET);
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (_features & GF_SMALL_HEADER) {
|
|
|
|
if (!(_features & GF_SMALL_NAMES))
|
|
|
|
fileSeek(_fileHandle, 8, SEEK_CUR);
|
|
|
|
size = fileReadDwordLE();
|
|
|
|
tag = fileReadWordLE();
|
|
|
|
fileSeek(_fileHandle, -6, SEEK_CUR);
|
|
|
|
} else {
|
|
|
|
if (type == rtSound) {
|
|
|
|
fileReadDwordLE();
|
|
|
|
fileReadDwordLE();
|
|
|
|
return readSoundResource(type, idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
tag = fileReadDword();
|
|
|
|
|
|
|
|
if (tag != res.tags[type]) {
|
2002-07-07 20:32:26 +00:00
|
|
|
error("%s %d not in room %d at %d+%d", res.name[type], type, roomNr, _fileOffset, fileOffs);
|
2002-04-11 17:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size = fileReadDwordBE();
|
|
|
|
fileSeek(_fileHandle, -8, SEEK_CUR);
|
|
|
|
}
|
2002-03-08 08:42:11 +00:00
|
|
|
fileRead(_fileHandle, createResource(type, idx, size), size);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
/* dump the resource */
|
2001-10-09 14:30:12 +00:00
|
|
|
#ifdef DUMP_SCRIPTS
|
2002-04-11 17:19:16 +00:00
|
|
|
if (type == rtScript) {
|
2002-03-08 08:42:11 +00:00
|
|
|
dumpResource("script-", idx, getResourceAddress(rtScript, idx));
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!fileReadFailed(_fileHandle)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-03-08 08:42:11 +00:00
|
|
|
nukeResource(type, idx);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
error("Cannot read resource");
|
2002-04-11 17:19:16 +00:00
|
|
|
} while (1);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
int Scumm::readSoundResource(int type, int idx)
|
|
|
|
{
|
|
|
|
uint32 pos, total_size, size, tag, basetag;
|
2001-12-01 17:06:13 +00:00
|
|
|
int pri, best_pri;
|
2002-04-11 17:19:16 +00:00
|
|
|
uint32 best_size = 0, best_offs = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-26 14:13:39 +00:00
|
|
|
debug(9, "readSoundResource(%s,%d)", resTypeFromId(type), idx);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-12-01 17:06:13 +00:00
|
|
|
pos = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-03-16 18:58:51 +00:00
|
|
|
basetag = fileReadDword();
|
2001-12-01 17:06:13 +00:00
|
|
|
total_size = fileReadDwordBE();
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-05-23 00:45:59 +00:00
|
|
|
debug(8, " basetag: %c%c%c%c, total_size=%d",
|
2002-07-07 20:32:26 +00:00
|
|
|
(char)((basetag >> 24) & 0xff),
|
|
|
|
(char)((basetag >> 16) & 0xff),
|
|
|
|
(char)((basetag >> 8) & 0xff), (char)(basetag & 0xff), total_size);
|
2002-05-17 21:58:59 +00:00
|
|
|
|
2002-05-13 08:25:58 +00:00
|
|
|
//if (_gameId == GID_SAMNMAX || _features & GF_AFTER_V7) {
|
|
|
|
if (basetag == MKID('MIDI') || basetag == MKID('iMUS')) {
|
|
|
|
fileSeek(_fileHandle, -8, SEEK_CUR);
|
2002-07-07 20:32:26 +00:00
|
|
|
fileRead(_fileHandle, createResource(type, idx, total_size + 8), total_size + 8);
|
2002-05-13 08:25:58 +00:00
|
|
|
return 1;
|
2002-03-16 05:33:25 +00:00
|
|
|
} else if (basetag == MKID('SOU ')) {
|
2002-03-05 22:23:48 +00:00
|
|
|
best_pri = -1;
|
|
|
|
while (pos < total_size) {
|
|
|
|
tag = fileReadDword();
|
|
|
|
size = fileReadDwordBE() + 8;
|
|
|
|
pos += size;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-04-13 18:34:11 +00:00
|
|
|
pri = -1;
|
2002-07-07 20:32:26 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
switch (tag) {
|
2002-08-19 12:56:12 +00:00
|
|
|
case MKID('SBL '):
|
|
|
|
pri = 15;
|
|
|
|
break;
|
2002-04-11 17:19:16 +00:00
|
|
|
case MKID('ADL '):
|
2002-04-13 18:34:11 +00:00
|
|
|
if (_use_adlib)
|
|
|
|
pri = 10;
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
|
|
|
case MKID('ROL '):
|
2002-04-13 18:34:11 +00:00
|
|
|
if (!_use_adlib)
|
2002-04-26 16:52:00 +00:00
|
|
|
pri = 2;
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
|
|
|
case MKID('GMD '):
|
2002-04-13 18:34:11 +00:00
|
|
|
if (!_use_adlib)
|
2002-04-26 16:52:00 +00:00
|
|
|
pri = 3;
|
|
|
|
break;
|
|
|
|
case MKID('MAC '):
|
|
|
|
if (!_use_adlib)
|
|
|
|
pri = 1;
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
2002-05-05 20:01:54 +00:00
|
|
|
case MKID('SPK '):
|
|
|
|
if (!_use_adlib)
|
|
|
|
pri = 0;
|
|
|
|
break;
|
2002-03-05 22:23:48 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-05-23 00:45:59 +00:00
|
|
|
debug(8, " tag: %c%c%c%c, total_size=%d, pri=%d",
|
2002-07-07 20:32:26 +00:00
|
|
|
(char)((tag >> 24) & 0xff),
|
|
|
|
(char)((tag >> 16) & 0xff), (char)((tag >> 8) & 0xff), (char)(tag & 0xff), size, pri);
|
|
|
|
|
2002-05-17 21:58:59 +00:00
|
|
|
|
2002-03-05 22:23:48 +00:00
|
|
|
if (pri > best_pri) {
|
|
|
|
best_pri = pri;
|
|
|
|
best_size = size;
|
|
|
|
best_offs = filePos(_fileHandle);
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-03-05 22:23:48 +00:00
|
|
|
fileSeek(_fileHandle, size - 8, SEEK_CUR);
|
2001-12-01 17:06:13 +00:00
|
|
|
}
|
|
|
|
|
2002-03-05 22:23:48 +00:00
|
|
|
if (best_pri != -1) {
|
|
|
|
fileSeek(_fileHandle, best_offs - 8, SEEK_SET);
|
2002-04-11 17:19:16 +00:00
|
|
|
fileRead(_fileHandle, createResource(type, idx, best_size), best_size);
|
2002-03-05 22:23:48 +00:00
|
|
|
return 1;
|
2002-04-11 17:19:16 +00:00
|
|
|
}
|
2002-03-16 05:33:25 +00:00
|
|
|
} else if (FROM_LE_32(basetag) == 24) {
|
|
|
|
fileSeek(_fileHandle, -12, SEEK_CUR);
|
|
|
|
total_size = fileReadDwordBE();
|
|
|
|
fileSeek(_fileHandle, -8, SEEK_CUR);
|
|
|
|
fileRead(_fileHandle, createResource(type, idx, total_size), total_size);
|
|
|
|
return 1;
|
2002-04-26 16:52:00 +00:00
|
|
|
} else if (basetag == MKID('Mac0')) {
|
2002-05-17 21:58:59 +00:00
|
|
|
debug(1, "Found base tag Mac0 in sound %d, size %d", idx, total_size);
|
2002-04-26 16:52:00 +00:00
|
|
|
debug(1, "It was at position %d", filePos(_fileHandle));
|
2002-07-07 20:32:26 +00:00
|
|
|
|
2002-04-26 16:52:00 +00:00
|
|
|
/* Offset
|
|
|
|
0x14, 0x1C, 0x20, 0x24 - offsets of channel 1/2/3/4 chunk-
|
|
|
|
Each channel has tag "Chan", followed by its length. At the end
|
|
|
|
of each chan follows either an empty "Done" chunk (length 0) or an
|
|
|
|
empty "Loop" chunk. Maybe "Loop" indicates the song should be
|
|
|
|
played forever?!?.
|
2002-07-07 20:32:26 +00:00
|
|
|
|
2002-05-17 21:58:59 +00:00
|
|
|
There can be various different subchunks it seems. The
|
|
|
|
following combinations appear in Monkey Island:
|
2002-07-07 20:32:26 +00:00
|
|
|
100: ORGA, TROM, BASS,
|
|
|
|
101: ORGA, SHAK, BASS,
|
|
|
|
103: PIPE, PIPE, PIPE,
|
|
|
|
104: VIBE, WHIS, BASS,
|
|
|
|
108: ORGA, MARI, BASS,
|
|
|
|
110: ORGA, SHAK, VIBE,
|
|
|
|
111: MARI, SHAK, BASS,
|
|
|
|
115: PLUC, SHAK, WHIS,
|
2002-05-17 21:58:59 +00:00
|
|
|
One guess is that these are instrument names: Organ, Marimba, Whistle...
|
|
|
|
Maybe there is a mapping table someplace? Maybe these are even mapped to
|
|
|
|
Mac1 type "instruments" ?
|
2002-07-07 20:32:26 +00:00
|
|
|
|
2002-04-26 16:52:00 +00:00
|
|
|
What follows are four byte "commands" it seems, like this (hex):
|
2002-07-07 20:32:26 +00:00
|
|
|
01 68 4F 49
|
|
|
|
01 68 00 40
|
|
|
|
01 68 4F 49
|
|
|
|
...
|
|
|
|
01 68 00 40
|
|
|
|
02 1C 5B 40
|
|
|
|
00 B4 00 40
|
|
|
|
...
|
|
|
|
01 68 37 3C
|
|
|
|
00 18 37 38
|
|
|
|
04 20 3E 34
|
|
|
|
01 68 4A 3C
|
|
|
|
|
2002-04-26 16:52:00 +00:00
|
|
|
More data:
|
2002-07-07 20:32:26 +00:00
|
|
|
00 09 3E 10
|
|
|
|
01 5F 00 40
|
|
|
|
00 9C 36 40
|
|
|
|
00 CC 00 40
|
|
|
|
00 18 42 49
|
|
|
|
00 18 45 3C
|
|
|
|
01 29 4A 3C
|
|
|
|
00 0F 00 40
|
|
|
|
|
2002-04-26 16:52:00 +00:00
|
|
|
Maybe I am mistaken when I think it's four byte, some other parts
|
2002-08-19 12:56:12 +00:00
|
|
|
seem to suggest it's 2 byte oriented, or even variable length...
|
2002-04-26 16:52:00 +00:00
|
|
|
*/
|
2002-05-17 21:58:59 +00:00
|
|
|
fileSeek(_fileHandle, -12, SEEK_CUR);
|
|
|
|
total_size = fileReadDwordBE();
|
|
|
|
fileRead(_fileHandle, createResource(type, idx, total_size), total_size - 8);
|
|
|
|
return 1;
|
2002-04-26 16:52:00 +00:00
|
|
|
} else if (basetag == MKID('Mac1')) {
|
2002-07-02 21:28:57 +00:00
|
|
|
fileSeek(_fileHandle, -12, SEEK_CUR);
|
|
|
|
total_size = fileReadDwordBE();
|
|
|
|
fileRead(_fileHandle, createResource(type, idx, total_size), total_size - 8);
|
|
|
|
return 1;
|
|
|
|
} else if (basetag == MKID('DIGI')) {
|
|
|
|
// Use in Putt-Putt Demo
|
|
|
|
debug(1, "Found base tag DIGI in sound %d, size %d", idx, total_size);
|
|
|
|
debug(1, "It was at position %d", filePos(_fileHandle));
|
|
|
|
|
2002-08-20 09:58:35 +00:00
|
|
|
fileSeek(_fileHandle, -12, SEEK_CUR);
|
|
|
|
total_size = fileReadDwordBE();
|
|
|
|
fileRead(_fileHandle, createResource(type, idx, total_size), total_size - 8);
|
|
|
|
return 1;
|
|
|
|
} else if (basetag == MKID('Crea')) {
|
2002-05-17 21:58:59 +00:00
|
|
|
fileSeek(_fileHandle, -12, SEEK_CUR);
|
|
|
|
total_size = fileReadDwordBE();
|
|
|
|
fileRead(_fileHandle, createResource(type, idx, total_size), total_size - 8);
|
|
|
|
return 1;
|
2002-03-16 05:33:25 +00:00
|
|
|
} else {
|
2002-07-07 20:32:26 +00:00
|
|
|
fprintf(stderr, "WARNING: Unrecognized base tag 0x%08lx in sound %d\n", basetag, idx);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2002-03-08 08:42:11 +00:00
|
|
|
res.roomoffs[type][idx] = 0xFFFFFFFF;
|
2001-10-09 14:30:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
int Scumm::getResourceRoomNr(int type, int idx)
|
|
|
|
{
|
|
|
|
if (type == rtRoom)
|
2002-03-08 08:42:11 +00:00
|
|
|
return idx;
|
|
|
|
return res.roomno[type][idx];
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
byte *Scumm::getResourceAddress(int type, int idx)
|
|
|
|
{
|
2001-10-09 14:30:12 +00:00
|
|
|
byte *ptr;
|
2002-07-07 20:32:26 +00:00
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
CHECK_HEAP validateResource("getResourceAddress", type, idx);
|
2002-04-26 14:13:39 +00:00
|
|
|
if (!res.address[type]) {
|
|
|
|
debug(9, "getResourceAddress(%s,%d) == NULL", resTypeFromId(type), idx);
|
2002-03-16 18:03:28 +00:00
|
|
|
return NULL;
|
2002-04-26 14:13:39 +00:00
|
|
|
}
|
2002-03-16 18:03:28 +00:00
|
|
|
|
2002-03-08 08:42:11 +00:00
|
|
|
if (res.mode[type] && !res.address[type][idx]) {
|
|
|
|
ensureResourceLoaded(type, idx);
|
2002-04-11 17:19:16 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-04-26 14:13:39 +00:00
|
|
|
if (!(ptr = (byte *)res.address[type][idx])) {
|
|
|
|
debug(9, "getResourceAddress(%s,%d) == NULL", resTypeFromId(type), idx);
|
2001-10-09 14:30:12 +00:00
|
|
|
return NULL;
|
2002-04-26 14:13:39 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-03-08 08:42:11 +00:00
|
|
|
setResourceCounter(type, idx, 1);
|
2001-11-14 18:40:39 +00:00
|
|
|
|
2002-04-26 14:13:39 +00:00
|
|
|
debug(9, "getResourceAddress(%s,%d) == %ld", resTypeFromId(type), idx, ptr + sizeof(MemBlkHeader));
|
2001-12-11 13:34:15 +00:00
|
|
|
return ptr + sizeof(MemBlkHeader);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
byte *Scumm::getStringAddress(int i)
|
|
|
|
{
|
2001-11-05 19:21:49 +00:00
|
|
|
byte *b = getResourceAddress(rtString, i);
|
2001-10-24 20:12:52 +00:00
|
|
|
if (!b)
|
|
|
|
return b;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2001-11-26 19:57:57 +00:00
|
|
|
if (_features & GF_NEW_OPCODES)
|
2002-04-11 17:19:16 +00:00
|
|
|
return ((ArrayHeader *)b)->data;
|
2001-10-24 20:12:52 +00:00
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
2002-04-24 04:26:09 +00:00
|
|
|
|
|
|
|
|
2002-07-07 20:32:26 +00:00
|
|
|
byte *Scumm::getStringAddressVar(int i)
|
|
|
|
{
|
2002-04-21 19:38:00 +00:00
|
|
|
byte *addr;
|
|
|
|
|
2002-07-07 20:32:26 +00:00
|
|
|
addr = getResourceAddress(rtString, _vars[i]);
|
|
|
|
if (addr == NULL)
|
|
|
|
error("NULL string var %d slot %d", i, _vars[i]);
|
2002-04-21 19:38:00 +00:00
|
|
|
|
|
|
|
if (_features & GF_NEW_OPCODES)
|
2002-07-07 20:32:26 +00:00
|
|
|
return ((ArrayHeader *)addr)->data;
|
2002-04-21 19:38:00 +00:00
|
|
|
|
2002-07-07 20:32:26 +00:00
|
|
|
return (addr);
|
2002-04-21 19:38:00 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
void Scumm::setResourceCounter(int type, int idx, byte flag)
|
|
|
|
{
|
2002-03-08 08:42:11 +00:00
|
|
|
res.flags[type][idx] &= ~RF_USAGE;
|
|
|
|
res.flags[type][idx] |= flag;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
/* 2 bytes safety area to make "precaching" of bytes in the gdi drawer easier */
|
|
|
|
#define SAFETY_AREA 2
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
byte *Scumm::createResource(int type, int idx, uint32 size)
|
|
|
|
{
|
2001-10-09 14:30:12 +00:00
|
|
|
byte *ptr;
|
|
|
|
|
2002-07-07 20:32:26 +00:00
|
|
|
CHECK_HEAP debug(9, "createResource(%s,%d,%d)", resTypeFromId(type), idx, size);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-03-08 08:42:11 +00:00
|
|
|
validateResource("allocating", type, idx);
|
|
|
|
nukeResource(type, idx);
|
2001-10-10 10:02:33 +00:00
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
expireResources(size);
|
|
|
|
|
2002-05-01 17:16:47 +00:00
|
|
|
CHECK_HEAP ptr = (byte *)calloc(size + sizeof(MemBlkHeader) + SAFETY_AREA, 1);
|
2002-04-11 17:19:16 +00:00
|
|
|
if (ptr == NULL) {
|
2001-10-09 14:30:12 +00:00
|
|
|
error("Out of memory while allocating %d", size);
|
|
|
|
}
|
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
_allocatedSize += size;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-03-08 08:42:11 +00:00
|
|
|
res.address[type][idx] = ptr;
|
2002-04-11 17:19:16 +00:00
|
|
|
((MemBlkHeader *)ptr)->size = size;
|
2002-03-08 08:42:11 +00:00
|
|
|
setResourceCounter(type, idx, 1);
|
2002-04-11 17:19:16 +00:00
|
|
|
return ptr + sizeof(MemBlkHeader); /* skip header */
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
void Scumm::validateResource(const char *str, int type, int idx)
|
|
|
|
{
|
|
|
|
if (type < rtFirst || type > rtLast || (uint) idx >= (uint) res.num[type]) {
|
2002-04-26 14:13:39 +00:00
|
|
|
warning("%s Illegal Glob type %s (%d) num %d", str, resTypeFromId(type), type, idx);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
void Scumm::nukeResource(int type, int idx)
|
|
|
|
{
|
2001-11-05 19:21:49 +00:00
|
|
|
byte *ptr;
|
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
CHECK_HEAP if (!res.address[type])
|
2002-07-07 20:32:26 +00:00
|
|
|
return;
|
2002-03-14 13:57:28 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
assert(idx >= 0 && idx < res.num[type]);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-03-08 08:42:11 +00:00
|
|
|
if ((ptr = res.address[type][idx]) != NULL) {
|
2002-08-20 09:58:35 +00:00
|
|
|
debug(9, "nukeResource(%s,%d)", resTypeFromId(type), idx);
|
2002-03-08 08:42:11 +00:00
|
|
|
res.address[type][idx] = 0;
|
|
|
|
res.flags[type][idx] = 0;
|
2002-04-11 17:19:16 +00:00
|
|
|
_allocatedSize -= ((MemBlkHeader *)ptr)->size;
|
2001-11-05 19:21:49 +00:00
|
|
|
free(ptr);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
byte *Scumm::findResourceData(uint32 tag, byte *ptr)
|
|
|
|
{
|
|
|
|
if (_features & GF_SMALL_HEADER) {
|
|
|
|
ptr = findResourceSmall(tag, ptr, 0);
|
|
|
|
if (ptr == NULL)
|
|
|
|
return NULL;
|
|
|
|
return ptr + 6;
|
|
|
|
}
|
2002-02-12 21:28:07 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
ptr = findResource(tag, ptr, 0);
|
|
|
|
if (ptr == NULL)
|
2001-11-26 19:57:57 +00:00
|
|
|
return NULL;
|
|
|
|
return ptr + 8;
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
int Scumm::getResourceDataSize(byte *ptr)
|
|
|
|
{
|
|
|
|
if (ptr == NULL)
|
2001-12-27 17:51:58 +00:00
|
|
|
return 0;
|
2002-02-12 21:28:07 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (_features & GF_SMALL_HEADER)
|
|
|
|
return READ_LE_UINT32(ptr) - 6;
|
|
|
|
else
|
2002-04-16 12:07:19 +00:00
|
|
|
return READ_BE_UINT32_UNALIGNED(ptr - 4) - 8;
|
2001-12-27 17:51:58 +00:00
|
|
|
}
|
|
|
|
|
2001-11-26 19:57:57 +00:00
|
|
|
struct FindResourceState {
|
2002-04-11 17:19:16 +00:00
|
|
|
uint32 size, pos;
|
2001-11-26 19:57:57 +00:00
|
|
|
byte *ptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* just O(N) complexity when iterating with this function */
|
2002-04-11 17:19:16 +00:00
|
|
|
byte *findResource(uint32 tag, byte *searchin)
|
|
|
|
{
|
2001-11-26 19:57:57 +00:00
|
|
|
uint32 size;
|
|
|
|
static FindResourceState frs;
|
2002-04-11 17:19:16 +00:00
|
|
|
FindResourceState *f = &frs; /* easier to make it thread safe like this */
|
2001-11-26 19:57:57 +00:00
|
|
|
|
|
|
|
if (searchin) {
|
2002-04-11 17:19:16 +00:00
|
|
|
f->size = READ_BE_UINT32_UNALIGNED(searchin + 4);
|
2001-11-26 19:57:57 +00:00
|
|
|
f->pos = 8;
|
2002-04-11 17:19:16 +00:00
|
|
|
f->ptr = searchin + 8;
|
2001-11-26 19:57:57 +00:00
|
|
|
goto StartScan;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
2002-04-11 17:19:16 +00:00
|
|
|
size = READ_BE_UINT32_UNALIGNED(f->ptr + 4);
|
2002-07-07 20:32:26 +00:00
|
|
|
if ((int32)size <= 0)
|
2001-11-26 19:57:57 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
f->pos += size;
|
|
|
|
f->ptr += size;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
StartScan:
|
2001-11-26 19:57:57 +00:00
|
|
|
if (f->pos >= f->size)
|
|
|
|
return NULL;
|
|
|
|
} while (READ_UINT32_UNALIGNED(f->ptr) != tag);
|
|
|
|
|
|
|
|
return f->ptr;
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
byte *findResourceSmall(uint32 tag, byte *searchin)
|
|
|
|
{
|
|
|
|
uint32 size;
|
|
|
|
static FindResourceState frs;
|
|
|
|
FindResourceState *f = &frs; /* easier to make it thread safe like this */
|
|
|
|
uint16 smallTag;
|
|
|
|
|
|
|
|
smallTag = newTag2Old(tag);
|
|
|
|
|
|
|
|
if (searchin) {
|
|
|
|
f->size = READ_LE_UINT32(searchin);
|
|
|
|
f->pos = 6;
|
|
|
|
f->ptr = searchin + 6;
|
|
|
|
goto StartScan;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
size = READ_LE_UINT32(f->ptr);
|
2002-07-07 20:32:26 +00:00
|
|
|
if ((int32)size <= 0)
|
2002-04-11 17:19:16 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
f->pos += size;
|
|
|
|
f->ptr += size;
|
|
|
|
|
|
|
|
StartScan:
|
|
|
|
if (f->pos >= f->size)
|
|
|
|
return NULL;
|
|
|
|
} while (READ_LE_UINT16(f->ptr + 4) != smallTag);
|
|
|
|
|
|
|
|
return f->ptr;
|
2002-02-12 18:20:37 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
byte *findResource(uint32 tag, byte *searchin, int idx)
|
|
|
|
{
|
|
|
|
uint32 curpos, totalsize, size;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-11-11 16:54:45 +00:00
|
|
|
assert(searchin);
|
|
|
|
|
2001-10-26 17:34:50 +00:00
|
|
|
searchin += 4;
|
|
|
|
totalsize = READ_BE_UINT32_UNALIGNED(searchin);
|
|
|
|
curpos = 8;
|
|
|
|
searchin += 4;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
while (curpos < totalsize) {
|
|
|
|
if (READ_UINT32_UNALIGNED(searchin) == tag && !idx--)
|
2001-10-26 17:34:50 +00:00
|
|
|
return searchin;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
size = READ_BE_UINT32_UNALIGNED(searchin + 4);
|
2002-07-07 20:32:26 +00:00
|
|
|
if ((int32)size <= 0) {
|
2002-04-11 17:19:16 +00:00
|
|
|
error("(%c%c%c%c) Not found in %d... illegal block len %d",
|
2002-07-07 20:32:26 +00:00
|
|
|
tag & 0xFF, (tag >> 8) & 0xFF, (tag >> 16) & 0xFF, (tag >> 24) & 0xFF, 0, size);
|
2001-10-09 14:30:12 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-10-26 17:34:50 +00:00
|
|
|
curpos += size;
|
|
|
|
searchin += size;
|
2002-04-11 17:19:16 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2001-10-26 17:34:50 +00:00
|
|
|
return NULL;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
byte *findResourceSmall(uint32 tag, byte *searchin, int idx)
|
|
|
|
{
|
|
|
|
uint32 curpos, totalsize, size;
|
|
|
|
uint16 smallTag;
|
2002-02-12 21:28:07 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
smallTag = newTag2Old(tag);
|
2002-02-12 21:28:07 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
assert(searchin);
|
2002-02-12 21:28:07 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
totalsize = READ_LE_UINT32(searchin);
|
|
|
|
searchin += 6;
|
|
|
|
curpos = 6;
|
2002-02-12 21:28:07 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
while (curpos < totalsize) {
|
|
|
|
size = READ_LE_UINT32(searchin);
|
2002-02-12 21:28:07 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (READ_LE_UINT16(searchin + 4) == smallTag && !idx--)
|
|
|
|
return searchin;
|
2002-02-12 21:28:07 +00:00
|
|
|
|
2002-07-07 20:32:26 +00:00
|
|
|
if ((int32)size <= 0) {
|
2002-04-11 17:19:16 +00:00
|
|
|
error("(%c%c%c%c) Not found in %d... illegal block len %d",
|
2002-07-07 20:32:26 +00:00
|
|
|
tag & 0xFF, (tag >> 8) & 0xFF, (tag >> 16) & 0xFF, (tag >> 24) & 0xFF, 0, size);
|
2002-04-11 17:19:16 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
curpos += size;
|
|
|
|
searchin += size;
|
|
|
|
}
|
2002-02-12 21:28:07 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
return NULL;
|
2002-02-12 21:28:07 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
void Scumm::lock(int type, int i)
|
|
|
|
{
|
2001-10-09 14:30:12 +00:00
|
|
|
validateResource("Locking", type, i);
|
2001-11-14 20:09:39 +00:00
|
|
|
res.flags[type][i] |= RF_LOCK;
|
2001-11-05 19:21:49 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
// debug(1, "locking %d,%d", type, i);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
void Scumm::unlock(int type, int i)
|
|
|
|
{
|
2001-10-09 14:30:12 +00:00
|
|
|
validateResource("Unlocking", type, i);
|
2001-11-14 20:09:39 +00:00
|
|
|
res.flags[type][i] &= ~RF_LOCK;
|
2001-11-05 19:21:49 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
// debug(1, "unlocking %d,%d", type, i);
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
bool Scumm::isResourceInUse(int type, int i)
|
|
|
|
{
|
2001-11-05 19:21:49 +00:00
|
|
|
validateResource("isResourceInUse", type, i);
|
2002-04-11 17:19:16 +00:00
|
|
|
switch (type) {
|
2001-11-05 19:21:49 +00:00
|
|
|
case rtRoom:
|
|
|
|
return _roomResource == (byte)i;
|
|
|
|
case rtScript:
|
|
|
|
return isScriptInUse(i);
|
|
|
|
case rtCostume:
|
|
|
|
return isCostumeInUse(i);
|
|
|
|
case rtSound:
|
2002-08-14 20:43:56 +00:00
|
|
|
return _sound->isSoundRunning(i) != 0;
|
2001-11-05 19:21:49 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
void Scumm::increaseResourceCounter()
|
|
|
|
{
|
|
|
|
int i, j;
|
2001-11-05 19:21:49 +00:00
|
|
|
byte counter;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = rtFirst; i <= rtLast; i++) {
|
|
|
|
for (j = res.num[i]; --j >= 0;) {
|
2001-11-14 20:09:39 +00:00
|
|
|
counter = res.flags[i][j] & RF_USAGE;
|
|
|
|
if (counter && counter < RF_USAGE_MAX) {
|
2002-04-11 17:19:16 +00:00
|
|
|
setResourceCounter(i, j, counter + 1);
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
void Scumm::expireResources(uint32 size)
|
|
|
|
{
|
|
|
|
int i, j;
|
2001-11-05 19:21:49 +00:00
|
|
|
byte flag;
|
|
|
|
byte best_counter;
|
2002-04-13 04:39:04 +00:00
|
|
|
int best_type, best_res = 0;
|
2001-11-06 21:29:23 +00:00
|
|
|
uint32 oldAllocatedSize;
|
2001-11-05 19:21:49 +00:00
|
|
|
|
2002-07-07 20:32:26 +00:00
|
|
|
// return;
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
if (_expire_counter != 0xFF) {
|
|
|
|
_expire_counter = 0xFF;
|
|
|
|
increaseResourceCounter();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size + _allocatedSize < _maxHeapThreshold)
|
|
|
|
return;
|
|
|
|
|
2001-11-06 21:29:23 +00:00
|
|
|
oldAllocatedSize = _allocatedSize;
|
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
do {
|
|
|
|
best_type = 0;
|
|
|
|
best_counter = 2;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = rtFirst; i <= rtLast; i++)
|
2001-11-05 19:21:49 +00:00
|
|
|
if (res.mode[i]) {
|
2002-04-11 17:19:16 +00:00
|
|
|
for (j = res.num[i]; --j >= 0;) {
|
2001-11-05 19:21:49 +00:00
|
|
|
flag = res.flags[i][j];
|
2002-07-07 20:32:26 +00:00
|
|
|
if (!(flag & 0x80) && flag >= best_counter && res.address[i][j] && !isResourceInUse(i, j)) {
|
2001-11-05 19:21:49 +00:00
|
|
|
best_counter = flag;
|
|
|
|
best_type = i;
|
|
|
|
best_res = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!best_type)
|
|
|
|
break;
|
|
|
|
nukeResource(best_type, best_res);
|
|
|
|
} while (size + _allocatedSize > _minHeapThreshold);
|
2001-11-06 21:29:23 +00:00
|
|
|
|
2001-11-07 18:10:52 +00:00
|
|
|
increaseResourceCounter();
|
|
|
|
|
2002-07-07 20:32:26 +00:00
|
|
|
debug(5, "Expired resources, mem %d -> %d", oldAllocatedSize, _allocatedSize);
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
void Scumm::freeResources()
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
for (i = rtFirst; i <= rtLast; i++) {
|
|
|
|
for (j = res.num[i]; --j >= 0;) {
|
|
|
|
if (isResourceLoaded(i, j))
|
|
|
|
nukeResource(i, j);
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
free(res.address[i]);
|
|
|
|
free(res.flags[i]);
|
|
|
|
free(res.roomno[i]);
|
|
|
|
free(res.roomoffs[i]);
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
void Scumm::loadPtrToResource(int type, int resindex, byte *source)
|
|
|
|
{
|
2002-02-24 17:25:03 +00:00
|
|
|
byte *alloced;
|
2002-04-11 17:19:16 +00:00
|
|
|
int i, len;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
nukeResource(type, resindex);
|
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
len = getStringLen(source);
|
|
|
|
|
2001-11-09 22:45:19 +00:00
|
|
|
if (len <= 0)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
alloced = createResource(type, resindex, len);
|
|
|
|
|
|
|
|
if (!source) {
|
|
|
|
alloced[0] = fetchScriptByte();
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 1; i < len; i++)
|
2001-10-09 14:30:12 +00:00
|
|
|
alloced[i] = *_scriptPointer++;
|
|
|
|
} else {
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < len; i++)
|
2001-10-09 14:30:12 +00:00
|
|
|
alloced[i] = source[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
bool Scumm::isResourceLoaded(int type, int idx)
|
|
|
|
{
|
2002-03-08 08:42:11 +00:00
|
|
|
validateResource("isLoaded", type, idx);
|
|
|
|
return res.address[type][idx] != NULL;
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
void Scumm::resourceStats()
|
|
|
|
{
|
|
|
|
int i, j;
|
2001-11-07 18:10:52 +00:00
|
|
|
uint32 lockedSize = 0, lockedNum = 0;
|
|
|
|
byte flag;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
for (i = rtFirst; i <= rtLast; i++)
|
|
|
|
for (j = res.num[i]; --j >= 0;) {
|
2001-11-07 18:10:52 +00:00
|
|
|
flag = res.flags[i][j];
|
2002-04-11 17:19:16 +00:00
|
|
|
if (flag & 0x80 && res.address[i][j]) {
|
|
|
|
lockedSize += ((MemBlkHeader *)res.address[i][j])->size;
|
2001-11-07 18:10:52 +00:00
|
|
|
lockedNum++;
|
|
|
|
}
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-07-07 20:32:26 +00:00
|
|
|
printf("Total allocated size=%ld, locked=%ld(%ld)\n", _allocatedSize, lockedSize, lockedNum);
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
void Scumm::heapClear(int mode)
|
|
|
|
{
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
void Scumm::unkHeapProc2(int a, int b)
|
|
|
|
{
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
void Scumm::readMAXS()
|
|
|
|
{
|
2002-07-04 15:48:17 +00:00
|
|
|
if (_features & GF_AFTER_V8) {
|
2002-07-07 20:32:26 +00:00
|
|
|
fileSeek(_fileHandle, 50 + 50, SEEK_CUR);
|
|
|
|
_numVariables = fileReadDwordLE(); /* ? 1500 */
|
|
|
|
_numBitVariables = fileReadDwordLE(); /* ? 2048 */
|
|
|
|
fileReadDwordLE(); /* 40 */
|
2002-07-04 15:48:17 +00:00
|
|
|
_numScripts = fileReadDwordLE();
|
|
|
|
_numSounds = fileReadDwordLE();
|
|
|
|
_numCharsets = fileReadDwordLE();
|
|
|
|
_numCostumes = fileReadDwordLE();
|
|
|
|
_numRooms = fileReadDwordLE();
|
|
|
|
_numInventory = fileReadDwordLE();
|
|
|
|
_numGlobalObjects = fileReadDwordLE();
|
|
|
|
_numFlObject = fileReadDwordLE();
|
|
|
|
_numLocalObjects = fileReadDwordLE();
|
|
|
|
_numVerbs = fileReadDwordLE();
|
|
|
|
_numNewNames = fileReadDwordLE();
|
|
|
|
fileReadDwordLE();
|
|
|
|
fileReadDwordLE();
|
|
|
|
_numArray = fileReadDwordLE();
|
|
|
|
|
2002-07-07 20:32:26 +00:00
|
|
|
_objectRoomTable = (byte *)calloc(_numGlobalObjects, 1);
|
2002-07-04 15:48:17 +00:00
|
|
|
_numGlobalScripts = 2000;
|
|
|
|
|
|
|
|
_shadowPaletteSize = NUM_SHADOW_PALETTE * 256;
|
|
|
|
} else if (_features & GF_AFTER_V7) {
|
2002-04-11 17:19:16 +00:00
|
|
|
fileSeek(_fileHandle, 50 + 50, SEEK_CUR);
|
2001-11-26 19:57:57 +00:00
|
|
|
_numVariables = fileReadWordLE();
|
|
|
|
_numBitVariables = fileReadWordLE();
|
|
|
|
fileReadWordLE();
|
|
|
|
_numGlobalObjects = fileReadWordLE();
|
|
|
|
_numLocalObjects = fileReadWordLE();
|
|
|
|
_numNewNames = fileReadWordLE();
|
|
|
|
_numVerbs = fileReadWordLE();
|
|
|
|
_numFlObject = fileReadWordLE();
|
|
|
|
_numInventory = fileReadWordLE();
|
|
|
|
_numArray = fileReadWordLE();
|
|
|
|
_numRooms = fileReadWordLE();
|
|
|
|
_numScripts = fileReadWordLE();
|
|
|
|
_numSounds = fileReadWordLE();
|
|
|
|
_numCharsets = fileReadWordLE();
|
|
|
|
_numCostumes = fileReadWordLE();
|
|
|
|
|
2002-05-01 17:16:47 +00:00
|
|
|
_objectRoomTable = (byte *)calloc(_numGlobalObjects, 1);
|
2001-11-26 19:57:57 +00:00
|
|
|
_numGlobalScripts = 2000;
|
2001-12-27 17:51:58 +00:00
|
|
|
|
|
|
|
_shadowPaletteSize = NUM_SHADOW_PALETTE * 256;
|
2001-11-26 19:57:57 +00:00
|
|
|
} else if (_features & GF_AFTER_V6) {
|
|
|
|
_numVariables = fileReadWordLE();
|
|
|
|
fileReadWordLE();
|
|
|
|
_numBitVariables = fileReadWordLE();
|
|
|
|
_numLocalObjects = fileReadWordLE();
|
|
|
|
_numArray = fileReadWordLE();
|
|
|
|
fileReadWordLE();
|
|
|
|
_numVerbs = fileReadWordLE();
|
|
|
|
_numFlObject = fileReadWordLE();
|
|
|
|
_numInventory = fileReadWordLE();
|
|
|
|
_numRooms = fileReadWordLE();
|
|
|
|
_numScripts = fileReadWordLE();
|
|
|
|
_numSounds = fileReadWordLE();
|
|
|
|
_numCharsets = fileReadWordLE();
|
|
|
|
_numCostumes = fileReadWordLE();
|
|
|
|
_numGlobalObjects = fileReadWordLE();
|
|
|
|
_numNewNames = 50;
|
|
|
|
|
|
|
|
_objectRoomTable = NULL;
|
|
|
|
_numGlobalScripts = 200;
|
2001-12-27 17:51:58 +00:00
|
|
|
|
|
|
|
_shadowPaletteSize = 256;
|
2001-11-26 19:57:57 +00:00
|
|
|
} else {
|
2002-04-11 17:19:16 +00:00
|
|
|
_numVariables = fileReadWordLE(); /* 800 */
|
|
|
|
fileReadWordLE(); /* 16 */
|
|
|
|
_numBitVariables = fileReadWordLE(); /* 2048 */
|
|
|
|
_numLocalObjects = fileReadWordLE(); /* 200 */
|
2001-11-26 19:57:57 +00:00
|
|
|
_numArray = 50;
|
|
|
|
_numVerbs = 100;
|
|
|
|
_numNewNames = 0;
|
|
|
|
_objectRoomTable = NULL;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
fileReadWordLE(); /* 50 */
|
|
|
|
_numCharsets = fileReadWordLE(); /* 9 */
|
|
|
|
fileReadWordLE(); /* 100 */
|
|
|
|
fileReadWordLE(); /* 50 */
|
|
|
|
_numInventory = fileReadWordLE(); /* 80 */
|
2001-11-26 19:57:57 +00:00
|
|
|
_numGlobalScripts = 200;
|
2001-12-27 17:51:58 +00:00
|
|
|
|
|
|
|
_shadowPaletteSize = 256;
|
|
|
|
|
|
|
|
_numFlObject = 50;
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|
2001-10-16 10:01:48 +00:00
|
|
|
|
2001-12-27 17:51:58 +00:00
|
|
|
if (_shadowPaletteSize)
|
2002-05-01 17:16:47 +00:00
|
|
|
_shadowPalette = (byte *)calloc(_shadowPaletteSize, 1);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2001-11-06 21:41:56 +00:00
|
|
|
allocateArrays();
|
2001-10-16 10:01:48 +00:00
|
|
|
_dynamicRoomOffsets = 1;
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
void Scumm::allocateArrays()
|
|
|
|
{
|
2002-03-14 13:57:28 +00:00
|
|
|
// Note: Buffers are now allocated in scummMain to allow for
|
2002-04-11 17:19:16 +00:00
|
|
|
// early GUI init.
|
|
|
|
|
2002-05-01 17:16:47 +00:00
|
|
|
_objectOwnerTable = (byte *)calloc(_numGlobalObjects, 1);
|
|
|
|
_objectStateTable = (byte *)calloc(_numGlobalObjects, 1);
|
|
|
|
_classData = (uint32 *)calloc(_numGlobalObjects, sizeof(uint32));
|
|
|
|
_arrays = (byte *)calloc(_numArray, 1);
|
|
|
|
_newNames = (uint16 *)calloc(_numNewNames, sizeof(uint16));
|
|
|
|
|
|
|
|
_inventory = (uint16 *)calloc(_numInventory, sizeof(uint16));
|
|
|
|
_verbs = (VerbSlot *)calloc(_numVerbs, sizeof(VerbSlot));
|
|
|
|
_objs = (ObjectData *)calloc(_numLocalObjects, sizeof(ObjectData));
|
2002-07-07 20:32:26 +00:00
|
|
|
_vars = (int16 *)calloc(_numVariables, sizeof(int16));
|
2002-05-01 17:16:47 +00:00
|
|
|
_bitVars = (byte *)calloc(_numBitVariables >> 3, 1);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
allocResTypeData(rtCostume,
|
|
|
|
(_features & GF_NEW_COSTUMES) ? MKID('AKOS') :
|
|
|
|
MKID('COST'), _numCostumes, "costume", 1);
|
2001-12-27 17:51:58 +00:00
|
|
|
|
2001-11-26 19:57:57 +00:00
|
|
|
allocResTypeData(rtRoom, MKID('ROOM'), _numRooms, "room", 1);
|
2002-07-04 15:48:17 +00:00
|
|
|
allocResTypeData(rtRoomScripts, MKID('RMSC'), _numRooms, "room script", 1);
|
2001-11-26 19:57:57 +00:00
|
|
|
allocResTypeData(rtSound, MKID('SOUN'), _numSounds, "sound", 1);
|
|
|
|
allocResTypeData(rtScript, MKID('SCRP'), _numScripts, "script", 1);
|
|
|
|
allocResTypeData(rtCharset, MKID('CHAR'), _numCharsets, "charset", 1);
|
2002-04-11 17:19:16 +00:00
|
|
|
allocResTypeData(rtObjectName, MKID('NONE'), _numNewNames, "new name", 0);
|
|
|
|
allocResTypeData(rtInventory, MKID('NONE'), _numInventory, "inventory", 0);
|
|
|
|
allocResTypeData(rtTemp, MKID('NONE'), 10, "temp", 0);
|
|
|
|
allocResTypeData(rtScaleTable, MKID('NONE'), 5, "scale table", 0);
|
|
|
|
allocResTypeData(rtActorName, MKID('NONE'), NUM_ACTORS, "actor name", 0);
|
|
|
|
allocResTypeData(rtVerb, MKID('NONE'), _numVerbs, "verb", 0);
|
|
|
|
allocResTypeData(rtString, MKID('NONE'), _numArray, "array", 0);
|
|
|
|
allocResTypeData(rtFlObject, MKID('NONE'), _numFlObject, "flobject", 0);
|
|
|
|
allocResTypeData(rtMatrix, MKID('NONE'), 10, "boxes", 0);
|
2001-11-06 21:41:56 +00:00
|
|
|
}
|
2002-02-12 18:20:37 +00:00
|
|
|
|
2002-04-21 19:38:00 +00:00
|
|
|
|
2002-04-24 04:26:09 +00:00
|
|
|
|
|
|
|
|
2002-05-14 23:32:34 +00:00
|
|
|
bool Scumm::isGlobInMemory(int type, int idx)
|
2002-04-21 19:38:00 +00:00
|
|
|
{
|
2002-07-07 20:32:26 +00:00
|
|
|
validateResource("isGlobInMemory", type, idx);
|
2002-04-24 04:26:09 +00:00
|
|
|
|
2002-05-14 23:32:34 +00:00
|
|
|
return res.address[type][idx] != NULL;
|
2002-04-21 19:38:00 +00:00
|
|
|
}
|
|
|
|
|
2002-04-24 04:26:09 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
uint16 newTag2Old(uint32 oldTag)
|
|
|
|
{
|
|
|
|
switch (oldTag) {
|
|
|
|
case (MKID('RMHD')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x4448); // HD
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
|
|
|
case (MKID('IM00')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x4D42); // BM
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
|
|
|
case (MKID('EXCD')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x5845); // EX
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
|
|
|
case (MKID('ENCD')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x4E45); // EN
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
|
|
|
case (MKID('SCAL')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x4153); // SA
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
|
|
|
case (MKID('LSCR')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x534C); // LS
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
|
|
|
case (MKID('OBCD')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x434F); // OC
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
|
|
|
case (MKID('OBIM')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x494F); // OI
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
|
|
|
case (MKID('SMAP')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x4D42); // BM
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
|
|
|
case (MKID('CLUT')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x4150); // PA
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
|
|
|
case (MKID('BOXD')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x5842); // BX
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (0);
|
|
|
|
}
|
2002-02-12 18:20:37 +00:00
|
|
|
}
|
2002-04-21 19:38:00 +00:00
|
|
|
|
2002-04-24 04:26:09 +00:00
|
|
|
|
2002-07-07 20:32:26 +00:00
|
|
|
char *Scumm::resTypeFromId(int id)
|
|
|
|
{
|
2002-04-26 14:13:39 +00:00
|
|
|
static char buf[100];
|
|
|
|
|
2002-07-07 20:32:26 +00:00
|
|
|
switch (id) {
|
|
|
|
case rtRoom:
|
|
|
|
sprintf(buf, "Room");
|
|
|
|
break;
|
|
|
|
case rtScript:
|
|
|
|
sprintf(buf, "Script");
|
|
|
|
break;
|
|
|
|
case rtCostume:
|
|
|
|
sprintf(buf, "Costume");
|
|
|
|
break;
|
|
|
|
case rtSound:
|
|
|
|
sprintf(buf, "Sound");
|
|
|
|
break;
|
|
|
|
case rtInventory:
|
|
|
|
sprintf(buf, "Inventory");
|
|
|
|
break;
|
|
|
|
case rtCharset:
|
|
|
|
sprintf(buf, "Charset");
|
|
|
|
break;
|
|
|
|
case rtString:
|
|
|
|
sprintf(buf, "String");
|
|
|
|
break;
|
|
|
|
case rtVerb:
|
|
|
|
sprintf(buf, "Verb");
|
|
|
|
break;
|
|
|
|
case rtActorName:
|
|
|
|
sprintf(buf, "ActorName");
|
|
|
|
break;
|
|
|
|
case rtBuffer:
|
|
|
|
sprintf(buf, "Buffer");
|
|
|
|
break;
|
|
|
|
case rtScaleTable:
|
|
|
|
sprintf(buf, "ScaleTable");
|
|
|
|
break;
|
|
|
|
case rtTemp:
|
|
|
|
sprintf(buf, "Temp");
|
|
|
|
break;
|
|
|
|
case rtFlObject:
|
|
|
|
sprintf(buf, "FlObject");
|
|
|
|
break;
|
|
|
|
case rtMatrix:
|
|
|
|
sprintf(buf, "Matrix");
|
|
|
|
break;
|
|
|
|
case rtBox:
|
|
|
|
sprintf(buf, "Box");
|
|
|
|
break;
|
|
|
|
case rtLast:
|
|
|
|
sprintf(buf, "Last");
|
|
|
|
break;
|
|
|
|
case rtNumTypes:
|
|
|
|
sprintf(buf, "NumTypes");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sprintf(buf, "%d", id);
|
2002-04-26 14:13:39 +00:00
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|