2006-05-23 23:43:52 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2006 The ScummVM project
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999-2003 Sarien Team
|
|
|
|
*
|
|
|
|
* 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-12-19 01:11:41 +00:00
|
|
|
|
2007-03-17 00:53:21 +00:00
|
|
|
#include "common/events.h"
|
2006-05-23 23:43:52 +00:00
|
|
|
#include "common/file.h"
|
2006-06-24 08:07:48 +00:00
|
|
|
#include "common/fs.h"
|
2006-05-23 23:43:52 +00:00
|
|
|
#include "common/savefile.h"
|
|
|
|
#include "common/config-manager.h"
|
|
|
|
|
|
|
|
#include "base/plugins.h"
|
2007-01-12 02:31:04 +00:00
|
|
|
#include "base/version.h"
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2006-05-25 22:51:42 +00:00
|
|
|
#include "graphics/cursorman.h"
|
|
|
|
|
2006-05-23 23:43:52 +00:00
|
|
|
#include "sound/mididrv.h"
|
|
|
|
#include "sound/mixer.h"
|
|
|
|
|
|
|
|
#include "agi/agi.h"
|
|
|
|
#include "agi/graphics.h"
|
|
|
|
#include "agi/sprite.h"
|
|
|
|
#include "agi/opcodes.h"
|
|
|
|
#include "agi/keyboard.h"
|
|
|
|
#include "agi/menu.h"
|
2006-12-06 19:27:02 +00:00
|
|
|
#include "agi/sound.h"
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2006-12-19 01:11:41 +00:00
|
|
|
|
|
|
|
|
2006-05-23 23:43:52 +00:00
|
|
|
namespace Agi {
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
static uint32 g_tickTimer;
|
2006-12-06 19:27:02 +00:00
|
|
|
struct Mouse g_mouse;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-03-17 16:08:29 +00:00
|
|
|
void AgiEngine::allowSynthetic(bool allow) {
|
|
|
|
_allowSynthetic = allow;
|
|
|
|
}
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
void AgiEngine::processEvents() {
|
2007-03-17 19:02:05 +00:00
|
|
|
Common::Event event;
|
2006-05-23 23:43:52 +00:00
|
|
|
int key = 0;
|
|
|
|
|
2007-04-01 17:36:13 +00:00
|
|
|
while (_eventMan->pollEvent(event)) {
|
2006-05-23 23:43:52 +00:00
|
|
|
switch (event.type) {
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_QUIT:
|
2006-12-06 19:27:02 +00:00
|
|
|
_gfx->deinitVideo();
|
|
|
|
_gfx->deinitMachine();
|
2007-03-17 00:53:21 +00:00
|
|
|
_system->quit();
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
2006-05-23 23:43:52 +00:00
|
|
|
key = BUTTON_LEFT;
|
2006-12-06 19:27:02 +00:00
|
|
|
g_mouse.button = 1;
|
2007-01-16 12:40:51 +00:00
|
|
|
keyEnqueue(key);
|
2006-12-06 19:27:02 +00:00
|
|
|
g_mouse.x = event.mouse.x;
|
|
|
|
g_mouse.y = event.mouse.y;
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_RBUTTONDOWN:
|
2006-05-23 23:43:52 +00:00
|
|
|
key = BUTTON_RIGHT;
|
2006-12-06 19:27:02 +00:00
|
|
|
g_mouse.button = 2;
|
2007-01-16 12:40:51 +00:00
|
|
|
keyEnqueue(key);
|
2006-12-06 19:27:02 +00:00
|
|
|
g_mouse.x = event.mouse.x;
|
|
|
|
g_mouse.y = event.mouse.y;
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_WHEELUP:
|
2007-03-12 08:43:13 +00:00
|
|
|
key = WHEEL_UP;
|
|
|
|
keyEnqueue(key);
|
|
|
|
break;
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_WHEELDOWN:
|
2007-03-12 08:43:13 +00:00
|
|
|
key = WHEEL_DOWN;
|
|
|
|
keyEnqueue(key);
|
|
|
|
break;
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_MOUSEMOVE:
|
2006-12-06 19:27:02 +00:00
|
|
|
g_mouse.x = event.mouse.x;
|
|
|
|
g_mouse.y = event.mouse.y;
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_LBUTTONUP:
|
|
|
|
case Common::EVENT_RBUTTONUP:
|
2006-12-06 19:27:02 +00:00
|
|
|
g_mouse.button = 0;
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
2007-03-17 19:02:05 +00:00
|
|
|
case Common::EVENT_KEYDOWN:
|
2007-01-16 12:40:51 +00:00
|
|
|
_keyControl = 0;
|
|
|
|
_keyAlt = 0;
|
2006-05-28 11:52:24 +00:00
|
|
|
|
2007-03-17 19:02:05 +00:00
|
|
|
if (event.kbd.flags == Common::KBD_CTRL && event.kbd.keycode == 'd') {
|
2006-05-28 11:52:24 +00:00
|
|
|
_console->attach();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-03-17 19:02:05 +00:00
|
|
|
if (event.kbd.flags & Common::KBD_CTRL)
|
2007-01-16 12:40:51 +00:00
|
|
|
_keyControl = 1;
|
2006-12-19 01:11:41 +00:00
|
|
|
|
2007-03-17 19:02:05 +00:00
|
|
|
if (event.kbd.flags & Common::KBD_ALT)
|
2007-01-16 12:40:51 +00:00
|
|
|
_keyAlt = 1;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
switch (key = event.kbd.keycode) {
|
|
|
|
case 256 + 20: // left arrow
|
2006-05-28 11:08:46 +00:00
|
|
|
case 260: // key pad 4
|
2007-03-17 16:08:29 +00:00
|
|
|
if (_allowSynthetic || !event.synthetic)
|
2007-03-17 15:44:26 +00:00
|
|
|
key = KEY_LEFT;
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
|
|
|
case 256 + 19: // right arrow
|
2006-05-28 11:08:46 +00:00
|
|
|
case 262: // key pad 6
|
2007-03-17 16:08:29 +00:00
|
|
|
if (_allowSynthetic || !event.synthetic)
|
2007-03-17 15:44:26 +00:00
|
|
|
key = KEY_RIGHT;
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
|
|
|
case 256 + 17: // up arrow
|
2006-05-28 11:08:46 +00:00
|
|
|
case 264: // key pad 8
|
2007-03-17 16:08:29 +00:00
|
|
|
if (_allowSynthetic || !event.synthetic)
|
2007-03-17 15:44:26 +00:00
|
|
|
key = KEY_UP;
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
|
|
|
case 256 + 18: // down arrow
|
2006-05-28 11:08:46 +00:00
|
|
|
case 258: // key pad 2
|
2007-03-17 16:08:29 +00:00
|
|
|
if (_allowSynthetic || !event.synthetic)
|
2007-03-17 15:44:26 +00:00
|
|
|
key = KEY_DOWN;
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
|
|
|
case 256 + 24: // page up
|
2006-05-28 11:08:46 +00:00
|
|
|
case 265: // key pad 9
|
2007-03-17 16:08:29 +00:00
|
|
|
if (_allowSynthetic || !event.synthetic)
|
2007-03-17 15:44:26 +00:00
|
|
|
key = KEY_UP_RIGHT;
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
|
|
|
case 256 + 25: // page down
|
2006-05-28 11:08:46 +00:00
|
|
|
case 259: // key pad 3
|
2007-03-17 16:08:29 +00:00
|
|
|
if (_allowSynthetic || !event.synthetic)
|
2007-03-17 15:44:26 +00:00
|
|
|
key = KEY_DOWN_RIGHT;
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
|
|
|
case 256 + 22: // home
|
2006-05-28 11:08:46 +00:00
|
|
|
case 263: // key pad 7
|
2007-03-17 16:08:29 +00:00
|
|
|
if (_allowSynthetic || !event.synthetic)
|
2007-03-17 15:44:26 +00:00
|
|
|
key = KEY_UP_LEFT;
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
|
|
|
case 256 + 23: // end
|
2006-05-28 11:08:46 +00:00
|
|
|
case 257: // key pad 1
|
2007-03-17 16:08:29 +00:00
|
|
|
if (_allowSynthetic || !event.synthetic)
|
2007-03-17 15:44:26 +00:00
|
|
|
key = KEY_DOWN_LEFT;
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
2006-05-28 11:08:46 +00:00
|
|
|
case 261: // key pad 5
|
|
|
|
key = KEY_STATIONARY;
|
|
|
|
break;
|
2006-05-23 23:43:52 +00:00
|
|
|
case '+':
|
|
|
|
key = '+';
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
key = '-';
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
key = 0x0009;
|
|
|
|
break;
|
|
|
|
case 282:
|
|
|
|
key = 0x3b00;
|
|
|
|
break;
|
|
|
|
case 283:
|
|
|
|
key = 0x3c00;
|
|
|
|
break;
|
|
|
|
case 284:
|
|
|
|
key = 0x3d00;
|
|
|
|
break;
|
|
|
|
case 285:
|
|
|
|
key = 0x3e00;
|
|
|
|
break;
|
|
|
|
case 286:
|
|
|
|
key = 0x3f00;
|
|
|
|
break;
|
|
|
|
case 287:
|
|
|
|
key = 0x4000;
|
|
|
|
break;
|
|
|
|
case 288:
|
|
|
|
key = 0x4100;
|
|
|
|
break;
|
|
|
|
case 289:
|
|
|
|
key = 0x4200;
|
|
|
|
break;
|
|
|
|
case 290:
|
|
|
|
key = 0x4300;
|
|
|
|
break;
|
|
|
|
case 291:
|
2006-05-28 11:52:24 +00:00
|
|
|
key = 0x4400;
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
|
|
|
case 292:
|
|
|
|
key = KEY_STATUSLN;
|
|
|
|
break;
|
|
|
|
case 293:
|
|
|
|
key = KEY_PRIORITY;
|
|
|
|
break;
|
|
|
|
case 27:
|
|
|
|
key = 0x1b;
|
|
|
|
break;
|
|
|
|
case '\n':
|
|
|
|
case '\r':
|
|
|
|
key = KEY_ENTER;
|
|
|
|
break;
|
|
|
|
default:
|
2006-06-01 13:57:19 +00:00
|
|
|
if (key < 256 && !isalpha(key)) {
|
2006-09-04 18:57:12 +00:00
|
|
|
// Make sure backspace works right (this fixes a small issue on OS X)
|
|
|
|
if (key != 8)
|
|
|
|
key = event.kbd.ascii;
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
2006-06-01 13:57:19 +00:00
|
|
|
}
|
2007-01-16 12:40:51 +00:00
|
|
|
if (_keyControl)
|
2006-05-23 23:43:52 +00:00
|
|
|
key = (key & ~0x20) - 0x40;
|
2007-01-16 12:40:51 +00:00
|
|
|
else if (_keyAlt)
|
|
|
|
key = scancodeTable[(key & ~0x20) - 0x41] << 8;
|
2007-03-17 19:02:05 +00:00
|
|
|
else if (event.kbd.flags & Common::KBD_SHIFT)
|
2006-06-01 13:57:19 +00:00
|
|
|
key = event.kbd.ascii;
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (key)
|
2007-01-16 12:40:51 +00:00
|
|
|
keyEnqueue(key);
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
int AgiEngine::agiIsKeypressLow() {
|
|
|
|
processEvents();
|
2007-01-16 12:40:51 +00:00
|
|
|
return _keyQueueStart != _keyQueueEnd;
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
void AgiEngine::agiTimerLow() {
|
2006-05-23 23:43:52 +00:00
|
|
|
static uint32 m = 0;
|
|
|
|
uint32 dm;
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (g_tickTimer < m)
|
2006-05-23 23:43:52 +00:00
|
|
|
m = 0;
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
while ((dm = g_tickTimer - m) < 5) {
|
2006-12-06 19:27:02 +00:00
|
|
|
processEvents();
|
2006-05-24 21:40:24 +00:00
|
|
|
if (_console->isAttached())
|
|
|
|
_console->onFrame();
|
2007-03-17 00:53:21 +00:00
|
|
|
_system->delayMillis(10);
|
|
|
|
_system->updateScreen();
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
2007-01-16 12:40:51 +00:00
|
|
|
m = g_tickTimer;
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
int AgiEngine::agiGetKeypressLow() {
|
2006-05-23 23:43:52 +00:00
|
|
|
int k;
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
while (_keyQueueStart == _keyQueueEnd) /* block */
|
2006-12-06 19:27:02 +00:00
|
|
|
agiTimerLow();
|
2007-01-16 12:40:51 +00:00
|
|
|
keyDequeue(k);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
void AgiEngine::agiTimerFunctionLow(void *refCon) {
|
2007-01-16 12:40:51 +00:00
|
|
|
g_tickTimer++;
|
2006-12-06 19:27:02 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
void AgiEngine::clearImageStack(void) {
|
|
|
|
_imageStackPointer = 0;
|
2006-12-06 19:27:02 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
void AgiEngine::releaseImageStack(void) {
|
|
|
|
if (_imageStack)
|
|
|
|
free(_imageStack);
|
|
|
|
_imageStack = NULL;
|
|
|
|
_stackSize = 0;
|
2007-01-16 13:09:42 +00:00
|
|
|
_imageStackPointer = 0;
|
2006-12-06 19:27:02 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
void AgiEngine::recordImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
|
2006-12-06 19:27:02 +00:00
|
|
|
int16 p4, int16 p5, int16 p6, int16 p7) {
|
2007-01-16 12:40:51 +00:00
|
|
|
struct ImageStackElement *pnew;
|
2006-12-06 19:27:02 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (_imageStackPointer == _stackSize) {
|
|
|
|
if (_stackSize == 0) { /* first call */
|
|
|
|
_imageStack = (ImageStackElement *)malloc(INITIAL_IMAGE_STACK_SIZE * sizeof(ImageStackElement));
|
|
|
|
_stackSize = INITIAL_IMAGE_STACK_SIZE;
|
2006-12-06 19:27:02 +00:00
|
|
|
} else { /* has to grow */
|
2007-01-16 12:40:51 +00:00
|
|
|
struct ImageStackElement *newStack;
|
|
|
|
newStack = (ImageStackElement *)malloc(2 * _stackSize * sizeof(ImageStackElement));
|
|
|
|
memcpy(newStack, _imageStack, _stackSize * sizeof(ImageStackElement));
|
|
|
|
free(_imageStack);
|
|
|
|
_imageStack = newStack;
|
|
|
|
_stackSize *= 2;
|
2006-12-06 19:27:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
pnew = &_imageStack[_imageStackPointer];
|
|
|
|
_imageStackPointer++;
|
2006-12-06 19:27:02 +00:00
|
|
|
|
|
|
|
pnew->type = type;
|
|
|
|
pnew->parm1 = p1;
|
|
|
|
pnew->parm2 = p2;
|
|
|
|
pnew->parm3 = p3;
|
|
|
|
pnew->parm4 = p4;
|
|
|
|
pnew->parm5 = p5;
|
|
|
|
pnew->parm6 = p6;
|
|
|
|
pnew->parm7 = p7;
|
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
void AgiEngine::replayImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
|
2006-12-06 19:27:02 +00:00
|
|
|
int16 p4, int16 p5, int16 p6, int16 p7) {
|
|
|
|
switch (type) {
|
|
|
|
case ADD_PIC:
|
|
|
|
debugC(8, kDebugLevelMain, "--- decoding picture %d ---", p1);
|
|
|
|
agiLoadResource(rPICTURE, p1);
|
2007-01-16 12:40:51 +00:00
|
|
|
_picture->decodePicture(p1, p2);
|
2006-12-06 19:27:02 +00:00
|
|
|
break;
|
|
|
|
case ADD_VIEW:
|
|
|
|
agiLoadResource(rVIEW, p1);
|
2007-01-16 12:40:51 +00:00
|
|
|
_sprites->addToPic(p1, p2, p3, p4, p5, p6, p7);
|
2006-12-06 19:27:02 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
void AgiEngine::initPriTable() {
|
2006-05-23 23:43:52 +00:00
|
|
|
int i, p, y = 0;
|
|
|
|
|
|
|
|
for (p = 1; p < 15; p++) {
|
|
|
|
for (i = 0; i < 12; i++) {
|
2007-01-16 12:40:51 +00:00
|
|
|
_game.priTable[y++] = p < 4 ? 4 : p;
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
int AgiEngine::agiInit() {
|
2006-05-23 23:43:52 +00:00
|
|
|
int ec, i;
|
|
|
|
|
|
|
|
debug(2, "initializing");
|
2007-01-16 12:40:51 +00:00
|
|
|
debug(2, "game.ver = 0x%x", _game.ver);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
/* reset all flags to false and all variables to 0 */
|
|
|
|
for (i = 0; i < MAX_FLAGS; i++)
|
2007-01-16 12:40:51 +00:00
|
|
|
_game.flags[i] = 0;
|
2006-05-23 23:43:52 +00:00
|
|
|
for (i = 0; i < MAX_VARS; i++)
|
2007-01-16 12:40:51 +00:00
|
|
|
_game.vars[i] = 0;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
/* clear all resources and events */
|
|
|
|
for (i = 0; i < MAX_DIRS; i++) {
|
2007-01-16 12:40:51 +00:00
|
|
|
memset(&_game.views[i], 0, sizeof(struct AgiView));
|
|
|
|
memset(&_game.pictures[i], 0, sizeof(struct AgiPicture));
|
|
|
|
memset(&_game.logics[i], 0, sizeof(struct AgiLogic));
|
|
|
|
memset(&_game.sounds[i], 0, sizeof(struct AgiSound));
|
|
|
|
memset(&_game.dirView[i], 0, sizeof(struct AgiDir));
|
|
|
|
memset(&_game.dirPic[i], 0, sizeof(struct AgiDir));
|
|
|
|
memset(&_game.dirLogic[i], 0, sizeof(struct AgiDir));
|
|
|
|
memset(&_game.dirSound[i], 0, sizeof(struct AgiDir));
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* clear view table */
|
|
|
|
for (i = 0; i < MAX_VIEWTABLE; i++)
|
2007-02-03 21:37:52 +00:00
|
|
|
memset(&_game.viewTable[i], 0, sizeof(VtEntry));
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
initWords();
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (!_menu)
|
|
|
|
_menu = new Menu(this, _gfx, _picture);
|
2006-09-07 16:13:41 +00:00
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
initPriTable();
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
/* clear string buffer */
|
|
|
|
for (i = 0; i < MAX_STRINGS; i++)
|
2007-01-16 12:40:51 +00:00
|
|
|
_game.strings[i][0] = 0;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
/* setup emulation */
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
switch (_loader->getIntVersion() >> 12) {
|
2006-05-23 23:43:52 +00:00
|
|
|
case 2:
|
|
|
|
report("Emulating Sierra AGI v%x.%03x\n",
|
2006-12-19 01:11:41 +00:00
|
|
|
(int)(agiGetRelease() >> 12) & 0xF,
|
|
|
|
(int)(agiGetRelease()) & 0xFFF);
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
report("Emulating Sierra AGI v%x.002.%03x\n",
|
2006-12-20 23:59:09 +00:00
|
|
|
(int)(agiGetRelease() >> 12) & 0xF,
|
|
|
|
(int)(agiGetRelease()) & 0xFFF);
|
2006-05-23 23:43:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-02-13 15:27:36 +00:00
|
|
|
if (getPlatform() == Common::kPlatformAmiga)
|
|
|
|
_game.gameFlags |= ID_AMIGA;
|
|
|
|
|
|
|
|
if (getFeatures() & GF_AGDS)
|
|
|
|
_game.gameFlags |= ID_AGDS;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (_game.gameFlags & ID_AMIGA)
|
2006-05-23 23:43:52 +00:00
|
|
|
report("Amiga padded game detected.\n");
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (_game.gameFlags & ID_AGDS)
|
2006-05-23 23:43:52 +00:00
|
|
|
report("AGDS mode enabled.\n");
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
ec = _loader->init(); /* load vol files, etc */
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (ec == errOK)
|
|
|
|
ec = _loader->loadObjects(OBJECTS);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
/* note: demogs has no words.tok */
|
2007-01-16 12:40:51 +00:00
|
|
|
if (ec == errOK)
|
|
|
|
ec = _loader->loadWords(WORDS);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
/* FIXME: load IIgs instruments and samples */
|
|
|
|
/* load_instruments("kq.sys16"); */
|
|
|
|
|
|
|
|
/* Load logic 0 into memory */
|
2007-01-16 12:40:51 +00:00
|
|
|
if (ec == errOK)
|
|
|
|
ec = _loader->loadResource(rLOGIC, 0);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-04-21 21:35:30 +00:00
|
|
|
|
|
|
|
if (ConfMan.hasKey("save_slot")) {
|
|
|
|
char saveNameBuffer[256];
|
|
|
|
|
|
|
|
snprintf (saveNameBuffer, 256, "%s.%03d", _targetName.c_str(), ConfMan.getInt("save_slot"));
|
|
|
|
|
|
|
|
loadGame(saveNameBuffer);
|
|
|
|
}
|
|
|
|
|
2006-05-23 23:43:52 +00:00
|
|
|
return ec;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Public functions
|
|
|
|
*/
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
void AgiEngine::agiUnloadResources() {
|
2006-05-23 23:43:52 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Make sure logic 0 is always loaded */
|
|
|
|
for (i = 1; i < MAX_DIRS; i++) {
|
2007-01-16 12:40:51 +00:00
|
|
|
_loader->unloadResource(rLOGIC, i);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < MAX_DIRS; i++) {
|
2007-01-16 12:40:51 +00:00
|
|
|
_loader->unloadResource(rVIEW, i);
|
|
|
|
_loader->unloadResource(rPICTURE, i);
|
|
|
|
_loader->unloadResource(rSOUND, i);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
int AgiEngine::agiDeinit() {
|
2006-05-23 23:43:52 +00:00
|
|
|
int ec;
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
cleanInput(); /* remove all words from memory */
|
2006-12-06 19:27:02 +00:00
|
|
|
agiUnloadResources(); /* unload resources in memory */
|
2007-01-16 12:40:51 +00:00
|
|
|
_loader->unloadResource(rLOGIC, 0);
|
|
|
|
ec = _loader->deinit();
|
|
|
|
unloadObjects();
|
|
|
|
unloadWords();
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
clearImageStack();
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
return ec;
|
|
|
|
}
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
int AgiEngine::agiDetectGame() {
|
2007-01-16 12:40:51 +00:00
|
|
|
int ec = errOK;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-07 18:02:54 +00:00
|
|
|
assert(_gameDescription != NULL);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-21 20:24:38 +00:00
|
|
|
if(getVersion() <= 0x2999) {
|
2007-01-16 12:40:51 +00:00
|
|
|
_loader = new AgiLoader_v2(this);
|
2007-01-07 18:02:54 +00:00
|
|
|
} else {
|
2007-01-16 12:40:51 +00:00
|
|
|
_loader = new AgiLoader_v3(this);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
2007-01-16 12:40:51 +00:00
|
|
|
ec = _loader->detectGame();
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
return ec;
|
|
|
|
}
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
int AgiEngine::agiVersion() {
|
2007-01-16 12:40:51 +00:00
|
|
|
return _loader->version();
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
int AgiEngine::agiGetRelease() {
|
2007-01-16 12:40:51 +00:00
|
|
|
return _loader->getIntVersion();
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
void AgiEngine::agiSetRelease(int n) {
|
2007-01-16 12:40:51 +00:00
|
|
|
_loader->setIntVersion(n);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
int AgiEngine::agiLoadResource(int r, int n) {
|
2006-05-23 23:43:52 +00:00
|
|
|
int i;
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
i = _loader->loadResource(r, n);
|
2006-05-23 23:43:52 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
int AgiEngine::agiUnloadResource(int r, int n) {
|
2007-01-16 12:40:51 +00:00
|
|
|
return _loader->unloadResource(r, n);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct GameSettings {
|
|
|
|
const char *gameid;
|
|
|
|
const char *description;
|
|
|
|
byte id;
|
|
|
|
uint32 features;
|
|
|
|
const char *detectname;
|
|
|
|
};
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
static const GameSettings agiSettings[] = {
|
2006-06-26 13:29:40 +00:00
|
|
|
{"agi", "AGI game", GID_AGI, MDT_ADLIB, "OBJECT"},
|
2006-05-23 23:43:52 +00:00
|
|
|
{NULL, NULL, 0, 0, NULL}
|
|
|
|
};
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
AgiEngine::AgiEngine(OSystem *syst) : Engine(syst) {
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
// Setup mixer
|
|
|
|
if (!_mixer->isReady()) {
|
|
|
|
warning("Sound initialization failed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume"));
|
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume"));
|
|
|
|
|
|
|
|
const GameSettings *g;
|
|
|
|
|
|
|
|
const char *gameid = ConfMan.get("gameid").c_str();
|
2007-01-16 12:40:51 +00:00
|
|
|
for (g = agiSettings; g->gameid; ++g)
|
2006-05-23 23:43:52 +00:00
|
|
|
if (!scumm_stricmp(g->gameid, gameid))
|
|
|
|
_gameId = g->id;
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
_rnd = new Common::RandomSource();
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2006-05-24 13:08:09 +00:00
|
|
|
Common::addSpecialDebugLevel(kDebugLevelMain, "Main", "Generic debug level");
|
|
|
|
Common::addSpecialDebugLevel(kDebugLevelResources, "Resources", "Resources debugging");
|
|
|
|
Common::addSpecialDebugLevel(kDebugLevelSprites, "Sprites", "Sprites debugging");
|
|
|
|
Common::addSpecialDebugLevel(kDebugLevelInventory, "Inventory", "Inventory debugging");
|
|
|
|
Common::addSpecialDebugLevel(kDebugLevelInput, "Input", "Input events debugging");
|
|
|
|
Common::addSpecialDebugLevel(kDebugLevelMenu, "Menu", "Menu debugging");
|
2006-05-25 21:16:49 +00:00
|
|
|
Common::addSpecialDebugLevel(kDebugLevelScripts, "Scripts", "Scripts debugging");
|
2006-05-24 13:08:09 +00:00
|
|
|
Common::addSpecialDebugLevel(kDebugLevelSound, "Sound", "Sound debugging");
|
|
|
|
Common::addSpecialDebugLevel(kDebugLevelText, "Text", "Text output debugging");
|
2007-01-12 02:29:20 +00:00
|
|
|
Common::addSpecialDebugLevel(kDebugLevelSavegame, "Savegame", "Saving & restoring game debugging");
|
2006-05-24 13:08:09 +00:00
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
memset(&_game, 0, sizeof(struct AgiGame));
|
|
|
|
memset(&_debug, 0, sizeof(struct AgiDebug));
|
2006-12-06 19:27:02 +00:00
|
|
|
memset(&g_mouse, 0, sizeof(struct Mouse));
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
_game.clockEnabled = false;
|
|
|
|
_game.state = STATE_INIT;
|
|
|
|
|
|
|
|
_keyQueueStart = 0;
|
|
|
|
_keyQueueEnd = 0;
|
2006-12-06 19:27:02 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
_keyControl = 0;
|
|
|
|
_keyAlt = 0;
|
2006-12-06 19:27:02 +00:00
|
|
|
|
2007-03-17 16:08:29 +00:00
|
|
|
_allowSynthetic = false;
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
g_tickTimer = 0;
|
2006-12-06 19:27:02 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
_intobj = NULL;
|
2006-12-06 19:27:02 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
_stackSize = 0;
|
|
|
|
_imageStack = NULL;
|
|
|
|
_imageStackPointer = 0;
|
2006-12-06 19:27:02 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
_menu = NULL;
|
2006-12-06 19:27:02 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
_lastSentence[0] = 0;
|
|
|
|
memset(&_stringdata, 0, sizeof(struct StringData));
|
2006-12-06 19:27:02 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
_objects = NULL;
|
2006-12-06 19:27:02 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
_oldMode = -1;
|
2007-02-12 00:21:30 +00:00
|
|
|
|
|
|
|
_searchTreeRoot = 0;
|
2007-03-12 08:43:13 +00:00
|
|
|
_firstSlot = 0;
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AgiEngine::initialize() {
|
2006-06-06 15:38:34 +00:00
|
|
|
// TODO: Some sound emulation modes do not fit our current music
|
|
|
|
// drivers, and I'm not sure what they are. For now, they might
|
|
|
|
// as well be called "PC Speaker" and "Not PC Speaker".
|
|
|
|
|
|
|
|
switch (MidiDriver::detectMusicDriver(MDT_PCSPK)) {
|
|
|
|
case MD_PCSPK:
|
2007-02-13 15:27:36 +00:00
|
|
|
_soundemu = SOUND_EMU_PC;
|
2006-06-06 15:38:34 +00:00
|
|
|
break;
|
|
|
|
default:
|
2007-02-13 15:27:36 +00:00
|
|
|
_soundemu = SOUND_EMU_NONE;
|
2006-06-06 15:38:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-02-10 10:27:07 +00:00
|
|
|
if (ConfMan.hasKey("render_mode")) {
|
2007-02-13 15:27:36 +00:00
|
|
|
_renderMode = Common::parseRenderMode(ConfMan.get("render_mode").c_str());
|
2007-02-10 10:27:07 +00:00
|
|
|
} else if (ConfMan.hasKey("platform")) {
|
|
|
|
switch (Common::parsePlatform(ConfMan.get("platform"))) {
|
|
|
|
case Common::kPlatformAmiga:
|
2007-02-13 15:27:36 +00:00
|
|
|
_renderMode = Common::kRenderAmiga;
|
2007-02-10 10:27:07 +00:00
|
|
|
break;
|
|
|
|
case Common::kPlatformPC:
|
2007-02-13 15:27:36 +00:00
|
|
|
_renderMode = Common::kRenderEGA;
|
2007-02-10 10:27:07 +00:00
|
|
|
break;
|
|
|
|
default:
|
2007-02-13 15:27:36 +00:00
|
|
|
_renderMode = Common::kRenderEGA;
|
2007-02-10 10:27:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-05-25 19:46:28 +00:00
|
|
|
|
2006-05-24 21:56:14 +00:00
|
|
|
_console = new Console(this);
|
2006-12-06 19:27:02 +00:00
|
|
|
_gfx = new GfxMgr(this);
|
|
|
|
_sound = new SoundMgr(this, _mixer);
|
|
|
|
_picture = new PictureMgr(this, _gfx);
|
|
|
|
_sprites = new SpritesMgr(this, _gfx);
|
|
|
|
|
|
|
|
_gfx->initMachine();
|
2006-05-24 21:56:14 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
_game.gameFlags = 0;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
_game.colorFg = 15;
|
|
|
|
_game.colorBg = 0;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
_game.name[0] = '\0';
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
_game.sbuf = (uint8 *)calloc(_WIDTH, _HEIGHT);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
_gfx->initVideo();
|
2007-01-16 12:40:51 +00:00
|
|
|
_sound->initSound();
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
_timer->installTimerProc(agiTimerFunctionLow, 10 * 1000, NULL);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
_game.ver = -1; /* Don't display the conf file warning */
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
debugC(2, kDebugLevelMain, "Detect game");
|
2006-12-19 01:11:41 +00:00
|
|
|
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (agiDetectGame() == errOK) {
|
|
|
|
_game.state = STATE_LOADED;
|
2006-05-23 23:43:52 +00:00
|
|
|
debugC(2, kDebugLevelMain, "game loaded");
|
|
|
|
} else {
|
|
|
|
report("Could not open AGI game");
|
|
|
|
}
|
|
|
|
|
|
|
|
debugC(2, kDebugLevelMain, "Init sound");
|
|
|
|
}
|
|
|
|
|
|
|
|
AgiEngine::~AgiEngine() {
|
2006-12-06 19:27:02 +00:00
|
|
|
agiDeinit();
|
2007-01-16 12:40:51 +00:00
|
|
|
_sound->deinitSound();
|
2006-12-06 19:27:02 +00:00
|
|
|
delete _sound;
|
|
|
|
_gfx->deinitVideo();
|
2006-05-30 18:53:01 +00:00
|
|
|
delete _sprites;
|
2007-01-16 12:40:51 +00:00
|
|
|
free(_game.sbuf);
|
2006-12-06 19:27:02 +00:00
|
|
|
_gfx->deinitMachine();
|
2007-01-16 12:40:51 +00:00
|
|
|
delete _rnd;
|
2006-05-24 21:40:24 +00:00
|
|
|
delete _console;
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int AgiEngine::init() {
|
2006-12-19 01:11:41 +00:00
|
|
|
|
|
|
|
// Detect game
|
|
|
|
if (!initGame()) {
|
|
|
|
GUIErrorMessage("No valid games were found in the specified directory.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-23 23:43:52 +00:00
|
|
|
// Initialize backend
|
|
|
|
_system->beginGFXTransaction();
|
|
|
|
initCommonGFX(false);
|
|
|
|
_system->initSize(320, 200);
|
|
|
|
_system->endGFXTransaction();
|
|
|
|
|
|
|
|
initialize();
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
_gfx->gfxSetPalette();
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AgiEngine::go() {
|
2006-05-25 22:51:42 +00:00
|
|
|
CursorMan.showMouse(true);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-12 02:31:04 +00:00
|
|
|
report(" \nAGI engine %s is ready.\n", gScummVMVersion);
|
2007-01-16 12:40:51 +00:00
|
|
|
if (_game.state < STATE_LOADED) {
|
2006-05-23 23:43:52 +00:00
|
|
|
do {
|
2007-01-16 12:40:51 +00:00
|
|
|
mainCycle();
|
|
|
|
} while (_game.state < STATE_RUNNING);
|
|
|
|
if (_game.ver < 0)
|
|
|
|
_game.ver = 0; /* Enable conf file warning */
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
runGame();
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-01-07 18:02:54 +00:00
|
|
|
} // End of namespace Agi
|