2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2006-04-29 13:38:07 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/stdafx.h"
|
|
|
|
|
2006-09-29 08:14:27 +00:00
|
|
|
#include "agos/agos.h"
|
2006-10-11 15:10:59 +00:00
|
|
|
#include "agos/debugger.h"
|
2006-09-29 08:14:27 +00:00
|
|
|
#include "agos/intern.h"
|
2006-04-29 13:38:07 +00:00
|
|
|
|
2007-03-17 00:53:21 +00:00
|
|
|
#include "common/events.h"
|
2006-10-11 15:10:59 +00:00
|
|
|
#include "common/system.h"
|
|
|
|
|
|
|
|
#include "gui/about.h"
|
|
|
|
|
2007-02-16 13:55:01 +00:00
|
|
|
#include "sound/audiocd.h"
|
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
namespace AGOS {
|
2006-04-29 13:38:07 +00:00
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
void AGOSEngine::addTimeEvent(uint timeout, uint subroutine_id) {
|
2006-04-29 13:38:07 +00:00
|
|
|
TimeEvent *te = (TimeEvent *)malloc(sizeof(TimeEvent)), *first, *last = NULL;
|
|
|
|
time_t cur_time;
|
|
|
|
|
|
|
|
time(&cur_time);
|
|
|
|
|
2007-05-16 05:57:26 +00:00
|
|
|
if (getGameId() == GID_DIMP) {
|
|
|
|
timeout /= 2;
|
|
|
|
}
|
|
|
|
|
2006-04-29 13:38:07 +00:00
|
|
|
te->time = cur_time + timeout - _gameStoppedClock;
|
2006-10-02 06:11:05 +00:00
|
|
|
if (getGameType() == GType_FF && _clockStopped)
|
2006-04-29 13:38:07 +00:00
|
|
|
te->time -= ((uint32)time(NULL) - _clockStopped);
|
|
|
|
te->subroutine_id = subroutine_id;
|
|
|
|
|
|
|
|
first = _firstTimeStruct;
|
|
|
|
while (first) {
|
|
|
|
if (te->time <= first->time) {
|
|
|
|
if (last) {
|
|
|
|
last->next = te;
|
|
|
|
te->next = first;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
te->next = _firstTimeStruct;
|
|
|
|
_firstTimeStruct = te;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
last = first;
|
|
|
|
first = first->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last) {
|
|
|
|
last->next = te;
|
|
|
|
te->next = NULL;
|
|
|
|
} else {
|
|
|
|
_firstTimeStruct = te;
|
|
|
|
te->next = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
void AGOSEngine::delTimeEvent(TimeEvent *te) {
|
2006-04-29 13:38:07 +00:00
|
|
|
TimeEvent *cur;
|
|
|
|
|
|
|
|
if (te == _pendingDeleteTimeEvent)
|
|
|
|
_pendingDeleteTimeEvent = NULL;
|
|
|
|
|
|
|
|
if (te == _firstTimeStruct) {
|
|
|
|
_firstTimeStruct = te->next;
|
|
|
|
free(te);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cur = _firstTimeStruct;
|
|
|
|
if (cur == NULL)
|
|
|
|
error("delTimeEvent: none available");
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if (cur->next == NULL)
|
|
|
|
error("delTimeEvent: no such te");
|
|
|
|
if (te == cur->next) {
|
|
|
|
cur->next = te->next;
|
|
|
|
free(te);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
void AGOSEngine::invokeTimeEvent(TimeEvent *te) {
|
2006-04-29 13:38:07 +00:00
|
|
|
Subroutine *sub;
|
|
|
|
|
|
|
|
_scriptVerb = 0;
|
|
|
|
|
|
|
|
if (_runScriptReturn1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sub = getSubroutineByID(te->subroutine_id);
|
|
|
|
if (sub != NULL)
|
|
|
|
startSubroutineEx(sub);
|
|
|
|
|
|
|
|
_runScriptReturn1 = false;
|
|
|
|
}
|
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
void AGOSEngine::killAllTimers() {
|
2006-04-29 13:38:07 +00:00
|
|
|
TimeEvent *cur, *next;
|
|
|
|
|
|
|
|
for (cur = _firstTimeStruct; cur; cur = next) {
|
|
|
|
next = cur->next;
|
|
|
|
delTimeEvent(cur);
|
|
|
|
}
|
2007-05-09 15:36:05 +00:00
|
|
|
_clickOnly = 0;
|
2006-04-29 13:38:07 +00:00
|
|
|
}
|
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
bool AGOSEngine::kickoffTimeEvents() {
|
2006-04-29 13:38:07 +00:00
|
|
|
time_t cur_time;
|
|
|
|
TimeEvent *te;
|
|
|
|
bool result = false;
|
|
|
|
|
2006-10-02 06:11:05 +00:00
|
|
|
if (getGameType() == GType_FF && _clockStopped)
|
2006-04-29 13:38:07 +00:00
|
|
|
return result;
|
|
|
|
|
|
|
|
time(&cur_time);
|
|
|
|
cur_time -= _gameStoppedClock;
|
|
|
|
|
|
|
|
while ((te = _firstTimeStruct) != NULL && te->time <= (uint32)cur_time) {
|
|
|
|
result = true;
|
|
|
|
_pendingDeleteTimeEvent = te;
|
|
|
|
invokeTimeEvent(te);
|
|
|
|
if (_pendingDeleteTimeEvent) {
|
|
|
|
_pendingDeleteTimeEvent = NULL;
|
|
|
|
delTimeEvent(te);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2006-09-30 07:15:19 +00:00
|
|
|
bool AGOSEngine::isVgaQueueEmpty() {
|
2006-09-30 07:29:23 +00:00
|
|
|
VgaTimerEntry *vte = _vgaTimerList;
|
2006-09-30 07:24:30 +00:00
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
while (vte->delay) {
|
|
|
|
if (vte->cur_vga_file == _variableArray[999] && vte->sprite_id >= 100) {
|
|
|
|
result = true;
|
|
|
|
break;
|
|
|
|
}
|
2006-09-30 07:26:40 +00:00
|
|
|
vte++;
|
2006-09-30 07:24:30 +00:00
|
|
|
}
|
|
|
|
return result;
|
2006-09-30 07:15:19 +00:00
|
|
|
}
|
|
|
|
|
2006-10-13 11:38:41 +00:00
|
|
|
void AGOSEngine::haltAnimation() {
|
2007-05-09 15:36:05 +00:00
|
|
|
if (_lockWord & 0x10)
|
|
|
|
return;
|
2006-10-13 11:38:41 +00:00
|
|
|
|
|
|
|
_lockWord |= 0x10;
|
|
|
|
|
2007-05-13 08:46:48 +00:00
|
|
|
if (_displayScreen) {
|
|
|
|
displayScreen();
|
|
|
|
_displayScreen = false;
|
2006-10-13 11:38:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AGOSEngine::restartAnimation() {
|
2007-05-09 15:36:05 +00:00
|
|
|
if (!(_lockWord & 0x10))
|
|
|
|
return;
|
|
|
|
|
2007-05-10 00:43:27 +00:00
|
|
|
_window4Flag = 2;
|
2007-05-13 08:46:48 +00:00
|
|
|
|
2007-05-10 00:43:27 +00:00
|
|
|
setMoveRect(0, 0, 224, 127);
|
2007-05-13 08:46:48 +00:00
|
|
|
displayScreen();
|
2007-05-10 00:43:27 +00:00
|
|
|
|
2006-10-13 11:38:41 +00:00
|
|
|
_lockWord &= ~0x10;
|
2007-05-09 15:36:05 +00:00
|
|
|
|
|
|
|
// Check picture queue
|
2006-10-13 11:38:41 +00:00
|
|
|
}
|
|
|
|
|
2007-05-26 13:23:06 +00:00
|
|
|
void AGOSEngine::addVgaEvent(uint16 num, uint8 type, const byte *code_ptr, uint16 cur_sprite, uint16 curZoneNum) {
|
2006-04-29 13:38:07 +00:00
|
|
|
VgaTimerEntry *vte;
|
|
|
|
|
|
|
|
_lockWord |= 1;
|
|
|
|
|
|
|
|
for (vte = _vgaTimerList; vte->delay; vte++) {
|
|
|
|
}
|
|
|
|
|
|
|
|
vte->delay = num;
|
|
|
|
vte->script_pointer = code_ptr;
|
|
|
|
vte->sprite_id = cur_sprite;
|
|
|
|
vte->cur_vga_file = curZoneNum;
|
2007-05-13 08:46:48 +00:00
|
|
|
vte->type = type;
|
2006-04-29 13:38:07 +00:00
|
|
|
|
|
|
|
_lockWord &= ~1;
|
|
|
|
}
|
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
void AGOSEngine::deleteVgaEvent(VgaTimerEntry * vte) {
|
2006-04-29 13:38:07 +00:00
|
|
|
_lockWord |= 1;
|
|
|
|
|
|
|
|
if (vte + 1 <= _nextVgaTimerToProcess) {
|
|
|
|
_nextVgaTimerToProcess--;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
memcpy(vte, vte + 1, sizeof(VgaTimerEntry));
|
|
|
|
vte++;
|
|
|
|
} while (vte->delay);
|
|
|
|
|
|
|
|
_lockWord &= ~1;
|
|
|
|
}
|
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
void AGOSEngine::processVgaEvents() {
|
2006-04-29 13:38:07 +00:00
|
|
|
VgaTimerEntry *vte = _vgaTimerList;
|
|
|
|
|
|
|
|
_vgaTickCounter++;
|
|
|
|
|
|
|
|
while (vte->delay) {
|
2006-10-01 10:48:06 +00:00
|
|
|
vte->delay -= _vgaBaseDelay;
|
2006-04-29 13:38:07 +00:00
|
|
|
if (vte->delay <= 0) {
|
|
|
|
uint16 curZoneNum = vte->cur_vga_file;
|
|
|
|
uint16 cur_sprite = vte->sprite_id;
|
|
|
|
const byte *script_ptr = vte->script_pointer;
|
2007-05-13 08:46:48 +00:00
|
|
|
|
2007-05-26 13:23:06 +00:00
|
|
|
switch (vte->type) {
|
|
|
|
case ANIMATE_INT:
|
2007-05-13 10:07:55 +00:00
|
|
|
vte->delay = (getGameType() == GType_SIMON2) ? 5 : _frameCount;
|
2007-05-13 08:46:48 +00:00
|
|
|
animateSprites();
|
|
|
|
vte++;
|
2007-05-26 13:23:06 +00:00
|
|
|
break;
|
|
|
|
case ANIMATE_EVENT:
|
2007-05-13 08:46:48 +00:00
|
|
|
_nextVgaTimerToProcess = vte + 1;
|
|
|
|
deleteVgaEvent(vte);
|
2007-05-26 13:23:06 +00:00
|
|
|
animateEvent(script_ptr, curZoneNum, cur_sprite);
|
2007-05-13 08:46:48 +00:00
|
|
|
vte = _nextVgaTimerToProcess;
|
2007-05-26 13:23:06 +00:00
|
|
|
break;
|
|
|
|
case SCROLL_EVENT:
|
2007-05-13 08:46:48 +00:00
|
|
|
_nextVgaTimerToProcess = vte + 1;
|
|
|
|
deleteVgaEvent(vte);
|
2007-05-26 13:23:06 +00:00
|
|
|
scrollEvent();
|
|
|
|
vte = _nextVgaTimerToProcess;
|
|
|
|
break;
|
|
|
|
case IMAGE_EVENT2:
|
|
|
|
imageEvent2(vte, curZoneNum);
|
|
|
|
vte = _nextVgaTimerToProcess;
|
|
|
|
break;
|
|
|
|
case IMAGE_EVENT3:
|
|
|
|
imageEvent3(vte, curZoneNum);
|
2007-05-13 08:46:48 +00:00
|
|
|
vte = _nextVgaTimerToProcess;
|
2007-05-26 13:23:06 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("processVgaEvents: Unknown event type %d", vte->type);
|
2006-04-29 13:38:07 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
vte++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
void AGOSEngine::animateEvent(const byte *code_ptr, uint16 curZoneNum, uint16 cur_sprite) {
|
2006-04-29 13:38:07 +00:00
|
|
|
VgaPointersEntry *vpe;
|
|
|
|
|
|
|
|
_vgaCurSpriteId = cur_sprite;
|
|
|
|
|
|
|
|
_vgaCurZoneNum = curZoneNum;
|
|
|
|
_zoneNumber = curZoneNum;
|
|
|
|
vpe = &_vgaBufferPointers[curZoneNum];
|
|
|
|
|
|
|
|
_curVgaFile1 = vpe->vgaFile1;
|
|
|
|
_curVgaFile2 = vpe->vgaFile2;
|
|
|
|
_curSfxFile = vpe->sfxFile;
|
|
|
|
|
|
|
|
_vcPtr = code_ptr;
|
|
|
|
|
|
|
|
runVgaScript();
|
|
|
|
}
|
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
void AGOSEngine::scrollEvent() {
|
2006-04-29 13:38:07 +00:00
|
|
|
if (_scrollCount == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (getGameType() == GType_FF) {
|
|
|
|
if (_scrollCount < 0) {
|
|
|
|
if (_scrollFlag != -8) {
|
|
|
|
_scrollFlag = -8;
|
|
|
|
_scrollCount += 8;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (_scrollFlag != 8) {
|
|
|
|
_scrollFlag = 8;
|
|
|
|
_scrollCount -= 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (_scrollCount < 0) {
|
|
|
|
if (_scrollFlag != -1) {
|
|
|
|
_scrollFlag = -1;
|
|
|
|
if (++_scrollCount == 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (_scrollFlag != 1) {
|
|
|
|
_scrollFlag = 1;
|
|
|
|
if (--_scrollCount == 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-26 13:23:06 +00:00
|
|
|
addVgaEvent(6, SCROLL_EVENT, NULL, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const byte _image1[32] = {
|
|
|
|
0x3A, 0x37, 0x3B, 0x37,
|
|
|
|
0x3A, 0x3E, 0x3F, 0x3E,
|
|
|
|
0x37, 0x3F, 0x31, 0x3F,
|
|
|
|
0x37, 0x3F, 0x31, 0x3F,
|
|
|
|
0x3A, 0x3E, 0x3F, 0x3E,
|
|
|
|
0x3A, 0x37, 0x3B, 0x37,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const byte _image2[32] = {
|
|
|
|
0x3A, 0x3A, 0x3B, 0x3A,
|
|
|
|
0x3A, 0x37, 0x3E, 0x37,
|
|
|
|
0x3A, 0x37, 0x3E, 0x37,
|
|
|
|
0x3A, 0x37, 0x3E, 0x37,
|
|
|
|
0x3A, 0x37, 0x3E, 0x37,
|
|
|
|
0x3A, 0x3A, 0x3B, 0x3A,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const byte _image3[32] = {
|
|
|
|
0x3A, 0x32, 0x3B, 0x32,
|
|
|
|
0x3A, 0x39, 0x3F, 0x39,
|
|
|
|
0x32, 0x3F, 0x31, 0x3F,
|
|
|
|
0x32, 0x3F, 0x31, 0x3F,
|
|
|
|
0x3A, 0x39, 0x3F, 0x39,
|
|
|
|
0x3A, 0x32, 0x3B, 0x32,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const byte _image4[32] = {
|
|
|
|
0x3A, 0x3A, 0x3B, 0x3A,
|
|
|
|
0x3A, 0x32, 0x39, 0x32,
|
|
|
|
0x3A, 0x32, 0x38, 0x32,
|
|
|
|
0x3A, 0x32, 0x38, 0x32,
|
|
|
|
0x3A, 0x32, 0x39, 0x32,
|
|
|
|
0x3A, 0x3A, 0x3B, 0x3A,
|
|
|
|
};
|
|
|
|
|
2007-05-28 08:54:13 +00:00
|
|
|
void AGOSEngine::drawStuff(const byte *src, uint xoffs) {
|
|
|
|
const uint8 y = (getPlatform() == Common::kPlatformAtariST) ? 132 : 135;
|
|
|
|
byte *dst = getFrontBuf() + y * _screenWidth + xoffs;
|
2007-05-26 13:23:06 +00:00
|
|
|
|
2007-05-28 08:54:13 +00:00
|
|
|
for (uint h = 0; h < 6; h++) {
|
2007-05-26 13:23:06 +00:00
|
|
|
memcpy(dst, src, 4);
|
|
|
|
src += 4;
|
|
|
|
dst += _screenWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AGOSEngine::imageEvent2(VgaTimerEntry * vte, uint dx) {
|
2007-05-28 08:54:13 +00:00
|
|
|
// Draws damage indicator gauge when player hit
|
2007-05-26 13:23:06 +00:00
|
|
|
_nextVgaTimerToProcess = vte + 1;
|
|
|
|
|
|
|
|
if (!_opcode177Var1) {
|
2007-05-28 08:54:13 +00:00
|
|
|
drawStuff(_image1, 4 + _opcode177Var2 * 4);
|
2007-05-26 13:23:06 +00:00
|
|
|
_opcode177Var2++;
|
|
|
|
if (_opcode177Var2 == dx) {
|
|
|
|
_opcode177Var1 = 1;
|
|
|
|
vte->delay = 16 - dx;
|
|
|
|
} else {
|
|
|
|
vte->delay = 1;
|
|
|
|
}
|
|
|
|
} else if (_opcode177Var2) {
|
|
|
|
_opcode177Var2--;
|
2007-05-28 08:54:13 +00:00
|
|
|
drawStuff(_image2, 4 + _opcode177Var2 * 4);
|
2007-05-26 13:23:06 +00:00
|
|
|
vte->delay = 3;
|
|
|
|
} else {
|
|
|
|
deleteVgaEvent(vte);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AGOSEngine::imageEvent3(VgaTimerEntry * vte, uint dx) {
|
2007-05-28 08:54:13 +00:00
|
|
|
// Draws damage indicator gauge when monster hit
|
2007-05-26 13:23:06 +00:00
|
|
|
_nextVgaTimerToProcess = vte + 1;
|
|
|
|
|
|
|
|
if (!_opcode178Var1) {
|
2007-05-28 08:54:13 +00:00
|
|
|
drawStuff(_image3, 275 + _opcode178Var2 * 4);
|
2007-05-26 13:23:06 +00:00
|
|
|
_opcode178Var2++;
|
|
|
|
if (_opcode178Var2 >= 10 || _opcode178Var2 == dx) {
|
|
|
|
_opcode178Var1 = 1;
|
|
|
|
vte->delay = 16 - dx;
|
|
|
|
} else {
|
|
|
|
vte->delay = 1;
|
|
|
|
}
|
|
|
|
} else if (_opcode178Var2) {
|
|
|
|
_opcode178Var2--;
|
2007-05-28 08:54:13 +00:00
|
|
|
drawStuff(_image4, 275 + _opcode178Var2 * 4);
|
2007-05-26 13:23:06 +00:00
|
|
|
vte->delay = 3;
|
|
|
|
} else {
|
|
|
|
deleteVgaEvent(vte);
|
2006-04-29 13:38:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-11 15:10:59 +00:00
|
|
|
void AGOSEngine::delay(uint amount) {
|
2007-03-17 19:02:05 +00:00
|
|
|
Common::Event event;
|
2006-10-11 15:10:59 +00:00
|
|
|
|
|
|
|
uint32 start = _system->getMillis();
|
|
|
|
uint32 cur = start;
|
2007-06-10 04:14:53 +00:00
|
|
|
uint this_delay, vgaPeriod;
|
2006-10-11 15:10:59 +00:00
|
|
|
|
2007-02-16 13:55:01 +00:00
|
|
|
AudioCD.updateCD();
|
|
|
|
|
2006-10-11 15:10:59 +00:00
|
|
|
if (_debugger->isAttached())
|
|
|
|
_debugger->onFrame();
|
|
|
|
|
2007-06-10 04:14:53 +00:00
|
|
|
vgaPeriod = (_fastMode) ? 10 : _vgaPeriod;
|
|
|
|
if (getGameType() == GType_PP && getGameId() != GID_DIMP) {
|
|
|
|
if (vgaPeriod == 15 && _variableArray[999] == 0)
|
|
|
|
vgaPeriod = 30;
|
|
|
|
}
|
2006-10-11 15:10:59 +00:00
|
|
|
|
|
|
|
_rnd.getRandomNumber(2);
|
|
|
|
|
|
|
|
do {
|
2007-06-10 04:14:53 +00:00
|
|
|
while (!_inCallBack && cur >= _lastVgaTick + vgaPeriod && !_pause) {
|
|
|
|
_lastVgaTick += vgaPeriod;
|
2006-10-11 15:10:59 +00:00
|
|
|
|
|
|
|
// don't get too many frames behind
|
2007-06-10 04:14:53 +00:00
|
|
|
if (cur >= _lastVgaTick + vgaPeriod * 2)
|
2006-10-11 15:10:59 +00:00
|
|
|
_lastVgaTick = cur;
|
|
|
|
|
|
|
|
_inCallBack = true;
|
|
|
|
timer_callback();
|
|
|
|
_inCallBack = false;
|
|
|
|
}
|
|
|
|
|
2007-04-01 17:36:13 +00:00
|
|
|
while (_eventMan->pollEvent(event)) {
|
2006-10-11 15:10:59 +00:00
|
|
|
switch (event.type) {
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_KEYDOWN:
|
2006-10-11 15:10:59 +00:00
|
|
|
if (event.kbd.keycode >= '0' && event.kbd.keycode <='9'
|
2007-03-17 19:02:05 +00:00
|
|
|
&& (event.kbd.flags == Common::KBD_ALT ||
|
|
|
|
event.kbd.flags == Common::KBD_CTRL)) {
|
2006-10-11 15:10:59 +00:00
|
|
|
_saveLoadSlot = event.kbd.keycode - '0';
|
|
|
|
|
|
|
|
// There is no save slot 0
|
|
|
|
if (_saveLoadSlot == 0)
|
|
|
|
_saveLoadSlot = 10;
|
|
|
|
|
2007-06-08 07:50:28 +00:00
|
|
|
memset(_saveLoadName, 0, sizeof(_saveLoadName));
|
2007-05-22 10:31:51 +00:00
|
|
|
sprintf(_saveLoadName, "Quick %d", _saveLoadSlot);
|
2007-03-17 19:02:05 +00:00
|
|
|
_saveLoadType = (event.kbd.flags == Common::KBD_ALT) ? 1 : 2;
|
2006-10-11 15:10:59 +00:00
|
|
|
|
|
|
|
// We should only allow a load or save when it was possible in original
|
|
|
|
// This stops load/save during copy protection, conversations and cut scenes
|
|
|
|
if (!_mouseHideCount && !_showPreposition)
|
|
|
|
quickLoadOrSave();
|
2007-03-17 19:02:05 +00:00
|
|
|
} else if (event.kbd.flags == Common::KBD_CTRL) {
|
2006-10-11 15:10:59 +00:00
|
|
|
if (event.kbd.keycode == 'a') {
|
|
|
|
GUI::Dialog *_aboutDialog;
|
|
|
|
_aboutDialog = new GUI::AboutDialog();
|
|
|
|
_aboutDialog->runModal();
|
2007-06-05 11:46:39 +00:00
|
|
|
} else if (event.kbd.keycode == 'f') {
|
2006-10-11 15:10:59 +00:00
|
|
|
_fastMode ^= 1;
|
2007-06-05 11:46:39 +00:00
|
|
|
} else if (event.kbd.keycode == 'd') {
|
2006-10-11 15:10:59 +00:00
|
|
|
_debugger->attach();
|
2007-06-05 11:46:39 +00:00
|
|
|
} else if (event.kbd.keycode == 'u') {
|
|
|
|
dumpAllSubroutines();
|
|
|
|
}
|
2006-10-11 15:10:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (getGameType() == GType_PP) {
|
2007-03-17 19:02:05 +00:00
|
|
|
if (event.kbd.flags == Common::KBD_SHIFT)
|
2006-10-11 15:10:59 +00:00
|
|
|
_variableArray[41] = 0;
|
|
|
|
else
|
|
|
|
_variableArray[41] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure backspace works right (this fixes a small issue on OS X)
|
|
|
|
if (event.kbd.keycode == 8)
|
|
|
|
_keyPressed = 8;
|
|
|
|
else
|
|
|
|
_keyPressed = (byte)event.kbd.ascii;
|
|
|
|
break;
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_MOUSEMOVE:
|
2006-10-11 15:10:59 +00:00
|
|
|
break;
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
2006-10-11 15:10:59 +00:00
|
|
|
if (getGameType() == GType_FF)
|
|
|
|
setBitFlag(89, true);
|
|
|
|
_leftButtonDown++;
|
2006-10-22 13:04:34 +00:00
|
|
|
_leftButton = 1;
|
2006-10-11 15:10:59 +00:00
|
|
|
break;
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_LBUTTONUP:
|
2006-10-11 15:10:59 +00:00
|
|
|
if (getGameType() == GType_FF)
|
|
|
|
setBitFlag(89, false);
|
2006-10-22 13:04:34 +00:00
|
|
|
|
|
|
|
_leftButton = 0;
|
|
|
|
_leftButtonCount = 0;
|
2007-06-05 11:38:26 +00:00
|
|
|
_leftClick = true;
|
2006-10-11 15:10:59 +00:00
|
|
|
break;
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_RBUTTONDOWN:
|
2006-10-11 15:10:59 +00:00
|
|
|
if (getGameType() == GType_FF)
|
|
|
|
setBitFlag(92, false);
|
|
|
|
_rightButtonDown++;
|
|
|
|
break;
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_QUIT:
|
2006-10-11 15:10:59 +00:00
|
|
|
shutdown();
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-22 13:04:34 +00:00
|
|
|
if (_leftButton == 1)
|
|
|
|
_leftButtonCount++;
|
|
|
|
|
2007-02-16 13:55:01 +00:00
|
|
|
AudioCD.updateCD();
|
|
|
|
|
2006-10-11 15:10:59 +00:00
|
|
|
_system->updateScreen();
|
|
|
|
|
|
|
|
if (amount == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
this_delay = _fastMode ? 1 : 20;
|
|
|
|
if (this_delay > amount)
|
|
|
|
this_delay = amount;
|
|
|
|
_system->delayMillis(this_delay);
|
|
|
|
|
|
|
|
cur = _system->getMillis();
|
|
|
|
} while (cur < start + amount);
|
|
|
|
}
|
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
void AGOSEngine::timer_callback() {
|
2007-06-10 04:36:44 +00:00
|
|
|
if (getGameId() == GID_DIMP) {
|
|
|
|
_lastTickCount = _system->getMillis();
|
|
|
|
|
|
|
|
timer_proc1();
|
|
|
|
dimp_idle();
|
|
|
|
} else {
|
|
|
|
timer_proc1();
|
|
|
|
}
|
2006-04-29 14:11:29 +00:00
|
|
|
}
|
|
|
|
|
2007-05-13 13:19:46 +00:00
|
|
|
void AGOSEngine_Feeble::timer_proc1() {
|
2006-04-29 14:11:29 +00:00
|
|
|
if (_lockWord & 0x80E9 || _lockWord & 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_syncCount++;
|
|
|
|
|
|
|
|
_lockWord |= 2;
|
|
|
|
|
|
|
|
if (!(_lockWord & 0x10)) {
|
2007-05-13 13:19:46 +00:00
|
|
|
_syncFlag2 ^= 1;
|
|
|
|
if (!_syncFlag2) {
|
2006-04-29 14:11:29 +00:00
|
|
|
processVgaEvents();
|
2007-05-13 13:19:46 +00:00
|
|
|
} else {
|
|
|
|
// Double speed on Oracle
|
|
|
|
if (getGameType() == GType_FF && getBitFlag(99)) {
|
2006-04-29 14:11:29 +00:00
|
|
|
processVgaEvents();
|
2007-05-13 13:19:46 +00:00
|
|
|
} else if (_scrollCount == 0) {
|
2006-04-29 14:11:29 +00:00
|
|
|
_lockWord &= ~2;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-17 09:00:14 +00:00
|
|
|
if (getGameType() == GType_FF) {
|
|
|
|
_moviePlay->nextFrame();
|
|
|
|
}
|
2006-04-29 14:11:29 +00:00
|
|
|
|
2007-05-17 09:00:14 +00:00
|
|
|
animateSprites();
|
|
|
|
}
|
2007-05-13 13:19:46 +00:00
|
|
|
|
2006-04-29 14:11:29 +00:00
|
|
|
if (_copyPartialMode == 2) {
|
2007-05-13 08:46:48 +00:00
|
|
|
fillFrontFromBack(0, 0, _screenWidth, _screenHeight);
|
2006-04-29 14:11:29 +00:00
|
|
|
_copyPartialMode = 0;
|
|
|
|
}
|
|
|
|
|
2007-05-13 08:46:48 +00:00
|
|
|
if (_displayScreen) {
|
2006-04-29 14:11:29 +00:00
|
|
|
if (getGameType() == GType_FF) {
|
|
|
|
if (!getBitFlag(78)) {
|
|
|
|
oracleLogo();
|
|
|
|
}
|
|
|
|
if (getBitFlag(76)) {
|
|
|
|
swapCharacterLogo();
|
|
|
|
}
|
|
|
|
}
|
2007-05-13 13:19:46 +00:00
|
|
|
handleMouseMoved();
|
|
|
|
displayScreen();
|
|
|
|
_displayScreen = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
_lockWord &= ~2;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AGOSEngine::timer_proc1() {
|
|
|
|
if (_lockWord & 0x80E9 || _lockWord & 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_syncCount++;
|
|
|
|
|
|
|
|
_lockWord |= 2;
|
|
|
|
|
|
|
|
handleMouseMoved();
|
|
|
|
|
|
|
|
if (!(_lockWord & 0x10)) {
|
|
|
|
processVgaEvents();
|
|
|
|
processVgaEvents();
|
|
|
|
_cepeFlag ^= 1;
|
|
|
|
if (!_cepeFlag)
|
|
|
|
processVgaEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_updateScreen) {
|
|
|
|
_system->copyRectToScreen(getFrontBuf(), _screenWidth, 0, 0, _screenWidth, _screenHeight);
|
|
|
|
_system->updateScreen();
|
|
|
|
|
|
|
|
_updateScreen = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_displayScreen) {
|
2007-05-13 08:46:48 +00:00
|
|
|
displayScreen();
|
|
|
|
_displayScreen = false;
|
2006-04-29 14:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_lockWord &= ~2;
|
|
|
|
}
|
|
|
|
|
2007-05-16 05:57:26 +00:00
|
|
|
void AGOSEngine::dimp_idle() {
|
|
|
|
int z, n;
|
|
|
|
|
|
|
|
_iconToggleCount++;
|
|
|
|
if (_iconToggleCount == 30) {
|
|
|
|
if ((_variableArray[110] < 3) || (_variableArray[111] < 3) || (_variableArray[112] < 3)) {
|
|
|
|
_voiceCount++;
|
|
|
|
if (_voiceCount == 50) {
|
|
|
|
if (!getBitFlag(14) && !getBitFlag(11) && !getBitFlag(13)) {
|
|
|
|
loadSoundFile("Whistle.WAV");
|
|
|
|
z = 0;
|
|
|
|
while (z == 0) {
|
|
|
|
n = _rnd.getRandomNumber(2);
|
|
|
|
switch (n) {
|
|
|
|
case(0):
|
|
|
|
if (_variableArray[110] > 2)
|
|
|
|
break;
|
|
|
|
n = _rnd.getRandomNumber(6);
|
|
|
|
switch(n) {
|
|
|
|
case(0): loadSoundFile("And01.wav");break;
|
|
|
|
case(1): loadSoundFile("And02.wav");break;
|
|
|
|
case(2): loadSoundFile("And03.wav");break;
|
|
|
|
case(3): loadSoundFile("And04.wav");break;
|
|
|
|
case(4): loadSoundFile("And05.wav");break;
|
|
|
|
case(5): loadSoundFile("And06.wav");break;
|
|
|
|
case(6): loadSoundFile("And07.wav");break;
|
|
|
|
}
|
|
|
|
z = 1;
|
|
|
|
break;
|
|
|
|
case(1):
|
|
|
|
if (_variableArray[111] > 2)
|
|
|
|
break;
|
|
|
|
n = _rnd.getRandomNumber(6);
|
|
|
|
switch(n) {
|
|
|
|
case(0): loadSoundFile("And08.wav");break;
|
|
|
|
case(1): loadSoundFile("And09.wav");break;
|
|
|
|
case(2): loadSoundFile("And0a.wav");break;
|
|
|
|
case(3): loadSoundFile("And0b.wav");break;
|
|
|
|
case(4): loadSoundFile("And0c.wav");break;
|
|
|
|
case(5): loadSoundFile("And0d.wav");break;
|
|
|
|
case(6): loadSoundFile("And0e.wav");break;
|
|
|
|
}
|
|
|
|
z = 1;
|
|
|
|
break;
|
|
|
|
case(2):
|
|
|
|
if (_variableArray[112] > 2)
|
|
|
|
break;
|
|
|
|
n = _rnd.getRandomNumber(4);
|
|
|
|
switch(n) {
|
|
|
|
case(0): loadSoundFile("And0f.wav");break;
|
|
|
|
case(1): loadSoundFile("And0g.wav");break;
|
|
|
|
case(2): loadSoundFile("And0h.wav");break;
|
|
|
|
case(3): loadSoundFile("And0i.wav");break;
|
|
|
|
case(4): loadSoundFile("And0j.wav");break;
|
|
|
|
}
|
|
|
|
z = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_voiceCount = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_voiceCount = 48;
|
|
|
|
}
|
|
|
|
_iconToggleCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_variableArray[121] == 0) {
|
|
|
|
_variableArray[121]++;
|
|
|
|
_startSecondCount = _lastTickCount;
|
|
|
|
}
|
|
|
|
if (((_lastTickCount - _startSecondCount) / 1000) != _tSecondCount) {
|
|
|
|
if (_startSecondCount != 0) {
|
|
|
|
uint32 x = (_variableArray[123] * 65536) + _variableArray[122] + ((_lastTickCount - _startSecondCount) / 1000) - _tSecondCount;
|
|
|
|
_variableArray[122] = (uint16)(x % 65536);
|
|
|
|
_variableArray[123] = (uint16)(x / 65536);
|
|
|
|
_tSecondCount = (_lastTickCount - _startSecondCount) / 1000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
} // End of namespace AGOS
|