2007-09-01 14:58:46 +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.
|
|
|
|
*
|
|
|
|
* 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.
|
2014-02-18 01:34:17 +00:00
|
|
|
*
|
2007-09-01 14:58:46 +00:00
|
|
|
* 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.
|
2014-02-18 01:34:17 +00:00
|
|
|
*
|
2007-09-01 14:58:46 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/config-manager.h"
|
2010-05-04 11:59:22 +00:00
|
|
|
#include "common/debug-channels.h"
|
2011-08-15 15:51:21 +00:00
|
|
|
#include "common/events.h"
|
2010-03-18 15:07:11 +00:00
|
|
|
#include "common/random.h"
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/textconsole.h"
|
2007-09-01 14:58:46 +00:00
|
|
|
|
2007-09-18 16:20:44 +00:00
|
|
|
#include "agi/preagi.h"
|
2007-09-01 14:58:46 +00:00
|
|
|
#include "agi/graphics.h"
|
2011-08-15 15:51:21 +00:00
|
|
|
#include "agi/keyboard.h"
|
2016-01-29 12:13:40 +00:00
|
|
|
#include "agi/text.h"
|
2007-09-01 14:58:46 +00:00
|
|
|
|
|
|
|
namespace Agi {
|
|
|
|
|
2007-11-03 21:06:58 +00:00
|
|
|
PreAgiEngine::PreAgiEngine(OSystem *syst, const AGIGameDescription *gameDesc) : AgiBase(syst, gameDesc) {
|
2007-09-01 14:58:46 +00:00
|
|
|
|
|
|
|
// Setup mixer
|
2011-03-19 14:22:15 +00:00
|
|
|
syncSoundSettings();
|
2007-09-01 14:58:46 +00:00
|
|
|
|
2010-04-27 21:40:52 +00:00
|
|
|
DebugMan.addDebugChannel(kDebugLevelMain, "Main", "Generic debug level");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelResources, "Resources", "Resources debugging");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelSprites, "Sprites", "Sprites debugging");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelInventory, "Inventory", "Inventory debugging");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelInput, "Input", "Input events debugging");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelMenu, "Menu", "Menu debugging");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelScripts, "Scripts", "Scripts debugging");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelSound, "Sound", "Sound debugging");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelText, "Text", "Text output debugging");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelSavegame, "Savegame", "Saving & restoring game debugging");
|
2007-09-01 14:58:46 +00:00
|
|
|
|
|
|
|
memset(&_game, 0, sizeof(struct AgiGame));
|
|
|
|
memset(&_debug, 0, sizeof(struct AgiDebug));
|
2009-10-20 11:13:00 +00:00
|
|
|
memset(&_mouse, 0, sizeof(struct Mouse));
|
2007-09-01 14:58:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PreAgiEngine::initialize() {
|
2011-09-26 02:23:42 +00:00
|
|
|
initRenderMode();
|
2007-09-01 14:58:46 +00:00
|
|
|
|
2016-01-29 15:18:31 +00:00
|
|
|
_font = new GfxFont(this);
|
2007-09-01 14:58:46 +00:00
|
|
|
_gfx = new GfxMgr(this);
|
|
|
|
_picture = new PictureMgr(this, _gfx);
|
|
|
|
|
2016-01-29 15:18:31 +00:00
|
|
|
_font->init();
|
2007-09-01 14:58:46 +00:00
|
|
|
|
|
|
|
_game.gameFlags = 0;
|
|
|
|
|
2016-01-29 12:13:40 +00:00
|
|
|
//_game._vm->_text->charAttrib_Set(15, 0);
|
2007-09-01 14:58:46 +00:00
|
|
|
|
2007-09-18 16:20:44 +00:00
|
|
|
_defaultColor = 0xF;
|
|
|
|
|
2007-09-01 14:58:46 +00:00
|
|
|
_game.name[0] = '\0';
|
|
|
|
|
2016-01-29 12:13:40 +00:00
|
|
|
//_game._vm->_text->configureScreen(0); // hardcoded
|
2007-09-01 14:58:46 +00:00
|
|
|
|
|
|
|
_gfx->initVideo();
|
2007-11-19 20:34:26 +00:00
|
|
|
|
|
|
|
_speakerStream = new Audio::PCSpeaker(_mixer->getOutputRate());
|
2010-04-12 09:14:17 +00:00
|
|
|
_mixer->playStream(Audio::Mixer::kSFXSoundType, &_speakerHandle,
|
2010-01-08 22:09:43 +00:00
|
|
|
_speakerStream, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true);
|
2007-11-19 20:34:26 +00:00
|
|
|
|
2007-09-01 14:58:46 +00:00
|
|
|
debugC(2, kDebugLevelMain, "Detect game");
|
|
|
|
|
2009-06-06 17:39:13 +00:00
|
|
|
// clear all resources and events
|
2016-01-29 12:13:40 +00:00
|
|
|
for (int i = 0; i < MAX_DIRECTORY_ENTRIES; i++) {
|
2007-09-01 14:58:46 +00:00
|
|
|
memset(&_game.pictures[i], 0, sizeof(struct AgiPicture));
|
2007-09-03 09:39:15 +00:00
|
|
|
memset(&_game.sounds[i], 0, sizeof(class AgiSound *)); // _game.sounds contains pointers now
|
2007-09-01 14:58:46 +00:00
|
|
|
memset(&_game.dirPic[i], 0, sizeof(struct AgiDir));
|
2007-09-03 09:39:15 +00:00
|
|
|
memset(&_game.dirSound[i], 0, sizeof(struct AgiDir));
|
2007-09-01 14:58:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PreAgiEngine::~PreAgiEngine() {
|
2007-11-19 22:37:52 +00:00
|
|
|
_mixer->stopHandle(_speakerHandle);
|
2007-11-19 20:34:26 +00:00
|
|
|
delete _speakerStream;
|
2016-01-29 15:18:31 +00:00
|
|
|
|
|
|
|
delete _picture;
|
|
|
|
delete _gfx;
|
|
|
|
delete _font;
|
2007-09-01 14:58:46 +00:00
|
|
|
}
|
|
|
|
|
2010-03-18 15:07:11 +00:00
|
|
|
int PreAgiEngine::rnd(int hi) {
|
|
|
|
return (_rnd->getRandomNumber(hi - 1) + 1);
|
|
|
|
}
|
|
|
|
|
2011-08-15 15:51:21 +00:00
|
|
|
// Screen functions
|
|
|
|
void PreAgiEngine::clearScreen(int attr, bool overrideDefault) {
|
|
|
|
if (overrideDefault)
|
|
|
|
_defaultColor = attr;
|
|
|
|
|
2016-01-29 12:13:40 +00:00
|
|
|
_gfx->clearDisplay((attr & 0xF0) / 0x10);
|
2011-08-15 15:51:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PreAgiEngine::clearGfxScreen(int attr) {
|
2016-01-29 12:13:40 +00:00
|
|
|
_gfx->drawDisplayRect(0, 0, GFX_WIDTH - 1, IDI_MAX_ROW_PIC * 8 -1, (attr & 0xF0) / 0x10);
|
2011-08-15 15:51:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// String functions
|
|
|
|
|
|
|
|
void PreAgiEngine::drawStr(int row, int col, int attr, const char *buffer) {
|
|
|
|
int code;
|
|
|
|
|
|
|
|
if (attr == kColorDefault)
|
|
|
|
attr = _defaultColor;
|
|
|
|
|
|
|
|
for (int iChar = 0; iChar < (int)strlen(buffer); iChar++) {
|
|
|
|
code = buffer[iChar];
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
case '\n':
|
|
|
|
case 0x8D:
|
|
|
|
if (++row == 200 / 8) return;
|
|
|
|
col = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '|':
|
|
|
|
// swap attribute nibbles
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-01-29 12:13:40 +00:00
|
|
|
_gfx->drawCharacter(row, col, code, attr & 0x0f, attr >> 4, false);
|
2011-08-15 15:51:21 +00:00
|
|
|
|
|
|
|
if (++col == 320 / 8) {
|
|
|
|
col = 0;
|
|
|
|
if (++row == 200 / 8) return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreAgiEngine::drawStrMiddle(int row, int attr, const char *buffer) {
|
|
|
|
int col = (25 / 2) - (strlen(buffer) / 2); // 25 = 320 / 8 (maximum column)
|
|
|
|
drawStr(row, col, attr, buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreAgiEngine::clearTextArea() {
|
|
|
|
int start = IDI_MAX_ROW_PIC;
|
|
|
|
|
|
|
|
if (getGameID() == GID_TROLL)
|
|
|
|
start = 21;
|
|
|
|
|
|
|
|
for (int row = start; row < 200 / 8; row++) {
|
|
|
|
clearRow(row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreAgiEngine::clearRow(int row) {
|
|
|
|
drawStr(row, 0, IDA_DEFAULT, " "); // 40 spaces
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreAgiEngine::printStr(const char* szMsg) {
|
|
|
|
clearTextArea();
|
|
|
|
drawStr(21, 0, IDA_DEFAULT, szMsg);
|
2016-01-29 12:13:40 +00:00
|
|
|
g_system->updateScreen();
|
2011-08-15 15:51:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PreAgiEngine::XOR80(char *buffer) {
|
|
|
|
for (size_t i = 0; i < strlen(buffer); i++)
|
|
|
|
if (buffer[i] & 0x80)
|
|
|
|
buffer[i] ^= 0x80;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreAgiEngine::printStrXOR(char *szMsg) {
|
|
|
|
XOR80(szMsg);
|
|
|
|
printStr(szMsg);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Input functions
|
|
|
|
|
|
|
|
int PreAgiEngine::getSelection(SelectionTypes type) {
|
|
|
|
Common::Event event;
|
2011-08-16 02:03:58 +00:00
|
|
|
GUI::Debugger *console = getDebugger();
|
2011-08-15 15:51:21 +00:00
|
|
|
|
|
|
|
while (!shouldQuit()) {
|
|
|
|
while (_eventMan->pollEvent(event)) {
|
|
|
|
switch (event.type) {
|
|
|
|
case Common::EVENT_RTL:
|
|
|
|
case Common::EVENT_QUIT:
|
|
|
|
return 0;
|
|
|
|
case Common::EVENT_RBUTTONUP:
|
|
|
|
return 0;
|
|
|
|
case Common::EVENT_LBUTTONUP:
|
|
|
|
if (type == kSelYesNo || type == kSelAnyKey)
|
|
|
|
return 1;
|
|
|
|
case Common::EVENT_KEYDOWN:
|
2011-08-16 02:03:58 +00:00
|
|
|
if (event.kbd.keycode == Common::KEYCODE_d && (event.kbd.flags & Common::KBD_CTRL) && console) {
|
|
|
|
console->attach();
|
|
|
|
console->onFrame();
|
2011-08-15 15:51:21 +00:00
|
|
|
//FIXME: If not cleared, clicking again will start the console
|
|
|
|
event.kbd.keycode = Common::KEYCODE_INVALID;
|
|
|
|
event.kbd.flags = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch (event.kbd.keycode) {
|
|
|
|
case Common::KEYCODE_y:
|
|
|
|
if (type == kSelYesNo)
|
|
|
|
return 1;
|
|
|
|
case Common::KEYCODE_n:
|
|
|
|
if (type == kSelYesNo)
|
|
|
|
return 0;
|
|
|
|
case Common::KEYCODE_ESCAPE:
|
|
|
|
if (type == kSelNumber || type == kSelAnyKey)
|
|
|
|
return 0;
|
|
|
|
case Common::KEYCODE_1:
|
|
|
|
case Common::KEYCODE_2:
|
|
|
|
case Common::KEYCODE_3:
|
|
|
|
case Common::KEYCODE_4:
|
|
|
|
case Common::KEYCODE_5:
|
|
|
|
case Common::KEYCODE_6:
|
|
|
|
case Common::KEYCODE_7:
|
|
|
|
case Common::KEYCODE_8:
|
|
|
|
case Common::KEYCODE_9:
|
|
|
|
if (type == kSelNumber)
|
|
|
|
return event.kbd.keycode - Common::KEYCODE_1 + 1;
|
|
|
|
case Common::KEYCODE_SPACE:
|
|
|
|
if (type == kSelSpace)
|
|
|
|
return 1;
|
|
|
|
case Common::KEYCODE_BACKSPACE:
|
|
|
|
if (type == kSelBackspace)
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
if (event.kbd.flags & Common::KBD_CTRL)
|
|
|
|
break;
|
|
|
|
if (type == kSelYesNo) {
|
|
|
|
return 2;
|
|
|
|
} else if (type == kSelNumber) {
|
|
|
|
return 10;
|
|
|
|
} else if (type == kSelAnyKey || type == kSelBackspace) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_system->updateScreen();
|
|
|
|
_system->delayMillis(10);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreAgiEngine::playNote(int16 frequency, int32 length) {
|
|
|
|
_speakerStream->play(Audio::PCSpeaker::kWaveFormSquare, frequency, length);
|
|
|
|
waitForTimer(length);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreAgiEngine::waitForTimer(int msec_delay) {
|
|
|
|
uint32 start_time = _system->getMillis();
|
|
|
|
|
|
|
|
while (_system->getMillis() < start_time + msec_delay) {
|
2016-01-29 12:13:40 +00:00
|
|
|
g_system->updateScreen();
|
2011-08-15 15:51:21 +00:00
|
|
|
_system->delayMillis(10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-01 14:58:46 +00:00
|
|
|
} // End of namespace Agi
|