scummvm/engines/simon/res.cpp

413 lines
14 KiB
C++
Raw Normal View History

2002-06-29 16:23:33 +00:00
/* ScummVM - Scumm Interpreter
2006-01-18 17:39:49 +00:00
* Copyright (C) 2001-2006 The ScummVM project
2002-06-29 16:23:33 +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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2002-06-29 16:23:33 +00:00
*
* $URL$
* $Id$
2002-06-29 16:23:33 +00:00
*
*/
// Resource file routines for Simon1/Simon2
#include "common/stdafx.h"
#include "common/file.h"
2002-08-21 16:07:07 +00:00
#include "simon/simon.h"
#include "simon/intern.h"
2002-06-29 16:23:33 +00:00
2003-10-03 19:42:27 +00:00
namespace Simon {
// Script opcodes to load into memory
2002-07-07 19:06:48 +00:00
static const char *const opcode_arg_table_simon1win[256] = {
" ", "I ", "I ", "I ", "I ", "I ", "I ", "II ", "II ", "II ", "II ", "B ", "B ", "BN ", "BN ",
2002-07-07 19:08:28 +00:00
"BN ", "BN ", "BB ", "BB ", "BB ", "BB ", "II ", "II ", "N ", "I ", "I ", "I ", "IN ", "IB ",
"II ", "I ", "I ", "II ", "II ", "IBB ", "BIB ", "BB ", "B ", "BI ", "IB ", "B ", "B ", "BN ",
"BN ", "BN ", "BB ", "BB ", "BN ", "BN ", "BB ", "BB ", "BN ", "BB ", "BN ", "B ", "I ", "IB ",
"IB ", "II ", "I ", "I ", "IN ", "B ", "T ", "T ", "NNNNNB ", "BT ", "BTS ", "T ", " ", "B ",
"N ", "IBN ", "I ", "I ", "I ", "NN ", " ", " ", "IT ", "II ", "I ", "B ", " ", "IB ", "IBB ",
"IIB ", "T ", " ", " ", "IB ", "IB ", "IB ", "B ", "BB ", "IBB ", "NB ", "N ", "NBNNN ", "N ",
" ", "BNNNNNN ", "B ", " ", "B ", "B ", "BB ", "NNNNNIN ", "N ", "N ", "N ", "NNN ", "NBNN ",
"IBNN ", "IB ", "IB ", "IB ", "IB ", "N ", "N ", "N ", "BI ", " ", " ", "N ", "I ", "IBB ",
"NN ", "N ", "N ", "Ban ", "BB ", " ", " ", " ", " ", "IB ", "B ", " ", "II ", " ", "BI ", "N ",
"I ", "IB ", "IB ", "IB ", "IB ", "IB ", "IB ", "IB ", "BI ", "BB ", "B ", "B ", "B ", "B ",
"IBB ", "IBN ", "IB ", "B ", "BNBN ", "BBTS ", "N ", " ", "Ian ", "B ", "B ", "B ", "B ", "T ",
"T ", "B ", " ", "I ", " ", " ", "BBI ", "NNBB ", "BBB ", " ", " ", " ", " ", "N ", "N ", " ",
" ",
2002-06-29 16:23:33 +00:00
};
2002-07-07 19:06:48 +00:00
static const char *const opcode_arg_table_simon1dos[256] = {
" ", "I ", "I ", "I ", "I ", "I ", "I ", "II ", "II ", "II ", "II ", "B ", "B ", "BN ", "BN ",
2002-07-07 19:08:28 +00:00
"BN ", "BN ", "BB ", "BB ", "BB ", "BB ", "II ", "II ", "N ", "I ", "I ", "I ", "IN ", "IB ",
"II ", "I ", "I ", "II ", "II ", "IBB ", "BIB ", "BB ", "B ", "BI ", "IB ", "B ", "B ", "BN ",
"BN ", "BN ", "BB ", "BB ", "BN ", "BN ", "BB ", "BB ", "BN ", "BB ", "BN ", "B ", "I ", "IB ",
"IB ", "II ", "I ", "I ", "IN ", "B ", "T ", "T ", "NNNNNB ", "BT ", "BT ", "T ", " ", "B ",
"N ", "IBN ", "I ", "I ", "I ", "NN ", " ", " ", "IT ", "II ", "I ", "B ", " ", "IB ", "IBB ",
"IIB ", "T ", " ", " ", "IB ", "IB ", "IB ", "B ", "BB ", "IBB ", "NB ", "N ", "NBNNN ", "N ",
" ", "BNNNNNN ", "B ", " ", "B ", "B ", "BB ", "NNNNNIN ", "N ", "N ", "N ", "NNN ", "NBNN ",
"IBNN ", "IB ", "IB ", "IB ", "IB ", "N ", "N ", "N ", "BI ", " ", " ", "N ", "I ", "IBB ",
"NN ", "N ", "N ", "Ban ", "BB ", " ", " ", " ", " ", "IB ", "B ", " ", "II ", " ", "BI ", "N ",
"I ", "IB ", "IB ", "IB ", "IB ", "IB ", "IB ", "IB ", "BI ", "BB ", "B ", "B ", "B ", "B ",
"IBB ", "IBN ", "IB ", "B ", "BNBN ", "BBT ", "N ", " ", "Ian ", "B ", "B ", "B ", "B ", "T ",
"T ", "B ", " ", "I ", " ", " ", "BBI ", "NNBB ", "BBB ", " ", " ", " ", " ", "N ", "N ", " ",
" ",
2002-06-29 16:23:33 +00:00
};
2002-07-07 19:06:48 +00:00
static const char *const opcode_arg_table_simon2win[256] = {
" ", "I ", "I ", "I ", "I ", "I ", "I ", "II ", "II ", "II ", "II ", "B ", "B ", "BN ", "BN ",
2002-07-07 19:08:28 +00:00
"BN ", "BN ", "BB ", "BB ", "BB ", "BB ", "II ", "II ", "N ", "I ", "I ", "I ", "IN ", "IB ",
"II ", "I ", "I ", "II ", "II ", "IBB ", "BIB ", "BB ", "B ", "BI ", "IB ", "B ", "B ", "BN ",
"BN ", "BN ", "BB ", "BB ", "BN ", "BN ", "BB ", "BB ", "BN ", "BB ", "BN ", "B ", "I ", "IB ",
"IB ", "II ", "I ", "I ", "IN ", "B ", "T ", "T ", "NNNNNB ", "BT ", "BTS ", "T ", " ", "B ",
"N ", "IBN ", "I ", "I ", "I ", "NN ", " ", " ", "IT ", "II ", "I ", "B ", " ", "IB ", "IBB ",
"IIB ", "T ", " ", " ", "IB ", "IB ", "IB ", "B ", "BB ", "IBB ", "NB ", "N ", "NNBNNN ", "NN ",
" ", "BNNNNNN ", "B ", " ", "B ", "B ", "BB ", "NNNNNIN ", "N ", "N ", "N ", "NNN ", "NBNN ",
"IBNN ", "IB ", "IB ", "IB ", "IB ", "N ", "N ", "N ", "BI ", " ", " ", "N ", "I ", "IBB ",
"NNB ", "N ", "N ", "Ban ", "BB ", " ", " ", " ", " ", "IB ", "B ", " ", "II ", " ", "BI ",
"N ", "I ", "IB ", "IB ", "IB ", "IB ", "IB ", "IB ", "IB ", "BI ", "BB ", "B ", "B ", "B ",
"B ", "IBB ", "IBN ", "IB ", "B ", "BNBN ", "BBTS ", "N ", " ", "Ian ", "B ", "B ", "B ", "B ",
"T ", "T ", "B ", " ", "I ", " ", " ", "BBI ", "NNBB ", "BBB ", " ", " ", " ", " ", "N ", "N ",
" ", " ", "BT ", " ", "B "
2002-07-07 19:06:48 +00:00
};
static const char *const opcode_arg_table_simon2dos[256] = {
" ", "I ", "I ", "I ", "I ", "I ", "I ", "II ", "II ", "II ", "II ", "B ", "B ", "BN ", "BN ",
2002-07-07 19:08:28 +00:00
"BN ", "BN ", "BB ", "BB ", "BB ", "BB ", "II ", "II ", "N ", "I ", "I ", "I ", "IN ", "IB ",
"II ", "I ", "I ", "II ", "II ", "IBB ", "BIB ", "BB ", "B ", "BI ", "IB ", "B ", "B ", "BN ",
"BN ", "BN ", "BB ", "BB ", "BN ", "BN ", "BB ", "BB ", "BN ", "BB ", "BN ", "B ", "I ", "IB ",
"IB ", "II ", "I ", "I ", "IN ", "B ", "T ", "T ", "NNNNNB ", "BT ", "BT ", "T ", " ", "B ",
"N ", "IBN ", "I ", "I ", "I ", "NN ", " ", " ", "IT ", "II ", "I ", "B ", " ", "IB ", "IBB ",
"IIB ", "T ", " ", " ", "IB ", "IB ", "IB ", "B ", "BB ", "IBB ", "NB ", "N ", "NNBNNN ", "NN ",
" ", "BNNNNNN ", "B ", " ", "B ", "B ", "BB ", "NNNNNIN ", "N ", "N ", "N ", "NNN ", "NBNN ",
"IBNN ", "IB ", "IB ", "IB ", "IB ", "N ", "N ", "N ", "BI ", " ", " ", "N ", "I ", "IBB ",
"NNB ", "N ", "N ", "Ban ", "BB ", " ", " ", " ", " ", "IB ", "B ", " ", "II ", " ", "BI ",
"N ", "I ", "IB ", "IB ", "IB ", "IB ", "IB ", "IB ", "IB ", "BI ", "BB ", "B ", "B ", "B ",
"B ", "IBB ", "IBN ", "IB ", "B ", "BNBN ", "BBT ", "N ", " ", "Ian ", "B ", "B ", "B ", "B ",
"T ", "T ", "B ", " ", "I ", " ", " ", "BBI ", "NNBB ", "BBB ", " ", " ", " ", " ", "N ", "N ",
" ", " ", "BT ", " ", "B "
2002-07-07 19:06:48 +00:00
};
2005-10-06 14:34:24 +00:00
static const char *const opcode_arg_table_feeblefiles[256] = {
" ", "I ", "I ", "I ", "I ", "I ", "I ", "II ", "II ", "II ", "II ", "B ", "B ", "BN ", "BN ",
"BN ", "BN ", "BB ", "BB ", "BB ", "BB ", "II ", "II ", "N ", "I ", "I ", "I ", "IN ", "IB ",
"II ", "I ", "I ", "II ", "II ", "IBB ", "BIB ", "BB ", "B ", "BI ", "IB ", "B ", "B ", "BN ",
"BN ", "BN ", "BB ", "BB ", "BN ", "BN ", "BB ", "BB ", "BN ", "BB ", "BN ", "B ", "I ", "IB ",
"IB ", "II ", "I ", "I ", "IN ", "B ", "T ", "T ", "NNNNNB ", "BT ", "BTS ", "T ", " ", "B ",
"N ", "IBN ", "I ", "I ", "I ", "NN ", " ", " ", "IT ", "II ", "I ", "B ", " ", "IB ", "IBB ",
"IIB ", "T ", " ", " ", "IB ", "IB ", "IB ", "B ", "BB ", "IBB ", "NB ", "N ", "NNBNNN ", "NN ",
" ", "BNNNNNN ", "B ", " ", "B ", "B ", "BB ", "NNNNNIN ", "N ", "N ", "N ", "NNN ", "NBNN ",
"IBNN ", "IB ", "IB ", "IB ", "IB ", "N ", "N ", "N ", "BI ", " ", " ", "N ", "I ", "IBB ",
"NNB ", "N ", "N ", "Ban ", " ", " ", " ", " ", " ", "IB ", "B ", " ", "II ", " ", "BI ",
"N ", "I ", "IB ", "IB ", "IB ", "IB ", "IB ", "IB ", "IB ", "BI ", "BB ", "B ", "B ", "B ",
"B ", "IBB ", "IBN ", "IB ", "B ", "BNNN ", "BBTS ", "N ", " ", "Ian ", "B ", "B ", "B ", "B ",
"T ", "N ", " ", " ", "I ", " ", " ", "BBI ", "NNBB ", "BBB ", " ", " ", "T ", " ", "N ", "N ",
" ", " ", "BT ", " ", "B ", " ", "BBBB ", " ", " ", "BBBB ", "B ", "B ", "B ", "B "
};
uint16 SimonEngine::to16Wrapper(uint value) {
if (getGameType() == GType_FF)
return TO_LE_16(value);
else
return TO_BE_16(value);
}
uint16 SimonEngine::readUint16Wrapper(const void *src) {
if (getGameType() == GType_FF)
return READ_LE_UINT16(src);
else
return READ_BE_UINT16(src);
}
uint32 SimonEngine::readUint32Wrapper(const void *src) {
if (getGameType() == GType_FF)
return READ_LE_UINT32(src);
else
return READ_BE_UINT32(src);
}
void SimonEngine::loadOffsets(const char *filename, int number, uint32 &file, uint32 &offset, uint32 &srcSize, uint32 &dstSize) {
Common::File in;
int offsSize = (getPlatform() == Common::kPlatformAmiga) ? 16 : 12;
/* read offsets from index */
in.open(filename);
if (in.isOpen() == false) {
error("Can't open index file '%s'", filename);
}
in.seek(number * offsSize, SEEK_SET);
offset = in.readUint32LE();
dstSize = in.readUint32LE();
srcSize = in.readUint32LE();
file = in.readUint32LE();
in.close();
}
void SimonEngine::loadGamePcFile(const char *filename) {
Common::File in;
2002-06-29 16:23:33 +00:00
int num_inited_objects;
int i, file_size;
/* read main gamepc file */
in.open(filename);
if (in.isOpen() == false) {
char *filename2;
2003-03-25 12:25:06 +00:00
filename2 = (char *)malloc(strlen(filename) + 2);
strcpy(filename2, filename);
strcat(filename2, ".");
in.open(filename2);
free(filename2);
if (in.isOpen() == false)
error("Can't open gamepc file '%s' or '%s.'", gss->gamepc_filename, gss->gamepc_filename);
}
2002-06-29 16:23:33 +00:00
num_inited_objects = allocGamePcVars(&in);
2002-06-29 16:23:33 +00:00
createPlayer();
readGamePcText(&in);
2002-06-29 16:23:33 +00:00
2002-07-07 19:06:48 +00:00
for (i = 2; i < num_inited_objects; i++) {
readItemFromGamePc(&in, _itemArrayPtr[i]);
2002-06-29 16:23:33 +00:00
}
readSubroutineBlock(&in);
2002-06-29 16:23:33 +00:00
in.close();
2002-06-29 16:23:33 +00:00
/* Read list of TABLE resources */
in.open("TBLLIST");
if (in.isOpen() == false) {
in.open("TBLLIST.");
if (in.isOpen() == false)
error("Can't open table resources file 'TBLLIST' or 'TBLLIST.'");
}
2002-06-29 16:23:33 +00:00
file_size = in.size();
2002-06-29 16:23:33 +00:00
_tblList = (byte *)malloc(file_size);
if (_tblList == NULL)
2002-06-29 16:23:33 +00:00
error("Out of memory for strip table list");
in.read(_tblList, file_size);
in.close();
2002-06-29 16:23:33 +00:00
/* Remember the current state */
_subroutineListOrg = _subroutineList;
_tablesHeapPtrOrg = _tablesHeapPtr;
_tablesHeapCurPosOrg = _tablesHeapCurPos;
2002-07-07 19:06:48 +00:00
if (getGameType() == GType_FF)
2005-10-06 14:34:24 +00:00
return;
2002-06-29 16:23:33 +00:00
/* Read list of TEXT resources */
if (getPlatform() == Common::kPlatformAcorn)
in.open("STRIPPED");
else
in.open("STRIPPED.TXT");
if (in.isOpen() == false)
error("Can't open text resources file 'STRIPPED.TXT'");
2002-06-29 16:23:33 +00:00
file_size = in.size();
_strippedTxtMem = (byte *)malloc(file_size);
if (_strippedTxtMem == NULL)
2002-06-29 16:23:33 +00:00
error("Out of memory for strip text list");
in.read(_strippedTxtMem, file_size);
in.close();
2002-06-29 16:23:33 +00:00
}
void SimonEngine::readGamePcText(Common::File *in) {
2002-06-29 16:23:33 +00:00
uint text_size;
byte *text_mem;
_textSize = text_size = in->readUint32BE();
2002-07-07 19:06:48 +00:00
text_mem = (byte *)malloc(text_size);
2002-06-29 16:23:33 +00:00
if (text_mem == NULL)
error("Out of text memory");
in->read(text_mem, text_size);
2002-06-29 16:23:33 +00:00
setupStringTable(text_mem, _stringTabNum);
2002-06-29 16:23:33 +00:00
}
void SimonEngine::readItemFromGamePc(Common::File *in, Item *item) {
2002-06-29 16:23:33 +00:00
uint32 type;
2005-10-03 14:08:07 +00:00
item->adjective = in->readUint16BE();
item->noun = in->readUint16BE();
item->state = in->readUint16BE();
2002-06-29 16:23:33 +00:00
item->sibling = (uint16)fileReadItemID(in);
item->child = (uint16)fileReadItemID(in);
item->parent = (uint16)fileReadItemID(in);
in->readUint16BE();
2005-10-03 14:08:07 +00:00
item->classFlags = in->readUint16BE();
2002-06-29 16:23:33 +00:00
item->children = NULL;
type = in->readUint32BE();
2002-06-29 16:23:33 +00:00
while (type) {
type = in->readUint16BE();
2002-06-29 16:23:33 +00:00
if (type != 0)
readItemChildren(in, item, type);
}
}
void SimonEngine::readItemChildren(Common::File *in, Item *item, uint type) {
2002-06-29 16:23:33 +00:00
if (type == 1) {
uint fr1 = in->readUint16BE();
uint fr2 = in->readUint16BE();
2002-06-29 16:23:33 +00:00
uint i, size;
uint j, k;
SubRoom *subRoom;
2002-06-29 16:23:33 +00:00
size = SubRoom_SIZE;
2002-07-07 19:06:48 +00:00
for (i = 0, j = fr2; i != 6; i++, j >>= 2)
if (j & 3)
size += sizeof(subRoom->roomExit[0]);
2002-06-29 16:23:33 +00:00
subRoom = (SubRoom *)allocateChildBlock(item, 1, size);
subRoom->subroutine_id = fr1;
subRoom->roomExitStates = fr2;
2002-06-29 16:23:33 +00:00
2002-07-07 19:06:48 +00:00
for (i = k = 0, j = fr2; i != 6; i++, j >>= 2)
if (j & 3)
subRoom->roomExit[k++] = (uint16)fileReadItemID(in);
2002-06-29 16:23:33 +00:00
} else if (type == 2) {
uint32 fr = in->readUint32BE();
2002-07-07 19:06:48 +00:00
uint i, k, size;
SubObject *subObject;
2002-06-29 16:23:33 +00:00
size = SubObject_SIZE;
2002-07-07 19:06:48 +00:00
for (i = 0; i != 16; i++)
if (fr & (1 << i))
size += sizeof(subObject->objectFlagValue[0]);
2002-06-29 16:23:33 +00:00
subObject = (SubObject *)allocateChildBlock(item, 2, size);
subObject->objectFlags = fr;
2002-06-29 16:23:33 +00:00
k = 0;
if (fr & 1) {
subObject->objectFlagValue[k++] = (uint16)in->readUint32BE();
2002-06-29 16:23:33 +00:00
}
2002-07-07 19:06:48 +00:00
for (i = 1; i != 16; i++)
if (fr & (1 << i))
subObject->objectFlagValue[k++] = in->readUint16BE();
2002-06-29 16:23:33 +00:00
subObject->objectName = (uint16)in->readUint32BE();
2002-06-29 16:23:33 +00:00
} else {
error("readItemChildren: invalid type %d", type);
2002-06-29 16:23:33 +00:00
}
}
uint fileReadItemID(Common::File *in) {
uint32 val = in->readUint32BE();
2002-07-07 19:06:48 +00:00
if (val == 0xFFFFFFFF)
2002-06-29 16:23:33 +00:00
return 0;
return val + 2;
}
byte *SimonEngine::readSingleOpcode(Common::File *in, byte *ptr) {
2002-07-07 19:06:48 +00:00
int i, l;
2002-06-29 16:23:33 +00:00
const char *string_ptr;
uint val;
2002-07-07 19:06:48 +00:00
const char *const *table;
if (getGameType() == GType_FF) {
2005-10-06 14:34:24 +00:00
table = opcode_arg_table_feeblefiles;
} else if ((getGameType() == GType_SIMON2) && (getFeatures() & GF_TALKIE))
2002-07-07 19:06:48 +00:00
table = opcode_arg_table_simon2win;
else if (getGameType() == GType_SIMON2)
table = opcode_arg_table_simon2dos;
else if (getFeatures() & GF_TALKIE)
table = opcode_arg_table_simon1win;
else
2002-10-24 09:40:20 +00:00
table = opcode_arg_table_simon1dos;
2002-06-29 16:23:33 +00:00
i = 0;
string_ptr = table[*ptr++];
if (!string_ptr)
error("Unable to locate opcode table. Perhaps you are using the wrong game target?");
2002-07-07 19:06:48 +00:00
for (;;) {
2002-06-29 16:23:33 +00:00
if (string_ptr[i] == ' ')
return ptr;
l = string_ptr[i++];
2002-07-07 19:06:48 +00:00
switch (l) {
2002-06-29 16:23:33 +00:00
case 'N':
case 'S':
case 'a':
case 'n':
case 'p':
case 'v':
val = in->readUint16BE();
2002-06-29 16:23:33 +00:00
*ptr++ = val >> 8;
*ptr++ = val & 255;
break;
2002-07-07 19:06:48 +00:00
2002-06-29 16:23:33 +00:00
case 'B':
*ptr++ = in->readByte();
2002-06-29 16:23:33 +00:00
if (ptr[-1] == 0xFF) {
*ptr++ = in->readByte();
2002-06-29 16:23:33 +00:00
}
break;
case 'I':
val = in->readUint16BE();
2002-07-07 19:06:48 +00:00
switch (val) {
case 1:
val = 0xFFFF;
break;
case 3:
val = 0xFFFD;
break;
case 5:
val = 0xFFFB;
break;
case 7:
val = 0xFFF9;
break;
case 9:
val = 0xFFF7;
break;
2002-06-29 16:23:33 +00:00
default:
val = fileReadItemID(in);;
}
*ptr++ = val >> 8;
*ptr++ = val & 255;
break;
case 'T':
val = in->readUint16BE();
2002-07-07 19:06:48 +00:00
switch (val) {
2002-06-29 16:23:33 +00:00
case 0:
val = 0xFFFF;
break;
case 3:
val = 0xFFFD;
break;
default:
val = (uint16)in->readUint32BE();
2002-06-29 16:23:33 +00:00
break;
}
*ptr++ = val >> 8;
*ptr++ = val & 255;
break;
default:
error("Bad cmd table entry %c", l);
}
}
}
2003-10-03 19:42:27 +00:00
} // End of namespace Simon