2002-05-22 12:20:36 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2001-10-09 14:30:12 +00:00
|
|
|
* Copyright (C) 2001 Ludvig Strigeus
|
2003-03-06 21:46:56 +00:00
|
|
|
* Copyright (C) 2001-2003 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"
|
2003-04-20 00:56:23 +00:00
|
|
|
#include "bundle.h"
|
2002-11-29 15:13:49 +00:00
|
|
|
#include "verbs.h"
|
2002-08-29 23:45:15 +00:00
|
|
|
#include "scumm/sound.h"
|
2002-12-24 16:10:31 +00:00
|
|
|
#include "common/map.h"
|
|
|
|
#include "common/str.h"
|
2003-01-02 10:36:17 +00:00
|
|
|
#include "gui/message.h"
|
|
|
|
#include "dialogs.h"
|
2002-07-16 21:03:14 +00:00
|
|
|
|
2003-06-25 23:49:54 +00:00
|
|
|
static uint16 newTag2Old(uint32 oldTag);
|
|
|
|
static const char *resTypeFromId(int id);
|
2002-07-16 21:03:14 +00:00
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
/* Open a room */
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::openRoom(int room) {
|
2002-02-24 17:25:03 +00:00
|
|
|
int room_offs, roomlimit;
|
2003-04-29 03:32:08 +00:00
|
|
|
bool result;
|
|
|
|
char buf[128];
|
|
|
|
char buf2[128] = "";
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
debug(9, "openRoom(%d)", room);
|
2002-12-22 21:58:16 +00:00
|
|
|
assert(room >= 0);
|
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();
|
2002-09-10 07:34:27 +00:00
|
|
|
_fileHandle.close();
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Either xxx.lfl or monkey.xxx file name */
|
2002-12-21 12:34:17 +00:00
|
|
|
while (1) {
|
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-12-21 12:34:17 +00:00
|
|
|
if (room_offs == -1)
|
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
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version >= 7) {
|
|
|
|
if (room > 0 && (_version == 8))
|
2003-05-08 15:48:50 +00:00
|
|
|
VAR(VAR_CURRENTDISK) = res.roomno[rtRoom][room];
|
2002-09-15 19:28:34 +00:00
|
|
|
sprintf(buf, "%s.la%d", _exe_name, room == 0 ? 0 : res.roomno[rtRoom][room]);
|
2003-04-29 03:32:08 +00:00
|
|
|
sprintf(buf2, "%s.%.3d", _exe_name, room == 0 ? 0 : res.roomno[rtRoom][room]);
|
2003-05-16 16:09:16 +00:00
|
|
|
} else if (_features & GF_AFTER_HEV7) {
|
|
|
|
sprintf(buf, "%s.he%.1d", _exe_name, room == 0 ? 0 : 1);
|
2003-01-02 10:36:17 +00:00
|
|
|
} else if (_features & GF_HUMONGOUS)
|
2002-09-15 19:28:34 +00:00
|
|
|
sprintf(buf, "%s.he%.1d", _exe_name, room == 0 ? 0 : res.roomno[rtRoom][room]);
|
2003-04-29 03:32:08 +00:00
|
|
|
else {
|
2002-09-15 19:28:34 +00:00
|
|
|
sprintf(buf, "%s.%.3d", _exe_name, room == 0 ? 0 : res.roomno[rtRoom][room]);
|
2003-04-29 03:32:08 +00:00
|
|
|
if (_gameId == GID_SAMNMAX)
|
|
|
|
sprintf(buf2, "%s.sm%.1d", _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) {
|
2002-09-15 19:28:34 +00:00
|
|
|
sprintf(buf, "%.3d.lfl", room);
|
2002-02-12 21:28:07 +00:00
|
|
|
_encbyte = 0;
|
|
|
|
if (openResourceFile(buf)) {
|
|
|
|
return;
|
|
|
|
}
|
2003-01-02 10:36:17 +00:00
|
|
|
askForDisk(buf, room == 0 ? 0 : res.roomno[rtRoom][room]);
|
2002-02-12 21:28:07 +00:00
|
|
|
|
|
|
|
} else {
|
2003-01-02 10:36:17 +00:00
|
|
|
sprintf(buf, "disk%.2d.lec", room == 0 ? 0 : res.roomno[rtRoom][room]);
|
2002-02-12 21:28:07 +00:00
|
|
|
_encbyte = 0x69;
|
|
|
|
}
|
|
|
|
} else {
|
2002-09-15 19:28:34 +00:00
|
|
|
sprintf(buf, "%.2d.lfl", room);
|
2002-12-21 12:34:17 +00:00
|
|
|
_encbyte = (_features & GF_USE_KEY) ? 0xFF : 0;
|
2002-02-12 21:28:07 +00:00
|
|
|
}
|
|
|
|
|
2003-04-29 03:32:08 +00:00
|
|
|
result = openResourceFile(buf);
|
|
|
|
if ((result == false) && (buf2[0]))
|
|
|
|
result = openResourceFile(buf2);
|
|
|
|
|
|
|
|
if (result) {
|
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;
|
|
|
|
}
|
2003-01-02 10:36:17 +00:00
|
|
|
askForDisk(buf, room == 0 ? 0 : res.roomno[rtRoom][room]);
|
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;
|
2003-01-02 10:36:17 +00:00
|
|
|
askForDisk(buf, room == 0 ? 0 : res.roomno[rtRoom][room]);
|
2002-04-11 17:19:16 +00:00
|
|
|
} while (1);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
|
|
|
deleteRoomOffsets();
|
2002-12-22 21:58:16 +00:00
|
|
|
_fileOffset = 0; // start of file
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::closeRoom() {
|
2002-12-22 21:58:16 +00:00
|
|
|
if (_lastLoadedRoom != -1) {
|
|
|
|
_lastLoadedRoom = -1;
|
|
|
|
_encbyte = 0;
|
|
|
|
deleteRoomOffsets();
|
|
|
|
_fileHandle.close();
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-05-30 20:13:29 +00:00
|
|
|
/** Delete the currently loaded room offsets. */
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::deleteRoomOffsets() {
|
2002-04-11 17:19:16 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-30 20:13:29 +00:00
|
|
|
/** Read room offsets */
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::readRoomsOffsets() {
|
2003-05-16 16:09:16 +00:00
|
|
|
int num, room, i;
|
|
|
|
byte *ptr;
|
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;
|
|
|
|
|
2003-05-16 16:09:16 +00:00
|
|
|
if (_features & GF_AFTER_HEV7) {
|
|
|
|
num = READ_LE_UINT16(_HEV7RoomOffsets);
|
|
|
|
ptr = _HEV7RoomOffsets + 2;
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
_roomFileOffsets[i] = READ_LE_UINT32(ptr);
|
|
|
|
ptr += 4;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (!(_features & GF_SMALL_HEADER)) {
|
|
|
|
if (!_dynamicRoomOffsets)
|
|
|
|
return;
|
2002-02-12 21:28:07 +00:00
|
|
|
|
2002-09-10 07:34:27 +00:00
|
|
|
_fileHandle.seek(16, SEEK_SET);
|
2002-04-11 17:19:16 +00:00
|
|
|
} else {
|
2002-10-23 14:02:46 +00:00
|
|
|
_fileHandle.seek(12, SEEK_SET); // Directly searching for the room offset block would be more generic...
|
2002-04-11 17:19:16 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-09-10 07:34:27 +00:00
|
|
|
num = _fileHandle.readByte();
|
2002-12-24 02:18:02 +00:00
|
|
|
while (num--) {
|
2002-09-10 07:34:27 +00:00
|
|
|
room = _fileHandle.readByte();
|
2002-04-11 17:19:16 +00:00
|
|
|
if (_roomFileOffsets[room] != 0xFFFFFFFF) {
|
2002-10-21 13:23:25 +00:00
|
|
|
_roomFileOffsets[room] = _fileHandle.readUint32LE();
|
2001-10-09 14:30:12 +00:00
|
|
|
} else {
|
2002-10-21 13:23:25 +00:00
|
|
|
_fileHandle.readUint32LE();
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
bool Scumm::openResourceFile(const char *filename) {
|
2002-04-11 17:19:16 +00:00
|
|
|
debug(9, "openResourceFile(%s)", filename);
|
2002-07-10 16:38:38 +00:00
|
|
|
|
2002-09-10 07:34:27 +00:00
|
|
|
if (_fileHandle.isOpen() == true) {
|
|
|
|
_fileHandle.close();
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-05-24 22:17:45 +00:00
|
|
|
_fileHandle.open(filename, getGameDataPath(), 1, _encbyte);
|
2002-07-09 14:31:00 +00:00
|
|
|
|
2002-09-10 07:34:27 +00:00
|
|
|
return _fileHandle.isOpen();
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::askForDisk(const char *filename, int disknum) {
|
2003-01-02 10:36:17 +00:00
|
|
|
char buf[128];
|
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8) {
|
2003-01-02 10:36:17 +00:00
|
|
|
char result;
|
|
|
|
|
2003-06-25 23:25:52 +00:00
|
|
|
_sound->_bundle->closeVoiceFile();
|
|
|
|
_sound->_bundle->closeMusicFile();
|
2003-04-20 00:56:23 +00:00
|
|
|
|
2003-05-24 22:17:45 +00:00
|
|
|
#ifdef MACOSX
|
|
|
|
sprintf(buf, "Cannot find file: '%s'\nPlease insert disc %d.\nHit OK to retry, Cancel to exit", filename, disknum);
|
|
|
|
#else
|
|
|
|
sprintf(buf, "Cannot find file: '%s'\nInsert disc %d into drive %s\nHit OK to retry, Cancel to exit", filename, disknum, getGameDataPath());
|
|
|
|
#endif
|
2003-01-02 10:36:17 +00:00
|
|
|
|
|
|
|
result = displayError(true, buf);
|
|
|
|
if (result == 2)
|
|
|
|
error("Cannot find file: '%s'", filename);
|
|
|
|
} else {
|
|
|
|
sprintf(buf, "Cannot find file: '%s'", filename);
|
|
|
|
InfoDialog* dialog = new InfoDialog(_newgui, this, (char*)buf);
|
|
|
|
runDialog (dialog);
|
|
|
|
delete dialog;
|
|
|
|
error("Cannot find file: '%s'", filename);
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::readIndexFile() {
|
2002-04-11 17:19:16 +00:00
|
|
|
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;
|
2003-04-28 05:54:54 +00:00
|
|
|
bool stop = false;
|
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
|
|
|
|
2002-12-22 21:58:16 +00:00
|
|
|
closeRoom();
|
2001-10-09 14:30:12 +00:00
|
|
|
openRoom(0);
|
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version <= 5) {
|
2001-11-26 19:57:57 +00:00
|
|
|
/* Figure out the sizes of various resources */
|
2002-09-10 07:34:27 +00:00
|
|
|
while (!_fileHandle.eof()) {
|
2001-11-26 19:57:57 +00:00
|
|
|
blocktype = fileReadDword();
|
2002-10-21 13:23:25 +00:00
|
|
|
itemsize = _fileHandle.readUint32BE();
|
2002-09-10 07:34:27 +00:00
|
|
|
if (_fileHandle.ioFailed())
|
2001-11-26 19:57:57 +00:00
|
|
|
break;
|
2002-04-11 17:19:16 +00:00
|
|
|
switch (blocktype) {
|
2001-11-26 19:57:57 +00:00
|
|
|
case MKID('DOBJ'):
|
2002-10-21 13:23:25 +00:00
|
|
|
_numGlobalObjects = _fileHandle.readUint16LE();
|
2002-04-11 17:19:16 +00:00
|
|
|
itemsize -= 2;
|
2001-11-26 19:57:57 +00:00
|
|
|
break;
|
|
|
|
case MKID('DROO'):
|
2002-10-21 13:23:25 +00:00
|
|
|
_numRooms = _fileHandle.readUint16LE();
|
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'):
|
2002-10-21 13:23:25 +00:00
|
|
|
_numScripts = _fileHandle.readUint16LE();
|
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'):
|
2002-10-21 13:23:25 +00:00
|
|
|
_numCostumes = _fileHandle.readUint16LE();
|
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'):
|
2002-10-21 13:23:25 +00:00
|
|
|
_numSounds = _fileHandle.readUint16LE();
|
2002-04-11 17:19:16 +00:00
|
|
|
itemsize -= 2;
|
2001-10-09 14:30:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-09-10 07:34:27 +00:00
|
|
|
_fileHandle.seek(itemsize - 8, SEEK_CUR);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2002-09-10 07:34:27 +00:00
|
|
|
_fileHandle.clearIOFailed();
|
|
|
|
_fileHandle.seek(0, SEEK_SET);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-04-28 05:54:54 +00:00
|
|
|
while (!stop) {
|
2001-10-16 10:01:48 +00:00
|
|
|
blocktype = fileReadDword();
|
|
|
|
|
2002-09-10 07:34:27 +00:00
|
|
|
if (_fileHandle.ioFailed())
|
2001-10-16 10:01:48 +00:00
|
|
|
break;
|
2002-10-21 13:23:25 +00:00
|
|
|
itemsize = _fileHandle.readUint32BE();
|
2001-10-16 10:01:48 +00:00
|
|
|
|
|
|
|
numblock++;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
switch (blocktype) {
|
2001-10-16 10:01:48 +00:00
|
|
|
case MKID('DCHR'):
|
2003-04-28 05:54:54 +00:00
|
|
|
case MKID('DIRF'):
|
2003-05-16 16:09:16 +00:00
|
|
|
readResTypeList(rtCharset, MKID('CHAR'), "charset");
|
2003-04-28 05:54:54 +00:00
|
|
|
break;
|
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
case MKID('DOBJ'):
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8)
|
2002-10-21 13:23:25 +00:00
|
|
|
num = _fileHandle.readUint32LE();
|
2002-07-04 15:48:17 +00:00
|
|
|
else
|
2002-10-21 13:23:25 +00:00
|
|
|
num = _fileHandle.readUint16LE();
|
2001-11-26 19:57:57 +00:00
|
|
|
assert(num == _numGlobalObjects);
|
2003-05-16 16:09:16 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8) { /* FIXME: Not sure.. */
|
2002-12-24 16:10:31 +00:00
|
|
|
char buffer[40];
|
2002-07-07 20:32:26 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
2002-12-24 16:10:31 +00:00
|
|
|
_fileHandle.read(buffer, 40);
|
|
|
|
if (buffer[0]) {
|
|
|
|
// Add to object name-to-id map
|
|
|
|
_objectIDMap[buffer] = i;
|
|
|
|
}
|
2002-09-10 07:34:27 +00:00
|
|
|
_objectStateTable[i] = _fileHandle.readByte();
|
|
|
|
_objectRoomTable[i] = _fileHandle.readByte();
|
2002-10-21 13:23:25 +00:00
|
|
|
_classData[i] = _fileHandle.readUint32LE();
|
2002-07-04 15:48:17 +00:00
|
|
|
}
|
|
|
|
memset(_objectOwnerTable, 0xFF, num);
|
2003-06-07 00:13:26 +00:00
|
|
|
} else if (_version == 7) {
|
2002-09-10 07:34:27 +00:00
|
|
|
_fileHandle.read(_objectStateTable, num);
|
|
|
|
_fileHandle.read(_objectRoomTable, num);
|
2001-11-26 19:57:57 +00:00
|
|
|
memset(_objectOwnerTable, 0xFF, num);
|
|
|
|
} else {
|
2002-09-10 07:34:27 +00:00
|
|
|
_fileHandle.read(_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;
|
|
|
|
}
|
2003-05-16 16:09:16 +00:00
|
|
|
if (_features & GF_AFTER_HEV7) {
|
|
|
|
// FIXME nasty nasty hack handle properly...
|
|
|
|
_fileHandle.seek(num * 6000, SEEK_CUR);
|
|
|
|
}
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|
2002-12-24 16:10:31 +00:00
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version != 8) {
|
2002-09-10 07:34:27 +00:00
|
|
|
_fileHandle.read(_classData, num * sizeof(uint32));
|
2002-07-04 15:48:17 +00:00
|
|
|
|
|
|
|
// 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'):
|
2002-09-10 07:34:27 +00:00
|
|
|
_fileHandle.seek(itemsize - 8, SEEK_CUR);
|
2001-10-16 10:01:48 +00:00
|
|
|
break;
|
2003-05-16 16:09:16 +00:00
|
|
|
|
|
|
|
case MKID('DLFL'):
|
|
|
|
_HEV7RoomOffsets = (byte *)calloc(itemsize - 8, 1);
|
|
|
|
_fileHandle.read(_HEV7RoomOffsets, itemsize - 8);
|
|
|
|
break;
|
2001-10-16 10:01:48 +00:00
|
|
|
|
2003-05-16 16:09:16 +00:00
|
|
|
case MKID('DIRI'):
|
|
|
|
num = _fileHandle.readUint16LE();
|
|
|
|
_fileHandle.seek(num + (8 * num), SEEK_CUR);
|
2003-04-28 05:54:54 +00:00
|
|
|
break;
|
|
|
|
|
2002-10-11 08:35:12 +00:00
|
|
|
case MKID('ANAM'):
|
2002-10-21 13:23:25 +00:00
|
|
|
_numAudioNames = _fileHandle.readUint16LE();
|
2002-10-11 08:35:12 +00:00
|
|
|
_audioNames = (char*)malloc(_numAudioNames * 9);
|
|
|
|
_fileHandle.read(_audioNames, _numAudioNames * 9);
|
|
|
|
break;
|
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
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;
|
|
|
|
|
2003-04-28 05:54:54 +00:00
|
|
|
case MKID('DIRR'):
|
2003-05-16 16:09:16 +00:00
|
|
|
readResTypeList(rtRoom, MKID('RMDA'), "room");
|
2003-04-28 05:54:54 +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'):
|
2003-04-28 05:54:54 +00:00
|
|
|
case MKID('DIRS'):
|
2003-05-16 16:09:16 +00:00
|
|
|
readResTypeList(rtScript, MKID('SCRP'), "script");
|
2003-04-28 05:54:54 +00:00
|
|
|
break;
|
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
case MKID('DCOS'):
|
2003-04-28 05:54:54 +00:00
|
|
|
case MKID('DIRC'):
|
2003-05-16 16:09:16 +00:00
|
|
|
readResTypeList(rtCostume, MKID('COST'), "costume");
|
2003-04-28 05:54:54 +00:00
|
|
|
break;
|
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
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;
|
|
|
|
|
2003-04-28 05:54:54 +00:00
|
|
|
case MKID('DIRN'):
|
|
|
|
readResTypeList(rtSound, MKID('DIRN'), "sound");
|
|
|
|
break;
|
|
|
|
|
2001-10-16 10:01:48 +00:00
|
|
|
case MKID('AARY'):
|
2002-12-22 21:58:16 +00:00
|
|
|
debug(3, "Going to call readArrayFromIndexFile (pos = 0x%08x)", _fileHandle.pos());
|
2001-10-16 10:01:48 +00:00
|
|
|
readArrayFromIndexFile();
|
2002-12-22 21:58:16 +00:00
|
|
|
debug(3, "After readArrayFromIndexFile (pos = 0x%08x)", _fileHandle.pos());
|
2001-10-16 10:01:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2002-12-22 21:58:16 +00:00
|
|
|
error("Bad ID %c%c%c%c found in directory!",
|
|
|
|
(byte)blocktype,
|
|
|
|
(byte)(blocktype >> 8),
|
|
|
|
(byte)(blocktype >> 16),
|
|
|
|
(byte)(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
|
|
|
|
2002-12-22 21:58:16 +00:00
|
|
|
closeRoom();
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::readArrayFromIndexFile() {
|
2001-10-16 10:01:48 +00:00
|
|
|
int num;
|
2002-12-23 00:21:49 +00:00
|
|
|
int a, b, c;
|
2002-12-22 21:58:16 +00:00
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8) {
|
2002-12-22 21:58:16 +00:00
|
|
|
while ((num = _fileHandle.readUint32LE()) != 0) {
|
2002-12-23 00:21:49 +00:00
|
|
|
a = _fileHandle.readUint32LE();
|
|
|
|
b = _fileHandle.readUint32LE();
|
2003-01-12 21:13:22 +00:00
|
|
|
|
|
|
|
// FIXME - seems the COMI scripts have a bug related to array 436.
|
|
|
|
// and visible in script 2015, room 20. Basically, the dimensions
|
|
|
|
// are swapped in the definition of the array, but its obvious
|
|
|
|
// that this must be a script bug simply by looking at the defintions
|
|
|
|
// of other arrays and how they are used.
|
|
|
|
// Talk to fingolfin if you have questions about this :-)
|
|
|
|
if (num == 436)
|
|
|
|
defineArray(num, 5, b, a);
|
|
|
|
else
|
|
|
|
defineArray(num, 5, a, b);
|
2002-12-22 21:58:16 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while ((num = _fileHandle.readUint16LE()) != 0) {
|
|
|
|
a = _fileHandle.readUint16LE();
|
|
|
|
b = _fileHandle.readUint16LE();
|
|
|
|
c = _fileHandle.readUint16LE();
|
|
|
|
if (c == 1)
|
|
|
|
defineArray(num, 1, a, b);
|
|
|
|
else
|
|
|
|
defineArray(num, 5, a, b);
|
|
|
|
}
|
2001-10-16 10:01:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +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
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8)
|
2002-10-21 13:23:25 +00:00
|
|
|
num = _fileHandle.readUint32LE();
|
2002-08-29 16:57:43 +00:00
|
|
|
else if (!(_features & GF_OLD_BUNDLE))
|
2002-10-21 13:23:25 +00:00
|
|
|
num = _fileHandle.readUint16LE();
|
2002-08-29 16:57:43 +00:00
|
|
|
else
|
2002-09-10 07:34:27 +00:00
|
|
|
num = _fileHandle.readByte();
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-04-11 11:40:35 +00:00
|
|
|
if (_features & GF_OLD_BUNDLE) {
|
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);
|
2003-04-11 11:40:35 +00:00
|
|
|
} else {
|
|
|
|
if (num != res.num[id]) {
|
|
|
|
error("Invalid number of %ss (%d) in directory", name, num);
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2002-02-12 21:28:07 +00:00
|
|
|
|
2002-08-29 16:57:43 +00:00
|
|
|
if (_features & GF_OLD_BUNDLE) {
|
2002-12-22 21:58:16 +00:00
|
|
|
if (id == rtRoom) {
|
2002-08-29 16:57:43 +00:00
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
res.roomno[id][i] = i;
|
2002-09-10 07:34:27 +00:00
|
|
|
_fileHandle.seek(num, SEEK_CUR);
|
2002-08-29 16:57:43 +00:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < num; i++)
|
2002-09-10 07:34:27 +00:00
|
|
|
res.roomno[id][i] = _fileHandle.readByte();
|
2002-08-29 16:57:43 +00:00
|
|
|
}
|
2003-05-01 22:19:10 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
2002-10-21 13:23:25 +00:00
|
|
|
res.roomoffs[id][i] = _fileHandle.readUint16LE();
|
2003-05-01 22:26:30 +00:00
|
|
|
if (res.roomoffs[id][i] == 0xFFFF)
|
|
|
|
res.roomoffs[id][i] = 0xFFFFFFFF;
|
2003-05-01 22:19:10 +00:00
|
|
|
}
|
|
|
|
|
2002-08-29 16:57:43 +00:00
|
|
|
} else if (_features & GF_SMALL_HEADER) {
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
2002-09-10 07:34:27 +00:00
|
|
|
res.roomno[id][i] = _fileHandle.readByte();
|
2002-11-28 23:47:58 +00:00
|
|
|
res.roomoffs[id][i] = _fileHandle.readUint32LE();
|
2002-04-11 17:19:16 +00:00
|
|
|
}
|
|
|
|
} else {
|
2003-05-01 22:19:10 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
res.roomno[id][i] = _fileHandle.readByte();
|
|
|
|
}
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
res.roomoffs[id][i] = _fileHandle.readUint32LE();
|
|
|
|
}
|
2003-05-16 16:09:16 +00:00
|
|
|
if (_features & GF_AFTER_HEV7) {
|
|
|
|
_fileHandle.seek(4 * num, SEEK_CUR); // FIXME what are these additional offsets
|
|
|
|
}
|
2002-11-28 23:47:58 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::allocResTypeData(int id, uint32 tag, int num, const char *name, int mode) {
|
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);
|
2003-05-18 21:03:57 +00:00
|
|
|
assert(id >= 0 && id < (int)(ARRAYSIZE(res.mode)));
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +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-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");
|
|
|
|
|
2002-08-29 20:01:27 +00:00
|
|
|
// ensureResourceLoaded(rtCharset, no);
|
|
|
|
ptr = getResourceAddress(rtCharset, no);
|
2002-12-04 15:00:35 +00:00
|
|
|
if (_features & GF_SMALL_HEADER)
|
|
|
|
ptr -= 12;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::nukeCharset(int i) {
|
2002-04-11 17:19:16 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::ensureResourceLoaded(int type, int i) {
|
2003-04-30 13:23:31 +00:00
|
|
|
void *addr = NULL;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-26 14:13:39 +00:00
|
|
|
debug(9, "ensureResourceLoaded(%s,%d)", resTypeFromId(type), i);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (type == rtRoom && i > 0x7F && _version < 7) {
|
2002-11-23 13:53:46 +00:00
|
|
|
i = _resourceMapper[i & 0x7F];
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-05-01 11:03:41 +00:00
|
|
|
// FIXME - TODO: This check used to be "i==0". However, that causes
|
|
|
|
// problems when using this function to ensure charset 0 is loaded.
|
2003-05-01 14:35:21 +00:00
|
|
|
// This is done for many games, e.g. Zak256 or Indy3 (EGA and VGA).
|
|
|
|
// For now we restrict the check to anything which is not a charset.
|
2003-05-01 11:40:21 +00:00
|
|
|
// Question: Why was this check like that in the first place?
|
2003-05-01 14:35:21 +00:00
|
|
|
// Answer: costumes with an index of zero in the newer games at least.
|
|
|
|
// TODO: determine why the heck anything would try to load a costume
|
|
|
|
// with id 0. Is that "normal", or is it caused by yet another bug in
|
|
|
|
// our code base? After all we also have to add special cases for many
|
|
|
|
// of our script opcodes that check for the (invalid) actor 0... so
|
|
|
|
// maybe both issues are related...
|
|
|
|
if (type != rtCharset && i == 0)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
|
2003-04-30 13:23:31 +00:00
|
|
|
if (i <= res.num[type])
|
|
|
|
addr = res.address[type][i];
|
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
if (addr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
loadResource(type, i);
|
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version < 7 && !(_features & GF_SMALL_HEADER))
|
2002-04-11 17:19:16 +00:00
|
|
|
if (type == rtRoom && i == _roomResource)
|
2003-05-08 15:48:50 +00:00
|
|
|
VAR(VAR_ROOM_FLAG) = 1;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::loadResource(int type, int idx) {
|
2002-11-28 23:47:58 +00:00
|
|
|
int roomNr;
|
2001-10-09 14:30:12 +00:00
|
|
|
uint32 fileOffs;
|
|
|
|
uint32 size, tag;
|
|
|
|
|
2002-12-28 12:42:55 +00:00
|
|
|
debug(2, "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) {
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8)
|
2002-12-24 02:18:02 +00:00
|
|
|
fileOffs = 8;
|
|
|
|
else
|
|
|
|
fileOffs = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
} 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
|
|
|
|
2002-11-28 23:47:58 +00:00
|
|
|
openRoom(roomNr);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-11-28 23:47:58 +00:00
|
|
|
_fileHandle.seek(fileOffs + _fileOffset, SEEK_SET);
|
2002-08-29 20:01:27 +00:00
|
|
|
|
2002-11-28 23:47:58 +00:00
|
|
|
if (_features & GF_OLD_BUNDLE) {
|
|
|
|
size = _fileHandle.readUint16LE();
|
2003-04-11 22:15:59 +00:00
|
|
|
_fileHandle.seek(-2, SEEK_CUR);
|
2002-11-28 23:47:58 +00:00
|
|
|
} else if (_features & GF_SMALL_HEADER) {
|
|
|
|
if (!(_features & GF_SMALL_NAMES))
|
|
|
|
_fileHandle.seek(8, SEEK_CUR);
|
|
|
|
size = _fileHandle.readUint32LE();
|
|
|
|
tag = _fileHandle.readUint16LE();
|
|
|
|
_fileHandle.seek(-6, SEEK_CUR);
|
|
|
|
/* FIXME */
|
2003-07-06 06:19:52 +00:00
|
|
|
if ((type == rtSound) && !(_features & GF_AMIGA) && (_gameId != GID_ZAK256)) {
|
2002-11-28 23:47:58 +00:00
|
|
|
return readSoundResourceSmallHeader(type, idx);
|
2003-05-03 12:48:18 +00:00
|
|
|
}
|
2002-11-28 23:47:58 +00:00
|
|
|
} else {
|
|
|
|
if (type == rtSound) {
|
|
|
|
_fileHandle.readUint32LE();
|
|
|
|
_fileHandle.readUint32LE();
|
|
|
|
return readSoundResource(type, idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
tag = fileReadDword();
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-11-28 23:47:58 +00:00
|
|
|
if (tag != res.tags[type]) {
|
2002-12-24 02:03:35 +00:00
|
|
|
error("%s %d not in room %d at %d+%d in file %s",
|
|
|
|
res.name[type], idx, roomNr,
|
|
|
|
_fileOffset, fileOffs, _fileHandle.name());
|
2002-08-29 20:01:27 +00:00
|
|
|
}
|
|
|
|
|
2002-11-28 23:47:58 +00:00
|
|
|
size = _fileHandle.readUint32BE();
|
|
|
|
_fileHandle.seek(-8, SEEK_CUR);
|
|
|
|
}
|
|
|
|
_fileHandle.read(createResource(type, idx, size), size);
|
|
|
|
|
2002-12-31 02:09:57 +00:00
|
|
|
// dump the resource if requested
|
|
|
|
if (_dumpScripts && type == rtScript) {
|
2002-11-28 23:47:58 +00:00
|
|
|
dumpResource("script-", idx, getResourceAddress(rtScript, idx));
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-11-28 23:47:58 +00:00
|
|
|
if (!_fileHandle.ioFailed()) {
|
|
|
|
return 1;
|
2002-08-29 20:01:27 +00:00
|
|
|
}
|
|
|
|
|
2002-11-28 23:47:58 +00:00
|
|
|
nukeResource(type, idx);
|
|
|
|
|
2002-08-29 20:01:27 +00:00
|
|
|
error("Cannot read resource");
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::readSoundResource(int type, int idx) {
|
2002-04-11 17:19:16 +00:00
|
|
|
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();
|
2002-10-21 13:23:25 +00:00
|
|
|
total_size = _fileHandle.readUint32BE();
|
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')) {
|
2002-09-10 07:34:27 +00:00
|
|
|
_fileHandle.seek(-8, SEEK_CUR);
|
|
|
|
_fileHandle.read(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();
|
2002-10-21 13:23:25 +00:00
|
|
|
size = _fileHandle.readUint32BE() + 8;
|
2002-03-05 22:23:48 +00:00
|
|
|
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 '):
|
2003-05-16 22:00:33 +00:00
|
|
|
pri = 1;
|
2002-04-13 18:34:11 +00:00
|
|
|
if (_use_adlib)
|
|
|
|
pri = 10;
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
2003-05-28 11:56:50 +00:00
|
|
|
case MKID('AMI '):
|
|
|
|
pri = 3;
|
|
|
|
break;
|
2002-04-11 17:19:16 +00:00
|
|
|
case MKID('ROL '):
|
2003-05-16 22:00:33 +00:00
|
|
|
pri = 3;
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
|
|
|
case MKID('GMD '):
|
2003-05-16 22:00:33 +00:00
|
|
|
pri = 4;
|
2002-04-26 16:52:00 +00:00
|
|
|
break;
|
|
|
|
case MKID('MAC '):
|
2003-05-16 22:00:33 +00:00
|
|
|
pri = 2;
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
2002-05-05 20:01:54 +00:00
|
|
|
case MKID('SPK '):
|
2003-05-07 19:24:14 +00:00
|
|
|
pri = -1;
|
|
|
|
// if (!_use_adlib)
|
|
|
|
// pri = 0;
|
2002-05-05 20:01:54 +00:00
|
|
|
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;
|
2002-09-10 07:34:27 +00:00
|
|
|
best_offs = _fileHandle.pos();
|
2002-03-05 22:23:48 +00:00
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-09-10 07:34:27 +00:00
|
|
|
_fileHandle.seek(size - 8, SEEK_CUR);
|
2001-12-01 17:06:13 +00:00
|
|
|
}
|
|
|
|
|
2002-03-05 22:23:48 +00:00
|
|
|
if (best_pri != -1) {
|
2002-09-10 07:34:27 +00:00
|
|
|
_fileHandle.seek(best_offs - 8, SEEK_SET);
|
|
|
|
_fileHandle.read(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) {
|
2002-09-10 07:34:27 +00:00
|
|
|
_fileHandle.seek(-12, SEEK_CUR);
|
2002-10-21 13:23:25 +00:00
|
|
|
total_size = _fileHandle.readUint32BE();
|
2002-09-10 07:34:27 +00:00
|
|
|
_fileHandle.seek(-8, SEEK_CUR);
|
|
|
|
_fileHandle.read(createResource(type, idx, total_size), total_size);
|
2002-03-16 05:33:25 +00:00
|
|
|
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-09-10 07:34:27 +00:00
|
|
|
debug(1, "It was at position %d", _fileHandle.pos());
|
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-09-10 07:34:27 +00:00
|
|
|
_fileHandle.seek(-12, SEEK_CUR);
|
2002-10-21 13:23:25 +00:00
|
|
|
total_size = _fileHandle.readUint32BE();
|
2002-09-10 07:34:27 +00:00
|
|
|
_fileHandle.read(createResource(type, idx, total_size), total_size - 8);
|
2002-05-17 21:58:59 +00:00
|
|
|
return 1;
|
2002-04-26 16:52:00 +00:00
|
|
|
} else if (basetag == MKID('Mac1')) {
|
2002-09-10 07:34:27 +00:00
|
|
|
_fileHandle.seek(-12, SEEK_CUR);
|
2002-10-21 13:23:25 +00:00
|
|
|
total_size = _fileHandle.readUint32BE();
|
2002-09-10 07:34:27 +00:00
|
|
|
_fileHandle.read(createResource(type, idx, total_size), total_size - 8);
|
2002-07-02 21:28:57 +00:00
|
|
|
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);
|
2002-09-10 07:34:27 +00:00
|
|
|
debug(1, "It was at position %d", _fileHandle.pos());
|
2002-07-02 21:28:57 +00:00
|
|
|
|
2002-09-10 07:34:27 +00:00
|
|
|
_fileHandle.seek(-12, SEEK_CUR);
|
2002-10-21 13:23:25 +00:00
|
|
|
total_size = _fileHandle.readUint32BE();
|
2002-09-10 07:34:27 +00:00
|
|
|
_fileHandle.read(createResource(type, idx, total_size), total_size - 8);
|
2002-08-20 09:58:35 +00:00
|
|
|
return 1;
|
2003-07-06 12:04:37 +00:00
|
|
|
} else if (basetag == MKID('FMUS')) {
|
|
|
|
// Used in 3DO version of puttputt joins the parade and probably others
|
|
|
|
// Specifies a seperate file to be used for music from what I gather.
|
|
|
|
int tmpsize;
|
|
|
|
int i = 0;
|
|
|
|
char buffer[128];
|
|
|
|
debug(1, "Found base tag FMUS in sound %d, size %d", idx, total_size);
|
|
|
|
debug(1, "It was at position %d", _fileHandle.pos());
|
|
|
|
|
|
|
|
_fileHandle.seek(4, SEEK_CUR);
|
|
|
|
// HSHD size
|
|
|
|
tmpsize = _fileHandle.readUint32BE();
|
|
|
|
// skip to size part of the SDAT block
|
|
|
|
_fileHandle.seek(tmpsize - 4, SEEK_CUR);
|
|
|
|
// SDAT size
|
|
|
|
tmpsize = _fileHandle.readUint32BE();
|
|
|
|
|
|
|
|
// SDAT contains name of file we want
|
|
|
|
do {
|
|
|
|
buffer[i] = _fileHandle.readByte();
|
|
|
|
i++;
|
|
|
|
} while (i < tmpsize && i < 128 && buffer[i] != ' ');
|
|
|
|
buffer[i] = '\0';
|
|
|
|
debug(1, "FMUS file %s", buffer);
|
|
|
|
|
|
|
|
res.roomoffs[type][idx] = 0xFFFFFFFF;
|
|
|
|
return 0;
|
2002-08-20 09:58:35 +00:00
|
|
|
} else if (basetag == MKID('Crea')) {
|
2002-09-10 07:34:27 +00:00
|
|
|
_fileHandle.seek(-12, SEEK_CUR);
|
2002-10-21 13:23:25 +00:00
|
|
|
total_size = _fileHandle.readUint32BE();
|
2002-09-10 07:34:27 +00:00
|
|
|
_fileHandle.read(createResource(type, idx, total_size), total_size - 8);
|
2002-05-17 21:58:59 +00:00
|
|
|
return 1;
|
2003-07-06 12:04:37 +00:00
|
|
|
|
2002-03-16 05:33:25 +00:00
|
|
|
} else {
|
2002-10-23 14:02:46 +00:00
|
|
|
fprintf(stderr, "WARNING: Unrecognized base tag 0x%08x 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-09-21 13:48:03 +00:00
|
|
|
// FIXME: some default MIDI instruments for INDY3/MI1
|
|
|
|
static char OLD256_MIDI_HACK[] =
|
2002-10-23 14:02:46 +00:00
|
|
|
// 0
|
|
|
|
"\x00\xf0\x14\x7d\x00" // sysex 00: part on/off
|
|
|
|
"\x00\x00\x03" // part/channel
|
|
|
|
"\x00\x00\x07\x0f\x00\x00\x08\x00\x00\x00\x00\x02\x00\x00\xf7"
|
|
|
|
"\x04\xf0\x41\x7d\x10" // sysex 16: set instrument
|
|
|
|
"\x00" // part/channel
|
|
|
|
"\x01\x06\x02\x0a\x08\x09\x0d\x08\x04\x04"
|
|
|
|
"\x04\x06\x02\x02\x03\x07\x0f\x0d"
|
|
|
|
"\x05\x04\x0c\x00\x03\x01\x01\x00"
|
|
|
|
"\x00\x00\x01\x01\x0e\x00\x02\x02"
|
|
|
|
"\x01\x00\x01\x00\x01\x02\x00\x01"
|
|
|
|
"\x08\x00\x00\x00\x01\x02\x04\x00"
|
|
|
|
"\x06\x02\x00\x00\x04\x00\x03\x02"
|
|
|
|
"\x04\x00\x00\xf7"
|
|
|
|
"\x00\xb0\x07\x64" // Controller 7 = 100
|
|
|
|
// 1
|
|
|
|
"\x00\xf0\x14\x7d\x00" // sysex 00: part on/off
|
|
|
|
"\x01\x00\x03" // part/channel
|
|
|
|
"\x00\x00\x07\x0f\x00\x00\x08\x00\x00\x00\x00\x02\x00\x00\xf7"
|
|
|
|
"\x04\xf0\x41\x7d\x10" // sysex 16: set instrument
|
|
|
|
"\x01" // part/channel
|
|
|
|
"\x01\x06\x02\x0a\x08\x09\x0d\x08\x04\x04"
|
|
|
|
"\x04\x06\x02\x02\x03\x07\x0f\x0d"
|
|
|
|
"\x05\x04\x0c\x00\x03\x01\x01\x00"
|
|
|
|
"\x00\x00\x01\x01\x0e\x00\x02\x02"
|
|
|
|
"\x01\x00\x01\x00\x01\x02\x00\x01"
|
|
|
|
"\x08\x00\x00\x00\x01\x02\x04\x00"
|
|
|
|
"\x06\x02\x00\x00\x04\x00\x03\x02"
|
|
|
|
"\x04\x00\x00\xf7"
|
|
|
|
"\x00\xb1\x07\x64" // Controller 7 = 100
|
|
|
|
// 2
|
|
|
|
"\x00\xf0\x14\x7d\x00" // sysex 00: part on/off
|
|
|
|
"\x02\x00\x03" // part/channel
|
|
|
|
"\x00\x00\x07\x0f\x00\x00\x08\x00\x00\x00\x00\x02\x00\x00\xf7"
|
|
|
|
"\x04\xf0\x41\x7d\x10" // sysex 16: set instrument
|
|
|
|
"\x02" // part/channel
|
|
|
|
"\x01\x06\x02\x0a\x08\x09\x0d\x08\x04\x04"
|
|
|
|
"\x04\x06\x02\x02\x03\x07\x0f\x0d"
|
|
|
|
"\x05\x04\x0c\x00\x03\x01\x01\x00"
|
|
|
|
"\x00\x00\x01\x01\x0e\x00\x02\x02"
|
|
|
|
"\x01\x00\x01\x00\x01\x02\x00\x01"
|
|
|
|
"\x08\x00\x00\x00\x01\x02\x04\x00"
|
|
|
|
"\x06\x02\x00\x00\x04\x00\x03\x02"
|
|
|
|
"\x04\x00\x00\xf7"
|
|
|
|
"\x00\xb2\x07\x64" // Controller 7 = 100
|
|
|
|
// 3
|
|
|
|
"\x00\xf0\x14\x7d\x00" // sysex 00: part on/off
|
|
|
|
"\x03\x00\x03" // part/channel
|
|
|
|
"\x00\x00\x07\x0f\x00\x00\x08\x00\x00\x00\x00\x02\x00\x00\xf7"
|
|
|
|
"\x04\xf0\x41\x7d\x10" // sysex 16: set instrument
|
|
|
|
"\x03" // part/channel
|
|
|
|
"\x01\x06\x02\x0a\x08\x09\x0d\x08\x04\x04"
|
|
|
|
"\x04\x06\x02\x02\x03\x07\x0f\x0d"
|
|
|
|
"\x05\x04\x0c\x00\x03\x01\x01\x00"
|
|
|
|
"\x00\x00\x01\x01\x0e\x00\x02\x02"
|
|
|
|
"\x01\x00\x01\x00\x01\x02\x00\x01"
|
|
|
|
"\x08\x00\x00\x00\x01\x02\x04\x00"
|
|
|
|
"\x06\x02\x00\x00\x04\x00\x03\x02"
|
|
|
|
"\x04\x00\x00\xf7"
|
|
|
|
"\x00\xb3\x07\x64" // Controller 7 = 100
|
|
|
|
// 4
|
|
|
|
"\x00\xf0\x14\x7d\x00" // sysex 00: part on/off
|
|
|
|
"\x04\x00\x03" // part/channel
|
|
|
|
"\x00\x00\x07\x0f\x00\x00\x08\x00\x00\x00\x00\x02\x00\x00\xf7"
|
|
|
|
"\x04\xf0\x41\x7d\x10" // sysex 16: set instrument
|
|
|
|
"\x04" // part/channel
|
|
|
|
"\x01\x06\x02\x0a\x08\x09\x0d\x08\x04\x04"
|
|
|
|
"\x04\x06\x02\x02\x03\x07\x0f\x0d"
|
|
|
|
"\x05\x04\x0c\x00\x03\x01\x01\x00"
|
|
|
|
"\x00\x00\x01\x01\x0e\x00\x02\x02"
|
|
|
|
"\x01\x00\x01\x00\x01\x02\x00\x01"
|
|
|
|
"\x08\x00\x00\x00\x01\x02\x04\x00"
|
|
|
|
"\x06\x02\x00\x00\x04\x00\x03\x02"
|
|
|
|
"\x04\x00\x00\xf7"
|
|
|
|
"\x00\xb4\x07\x64" // Controller 7 = 100
|
|
|
|
// 5
|
|
|
|
"\x00\xf0\x14\x7d\x00" // sysex 00: part on/off
|
|
|
|
"\x05\x00\x03" // part/channel
|
|
|
|
"\x00\x00\x07\x0f\x00\x00\x08\x00\x00\x00\x00\x02\x00\x00\xf7"
|
|
|
|
"\x04\xf0\x41\x7d\x10" // sysex 16: set instrument
|
|
|
|
"\x05" // part/channel
|
|
|
|
"\x01\x06\x02\x0a\x08\x09\x0d\x08\x04\x04"
|
|
|
|
"\x04\x06\x02\x02\x03\x07\x0f\x0d"
|
|
|
|
"\x05\x04\x0c\x00\x03\x01\x01\x00"
|
|
|
|
"\x00\x00\x01\x01\x0e\x00\x02\x02"
|
|
|
|
"\x01\x00\x01\x00\x01\x02\x00\x01"
|
|
|
|
"\x08\x00\x00\x00\x01\x02\x04\x00"
|
|
|
|
"\x06\x02\x00\x00\x04\x00\x03\x02"
|
|
|
|
"\x04\x00\x00\xf7"
|
|
|
|
"\x00\xb5\x07\x64" // Controller 7 = 100
|
|
|
|
// 6
|
|
|
|
"\x00\xf0\x14\x7d\x00" // sysex 00: part on/off
|
|
|
|
"\x06\x00\x03" // part/channel
|
|
|
|
"\x00\x00\x07\x0f\x00\x00\x08\x00\x00\x00\x00\x02\x00\x00\xf7"
|
|
|
|
"\x04\xf0\x41\x7d\x10" // sysex 16: set instrument
|
|
|
|
"\x06" // part/channel
|
|
|
|
"\x01\x06\x02\x0a\x08\x09\x0d\x08\x04\x04"
|
|
|
|
"\x04\x06\x02\x02\x03\x07\x0f\x0d"
|
|
|
|
"\x05\x04\x0c\x00\x03\x01\x01\x00"
|
|
|
|
"\x00\x00\x01\x01\x0e\x00\x02\x02"
|
|
|
|
"\x01\x00\x01\x00\x01\x02\x00\x01"
|
|
|
|
"\x08\x00\x00\x00\x01\x02\x04\x00"
|
|
|
|
"\x06\x02\x00\x00\x04\x00\x03\x02"
|
|
|
|
"\x04\x00\x00\xf7"
|
|
|
|
"\x00\xb6\x07\x64" // Controller 7 = 100
|
|
|
|
// 7
|
|
|
|
"\x00\xf0\x14\x7d\x00" // sysex 00: part on/off
|
|
|
|
"\x07\x00\x03" // part/channel
|
|
|
|
"\x00\x00\x07\x0f\x00\x00\x08\x00\x00\x00\x00\x02\x00\x00\xf7"
|
|
|
|
"\x04\xf0\x41\x7d\x10" // sysex 16: set instrument
|
|
|
|
"\x07" // part/channel
|
|
|
|
"\x01\x06\x02\x0a\x08\x09\x0d\x08\x04\x04"
|
|
|
|
"\x04\x06\x02\x02\x03\x07\x0f\x0d"
|
|
|
|
"\x05\x04\x0c\x00\x03\x01\x01\x00"
|
|
|
|
"\x00\x00\x01\x01\x0e\x00\x02\x02"
|
|
|
|
"\x01\x00\x01\x00\x01\x02\x00\x01"
|
|
|
|
"\x08\x00\x00\x00\x01\x02\x04\x00"
|
|
|
|
"\x06\x02\x00\x00\x04\x00\x03\x02"
|
|
|
|
"\x04\x00\x00\xf7"
|
|
|
|
"\x00\xb7\x07\x64"; // Controller 7 = 100
|
2002-09-21 13:48:03 +00:00
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::readSoundResourceSmallHeader(int type, int idx) {
|
2002-09-21 13:48:03 +00:00
|
|
|
uint32 pos, total_size, size, dw, tag;
|
|
|
|
uint32 best_size = 0, best_offs = 0;
|
|
|
|
|
|
|
|
debug(4, "readSoundResourceSmallHeader(%s,%d)", resTypeFromId(type), idx);
|
|
|
|
|
|
|
|
//if (_rescache->readResource(roomNr, type, idx))
|
|
|
|
// return 1;
|
|
|
|
|
2002-10-21 13:23:25 +00:00
|
|
|
total_size = size = _fileHandle.readUint32LE();
|
|
|
|
tag = _fileHandle.readUint16LE();
|
2002-09-21 13:48:03 +00:00
|
|
|
debug(4, " tag='%c%c', size=%d",
|
|
|
|
(char) (tag & 0xff),
|
|
|
|
(char) ((tag >> 8) & 0xff), size);
|
|
|
|
|
|
|
|
pos = 6;
|
|
|
|
while (pos < total_size) {
|
2002-10-21 13:23:25 +00:00
|
|
|
size = _fileHandle.readUint32LE();
|
|
|
|
tag = _fileHandle.readUint16LE();
|
2003-05-01 21:04:38 +00:00
|
|
|
debug(4, " tag='%c%c', size=%d",
|
2002-09-21 13:48:03 +00:00
|
|
|
(char) (tag & 0xff),
|
|
|
|
(char) ((tag >> 8) & 0xff), size);
|
|
|
|
pos += size;
|
|
|
|
|
|
|
|
// MI1 and Indy3 uses one or more nested SO resources, which contains AD and WA
|
|
|
|
// resources.
|
|
|
|
if ((tag == 0x4441) && !(best_offs)) { // AD
|
|
|
|
best_size = size;
|
|
|
|
best_offs = _fileHandle.pos();
|
|
|
|
} else { // other AD, WA and nested SO resources
|
|
|
|
if (tag == 0x4F53) {
|
|
|
|
pos -= size;
|
|
|
|
size = 6;
|
|
|
|
pos += 6;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_fileHandle.seek(size - 6, SEEK_CUR);
|
|
|
|
}
|
|
|
|
|
|
|
|
// AD resources have a header, instrument definitions and one MIDI track.
|
|
|
|
// We build an 'ADL ' resource from that:
|
|
|
|
// 8 bytes resource header
|
|
|
|
// 16 bytes MDhd header
|
|
|
|
// 14 bytes MThd header
|
|
|
|
// 8 bytes MTrk header
|
2003-05-03 12:48:18 +00:00
|
|
|
// 7 bytes MIDI tempo sysex
|
2002-09-21 13:48:03 +00:00
|
|
|
// + some default instruments
|
|
|
|
// TODO: - make some real MIDI instrument definitions
|
2003-05-03 12:48:18 +00:00
|
|
|
// - proper handling of the short (non-music, SFX) AD resources format
|
2002-09-21 13:48:03 +00:00
|
|
|
// - check the LE/BE handling for platforms other than PC
|
|
|
|
|
|
|
|
if (best_offs != 0) {
|
2003-05-01 21:04:38 +00:00
|
|
|
byte *ptr, *track, *instr;
|
2003-05-03 12:48:18 +00:00
|
|
|
byte ticks, play_once;
|
2003-05-01 21:04:38 +00:00
|
|
|
byte music_type, num_instr;
|
|
|
|
|
2002-09-21 13:48:03 +00:00
|
|
|
_fileHandle.seek(best_offs - 6, SEEK_SET);
|
|
|
|
|
|
|
|
ptr = createResource(type, idx, best_size);
|
|
|
|
_fileHandle.read(ptr, best_size);
|
|
|
|
|
2003-05-01 21:04:38 +00:00
|
|
|
music_type = *(ptr + 8); // 0x80: is music; otherwise not.
|
|
|
|
|
|
|
|
if (music_type != 0x80) {
|
|
|
|
// It's an SFX; we don't know how to handle those yet
|
2003-05-20 15:03:47 +00:00
|
|
|
debug(4, "Sound %d not played, format not yet supported", idx);
|
2003-05-01 21:04:38 +00:00
|
|
|
nukeResource(type, idx);
|
|
|
|
res.roomoffs[type][idx] = 0xFFFFFFFF;
|
|
|
|
return 0;
|
2002-09-21 13:48:03 +00:00
|
|
|
}
|
2003-05-01 21:04:38 +00:00
|
|
|
|
|
|
|
// The "speed" of the song
|
|
|
|
ticks = *(ptr + 9);
|
2003-05-03 12:48:18 +00:00
|
|
|
|
|
|
|
// Flag that tells us whether we should loop the song (0) or play it only once (1)
|
|
|
|
play_once = *(ptr + 10);
|
|
|
|
|
|
|
|
// Number of instruments used
|
2003-05-01 21:04:38 +00:00
|
|
|
num_instr = *(ptr + 16); // Normally 8
|
|
|
|
if (num_instr != 8)
|
|
|
|
warning("Sound %d has %d instruments, expected 8", idx, num_instr);
|
|
|
|
|
|
|
|
// copy the instrument data in another memory area
|
|
|
|
instr = (byte *)calloc(8 * 16, 1);
|
|
|
|
assert(instr);
|
|
|
|
memcpy(instr, ptr + 0x19, 8*16);
|
|
|
|
|
|
|
|
// skip over the rest of the header and copy the MIDI data into a buffer
|
2003-05-03 12:48:18 +00:00
|
|
|
size = best_size;
|
|
|
|
ptr += 0x19 + 8 * 16;
|
|
|
|
size -= 0x19 + 8 * 16;
|
2002-09-25 03:09:00 +00:00
|
|
|
CHECK_HEAP
|
|
|
|
track = (byte *)calloc(size, 1);
|
2002-09-21 13:48:03 +00:00
|
|
|
if (track == NULL) {
|
|
|
|
error("Out of memory while allocating %d", size);
|
|
|
|
}
|
|
|
|
memcpy(track, ptr, size); // saving MIDI track data
|
2002-09-29 15:14:54 +00:00
|
|
|
|
2003-05-01 21:04:38 +00:00
|
|
|
// Now nuke the old resource, and replace it with a new one
|
2002-09-21 13:48:03 +00:00
|
|
|
nukeResource(type, idx);
|
2003-05-03 12:48:18 +00:00
|
|
|
total_size = 8 + 16 + 14 + 8 + 7 + sizeof(OLD256_MIDI_HACK) + size;
|
|
|
|
if (!play_once)
|
2003-05-25 01:42:53 +00:00
|
|
|
total_size += 24; // Up to 24 additional bytes are needed for the jump sysex
|
2003-05-01 21:04:38 +00:00
|
|
|
|
|
|
|
// Write the ADL header (see also above for more information)
|
2002-09-21 13:48:03 +00:00
|
|
|
ptr = createResource(type, idx, total_size);
|
|
|
|
memcpy(ptr, "ADL ", 4); ptr += 4;
|
|
|
|
dw = READ_BE_UINT32(&total_size);
|
|
|
|
memcpy(ptr, &dw, 4); ptr += 4;
|
|
|
|
memcpy(ptr, "MDhd", 4); ptr += 4;
|
|
|
|
ptr[0] = 0; ptr[1] = 0; ptr[2] = 0; ptr[3] = 8;
|
|
|
|
ptr += 4;
|
2003-05-01 21:04:38 +00:00
|
|
|
memset(ptr, 0, 8), ptr += 8;
|
2002-09-21 13:48:03 +00:00
|
|
|
memcpy(ptr, "MThd", 4); ptr += 4;
|
|
|
|
ptr[0] = 0; ptr[1] = 0; ptr[2] = 0; ptr[3] = 6;
|
|
|
|
ptr += 4;
|
|
|
|
ptr[0] = 0; ptr[1] = 0; ptr[2] = 0; ptr[3] = 1; // MIDI format 0 with 1 track
|
|
|
|
ptr += 4;
|
2003-05-01 21:04:38 +00:00
|
|
|
|
2003-05-23 04:47:47 +00:00
|
|
|
// We will ignore the PPQN in the original resource, because
|
|
|
|
// it's invalid anyway. We use a constant PPQN of 480.
|
|
|
|
// memcpy(ptr, &ticks, 2); ptr += 2;
|
|
|
|
*ptr++ = 480 >> 8;
|
|
|
|
*ptr++ = 480 & 0xFF;
|
2003-05-01 21:04:38 +00:00
|
|
|
|
2002-09-21 13:48:03 +00:00
|
|
|
memcpy(ptr, "MTrk", 4); ptr += 4;
|
2003-05-03 12:48:18 +00:00
|
|
|
*ptr++ = ((sizeof(OLD256_MIDI_HACK) + size + 7) >> 24) & 0xFF;
|
|
|
|
*ptr++ = ((sizeof(OLD256_MIDI_HACK) + size + 7) >> 16) & 0xFF;
|
|
|
|
*ptr++ = ((sizeof(OLD256_MIDI_HACK) + size + 7) >> 8) & 0xFF;
|
|
|
|
*ptr++ = ((sizeof(OLD256_MIDI_HACK) + size + 7) ) & 0xFF;
|
2003-05-01 21:04:38 +00:00
|
|
|
|
|
|
|
// Conver the ticks into a MIDI tempo.
|
|
|
|
dw = (500000 * 256) / ticks;
|
2003-06-14 08:57:56 +00:00
|
|
|
debug(4, " ticks = %d, speed = %u", ticks, dw);
|
2003-05-01 21:04:38 +00:00
|
|
|
|
|
|
|
// Write a tempo change SysEx
|
2002-09-21 13:48:03 +00:00
|
|
|
memcpy(ptr, "\x00\xFF\x51\x03", 4); ptr += 4;
|
2002-09-21 Matt Hargett <matt@use.net>
* scumm.dsp, scummvm.dsp, simon.dsp: Turn on warning as errors. Generate
PDBs on all builds.
* gameDetector.cpp, newgui.cpp, widget.cpp, actor.cpp,
dialogs.cpp, resource.cpp, saveload.cpp, scumm_renderer.cpp:
Fix warnings where possible. One pragma added to eliminate
warning of unknown pragmas.
* string.cpp: If unknown escape sequence, print warning.
svn-id: r4998
2002-09-22 03:53:53 +00:00
|
|
|
*ptr++ = (byte)((dw >> 16) & 0xFF);
|
|
|
|
*ptr++ = (byte)((dw >> 8) & 0xFF);
|
|
|
|
*ptr++ = (byte)(dw & 0xFF);
|
2002-09-29 15:14:54 +00:00
|
|
|
|
2003-05-01 21:04:38 +00:00
|
|
|
// Copy our hardcoded instrument table into it
|
|
|
|
// Then, convert the instrument table as given in this song resource
|
|
|
|
// And write it *over* the hardcoded table.
|
2003-05-03 12:48:18 +00:00
|
|
|
// Note: we deliberately.
|
|
|
|
memcpy(ptr, OLD256_MIDI_HACK, sizeof(OLD256_MIDI_HACK));
|
2002-09-29 15:14:54 +00:00
|
|
|
|
2003-05-01 21:04:38 +00:00
|
|
|
|
|
|
|
/* now fill in the instruments */
|
|
|
|
for (int i = 0; i < 8; i++) {
|
2002-09-29 15:14:54 +00:00
|
|
|
|
2003-05-01 21:04:38 +00:00
|
|
|
/* flags_1 */
|
|
|
|
ptr[95 * i + 30 + 0] = (instr[i * 16 + 3] >> 4) & 0xf;
|
|
|
|
ptr[95 * i + 30 + 1] = instr[i * 16 + 3] & 0xf;
|
2002-09-29 15:14:54 +00:00
|
|
|
|
2003-05-01 21:04:38 +00:00
|
|
|
/* oplvl_1 */
|
|
|
|
ptr[95 * i + 30 + 2] = (instr[i * 16 + 4] >> 4) & 0xf;
|
|
|
|
ptr[95 * i + 30 + 3] = instr[i * 16 + 4] & 0xf;
|
2002-09-29 15:14:54 +00:00
|
|
|
|
2003-05-01 21:04:38 +00:00
|
|
|
/* atdec_1 */
|
|
|
|
ptr[95 * i + 30 + 4] = ((~instr[i * 16 + 5]) >> 4) & 0xf;
|
|
|
|
ptr[95 * i + 30 + 5] = (~instr[i * 16 + 5]) & 0xf;
|
2002-09-29 15:14:54 +00:00
|
|
|
|
2003-05-01 21:04:38 +00:00
|
|
|
/* sustrel_1 */
|
|
|
|
ptr[95 * i + 30 + 6] = ((~instr[i * 16 + 6]) >> 4) & 0xf;
|
|
|
|
ptr[95 * i + 30 + 7] = (~instr[i * 16 + 6]) & 0xf;
|
2002-09-29 15:14:54 +00:00
|
|
|
|
2003-05-01 21:04:38 +00:00
|
|
|
/* waveform_1 */
|
|
|
|
ptr[95 * i + 30 + 8] = (instr[i * 16 + 7] >> 4) & 0xf;
|
|
|
|
ptr[95 * i + 30 + 9] = instr[i * 16 + 7] & 0xf;
|
2002-09-29 15:14:54 +00:00
|
|
|
|
2003-05-01 21:04:38 +00:00
|
|
|
/* flags_2 */
|
|
|
|
ptr[95 * i + 30 + 10] = (instr[i * 16 + 8] >> 4) & 0xf;
|
|
|
|
ptr[95 * i + 30 + 11] = instr[i * 16 + 8] & 0xf;
|
2002-09-29 15:14:54 +00:00
|
|
|
|
2003-05-01 21:04:38 +00:00
|
|
|
/* oplvl_2 */
|
|
|
|
ptr[95 * i + 30 + 12] = 3;
|
|
|
|
ptr[95 * i + 30 + 13] = 0xF;
|
2002-09-29 15:14:54 +00:00
|
|
|
|
2003-05-01 21:04:38 +00:00
|
|
|
/* atdec_2 */
|
|
|
|
ptr[95 * i + 30 + 14] = ((~instr[i * 16 + 10]) >> 4) & 0xf;
|
|
|
|
ptr[95 * i + 30 + 15] = (~instr[i * 16 + 10]) & 0xf;
|
2002-09-29 15:14:54 +00:00
|
|
|
|
2003-05-01 21:04:38 +00:00
|
|
|
/* sustrel_2 */
|
|
|
|
ptr[95 * i + 30 + 16] = ((~instr[i * 16 + 11]) >> 4) & 0xf;
|
|
|
|
ptr[95 * i + 30 + 17] = (~instr[i * 16 + 11]) & 0xf;
|
2002-09-29 15:14:54 +00:00
|
|
|
|
2003-05-01 21:04:38 +00:00
|
|
|
/* waveform_2 */
|
|
|
|
ptr[95 * i + 30 + 18] = (instr[i * 16 + 12] >> 4) & 0xf;
|
|
|
|
ptr[95 * i + 30 + 19] = instr[i * 16 + 12] & 0xf;
|
2002-09-29 17:34:00 +00:00
|
|
|
|
2003-05-01 21:04:38 +00:00
|
|
|
/* feedback */
|
|
|
|
ptr[95 * i + 30 + 20] = (instr[i * 16 + 2] >> 4) & 0xf;
|
|
|
|
ptr[95 * i + 30 + 21] = instr[i * 16 + 2] & 0xf;
|
2002-09-29 17:34:00 +00:00
|
|
|
}
|
2002-09-29 15:14:54 +00:00
|
|
|
|
2003-05-01 21:04:38 +00:00
|
|
|
free(instr);
|
2003-05-03 12:48:18 +00:00
|
|
|
ptr += sizeof(OLD256_MIDI_HACK);
|
2003-05-01 21:04:38 +00:00
|
|
|
|
2003-05-03 12:48:18 +00:00
|
|
|
// Now copy the actual music data
|
2002-09-21 13:48:03 +00:00
|
|
|
memcpy(ptr, track, size);
|
|
|
|
free(track);
|
2003-05-03 12:48:18 +00:00
|
|
|
|
|
|
|
if (!play_once) {
|
|
|
|
// The song is meant to be looped. We achieve this by inserting just
|
|
|
|
// before the song end a jump to the song start. More precisely we abuse
|
|
|
|
// a S&M sysex, "maybe_jump" to achieve this effect. We could also
|
|
|
|
// use a set_loop sysex, but it's a bit longer, a little more complicated,
|
2003-05-25 00:04:16 +00:00
|
|
|
// and has no advantage either.
|
2003-05-03 12:48:18 +00:00
|
|
|
|
|
|
|
// First, find the track end
|
|
|
|
byte *end = ptr + size;
|
|
|
|
for (; ptr < end; ptr++) {
|
|
|
|
if (*ptr == 0xff && *(ptr + 1) == 0x2f)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
assert(ptr < end);
|
|
|
|
|
2003-05-25 00:04:16 +00:00
|
|
|
// Now insert the jump. The jump offset is measured in ticks, and
|
2003-05-03 12:48:18 +00:00
|
|
|
// each instrument definition spans 4 ticks... so we jump to tick
|
|
|
|
// 8*4, although jumping to tick 0 would probably work fine, too.
|
|
|
|
// Note: it's possible that some musics don't loop from the start...
|
|
|
|
// in that case we'll have to figure out how the loop range is specified
|
|
|
|
// and then how to handle it appropriately (if it's specified in
|
2003-05-25 00:04:16 +00:00
|
|
|
// ticks, we are fine; but if it's a byte offset, it'll be nasty).
|
|
|
|
const int jump_offset = 8 * 4;
|
2003-05-03 12:48:18 +00:00
|
|
|
memcpy(ptr, "\xf0\x13\x7d\x30\00", 5); ptr += 5; // maybe_jump
|
|
|
|
memcpy(ptr, "\x00\x00", 2); ptr += 2; // cmd -> 0 means always jump
|
|
|
|
memcpy(ptr, "\x00\x00\x00\x00", 4); ptr += 4; // track -> there is only one track, 0
|
2003-05-25 02:02:37 +00:00
|
|
|
memcpy(ptr, "\x00\x00\x00\x01", 4); ptr += 4; // beat -> for now, 1 (first beat)
|
2003-05-03 12:48:18 +00:00
|
|
|
// Ticks
|
|
|
|
*ptr++ = (byte)((jump_offset >> 12) & 0x0F);
|
|
|
|
*ptr++ = (byte)((jump_offset >> 8) & 0x0F);
|
|
|
|
*ptr++ = (byte)((jump_offset >> 4) & 0x0F);
|
|
|
|
*ptr++ = (byte)(jump_offset & 0x0F);
|
|
|
|
memcpy(ptr, "\x00\xf7", 2); ptr += 2; // sysex end marker
|
|
|
|
|
|
|
|
// Finally we reinsert the end of song sysex, just in case
|
2003-05-25 01:48:59 +00:00
|
|
|
memcpy(ptr, "\x00\xff\x2f\x00\x00", 5); ptr += 5;
|
2003-05-03 12:48:18 +00:00
|
|
|
}
|
|
|
|
|
2002-09-21 13:48:03 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
res.roomoffs[type][idx] = 0xFFFFFFFF;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Scumm::getResourceRoomNr(int type, int idx) {
|
2002-04-11 17:19:16 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +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
|
|
|
|
2002-09-25 03:09:00 +00:00
|
|
|
CHECK_HEAP
|
|
|
|
if (!validateResource("getResourceAddress", type, idx))
|
2002-09-25 03:04:28 +00:00
|
|
|
return NULL;
|
|
|
|
|
2002-04-26 14:13:39 +00:00
|
|
|
if (!res.address[type]) {
|
2002-08-30 20:47:48 +00:00
|
|
|
debug(9, "getResourceAddress(%s,%d), res.address[type] == 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-26 14:13:39 +00:00
|
|
|
if (!(ptr = (byte *)res.address[type][idx])) {
|
2002-08-30 20:47:48 +00:00
|
|
|
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
|
|
|
|
2003-06-14 08:57:56 +00:00
|
|
|
debug(9, "getResourceAddress(%s,%d) == %p", 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
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +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)
|
2003-01-26 06:17:25 +00:00
|
|
|
return NULL;
|
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;
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
byte *Scumm::getStringAddressVar(int i) {
|
2002-04-21 19:38:00 +00:00
|
|
|
byte *addr;
|
|
|
|
|
2003-05-08 15:48:50 +00:00
|
|
|
addr = getResourceAddress(rtString, _scummVars[i]);
|
2002-07-07 20:32:26 +00:00
|
|
|
if (addr == NULL)
|
2003-05-19 08:42:10 +00:00
|
|
|
// as this is used for string mapping in the gui
|
|
|
|
// it must be allowed to return NULL
|
|
|
|
// error("NULL string var %d slot %d", i, _scummVars[i]);
|
|
|
|
return NULL;
|
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
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +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
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
byte *Scumm::createResource(int type, int idx, uint32 size) {
|
2001-10-09 14:30:12 +00:00
|
|
|
byte *ptr;
|
|
|
|
|
2002-09-25 03:09:00 +00:00
|
|
|
CHECK_HEAP
|
|
|
|
debug(9, "createResource(%s,%d,%d)", resTypeFromId(type), idx, size);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-09-25 03:04:28 +00:00
|
|
|
if (!validateResource("allocating", type, idx))
|
|
|
|
return NULL;
|
2002-03-08 08:42:11 +00:00
|
|
|
nukeResource(type, idx);
|
2001-10-10 10:02:33 +00:00
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
expireResources(size);
|
|
|
|
|
2002-09-25 03:09:00 +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
|
|
|
}
|
|
|
|
|
2003-06-25 23:49:54 +00:00
|
|
|
bool Scumm::validateResource(const char *str, int type, int idx) const {
|
2002-04-11 17:19:16 +00:00
|
|
|
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);
|
2002-09-25 03:04:28 +00:00
|
|
|
return false;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2002-09-25 03:04:28 +00:00
|
|
|
return true;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::nukeResource(int type, int idx) {
|
2001-11-05 19:21:49 +00:00
|
|
|
byte *ptr;
|
|
|
|
|
2002-09-25 03:09:00 +00:00
|
|
|
CHECK_HEAP
|
|
|
|
if (!res.address[type])
|
2002-08-29 20:01:27 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *Scumm::findResourceData(uint32 tag, const byte *ptr) {
|
2003-04-28 13:16:37 +00:00
|
|
|
if (_features & GF_OLD_BUNDLE)
|
|
|
|
error("findResourceData must not be used in GF_OLD_BUNDLE games");
|
|
|
|
else if (_features & GF_SMALL_HEADER)
|
2003-06-26 00:47:39 +00:00
|
|
|
ptr = findResourceSmall(tag, ptr);
|
2002-08-29 20:01:27 +00:00
|
|
|
else
|
2003-06-26 00:47:39 +00:00
|
|
|
ptr = findResource(tag, ptr);
|
2002-02-12 21:28:07 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (ptr == NULL)
|
2001-11-26 19:57:57 +00:00
|
|
|
return NULL;
|
2002-08-29 20:01:27 +00:00
|
|
|
return ptr + _resourceHeaderSize;
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|
|
|
|
|
2003-05-26 13:14:57 +00:00
|
|
|
int Scumm::getResourceDataSize(const byte *ptr) const {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (ptr == NULL)
|
2001-12-27 17:51:58 +00:00
|
|
|
return 0;
|
2002-02-12 21:28:07 +00:00
|
|
|
|
2003-04-12 20:12:52 +00:00
|
|
|
if (_features & GF_OLD_BUNDLE)
|
|
|
|
return READ_LE_UINT16(ptr) - 4;
|
|
|
|
else if (_features & GF_SMALL_HEADER)
|
2002-04-11 17:19:16 +00:00
|
|
|
return READ_LE_UINT32(ptr) - 6;
|
|
|
|
else
|
2003-06-14 18:52:30 +00:00
|
|
|
return READ_BE_UINT32(ptr - 4) - 8;
|
2001-12-27 17:51:58 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::lock(int type, int i) {
|
2002-09-25 03:04:28 +00:00
|
|
|
if (!validateResource("Locking", type, i))
|
|
|
|
return;
|
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
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::unlock(int type, int i) {
|
2002-09-25 03:04:28 +00:00
|
|
|
if (!validateResource("Unlocking", type, i))
|
|
|
|
return;
|
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
|
|
|
}
|
|
|
|
|
2003-06-25 23:49:54 +00:00
|
|
|
bool Scumm::isResourceInUse(int type, int i) const {
|
2002-09-25 03:04:28 +00:00
|
|
|
if (!validateResource("isResourceInUse", type, i))
|
|
|
|
return false;
|
2002-04-11 17:19:16 +00:00
|
|
|
switch (type) {
|
2001-11-05 19:21:49 +00:00
|
|
|
case rtRoom:
|
|
|
|
return _roomResource == (byte)i;
|
2002-12-27 19:48:30 +00:00
|
|
|
case rtRoomScripts:
|
|
|
|
return _roomResource == (byte)i;
|
2001-11-05 19:21:49 +00:00
|
|
|
case rtScript:
|
|
|
|
return isScriptInUse(i);
|
|
|
|
case rtCostume:
|
|
|
|
return isCostumeInUse(i);
|
|
|
|
case rtSound:
|
2002-12-05 21:45:55 +00:00
|
|
|
return _sound->isSoundActive(i);
|
2001-11-05 19:21:49 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::increaseResourceCounter() {
|
2002-04-11 17:19:16 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::expireResources(uint32 size) {
|
2002-04-11 17:19:16 +00:00
|
|
|
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-11-23 13:53:46 +00:00
|
|
|
if (!(flag & RF_LOCK) && 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
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::freeResources() {
|
2002-04-11 17:19:16 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2003-05-21 18:09:49 +00:00
|
|
|
void Scumm::loadPtrToResource(int type, int resindex, const 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);
|
|
|
|
|
2002-12-28 01:57:19 +00:00
|
|
|
len = resStrLen(source) + 1;
|
2001-10-16 10:01:48 +00:00
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-25 23:49:54 +00:00
|
|
|
bool Scumm::isResourceLoaded(int type, int idx) const {
|
2002-09-25 03:04:28 +00:00
|
|
|
if (!validateResource("isLoaded", type, idx))
|
|
|
|
return false;
|
2002-03-08 08:42:11 +00:00
|
|
|
return res.address[type][idx] != NULL;
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::resourceStats() {
|
2002-04-11 17:19:16 +00:00
|
|
|
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-11-23 13:53:46 +00:00
|
|
|
if (flag & RF_LOCK && res.address[i][j]) {
|
2002-04-11 17:19:16 +00:00
|
|
|
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-11-28 23:49:48 +00:00
|
|
|
debug(1, "Total allocated size=%d, locked=%d(%d)\n", _allocatedSize, lockedSize, lockedNum);
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Scumm::readMAXS() {
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8) { // CMI
|
2003-01-19 04:10:13 +00:00
|
|
|
_fileHandle.seek(50 + 50, SEEK_CUR); // 176 - 8
|
|
|
|
_numVariables = _fileHandle.readUint32LE(); // 1500
|
|
|
|
_numBitVariables = _fileHandle.readUint32LE(); // 2048
|
|
|
|
_fileHandle.readUint32LE(); // 40
|
|
|
|
_numScripts = _fileHandle.readUint32LE(); // 458
|
|
|
|
_numSounds = _fileHandle.readUint32LE(); // 789
|
|
|
|
_numCharsets = _fileHandle.readUint32LE(); // 1
|
|
|
|
_numCostumes = _fileHandle.readUint32LE(); // 446
|
|
|
|
_numRooms = _fileHandle.readUint32LE(); // 95
|
|
|
|
_fileHandle.readUint32LE(); // 80
|
|
|
|
_numGlobalObjects = _fileHandle.readUint32LE(); // 1401
|
|
|
|
_fileHandle.readUint32LE(); // 60
|
|
|
|
_numLocalObjects = _fileHandle.readUint32LE(); // 200
|
|
|
|
_numNewNames = _fileHandle.readUint32LE(); // 100
|
|
|
|
_numFlObject = _fileHandle.readUint32LE(); // 128
|
|
|
|
_numInventory = _fileHandle.readUint32LE(); // 80
|
|
|
|
_numArray = _fileHandle.readUint32LE(); // 200
|
|
|
|
_numVerbs = _fileHandle.readUint32LE(); // 50
|
2002-07-04 15:48:17 +00:00
|
|
|
|
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;
|
2003-06-07 00:13:26 +00:00
|
|
|
} else if (_version == 7) {
|
2002-09-10 07:34:27 +00:00
|
|
|
_fileHandle.seek(50 + 50, SEEK_CUR);
|
2002-10-21 13:23:25 +00:00
|
|
|
_numVariables = _fileHandle.readUint16LE();
|
|
|
|
_numBitVariables = _fileHandle.readUint16LE();
|
2003-01-19 04:10:13 +00:00
|
|
|
_fileHandle.readUint16LE(); // 40 in FT; 16 in Dig
|
2002-10-21 13:23:25 +00:00
|
|
|
_numGlobalObjects = _fileHandle.readUint16LE();
|
|
|
|
_numLocalObjects = _fileHandle.readUint16LE();
|
|
|
|
_numNewNames = _fileHandle.readUint16LE();
|
|
|
|
_numVerbs = _fileHandle.readUint16LE();
|
|
|
|
_numFlObject = _fileHandle.readUint16LE();
|
|
|
|
_numInventory = _fileHandle.readUint16LE();
|
|
|
|
_numArray = _fileHandle.readUint16LE();
|
|
|
|
_numRooms = _fileHandle.readUint16LE();
|
|
|
|
_numScripts = _fileHandle.readUint16LE();
|
|
|
|
_numSounds = _fileHandle.readUint16LE();
|
|
|
|
_numCharsets = _fileHandle.readUint16LE();
|
|
|
|
_numCostumes = _fileHandle.readUint16LE();
|
2001-11-26 19:57:57 +00:00
|
|
|
|
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;
|
2003-06-07 00:13:26 +00:00
|
|
|
} else if (_version == 6) {
|
2002-10-21 13:23:25 +00:00
|
|
|
_numVariables = _fileHandle.readUint16LE();
|
2003-01-19 04:10:13 +00:00
|
|
|
_fileHandle.readUint16LE(); // 16 in Sam/DOTT
|
2002-10-21 13:23:25 +00:00
|
|
|
_numBitVariables = _fileHandle.readUint16LE();
|
|
|
|
_numLocalObjects = _fileHandle.readUint16LE();
|
|
|
|
_numArray = _fileHandle.readUint16LE();
|
2003-01-19 04:10:13 +00:00
|
|
|
_fileHandle.readUint16LE(); // 0 in Sam/DOTT
|
2002-10-21 13:23:25 +00:00
|
|
|
_numVerbs = _fileHandle.readUint16LE();
|
|
|
|
_numFlObject = _fileHandle.readUint16LE();
|
|
|
|
_numInventory = _fileHandle.readUint16LE();
|
|
|
|
_numRooms = _fileHandle.readUint16LE();
|
|
|
|
_numScripts = _fileHandle.readUint16LE();
|
|
|
|
_numSounds = _fileHandle.readUint16LE();
|
|
|
|
_numCharsets = _fileHandle.readUint16LE();
|
|
|
|
_numCostumes = _fileHandle.readUint16LE();
|
|
|
|
_numGlobalObjects = _fileHandle.readUint16LE();
|
2001-11-26 19:57:57 +00:00
|
|
|
_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 {
|
2003-01-19 04:10:13 +00:00
|
|
|
_numVariables = _fileHandle.readUint16LE(); // 800
|
|
|
|
_fileHandle.readUint16LE(); // 16
|
|
|
|
_numBitVariables = _fileHandle.readUint16LE(); // 2048
|
|
|
|
_numLocalObjects = _fileHandle.readUint16LE(); // 200
|
2001-11-26 19:57:57 +00:00
|
|
|
_numArray = 50;
|
|
|
|
_numVerbs = 100;
|
|
|
|
_numNewNames = 0;
|
|
|
|
_objectRoomTable = NULL;
|
|
|
|
|
2003-01-19 04:10:13 +00:00
|
|
|
_fileHandle.readUint16LE(); // 50
|
|
|
|
_numCharsets = _fileHandle.readUint16LE(); // 9
|
|
|
|
_fileHandle.readUint16LE(); // 100
|
|
|
|
_fileHandle.readUint16LE(); // 50
|
|
|
|
_numInventory = _fileHandle.readUint16LE(); // 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;
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +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));
|
|
|
|
_newNames = (uint16 *)calloc(_numNewNames, sizeof(uint16));
|
|
|
|
|
|
|
|
_inventory = (uint16 *)calloc(_numInventory, sizeof(uint16));
|
|
|
|
_verbs = (VerbSlot *)calloc(_numVerbs, sizeof(VerbSlot));
|
|
|
|
_objs = (ObjectData *)calloc(_numLocalObjects, sizeof(ObjectData));
|
2003-03-29 15:56:42 +00:00
|
|
|
debug(2, "Allocated %d space in numObjects\n", _numLocalObjects);
|
2003-05-08 15:48:50 +00:00
|
|
|
_scummVars = (int32 *)calloc(_numVariables, sizeof(int32));
|
2002-05-01 17:16:47 +00:00
|
|
|
_bitVars = (byte *)calloc(_numBitVariables >> 3, 1);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-12-24 02:18:02 +00:00
|
|
|
allocResTypeData(rtCostume, (_features & GF_NEW_COSTUMES) ? MKID('AKOS') : MKID('COST'),
|
|
|
|
_numCostumes, "costume", 1);
|
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);
|
2003-05-13 23:42:41 +00:00
|
|
|
allocResTypeData(rtActorName, MKID('NONE'), _numActors, "actor name", 0);
|
2002-04-11 17:19:16 +00:00
|
|
|
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
|
|
|
|
2003-06-25 23:49:54 +00:00
|
|
|
bool Scumm::isGlobInMemory(int type, int idx) const{
|
2002-09-25 03:04:28 +00:00
|
|
|
if (!validateResource("isGlobInMemory", type, idx))
|
|
|
|
return false;
|
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
|
|
|
}
|
|
|
|
|
2003-06-26 13:54:29 +00:00
|
|
|
ResourceIterator::ResourceIterator(const byte *searchin, bool smallHeader)
|
|
|
|
: _ptr(searchin), _smallHeader(smallHeader) {
|
|
|
|
assert(searchin);
|
|
|
|
if (_smallHeader) {
|
|
|
|
_size = READ_LE_UINT32(searchin);
|
|
|
|
_pos = 6;
|
|
|
|
_ptr = searchin + 6;
|
|
|
|
} else {
|
|
|
|
_size = READ_BE_UINT32(searchin + 4);
|
|
|
|
_pos = 8;
|
|
|
|
_ptr = searchin + 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const byte *ResourceIterator::findNext(uint32 tag) {
|
|
|
|
uint32 size = 0;
|
|
|
|
const byte *result = 0;
|
|
|
|
|
|
|
|
if (_smallHeader) {
|
|
|
|
uint16 smallTag = newTag2Old(tag);
|
|
|
|
do {
|
|
|
|
if (_pos >= _size)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
result = _ptr;
|
|
|
|
size = READ_LE_UINT32(result);
|
|
|
|
if ((int32)size <= 0)
|
|
|
|
return 0; // Avoid endless loop
|
|
|
|
|
|
|
|
_pos += size;
|
|
|
|
_ptr += size;
|
|
|
|
} while (READ_LE_UINT16(result + 4) != smallTag);
|
|
|
|
} else {
|
|
|
|
do {
|
|
|
|
if (_pos >= _size)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
result = _ptr;
|
|
|
|
size = READ_BE_UINT32(result + 4);
|
|
|
|
if ((int32)size <= 0)
|
|
|
|
return 0; // Avoid endless loop
|
|
|
|
|
|
|
|
_pos += size;
|
|
|
|
_ptr += size;
|
|
|
|
} while (READ_UINT32(result) != tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
const byte *findResource(uint32 tag, const byte *searchin) {
|
|
|
|
uint32 curpos, totalsize, size;
|
|
|
|
|
|
|
|
assert(searchin);
|
|
|
|
|
|
|
|
searchin += 4;
|
|
|
|
totalsize = READ_BE_UINT32(searchin);
|
|
|
|
curpos = 8;
|
|
|
|
searchin += 4;
|
|
|
|
|
|
|
|
while (curpos < totalsize) {
|
|
|
|
if (READ_UINT32(searchin) == tag)
|
|
|
|
return searchin;
|
|
|
|
|
|
|
|
size = READ_BE_UINT32(searchin + 4);
|
|
|
|
if ((int32)size <= 0) {
|
|
|
|
error("(%c%c%c%c) Not found in %d... illegal block len %d",
|
|
|
|
tag & 0xFF, (tag >> 8) & 0xFF, (tag >> 16) & 0xFF, (tag >> 24) & 0xFF, 0, size);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
curpos += size;
|
|
|
|
searchin += size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const byte *findResourceSmall(uint32 tag, const byte *searchin) {
|
|
|
|
uint32 curpos, totalsize, size;
|
|
|
|
uint16 smallTag;
|
|
|
|
|
|
|
|
smallTag = newTag2Old(tag);
|
|
|
|
|
|
|
|
assert(searchin);
|
|
|
|
|
|
|
|
totalsize = READ_LE_UINT32(searchin);
|
|
|
|
searchin += 6;
|
|
|
|
curpos = 6;
|
|
|
|
|
|
|
|
while (curpos < totalsize) {
|
|
|
|
size = READ_LE_UINT32(searchin);
|
|
|
|
|
|
|
|
if (READ_LE_UINT16(searchin + 4) == smallTag)
|
|
|
|
return searchin;
|
|
|
|
|
|
|
|
if ((int32)size <= 0) {
|
|
|
|
error("(%c%c%c%c) Not found in %d... illegal block len %d",
|
|
|
|
tag & 0xFF, (tag >> 8) & 0xFF, (tag >> 16) & 0xFF, (tag >> 24) & 0xFF, 0, size);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
curpos += size;
|
|
|
|
searchin += size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
uint16 newTag2Old(uint32 oldTag) {
|
2002-04-11 17:19:16 +00:00
|
|
|
switch (oldTag) {
|
|
|
|
case (MKID('RMHD')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x4448); // HD
|
2002-04-11 17:19:16 +00:00
|
|
|
case (MKID('IM00')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x4D42); // BM
|
2002-04-11 17:19:16 +00:00
|
|
|
case (MKID('EXCD')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x5845); // EX
|
2002-04-11 17:19:16 +00:00
|
|
|
case (MKID('ENCD')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x4E45); // EN
|
2002-04-11 17:19:16 +00:00
|
|
|
case (MKID('SCAL')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x4153); // SA
|
2002-04-11 17:19:16 +00:00
|
|
|
case (MKID('LSCR')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x534C); // LS
|
2002-04-11 17:19:16 +00:00
|
|
|
case (MKID('OBCD')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x434F); // OC
|
2002-04-11 17:19:16 +00:00
|
|
|
case (MKID('OBIM')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x494F); // OI
|
2002-04-11 17:19:16 +00:00
|
|
|
case (MKID('SMAP')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x4D42); // BM
|
2002-04-11 17:19:16 +00:00
|
|
|
case (MKID('CLUT')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x4150); // PA
|
2002-04-11 17:19:16 +00:00
|
|
|
case (MKID('BOXD')):
|
2002-07-28 11:57:33 +00:00
|
|
|
return (0x5842); // BX
|
2002-04-11 17:19:16 +00:00
|
|
|
default:
|
|
|
|
return (0);
|
|
|
|
}
|
2002-02-12 18:20:37 +00:00
|
|
|
}
|
2002-04-21 19:38:00 +00:00
|
|
|
|
2003-06-25 23:49:54 +00:00
|
|
|
const char *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:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "Room";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtScript:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "Script";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtCostume:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "Costume";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtSound:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "Sound";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtInventory:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "Inventory";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtCharset:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "Charset";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtString:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "String";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtVerb:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "Verb";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtActorName:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "ActorName";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtBuffer:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "Buffer";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtScaleTable:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "ScaleTable";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtTemp:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "Temp";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtFlObject:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "FlObject";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtMatrix:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "Matrix";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtBox:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "Box";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtLast:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "Last";
|
2002-07-07 20:32:26 +00:00
|
|
|
case rtNumTypes:
|
2003-06-25 23:49:54 +00:00
|
|
|
return "NumTypes";
|
2002-07-07 20:32:26 +00:00
|
|
|
default:
|
|
|
|
sprintf(buf, "%d", id);
|
2003-06-25 23:49:54 +00:00
|
|
|
return buf;
|
2002-04-26 14:13:39 +00:00
|
|
|
}
|
|
|
|
}
|