From 62aabc57e446efcf15353a49209ce1d99c567fa4 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Mon, 15 Aug 2011 11:51:21 -0400 Subject: AGI: Reorganize the PreAGI code a bit --- engines/agi/module.mk | 1 - engines/agi/preagi.cpp | 196 +++++++++++++++++++++++++++++++++++----- engines/agi/preagi.h | 21 ++++- engines/agi/preagi_common.cpp | 205 ------------------------------------------ engines/agi/preagi_common.h | 51 ----------- engines/agi/preagi_winnie.cpp | 18 ++++ 6 files changed, 211 insertions(+), 281 deletions(-) delete mode 100644 engines/agi/preagi_common.cpp delete mode 100644 engines/agi/preagi_common.h (limited to 'engines/agi') diff --git a/engines/agi/module.mk b/engines/agi/module.mk index cd901c50c1..68d86f7b2e 100644 --- a/engines/agi/module.mk +++ b/engines/agi/module.mk @@ -25,7 +25,6 @@ MODULE_OBJS := \ op_test.o \ picture.o \ preagi.o \ - preagi_common.o \ preagi_mickey.o \ preagi_troll.o \ preagi_winnie.o \ diff --git a/engines/agi/preagi.cpp b/engines/agi/preagi.cpp index 5bbf072918..065b93e5f9 100644 --- a/engines/agi/preagi.cpp +++ b/engines/agi/preagi.cpp @@ -22,13 +22,13 @@ #include "common/config-manager.h" #include "common/debug-channels.h" +#include "common/events.h" #include "common/random.h" #include "common/textconsole.h" -#include "audio/mididrv.h" - #include "agi/preagi.h" #include "agi/graphics.h" +#include "agi/keyboard.h" namespace Agi { @@ -54,22 +54,6 @@ PreAgiEngine::PreAgiEngine(OSystem *syst, const AGIGameDescription *gameDesc) : } void PreAgiEngine::initialize() { - // 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::getMusicType(MidiDriver::detectDevice(MDT_PCSPK|MDT_PCJR))) { - case MT_PCSPK: - _soundemu = SOUND_EMU_PC; - break; - case MT_PCJR: - _soundemu = SOUND_EMU_PCJR; - break; - default: - _soundemu = SOUND_EMU_NONE; - break; - } - if (ConfMan.hasKey("render_mode")) { _renderMode = Common::parseRenderMode(ConfMan.get("render_mode").c_str()); } else if (ConfMan.hasKey("platform")) { @@ -87,7 +71,6 @@ void PreAgiEngine::initialize() { } _gfx = new GfxMgr(this); - _sound = new SoundMgr(this, _mixer); _picture = new PictureMgr(this, _gfx); _gfx->initMachine(); @@ -108,7 +91,6 @@ void PreAgiEngine::initialize() { _game.lineMinPrint = 0; // hardcoded _gfx->initVideo(); - _sound->initSound(); _speakerStream = new Audio::PCSpeaker(_mixer->getOutputRate()); _mixer->playStream(Audio::Mixer::kSFXSoundType, &_speakerHandle, @@ -123,8 +105,6 @@ void PreAgiEngine::initialize() { memset(&_game.dirPic[i], 0, sizeof(struct AgiDir)); memset(&_game.dirSound[i], 0, sizeof(struct AgiDir)); } - - debugC(2, kDebugLevelMain, "Init sound"); } PreAgiEngine::~PreAgiEngine() { @@ -136,4 +116,176 @@ int PreAgiEngine::rnd(int hi) { return (_rnd->getRandomNumber(hi - 1) + 1); } +// Screen functions +void PreAgiEngine::clearScreen(int attr, bool overrideDefault) { + if (overrideDefault) + _defaultColor = attr; + + _gfx->clearScreen((attr & 0xF0) / 0x10); +} + +void PreAgiEngine::clearGfxScreen(int attr) { + _gfx->drawRectangle(0, 0, GFX_WIDTH - 1, IDI_MAX_ROW_PIC * 8 -1, (attr & 0xF0) / 0x10); +} + +// 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: + _gfx->putTextCharacter(1, col * 8 , row * 8, static_cast(code), attr & 0x0f, (attr & 0xf0) / 0x10, false, getGameID() == GID_MICKEY ? mickey_fontdata : ibm_fontdata); + + 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); + _gfx->doUpdate(); + _system->updateScreen(); +} + +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; + + 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: + if (event.kbd.keycode == Common::KEYCODE_d && (event.kbd.flags & Common::KBD_CTRL) && _console) { + _console->attach(); + _console->onFrame(); + //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) { + _gfx->doUpdate(); + _system->updateScreen(); + _system->delayMillis(10); + } +} + } // End of namespace Agi diff --git a/engines/agi/preagi.h b/engines/agi/preagi.h index 4734b92fde..d0aea0e77a 100644 --- a/engines/agi/preagi.h +++ b/engines/agi/preagi.h @@ -24,19 +24,36 @@ #define AGI_PREAGI_H #include "agi/agi.h" -#include "agi/preagi_common.h" #include "audio/softsynth/pcspk.h" namespace Agi { +// default attributes +#define IDA_DEFAULT 0x0F +#define IDA_DEFAULT_REV 0xF0 + +#define IDI_SND_OSCILLATOR_FREQUENCY 1193180 +#define IDI_SND_TIMER_RESOLUTION 0.0182 + +#define kColorDefault 0x1337 + +#define IDI_MAX_ROW_PIC 20 + +enum SelectionTypes { + kSelYesNo, + kSelNumber, + kSelSpace, + kSelAnyKey, + kSelBackspace +}; + class PreAgiEngine : public AgiBase { int _gameId; protected: void initialize(); -public: void pollTimer() {} int getKeypress() { return 0; } bool isKeypress() { return false; } diff --git a/engines/agi/preagi_common.cpp b/engines/agi/preagi_common.cpp deleted file mode 100644 index d437dc08f2..0000000000 --- a/engines/agi/preagi_common.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/* 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. - - * 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. - * - */ - -#include "agi/preagi.h" -#include "agi/graphics.h" -#include "agi/keyboard.h" - -#include "agi/preagi_common.h" - -#include "common/events.h" - -namespace Agi { - -// Screen functions -void PreAgiEngine::clearScreen(int attr, bool overrideDefault) { - if (overrideDefault) - _defaultColor = attr; - - _gfx->clearScreen((attr & 0xF0) / 0x10); -} - -void PreAgiEngine::clearGfxScreen(int attr) { - _gfx->drawRectangle(0, 0, GFX_WIDTH - 1, IDI_MAX_ROW_PIC * 8 -1, (attr & 0xF0) / 0x10); -} - -// 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: - _gfx->putTextCharacter(1, col * 8 , row * 8, static_cast(code), attr & 0x0f, (attr & 0xf0) / 0x10, false, getGameID() == GID_MICKEY ? mickey_fontdata : ibm_fontdata); - - 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); - _gfx->doUpdate(); - _system->updateScreen(); -} - -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; - - 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: - if (event.kbd.keycode == Common::KEYCODE_d && (event.kbd.flags & Common::KBD_CTRL) && _console) { - _console->attach(); - _console->onFrame(); - //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) { - _gfx->doUpdate(); - _system->updateScreen(); - _system->delayMillis(10); - } -} - -} diff --git a/engines/agi/preagi_common.h b/engines/agi/preagi_common.h deleted file mode 100644 index a557f69977..0000000000 --- a/engines/agi/preagi_common.h +++ /dev/null @@ -1,51 +0,0 @@ -/* 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. - - * 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. - * - */ - - - -#ifndef AGI_PREAGI_COMMON_H -#define AGI_PREAGI_COMMON_H - -namespace Agi { - -// default attributes -#define IDA_DEFAULT 0x0F -#define IDA_DEFAULT_REV 0xF0 - -#define IDI_SND_OSCILLATOR_FREQUENCY 1193180 -#define IDI_SND_TIMER_RESOLUTION 0.0182 - -#define kColorDefault 0x1337 - -#define IDI_MAX_ROW_PIC 20 - -enum SelectionTypes { - kSelYesNo, - kSelNumber, - kSelSpace, - kSelAnyKey, - kSelBackspace -}; - -} // End of namespace Agi - -#endif diff --git a/engines/agi/preagi_winnie.cpp b/engines/agi/preagi_winnie.cpp index 016f268013..2c7f50ce0d 100644 --- a/engines/agi/preagi_winnie.cpp +++ b/engines/agi/preagi_winnie.cpp @@ -31,6 +31,8 @@ #include "common/savefile.h" #include "common/textconsole.h" +#include "audio/mididrv.h" + namespace Agi { void WinnieEngine::parseRoomHeader(WTP_ROOM_HDR *roomHdr, byte *buffer, int len) { @@ -1312,6 +1314,22 @@ WinnieEngine::~WinnieEngine() { } void WinnieEngine::init() { + // Initialize sound + + switch (MidiDriver::getMusicType(MidiDriver::detectDevice(MDT_PCSPK|MDT_PCJR))) { + case MT_PCSPK: + _soundemu = SOUND_EMU_PC; + break; + case MT_PCJR: + _soundemu = SOUND_EMU_PCJR; + break; + default: + _soundemu = SOUND_EMU_NONE; + break; + } + + _sound = new SoundMgr(this, _mixer); + _sound->initSound(); setflag(fSoundOn, true); // enable sound memset(&_gameStateWinnie, 0, sizeof(_gameStateWinnie)); -- cgit v1.2.3