2002-04-12 21:26:59 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2001/2002 The ScummVM project
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
2002-08-21 16:07:07 +00:00
|
|
|
#include "simon/simon.h"
|
|
|
|
#include "simon/intern.h"
|
|
|
|
#include "common/gameDetector.h"
|
2002-06-29 16:23:33 +00:00
|
|
|
#include <errno.h>
|
2002-08-18 17:48:18 +00:00
|
|
|
#include <time.h>
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-18 22:51:29 +00:00
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
|
|
|
|
extern bool toolbar_drawn;
|
|
|
|
extern bool draw_keyboard;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2002-08-18 16:21:34 +00:00
|
|
|
static const GameSpecificSettings simon1_settings = {
|
|
|
|
1, /* VGA_DELAY_BASE */
|
|
|
|
1576 / 4, /* TABLE_INDEX_BASE */
|
|
|
|
1460 / 4, /* TEXT_INDEX_BASE */
|
|
|
|
1700 / 4, /* NUM_GAME_OFFSETS */
|
|
|
|
64, /* NUM_VIDEO_OP_CODES */
|
|
|
|
1000000, /* VGA_MEM_SIZE */
|
|
|
|
50000, /* TABLES_MEM_SIZE */
|
|
|
|
3624, /* NUM_VOICE_RESOURCES */
|
|
|
|
141, /* NUM_EFFECT_RESOURCES */
|
|
|
|
1316 / 4, /* MUSIC_INDEX_BASE */
|
|
|
|
0, /* SOUND_INDEX_BASE */
|
|
|
|
"SIMON.GME", /* gme_filename */
|
|
|
|
"SIMON.WAV", /* wav_filename */
|
|
|
|
"SIMON.VOC", /* wav_filename2 */
|
|
|
|
"EFFECTS.VOC", /* effects_filename */
|
|
|
|
"GAMEPC", /* gamepc_filename */
|
|
|
|
};
|
|
|
|
|
|
|
|
static const GameSpecificSettings simon2_settings = {
|
|
|
|
5, /* VGA_DELAY_BASE */
|
|
|
|
1580 / 4, /* TABLE_INDEX_BASE */
|
|
|
|
1500 / 4, /* TEXT_INDEX_BASE */
|
|
|
|
2116 / 4, /* NUM_GAME_OFFSETS */
|
|
|
|
75, /* NUM_VIDEO_OP_CODES */
|
|
|
|
2000000, /* VGA_MEM_SIZE */
|
|
|
|
100000, /* TABLES_MEM_SIZE */
|
|
|
|
12256, /* NUM_VOICE_RESOURCES */
|
|
|
|
0,
|
|
|
|
1128 / 4, /* MUSIC_INDEX_BASE */
|
|
|
|
1660 / 4, /* SOUND_INDEX_BASE */
|
|
|
|
"SIMON2.GME", /* gme_filename */
|
|
|
|
"SIMON2.WAV", /* wav_filename */
|
|
|
|
NULL,
|
|
|
|
"",
|
|
|
|
"GSPTR30", /* gamepc_filename */
|
|
|
|
};
|
|
|
|
|
|
|
|
static const GameSpecificSettings simon2win_settings = {
|
|
|
|
5, /* VGA_DELAY_BASE */
|
|
|
|
1580 / 4, /* TABLE_INDEX_BASE */
|
|
|
|
1500 / 4, /* TEXT_INDEX_BASE */
|
|
|
|
2116 / 4, /* NUM_GAME_OFFSETS */
|
|
|
|
75, /* NUM_VIDEO_OP_CODES */
|
|
|
|
2000000, /* VGA_MEM_SIZE */
|
|
|
|
100000, /* TABLES_MEM_SIZE */
|
|
|
|
12256, /* NUM_VOICE_RESOURCES */
|
|
|
|
0,
|
|
|
|
1128 / 4, /* MUSIC_INDEX_BASE */
|
|
|
|
1660 / 4, /* SOUND_INDEX_BASE */
|
|
|
|
"SIMON2.GME", /* gme_filename */
|
|
|
|
"SIMON2.WAV", /* wav_filename */
|
|
|
|
NULL,
|
|
|
|
"",
|
|
|
|
"GSPTR30", /* gamepc_filename */
|
|
|
|
};
|
|
|
|
|
|
|
|
static const GameSpecificSettings simon2dos_settings = {
|
|
|
|
5, /* VGA_DELAY_BASE */
|
|
|
|
1580 / 4, /* TABLE_INDEX_BASE */
|
|
|
|
1500 / 4, /* TEXT_INDEX_BASE */
|
|
|
|
2116 / 4, /* NUM_GAME_OFFSETS */
|
|
|
|
75, /* NUM_VIDEO_OP_CODES */
|
|
|
|
2000000, /* VGA_MEM_SIZE */
|
|
|
|
100000, /* TABLES_MEM_SIZE */
|
|
|
|
12256, /* NUM_VOICE_RESOURCES */
|
|
|
|
0,
|
|
|
|
1128 / 4, /* MUSIC_INDEX_BASE */
|
|
|
|
1660 / 4, /* SOUND_INDEX_BASE */
|
|
|
|
"SIMON2.GME", /* gme_filename */
|
|
|
|
"SIMON2.WAV", /* wav_filename */
|
|
|
|
NULL,
|
|
|
|
"",
|
|
|
|
"GAME32", /* gamepc_filename */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-08-18 17:48:18 +00:00
|
|
|
SimonState::SimonState(GameDetector *detector, OSystem *syst)
|
|
|
|
: Engine(detector, syst)
|
2002-08-18 16:21:34 +00:00
|
|
|
{
|
2002-08-18 17:48:18 +00:00
|
|
|
MidiDriver *driver = detector->createMidi();
|
|
|
|
|
2002-08-18 16:21:34 +00:00
|
|
|
_dummy_item_1 = new Item();
|
|
|
|
_dummy_item_2 = new Item();
|
|
|
|
_dummy_item_3 = new Item();
|
|
|
|
|
|
|
|
_fcs_list = new FillOrCopyStruct[16];
|
2002-08-18 17:48:18 +00:00
|
|
|
|
|
|
|
/* Setup midi driver */
|
|
|
|
midi.set_driver(driver);
|
|
|
|
|
|
|
|
_game = detector->_gameId;
|
2002-08-18 18:15:15 +00:00
|
|
|
|
|
|
|
/* Setup mixer */
|
2002-08-24 15:31:37 +00:00
|
|
|
if (!_mixer->bindToSystem(syst))
|
2002-08-18 18:15:15 +00:00
|
|
|
warning("Sound initialization failed. "
|
|
|
|
"Features of the game that depend on sound synchronization will most likely break");
|
|
|
|
set_volume(detector->_sfx_volume);
|
2002-08-18 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SimonState::~SimonState()
|
|
|
|
{
|
|
|
|
delete _dummy_item_1;
|
|
|
|
delete _dummy_item_2;
|
|
|
|
delete _dummy_item_3;
|
|
|
|
|
|
|
|
delete [] _fcs_list;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void palette_fadeout(uint32 *pal_values, uint num)
|
|
|
|
{
|
|
|
|
byte *p = (byte *)pal_values;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
do {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (p[0] >= 8)
|
|
|
|
p[0] -= 8;
|
|
|
|
else
|
|
|
|
p[0] = 0;
|
|
|
|
if (p[1] >= 8)
|
|
|
|
p[1] -= 8;
|
|
|
|
else
|
|
|
|
p[1] = 0;
|
|
|
|
if (p[2] >= 8)
|
|
|
|
p[2] -= 8;
|
|
|
|
else
|
|
|
|
p[2] = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
p += sizeof(uint32);
|
|
|
|
} while (--num);
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
byte *SimonState::allocateItem(uint size)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
byte *org = _itemheap_ptr;
|
2002-04-13 21:06:48 +00:00
|
|
|
size = (size + 3) & ~3;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
_itemheap_ptr += size;
|
|
|
|
_itemheap_curpos += size;
|
|
|
|
|
|
|
|
if (_itemheap_curpos > _itemheap_size)
|
|
|
|
error("Itemheap overflow");
|
|
|
|
|
|
|
|
return org;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::alignTableMem()
|
|
|
|
{
|
2002-04-13 21:06:48 +00:00
|
|
|
if ((uint32)_tablesheap_ptr & 3) {
|
|
|
|
_tablesheap_ptr += 2;
|
|
|
|
_tablesheap_curpos += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
byte *SimonState::allocateTable(uint size)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
byte *org = _tablesheap_ptr;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
size = (size + 1) & ~1;
|
|
|
|
|
|
|
|
_tablesheap_ptr += size;
|
|
|
|
_tablesheap_curpos += size;
|
|
|
|
|
|
|
|
if (_tablesheap_curpos > _tablesheap_size)
|
|
|
|
error("Tablesheap overflow");
|
|
|
|
|
|
|
|
return org;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
int SimonState::allocGamePcVars(FILE *in)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
uint item_array_size, item_array_inited, stringtable_num;
|
|
|
|
uint32 version;
|
|
|
|
uint i;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
item_array_size = fileReadBE32(in);
|
|
|
|
version = fileReadBE32(in);
|
|
|
|
item_array_inited = fileReadBE32(in);
|
|
|
|
stringtable_num = fileReadBE32(in);
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
item_array_inited += 2; /* first two items are predefined */
|
2002-04-12 21:26:59 +00:00
|
|
|
item_array_size += 2;
|
|
|
|
|
|
|
|
if (version != 0x80)
|
|
|
|
error("Not a runtime database");
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
_itemarray_ptr = (Item **)calloc(item_array_size, sizeof(Item *));
|
2002-04-12 21:26:59 +00:00
|
|
|
if (_itemarray_ptr == NULL)
|
|
|
|
error("Out of memory for Item array");
|
|
|
|
|
|
|
|
_itemarray_size = item_array_size;
|
|
|
|
_itemarray_inited = item_array_inited;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
for (i = 2; i != item_array_inited; i++) {
|
|
|
|
_itemarray_ptr[i] = (Item *)allocateItem(sizeof(Item));
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The rest is cleared automatically by calloc */
|
|
|
|
allocateStringTable(stringtable_num + 10);
|
|
|
|
_stringtab_num = stringtable_num;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
return item_array_inited;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
Item *SimonState::allocItem1()
|
|
|
|
{
|
|
|
|
Item *item = (Item *)allocateItem(sizeof(Item));
|
2002-04-12 21:26:59 +00:00
|
|
|
_itemarray_ptr[1] = item;
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::loginPlayerHelper(Item *item, int a, int b)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
Child9 *child;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
child = (Child9 *) findChildOfType(item, 9);
|
2002-04-12 21:26:59 +00:00
|
|
|
if (child == NULL) {
|
2002-07-07 19:06:48 +00:00
|
|
|
child = (Child9 *) allocateChildBlock(item, 9, sizeof(Child9));
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (a >= 0 && a <= 3)
|
2002-04-12 21:26:59 +00:00
|
|
|
child->array[a] = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::loginPlayer()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
Item *item;
|
|
|
|
Child *child;
|
|
|
|
|
|
|
|
item = _itemarray_ptr[1];
|
|
|
|
item->unk2 = -1;
|
|
|
|
item->unk1 = 10000;
|
|
|
|
_item_1 = item;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
child = (Child *)allocateChildBlock(item, 3, sizeof(Child));
|
2002-04-12 21:26:59 +00:00
|
|
|
if (child == NULL)
|
|
|
|
error("player create failure");
|
|
|
|
|
|
|
|
loginPlayerHelper(item, 0, 0);
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::allocateStringTable(int num)
|
|
|
|
{
|
|
|
|
_stringtab_ptr = (byte **)calloc(num, sizeof(byte *));
|
2002-04-12 21:26:59 +00:00
|
|
|
_stringtab_pos = 0;
|
|
|
|
_stringtab_numalloc = num;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::setupStringTable(byte *mem, int num)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
int i = 0;
|
2002-07-07 19:06:48 +00:00
|
|
|
for (;;) {
|
2002-04-12 21:26:59 +00:00
|
|
|
_stringtab_ptr[i++] = mem;
|
|
|
|
if (--num == 0)
|
|
|
|
break;
|
2002-07-07 19:06:48 +00:00
|
|
|
for (; *mem; mem++);
|
2002-04-12 21:26:59 +00:00
|
|
|
mem++;
|
|
|
|
}
|
|
|
|
|
|
|
|
_stringtab_pos = i;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::setupLocalStringTable(byte *mem, int num)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
int i = 0;
|
2002-07-07 19:06:48 +00:00
|
|
|
for (;;) {
|
2002-04-12 21:26:59 +00:00
|
|
|
_local_stringtable[i++] = mem;
|
|
|
|
if (--num == 0)
|
|
|
|
break;
|
2002-07-07 19:06:48 +00:00
|
|
|
for (; *mem; mem++);
|
2002-04-12 21:26:59 +00:00
|
|
|
mem++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::readSubroutineLine(FILE *in, SubroutineLine *sl, Subroutine *sub)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
byte line_buffer[1024], *q = line_buffer;
|
|
|
|
int size;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
if (sub->id == 0) {
|
|
|
|
sl->cond_a = fileReadBE16(in);
|
|
|
|
sl->cond_b = fileReadBE16(in);
|
|
|
|
sl->cond_c = fileReadBE16(in);
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
while ((*q = fileReadByte(in)) != 0xFF) {
|
2002-04-12 21:26:59 +00:00
|
|
|
if (*q == 87) {
|
|
|
|
fileReadBE16(in);
|
|
|
|
} else {
|
|
|
|
q = readSingleOpcode(in, q);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size = q - line_buffer + 1;
|
|
|
|
|
|
|
|
memcpy(allocateTable(size), line_buffer, size);
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
SubroutineLine *SimonState::createSubroutineLine(Subroutine *sub, int where)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
SubroutineLine *sl, *cur_sl = NULL, *last_sl = NULL;
|
|
|
|
|
|
|
|
if (sub->id == 0)
|
2002-07-07 19:06:48 +00:00
|
|
|
sl = (SubroutineLine *)allocateTable(SUBROUTINE_LINE_BIG_SIZE);
|
2002-04-12 21:26:59 +00:00
|
|
|
else
|
2002-07-07 19:06:48 +00:00
|
|
|
sl = (SubroutineLine *)allocateTable(SUBROUTINE_LINE_SMALL_SIZE);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
/* where is what offset to insert the line at, locate the proper beginning line */
|
|
|
|
if (sub->first != 0) {
|
2002-07-07 19:06:48 +00:00
|
|
|
cur_sl = (SubroutineLine *)((byte *)sub + sub->first);
|
2002-04-12 21:26:59 +00:00
|
|
|
while (where) {
|
|
|
|
last_sl = cur_sl;
|
2002-07-07 19:06:48 +00:00
|
|
|
cur_sl = (SubroutineLine *)((byte *)sub + cur_sl->next);
|
|
|
|
if ((byte *)cur_sl == (byte *)sub)
|
2002-04-12 21:26:59 +00:00
|
|
|
break;
|
|
|
|
where--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last_sl != NULL) {
|
|
|
|
/* Insert the subroutine line in the middle of the link */
|
2002-07-07 19:06:48 +00:00
|
|
|
last_sl->next = (byte *)sl - (byte *)sub;
|
|
|
|
sl->next = (byte *)cur_sl - (byte *)sub;
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
|
|
|
/* Insert the subroutine line at the head of the link */
|
|
|
|
sl->next = sub->first;
|
2002-07-07 19:06:48 +00:00
|
|
|
sub->first = (byte *)sl - (byte *)sub;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return sl;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::readSubroutine(FILE *in, Subroutine *sub)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
while (fileReadBE16(in) == 0) {
|
2002-07-07 19:06:48 +00:00
|
|
|
readSubroutineLine(in, createSubroutineLine(sub, 0xFFFF), sub);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
Subroutine *SimonState::createSubroutine(uint id)
|
|
|
|
{
|
2002-04-13 21:06:48 +00:00
|
|
|
Subroutine *sub;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-13 21:06:48 +00:00
|
|
|
alignTableMem();
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
sub = (Subroutine *)allocateTable(sizeof(Subroutine));
|
2002-04-12 21:26:59 +00:00
|
|
|
sub->id = id;
|
|
|
|
sub->first = 0;
|
|
|
|
sub->next = _subroutine_list;
|
|
|
|
_subroutine_list = sub;
|
|
|
|
return sub;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::readSubroutineBlock(FILE *in)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
while (fileReadBE16(in) == 0) {
|
2002-07-07 19:06:48 +00:00
|
|
|
readSubroutine(in, createSubroutine(fileReadBE16(in)));
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
Child *SimonState::findChildOfType(Item *i, uint type)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
Child *child = i->children;
|
2002-07-07 19:06:48 +00:00
|
|
|
for (; child; child = child->next)
|
2002-04-12 21:26:59 +00:00
|
|
|
if (child->type == type)
|
|
|
|
return child;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
bool SimonState::hasChildOfType1(Item *item)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
return findChildOfType1(item) != NULL;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
bool SimonState::hasChildOfType2(Item *item)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
return findChildOfType2(item) != NULL;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
Child1 *SimonState::findChildOfType1(Item *item)
|
|
|
|
{
|
|
|
|
return (Child1 *)findChildOfType(item, 1);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
Child2 *SimonState::findChildOfType2(Item *item)
|
|
|
|
{
|
|
|
|
return (Child2 *)findChildOfType(item, 2);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
Child3 *SimonState::findChildOfType3(Item *item)
|
|
|
|
{
|
|
|
|
return (Child3 *) findChildOfType(item, 3);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
uint SimonState::getOffsetOfChild2Param(Child2 *child, uint prop)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
uint m = 1;
|
|
|
|
uint offset = 0;
|
|
|
|
while (m != prop) {
|
|
|
|
if (child->avail_props & m)
|
|
|
|
offset++;
|
2002-07-07 19:06:48 +00:00
|
|
|
m <<= 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
Child *SimonState::allocateChildBlock(Item *i, uint type, uint size)
|
|
|
|
{
|
|
|
|
Child *child = (Child *)allocateItem(size);
|
2002-04-12 21:26:59 +00:00
|
|
|
child->next = i->children;
|
|
|
|
i->children = child;
|
|
|
|
child->type = type;
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::allocItemHeap()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
_itemheap_size = 10000;
|
|
|
|
_itemheap_curpos = 0;
|
2002-07-07 19:06:48 +00:00
|
|
|
_itemheap_ptr = (byte *)calloc(10000, 1);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::allocTablesHeap()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
_tablesheap_size = gss->TABLES_MEM_SIZE;
|
|
|
|
_tablesheap_curpos = 0;
|
2002-07-07 19:06:48 +00:00
|
|
|
_tablesheap_ptr = (byte *)calloc(gss->TABLES_MEM_SIZE, 1);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::setItemUnk3(Item *item, int value)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
item->unk3 = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
int SimonState::getNextWord()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
_code_ptr += 2;
|
2002-07-07 19:06:48 +00:00
|
|
|
return (int16)((_code_ptr[-2] << 8) | _code_ptr[-1]);
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
uint SimonState::getNextStringID()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
return (uint16)getNextWord();
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
uint SimonState::getVarOrByte()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
uint a = *_code_ptr++;
|
2002-07-07 19:06:48 +00:00
|
|
|
if (a != 255)
|
2002-06-29 16:11:13 +00:00
|
|
|
return a;
|
|
|
|
return readVariable(*_code_ptr++);
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
uint SimonState::getVarOrWord()
|
|
|
|
{
|
|
|
|
uint a = (_code_ptr[0] << 8) | _code_ptr[1];
|
2002-06-29 16:11:13 +00:00
|
|
|
_code_ptr += 2;
|
2002-07-07 19:06:48 +00:00
|
|
|
if (a >= 30000 && a < 30512)
|
2002-06-29 16:11:13 +00:00
|
|
|
return readVariable(a - 30000);
|
|
|
|
return a;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
Item *SimonState::getNextItemPtr()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
int a = getNextWord();
|
2002-07-07 19:06:48 +00:00
|
|
|
switch (a) {
|
|
|
|
case -1:
|
|
|
|
return _subject_item;
|
|
|
|
case -3:
|
|
|
|
return _object_item;
|
|
|
|
case -5:
|
|
|
|
return getItem1Ptr();
|
|
|
|
case -7:
|
|
|
|
return getItemPtrB();
|
|
|
|
case -9:
|
|
|
|
return derefItem(getItem1Ptr()->parent);
|
2002-06-29 16:11:13 +00:00
|
|
|
default:
|
|
|
|
return derefItem(a);
|
|
|
|
}
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
Item *SimonState::getNextItemPtrStrange()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
int a = getNextWord();
|
2002-07-07 19:06:48 +00:00
|
|
|
switch (a) {
|
|
|
|
case -1:
|
|
|
|
return _subject_item;
|
|
|
|
case -3:
|
|
|
|
return _object_item;
|
|
|
|
case -5:
|
2002-08-18 16:21:34 +00:00
|
|
|
return _dummy_item_2;
|
2002-07-07 19:06:48 +00:00
|
|
|
case -7:
|
|
|
|
return NULL;
|
|
|
|
case -9:
|
2002-08-18 16:21:34 +00:00
|
|
|
return _dummy_item_3;
|
2002-06-29 16:11:13 +00:00
|
|
|
default:
|
|
|
|
return derefItem(a);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
uint SimonState::getNextItemID()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
int a = getNextWord();
|
2002-07-07 19:06:48 +00:00
|
|
|
switch (a) {
|
|
|
|
case -1:
|
|
|
|
return itemPtrToID(_subject_item);
|
|
|
|
case -3:
|
|
|
|
return itemPtrToID(_object_item);
|
|
|
|
case -5:
|
|
|
|
return getItem1ID();
|
|
|
|
case -7:
|
|
|
|
return 0;
|
|
|
|
case -9:
|
|
|
|
return getItem1Ptr()->parent;
|
2002-06-29 16:11:13 +00:00
|
|
|
default:
|
|
|
|
return a;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
Item *SimonState::getItem1Ptr()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_item_1_ptr)
|
2002-07-07 19:06:48 +00:00
|
|
|
return _item_1_ptr;
|
2002-08-18 16:21:34 +00:00
|
|
|
return _dummy_item_1;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
Item *SimonState::getItemPtrB()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
error("getItemPtrB: is this code ever used?");
|
|
|
|
if (_item_ptr_B)
|
2002-07-07 19:06:48 +00:00
|
|
|
return _item_ptr_B;
|
2002-08-18 16:21:34 +00:00
|
|
|
return _dummy_item_1;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
uint SimonState::getNextVarContents()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
return (uint16)readVariable(getVarOrByte());
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
uint SimonState::readVariable(uint variable)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
if (variable >= 255)
|
|
|
|
error("Variable %d out of range in read", variable);
|
|
|
|
return _variableArray[variable];
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::writeNextVarContents(uint16 contents)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
writeVariable(getVarOrByte(), contents);
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::writeVariable(uint variable, uint16 contents)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
if (variable >= 256)
|
|
|
|
error("Variable %d out of range in write", variable);
|
|
|
|
_variableArray[variable] = contents;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::setItemParent(Item *item, Item *parent)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
Item *old_parent = derefItem(item->parent);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (item == parent)
|
2002-06-29 16:11:13 +00:00
|
|
|
error("Trying to set item as its own parent");
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
/* unlink it if it has a parent */
|
|
|
|
if (old_parent)
|
|
|
|
unlinkItem(item);
|
|
|
|
itemChildrenChanged(old_parent);
|
|
|
|
linkItem(item, parent);
|
|
|
|
itemChildrenChanged(parent);
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::itemChildrenChanged(Item *item)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
int i;
|
|
|
|
FillOrCopyStruct *fcs;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_no_parent_notify)
|
|
|
|
return;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
lock();
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
for (i = 0; i != 8; i++) {
|
2002-06-29 16:11:13 +00:00
|
|
|
fcs = _fcs_ptr_array_3[i];
|
|
|
|
if (fcs && fcs->fcs_data && fcs->fcs_data->item_ptr == item) {
|
|
|
|
if (_fcs_data_1[i]) {
|
|
|
|
_fcs_data_2[i] = true;
|
|
|
|
} else {
|
|
|
|
_fcs_data_2[i] = false;
|
|
|
|
fcs_unk_proc_1(i, item, fcs->fcs_data->unk1, fcs->fcs_data->unk2);
|
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unlock();
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::unlinkItem(Item *item)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
Item *first, *parent, *next;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
/* cannot unlink item without parent */
|
|
|
|
if (item->parent == 0)
|
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
/* get parent and first child of parent */
|
|
|
|
parent = derefItem(item->parent);
|
|
|
|
first = derefItem(parent->child);
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
/* the node to remove is first in the parent's children? */
|
|
|
|
if (first == item) {
|
|
|
|
parent->child = item->sibling;
|
|
|
|
item->parent = 0;
|
|
|
|
item->sibling = 0;
|
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
for (;;) {
|
2002-06-29 16:11:13 +00:00
|
|
|
if (!first)
|
|
|
|
error("unlinkItem: parent empty");
|
|
|
|
if (first->sibling == 0)
|
|
|
|
error("unlinkItem: parent does not contain child");
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
next = derefItem(first->sibling);
|
|
|
|
if (next == item) {
|
|
|
|
first->sibling = next->sibling;
|
|
|
|
item->parent = 0;
|
|
|
|
item->sibling = 0;
|
2002-07-07 19:06:48 +00:00
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-06-29 16:11:13 +00:00
|
|
|
first = next;
|
|
|
|
}
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::linkItem(Item *item, Item *parent)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
uint id;
|
|
|
|
/* Don't allow that an item that is already linked is relinked */
|
|
|
|
if (item->parent)
|
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
id = itemPtrToID(parent);
|
|
|
|
item->parent = id;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (parent != 0) {
|
|
|
|
item->sibling = parent->child;
|
|
|
|
parent->child = itemPtrToID(item);
|
|
|
|
} else {
|
|
|
|
item->sibling = 0;
|
|
|
|
}
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
const byte *SimonState::getStringPtrByID(uint string_id)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
const byte *string_ptr;
|
|
|
|
byte *dst;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
_free_string_slot ^= 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (string_id < 0x8000) {
|
|
|
|
string_ptr = _stringtab_ptr[string_id];
|
|
|
|
} else {
|
|
|
|
string_ptr = getLocalStringByID(string_id);
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
dst = &_stringReturnBuffer[_free_string_slot][0];
|
2002-07-07 19:06:48 +00:00
|
|
|
strcpy((char *)dst, (const char *)string_ptr);
|
2002-06-29 16:11:13 +00:00
|
|
|
return dst;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
const byte *SimonState::getLocalStringByID(uint string_id)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
if (string_id < _string_id_local_min || string_id >= _string_id_local_max) {
|
|
|
|
loadTextIntoMem(string_id);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-06-29 16:11:13 +00:00
|
|
|
return _local_stringtable[string_id - _string_id_local_min];
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::loadTextIntoMem(uint string_id)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
byte *p;
|
|
|
|
char filename[30];
|
|
|
|
int i;
|
|
|
|
uint base_min = 0x8000, base_max, size;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
_tablesheap_ptr = _tablesheap_ptr_new;
|
|
|
|
_tablesheap_curpos = _tablesheap_curpos_new;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
p = _stripped_txt_mem;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
/* get filename */
|
|
|
|
while (*p) {
|
2002-07-07 19:06:48 +00:00
|
|
|
for (i = 0; *p; p++, i++)
|
2002-06-29 16:11:13 +00:00
|
|
|
filename[i] = *p;
|
2002-07-07 19:06:48 +00:00
|
|
|
filename[i] = 0;
|
2002-06-29 16:11:13 +00:00
|
|
|
p++;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
base_max = (p[0] << 8) | p[1];
|
2002-06-29 16:11:13 +00:00
|
|
|
p += 2;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (string_id < base_max) {
|
|
|
|
_string_id_local_min = base_min;
|
|
|
|
_string_id_local_max = base_max;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
_local_stringtable = (byte **)_tablesheap_ptr;
|
|
|
|
|
|
|
|
size = (base_max - base_min + 1) * sizeof(byte *);
|
2002-06-29 16:11:13 +00:00
|
|
|
_tablesheap_ptr += size;
|
|
|
|
_tablesheap_curpos += size;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
size = loadTextFile(filename, _tablesheap_ptr);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
setupLocalStringTable(_tablesheap_ptr, base_max - base_min + 1);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
_tablesheap_ptr += size;
|
|
|
|
_tablesheap_curpos += size;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_tablesheap_curpos > _tablesheap_size) {
|
|
|
|
error("loadTextIntoMem: Out of table memory");
|
|
|
|
}
|
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
base_min = base_max;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
error("loadTextIntoMem: didn't find %d", string_id);
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::loadTablesIntoMem(uint subr_id)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
byte *p;
|
|
|
|
int i;
|
|
|
|
uint min_num, max_num;
|
|
|
|
char filename[30];
|
|
|
|
FILE *in;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
p = _tbl_list;
|
|
|
|
if (p == NULL)
|
2002-07-07 19:06:48 +00:00
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
while (*p) {
|
2002-07-07 19:06:48 +00:00
|
|
|
for (i = 0; *p; p++, i++)
|
2002-06-29 16:11:13 +00:00
|
|
|
filename[i] = *p;
|
|
|
|
filename[i] = 0;
|
|
|
|
p++;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
for (;;) {
|
|
|
|
min_num = (p[0] << 8) | p[1];
|
2002-06-29 16:11:13 +00:00
|
|
|
p += 2;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (min_num == 0)
|
2002-06-29 16:11:13 +00:00
|
|
|
break;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
max_num = (p[0] << 8) | p[1];
|
2002-06-29 16:11:13 +00:00
|
|
|
p += 2;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (subr_id >= min_num && subr_id <= max_num) {
|
|
|
|
_subroutine_list = _subroutine_list_org;
|
|
|
|
_tablesheap_ptr = _tablesheap_ptr_org;
|
|
|
|
_tablesheap_curpos = _tablesheap_curpos_org;
|
|
|
|
_string_id_local_min = 1;
|
|
|
|
_string_id_local_max = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
in = openTablesFile(filename);
|
|
|
|
readSubroutineBlock(in);
|
|
|
|
closeTablesFile(in);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
memcpy(filename, "SFXXXX", 6);
|
|
|
|
readSfxFile(filename);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
alignTableMem();
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
_tablesheap_ptr_new = _tablesheap_ptr;
|
|
|
|
_tablesheap_curpos_new = _tablesheap_curpos;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_tablesheap_curpos > _tablesheap_size)
|
|
|
|
error("loadTablesIntoMem: Out of table memory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
warning("loadTablesIntoMem: didn't find %d", subr_id);
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
Subroutine *SimonState::getSubroutineByID(uint subroutine_id)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
Subroutine *cur;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
for (cur = _subroutine_list; cur; cur = cur->next) {
|
2002-06-29 16:11:13 +00:00
|
|
|
if (cur->id == subroutine_id)
|
|
|
|
return cur;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
loadTablesIntoMem(subroutine_id);
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
for (cur = _subroutine_list; cur; cur = cur->next) {
|
2002-06-29 16:11:13 +00:00
|
|
|
if (cur->id == subroutine_id)
|
|
|
|
return cur;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
warning("getSubroutineByID: subroutine %d not found", subroutine_id);
|
|
|
|
return NULL;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
uint SimonState::loadTextFile_gme(const char *filename, byte *dst)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
uint res;
|
|
|
|
uint32 offs;
|
|
|
|
uint32 size;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
res = atoi(filename + 4) + gss->TEXT_INDEX_BASE - 1;
|
|
|
|
offs = _game_offsets_ptr[res];
|
2002-07-07 19:06:48 +00:00
|
|
|
size = _game_offsets_ptr[res + 1] - offs;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
resfile_read(dst, offs, size);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
return size;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
FILE *SimonState::openTablesFile_gme(const char *filename)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
uint res;
|
|
|
|
uint32 offs;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
res = atoi(filename + 6) + gss->TABLE_INDEX_BASE - 1;
|
|
|
|
offs = _game_offsets_ptr[res];
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
fseek(_game_file, offs, SEEK_SET);
|
|
|
|
return _game_file;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::closeTablesFile_gme(FILE *in)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
/* not needed */
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
/* Simon1DOS load tables file */
|
2002-07-07 19:06:48 +00:00
|
|
|
uint SimonState::loadTextFile_simon1(const char *filename, byte *dst)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
FILE *fo = fopen_maybe_lowercase(filename);
|
|
|
|
uint32 size;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
if (fo == NULL)
|
2002-06-29 16:11:13 +00:00
|
|
|
error("loadTextFile: Cannot open '%s'", filename);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
fseek(fo, 0, SEEK_END);
|
|
|
|
size = ftell(fo);
|
|
|
|
fseek(fo, 0, SEEK_SET);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (fread(dst, size, 1, fo) != 1)
|
2002-06-29 16:11:13 +00:00
|
|
|
error("loadTextFile: fread failed");
|
|
|
|
fclose(fo);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
return size;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
FILE *SimonState::openTablesFile_simon1(const char *filename)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
FILE *fo = fopen_maybe_lowercase(filename);
|
2002-07-07 19:06:48 +00:00
|
|
|
if (fo == NULL)
|
2002-06-29 16:11:13 +00:00
|
|
|
error("openTablesFile: Cannot open '%s'", filename);
|
|
|
|
return fo;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::closeTablesFile_simon1(FILE *in)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
fclose(in);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
uint SimonState::loadTextFile(const char *filename, byte *dst)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_game == GAME_SIMON1DOS)
|
|
|
|
return loadTextFile_simon1(filename, dst);
|
|
|
|
else
|
|
|
|
return loadTextFile_gme(filename, dst);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
FILE *SimonState::openTablesFile(const char *filename)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_game == GAME_SIMON1DOS)
|
|
|
|
return openTablesFile_simon1(filename);
|
|
|
|
else
|
|
|
|
return openTablesFile_gme(filename);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::closeTablesFile(FILE *in)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_game == GAME_SIMON1DOS)
|
|
|
|
closeTablesFile_simon1(in);
|
|
|
|
else
|
|
|
|
closeTablesFile_gme(in);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::addTimeEvent(uint timeout, uint subroutine_id)
|
|
|
|
{
|
|
|
|
TimeEvent *te = (TimeEvent *)malloc(sizeof(TimeEvent)), *first, *last = NULL;
|
2002-06-29 16:11:13 +00:00
|
|
|
time_t cur_time;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
time(&cur_time);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
te->time = cur_time + timeout - _base_time;
|
|
|
|
te->subroutine_id = subroutine_id;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
first = _first_time_struct;
|
|
|
|
while (first) {
|
|
|
|
if (te->time <= first->time) {
|
|
|
|
if (last) {
|
|
|
|
last->next = te;
|
|
|
|
te->next = first;
|
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-06-29 16:11:13 +00:00
|
|
|
te->next = _first_time_struct;
|
|
|
|
_first_time_struct = te;
|
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-06-29 16:11:13 +00:00
|
|
|
|
|
|
|
last = first;
|
|
|
|
first = first->next;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (last) {
|
|
|
|
last->next = te;
|
|
|
|
te->next = NULL;
|
|
|
|
} else {
|
|
|
|
_first_time_struct = te;
|
|
|
|
te->next = NULL;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::delTimeEvent(TimeEvent *te)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
TimeEvent *cur;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (te == _pending_delete_time_event)
|
|
|
|
_pending_delete_time_event = NULL;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (te == _first_time_struct) {
|
|
|
|
_first_time_struct = te->next;
|
|
|
|
free(te);
|
|
|
|
return;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
cur = _first_time_struct;
|
|
|
|
if (cur == NULL)
|
|
|
|
error("delTimeEvent: none available");
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
for (;;) {
|
2002-06-29 16:11:13 +00:00
|
|
|
if (cur->next == NULL)
|
|
|
|
error("delTimeEvent: no such te");
|
|
|
|
if (te == cur->next) {
|
|
|
|
cur->next = te->next;
|
|
|
|
free(te);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cur = cur->next;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::killAllTimers()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
TimeEvent *cur, *next;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
for (cur = _first_time_struct; cur; cur = next) {
|
2002-06-29 16:11:13 +00:00
|
|
|
next = cur->next;
|
|
|
|
delTimeEvent(cur);
|
|
|
|
}
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
bool SimonState::kickoffTimeEvents()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
time_t cur_time;
|
|
|
|
TimeEvent *te;
|
|
|
|
bool result = false;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
time(&cur_time);
|
|
|
|
cur_time -= _base_time;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
while ((te = _first_time_struct) != NULL && te->time <= (uint32)cur_time) {
|
2002-06-29 16:11:13 +00:00
|
|
|
result = true;
|
|
|
|
_pending_delete_time_event = te;
|
|
|
|
invokeTimeEvent(te);
|
|
|
|
if (_pending_delete_time_event) {
|
|
|
|
_pending_delete_time_event = NULL;
|
|
|
|
delTimeEvent(te);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
return result;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::invokeTimeEvent(TimeEvent *te)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
Subroutine *sub;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
_script_cond_a = 0;
|
|
|
|
if (_run_script_return_1)
|
|
|
|
return;
|
|
|
|
sub = getSubroutineByID(te->subroutine_id);
|
|
|
|
if (sub != NULL)
|
|
|
|
startSubroutineEx(sub);
|
|
|
|
_run_script_return_1 = false;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::o_setup_cond_c()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
Item *item = _item_1;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
setup_cond_c_helper();
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
_item_1_ptr = item;
|
|
|
|
_object_item = _hitarea_object_item;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-08-18 16:21:34 +00:00
|
|
|
if (_object_item == _dummy_item_2)
|
2002-06-29 16:11:13 +00:00
|
|
|
_object_item = getItem1Ptr();
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-08-18 16:21:34 +00:00
|
|
|
if (_object_item == _dummy_item_3)
|
2002-06-29 16:11:13 +00:00
|
|
|
_object_item = derefItem(getItem1Ptr()->parent);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_object_item != NULL) {
|
|
|
|
_script_cond_c = _object_item->unk1;
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2002-06-29 16:11:13 +00:00
|
|
|
_script_cond_c = -1;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::setup_cond_c_helper()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
HitArea *last;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if ((_game == GAME_SIMON2WIN) || (_game == GAME_SIMON2DOS)) {
|
|
|
|
_mouse_cursor = 0;
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_hitarea_unk_4 != 999) {
|
2002-06-29 16:11:13 +00:00
|
|
|
_mouse_cursor = 9;
|
|
|
|
_need_hitarea_recalc++;
|
|
|
|
_hitarea_unk_4 = 0;
|
|
|
|
}
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
_last_hitarea = 0;
|
|
|
|
_hitarea_object_item = NULL;
|
|
|
|
_hitarea_unk_6 = true;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
last = _last_hitarea_2_ptr;
|
|
|
|
defocusHitarea();
|
|
|
|
_last_hitarea_2_ptr = last;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
for (;;) {
|
2002-06-29 16:11:13 +00:00
|
|
|
_last_hitarea = NULL;
|
|
|
|
_last_hitarea_3 = 0;
|
|
|
|
_left_button_down = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
do {
|
2002-08-18 16:21:34 +00:00
|
|
|
#ifdef WIN32
|
2002-07-07 19:06:48 +00:00
|
|
|
if (GetAsyncKeyState(VK_F5) != 0 && _bit_array[0] & 0x200) {
|
2002-08-18 16:21:34 +00:00
|
|
|
#else
|
|
|
|
if (_bit_array[0] & 0x200) {
|
|
|
|
#endif
|
2002-06-29 16:11:13 +00:00
|
|
|
startSubroutine170();
|
|
|
|
goto out_of_here;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
delay(100);
|
2002-07-07 19:06:48 +00:00
|
|
|
} while (_last_hitarea_3 == (HitArea *) 0xFFFFFFFF || _last_hitarea_3 == 0);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_last_hitarea == NULL) {
|
|
|
|
} else if (_last_hitarea->id == 0x7FFB) {
|
|
|
|
handle_unk2_hitarea(_last_hitarea->fcs);
|
|
|
|
} else if (_last_hitarea->id == 0x7FFC) {
|
|
|
|
handle_unk_hitarea(_last_hitarea->fcs);
|
|
|
|
} else if (_last_hitarea->item_ptr != NULL) {
|
|
|
|
_hitarea_object_item = _last_hitarea->item_ptr;
|
2002-07-07 19:06:48 +00:00
|
|
|
_variableArray[60] = (_last_hitarea->flags & 1) ? (_last_hitarea->flags >> 8) : 0xFFFF;
|
2002-06-29 16:11:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
out_of_here:
|
|
|
|
_last_hitarea_3 = 0;
|
|
|
|
_last_hitarea = 0;
|
|
|
|
_last_hitarea_2_ptr = NULL;
|
|
|
|
_hitarea_unk_6 = false;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::startSubroutine170()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
Subroutine *sub;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
/* XXX: stop speech */
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
sub = getSubroutineByID(170);
|
|
|
|
if (sub != NULL)
|
|
|
|
startSubroutineEx(sub);
|
|
|
|
|
|
|
|
_run_script_return_1 = true;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
uint SimonState::get_fcs_ptr_3_index(FillOrCopyStruct *fcs)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
uint i;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
for (i = 0; i != ARRAYSIZE(_fcs_ptr_array_3); i++)
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_fcs_ptr_array_3[i] == fcs)
|
|
|
|
return i;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
error("get_fcs_ptr_3_index: not found");
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::lock()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
_lock_counter++;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::unlock()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
_lock_word |= 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_lock_counter != 0) {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_lock_counter == 1) {
|
2002-08-18 16:21:34 +00:00
|
|
|
#ifdef WIN32
|
2002-06-29 16:11:13 +00:00
|
|
|
GetAsyncKeyState(VK_LBUTTON);
|
2002-08-18 16:21:34 +00:00
|
|
|
#endif
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
|
|
|
_lock_counter--;
|
|
|
|
}
|
|
|
|
_lock_word &= ~1;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::handle_mouse_moved()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
uint x;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_lock_counter)
|
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
pollMouseXY();
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_mouse_x >= 32768)
|
|
|
|
_mouse_x = 0;
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_mouse_x >= 638 / 2)
|
|
|
|
_mouse_x = 638 / 2;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_mouse_y >= 32768)
|
|
|
|
_mouse_y = 0;
|
|
|
|
if (_mouse_y >= 199)
|
|
|
|
_mouse_y = 199;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_hitarea_unk_4) {
|
|
|
|
uint id = 101;
|
|
|
|
if (_mouse_y >= 136)
|
|
|
|
id = 102;
|
|
|
|
if (_hitarea_unk_4 != id)
|
|
|
|
hitarea_proc_1();
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_game & GAME_SIMON2) {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_bit_array[4] & 0x8000) {
|
2002-06-29 16:11:13 +00:00
|
|
|
if (!_vga_var9) {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_mouse_x >= 630 / 2 || _mouse_x < 9)
|
2002-06-29 16:11:13 +00:00
|
|
|
goto get_out2;
|
|
|
|
_vga_var9 = 1;
|
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_vga_var2 == 0) {
|
|
|
|
if (_mouse_x >= 631 / 2) {
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_x_scroll != _vga_var1)
|
|
|
|
_vga_var3 = 1;
|
|
|
|
} else if (_mouse_x < 8) {
|
|
|
|
if (_x_scroll != 0)
|
|
|
|
_vga_var3 = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2002-07-07 19:06:48 +00:00
|
|
|
get_out2:;
|
2002-06-29 16:11:13 +00:00
|
|
|
_vga_var9 = 0;
|
|
|
|
}
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_mouse_x != _mouse_x_old || _mouse_y != _mouse_y_old)
|
|
|
|
_need_hitarea_recalc++;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
x = 0;
|
|
|
|
if (_last_hitarea_3 == 0 && _left_button_down != 0) {
|
|
|
|
_left_button_down = 0;
|
|
|
|
x = 1;
|
|
|
|
} else {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_hitarea_unk_3 == 0 && _need_hitarea_recalc == 0)
|
|
|
|
goto get_out;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
setup_hitarea_from_pos(_mouse_x, _mouse_y, x);
|
|
|
|
_last_hitarea_3 = _last_hitarea;
|
2002-07-07 19:06:48 +00:00
|
|
|
if (x == 1 && _last_hitarea == NULL)
|
|
|
|
_last_hitarea_3 = (HitArea *) - 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
get_out:
|
|
|
|
draw_mouse_pointer();
|
|
|
|
_need_hitarea_recalc = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::fcs_unk_proc_1(uint fcs_index, Item *item_ptr, int unk1, int unk2)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
Item *item_ptr_org = item_ptr;
|
|
|
|
FillOrCopyStruct *fcs_ptr;
|
|
|
|
uint width_div_3, height_div_3;
|
2002-07-07 19:06:48 +00:00
|
|
|
uint j, k, i, num_sibs_with_flag;
|
2002-06-29 16:11:13 +00:00
|
|
|
bool item_again;
|
|
|
|
uint x_pos, y_pos;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
fcs_ptr = _fcs_ptr_array_3[fcs_index & 7];
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (!(_game & GAME_SIMON2)) {
|
|
|
|
width_div_3 = fcs_ptr->width / 3;
|
|
|
|
height_div_3 = fcs_ptr->height / 3;
|
|
|
|
} else {
|
|
|
|
width_div_3 = 100;
|
|
|
|
height_div_3 = 40;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
i = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (fcs_ptr == NULL)
|
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (fcs_ptr->fcs_data)
|
|
|
|
fcs_unk1(fcs_index);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
fcs_ptr->fcs_data = (FillOrCopyData *) malloc(sizeof(FillOrCopyData));
|
2002-06-29 16:11:13 +00:00
|
|
|
fcs_ptr->fcs_data->item_ptr = item_ptr;
|
|
|
|
fcs_ptr->fcs_data->unk3 = -1;
|
|
|
|
fcs_ptr->fcs_data->unk4 = -1;
|
|
|
|
fcs_ptr->fcs_data->unk1 = unk1;
|
|
|
|
fcs_ptr->fcs_data->unk2 = unk2;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
item_ptr = derefItem(item_ptr->child);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
while (item_ptr && unk1-- != 0) {
|
|
|
|
num_sibs_with_flag = 0;
|
|
|
|
while (item_ptr && width_div_3 > num_sibs_with_flag) {
|
2002-07-07 19:06:48 +00:00
|
|
|
if ((unk2 == 0 || item_ptr->unk4 & unk2) && has_item_childflag_0x10(item_ptr))
|
2002-06-29 16:11:13 +00:00
|
|
|
if (!(_game & GAME_SIMON2)) {
|
|
|
|
num_sibs_with_flag++;
|
|
|
|
} else {
|
2002-07-07 19:06:48 +00:00
|
|
|
num_sibs_with_flag += 20;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-06-29 16:11:13 +00:00
|
|
|
item_ptr = derefItem(item_ptr->sibling);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (item_ptr == NULL) {
|
|
|
|
fcs_ptr->fcs_data->unk1 = 0;
|
|
|
|
item_ptr = derefItem(item_ptr_org->child);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
x_pos = 0;
|
|
|
|
y_pos = 0;
|
|
|
|
item_again = false;
|
|
|
|
k = 0;
|
|
|
|
j = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
while (item_ptr) {
|
2002-07-07 19:06:48 +00:00
|
|
|
if ((unk2 == 0 || item_ptr->unk4 & unk2) && has_item_childflag_0x10(item_ptr)) {
|
2002-06-29 16:11:13 +00:00
|
|
|
if (item_again == false) {
|
|
|
|
fcs_ptr->fcs_data->e[k].item = item_ptr;
|
|
|
|
if (!(_game & GAME_SIMON2)) {
|
2002-07-07 19:06:48 +00:00
|
|
|
draw_icon_c(fcs_ptr, item_get_icon_number(item_ptr), x_pos * 3, y_pos);
|
|
|
|
fcs_ptr->fcs_data->e[k].hit_area =
|
|
|
|
setup_icon_hit_area(fcs_ptr, x_pos * 3, y_pos,
|
|
|
|
item_get_icon_number(item_ptr), item_ptr);
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2002-06-29 16:11:13 +00:00
|
|
|
draw_icon_c(fcs_ptr, item_get_icon_number(item_ptr), x_pos, y_pos);
|
2002-07-07 19:06:48 +00:00
|
|
|
fcs_ptr->fcs_data->e[k].hit_area =
|
|
|
|
setup_icon_hit_area(fcs_ptr, x_pos, y_pos, item_get_icon_number(item_ptr), item_ptr);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-06-29 16:11:13 +00:00
|
|
|
k++;
|
|
|
|
} else {
|
|
|
|
fcs_ptr->fcs_data->e[k].item = NULL;
|
|
|
|
j = 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
x_pos += (_game & GAME_SIMON2) ? 20 : 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (x_pos >= width_div_3) {
|
|
|
|
x_pos = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
y_pos += (_game & GAME_SIMON2) ? 20 : 1;
|
2002-06-29 16:11:13 +00:00
|
|
|
if (y_pos >= height_div_3)
|
|
|
|
item_again = true;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
|
|
|
item_ptr = derefItem(item_ptr->sibling);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
fcs_ptr->fcs_data->e[k].item = NULL;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
if (j != 0 || fcs_ptr->fcs_data->unk1 != 0) {
|
2002-06-29 16:11:13 +00:00
|
|
|
fcs_unk_proc_2(fcs_ptr, fcs_index);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::fcs_unk_proc_2(FillOrCopyStruct *fcs, uint fcs_index)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
setup_hit_areas(fcs, fcs_index);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
fcs->fcs_data->unk3 = _scroll_up_hit_area;
|
|
|
|
fcs->fcs_data->unk4 = _scroll_down_hit_area;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::setup_hit_areas(FillOrCopyStruct *fcs, uint fcs_index)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
HitArea *ha;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
ha = findEmptyHitArea();
|
|
|
|
_scroll_up_hit_area = ha - _hit_areas;
|
2002-04-12 21:26:59 +00:00
|
|
|
if (!(_game & GAME_SIMON2)) {
|
2002-06-29 16:11:13 +00:00
|
|
|
ha->x = 308;
|
|
|
|
ha->y = 149;
|
|
|
|
ha->width = 12;
|
|
|
|
ha->height = 17;
|
|
|
|
ha->flags = 0x24;
|
|
|
|
ha->id = 0x7FFB;
|
|
|
|
ha->layer = 100;
|
|
|
|
ha->fcs = fcs;
|
|
|
|
ha->unk3 = 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2002-06-29 16:11:13 +00:00
|
|
|
ha->x = 81;
|
|
|
|
ha->y = 158;
|
|
|
|
ha->width = 12;
|
|
|
|
ha->height = 26;
|
|
|
|
ha->flags = 36;
|
|
|
|
ha->id = 0x7FFB;
|
|
|
|
ha->layer = 100;
|
|
|
|
ha->fcs = fcs;
|
|
|
|
ha->unk3 = 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
ha = findEmptyHitArea();
|
|
|
|
_scroll_down_hit_area = ha - _hit_areas;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (!(_game & GAME_SIMON2)) {
|
|
|
|
ha->x = 308;
|
|
|
|
ha->y = 176;
|
|
|
|
ha->width = 12;
|
|
|
|
ha->height = 17;
|
|
|
|
ha->flags = 0x24;
|
|
|
|
ha->id = 0x7FFC;
|
|
|
|
ha->layer = 100;
|
|
|
|
ha->fcs = fcs;
|
|
|
|
ha->unk3 = 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
/* Simon1 specific */
|
|
|
|
o_unk_99_simon1(0x80);
|
|
|
|
start_vga_code(0, 1, 0x80, 0, 0, 0xE);
|
|
|
|
} else {
|
|
|
|
ha->x = 227;
|
|
|
|
ha->y = 162;
|
|
|
|
ha->width = 12;
|
|
|
|
ha->height = 26;
|
|
|
|
ha->flags = 36;
|
|
|
|
ha->id = 0x7FFC;
|
|
|
|
ha->layer = 100;
|
|
|
|
ha->fcs = fcs;
|
|
|
|
ha->unk3 = 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
bool SimonState::has_item_childflag_0x10(Item *item)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
Child2 *child = findChildOfType2(item);
|
|
|
|
return child && (child->avail_props & 0x10) != 0;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
uint SimonState::item_get_icon_number(Item *item)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
Child2 *child = findChildOfType2(item);
|
|
|
|
uint offs;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (child == NULL || !(child->avail_props & 0x10))
|
2002-06-29 16:11:13 +00:00
|
|
|
return 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
offs = getOffsetOfChild2Param(child, 0x10);
|
|
|
|
return child->array[offs];
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::loadIconFile()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
FILE *in = fopen_maybe_lowercase("ICON.DAT");
|
|
|
|
uint size;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (in == NULL)
|
2002-06-29 16:11:13 +00:00
|
|
|
error("Cannot open icon.dat");
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
fseek(in, 0, SEEK_END);
|
|
|
|
size = ftell(in);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
_icon_file_ptr = (byte *)malloc(size);
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_icon_file_ptr == NULL)
|
|
|
|
error("Out of icon memory");
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
fseek(in, 0, SEEK_SET);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
fread(_icon_file_ptr, size, 1, in);
|
|
|
|
fclose(in);
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
uint SimonState::setup_icon_hit_area(FillOrCopyStruct *fcs, uint x, uint y, uint icon_number,
|
|
|
|
Item *item_ptr)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
HitArea *ha;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
ha = findEmptyHitArea();
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (!(_game & GAME_SIMON2)) {
|
2002-07-07 19:06:48 +00:00
|
|
|
ha->x = (x + fcs->x) << 3;
|
|
|
|
ha->y = y * 25 + fcs->y;
|
2002-06-29 16:11:13 +00:00
|
|
|
ha->item_ptr = item_ptr;
|
|
|
|
ha->width = 24;
|
|
|
|
ha->height = 24;
|
|
|
|
ha->flags = 0xB0;
|
|
|
|
ha->id = 0x7FFD;
|
|
|
|
ha->layer = 100;
|
|
|
|
ha->unk3 = 0xD0;
|
|
|
|
} else {
|
|
|
|
ha->x = x + 110;
|
|
|
|
ha->y = fcs->y + y;
|
|
|
|
ha->item_ptr = item_ptr;
|
|
|
|
ha->width = 20;
|
|
|
|
ha->height = 20;
|
|
|
|
ha->flags = 0xB0;
|
|
|
|
ha->id = 0x7FFD;
|
|
|
|
ha->layer = 100;
|
|
|
|
ha->unk3 = 0xD0;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
return ha - _hit_areas;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::hitarea_stuff()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
HitArea *ha;
|
|
|
|
uint id;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
_left_button_down = 0;
|
|
|
|
_last_hitarea = 0;
|
|
|
|
_verb_hitarea = 0;
|
|
|
|
_hitarea_subject_item = NULL;
|
|
|
|
_hitarea_object_item = NULL;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
hitarea_proc_1();
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
startOver:
|
2002-07-07 19:06:48 +00:00
|
|
|
for (;;) {
|
2002-06-29 16:11:13 +00:00
|
|
|
_last_hitarea = NULL;
|
|
|
|
_last_hitarea_3 = NULL;
|
2002-07-07 19:06:48 +00:00
|
|
|
for (;;) {
|
2002-06-29 16:11:13 +00:00
|
|
|
processSpecialKeys();
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_last_hitarea_3 == (HitArea *) 0xFFFFFFFF)
|
|
|
|
goto startOver;
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_last_hitarea_3 != 0)
|
|
|
|
break;
|
|
|
|
hitarea_stuff_helper();
|
|
|
|
delay(100);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
ha = _last_hitarea;
|
|
|
|
|
|
|
|
if (ha == NULL) {
|
2002-07-07 19:06:48 +00:00
|
|
|
} else if (ha->id == 0x7FFB) {
|
2002-06-29 16:11:13 +00:00
|
|
|
handle_unk2_hitarea(ha->fcs);
|
|
|
|
} else if (ha->id == 0x7FFC) {
|
|
|
|
handle_unk_hitarea(ha->fcs);
|
2002-07-07 19:06:48 +00:00
|
|
|
} else if (ha->id >= 101 && ha->id < 113) {
|
2002-06-29 16:11:13 +00:00
|
|
|
_verb_hitarea = ha->unk3;
|
|
|
|
handle_verb_hitarea(ha);
|
|
|
|
_hitarea_unk_4 = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2002-07-07 19:06:48 +00:00
|
|
|
if ((_verb_hitarea != 0 || _hitarea_subject_item != ha->item_ptr && ha->flags & 0x80) &&
|
|
|
|
ha->item_ptr) {
|
|
|
|
if_1:;
|
2002-06-29 16:11:13 +00:00
|
|
|
_hitarea_subject_item = ha->item_ptr;
|
|
|
|
id = 0xFFFF;
|
2002-07-07 19:06:48 +00:00
|
|
|
if (ha->flags & 1)
|
|
|
|
id = ha->flags >> 8;
|
2002-06-29 16:11:13 +00:00
|
|
|
_variableArray[60] = id;
|
|
|
|
new_current_hitarea(ha);
|
|
|
|
if (_verb_hitarea != 0)
|
|
|
|
break;
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2002-06-29 16:11:13 +00:00
|
|
|
/* else 1 */
|
|
|
|
if (ha->unk3 == 0) {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (ha->item_ptr)
|
|
|
|
goto if_1;
|
2002-06-29 16:11:13 +00:00
|
|
|
} else {
|
|
|
|
_verb_hitarea = ha->unk3 & 0xBFFF;
|
|
|
|
if (ha->unk3 & 0x4000) {
|
|
|
|
_hitarea_subject_item = ha->item_ptr;
|
|
|
|
break;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_hitarea_subject_item != NULL)
|
|
|
|
break;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
_need_hitarea_recalc++;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::hitarea_stuff_helper()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
time_t cur_time;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
if (!(_game & GAME_SIMON2)) {
|
2002-07-07 19:06:48 +00:00
|
|
|
uint subr_id = _variableArray[0x1FC / 2];
|
2002-06-29 16:11:13 +00:00
|
|
|
if (subr_id != 0) {
|
|
|
|
Subroutine *sub = getSubroutineByID(subr_id);
|
|
|
|
if (sub != NULL) {
|
|
|
|
startSubroutineEx(sub);
|
|
|
|
startUp_helper_2();
|
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
_variableArray[0x1FC / 2] = 0;
|
2002-06-29 16:11:13 +00:00
|
|
|
_run_script_return_1 = false;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_variableArray[0x1FC / 2] || _variableArray[0x1F2 / 2]) {
|
2002-06-29 16:11:13 +00:00
|
|
|
hitarea_stuff_helper_2();
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
time(&cur_time);
|
2002-07-07 19:06:48 +00:00
|
|
|
if ((uint) cur_time != _last_time) {
|
2002-06-29 16:11:13 +00:00
|
|
|
_last_time = cur_time;
|
|
|
|
if (kickoffTimeEvents())
|
|
|
|
startUp_helper_2();
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
/* Simon 2 specific */
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::hitarea_stuff_helper_2()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
uint subr_id;
|
|
|
|
Subroutine *sub;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
subr_id = _variableArray[0x1F2 / 2];
|
2002-06-29 16:11:13 +00:00
|
|
|
if (subr_id != 0) {
|
|
|
|
sub = getSubroutineByID(subr_id);
|
|
|
|
if (sub != NULL) {
|
2002-07-07 19:06:48 +00:00
|
|
|
_variableArray[0x1F2 / 2] = 0;
|
2002-06-29 16:11:13 +00:00
|
|
|
startSubroutineEx(sub);
|
|
|
|
startUp_helper_2();
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
_variableArray[0x1F2 / 2] = 0;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
subr_id = _variableArray[0x1FC / 2];
|
2002-06-29 16:11:13 +00:00
|
|
|
if (subr_id != 0) {
|
|
|
|
sub = getSubroutineByID(subr_id);
|
|
|
|
if (sub != NULL) {
|
2002-07-07 19:06:48 +00:00
|
|
|
_variableArray[0x1FC / 2] = 0;
|
2002-06-29 16:11:13 +00:00
|
|
|
startSubroutineEx(sub);
|
|
|
|
startUp_helper_2();
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
_variableArray[0x1FC / 2] = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
_run_script_return_1 = false;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::startUp_helper_2()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
if (!_mortal_flag) {
|
|
|
|
_mortal_flag = true;
|
|
|
|
startUp_helper_3();
|
|
|
|
_fcs_unk_1 = 0;
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_fcs_ptr_array_3[0] != 0) {
|
2002-06-29 16:11:13 +00:00
|
|
|
_fcs_ptr_1 = _fcs_ptr_array_3[0];
|
2002-08-04 13:25:06 +00:00
|
|
|
showmessage_helper_3(_fcs_ptr_1->textLength,
|
|
|
|
_fcs_ptr_1->textMaxLength);
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
|
|
|
_mortal_flag = false;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::startUp_helper_3()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
showmessage_print_char(0);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::showmessage_helper_3(uint a, uint b)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
_print_char_unk_1 = a;
|
|
|
|
_print_char_unk_2 = b;
|
|
|
|
_num_letters_to_print = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::pollMouseXY()
|
|
|
|
{
|
2002-08-18 16:21:34 +00:00
|
|
|
_mouse_x = _sdl_mouse_x;
|
|
|
|
_mouse_y = _sdl_mouse_y;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::handle_verb_clicked(uint verb)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
Subroutine *sub;
|
|
|
|
int result;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
_item_1_ptr = _item_1;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
_object_item = _hitarea_object_item;
|
2002-08-18 16:21:34 +00:00
|
|
|
if (_object_item == _dummy_item_2) {
|
2002-06-29 16:11:13 +00:00
|
|
|
_object_item = getItem1Ptr();
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-08-18 16:21:34 +00:00
|
|
|
if (_object_item == _dummy_item_3) {
|
2002-06-29 16:11:13 +00:00
|
|
|
_object_item = derefItem(getItem1Ptr()->parent);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
_subject_item = _hitarea_subject_item;
|
2002-08-18 16:21:34 +00:00
|
|
|
if (_subject_item == _dummy_item_2) {
|
2002-06-29 16:11:13 +00:00
|
|
|
_subject_item = getItem1Ptr();
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-08-18 16:21:34 +00:00
|
|
|
if (_subject_item == _dummy_item_3) {
|
2002-06-29 16:11:13 +00:00
|
|
|
_subject_item = derefItem(getItem1Ptr()->parent);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_subject_item) {
|
|
|
|
_script_cond_b = _subject_item->unk1;
|
|
|
|
} else {
|
|
|
|
_script_cond_b = -1;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_object_item) {
|
|
|
|
_script_cond_c = _object_item->unk1;
|
|
|
|
} else {
|
|
|
|
_script_cond_c = -1;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
_script_cond_a = _verb_hitarea;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
sub = getSubroutineByID(0);
|
2002-07-07 19:06:48 +00:00
|
|
|
if (sub == NULL)
|
2002-06-29 16:11:13 +00:00
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
result = startSubroutine(sub);
|
|
|
|
if (result == -1)
|
|
|
|
showMessageFormat("I don't understand");
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
_run_script_return_1 = false;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
sub = getSubroutineByID(100);
|
2002-07-07 19:06:48 +00:00
|
|
|
if (sub)
|
|
|
|
startSubroutine(sub);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_game & GAME_SIMON2)
|
|
|
|
_run_script_return_1 = false;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
startUp_helper_2();
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::o_print_str()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
uint num_1 = getVarOrByte();
|
|
|
|
uint num_2 = getVarOrByte();
|
|
|
|
uint string_id = getNextStringID();
|
|
|
|
const byte *string_ptr = NULL;
|
|
|
|
uint speech_id = 0;
|
|
|
|
ThreeValues *tv;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
switch (_game) {
|
2002-06-29 16:11:13 +00:00
|
|
|
case GAME_SIMON1WIN:
|
|
|
|
if (string_id != 0xFFFF)
|
|
|
|
string_ptr = getStringPtrByID(string_id);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
speech_id = (uint16)getNextWord();
|
|
|
|
break;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
case GAME_SIMON2WIN:
|
|
|
|
if (string_id != 0xFFFF)
|
|
|
|
string_ptr = getStringPtrByID(string_id);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
speech_id = (uint16)getNextWord();
|
|
|
|
break;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
case GAME_SIMON2DOS:
|
|
|
|
if (string_id != 0xFFFF)
|
|
|
|
string_ptr = getStringPtrByID(string_id);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
speech_id = (uint16)getNextWord();
|
|
|
|
break;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
case GAME_SIMON1DOS:
|
|
|
|
string_ptr = getStringPtrByID(string_id);
|
|
|
|
break;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
switch (num_1) {
|
|
|
|
case 1:
|
|
|
|
tv = &_threevalues_1;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
tv = &_threevalues_2;
|
|
|
|
break;
|
|
|
|
case 101:
|
|
|
|
tv = &_threevalues_3;
|
|
|
|
break;
|
|
|
|
case 102:
|
|
|
|
tv = &_threevalues_4;
|
|
|
|
break;
|
2002-06-29 16:11:13 +00:00
|
|
|
default:
|
|
|
|
error("o_print_str, invalid value %d", num_1);
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
switch (_game) {
|
2002-06-29 16:11:13 +00:00
|
|
|
case GAME_SIMON1WIN:
|
|
|
|
#ifdef USE_TEXT_HACK
|
|
|
|
if (speech_id != 0) {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (string_ptr == NULL)
|
2002-06-29 16:11:13 +00:00
|
|
|
talk_with_speech(speech_id, num_1);
|
2002-07-07 19:06:48 +00:00
|
|
|
else if (speech_id != 9999)
|
2002-06-29 16:11:13 +00:00
|
|
|
playVoice(speech_id);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (string_ptr != NULL) {
|
2002-07-07 19:06:48 +00:00
|
|
|
talk_with_text(num_1, num_2, (char *)string_ptr, tv->a, tv->b, tv->c);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-06-29 16:11:13 +00:00
|
|
|
#else
|
|
|
|
if (speech_id != 0) {
|
|
|
|
talk_with_speech(speech_id, num_1);
|
2002-07-07 19:06:48 +00:00
|
|
|
} else if (string_ptr != NULL) {
|
|
|
|
talk_with_text(num_1, num_2, (char *)string_ptr, tv->a, tv->b, tv->c);
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
case GAME_SIMON1DOS:
|
2002-07-07 19:06:48 +00:00
|
|
|
talk_with_text(num_1, num_2, (char *)string_ptr, tv->a, tv->b, tv->c);
|
2002-06-29 16:11:13 +00:00
|
|
|
break;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
case GAME_SIMON2DOS:
|
2002-07-07 19:06:48 +00:00
|
|
|
if (speech_id != 0 && num_1 == 1 && !_vk_t_toggle)
|
2002-06-29 16:11:13 +00:00
|
|
|
talk_with_speech(speech_id, num_1);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (speech_id != 0 && !_vk_t_toggle)
|
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (speech_id == 0)
|
2002-07-07 19:06:48 +00:00
|
|
|
o_unk_99_simon2(2, num_1 + 2);
|
|
|
|
|
|
|
|
talk_with_text(num_1, num_2, (char *)string_ptr, tv->a, tv->b, tv->c);
|
|
|
|
break;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
case GAME_SIMON2WIN:
|
2002-07-07 19:06:48 +00:00
|
|
|
if (speech_id != 0 && num_1 == 1 && !_vk_t_toggle)
|
2002-06-29 16:11:13 +00:00
|
|
|
talk_with_speech(speech_id, num_1);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (speech_id != 0 && !_vk_t_toggle)
|
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (speech_id == 0)
|
2002-07-07 19:06:48 +00:00
|
|
|
o_unk_99_simon2(2, num_1 + 2);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
talk_with_text(num_1, num_2, (char *)string_ptr, tv->a, tv->b, tv->c);
|
|
|
|
break;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::ensureVgaResLoadedC(uint vga_res)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
_lock_word |= 0x80;
|
|
|
|
ensureVgaResLoaded(vga_res);
|
|
|
|
_lock_word &= ~0x80;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::ensureVgaResLoaded(uint vga_res)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
VgaPointersEntry *vpe;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
CHECK_BOUNDS(vga_res, _vga_buffer_pointers);
|
|
|
|
|
|
|
|
vpe = _vga_buffer_pointers + vga_res;
|
|
|
|
if (vpe->vgaFile1 != NULL)
|
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
vpe->vgaFile2 = read_vga_from_datfile_2(vga_res * 2 + 1);
|
|
|
|
vpe->vgaFile1 = read_vga_from_datfile_2(vga_res * 2);
|
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
byte *SimonState::setup_vga_destination(uint32 size)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
byte *dest, *end;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
_video_var_4 = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
for (;;) {
|
2002-06-29 16:11:13 +00:00
|
|
|
dest = _vga_buf_free_start;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
end = dest + size;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (end >= _vga_buf_end) {
|
|
|
|
_vga_buf_free_start = _vga_buf_start;
|
|
|
|
} else {
|
|
|
|
_video_var_5 = false;
|
|
|
|
vga_buf_unk_proc3(end);
|
|
|
|
if (_video_var_5)
|
|
|
|
continue;
|
|
|
|
vga_buf_unk_proc1(end);
|
|
|
|
if (_video_var_5)
|
|
|
|
continue;
|
|
|
|
delete_memptr_range(end);
|
|
|
|
_vga_buf_free_start = end;
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::setup_vga_file_buf_pointers()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
byte *alloced;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
alloced = (byte *)malloc(gss->VGA_MEM_SIZE);
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
_vga_buf_free_start = alloced;
|
|
|
|
_vga_buf_start = alloced;
|
|
|
|
_vga_file_buf_org = alloced;
|
|
|
|
_vga_file_buf_org_2 = alloced;
|
|
|
|
_vga_buf_end = alloced + gss->VGA_MEM_SIZE;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::vga_buf_unk_proc3(byte *end)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
VgaPointersEntry *vpe;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
if (_video_var_7 == 0xFFFF)
|
2002-06-29 16:11:13 +00:00
|
|
|
return;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_video_var_4 == 2)
|
|
|
|
error("vga_buf_unk_proc3: _video_var_4 == 2");
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
vpe = &_vga_buffer_pointers[_video_var_7];
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_vga_buf_free_start <= vpe->vgaFile1 && end >= vpe->vgaFile1 ||
|
2002-07-07 19:06:48 +00:00
|
|
|
_vga_buf_free_start <= vpe->vgaFile2 && end >= vpe->vgaFile2) {
|
2002-06-29 16:11:13 +00:00
|
|
|
_video_var_5 = 1;
|
|
|
|
_video_var_4++;
|
|
|
|
_vga_buf_free_start = vpe->vgaFile1 + 0x5000;
|
|
|
|
} else {
|
|
|
|
_video_var_5 = 0;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::vga_buf_unk_proc1(byte *end)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
VgaSprite *vsp;
|
|
|
|
if (_lock_word & 0x20)
|
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
for (vsp = _vga_sprites; vsp->id; vsp++) {
|
2002-06-29 16:11:13 +00:00
|
|
|
vga_buf_unk_proc2(vsp->unk7, end);
|
|
|
|
if (_video_var_5 == true)
|
|
|
|
return;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::delete_memptr_range(byte *end)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
uint count = ARRAYSIZE(_vga_buffer_pointers);
|
|
|
|
VgaPointersEntry *vpe = _vga_buffer_pointers;
|
|
|
|
do {
|
|
|
|
if (_vga_buf_free_start <= vpe->vgaFile1 && end >= vpe->vgaFile1 ||
|
2002-07-07 19:06:48 +00:00
|
|
|
_vga_buf_free_start <= vpe->vgaFile2 && end >= vpe->vgaFile2) {
|
|
|
|
vpe->dd = 0;
|
|
|
|
vpe->vgaFile1 = NULL;
|
|
|
|
vpe->vgaFile2 = NULL;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
} while (++vpe, --count);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::vga_buf_unk_proc2(uint a, byte *end)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
VgaPointersEntry *vpe;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
vpe = &_vga_buffer_pointers[a];
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_vga_buf_free_start <= vpe->vgaFile1 && end >= vpe->vgaFile1 ||
|
2002-07-07 19:06:48 +00:00
|
|
|
_vga_buf_free_start <= vpe->vgaFile2 && end >= vpe->vgaFile2) {
|
2002-06-29 16:11:13 +00:00
|
|
|
_video_var_5 = true;
|
|
|
|
_video_var_4++;
|
|
|
|
_vga_buf_free_start = vpe->vgaFile1 + 0x5000;
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2002-06-29 16:11:13 +00:00
|
|
|
_video_var_5 = false;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::o_clear_vgapointer_entry(uint a)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
VgaPointersEntry *vpe;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
vpe = &_vga_buffer_pointers[a];
|
2002-04-14 11:00:33 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
vpe->dd = 0;
|
|
|
|
vpe->vgaFile1 = NULL;
|
|
|
|
vpe->vgaFile2 = NULL;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::o_set_video_mode(uint mode, uint vga_res)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
if (mode == 4)
|
|
|
|
vc_29_stop_all_sounds();
|
|
|
|
|
|
|
|
if (_lock_word & 0x10) {
|
|
|
|
error("o_set_video_mode_ex: _lock_word & 0x10");
|
2002-07-07 19:06:48 +00:00
|
|
|
// _unk21_word_array[a] = b;
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2002-07-07 19:06:48 +00:00
|
|
|
set_video_mode(mode, vga_res);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::set_video_mode_internal(uint mode, uint vga_res_id)
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
uint num;
|
|
|
|
VgaPointersEntry *vpe;
|
2002-07-07 19:06:48 +00:00
|
|
|
byte *bb, *b;
|
2002-06-29 16:11:13 +00:00
|
|
|
uint16 c;
|
|
|
|
byte *vc_ptr_org;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
warning("Set video mode internal: %d, %d", mode, vga_res_id);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
_video_palette_mode = mode;
|
|
|
|
_lock_word |= 0x20;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (vga_res_id == 0) {
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (!(_game & GAME_SIMON2)) {
|
|
|
|
_unk_pal_flag = true;
|
|
|
|
} else {
|
|
|
|
_dx_use_3_or_4_for_lock = true;
|
|
|
|
_vga_var6 = true;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
_vga_cur_file_2 = num = vga_res_id / 100;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
for (;;) {
|
2002-06-29 16:11:13 +00:00
|
|
|
vpe = &_vga_buffer_pointers[num];
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
_cur_vga_file_1 = vpe->vgaFile1;
|
|
|
|
_cur_vga_file_2 = vpe->vgaFile2;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (vpe->vgaFile1 != NULL)
|
|
|
|
break;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
ensureVgaResLoaded(num);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
/* ensure flipping complete */
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
bb = _cur_vga_file_1;
|
2002-07-07 19:06:48 +00:00
|
|
|
b = bb + READ_BE_UINT16_UNALIGNED(&((VgaFile1Header *) bb)->hdr2_start);
|
|
|
|
c = READ_BE_UINT16_UNALIGNED(&((VgaFile1Header2 *) b)->unk1);
|
|
|
|
b = bb + READ_BE_UINT16_UNALIGNED(&((VgaFile1Header2 *) b)->unk2_offs);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
while (READ_BE_UINT16_UNALIGNED(&((VgaFile1Struct0x8 *) b)->id) != vga_res_id)
|
2002-06-29 16:11:13 +00:00
|
|
|
b += sizeof(VgaFile1Struct0x8);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (!(_game & GAME_SIMON2)) {
|
|
|
|
if (num == 16300) {
|
|
|
|
dx_clear_attached_from_top(134);
|
|
|
|
_use_palette_delay = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_x_scroll = 0;
|
|
|
|
_vga_var1 = 0;
|
|
|
|
_vga_var2 = 0;
|
|
|
|
_vga_var3 = 0;
|
|
|
|
_vga_var5 = 134;
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_variableArray[34] != -1)
|
|
|
|
_variableArray[502 / 2] = 0;
|
2002-06-29 16:11:13 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
vc_ptr_org = _vc_ptr;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
_vc_ptr = _cur_vga_file_1 + READ_BE_UINT16_UNALIGNED(&((VgaFile1Struct0x8 *) b)->script_offs);
|
|
|
|
// dump_vga_script(_vc_ptr, num, vga_res_id);
|
2002-06-29 16:11:13 +00:00
|
|
|
run_vga_script();
|
|
|
|
_vc_ptr = vc_ptr_org;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_game & GAME_SIMON2) {
|
|
|
|
if (!_dx_use_3_or_4_for_lock) {
|
2002-07-07 19:06:48 +00:00
|
|
|
uint num_lines = _video_palette_mode == 4 ? 134 : 200;
|
2002-06-29 16:11:13 +00:00
|
|
|
_vga_var8 = num_lines;
|
|
|
|
dx_copy_from_attached_to_2(0, 0, 320, num_lines);
|
|
|
|
dx_copy_from_attached_to_3(num_lines);
|
|
|
|
_sync_flag_2 = 1;
|
|
|
|
}
|
|
|
|
_dx_use_3_or_4_for_lock = false;
|
|
|
|
} else {
|
2002-07-07 19:06:48 +00:00
|
|
|
uint num_lines = _video_palette_mode == 4 ? 134 : 200;
|
2002-06-29 16:11:13 +00:00
|
|
|
dx_copy_from_attached_to_2(0, 0, 320, num_lines);
|
|
|
|
dx_copy_from_attached_to_3(num_lines);
|
|
|
|
_sync_flag_2 = 1;
|
|
|
|
_timer_5 = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
_lock_word &= ~0x20;
|
|
|
|
/* XXX: fix */
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
|
|
|
|
if (!(_game & GAME_SIMON2)) {
|
|
|
|
if (_unk_pal_flag) {
|
|
|
|
_unk_pal_flag = false;
|
2002-07-07 19:06:48 +00:00
|
|
|
while (*(volatile int *)&_palette_color_count != 0) {
|
2002-06-29 16:11:13 +00:00
|
|
|
delay(10);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::set_video_mode(uint mode, uint vga_res_id)
|
|
|
|
{
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
if (_lock_counter == 0) {
|
|
|
|
lock();
|
|
|
|
if (_lock_word == 0) {
|
|
|
|
_sync_flag_1 = true;
|
2002-07-07 19:06:48 +00:00
|
|
|
while ((*(volatile bool *)&_sync_flag_1) == true) {
|
2002-06-29 16:11:13 +00:00
|
|
|
delay(10);
|
|
|
|
}
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
_lock_word |= 0x20;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
// while ((*(volatile uint16*)&_lock_word) & 2) {
|
|
|
|
// delay(10);
|
|
|
|
// }
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
unlock();
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
set_video_mode_internal(mode, vga_res_id);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::o_fade_to_black()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
uint i;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
memcpy(_video_buf_1, _palette_backup, 256 * sizeof(uint32));
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
i = NUM_PALETTE_FADEOUT;
|
|
|
|
do {
|
2002-07-07 19:06:48 +00:00
|
|
|
palette_fadeout((uint32 *)_video_buf_1, 32);
|
|
|
|
palette_fadeout((uint32 *)_video_buf_1 + 32 + 16, 144);
|
|
|
|
palette_fadeout((uint32 *)_video_buf_1 + 32 + 16 + 144 + 16, 48);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
_system->set_palette(_video_buf_1, 0, 256);
|
|
|
|
_system->update_screen();
|
|
|
|
delay(5);
|
|
|
|
} while (--i);
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
memcpy(_palette_backup, _video_buf_1, 256 * sizeof(uint32));
|
|
|
|
memcpy(_palette, _video_buf_1, 256 * sizeof(uint32));
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::delete_vga_timer(VgaTimerEntry * vte)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
_lock_word |= 1;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
if (vte + 1 <= _next_vga_timer_to_process) {
|
2002-04-12 21:26:59 +00:00
|
|
|
_next_vga_timer_to_process--;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
2002-07-07 19:06:48 +00:00
|
|
|
memcpy(vte, vte + 1, sizeof(VgaTimerEntry));
|
2002-04-12 21:26:59 +00:00
|
|
|
vte++;
|
|
|
|
} while (vte->delay);
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
_lock_word &= ~1;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::expire_vga_timers()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
if (_game & GAME_SIMON2) {
|
|
|
|
VgaTimerEntry *vte = _vga_timer_list;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
_vga_tick_counter++;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
while (vte->delay) {
|
|
|
|
/* not quite ok, good enough */
|
2002-07-07 19:06:48 +00:00
|
|
|
if ((int16)(vte->delay -= 5) <= 0) {
|
2002-04-12 21:26:59 +00:00
|
|
|
uint16 cur_file = vte->cur_vga_file;
|
|
|
|
uint16 cur_unk = vte->sprite_id;
|
|
|
|
byte *script_ptr = vte->script_pointer;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
_next_vga_timer_to_process = vte + 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
delete_vga_timer(vte);
|
|
|
|
|
|
|
|
if (script_ptr == NULL) {
|
|
|
|
/* special scroll timer */
|
|
|
|
scroll_timeout();
|
|
|
|
} else {
|
|
|
|
vc_resume_thread(script_ptr, cur_file, cur_unk);
|
|
|
|
}
|
|
|
|
vte = _next_vga_timer_to_process;
|
|
|
|
} else {
|
|
|
|
vte++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
VgaTimerEntry *vte = _vga_timer_list;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
_vga_tick_counter++;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
while (vte->delay) {
|
|
|
|
if (!--vte->delay) {
|
|
|
|
uint16 cur_file = vte->cur_vga_file;
|
|
|
|
uint16 cur_unk = vte->sprite_id;
|
|
|
|
byte *script_ptr = vte->script_pointer;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
_next_vga_timer_to_process = vte + 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
delete_vga_timer(vte);
|
|
|
|
|
|
|
|
vc_resume_thread(script_ptr, cur_file, cur_unk);
|
|
|
|
vte = _next_vga_timer_to_process;
|
|
|
|
} else {
|
|
|
|
vte++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Simon2 specific */
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::scroll_timeout()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
if (_vga_var2 == 0)
|
|
|
|
return;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
if (_vga_var2 < 0) {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_vga_var3 != -1) {
|
2002-04-12 21:26:59 +00:00
|
|
|
_vga_var3 = -1;
|
|
|
|
if (++_vga_var2 == 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_vga_var3 != 1) {
|
2002-04-12 21:26:59 +00:00
|
|
|
_vga_var3 = 1;
|
|
|
|
if (--_vga_var2 == 0)
|
|
|
|
return;
|
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
add_vga_timer(10, NULL, 0, 0);
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::vc_resume_thread(byte *code_ptr, uint16 cur_file, uint16 cur_sprite)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
VgaPointersEntry *vpe;
|
|
|
|
|
|
|
|
_vga_cur_sprite_id = cur_sprite;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
_vga_cur_file_id = cur_file;
|
|
|
|
_vga_cur_file_2 = cur_file;
|
|
|
|
vpe = &_vga_buffer_pointers[cur_file];
|
|
|
|
|
|
|
|
_cur_vga_file_1 = vpe->vgaFile1;
|
|
|
|
_cur_vga_file_2 = vpe->vgaFile2;
|
|
|
|
|
|
|
|
_vc_ptr = code_ptr;
|
|
|
|
|
|
|
|
run_vga_script();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::add_vga_timer(uint num, byte *code_ptr, uint cur_sprite, uint cur_file)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
VgaTimerEntry *vte;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
// assert( (uint)READ_BE_UINT16_UNALIGNED(&*(uint16*)code_ptr) <= 63);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
_lock_word |= 1;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
for (vte = _vga_timer_list; vte->delay; vte++) {
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
vte->delay = num;
|
|
|
|
vte->script_pointer = code_ptr;
|
|
|
|
vte->sprite_id = cur_sprite;
|
|
|
|
vte->cur_vga_file = cur_file;
|
|
|
|
|
|
|
|
_lock_word &= ~1;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::o_force_unlock()
|
|
|
|
{
|
|
|
|
if (_game & GAME_SIMON2 && _bit_array[4] & 0x8000)
|
2002-04-12 21:26:59 +00:00
|
|
|
_mouse_cursor = 0;
|
|
|
|
_lock_counter = 0;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::o_force_lock()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
_lock_word |= 0x4000;
|
|
|
|
vc_34();
|
|
|
|
_lock_word &= ~0x4000;
|
|
|
|
}
|
2002-04-16 12:07:19 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::o_save_game()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
save_or_load_dialog(false);
|
2002-04-16 12:07:19 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::o_load_game()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
save_or_load_dialog(true);
|
2002-04-16 12:07:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
int SimonState::display_savegame_list(int curpos, bool load, char *dst)
|
|
|
|
{
|
2002-04-16 12:07:19 +00:00
|
|
|
int slot, last_slot;
|
|
|
|
FILE *in;
|
|
|
|
|
|
|
|
showMessageFormat("\xC");
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
memset(dst, 0, 18 * 6);
|
2002-04-16 12:07:19 +00:00
|
|
|
|
|
|
|
slot = curpos;
|
|
|
|
|
|
|
|
while (curpos + 6 > slot) {
|
|
|
|
in = fopen(gen_savename(slot), "rb");
|
2002-07-07 19:06:48 +00:00
|
|
|
if (!in)
|
|
|
|
break;
|
2002-04-16 12:07:19 +00:00
|
|
|
|
|
|
|
fread(dst, 1, 18, in);
|
|
|
|
fclose(in);
|
|
|
|
last_slot = slot;
|
|
|
|
if (slot < 10)
|
|
|
|
showMessageFormat(" ");
|
|
|
|
showMessageFormat("%d", slot);
|
|
|
|
showMessageFormat(".%s\n", dst);
|
2002-07-07 19:06:48 +00:00
|
|
|
dst += 18;
|
2002-04-16 12:07:19 +00:00
|
|
|
slot++;
|
|
|
|
}
|
|
|
|
/* while_break */
|
|
|
|
if (!load) {
|
|
|
|
if (curpos + 6 == slot)
|
|
|
|
slot++;
|
|
|
|
else {
|
|
|
|
if (slot < 10)
|
|
|
|
showMessageFormat(" ");
|
|
|
|
showMessageFormat("%d.\n", slot);
|
|
|
|
}
|
|
|
|
} else {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (curpos + 6 == slot) {
|
2002-04-16 12:07:19 +00:00
|
|
|
in = fopen(gen_savename(slot), "rb");
|
|
|
|
if (in != NULL) {
|
|
|
|
slot++;
|
|
|
|
fclose(in);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return slot - curpos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::savegame_dialog(char *buf)
|
|
|
|
{
|
2002-04-16 12:07:19 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
o_unk_132_helper_3();
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-16 12:07:19 +00:00
|
|
|
i = display_savegame_list(_saveload_row_curpos, _save_or_load, buf);
|
|
|
|
|
|
|
|
_savedialog_flag = true;
|
|
|
|
|
|
|
|
if (i != 7) {
|
|
|
|
i++;
|
|
|
|
if (!_save_or_load)
|
|
|
|
i++;
|
|
|
|
_savedialog_flag = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!--i)
|
|
|
|
return;
|
|
|
|
|
|
|
|
do {
|
|
|
|
clear_hitarea_bit_0x40(0xd0 + i - 1);
|
|
|
|
} while (--i);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::save_or_load_dialog(bool load)
|
|
|
|
{
|
2002-04-16 12:07:19 +00:00
|
|
|
time_t save_time;
|
|
|
|
int num = _number_of_savegames;
|
|
|
|
int i;
|
|
|
|
int unk132_result;
|
|
|
|
FillOrCopyStruct *fcs;
|
|
|
|
char *name;
|
|
|
|
int name_len;
|
|
|
|
bool b;
|
|
|
|
char buf[108];
|
|
|
|
|
|
|
|
_save_or_load = load;
|
|
|
|
|
|
|
|
save_time = time(NULL);
|
|
|
|
|
|
|
|
_copy_partial_mode = 1;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-16 12:07:19 +00:00
|
|
|
num = _number_of_savegames;
|
2002-07-07 19:06:48 +00:00
|
|
|
if (!load)
|
|
|
|
num++;
|
2002-04-16 12:07:19 +00:00
|
|
|
num -= 6;
|
2002-07-07 19:06:48 +00:00
|
|
|
if (num < 0)
|
|
|
|
num = 0;
|
2002-04-16 12:07:19 +00:00
|
|
|
num++;
|
|
|
|
_num_savegame_rows = num;
|
|
|
|
|
|
|
|
_saveload_row_curpos = 1;
|
|
|
|
if (!load)
|
|
|
|
_saveload_row_curpos = num;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-16 12:07:19 +00:00
|
|
|
_saveload_flag = false;
|
|
|
|
|
|
|
|
restart:;
|
|
|
|
do {
|
|
|
|
i = o_unk_132_helper(&b, buf);
|
|
|
|
} while (!b);
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (i == 205)
|
|
|
|
goto get_out;
|
2002-04-16 12:07:19 +00:00
|
|
|
if (!load) {
|
|
|
|
/* if_1 */
|
2002-07-07 19:06:48 +00:00
|
|
|
if_1:;
|
2002-04-16 12:07:19 +00:00
|
|
|
unk132_result = i;
|
|
|
|
|
|
|
|
set_hitarea_bit_0x40(0xd0 + i);
|
|
|
|
leaveHitAreaById(0xd0 + i);
|
|
|
|
|
|
|
|
/* some code here */
|
|
|
|
|
|
|
|
fcs = _fcs_ptr_array_3[5];
|
|
|
|
|
2002-08-04 13:25:06 +00:00
|
|
|
fcs->textRow = unk132_result;
|
|
|
|
|
|
|
|
// init x offset with a 2 character savegame number + a period (18 pix)
|
|
|
|
fcs->textColumn = 2;
|
|
|
|
fcs->textColumnOffset = 2;
|
|
|
|
fcs->textLength = 3;
|
2002-04-16 12:07:19 +00:00
|
|
|
|
|
|
|
name = buf + i * 18;
|
|
|
|
|
2002-08-04 13:25:06 +00:00
|
|
|
// now process entire savegame name to get correct x offset for cursor
|
2002-04-16 12:07:19 +00:00
|
|
|
name_len = 0;
|
|
|
|
while (name[name_len]) {
|
2002-08-04 13:25:06 +00:00
|
|
|
fcs->textLength++;
|
|
|
|
fcs->textColumnOffset += 6;
|
2002-04-16 12:07:19 +00:00
|
|
|
if (name[name_len] == 'i' || name[name_len] == 'l')
|
2002-08-04 13:25:06 +00:00
|
|
|
fcs->textColumnOffset -= 2;
|
|
|
|
if (fcs->textColumnOffset >= 8) {
|
|
|
|
fcs->textColumnOffset -= 8;
|
|
|
|
fcs->textColumn++;
|
2002-04-16 12:07:19 +00:00
|
|
|
}
|
|
|
|
name_len++;
|
|
|
|
}
|
|
|
|
/* while_1_end */
|
|
|
|
|
|
|
|
/* do_3_start */
|
2002-07-07 19:06:48 +00:00
|
|
|
for (;;) {
|
2002-04-16 12:07:19 +00:00
|
|
|
video_putchar(fcs, 0x7f);
|
|
|
|
|
|
|
|
_saveload_flag = true;
|
|
|
|
|
|
|
|
/* do_2 */
|
|
|
|
do {
|
|
|
|
i = o_unk_132_helper(&b, buf);
|
|
|
|
|
|
|
|
if (b) {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (i == 205)
|
|
|
|
goto get_out;
|
2002-04-16 12:07:19 +00:00
|
|
|
clear_hitarea_bit_0x40(0xd0 + unk132_result);
|
|
|
|
if (_saveload_flag) {
|
|
|
|
o_unk_132_helper_2(_fcs_ptr_array_3[5], 8);
|
|
|
|
/* move code */
|
2002-07-07 19:06:48 +00:00
|
|
|
}
|
|
|
|
goto if_1;
|
2002-04-16 12:07:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* is_not_b */
|
|
|
|
if (!_saveload_flag) {
|
|
|
|
clear_hitarea_bit_0x40(0xd0 + unk132_result);
|
|
|
|
goto restart;
|
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
} while (i >= 0x80 || i == 0);
|
2002-04-16 12:07:19 +00:00
|
|
|
|
|
|
|
/* after_do_2 */
|
|
|
|
o_unk_132_helper_2(_fcs_ptr_array_3[5], 8);
|
2002-07-07 19:06:48 +00:00
|
|
|
if (i == 10 || i == 13)
|
|
|
|
break;
|
|
|
|
if (i == 8) {
|
2002-04-16 12:07:19 +00:00
|
|
|
/* do_backspace */
|
|
|
|
if (name_len != 0) {
|
|
|
|
int x;
|
|
|
|
|
|
|
|
name_len--;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
x = (name[name_len] == 'i' || name[name_len] == 'l') ? 1 : 8;
|
2002-04-16 12:07:19 +00:00
|
|
|
name[name_len] = 0;
|
|
|
|
|
|
|
|
o_unk_132_helper_2(_fcs_ptr_array_3[5], x);
|
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
} else if (i >= 32 && name_len != 17) {
|
2002-04-16 12:07:19 +00:00
|
|
|
name[name_len++] = i;
|
|
|
|
|
|
|
|
video_putchar(_fcs_ptr_array_3[5], i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do_save */
|
|
|
|
if (!save_game(_saveload_row_curpos + unk132_result, buf + unk132_result * 18))
|
|
|
|
warning("Save failed");
|
|
|
|
} else {
|
|
|
|
if (!load_game(_saveload_row_curpos + i))
|
|
|
|
warning("Load failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
get_out:;
|
|
|
|
o_unk_132_helper_3();
|
2002-07-07 19:06:48 +00:00
|
|
|
// clear_keydowns();
|
2002-04-16 12:07:19 +00:00
|
|
|
|
|
|
|
_base_time = time(NULL) - save_time + _base_time;
|
|
|
|
_copy_partial_mode = 0;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-16 12:07:19 +00:00
|
|
|
dx_copy_rgn_from_3_to_2(94, 208, 46, 80);
|
|
|
|
|
|
|
|
i = _timer_4;
|
|
|
|
do {
|
|
|
|
delay(10);
|
|
|
|
} while (i == _timer_4);
|
2002-07-18 22:51:29 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
|
|
|
|
if (draw_keyboard) {
|
|
|
|
draw_keyboard = false;
|
|
|
|
toolbar_drawn = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::o_wait_for_vga(uint a)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
_vga_wait_for = a;
|
|
|
|
_timer_1 = 0;
|
|
|
|
_exit_cutscene = false;
|
|
|
|
while (_vga_wait_for != 0) {
|
|
|
|
if (_exit_cutscene) {
|
|
|
|
if (vc_get_bit(9)) {
|
|
|
|
startSubroutine170();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
processSpecialKeys();
|
|
|
|
}
|
|
|
|
|
|
|
|
delay(10);
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
// if (_timer_1 >= 500) {
|
|
|
|
// warning("wait timed out");
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
// warning("waiting on %d done", a);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::timer_vga_sprites()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
VgaSprite *vsp;
|
|
|
|
VgaPointersEntry *vpe;
|
|
|
|
byte *vc_ptr_org = _vc_ptr;
|
2002-07-07 19:06:48 +00:00
|
|
|
uint16 params[5]; /* parameters to vc_10 */
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
if (_video_var_9 == 2)
|
|
|
|
_video_var_9 = 1;
|
|
|
|
|
|
|
|
#ifdef DRAW_THREE_STARS
|
2002-07-07 19:06:48 +00:00
|
|
|
fprintf(_dump_file, "***\n");
|
2002-04-12 21:26:59 +00:00
|
|
|
#endif
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_game & GAME_SIMON2 && _vga_var3) {
|
2002-04-12 21:26:59 +00:00
|
|
|
timer_vga_sprites_helper();
|
|
|
|
}
|
|
|
|
|
|
|
|
vsp = _vga_sprites;
|
|
|
|
while (vsp->id != 0) {
|
|
|
|
vsp->unk6 &= 0x7FFF;
|
|
|
|
|
|
|
|
vpe = &_vga_buffer_pointers[vsp->unk7];
|
|
|
|
_cur_vga_file_1 = vpe->vgaFile1;
|
|
|
|
_cur_vga_file_2 = vpe->vgaFile2;
|
|
|
|
_video_palette_mode = vsp->unk6;
|
|
|
|
_vga_cur_sprite_id = vsp->id;
|
|
|
|
|
2002-04-13 20:08:58 +00:00
|
|
|
params[0] = READ_BE_UINT16_UNALIGNED(&vsp->image);
|
|
|
|
params[1] = READ_BE_UINT16_UNALIGNED(&vsp->base_color);
|
|
|
|
params[2] = READ_BE_UINT16_UNALIGNED(&vsp->x);
|
|
|
|
params[3] = READ_BE_UINT16_UNALIGNED(&vsp->y);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_game & GAME_SIMON2) {
|
|
|
|
*(byte *)(¶ms[4]) = (byte)vsp->unk4;
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2002-04-13 20:08:58 +00:00
|
|
|
params[4] = READ_BE_UINT16_UNALIGNED(&vsp->unk4);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
_vc_ptr = (byte *)params;
|
2002-04-12 21:26:59 +00:00
|
|
|
vc_10();
|
|
|
|
|
|
|
|
vsp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DRAW_IMAGES_DEBUG
|
2002-08-18 16:21:34 +00:00
|
|
|
memset(_sdl_buf_attached, 0, 320 * 200);
|
2002-04-12 21:26:59 +00:00
|
|
|
#endif
|
|
|
|
_video_var_8++;
|
|
|
|
_vc_ptr = vc_ptr_org;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::timer_vga_sprites_helper()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
byte *dst = dx_lock_2(), *src;
|
|
|
|
uint x;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_vga_var3 < 0) {
|
|
|
|
memmove(dst + 8, dst, 320 * _vga_var5 - 8);
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2002-07-07 19:06:48 +00:00
|
|
|
memmove(dst, dst + 8, 320 * _vga_var5 - 8);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
x = _x_scroll - 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_vga_var3 > 0) {
|
|
|
|
dst += 320 - 8;
|
2002-04-12 21:26:59 +00:00
|
|
|
x += 41;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
src = _vga_var7 + x * 4;
|
|
|
|
vc_10_helper_8(dst, src + READ_BE_UINT32_UNALIGNED(&*((uint32 *)src)));
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
dx_unlock_2();
|
|
|
|
|
|
|
|
|
2002-08-18 16:21:34 +00:00
|
|
|
memcpy(_sdl_buf_attached, _sdl_buf, 320 * 200);
|
2002-04-12 21:26:59 +00:00
|
|
|
dx_copy_from_attached_to_3(_vga_var5);
|
|
|
|
|
|
|
|
|
|
|
|
_x_scroll += _vga_var3;
|
|
|
|
|
|
|
|
vc_write_var(0xfB, _x_scroll);
|
|
|
|
|
|
|
|
_vga_var3 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DRAW_IMAGES_DEBUG
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::timer_vga_sprites_2()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
VgaSprite *vsp;
|
|
|
|
VgaPointersEntry *vpe;
|
|
|
|
byte *vc_ptr_org = _vc_ptr;
|
2002-07-07 19:06:48 +00:00
|
|
|
uint16 params[5]; /* parameters to vc_10 */
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
if (_video_var_9 == 2)
|
|
|
|
_video_var_9 = 1;
|
|
|
|
|
|
|
|
vsp = _vga_sprites;
|
|
|
|
while (vsp->id != 0) {
|
|
|
|
vsp->unk6 &= 0x7FFF;
|
|
|
|
|
|
|
|
vpe = &_vga_buffer_pointers[vsp->unk7];
|
|
|
|
_cur_vga_file_1 = vpe->vgaFile1;
|
|
|
|
_cur_vga_file_2 = vpe->vgaFile2;
|
|
|
|
_video_palette_mode = vsp->unk6;
|
|
|
|
_vga_cur_sprite_id = vsp->id;
|
|
|
|
|
|
|
|
if (vsp->image)
|
2002-07-07 19:06:48 +00:00
|
|
|
fprintf(_dump_file, "id:%5d image:%3d base-color:%3d x:%3d y:%3d flags:%x\n",
|
|
|
|
vsp->id, vsp->image, vsp->base_color, vsp->x, vsp->y, vsp->unk4);
|
2002-04-13 20:08:58 +00:00
|
|
|
params[0] = READ_BE_UINT16_UNALIGNED(&vsp->image);
|
|
|
|
params[1] = READ_BE_UINT16_UNALIGNED(&vsp->base_color);
|
|
|
|
params[2] = READ_BE_UINT16_UNALIGNED(&vsp->x);
|
|
|
|
params[3] = READ_BE_UINT16_UNALIGNED(&vsp->y);
|
|
|
|
params[4] = READ_BE_UINT16_UNALIGNED(&vsp->unk4);
|
2002-07-07 19:06:48 +00:00
|
|
|
_vc_ptr = (byte *)params;
|
2002-04-12 21:26:59 +00:00
|
|
|
vc_10();
|
|
|
|
|
|
|
|
vsp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DRAW_THREE_STARS
|
2002-07-07 19:06:48 +00:00
|
|
|
fprintf(_dump_file, "***\n");
|
2002-04-12 21:26:59 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
_video_var_8++;
|
|
|
|
_vc_ptr = vc_ptr_org;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::timer_proc1()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
_timer_4++;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
if (_lock_word & 0xC0E9 || _lock_word & 2)
|
2002-04-12 21:26:59 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
_timer_1++;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
_lock_word |= 2;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (!(_lock_word & 0x10)) {
|
2002-04-12 21:26:59 +00:00
|
|
|
if (!(_game & GAME_SIMON2)) {
|
|
|
|
expire_vga_timers();
|
|
|
|
expire_vga_timers();
|
2002-07-07 19:06:48 +00:00
|
|
|
_cepe_flag ^= 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
if (!_cepe_flag)
|
|
|
|
expire_vga_timers();
|
|
|
|
|
|
|
|
_sync_flag_2 ^= 1;
|
|
|
|
} else {
|
2002-07-07 19:06:48 +00:00
|
|
|
_sync_flag_2 ^= 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
if (!_sync_flag_2)
|
|
|
|
expire_vga_timers();
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
if (_lock_counter != 0 && !_sync_flag_2) {
|
2002-04-12 21:26:59 +00:00
|
|
|
_lock_word &= ~2;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
// if (_lock_counter !=0 && _sync_flag_2==1) {
|
|
|
|
// printf("skipping draw...\n");
|
|
|
|
// goto get_out;
|
|
|
|
// }
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
timer_vga_sprites();
|
|
|
|
#ifdef DRAW_IMAGES_DEBUG
|
|
|
|
timer_vga_sprites_2();
|
|
|
|
#endif
|
|
|
|
|
2002-08-20 09:58:35 +00:00
|
|
|
if (_copy_partial_mode == 1) {
|
|
|
|
dx_copy_from_2_to_attached(80, 46, 208 - 80, 94 - 46);
|
|
|
|
}
|
2002-04-16 12:07:19 +00:00
|
|
|
|
2002-08-20 09:58:35 +00:00
|
|
|
if (_copy_partial_mode == 2) {
|
|
|
|
/* copy partial from attached to 2 */
|
|
|
|
dx_copy_from_attached_to_2(176, 61, 320 - 176, 134 - 61);
|
|
|
|
_copy_partial_mode = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: more stuff here */
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_video_var_8) {
|
2002-04-12 21:26:59 +00:00
|
|
|
handle_mouse_moved();
|
|
|
|
/* XXX: more stuff here */
|
|
|
|
dx_update_screen_and_palette();
|
|
|
|
_sync_flag_1 = false;
|
|
|
|
_video_var_8 = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
_lock_word &= ~2;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::timer_callback()
|
|
|
|
{
|
|
|
|
// uint32 start, end;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
if (_timer_5 != 0) {
|
|
|
|
_sync_flag_2 = true;
|
2002-07-07 19:06:48 +00:00
|
|
|
_timer_5--;
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2002-07-07 19:06:48 +00:00
|
|
|
// start = timeGetTime();
|
2002-04-12 21:26:59 +00:00
|
|
|
timer_proc1();
|
2002-07-07 19:06:48 +00:00
|
|
|
// end = timeGetTime();
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
// if (start + 45 < end) {
|
|
|
|
// _timer_5 = (uint16)( (end - start) / 45);
|
|
|
|
// }
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::checkTimerCallback()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
if (_invoke_timer_callback && !_in_callback) {
|
|
|
|
_in_callback = true;
|
|
|
|
_invoke_timer_callback = 0;
|
|
|
|
timer_callback();
|
|
|
|
_in_callback = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-08-04 13:25:06 +00:00
|
|
|
void SimonState::fcs_setTextColor(FillOrCopyStruct *fcs, uint value)
|
2002-07-07 19:06:48 +00:00
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
fcs->text_color = value;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::o_vga_reset()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
_lock_word |= 0x4000;
|
|
|
|
vc_27_reset();
|
|
|
|
_lock_word &= ~0x4000;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
bool SimonState::vc_maybe_skip_proc_3(uint16 a)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
Item *item;
|
|
|
|
|
|
|
|
CHECK_BOUNDS(a, _vc_item_array);
|
|
|
|
|
|
|
|
item = _vc_item_array[a];
|
|
|
|
if (item == NULL)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return getItem1Ptr()->parent == item->parent;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
bool SimonState::vc_maybe_skip_proc_2(uint16 a, uint16 b)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
Item *item_a, *item_b;
|
|
|
|
|
|
|
|
CHECK_BOUNDS(a, _vc_item_array);
|
|
|
|
CHECK_BOUNDS(b, _vc_item_array);
|
|
|
|
|
|
|
|
item_a = _vc_item_array[a];
|
|
|
|
item_b = _vc_item_array[b];
|
|
|
|
|
|
|
|
if (item_a == NULL || item_b == NULL)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return derefItem(item_a->parent) == item_b;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
bool SimonState::vc_maybe_skip_proc_1(uint16 a, int16 b)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
Item *item;
|
|
|
|
|
|
|
|
CHECK_BOUNDS(a, _vc_item_array);
|
|
|
|
|
|
|
|
item = _vc_item_array[a];
|
|
|
|
if (item == NULL)
|
|
|
|
return true;
|
|
|
|
return item->unk3 == b;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* OK */
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::fcs_delete(uint a)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
if (_fcs_ptr_array_3[a] == NULL)
|
|
|
|
return;
|
|
|
|
fcs_unk1(a);
|
|
|
|
video_copy_if_flag_0x8_c(_fcs_ptr_array_3[a]);
|
|
|
|
_fcs_ptr_array_3[a] = NULL;
|
|
|
|
if (_fcs_unk_1 == a) {
|
|
|
|
_fcs_ptr_1 = NULL;
|
|
|
|
fcs_unk_2(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* OK */
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::fcs_unk_2(uint a)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
a &= 7;
|
|
|
|
|
|
|
|
if (_fcs_ptr_array_3[a] == NULL || _fcs_unk_1 == a)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_fcs_unk_1 = a;
|
|
|
|
startUp_helper_3();
|
|
|
|
_fcs_ptr_1 = _fcs_ptr_array_3[a];
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-08-04 13:25:06 +00:00
|
|
|
showmessage_helper_3(_fcs_ptr_1->textLength, _fcs_ptr_1->textMaxLength);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* OK */
|
2002-07-07 19:06:48 +00:00
|
|
|
FillOrCopyStruct *SimonState::fcs_alloc(uint x, uint y, uint w, uint h, uint flags, uint fill_color,
|
|
|
|
uint unk4)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
FillOrCopyStruct *fcs;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
fcs = _fcs_list;
|
2002-07-07 19:06:48 +00:00
|
|
|
while (fcs->mode != 0)
|
|
|
|
fcs++;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
fcs->mode = 2;
|
|
|
|
fcs->x = x;
|
|
|
|
fcs->y = y;
|
|
|
|
fcs->width = w;
|
|
|
|
fcs->height = h;
|
|
|
|
fcs->flags = flags;
|
|
|
|
fcs->fill_color = fill_color;
|
|
|
|
fcs->text_color = unk4;
|
2002-08-04 13:25:06 +00:00
|
|
|
fcs->textColumn = 0;
|
|
|
|
fcs->textRow = 0;
|
|
|
|
fcs->textColumnOffset = 0;
|
|
|
|
fcs->textMaxLength = fcs->width * 8 / 6; // characters are 6 pixels
|
2002-04-12 21:26:59 +00:00
|
|
|
return fcs;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
Item *SimonState::derefItem(uint item)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
if (item >= _itemarray_size)
|
|
|
|
error("derefItem: invalid item %d", item);
|
|
|
|
return _itemarray_ptr[item];
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
uint SimonState::itemPtrToID(Item *id)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
uint i;
|
2002-07-07 19:06:48 +00:00
|
|
|
for (i = 0; i != _itemarray_size; i++)
|
2002-04-12 21:26:59 +00:00
|
|
|
if (_itemarray_ptr[i] == id)
|
|
|
|
return i;
|
|
|
|
error("itemPtrToID: not found");
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::o_pathfind(int x, int y, uint var_1, uint var_2)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
uint16 *p;
|
|
|
|
uint i, j;
|
|
|
|
uint prev_i;
|
|
|
|
uint x_diff, y_diff;
|
2002-07-07 19:06:48 +00:00
|
|
|
uint best_i = 0, best_j = 0, best_dist = 0xFFFFFFFF;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-04-16 12:07:19 +00:00
|
|
|
if (_game & GAME_SIMON2) {
|
|
|
|
x += _x_scroll * 8;
|
|
|
|
}
|
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
prev_i = 21 - _variableArray[12];
|
2002-07-07 19:06:48 +00:00
|
|
|
for (i = 20; i != 0; --i) {
|
|
|
|
p = (uint16 *)_pathfind_array[20 - i];
|
2002-04-12 21:26:59 +00:00
|
|
|
if (!p)
|
|
|
|
continue;
|
2002-07-07 19:06:48 +00:00
|
|
|
for (j = 0; READ_BE_UINT16_UNALIGNED(&p[0]) != 999; j++, p += 2) { /* 0xE703 = byteswapped 999 */
|
|
|
|
x_diff = abs((int)(READ_BE_UINT16_UNALIGNED(&p[0]) - x));
|
|
|
|
y_diff = abs((int)(READ_BE_UINT16_UNALIGNED(&p[1]) - 12 - y));
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
if (x_diff < y_diff) {
|
|
|
|
x_diff >>= 2;
|
|
|
|
y_diff <<= 2;
|
|
|
|
}
|
|
|
|
x_diff += y_diff >> 2;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (x_diff < best_dist || x_diff == best_dist && prev_i == i) {
|
2002-04-12 21:26:59 +00:00
|
|
|
best_dist = x_diff;
|
|
|
|
best_i = 21 - i;
|
|
|
|
best_j = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
_variableArray[var_1] = best_i;
|
|
|
|
_variableArray[var_2] = best_j;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ok */
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::fcs_unk1(uint fcs_index)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
FillOrCopyStruct *fcs;
|
|
|
|
uint16 fcsunk1;
|
|
|
|
uint16 i;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
fcs = _fcs_ptr_array_3[fcs_index & 7];
|
2002-04-12 21:26:59 +00:00
|
|
|
fcsunk1 = _fcs_unk_1;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
if (fcs == NULL || fcs->fcs_data == NULL)
|
2002-04-12 21:26:59 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
fcs_unk_2(fcs_index);
|
|
|
|
fcs_putchar(12);
|
|
|
|
fcs_unk_2(fcsunk1);
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
for (i = 0; fcs->fcs_data->e[i].item != NULL; i++) {
|
2002-04-12 21:26:59 +00:00
|
|
|
delete_hitarea_by_index(fcs->fcs_data->e[i].hit_area);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fcs->fcs_data->unk3 != -1) {
|
|
|
|
delete_hitarea_by_index(fcs->fcs_data->unk3);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fcs->fcs_data->unk4 != -1) {
|
|
|
|
delete_hitarea_by_index(fcs->fcs_data->unk4);
|
|
|
|
fcs_unk_5(fcs, fcs_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(fcs->fcs_data);
|
|
|
|
fcs->fcs_data = NULL;
|
|
|
|
|
|
|
|
_fcs_data_1[fcs_index] = 0;
|
|
|
|
_fcs_data_2[fcs_index] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ok */
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::fcs_unk_5(FillOrCopyStruct *fcs, uint fcs_index)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
if (!(_game & GAME_SIMON2)) {
|
|
|
|
o_unk_99_simon1(0x80);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::delete_hitarea_by_index(uint index)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
CHECK_BOUNDS(index, _hit_areas);
|
|
|
|
_hit_areas[index].flags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ok */
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::fcs_putchar(uint a)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
if (_fcs_ptr_1 != _fcs_ptr_array_3[0])
|
|
|
|
video_putchar(_fcs_ptr_1, a);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ok */
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::video_fill_or_copy_from_3_to_2(FillOrCopyStruct *fcs)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
if (fcs->flags & 0x10)
|
|
|
|
copy_img_from_3_to_2(fcs);
|
|
|
|
else
|
|
|
|
video_erase(fcs);
|
|
|
|
|
2002-08-04 13:25:06 +00:00
|
|
|
fcs->textColumn = 0;
|
|
|
|
fcs->textRow = 0;
|
|
|
|
fcs->textColumnOffset = 0;
|
|
|
|
fcs->textLength = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ok */
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::copy_img_from_3_to_2(FillOrCopyStruct *fcs)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
_lock_word |= 0x8000;
|
|
|
|
|
|
|
|
if (!(_game & GAME_SIMON2)) {
|
2002-07-07 19:06:48 +00:00
|
|
|
dx_copy_rgn_from_3_to_2(fcs->y + fcs->height * 8 + ((fcs == _fcs_ptr_array_3[2]) ? 1 : 0),
|
|
|
|
(fcs->x + fcs->width) * 8, fcs->y, fcs->x * 8);
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_vga_var6 && _fcs_ptr_array_3[2] == fcs) {
|
|
|
|
fcs = _fcs_ptr_array_3[0x18 / 4];
|
2002-04-12 21:26:59 +00:00
|
|
|
_vga_var6 = 0;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
dx_copy_rgn_from_3_to_2(fcs->y + fcs->height * 8,
|
|
|
|
(fcs->x + fcs->width) * 8, fcs->y, fcs->x * 8);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_lock_word &= ~0x8000;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::video_erase(FillOrCopyStruct *fcs)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
byte *dst;
|
|
|
|
uint h;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
_lock_word |= 0x8000;
|
|
|
|
|
|
|
|
dst = dx_lock_2();
|
2002-07-07 19:06:48 +00:00
|
|
|
dst += _dx_surface_pitch * fcs->y + fcs->x * 8;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
h = fcs->height * 8;
|
|
|
|
do {
|
2002-07-07 19:06:48 +00:00
|
|
|
memset(dst, fcs->fill_color, fcs->width * 8);
|
2002-04-12 21:26:59 +00:00
|
|
|
dst += _dx_surface_pitch;
|
|
|
|
} while (--h);
|
|
|
|
|
|
|
|
dx_unlock_2();
|
|
|
|
_lock_word &= ~0x8000;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
VgaSprite *SimonState::find_cur_sprite()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
if (_game & GAME_SIMON2) {
|
|
|
|
VgaSprite *vsp = _vga_sprites;
|
|
|
|
while (vsp->id) {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (vsp->id == _vga_cur_sprite_id && vsp->unk7 == _vga_cur_file_id)
|
2002-04-12 21:26:59 +00:00
|
|
|
break;
|
|
|
|
vsp++;
|
|
|
|
}
|
|
|
|
return vsp;
|
|
|
|
} else {
|
|
|
|
VgaSprite *vsp = _vga_sprites;
|
|
|
|
while (vsp->id) {
|
|
|
|
if (vsp->id == _vga_cur_sprite_id)
|
|
|
|
break;
|
|
|
|
vsp++;
|
|
|
|
}
|
|
|
|
return vsp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
bool SimonState::has_vgastruct_with_id(uint16 id, uint16 file)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
if (_game & GAME_SIMON2) {
|
|
|
|
VgaSprite *vsp = _vga_sprites;
|
|
|
|
while (vsp->id) {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (vsp->id == id && vsp->unk7 == file)
|
2002-04-12 21:26:59 +00:00
|
|
|
return true;
|
|
|
|
vsp++;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
VgaSprite *vsp = _vga_sprites;
|
|
|
|
while (vsp->id) {
|
|
|
|
if (vsp->id == id)
|
|
|
|
return true;
|
|
|
|
vsp++;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::processSpecialKeys()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::draw_mouse_pointer()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void decompress_icon(byte *dst, byte *src, uint w, uint h_org, byte base, uint pitch)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
int8 reps;
|
|
|
|
byte color_1, color_2;
|
|
|
|
byte *dst_org = dst;
|
|
|
|
uint h = h_org;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
for (;;) {
|
2002-04-12 21:26:59 +00:00
|
|
|
reps = *src++;
|
|
|
|
if (reps < 0) {
|
|
|
|
reps--;
|
|
|
|
color_1 = *src >> 4;
|
2002-07-07 19:06:48 +00:00
|
|
|
if (color_1 != 0)
|
|
|
|
color_1 |= base;
|
2002-04-12 21:26:59 +00:00
|
|
|
color_2 = *src++ & 0xF;
|
2002-07-07 19:06:48 +00:00
|
|
|
if (color_2 != 0)
|
|
|
|
color_2 |= base;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (color_1 != 0)
|
|
|
|
*dst = color_1;
|
2002-04-12 21:26:59 +00:00
|
|
|
dst += pitch;
|
2002-07-07 19:06:48 +00:00
|
|
|
if (color_2 != 0)
|
|
|
|
*dst = color_2;
|
2002-04-12 21:26:59 +00:00
|
|
|
dst += pitch;
|
|
|
|
|
|
|
|
/* reached bottom? */
|
|
|
|
if (--h == 0) {
|
2002-07-07 19:06:48 +00:00
|
|
|
/* reached right edge? */
|
2002-04-12 21:26:59 +00:00
|
|
|
if (--w == 0)
|
|
|
|
return;
|
|
|
|
dst = ++dst_org;
|
|
|
|
h = h_org;
|
|
|
|
}
|
|
|
|
} while (++reps != 0);
|
|
|
|
} else {
|
2002-07-07 19:06:48 +00:00
|
|
|
do {
|
2002-04-12 21:26:59 +00:00
|
|
|
color_1 = *src >> 4;
|
2002-07-07 19:06:48 +00:00
|
|
|
if (color_1 != 0)
|
|
|
|
*dst = color_1 | base;
|
2002-04-12 21:26:59 +00:00
|
|
|
dst += pitch;
|
|
|
|
|
|
|
|
color_2 = *src++ & 0xF;
|
2002-07-07 19:06:48 +00:00
|
|
|
if (color_2 != 0)
|
|
|
|
*dst = color_2 | base;
|
2002-04-12 21:26:59 +00:00
|
|
|
dst += pitch;
|
|
|
|
|
|
|
|
/* reached bottom? */
|
|
|
|
if (--h == 0) {
|
2002-07-07 19:06:48 +00:00
|
|
|
/* reached right edge? */
|
2002-04-12 21:26:59 +00:00
|
|
|
if (--w == 0)
|
|
|
|
return;
|
|
|
|
dst = ++dst_org;
|
|
|
|
h = h_org;
|
|
|
|
}
|
|
|
|
} while (--reps >= 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::draw_icon_c(FillOrCopyStruct *fcs, uint icon, uint x, uint y)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
byte *dst;
|
|
|
|
byte *src;
|
|
|
|
|
|
|
|
if (!(_game & GAME_SIMON2)) {
|
|
|
|
_lock_word |= 0x8000;
|
|
|
|
|
|
|
|
dst = dx_lock_2();
|
|
|
|
dst += (x + fcs->x) * 8;
|
2002-07-07 19:06:48 +00:00
|
|
|
dst += (y * 25 + fcs->y) * _dx_surface_pitch;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
src = _icon_file_ptr;
|
2002-07-07 19:06:48 +00:00
|
|
|
src += READ_LE_UINT16(&((uint16 *)src)[icon]);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
decompress_icon(dst, src, 24, 12, 0xE0, _dx_surface_pitch);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
dx_unlock_2();
|
|
|
|
_lock_word &= ~0x8000;
|
|
|
|
} else {
|
2002-07-07 19:06:48 +00:00
|
|
|
_lock_word |= 0x8000;
|
2002-04-12 21:26:59 +00:00
|
|
|
dst = dx_lock_2();
|
|
|
|
|
|
|
|
dst += 110;
|
|
|
|
dst += x;
|
2002-07-07 19:06:48 +00:00
|
|
|
dst += (y + fcs->y) * _dx_surface_pitch;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
src = _icon_file_ptr;
|
2002-07-07 19:06:48 +00:00
|
|
|
src += READ_LE_UINT16(&((uint16 *)src)[icon * 2 + 0]);
|
|
|
|
decompress_icon(dst, src, 20, 10, 0xE0, _dx_surface_pitch);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
src = _icon_file_ptr;
|
2002-07-07 19:06:48 +00:00
|
|
|
src += READ_LE_UINT16(&((uint16 *)src)[icon * 2 + 1]);
|
|
|
|
decompress_icon(dst, src, 20, 10, 0xD0, _dx_surface_pitch);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
dx_unlock_2();
|
|
|
|
_lock_word &= ~0x8000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::video_toggle_colors(HitArea * ha, byte a, byte b, byte c, byte d)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
byte *src, color;
|
2002-07-07 19:06:48 +00:00
|
|
|
uint w, h, i;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
_lock_word |= 0x8000;
|
2002-07-07 19:06:48 +00:00
|
|
|
src = dx_lock_2() + ha->y * _dx_surface_pitch + ha->x;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
w = ha->width;
|
|
|
|
h = ha->height;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (!(h > 0 && w > 0 && ha->x + w <= 320 && ha->y + h <= 200)) {
|
|
|
|
warning("Invalid coordinates in video_toggle_colors (%d,%d,%d,%d)", ha->x, ha->y, ha->width,
|
|
|
|
ha->height);
|
2002-08-20 09:58:35 +00:00
|
|
|
_lock_word &= ~0x8000;
|
2002-04-12 21:26:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
2002-07-07 19:06:48 +00:00
|
|
|
for (i = 0; i != w; ++i) {
|
2002-04-12 21:26:59 +00:00
|
|
|
color = src[i];
|
2002-07-07 19:06:48 +00:00
|
|
|
if (a >= color && b < color) {
|
2002-04-12 21:26:59 +00:00
|
|
|
if (c >= color)
|
|
|
|
color += d;
|
|
|
|
else
|
|
|
|
color -= d;
|
|
|
|
src[i] = color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
src += _dx_surface_pitch;
|
2002-07-07 19:06:48 +00:00
|
|
|
} while (--h);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
dx_unlock_2();
|
|
|
|
_lock_word &= ~0x8000;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
bool SimonState::vc_59_helper()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
#ifdef USE_TEXT_HACK
|
|
|
|
return true;
|
|
|
|
#else
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_voice_file == NULL)
|
2002-04-12 21:26:59 +00:00
|
|
|
return false;
|
2002-04-14 18:13:08 +00:00
|
|
|
return _voice_sound == 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::video_copy_if_flag_0x8_c(FillOrCopyStruct *fcs)
|
|
|
|
{
|
|
|
|
if (fcs->flags & 8)
|
2002-04-12 21:26:59 +00:00
|
|
|
copy_img_from_3_to_2(fcs);
|
|
|
|
fcs->mode = 0;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::showMessageFormat(const char *s, ...)
|
|
|
|
{
|
|
|
|
char buf[1024], *str;
|
2002-04-12 21:26:59 +00:00
|
|
|
va_list va;
|
|
|
|
|
|
|
|
va_start(va, s);
|
|
|
|
vsprintf(buf, s, va);
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
if (!_fcs_data_1[_fcs_unk_1]) {
|
|
|
|
showmessage_helper_2();
|
|
|
|
if (!_showmessage_flag) {
|
|
|
|
_fcs_ptr_array_3[0] = _fcs_ptr_1;
|
2002-08-04 13:25:06 +00:00
|
|
|
showmessage_helper_3(_fcs_ptr_1->textLength,
|
|
|
|
_fcs_ptr_1->textMaxLength);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
_showmessage_flag = true;
|
|
|
|
_fcs_data_1[_fcs_unk_1] = 1;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
for (str = buf; *str; str++)
|
2002-04-12 21:26:59 +00:00
|
|
|
showmessage_print_char(*str);
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::showmessage_helper_2()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
if (_fcs_ptr_1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_fcs_ptr_1 = fcs_alloc(8, 0x90, 0x18, 6, 1, 0, 0xF);
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::readSfxFile(const char *filename)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
if (!(_game & GAME_SIMON2)) {
|
|
|
|
FILE *in;
|
|
|
|
uint32 size;
|
|
|
|
|
2002-04-13 11:44:56 +00:00
|
|
|
in = fopen_maybe_lowercase(filename);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (in == NULL) {
|
2002-04-12 21:26:59 +00:00
|
|
|
warning("readSfxFile: Cannot load sfx file %s", filename);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fseek(in, 0, SEEK_END);
|
|
|
|
size = ftell(in);
|
|
|
|
|
2002-04-19 06:23:49 +00:00
|
|
|
fseek(in, 0, SEEK_SET);
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-14 18:13:08 +00:00
|
|
|
/* stop all sounds */
|
2002-08-24 15:31:37 +00:00
|
|
|
_mixer->stopAll();
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_sfx_heap)
|
|
|
|
free(_sfx_heap);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
_sfx_heap = (byte *)malloc(size);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
if (_sfx_heap == NULL)
|
|
|
|
error("readSfxFile: Not enough SFX memory");
|
|
|
|
|
|
|
|
fread(_sfx_heap, size, 1, in);
|
|
|
|
|
|
|
|
fclose(in);
|
|
|
|
} else {
|
|
|
|
int res;
|
|
|
|
uint32 offs;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
vc_29_stop_all_sounds();
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_sfx_heap)
|
|
|
|
free(_sfx_heap);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
res = atoi(filename + 6) + gss->SOUND_INDEX_BASE - 1;
|
|
|
|
offs = _game_offsets_ptr[res];
|
2002-07-07 19:06:48 +00:00
|
|
|
size = _game_offsets_ptr[res + 1] - offs;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
if (size == 0)
|
|
|
|
return;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
_sfx_heap = (byte *)malloc(size);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
resfile_read(_sfx_heap, offs, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::video_putchar(FillOrCopyStruct *fcs, byte c)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
if (c == 0xC) {
|
|
|
|
video_fill_or_copy_from_3_to_2(fcs);
|
2002-07-07 19:06:48 +00:00
|
|
|
} else if (c == 0xD || c == 0xA) {
|
2002-08-04 13:25:06 +00:00
|
|
|
video_putchar_newline(fcs);
|
2002-07-07 19:06:48 +00:00
|
|
|
} else if (c == 8 || c == 1) {
|
|
|
|
int8 val = (c == 8) ? 6 : 4;
|
2002-08-04 13:25:06 +00:00
|
|
|
if (fcs->textLength != 0) {
|
|
|
|
fcs->textLength--;
|
|
|
|
fcs->textColumnOffset -= val;
|
|
|
|
if ((int8)fcs->textColumnOffset < val) {
|
|
|
|
fcs->textColumnOffset += 8;
|
|
|
|
fcs->textColumn--;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
} else if (c >= 0x20) {
|
2002-08-04 13:25:06 +00:00
|
|
|
if (fcs->textLength == fcs->textMaxLength) {
|
|
|
|
video_putchar_newline(fcs);
|
|
|
|
} else if (fcs->textRow == fcs->height) {
|
|
|
|
video_putchar_newline(fcs);
|
|
|
|
fcs->textRow--;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-08-04 13:25:06 +00:00
|
|
|
video_putchar_drawchar(fcs, fcs->textColumn + fcs->x,
|
|
|
|
fcs->textRow * 8 + fcs->y, c);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-08-04 13:25:06 +00:00
|
|
|
fcs->textLength++;
|
|
|
|
fcs->textColumnOffset += 6;
|
2002-08-03 22:49:28 +00:00
|
|
|
if (c == 'i' || c == 'l')
|
2002-08-04 13:25:06 +00:00
|
|
|
fcs->textColumnOffset -= 2;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-08-04 13:25:06 +00:00
|
|
|
if (fcs->textColumnOffset >= 8) {
|
|
|
|
fcs->textColumnOffset -= 8;
|
|
|
|
fcs->textColumn++;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-04 13:25:06 +00:00
|
|
|
void SimonState::video_putchar_newline(FillOrCopyStruct *fcs)
|
2002-07-07 19:06:48 +00:00
|
|
|
{
|
2002-08-04 13:25:06 +00:00
|
|
|
fcs->textColumnOffset = 0;
|
|
|
|
fcs->textLength = 0;
|
|
|
|
fcs->textColumn = 0;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-08-04 13:25:06 +00:00
|
|
|
if (fcs->textRow != fcs->height)
|
|
|
|
fcs->textRow++;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const byte video_font[] = {
|
2002-07-07 19:06:48 +00:00
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
32, 112, 112, 32, 32, 0, 32, 0,
|
|
|
|
48, 48, 96, 0, 0, 0, 0, 0,
|
|
|
|
0, 144, 0, 96, 144, 144, 104, 0,
|
|
|
|
0, 144, 0, 96, 144, 144, 96, 0,
|
|
|
|
0, 144, 0, 144, 144, 144, 96, 0,
|
|
|
|
0, 16, 40, 16, 42, 68, 58, 0,
|
|
|
|
48, 48, 96, 0, 0, 0, 0, 0,
|
|
|
|
0, 4, 8, 8, 8, 8, 4, 0,
|
|
|
|
0, 32, 16, 16, 16, 16, 32, 0,
|
|
|
|
0, 0, 20, 8, 62, 8, 20, 0,
|
|
|
|
0, 112, 136, 240, 136, 136, 240, 0,
|
|
|
|
0, 0, 0, 0, 0, 48, 48, 96,
|
|
|
|
0, 0, 0, 240, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 48, 48, 0,
|
|
|
|
16, 32, 0, 120, 112, 64, 56, 0,
|
|
|
|
112, 136, 152, 168, 200, 136, 112, 0,
|
|
|
|
32, 96, 32, 32, 32, 32, 112, 0,
|
|
|
|
112, 136, 8, 48, 64, 136, 248, 0,
|
|
|
|
112, 136, 8, 48, 8, 136, 112, 0,
|
|
|
|
16, 48, 80, 144, 248, 16, 56, 0,
|
|
|
|
248, 128, 240, 8, 8, 136, 112, 0,
|
|
|
|
48, 64, 128, 240, 136, 136, 112, 0,
|
|
|
|
248, 136, 8, 16, 32, 32, 32, 0,
|
|
|
|
112, 136, 136, 112, 136, 136, 112, 0,
|
|
|
|
112, 136, 136, 120, 8, 16, 96, 0,
|
|
|
|
0, 0, 48, 48, 0, 48, 48, 0,
|
|
|
|
32, 16, 0, 112, 8, 248, 120, 0,
|
|
|
|
32, 80, 0, 144, 144, 144, 104, 0,
|
|
|
|
32, 16, 0, 112, 248, 128, 112, 0,
|
|
|
|
32, 80, 0, 112, 248, 128, 112, 0,
|
|
|
|
112, 136, 8, 16, 32, 0, 32, 0,
|
|
|
|
32, 80, 0, 192, 64, 64, 224, 0,
|
|
|
|
112, 136, 136, 248, 136, 136, 136, 0,
|
|
|
|
240, 72, 72, 112, 72, 72, 240, 0,
|
|
|
|
48, 72, 128, 128, 128, 72, 48, 0,
|
|
|
|
224, 80, 72, 72, 72, 80, 224, 0,
|
|
|
|
248, 72, 64, 112, 64, 72, 248, 0,
|
|
|
|
248, 72, 64, 112, 64, 64, 224, 0,
|
|
|
|
48, 72, 128, 152, 136, 72, 56, 0,
|
|
|
|
136, 136, 136, 248, 136, 136, 136, 0,
|
|
|
|
248, 32, 32, 32, 32, 32, 248, 0,
|
|
|
|
24, 8, 8, 8, 136, 136, 112, 0,
|
|
|
|
200, 72, 80, 96, 80, 72, 200, 0,
|
|
|
|
224, 64, 64, 64, 64, 72, 248, 0,
|
|
|
|
136, 216, 168, 168, 136, 136, 136, 0,
|
|
|
|
136, 200, 168, 152, 136, 136, 136, 0,
|
|
|
|
112, 136, 136, 136, 136, 136, 112, 0,
|
|
|
|
240, 72, 72, 112, 64, 64, 224, 0,
|
|
|
|
112, 136, 136, 136, 136, 168, 112, 8,
|
|
|
|
240, 72, 72, 112, 72, 72, 200, 0,
|
|
|
|
112, 136, 128, 112, 8, 136, 112, 0,
|
|
|
|
248, 168, 32, 32, 32, 32, 112, 0,
|
|
|
|
136, 136, 136, 136, 136, 136, 120, 0,
|
|
|
|
136, 136, 136, 80, 80, 32, 32, 0,
|
|
|
|
136, 136, 136, 136, 168, 216, 136, 0,
|
|
|
|
136, 136, 80, 32, 80, 136, 136, 0,
|
|
|
|
136, 136, 136, 112, 32, 32, 112, 0,
|
|
|
|
248, 136, 16, 32, 64, 136, 248, 0,
|
|
|
|
0, 14, 8, 8, 8, 8, 14, 0,
|
|
|
|
0, 128, 64, 32, 16, 8, 4, 0,
|
|
|
|
0, 112, 16, 16, 16, 16, 112, 0,
|
|
|
|
0, 48, 72, 64, 72, 48, 16, 48,
|
|
|
|
0, 80, 0, 96, 32, 40, 48, 0,
|
|
|
|
32, 16, 0, 152, 144, 144, 232, 0,
|
|
|
|
0, 0, 112, 8, 120, 136, 120, 0,
|
|
|
|
192, 64, 80, 104, 72, 72, 112, 0,
|
|
|
|
0, 0, 112, 136, 128, 136, 112, 0,
|
|
|
|
24, 16, 80, 176, 144, 144, 112, 0,
|
|
|
|
0, 0, 112, 136, 248, 128, 112, 0,
|
|
|
|
48, 72, 64, 224, 64, 64, 224, 0,
|
|
|
|
0, 0, 104, 144, 144, 112, 136, 112,
|
|
|
|
192, 64, 80, 104, 72, 72, 200, 0,
|
|
|
|
64, 0, 192, 64, 64, 64, 224, 0,
|
|
|
|
8, 0, 8, 8, 8, 8, 136, 112,
|
|
|
|
192, 64, 72, 80, 96, 80, 200, 0,
|
|
|
|
192, 64, 64, 64, 64, 64, 224, 0,
|
|
|
|
0, 0, 144, 216, 168, 136, 136, 0,
|
|
|
|
0, 0, 240, 136, 136, 136, 136, 0,
|
|
|
|
0, 0, 112, 136, 136, 136, 112, 0,
|
|
|
|
0, 0, 176, 72, 72, 112, 64, 224,
|
|
|
|
0, 0, 104, 144, 144, 112, 16, 56,
|
|
|
|
0, 0, 176, 72, 72, 64, 224, 0,
|
|
|
|
0, 0, 120, 128, 112, 8, 240, 0,
|
|
|
|
64, 64, 240, 64, 64, 72, 48, 0,
|
|
|
|
0, 0, 144, 144, 144, 144, 104, 0,
|
|
|
|
0, 0, 136, 136, 136, 80, 32, 0,
|
|
|
|
0, 0, 136, 136, 168, 216, 144, 0,
|
|
|
|
0, 0, 136, 80, 32, 80, 136, 0,
|
|
|
|
0, 0, 136, 136, 136, 112, 32, 192,
|
|
|
|
0, 0, 248, 144, 32, 72, 248, 0,
|
|
|
|
32, 80, 0, 96, 144, 144, 96, 0,
|
|
|
|
0, 14, 8, 48, 8, 8, 14, 0,
|
|
|
|
0, 8, 8, 8, 8, 8, 8, 0,
|
|
|
|
0, 112, 16, 12, 16, 16, 112, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 248, 0,
|
|
|
|
252, 252, 252, 252, 252, 252, 252, 252,
|
|
|
|
240, 240, 240, 240, 240, 240, 240, 240,
|
2002-04-12 21:26:59 +00:00
|
|
|
};
|
|
|
|
|
2002-08-04 13:25:06 +00:00
|
|
|
void SimonState::video_putchar_drawchar(FillOrCopyStruct *fcs, uint x, uint y, byte chr)
|
2002-07-07 19:06:48 +00:00
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
const byte *src;
|
|
|
|
byte color, *dst;
|
2002-07-07 19:06:48 +00:00
|
|
|
uint h, i;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
_lock_word |= 0x8000;
|
|
|
|
|
|
|
|
dst = dx_lock_2();
|
2002-08-04 13:25:06 +00:00
|
|
|
dst += y * _dx_surface_pitch + x * 8 + fcs->textColumnOffset;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
src = video_font + (chr - 0x20) * 8;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
color = fcs->text_color;
|
|
|
|
|
|
|
|
h = 8;
|
|
|
|
do {
|
|
|
|
int8 b = *src++;
|
|
|
|
i = 0;
|
|
|
|
do {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (b < 0)
|
|
|
|
dst[i] = color;
|
|
|
|
b <<= 1;
|
|
|
|
} while (++i != 6);
|
2002-04-12 21:26:59 +00:00
|
|
|
dst += _dx_surface_pitch;
|
|
|
|
} while (--h);
|
|
|
|
|
|
|
|
dx_unlock_2();
|
2002-04-16 12:07:19 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
_lock_word &= ~0x8000;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::start_vga_code(uint b, uint vga_res, uint vga_struct_id, uint c, uint d, uint f)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
VgaSprite *vsp;
|
|
|
|
VgaPointersEntry *vpe;
|
2002-07-07 19:06:48 +00:00
|
|
|
byte *p, *pp;
|
2002-04-12 21:26:59 +00:00
|
|
|
uint count;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
_lock_word |= 0x40;
|
|
|
|
|
2002-08-11 09:05:30 +00:00
|
|
|
if (has_vgastruct_with_id(vga_struct_id, vga_res)) {
|
|
|
|
_lock_word &= ~0x40;
|
2002-04-12 21:26:59 +00:00
|
|
|
return;
|
2002-08-11 09:05:30 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
vsp = _vga_sprites;
|
2002-07-07 19:06:48 +00:00
|
|
|
while (vsp->id != 0)
|
|
|
|
vsp++;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
vsp->unk6 = b;
|
|
|
|
vsp->unk5 = 0;
|
|
|
|
vsp->unk4 = 0;
|
|
|
|
|
|
|
|
vsp->y = d;
|
|
|
|
vsp->x = c;
|
|
|
|
vsp->image = 0;
|
|
|
|
vsp->base_color = f;
|
|
|
|
vsp->id = vga_struct_id;
|
|
|
|
vsp->unk7 = vga_res;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
for (;;) {
|
2002-04-12 21:26:59 +00:00
|
|
|
vpe = &_vga_buffer_pointers[vga_res];
|
|
|
|
_vga_cur_file_2 = vga_res;
|
|
|
|
_cur_vga_file_1 = vpe->vgaFile1;
|
|
|
|
if (vpe->vgaFile1 != NULL)
|
|
|
|
break;
|
|
|
|
ensureVgaResLoaded(vga_res);
|
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
pp = _cur_vga_file_1;
|
2002-07-07 19:06:48 +00:00
|
|
|
p = pp + READ_BE_UINT16_UNALIGNED(&((VgaFile1Header *) pp)->hdr2_start);
|
|
|
|
|
|
|
|
count = READ_BE_UINT16_UNALIGNED(&((VgaFile1Header2 *) p)->id_count);
|
|
|
|
p = pp + READ_BE_UINT16_UNALIGNED(&((VgaFile1Header2 *) p)->id_table);
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if (READ_BE_UINT16_UNALIGNED(&((VgaFile1Struct0x6 *) p)->id) == vga_struct_id) {
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
//dump_vga_script(pp + READ_BE_UINT16_UNALIGNED(&((VgaFile1Struct0x6*)p)->script_offs), vga_res, vga_struct_id);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
add_vga_timer(gss->VGA_DELAY_BASE,
|
|
|
|
pp + READ_BE_UINT16_UNALIGNED(&((VgaFile1Struct0x6 *) p)->script_offs),
|
|
|
|
vga_struct_id, vga_res);
|
2002-04-12 21:26:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
p += sizeof(VgaFile1Struct0x6);
|
|
|
|
if (!--count) {
|
|
|
|
vsp->id = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_lock_word &= ~0x40;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::talk_with_speech(uint speech_id, uint num_1)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
if (!(_game & GAME_SIMON2)) {
|
|
|
|
if (speech_id == 9999) {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (!(_bit_array[0] & 0x4000) && !(_bit_array[1] & 0x1000)) {
|
|
|
|
_bit_array[0] |= 0x4000;
|
|
|
|
_variableArray[0xc8 / 2] = 0xF;
|
2002-04-12 21:26:59 +00:00
|
|
|
start_vga_code(4, 1, 0x82, 0, 0, 0);
|
|
|
|
o_wait_for_vga(0x82);
|
|
|
|
}
|
|
|
|
_skip_vga_wait = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_1 < 100) {
|
|
|
|
o_unk_99_simon1(num_1 + 201);
|
|
|
|
}
|
|
|
|
|
|
|
|
playVoice(speech_id);
|
|
|
|
|
|
|
|
if (num_1 < 100) {
|
2002-07-07 19:06:48 +00:00
|
|
|
start_vga_code(4, 2, num_1 + 201, 0, 0, 0);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
} else {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (speech_id == 0xFFFF) {
|
2002-04-12 21:26:59 +00:00
|
|
|
if (_vk_t_toggle)
|
|
|
|
return;
|
2002-07-07 19:06:48 +00:00
|
|
|
if (!(_bit_array[0] & 0x4000 || _bit_array[1] & 0x1000)) {
|
2002-04-12 21:26:59 +00:00
|
|
|
_bit_array[0] |= 0x4000;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
start_vga_code(4, 1, 0x1e, 0, 0, 0);
|
|
|
|
o_wait_for_vga(0x82);
|
|
|
|
}
|
|
|
|
_skip_vga_wait = true;
|
|
|
|
} else {
|
|
|
|
if (_vk_t_toggle && _scriptvar_2) {
|
|
|
|
start_vga_code(4, 2, 5, 0, 0, 0);
|
|
|
|
o_wait_for_vga(0xcd);
|
2002-07-07 19:06:48 +00:00
|
|
|
o_unk_99_simon2(2, 5);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
o_unk_99_simon2(2, num_1 + 2);
|
2002-04-12 21:26:59 +00:00
|
|
|
playVoice(speech_id);
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
start_vga_code(4, 2, num_1 + 2, 0, 0, 0);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::talk_with_text(uint num_1, uint num_2, const char *string_ptr, uint threeval_a,
|
|
|
|
int threeval_b, uint width)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
char print_str_buf[0x140];
|
|
|
|
char *char_buf;
|
|
|
|
const char *string_ptr_2, *string_ptr_3;
|
|
|
|
int j;
|
|
|
|
uint letters_per_row, len_div_3, num_of_rows;
|
|
|
|
uint m, n;
|
|
|
|
uint height;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (num_1 >= 100) // FIXME: Simon1 Mine - Fix text for dwarf song
|
2002-06-18 08:38:39 +00:00
|
|
|
num_1 -= 100;
|
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
char_buf = print_str_buf;
|
|
|
|
string_ptr_3 = string_ptr_2 = string_ptr;
|
|
|
|
|
|
|
|
height = 10;
|
|
|
|
j = 0;
|
|
|
|
|
|
|
|
letters_per_row = width / 6;
|
|
|
|
|
|
|
|
len_div_3 = (strlen(string_ptr) + 3) / 3;
|
|
|
|
|
2002-04-14 11:00:33 +00:00
|
|
|
if (!(_game & GAME_SIMON2)) {
|
|
|
|
if (_variableArray[141] == 0)
|
|
|
|
_variableArray[141] = 9;
|
|
|
|
_variableArray[85] = _variableArray[141] * len_div_3;
|
|
|
|
} else {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_variableArray[86] == 0)
|
|
|
|
len_div_3 >>= 1;
|
|
|
|
if (_variableArray[86] == 2)
|
|
|
|
len_div_3 <<= 1;
|
2002-04-14 11:00:33 +00:00
|
|
|
_variableArray[85] = len_div_3 * 5;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
num_of_rows = strlen(string_ptr) / letters_per_row;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
while (num_of_rows == 1 && j != -1) {
|
2002-04-12 21:26:59 +00:00
|
|
|
m = strlen(string_ptr) >> 1;
|
|
|
|
m -= j;
|
|
|
|
string_ptr_2 += m;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
while (*string_ptr_2++ != ' ' && m <= letters_per_row)
|
|
|
|
m++;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
if (m <= letters_per_row && strlen(string_ptr_2) < letters_per_row) {
|
|
|
|
/* if_1 */
|
|
|
|
n = (letters_per_row - m + 1) >> 1;
|
|
|
|
|
|
|
|
while (n != 0) {
|
|
|
|
*char_buf++ = ' ';
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
strncpy(char_buf, string_ptr, m);
|
|
|
|
char_buf += m;
|
2002-07-07 19:06:48 +00:00
|
|
|
*char_buf++ = 10;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
height += 10;
|
|
|
|
threeval_b -= 10;
|
|
|
|
j = -1;
|
|
|
|
} else {
|
|
|
|
/* else_1 */
|
|
|
|
j -= 4;
|
|
|
|
if (j == -12) {
|
|
|
|
j = 0;
|
|
|
|
num_of_rows = 2;
|
|
|
|
}
|
|
|
|
string_ptr_2 = string_ptr_3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (j != -1 && width * 30 > 8000)
|
2002-04-12 21:26:59 +00:00
|
|
|
num_of_rows = 4;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
while (num_of_rows == 2 && j != -1) {
|
2002-04-12 21:26:59 +00:00
|
|
|
m = strlen(string_ptr) / 3;
|
|
|
|
m += j;
|
|
|
|
string_ptr_2 += m;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
while (*string_ptr_2++ != ' ' && m <= letters_per_row)
|
|
|
|
m++;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
if (m <= letters_per_row) {
|
|
|
|
/* if_4 */
|
|
|
|
n = (letters_per_row - m + 1) >> 1;
|
|
|
|
while (n) {
|
|
|
|
*char_buf++ = ' ';
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
strncpy(char_buf, string_ptr, m);
|
|
|
|
char_buf += m;
|
2002-07-07 19:06:48 +00:00
|
|
|
*char_buf++ = 10;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
string_ptr = string_ptr_2;
|
|
|
|
string_ptr_2 += m;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
while (*string_ptr_2-- != ' ' && m > 0)
|
|
|
|
m--;
|
2002-04-12 21:26:59 +00:00
|
|
|
/* while_6_end */
|
|
|
|
|
|
|
|
string_ptr_2 += 2;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (strlen(string_ptr_2) <= m && m > 0) {
|
2002-04-12 21:26:59 +00:00
|
|
|
/* if_6 */
|
|
|
|
n = (letters_per_row - m + 1) >> 1;
|
|
|
|
while (n) {
|
|
|
|
*char_buf++ = ' ';
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
strncpy(char_buf, string_ptr, m);
|
|
|
|
char_buf += m;
|
|
|
|
*char_buf++ = 10;
|
|
|
|
height += 20;
|
|
|
|
threeval_b -= 20;
|
|
|
|
j = -1;
|
|
|
|
} else {
|
|
|
|
/* else_6 */
|
|
|
|
j += 2;
|
|
|
|
string_ptr_2 = string_ptr_3;
|
|
|
|
string_ptr = string_ptr_3;
|
|
|
|
char_buf = print_str_buf;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
num_of_rows = 3;
|
|
|
|
string_ptr_2 = string_ptr_3;
|
|
|
|
string_ptr = string_ptr_3;
|
|
|
|
char_buf = print_str_buf;
|
|
|
|
j = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (j != -1 && width * 40 > 8000)
|
2002-04-12 21:26:59 +00:00
|
|
|
num_of_rows = 4;
|
|
|
|
|
|
|
|
/* while_8 */
|
2002-07-07 19:06:48 +00:00
|
|
|
while (num_of_rows == 3 && j != -1) {
|
2002-04-12 21:26:59 +00:00
|
|
|
m = strlen(string_ptr) >> 2;
|
|
|
|
m += j;
|
|
|
|
string_ptr_2 += m;
|
2002-07-07 19:06:48 +00:00
|
|
|
while (*string_ptr_2++ != ' ' && m <= letters_per_row)
|
|
|
|
m++;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
if (m <= letters_per_row) {
|
|
|
|
/* if_10 */
|
|
|
|
n = (letters_per_row - m + 1) >> 1;
|
2002-07-07 19:06:48 +00:00
|
|
|
while (n) {
|
2002-04-12 21:26:59 +00:00
|
|
|
*char_buf++ = ' ';
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
strncpy(char_buf, string_ptr, m);
|
|
|
|
char_buf += m;
|
2002-07-25 20:57:55 +00:00
|
|
|
*char_buf++ = '\n';
|
2002-04-12 21:26:59 +00:00
|
|
|
string_ptr = string_ptr_2;
|
|
|
|
string_ptr_2 += m;
|
2002-07-07 19:06:48 +00:00
|
|
|
while (*string_ptr_2-- != ' ' && m > 0)
|
|
|
|
m--;
|
2002-04-12 21:26:59 +00:00
|
|
|
string_ptr_2 += 2;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (strlen(string_ptr_2) < m * 2 && m > 0) {
|
2002-04-12 21:26:59 +00:00
|
|
|
/* if_11 */
|
|
|
|
n = (letters_per_row - m + 1) >> 1;
|
|
|
|
while (n) {
|
|
|
|
*char_buf++ = ' ';
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
strncpy(char_buf, string_ptr, m);
|
|
|
|
char_buf += m;
|
|
|
|
*char_buf++ = 10;
|
|
|
|
string_ptr = string_ptr_2;
|
|
|
|
string_ptr_2 += m;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
while (*string_ptr_2-- != ' ' && m > 0)
|
|
|
|
m--;
|
2002-04-12 21:26:59 +00:00
|
|
|
string_ptr_2 += 2;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (strlen(string_ptr_2) <= m && m > 0) {
|
2002-04-12 21:26:59 +00:00
|
|
|
/* if_15 */
|
|
|
|
n = (letters_per_row - m + 1) >> 1;
|
|
|
|
while (n) {
|
|
|
|
*char_buf++ = ' ';
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
strncpy(char_buf, string_ptr, m);
|
|
|
|
char_buf += m;
|
2002-07-25 20:57:55 +00:00
|
|
|
*char_buf++ = '\n';
|
2002-04-12 21:26:59 +00:00
|
|
|
height += 30;
|
|
|
|
threeval_b -= 30;
|
|
|
|
j = -1;
|
|
|
|
} else {
|
|
|
|
/* else_15 */
|
|
|
|
j += 2;
|
|
|
|
string_ptr_2 = string_ptr_3;
|
|
|
|
string_ptr = string_ptr_3;
|
|
|
|
char_buf = print_str_buf;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* else_11 */
|
|
|
|
j += 2;
|
|
|
|
string_ptr_2 = string_ptr_3;
|
|
|
|
string_ptr = string_ptr_3;
|
|
|
|
char_buf = print_str_buf;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* else_10 */
|
|
|
|
num_of_rows = 4;
|
|
|
|
string_ptr = string_ptr_3;
|
|
|
|
string_ptr_2 = string_ptr_3;
|
|
|
|
char_buf = print_str_buf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* while_8_end */
|
|
|
|
if (num_of_rows == 4) {
|
|
|
|
while (strlen(string_ptr) > letters_per_row) {
|
|
|
|
m = letters_per_row;
|
|
|
|
string_ptr_2 += m;
|
2002-07-07 19:06:48 +00:00
|
|
|
while (*string_ptr_2-- != ' ')
|
|
|
|
m--;
|
2002-04-12 21:26:59 +00:00
|
|
|
string_ptr_2 += 2;
|
|
|
|
n = (letters_per_row - m + 1) >> 1;
|
|
|
|
while (n) {
|
|
|
|
*char_buf++ = ' ';
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
strncpy(char_buf, string_ptr, m);
|
|
|
|
char_buf += m;
|
|
|
|
*char_buf++ = 10;
|
|
|
|
height += 10;
|
|
|
|
threeval_b -= 10;
|
|
|
|
string_ptr = string_ptr_2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
n = (letters_per_row - strlen(string_ptr_2) + 1) >> 1;
|
2002-07-07 19:06:48 +00:00
|
|
|
while (n) {
|
2002-04-12 21:26:59 +00:00
|
|
|
*char_buf++ = ' ';
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(char_buf, string_ptr_2);
|
|
|
|
if (!(_game & GAME_SIMON2)) {
|
|
|
|
o_unk_99_simon1(199 + num_1);
|
|
|
|
} else {
|
|
|
|
o_unk_99_simon2(2, num_1);
|
|
|
|
}
|
|
|
|
num_2 = num_2 * 3 + 192;
|
|
|
|
|
|
|
|
render_string(num_1, num_2, width, height, print_str_buf);
|
|
|
|
num_of_rows = 4;
|
|
|
|
if (!(_bit_array[8] & 0x20))
|
|
|
|
num_of_rows = 3;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
if (threeval_b < 2)
|
|
|
|
threeval_b = 2; // Fixme (pos): look at mine
|
|
|
|
// ladder, look at gorge, etc
|
2002-06-18 08:38:39 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
if (!(_game & GAME_SIMON2)) {
|
|
|
|
start_vga_code(num_of_rows, 2, 199 + num_1, threeval_a >> 3, threeval_b, 12);
|
|
|
|
} else {
|
|
|
|
start_vga_code(num_of_rows, 2, num_1, threeval_a >> 3, threeval_b, 12);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::render_string(uint num_1, uint color, uint width, uint height, const char *txt)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
VgaPointersEntry *vpe = &_vga_buffer_pointers[2];
|
2002-07-07 19:06:48 +00:00
|
|
|
byte *src, *dst, *p, *dst_org, chr;
|
2002-04-12 21:26:59 +00:00
|
|
|
uint count;
|
|
|
|
|
|
|
|
if (num_1 >= 100) {
|
|
|
|
num_1 -= 100;
|
|
|
|
vpe++;
|
|
|
|
}
|
|
|
|
|
|
|
|
src = dst = vpe->vgaFile2;
|
|
|
|
|
|
|
|
count = 4000;
|
|
|
|
if (num_1 == 1)
|
|
|
|
count *= 2;
|
|
|
|
|
|
|
|
p = dst + num_1 * 8;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
*(uint16 *)(p + 4) = TO_BE_16(height);
|
|
|
|
*(uint16 *)(p + 6) = TO_BE_16(width);
|
2002-04-14 20:22:36 +00:00
|
|
|
dst += READ_BE_UINT32_UNALIGNED(p);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
memset(dst, 0, count);
|
|
|
|
|
|
|
|
dst_org = dst;
|
2002-07-07 19:06:48 +00:00
|
|
|
while ((chr = *txt++) != 0) {
|
2002-04-12 21:26:59 +00:00
|
|
|
if (chr == 10) {
|
|
|
|
dst_org += width * 10;
|
|
|
|
dst = dst_org;
|
|
|
|
} else if ((chr -= ' ') == 0) {
|
|
|
|
dst += 6;
|
|
|
|
} else {
|
|
|
|
byte *img_hdr = src + 48 + chr * 4;
|
|
|
|
uint img_height = img_hdr[2];
|
2002-07-07 19:06:48 +00:00
|
|
|
uint img_width = img_hdr[3], i;
|
2002-04-15 14:37:47 +00:00
|
|
|
byte *img = src + READ_LE_UINT16(img_hdr);
|
2002-04-12 21:26:59 +00:00
|
|
|
byte *cur_dst = dst;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
assert(img_width > 0 && img_width < 50 && img_height > 0 && img_height < 50);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
do {
|
2002-07-07 19:06:48 +00:00
|
|
|
for (i = 0; i != img_width; i++) {
|
2002-04-12 21:26:59 +00:00
|
|
|
chr = *img++;
|
|
|
|
if (chr) {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (chr == 0xF)
|
|
|
|
chr = 207;
|
|
|
|
else
|
|
|
|
chr += color;
|
2002-04-12 21:26:59 +00:00
|
|
|
cur_dst[i] = chr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cur_dst += width;
|
2002-07-07 19:06:48 +00:00
|
|
|
} while (--img_height);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
dst += img_width - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::showmessage_print_char(byte chr)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
if (chr == 12) {
|
|
|
|
_num_letters_to_print = 0;
|
|
|
|
_print_char_unk_1 = 0;
|
|
|
|
print_char_helper_1(&chr, 1);
|
|
|
|
print_char_helper_5(_fcs_ptr_1);
|
2002-07-07 19:06:48 +00:00
|
|
|
} else if (chr == 0 || chr == ' ' || chr == 10) {
|
2002-04-12 21:26:59 +00:00
|
|
|
if (_print_char_unk_2 - _print_char_unk_1 >= _num_letters_to_print) {
|
|
|
|
_print_char_unk_1 += _num_letters_to_print;
|
|
|
|
print_char_helper_1(_letters_to_print_buf, _num_letters_to_print);
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
if (_print_char_unk_1 == _print_char_unk_2) {
|
|
|
|
_print_char_unk_1 = 0;
|
|
|
|
} else {
|
|
|
|
if (chr)
|
|
|
|
print_char_helper_1(&chr, 1);
|
2002-07-07 19:06:48 +00:00
|
|
|
if (chr == 10)
|
2002-04-12 21:26:59 +00:00
|
|
|
_print_char_unk_1 = 0;
|
2002-07-07 19:06:48 +00:00
|
|
|
else if (chr != 0)
|
2002-04-12 21:26:59 +00:00
|
|
|
_print_char_unk_1++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const byte newline_character = 10;
|
|
|
|
_print_char_unk_1 = _num_letters_to_print;
|
|
|
|
print_char_helper_1(&newline_character, 1);
|
|
|
|
print_char_helper_1(_letters_to_print_buf, _num_letters_to_print);
|
|
|
|
if (chr == ' ') {
|
|
|
|
print_char_helper_1(&chr, 1);
|
|
|
|
_print_char_unk_1++;
|
|
|
|
} else {
|
2002-07-07 19:06:48 +00:00
|
|
|
print_char_helper_1(&chr, 1);
|
2002-04-12 21:26:59 +00:00
|
|
|
_print_char_unk_1 = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_num_letters_to_print = 0;
|
|
|
|
} else {
|
|
|
|
_letters_to_print_buf[_num_letters_to_print++] = chr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::print_char_helper_1(const byte *src, uint len)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
uint ind;
|
|
|
|
|
|
|
|
if (_fcs_ptr_1 == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (len-- != 0) {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (*src != 12 && _fcs_ptr_1->fcs_data != NULL &&
|
|
|
|
_fcs_data_1[ind = get_fcs_ptr_3_index(_fcs_ptr_1)] != 2) {
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
_fcs_data_1[ind] = 2;
|
|
|
|
_fcs_data_2[ind] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fcs_putchar(*src++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::print_char_helper_5(FillOrCopyStruct *fcs)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
uint index = get_fcs_ptr_3_index(fcs);
|
|
|
|
print_char_helper_6(index);
|
|
|
|
_fcs_data_1[index] = 0;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::print_char_helper_6(uint i)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
FillOrCopyStruct *fcs;
|
|
|
|
|
|
|
|
if (_fcs_data_2[i]) {
|
|
|
|
lock();
|
|
|
|
fcs = _fcs_ptr_array_3[i];
|
|
|
|
fcs_unk_proc_1(i, fcs->fcs_data->item_ptr, fcs->fcs_data->unk1, fcs->fcs_data->unk2);
|
|
|
|
_fcs_data_2[i] = 0;
|
|
|
|
unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::read_vga_from_datfile_1(uint vga_id)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
if (_game == GAME_SIMON1DOS) {
|
|
|
|
FILE *in;
|
|
|
|
char buf[50];
|
|
|
|
uint32 size;
|
2002-08-24 15:31:37 +00:00
|
|
|
// FIXME - weird hack to make the beard show up when wearing it (see bug #590800)
|
|
|
|
if (vga_id == 328)
|
|
|
|
sprintf(buf, "0119.VGA");
|
|
|
|
else
|
|
|
|
sprintf(buf, "%.3d%d.VGA", vga_id >> 1, (vga_id & 1) + 1);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-04-13 11:44:56 +00:00
|
|
|
in = fopen_maybe_lowercase(buf);
|
2002-07-07 19:06:48 +00:00
|
|
|
if (in == NULL) {
|
2002-05-29 12:30:22 +00:00
|
|
|
warning("read_vga_from_datfile_1: cannot open %s", buf);
|
|
|
|
return;
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
fseek(in, 0, SEEK_END);
|
|
|
|
size = ftell(in);
|
2002-04-19 06:23:49 +00:00
|
|
|
fseek(in, 0, SEEK_SET);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
if (fread(_vga_buffer_pointers[11].vgaFile2, size, 1, in) != 1)
|
|
|
|
error("read_vga_from_datfile_1: read failed");
|
|
|
|
|
|
|
|
fclose(in);
|
|
|
|
} else {
|
|
|
|
uint32 offs_a = _game_offsets_ptr[vga_id];
|
|
|
|
uint32 size = _game_offsets_ptr[vga_id + 1] - offs_a;
|
|
|
|
|
|
|
|
resfile_read(_vga_buffer_pointers[11].vgaFile2, offs_a, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
byte *SimonState::read_vga_from_datfile_2(uint id)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
if (_game == GAME_SIMON1DOS) {
|
|
|
|
FILE *in;
|
|
|
|
char buf[50];
|
|
|
|
uint32 size;
|
|
|
|
byte *dst;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
sprintf(buf, "%.3d%d.VGA", id >> 1, (id & 1) + 1);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-04-13 11:44:56 +00:00
|
|
|
in = fopen_maybe_lowercase(buf);
|
2002-07-07 19:06:48 +00:00
|
|
|
if (in == NULL)
|
2002-04-12 21:26:59 +00:00
|
|
|
error("read_vga_from_datfile_2: cannot open %s", buf);
|
|
|
|
|
|
|
|
fseek(in, 0, SEEK_END);
|
|
|
|
size = ftell(in);
|
2002-04-19 06:23:49 +00:00
|
|
|
fseek(in, 0, SEEK_SET);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
dst = setup_vga_destination(size);
|
|
|
|
|
|
|
|
if (fread(dst, size, 1, in) != 1)
|
|
|
|
error("read_vga_from_datfile_2: read failed");
|
|
|
|
|
|
|
|
fclose(in);
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
} else {
|
|
|
|
uint32 offs_a = _game_offsets_ptr[id];
|
|
|
|
uint32 size = _game_offsets_ptr[id + 1] - offs_a;
|
|
|
|
byte *dst;
|
|
|
|
|
|
|
|
dst = setup_vga_destination(size);
|
|
|
|
resfile_read(dst, offs_a, size);
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::resfile_read(void *dst, uint32 offs, uint32 size)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
if (fseek(_game_file, offs, SEEK_SET) != 0)
|
|
|
|
error("resfile_read(%d,%d) seek failed", offs, size);
|
2002-07-07 19:06:48 +00:00
|
|
|
if (fread(dst, size, 1, _game_file) != 1)
|
2002-04-12 21:26:59 +00:00
|
|
|
error("resfile_read(%d,%d) read failed", offs, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::openGameFile()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
if (_game != GAME_SIMON1DOS) {
|
2002-04-13 11:44:56 +00:00
|
|
|
_game_file = fopen_maybe_lowercase(gss->gme_filename);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_game_file == NULL)
|
2002-04-12 21:26:59 +00:00
|
|
|
error("cannot open game file '%s'", gss->gme_filename);
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
_game_offsets_ptr = (uint32 *)malloc(gss->NUM_GAME_OFFSETS * sizeof(uint32));
|
2002-04-12 21:26:59 +00:00
|
|
|
if (_game_offsets_ptr == NULL)
|
|
|
|
error("out of memory, game offsets");
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
resfile_read(_game_offsets_ptr, 0, gss->NUM_GAME_OFFSETS * sizeof(uint32));
|
2002-04-21 12:51:13 +00:00
|
|
|
#if defined(SCUMM_BIG_ENDIAN)
|
2002-07-07 19:06:48 +00:00
|
|
|
for (int r = 0; r < gss->NUM_GAME_OFFSETS; r++)
|
|
|
|
_game_offsets_ptr[r] = READ_LE_UINT32(&_game_offsets_ptr[r]);
|
2002-04-21 12:51:13 +00:00
|
|
|
#endif
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
loadIconFile();
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
_system->init_size(320, 200);
|
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
startUp(1);
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::startUp(uint a)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
if (a == 1)
|
|
|
|
startUp_helper();
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::startUp_helper()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
runSubroutine101();
|
|
|
|
startUp_helper_2();
|
2002-07-07 19:06:48 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::runSubroutine101()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
Subroutine *sub;
|
|
|
|
|
|
|
|
sub = getSubroutineByID(101);
|
|
|
|
if (sub != NULL)
|
|
|
|
startSubroutineEx(sub);
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
startUp_helper_2();
|
|
|
|
}
|
|
|
|
|
2002-04-14 18:13:08 +00:00
|
|
|
#if 0
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::generateSound(byte *ptr, int len)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
uint cur;
|
|
|
|
|
|
|
|
cur = _voice_size;
|
2002-07-07 19:06:48 +00:00
|
|
|
if (cur > (uint) len)
|
|
|
|
cur = (uint) len;
|
2002-04-12 21:26:59 +00:00
|
|
|
_voice_size -= cur;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (cur != 0) {
|
2002-04-12 21:26:59 +00:00
|
|
|
fread(ptr, cur, 1, _voice_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(ptr + cur, 0x80, len - cur);
|
|
|
|
|
|
|
|
cur = _sound_size;
|
|
|
|
if (cur) {
|
|
|
|
uint i;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (cur > (uint) len)
|
|
|
|
cur = (uint) len;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
for (i = 0; i != cur; i++) {
|
|
|
|
ptr[i] += _sound_ptr[i] ^ 0x80;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
_sound_size -= cur;
|
|
|
|
_sound_ptr += cur;
|
|
|
|
}
|
|
|
|
}
|
2002-04-14 18:13:08 +00:00
|
|
|
#endif
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-04-14 18:13:08 +00:00
|
|
|
//static void fill_sound(void *userdata, int16 *stream, int len) {
|
2002-07-07 19:06:48 +00:00
|
|
|
// ((SimonState*)userdata)->generateSound((byte*)stream, len*2);
|
2002-04-14 18:13:08 +00:00
|
|
|
//}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::dx_copy_rgn_from_3_to_2(uint b, uint r, uint y, uint x)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
byte *dst, *src;
|
|
|
|
uint i;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
dst = dx_lock_2();
|
2002-08-18 16:21:34 +00:00
|
|
|
src = _sdl_buf_3;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
dst += y * _dx_surface_pitch;
|
|
|
|
src += y * _dx_surface_pitch;
|
|
|
|
|
|
|
|
while (y < b) {
|
2002-07-07 19:06:48 +00:00
|
|
|
for (i = x; i < r; i++)
|
2002-04-12 21:26:59 +00:00
|
|
|
dst[i] = src[i];
|
|
|
|
y++;
|
|
|
|
dst += _dx_surface_pitch;
|
|
|
|
src += _dx_surface_pitch;
|
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
dx_unlock_2();
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::dx_clear_surfaces(uint num_lines)
|
|
|
|
{
|
2002-08-18 16:21:34 +00:00
|
|
|
memset(_sdl_buf_attached, 0, num_lines * 320);
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-08-18 16:21:34 +00:00
|
|
|
_system->copy_rect(_sdl_buf_attached, 320, 0, 0, 320, 200);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
if (_dx_use_3_or_4_for_lock) {
|
2002-08-18 16:21:34 +00:00
|
|
|
memset(_sdl_buf, 0, num_lines * 320);
|
|
|
|
memset(_sdl_buf_3, 0, num_lines * 320);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::dx_clear_attached_from_top(uint lines)
|
|
|
|
{
|
2002-08-18 16:21:34 +00:00
|
|
|
memset(_sdl_buf_attached, 0, lines * 320);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::dx_copy_from_attached_to_2(uint x, uint y, uint w, uint h)
|
|
|
|
{
|
|
|
|
uint offs = x + y * 320;
|
2002-08-18 16:21:34 +00:00
|
|
|
byte *s = _sdl_buf_attached + offs;
|
|
|
|
byte *d = _sdl_buf + offs;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
do {
|
2002-07-07 19:06:48 +00:00
|
|
|
memcpy(d, s, w);
|
|
|
|
d += 320;
|
|
|
|
s += 320;
|
|
|
|
} while (--h);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::dx_copy_from_2_to_attached(uint x, uint y, uint w, uint h)
|
|
|
|
{
|
|
|
|
uint offs = x + y * 320;
|
2002-08-18 16:21:34 +00:00
|
|
|
byte *s = _sdl_buf + offs;
|
|
|
|
byte *d = _sdl_buf_attached + offs;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-16 12:07:19 +00:00
|
|
|
do {
|
2002-07-07 19:06:48 +00:00
|
|
|
memcpy(d, s, w);
|
|
|
|
d += 320;
|
|
|
|
s += 320;
|
|
|
|
} while (--h);
|
2002-04-16 12:07:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::dx_copy_from_attached_to_3(uint lines)
|
|
|
|
{
|
2002-08-18 16:21:34 +00:00
|
|
|
memcpy(_sdl_buf_3, _sdl_buf_attached, lines * 320);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::dx_update_screen_and_palette()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
_num_screen_updates++;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_palette_color_count == 0 && _video_var_9 == 1) {
|
2002-04-12 21:26:59 +00:00
|
|
|
_video_var_9 = 0;
|
2002-07-07 19:06:48 +00:00
|
|
|
if (memcmp(_palette, _palette_backup, 256 * 4) != 0) {
|
|
|
|
memcpy(_palette_backup, _palette, 256 * 4);
|
2002-04-12 21:26:59 +00:00
|
|
|
_system->set_palette(_palette, 0, 256);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (!_fast_mode || !(rand() & 7)) {
|
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
if (_mouse_pos_changed) {
|
|
|
|
_mouse_pos_changed = false;
|
2002-08-18 16:21:34 +00:00
|
|
|
_system->set_mouse_pos(_sdl_mouse_x, _sdl_mouse_y);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-08-18 16:21:34 +00:00
|
|
|
_system->copy_rect(_sdl_buf_attached, 320, 0, 0, 320, 200);
|
2002-04-12 21:26:59 +00:00
|
|
|
_system->update_screen();
|
|
|
|
}
|
|
|
|
|
2002-08-18 16:21:34 +00:00
|
|
|
memcpy(_sdl_buf_attached, _sdl_buf, 320 * 200);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
if (_palette_color_count != 0) {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (!(_game & GAME_SIMON2) && _use_palette_delay) {
|
2002-04-12 21:26:59 +00:00
|
|
|
delay(100);
|
|
|
|
_use_palette_delay = false;
|
|
|
|
}
|
|
|
|
realizePalette();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::realizePalette()
|
|
|
|
{
|
|
|
|
if (_palette_color_count & 0x8000) {
|
2002-04-12 21:26:59 +00:00
|
|
|
error("_palette_color_count&0x8000");
|
|
|
|
}
|
|
|
|
_video_var_9 = false;
|
2002-07-07 19:06:48 +00:00
|
|
|
memcpy(_palette_backup, _palette, 256 * 4);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
_system->set_palette(_palette, 0, _palette_color_count);
|
|
|
|
_palette_color_count = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::go()
|
|
|
|
{
|
2002-05-04 09:55:10 +00:00
|
|
|
OSystem::Property prop;
|
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
if (!_dump_file)
|
|
|
|
_dump_file = stdout;
|
|
|
|
|
|
|
|
/* allocate buffers */
|
2002-08-18 16:21:34 +00:00
|
|
|
_sdl_buf_3 = (byte *)calloc(320 * 200, 1);
|
|
|
|
_sdl_buf = (byte *)calloc(320 * 200, 1);
|
|
|
|
_sdl_buf_attached = (byte *)calloc(320 * 200, 1);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-29 10:28:43 +00:00
|
|
|
if (_game == GAME_SIMON2WIN) {
|
|
|
|
gss = &simon2win_settings;
|
2002-07-07 19:06:48 +00:00
|
|
|
} else if (_game == GAME_SIMON2DOS) {
|
|
|
|
gss = &simon2dos_settings;
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
|
|
|
gss = &simon1_settings;
|
|
|
|
}
|
|
|
|
|
|
|
|
allocItemHeap();
|
|
|
|
allocTablesHeap();
|
|
|
|
|
|
|
|
setup_vga_file_buf_pointers();
|
|
|
|
|
|
|
|
initSound();
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
if (!loadGamePcFile(gss->gamepc_filename))
|
2002-07-07 19:06:48 +00:00
|
|
|
error("Error loading gamepc file '%s' (or one of the files it depends on)",
|
|
|
|
gss->gamepc_filename);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
addTimeEvent(0, 1);
|
|
|
|
openGameFile();
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
_last_music_played = (uint) - 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
_vga_base_delay = 1;
|
|
|
|
_vk_t_toggle = true;
|
|
|
|
|
2002-05-04 09:55:10 +00:00
|
|
|
prop.show_cursor = true;
|
|
|
|
_system->property(OSystem::PROP_SHOW_DEFAULT_CURSOR, &prop);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
while (1) {
|
2002-04-12 21:26:59 +00:00
|
|
|
hitarea_stuff();
|
|
|
|
handle_verb_clicked(_verb_hitarea);
|
|
|
|
delay(100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::shutdown()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
if (_game_file) {
|
|
|
|
fclose(_game_file);
|
|
|
|
_game_file = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::delay(uint delay)
|
|
|
|
{
|
|
|
|
OSystem::Event event;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
uint32 start = _system->get_msecs();
|
|
|
|
uint32 cur = start;
|
|
|
|
const uint vga_period = _fast_mode ? 10 : 50;
|
|
|
|
|
|
|
|
do {
|
|
|
|
while (!_in_callback && cur >= _last_vga_tick + vga_period) {
|
|
|
|
_last_vga_tick += vga_period;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
/* don't get too many frames behind */
|
2002-07-07 19:06:48 +00:00
|
|
|
if (cur >= _last_vga_tick + vga_period * 2)
|
2002-04-12 21:26:59 +00:00
|
|
|
_last_vga_tick = cur;
|
|
|
|
|
|
|
|
_in_callback = true;
|
|
|
|
timer_callback();
|
|
|
|
_in_callback = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (_system->poll_event(&event)) {
|
2002-07-07 19:06:48 +00:00
|
|
|
switch (event.event_code) {
|
2002-08-18 16:21:34 +00:00
|
|
|
case OSystem::EVENT_KEYDOWN:
|
|
|
|
if (event.kbd.keycode == 't') {
|
2002-04-12 21:26:59 +00:00
|
|
|
_vk_t_toggle ^= 1;
|
2002-07-07 19:06:48 +00:00
|
|
|
} else if (event.kbd.flags == OSystem::KBD_CTRL) {
|
|
|
|
if (event.kbd.keycode == 'f') {
|
|
|
|
_fast_mode ^= 1;
|
2002-04-13 11:31:54 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-04-16 12:07:19 +00:00
|
|
|
_key_pressed = (byte)event.kbd.ascii;
|
2002-04-12 21:26:59 +00:00
|
|
|
break;
|
2002-08-18 16:21:34 +00:00
|
|
|
case OSystem::EVENT_MOUSEMOVE:
|
|
|
|
_sdl_mouse_x = event.mouse.x;
|
|
|
|
_sdl_mouse_y = event.mouse.y;
|
2002-04-12 21:26:59 +00:00
|
|
|
_mouse_pos_changed = true;
|
|
|
|
break;
|
|
|
|
|
2002-08-18 16:21:34 +00:00
|
|
|
case OSystem::EVENT_LBUTTONDOWN:
|
|
|
|
_left_button_down++;
|
2002-07-18 22:51:29 +00:00
|
|
|
#ifdef _WIN32_WCE
|
2002-08-18 16:21:34 +00:00
|
|
|
_sdl_mouse_x = event.mouse.x;
|
|
|
|
_sdl_mouse_y = event.mouse.y;
|
2002-07-18 22:51:29 +00:00
|
|
|
#endif
|
2002-04-12 21:26:59 +00:00
|
|
|
break;
|
|
|
|
|
2002-08-18 16:21:34 +00:00
|
|
|
case OSystem::EVENT_RBUTTONDOWN:
|
|
|
|
_exit_cutscene = true;
|
2002-04-12 21:26:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (delay == 0)
|
|
|
|
break;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-04-13 12:43:02 +00:00
|
|
|
{
|
|
|
|
uint this_delay = _fast_mode ? 1 : 20;
|
2002-07-07 19:06:48 +00:00
|
|
|
if (this_delay > delay)
|
|
|
|
this_delay = delay;
|
2002-04-13 12:43:02 +00:00
|
|
|
_system->delay_msecs(this_delay);
|
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
cur = _system->get_msecs();
|
|
|
|
} while (cur < start + delay);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
bool SimonState::save_game(uint slot, const char *caption)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
FILE *f;
|
|
|
|
uint item_index, num_item, i;
|
|
|
|
TimeEvent *te;
|
|
|
|
|
|
|
|
_lock_word |= 0x100;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-19 06:23:49 +00:00
|
|
|
#ifndef _WIN32_WCE
|
2002-04-12 21:26:59 +00:00
|
|
|
errno = 0;
|
2002-04-19 06:23:49 +00:00
|
|
|
#endif
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-16 12:07:19 +00:00
|
|
|
f = fopen(gen_savename(slot), "wb");
|
2002-08-20 09:58:35 +00:00
|
|
|
if (f == NULL) {
|
|
|
|
_lock_word &= ~0x100;
|
2002-04-12 21:26:59 +00:00
|
|
|
return false;
|
2002-08-20 09:58:35 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
fwrite(caption, 1, 0x12, f);
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
fileWriteBE32(f, _itemarray_inited - 1);
|
2002-04-12 21:26:59 +00:00
|
|
|
fileWriteBE32(f, 0xFFFFFFFF);
|
|
|
|
fileWriteBE32(f, 0);
|
|
|
|
fileWriteBE32(f, 0);
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
i = 0;
|
|
|
|
for (te = _first_time_struct; te; te = te->next)
|
2002-04-12 21:26:59 +00:00
|
|
|
i++;
|
|
|
|
|
|
|
|
fileWriteBE32(f, i);
|
2002-07-07 19:06:48 +00:00
|
|
|
for (te = _first_time_struct; te; te = te->next) {
|
2002-04-12 21:26:59 +00:00
|
|
|
fileWriteBE32(f, te->time + _base_time);
|
|
|
|
fileWriteBE16(f, te->subroutine_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
item_index = 1;
|
2002-07-07 19:06:48 +00:00
|
|
|
for (num_item = _itemarray_inited - 1; num_item; num_item--) {
|
2002-04-12 21:26:59 +00:00
|
|
|
Item *item = _itemarray_ptr[item_index++];
|
|
|
|
|
|
|
|
fileWriteBE16(f, item->parent);
|
|
|
|
fileWriteBE16(f, item->sibling);
|
|
|
|
fileWriteBE16(f, item->unk3);
|
|
|
|
fileWriteBE16(f, item->unk4);
|
|
|
|
|
|
|
|
{
|
|
|
|
Child1 *child1 = findChildOfType1(item);
|
|
|
|
if (child1) {
|
|
|
|
fileWriteBE16(f, child1->fr2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Child2 *child2 = findChildOfType2(item);
|
2002-07-07 19:06:48 +00:00
|
|
|
uint i, j;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
if (child2) {
|
|
|
|
fileWriteBE32(f, child2->avail_props);
|
2002-07-07 19:06:48 +00:00
|
|
|
i = child2->avail_props & 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
for (j = 1; j < 16; j++) {
|
|
|
|
if ((1 << j) & child2->avail_props) {
|
2002-04-12 21:26:59 +00:00
|
|
|
fileWriteBE16(f, child2->array[i++]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2002-07-07 19:06:48 +00:00
|
|
|
Child9 *child9 = (Child9 *) findChildOfType(item, 9);
|
2002-04-12 21:26:59 +00:00
|
|
|
if (child9) {
|
|
|
|
uint i;
|
2002-07-07 19:06:48 +00:00
|
|
|
for (i = 0; i != 4; i++) {
|
2002-04-12 21:26:59 +00:00
|
|
|
fileWriteBE16(f, child9->array[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write the 255 variables */
|
2002-07-07 19:06:48 +00:00
|
|
|
for (i = 0; i != 255; i++) {
|
2002-04-12 21:26:59 +00:00
|
|
|
fileWriteBE16(f, readVariable(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write the items in array 6 */
|
2002-07-07 19:06:48 +00:00
|
|
|
for (i = 0; i != 10; i++) {
|
2002-04-12 21:26:59 +00:00
|
|
|
fileWriteBE16(f, itemPtrToID(_item_array_6[i]));
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
/* Write the bits in array 1 & 2 */
|
|
|
|
for (i = 0; i != 32; i++)
|
2002-04-12 21:26:59 +00:00
|
|
|
fileWriteBE16(f, _bit_array[i]);
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
_lock_word &= ~0x100;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
char *SimonState::gen_savename(int slot)
|
|
|
|
{
|
2002-04-18 08:35:17 +00:00
|
|
|
static char buf[256];
|
2002-08-18 22:47:11 +00:00
|
|
|
const char *dir = getSavePath();
|
2002-04-18 08:35:17 +00:00
|
|
|
|
|
|
|
sprintf(buf, "%sSAVE.%.3d", dir, slot);
|
2002-04-16 12:07:19 +00:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
bool SimonState::load_game(uint slot)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
char ident[18];
|
|
|
|
FILE *f;
|
|
|
|
uint num, item_index, i;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
_lock_word |= 0x100;
|
|
|
|
|
2002-04-19 06:23:49 +00:00
|
|
|
#ifndef _WIN32_WCE
|
2002-04-12 21:26:59 +00:00
|
|
|
errno = 0;
|
2002-04-19 06:23:49 +00:00
|
|
|
#endif
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-04-18 08:35:17 +00:00
|
|
|
f = fopen(gen_savename(slot), "rb");
|
2002-08-20 09:58:35 +00:00
|
|
|
if (f == NULL) {
|
|
|
|
_lock_word &= ~0x100;
|
2002-04-12 21:26:59 +00:00
|
|
|
return false;
|
2002-08-20 09:58:35 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
fread(ident, 1, 18, f);
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
num = fileReadBE32(f);
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (fileReadBE32(f) != 0xFFFFFFFF || num != _itemarray_inited - 1) {
|
2002-04-12 21:26:59 +00:00
|
|
|
fclose(f);
|
2002-08-20 09:58:35 +00:00
|
|
|
_lock_word &= ~0x100;
|
2002-04-12 21:26:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
fileReadBE32(f);
|
|
|
|
fileReadBE32(f);
|
|
|
|
|
|
|
|
_no_parent_notify = true;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
/* add all timers */
|
|
|
|
killAllTimers();
|
2002-07-07 19:06:48 +00:00
|
|
|
for (num = fileReadBE32(f); num; num--) {
|
2002-04-12 21:26:59 +00:00
|
|
|
uint32 timeout = fileReadBE32(f);
|
|
|
|
uint16 func_to_call = fileReadBE16(f);
|
|
|
|
addTimeEvent(timeout, func_to_call);
|
|
|
|
}
|
|
|
|
|
|
|
|
item_index = 1;
|
2002-07-07 19:06:48 +00:00
|
|
|
for (num = _itemarray_inited - 1; num; num--) {
|
2002-04-12 21:26:59 +00:00
|
|
|
Item *item = _itemarray_ptr[item_index++], *parent_item;
|
|
|
|
|
|
|
|
uint parent = fileReadBE16(f);
|
|
|
|
uint sibling = fileReadBE16(f);
|
|
|
|
|
|
|
|
parent_item = derefItem(parent);
|
|
|
|
|
|
|
|
setItemParent(item, parent_item);
|
|
|
|
|
|
|
|
if (parent_item == NULL) {
|
|
|
|
item->parent = parent;
|
|
|
|
item->sibling = sibling;
|
|
|
|
}
|
|
|
|
|
|
|
|
item->unk3 = fileReadBE16(f);
|
|
|
|
item->unk4 = fileReadBE16(f);
|
|
|
|
|
|
|
|
{
|
|
|
|
Child1 *child1 = findChildOfType1(item);
|
|
|
|
if (child1 != NULL) {
|
|
|
|
child1->fr2 = fileReadBE16(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Child2 *child2 = findChildOfType2(item);
|
2002-07-07 19:06:48 +00:00
|
|
|
uint i, j;
|
2002-04-12 21:26:59 +00:00
|
|
|
if (child2 != NULL) {
|
|
|
|
child2->avail_props = fileReadBE32(f);
|
2002-07-07 19:06:48 +00:00
|
|
|
i = child2->avail_props & 1;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
for (j = 1; j < 16; j++) {
|
|
|
|
if ((1 << j) & child2->avail_props) {
|
2002-04-12 21:26:59 +00:00
|
|
|
child2->array[i++] = fileReadBE16(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2002-07-07 19:06:48 +00:00
|
|
|
Child9 *child9 = (Child9 *) findChildOfType(item, 9);
|
2002-04-12 21:26:59 +00:00
|
|
|
if (child9) {
|
|
|
|
uint i;
|
2002-07-07 19:06:48 +00:00
|
|
|
for (i = 0; i != 4; i++) {
|
2002-04-12 21:26:59 +00:00
|
|
|
child9->array[i] = fileReadBE16(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
/* read the 255 variables */
|
2002-07-07 19:06:48 +00:00
|
|
|
for (i = 0; i != 255; i++) {
|
2002-04-12 21:26:59 +00:00
|
|
|
writeVariable(i, fileReadBE16(f));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write the items in array 6 */
|
2002-07-07 19:06:48 +00:00
|
|
|
for (i = 0; i != 10; i++) {
|
2002-04-12 21:26:59 +00:00
|
|
|
_item_array_6[i] = derefItem(fileReadBE16(f));
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
/* Write the bits in array 1 & 2 */
|
|
|
|
for (i = 0; i != 32; i++)
|
2002-04-12 21:26:59 +00:00
|
|
|
_bit_array[i] = fileReadBE16(f);
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
_no_parent_notify = false;
|
|
|
|
|
|
|
|
_lock_word &= ~0x100;
|
|
|
|
|
2002-04-19 06:23:49 +00:00
|
|
|
#ifndef _WIN32_WCE
|
2002-04-12 21:26:59 +00:00
|
|
|
if (errno != 0)
|
|
|
|
error("load failed");
|
2002-04-19 06:23:49 +00:00
|
|
|
#endif
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::initSound()
|
|
|
|
{
|
2002-04-13 11:44:56 +00:00
|
|
|
/* only read voice file in windows game */
|
|
|
|
if (_game & GAME_WIN) {
|
|
|
|
const char *s = gss->wav_filename;
|
2002-06-06 03:46:44 +00:00
|
|
|
const char *s2 = gss->wav_filename2;
|
2002-06-05 02:59:35 +00:00
|
|
|
const char *e = gss->effects_filename;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-04-13 11:44:56 +00:00
|
|
|
_voice_offsets = NULL;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-04-13 11:44:56 +00:00
|
|
|
_voice_file = fopen_maybe_lowercase(s);
|
|
|
|
if (_voice_file == NULL) {
|
2002-07-07 19:06:48 +00:00
|
|
|
warning("Cannot open voice file %s, trying %s", s, s2);
|
2002-06-29 10:28:43 +00:00
|
|
|
if (s2) {
|
|
|
|
_voice_file = fopen_maybe_lowercase(s2);
|
|
|
|
if (_voice_file == NULL) {
|
2002-07-07 19:06:48 +00:00
|
|
|
warning("Cannot open voice file %s", s2);
|
2002-06-29 10:28:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else
|
2002-06-06 03:46:44 +00:00
|
|
|
return;
|
2002-04-13 11:44:56 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
_voice_offsets = (uint32 *)malloc(gss->NUM_VOICE_RESOURCES * sizeof(uint32));
|
2002-04-13 11:44:56 +00:00
|
|
|
if (_voice_offsets == NULL)
|
|
|
|
error("Out of memory for voice offsets");
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-04-13 11:44:56 +00:00
|
|
|
if (fread(_voice_offsets, gss->NUM_VOICE_RESOURCES * sizeof(uint32), 1, _voice_file) != 1)
|
|
|
|
error("Cannot read voice offsets");
|
2002-06-05 02:59:35 +00:00
|
|
|
|
|
|
|
_effects_offsets = NULL;
|
|
|
|
_effects_file = fopen_maybe_lowercase(e);
|
2002-07-21 14:31:58 +00:00
|
|
|
if (_effects_file != NULL)
|
|
|
|
{
|
|
|
|
_effects_offsets = (uint32 *)malloc(gss->NUM_EFFECTS_RESOURCES * sizeof(uint32));
|
|
|
|
if (_effects_offsets == NULL)
|
|
|
|
error("Out of memory for effects offsets");
|
2002-06-05 02:59:35 +00:00
|
|
|
|
2002-07-21 14:31:58 +00:00
|
|
|
if (fread(_effects_offsets, gss->NUM_EFFECTS_RESOURCES * sizeof(uint32), 1, _effects_file) != 1)
|
|
|
|
error("Cannot read effects offsets");
|
|
|
|
}
|
2002-06-05 02:59:35 +00:00
|
|
|
|
2002-04-21 12:51:13 +00:00
|
|
|
#if defined(SCUMM_BIG_ENDIAN)
|
2002-07-07 19:06:48 +00:00
|
|
|
for (int r = 0; r < gss->NUM_VOICE_RESOURCES; r++)
|
|
|
|
_voice_offsets[r] = READ_LE_UINT32(&_voice_offsets[r]);
|
2002-06-05 02:59:35 +00:00
|
|
|
|
|
|
|
if (_effects_offsets)
|
2002-07-07 19:06:48 +00:00
|
|
|
for (int r = 0; r < gss->NUM_EFFECTS_RESOURCES; r++)
|
|
|
|
_effects_offsets[r] = READ_LE_UINT32(&_effects_offsets[r]);
|
2002-04-21 12:51:13 +00:00
|
|
|
#endif
|
2002-04-13 11:44:56 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-05-01 00:13:03 +00:00
|
|
|
#if !defined(__GNUC__)
|
2002-07-07 19:06:48 +00:00
|
|
|
#pragma START_PACK_STRUCTS
|
|
|
|
#endif
|
2002-05-01 00:13:03 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
struct WaveHeader {
|
|
|
|
uint32 riff;
|
|
|
|
uint32 unk;
|
|
|
|
uint32 wave;
|
|
|
|
uint32 fmt;
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
uint32 size;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
|
|
|
uint16 format_tag;
|
|
|
|
uint16 channels;
|
|
|
|
uint32 samples_per_sec;
|
|
|
|
uint32 avg_bytes;
|
|
|
|
|
|
|
|
uint16 block_align;
|
|
|
|
uint16 bits_per_sample;
|
2002-04-21 12:51:13 +00:00
|
|
|
} GCC_PACK;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-05 02:59:35 +00:00
|
|
|
struct VocHeader {
|
2002-07-07 19:06:48 +00:00
|
|
|
uint8 desc[20];
|
|
|
|
uint16 datablock_offset;
|
|
|
|
uint16 version;
|
|
|
|
uint16 id;
|
|
|
|
uint8 blocktype;
|
2002-06-05 02:59:35 +00:00
|
|
|
} GCC_PACK;
|
|
|
|
|
|
|
|
struct VocBlockHeader {
|
2002-07-07 19:06:48 +00:00
|
|
|
uint8 tc;
|
|
|
|
uint8 pack;
|
2002-06-05 02:59:35 +00:00
|
|
|
} GCC_PACK;
|
|
|
|
|
|
|
|
|
2002-05-01 00:13:03 +00:00
|
|
|
#if !defined(__GNUC__)
|
2002-07-07 19:06:48 +00:00
|
|
|
#pragma END_PACK_STRUCTS
|
|
|
|
#endif
|
2002-05-01 00:13:03 +00:00
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::playVoice(uint voice)
|
|
|
|
{
|
2002-06-06 03:46:44 +00:00
|
|
|
_mixer->stop(_voice_sound);
|
|
|
|
fseek(_voice_file, _voice_offsets[voice], SEEK_SET);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (!_effects_offsets) { /* WAVE audio */
|
2002-06-06 03:46:44 +00:00
|
|
|
WaveHeader wave_hdr;
|
2002-07-07 19:06:48 +00:00
|
|
|
uint32 data[2];
|
|
|
|
|
|
|
|
if (fread(&wave_hdr, sizeof(wave_hdr), 1, _voice_file) != 1 ||
|
|
|
|
wave_hdr.riff != MKID('RIFF') || wave_hdr.wave != MKID('WAVE')
|
|
|
|
|| wave_hdr.fmt != MKID('fmt ') || READ_LE_UINT16(&wave_hdr.format_tag) != 1
|
|
|
|
|| READ_LE_UINT16(&wave_hdr.channels) != 1
|
|
|
|
|| READ_LE_UINT16(&wave_hdr.bits_per_sample) != 8) {
|
2002-07-21 14:36:51 +00:00
|
|
|
warning("playVoice(%d): cannot read RIFF header", voice);
|
2002-07-07 19:06:48 +00:00
|
|
|
return;
|
2002-06-05 02:59:35 +00:00
|
|
|
}
|
2002-04-14 18:13:08 +00:00
|
|
|
|
2002-06-05 02:59:35 +00:00
|
|
|
fseek(_voice_file, READ_LE_UINT32(&wave_hdr.size) - sizeof(wave_hdr) + 20, SEEK_CUR);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-06 03:46:44 +00:00
|
|
|
data[0] = fileReadLE32(_voice_file);
|
|
|
|
data[1] = fileReadLE32(_voice_file);
|
2002-07-07 19:06:48 +00:00
|
|
|
if ( //fread(data, sizeof(data), 1, _voice_file) != 1 ||
|
|
|
|
data[0] != 'atad') {
|
|
|
|
warning("playVoice(%d): cannot read data header", voice);
|
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
2002-06-06 03:46:44 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
byte *buffer = (byte *)malloc(data[1]);
|
2002-06-06 03:46:44 +00:00
|
|
|
fread(buffer, data[1], 1, _voice_file);
|
|
|
|
|
2002-08-24 15:31:37 +00:00
|
|
|
_mixer->playRaw(&_voice_sound, buffer, data[1], READ_LE_UINT32(&wave_hdr.samples_per_sec),
|
2002-07-07 19:06:48 +00:00
|
|
|
SoundMixer::FLAG_UNSIGNED);
|
|
|
|
} else { /* VOC audio */
|
2002-06-05 02:59:35 +00:00
|
|
|
VocHeader voc_hdr;
|
|
|
|
VocBlockHeader voc_block_hdr;
|
|
|
|
uint32 size;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
if (fread(&voc_hdr, sizeof(voc_hdr), 1, _voice_file) != 1 ||
|
|
|
|
strncmp((char *)voc_hdr.desc, "Creative Voice File\x1A", 10) != 0) {
|
|
|
|
warning("playVoice(%d): cannot read voc header", voice);
|
|
|
|
return;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-05 02:59:35 +00:00
|
|
|
fread(&size, 4, 1, _voice_file);
|
|
|
|
size = size & 0xffffff;
|
|
|
|
fseek(_voice_file, -1, SEEK_CUR);
|
|
|
|
fread(&voc_block_hdr, sizeof(voc_block_hdr), 1, _voice_file);
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
uint32 samples_per_sec = 1000000L / (256L - (long)voc_block_hdr.tc);
|
|
|
|
|
|
|
|
byte *buffer = (byte *)malloc(size);
|
2002-06-06 07:12:17 +00:00
|
|
|
fread(buffer, size, 1, _voice_file);
|
2002-06-06 03:46:44 +00:00
|
|
|
|
2002-08-24 15:31:37 +00:00
|
|
|
_mixer->playRaw(&_voice_sound, buffer, size, samples_per_sec, SoundMixer::FLAG_UNSIGNED);
|
2002-06-05 02:59:35 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::playSound(uint sound)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
if (_game & GAME_WIN) {
|
2002-07-07 19:06:48 +00:00
|
|
|
if (_effects_offsets) { /* VOC sound file */
|
2002-06-05 02:59:35 +00:00
|
|
|
VocHeader voc_hdr;
|
|
|
|
VocBlockHeader voc_block_hdr;
|
|
|
|
uint32 size;
|
2002-04-13 11:11:41 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
_mixer->stop(_effects_sound);
|
2002-06-05 02:59:35 +00:00
|
|
|
fseek(_effects_file, _effects_offsets[sound], SEEK_SET);
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
if (fread(&voc_hdr, sizeof(voc_hdr), 1, _effects_file) != 1 ||
|
|
|
|
strncmp((char *)voc_hdr.desc, "Creative Voice File\x1A", 10) != 0) {
|
|
|
|
warning("playSound(%d): cannot read voc header", sound);
|
|
|
|
return;
|
2002-06-05 02:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fread(&size, 4, 1, _effects_file);
|
|
|
|
size = size & 0xffffff;
|
|
|
|
fseek(_effects_file, -1, SEEK_CUR);
|
|
|
|
fread(&voc_block_hdr, sizeof(voc_block_hdr), 1, _effects_file);
|
2002-07-07 19:06:48 +00:00
|
|
|
|
|
|
|
uint32 samples_per_sec = 1000000L / (256L - (long)voc_block_hdr.tc);
|
|
|
|
|
|
|
|
byte *buffer = (byte *)malloc(size);
|
2002-06-06 03:46:44 +00:00
|
|
|
fread(buffer, size, 1, _effects_file);
|
|
|
|
|
2002-08-24 15:31:37 +00:00
|
|
|
_mixer->playRaw(&_effects_sound, buffer, size, samples_per_sec, SoundMixer::FLAG_UNSIGNED);
|
2002-06-05 02:59:35 +00:00
|
|
|
} else {
|
|
|
|
byte *p;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-06-05 02:59:35 +00:00
|
|
|
_mixer->stop(_playing_sound);
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-05 02:59:35 +00:00
|
|
|
/* Check if _sfx_heap is NULL */
|
|
|
|
if (_sfx_heap == NULL) {
|
|
|
|
warning("playSound(%d) cannot play. No voice file loaded", sound);
|
2002-04-12 21:26:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
p = _sfx_heap + READ_LE_UINT32(&((uint32 *)_sfx_heap)[sound]);
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
p = (byte *)memchr(p, 'd', 1000);
|
2002-06-05 02:59:35 +00:00
|
|
|
if (!p) {
|
|
|
|
error("playSound(%d): didn't find", sound);
|
|
|
|
return;
|
|
|
|
}
|
2002-07-07 19:06:48 +00:00
|
|
|
if (p[1] == 'a' && p[2] == 't' && p[3] == 'a')
|
2002-06-05 02:59:35 +00:00
|
|
|
break;
|
2002-04-12 21:26:59 +00:00
|
|
|
|
2002-06-05 02:59:35 +00:00
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
2002-08-24 15:31:37 +00:00
|
|
|
_mixer->playRaw(&_playing_sound, p + 8, READ_LE_UINT32(p + 4), 22050,
|
2002-07-07 19:06:48 +00:00
|
|
|
SoundMixer::FLAG_UNSIGNED);
|
2002-06-05 02:59:35 +00:00
|
|
|
}
|
2002-04-12 21:26:59 +00:00
|
|
|
} else {
|
|
|
|
warning("playSound(%d)", sound);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::playMusic(uint music)
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
midi.shutdown();
|
|
|
|
|
|
|
|
/* FIXME: not properly implemented */
|
|
|
|
if (_game & GAME_WIN) {
|
2002-07-07 19:06:48 +00:00
|
|
|
fseek(_game_file, _game_offsets_ptr[gss->MUSIC_INDEX_BASE + music] - 1, SEEK_SET);
|
2002-04-12 21:26:59 +00:00
|
|
|
f = _game_file;
|
2002-07-07 19:06:48 +00:00
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
midi.read_all_songs(f);
|
|
|
|
} else {
|
|
|
|
char buf[50];
|
2002-04-13 11:44:56 +00:00
|
|
|
sprintf(buf, "MOD%d.MUS", music);
|
|
|
|
f = fopen_maybe_lowercase(buf);
|
2002-07-07 19:06:48 +00:00
|
|
|
if (f == NULL) {
|
2002-04-12 21:26:59 +00:00
|
|
|
warning("Cannot load music from '%s'", buf);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
midi.read_all_songs_old(f);
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
midi.initialize();
|
|
|
|
midi.play();
|
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
byte *SimonState::dx_lock_2()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
_dx_surface_pitch = 320;
|
2002-08-18 16:21:34 +00:00
|
|
|
return _sdl_buf;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::dx_unlock_2()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
byte *SimonState::dx_lock_attached()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
_dx_surface_pitch = 320;
|
2002-08-18 16:21:34 +00:00
|
|
|
return _dx_use_3_or_4_for_lock ? _sdl_buf_3 : _sdl_buf_attached;
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::dx_unlock_attached()
|
|
|
|
{
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
void SimonState::set_volume(byte volume)
|
|
|
|
{
|
2002-08-24 15:31:37 +00:00
|
|
|
_mixer->setVolume(volume);
|
2002-04-12 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2002-06-29 16:11:13 +00:00
|
|
|
|
2002-07-07 19:06:48 +00:00
|
|
|
byte SimonState::getByte()
|
|
|
|
{
|
2002-06-29 16:11:13 +00:00
|
|
|
return *_code_ptr++;
|
|
|
|
}
|