aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/adl/adl.cpp261
-rw-r--r--engines/adl/adl.h20
-rw-r--r--engines/adl/display.cpp178
-rw-r--r--engines/adl/display.h20
-rw-r--r--engines/adl/hires1.cpp33
-rw-r--r--engines/adl/module.mk3
-rw-r--r--engines/adl/parser.cpp168
-rw-r--r--engines/adl/parser.h66
8 files changed, 349 insertions, 400 deletions
diff --git a/engines/adl/adl.cpp b/engines/adl/adl.cpp
index ab05c40b69..3c405b67b5 100644
--- a/engines/adl/adl.cpp
+++ b/engines/adl/adl.cpp
@@ -36,7 +36,6 @@
#include "adl/adl.h"
#include "adl/display.h"
-#include "adl/parser.h"
namespace Adl {
@@ -44,12 +43,10 @@ AdlEngine::AdlEngine(OSystem *syst, const AdlGameDescription *gd) :
Engine(syst),
_gameDescription(gd),
_display(nullptr),
- _parser(nullptr),
_isRestarting(false) {
}
AdlEngine::~AdlEngine() {
- delete _parser;
delete _display;
}
@@ -68,7 +65,6 @@ Common::Error AdlEngine::run() {
g_system->getPaletteManager()->setPalette(palette, 0, 6);
_display = new Display();
- _parser = new Parser(*this, *_display);
int saveSlot = ConfMan.getInt("save_slot");
if (saveSlot >= 0) {
@@ -137,7 +133,7 @@ void AdlEngine::printMessage(uint idx, bool wait) {
_display->printString(msg);
if (wait)
- _display->delay(14 * 166018 / 1000);
+ delay(14 * 166018 / 1000);
}
void AdlEngine::printEngineMessage(EngineMessage msg) {
@@ -282,7 +278,7 @@ void AdlEngine::doActions(const Command &command, byte noun, byte offset) {
break;
case IDO_ACT_RESTART: {
_display->printString(_strings[IDI_STR_PLAY_AGAIN]);
- Common::String input = _display->inputString();
+ Common::String input = inputString();
if (input.size() == 0 || input[0] != APPLECHAR('N')) {
_isRestarting = true;
_display->clear(0x00);
@@ -614,6 +610,259 @@ byte &AdlEngine::var(uint i) {
return _state.vars[i];
}
+void AdlEngine::loadWords(Common::ReadStream &stream, WordMap &map) {
+ uint index = 0;
+
+ while (1) {
+ ++index;
+
+ byte buf[kWordSize];
+
+ if (stream.read(buf, kWordSize) < kWordSize)
+ error("Error reading word list");
+
+ Common::String word((char *)buf, kWordSize);
+
+ if (!map.contains(word))
+ map[word] = index;
+
+ byte synonyms = stream.readByte();
+
+ if (stream.err() || stream.eos())
+ error("Error reading word list");
+
+ if (synonyms == 0xff)
+ break;
+
+ for (uint i = 0; i < synonyms; ++i) {
+ if (stream.read((char *)buf, kWordSize) < kWordSize)
+ error("Error reading word list");
+
+ word = Common::String((char *)buf, kWordSize);
+
+ if (!map.contains(word))
+ map[word] = index;
+ }
+ }
+}
+
+Common::String AdlEngine::getLine() {
+ // Original engine uses a global here, which isn't reset between
+ // calls and may not match actual mode
+ bool textMode = false;
+
+ while (1) {
+ Common::String line = inputString(APPLECHAR('?'));
+
+ if (shouldQuit())
+ return "";
+
+ if ((byte)line[0] == ('\r' | 0x80)) {
+ textMode = !textMode;
+ _display->setMode(textMode ? Display::kModeText : Display::kModeMixed);
+ continue;
+ }
+
+ // Remove the return
+ line.deleteLastChar();
+ return line;
+ }
+}
+
+Common::String AdlEngine::getWord(const Common::String &line, uint &index) {
+ Common::String str;
+
+ for (uint i = 0; i < 8; ++i)
+ str += APPLECHAR(' ');
+
+ int copied = 0;
+
+ // Skip initial whitespace
+ while (1) {
+ if (index == line.size())
+ return str;
+ if (line[index] != APPLECHAR(' '))
+ break;
+ ++index;
+ }
+
+ // Copy up to 8 characters
+ while (1) {
+ if (copied < 8)
+ str.setChar(line[index], copied++);
+
+ index++;
+
+ if (index == line.size() || line[index] == APPLECHAR(' '))
+ return str;
+ }
+}
+
+void AdlEngine::getInput(uint &verb, uint &noun) {
+ while (1) {
+ _display->printString(getEngineString(IDI_STR_ENTER_COMMAND));
+ Common::String line = getLine();
+
+ if (shouldQuit())
+ return;
+
+ uint index = 0;
+ Common::String verbStr = getWord(line, index);
+
+ if (!_verbs.contains(verbStr)) {
+ Common::String err = getEngineString(IDI_STR_VERB_ERROR);
+ for (uint i = 0; i < verbStr.size(); ++i)
+ err.setChar(verbStr[i], i + 19);
+ _display->printString(err);
+ continue;
+ }
+
+ verb = _verbs[verbStr];
+
+ Common::String nounStr = getWord(line, index);
+
+ if (!_nouns.contains(nounStr)) {
+ Common::String err = getEngineString(IDI_STR_NOUN_ERROR);
+ for (uint i = 0; i < verbStr.size(); ++i)
+ err.setChar(verbStr[i], i + 19);
+ for (uint i = 0; i < nounStr.size(); ++i)
+ err.setChar(nounStr[i], i + 30);
+ _display->printString(err);
+ continue;
+ }
+
+ noun = _nouns[nounStr];
+ return;
+ }
+}
+
+void AdlEngine::printASCIIString(const Common::String &str) {
+ Common::String aStr;
+
+ Common::String::const_iterator it;
+ for (it = str.begin(); it != str.end(); ++it)
+ aStr += APPLECHAR(*it);
+
+ _display->printString(aStr);
+}
+
+Common::String AdlEngine::inputString(byte prompt) {
+ Common::String s;
+
+ if (prompt > 0)
+ _display->printString(Common::String(prompt));
+
+ while (1) {
+ byte b = inputKey();
+
+ if (g_engine->shouldQuit())
+ return 0;
+
+ if (b == 0)
+ continue;
+
+ if (b == ('\r' | 0x80)) {
+ s += b;
+ _display->printString(Common::String(b));
+ return s;
+ }
+
+ if (b < 0xa0) {
+ switch (b) {
+ case Common::KEYCODE_BACKSPACE | 0x80:
+ if (!s.empty()) {
+ _display->moveCursorBackward();
+ _display->setCharAtCursor(APPLECHAR(' '));
+ s.deleteLastChar();
+ }
+ break;
+ };
+ } else {
+ s += b;
+ _display->printString(Common::String(b));
+ }
+ }
+}
+
+byte AdlEngine::convertKey(uint16 ascii) {
+ ascii = toupper(ascii);
+
+ if (ascii >= 0x80)
+ return 0;
+
+ ascii |= 0x80;
+
+ if (ascii >= 0x80 && ascii <= 0xe0)
+ return ascii;
+
+ return 0;
+}
+
+byte AdlEngine::inputKey() {
+ Common::EventManager *ev = g_system->getEventManager();
+
+ byte key = 0;
+
+ _display->showCursor(true);
+
+ while (!g_engine->shouldQuit() && key == 0) {
+ Common::Event event;
+ if (ev->pollEvent(event)) {
+ if (event.type != Common::EVENT_KEYDOWN)
+ continue;
+
+ if (event.kbd.flags & Common::KBD_CTRL) {
+ if (event.kbd.keycode == Common::KEYCODE_q)
+ g_engine->quitGame();
+ continue;
+ }
+
+ switch (event.kbd.keycode) {
+ case Common::KEYCODE_BACKSPACE:
+ case Common::KEYCODE_RETURN:
+ key = convertKey(event.kbd.keycode);
+ break;
+ default:
+ if (event.kbd.ascii >= 0x20 && event.kbd.ascii < 0x80)
+ key = convertKey(event.kbd.ascii);
+ };
+ }
+
+ _display->updateTextSurface();
+ _display->updateScreen();
+ g_system->updateScreen();
+ g_system->delayMillis(16);
+ }
+
+ _display->showCursor(false);
+
+ return key;
+}
+
+void AdlEngine::delay(uint32 ms) {
+ Common::EventManager *ev = g_system->getEventManager();
+
+ uint32 start = g_system->getMillis();
+
+ while (!g_engine->shouldQuit() && g_system->getMillis() - start < ms) {
+ Common::Event event;
+ if (ev->pollEvent(event)) {
+ if (event.type == Common::EVENT_KEYDOWN && (event.kbd.flags & Common::KBD_CTRL)) {
+ switch(event.kbd.keycode) {
+ case Common::KEYCODE_q:
+ g_engine->quitGame();
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ _display->updateScreen();
+ g_system->updateScreen();
+ g_system->delayMillis(16);
+ }
+}
+
AdlEngine *AdlEngine::create(GameType type, OSystem *syst, const AdlGameDescription *gd) {
switch(type) {
case kGameTypeHires1:
diff --git a/engines/adl/adl.h b/engines/adl/adl.h
index 9955b0d79a..a9ac79d9f0 100644
--- a/engines/adl/adl.h
+++ b/engines/adl/adl.h
@@ -177,6 +177,8 @@ public:
virtual Common::String getEngineString(int str);
protected:
+ typedef Common::HashMap<Common::String, uint> WordMap;
+
virtual void runIntro() { }
virtual void runGame() = 0;
virtual void initState() = 0;
@@ -201,6 +203,16 @@ protected:
Room &curRoom();
Item &item(uint i);
byte &var(uint i);
+ void loadVerbs(Common::ReadStream &stream) { loadWords(stream, _verbs); }
+ void loadNouns(Common::ReadStream &stream) { loadWords(stream, _nouns); }
+ void getInput(uint &verb, uint &noun);
+ void loadWords(Common::ReadStream &stream, WordMap &map);
+ Common::String getLine();
+ Common::String getWord(const Common::String &line, uint &index);
+ void printASCIIString(const Common::String &str);
+ Common::String inputString(byte prompt = 0);
+ void delay(uint32 ms);
+ byte inputKey();
Display *_display;
Parser *_parser;
@@ -222,6 +234,14 @@ private:
bool saveState(uint slot, const Common::String *description = nullptr);
bool loadState(uint slot);
Common::String getTargetName() { return _targetName; }
+ byte convertKey(uint16 ascii);
+
+ enum {
+ kWordSize = 8
+ };
+
+ WordMap _verbs;
+ WordMap _nouns;
};
AdlEngine *HiRes1Engine__create(OSystem *syst, const AdlGameDescription *gd);
diff --git a/engines/adl/display.cpp b/engines/adl/display.cpp
index ffb98c4a1b..a6d94f6e13 100644
--- a/engines/adl/display.cpp
+++ b/engines/adl/display.cpp
@@ -71,7 +71,8 @@ static byte font[64][5] = {
Display::Display() :
_scanlines(false),
_cursorPos(0),
- _mode(kModeText) {
+ _mode(kModeText),
+ _showCursor(false) {
_frameBuf = new byte[kFrameBufSize];
_frameBufSurface = new Graphics::Surface;
_frameBufSurface->create(kWidth * 2, kHeight * 2, Graphics::PixelFormat::createFormatCLUT8());
@@ -367,8 +368,12 @@ void Display::clear(byte color) {
void Display::updateTextSurface() {
for (uint row = 0; row < 24; ++row)
for (uint col = 0; col < 40; ++col) {
+ int charPos = row * 40 + col;
char c = _textBuf[row * 40 + col];
+ if (charPos == _cursorPos && _showCursor)
+ c = (c & 0x3f) | 0x40;
+
Common::Rect r(7 * 2, 8 * 2);
r.translate(((c & 0x3f) % 16) * 7 * 2, (c & 0x3f) / 16 * 8 * 2);
@@ -381,36 +386,6 @@ void Display::updateTextSurface() {
}
}
-void Display::printString(const Common::String &str) {
- Common::String::const_iterator it;
- for (it = str.begin(); it != str.end(); ++it) {
- byte b = *it;
-
- if (b == ('\r' | 0x80))
- _cursorPos = (_cursorPos / 40 + 1) * 40;
- else if (b < 0x80 || b >= 0xa0)
- _textBuf[_cursorPos++] = b;
-
- if (_cursorPos == kTextBufSize) {
- memmove(_textBuf, _textBuf + 40, kTextBufSize - 40);
- memset(_textBuf + kTextBufSize - 40, ' ' | 0x80, 40);
- _cursorPos -= 40;
- }
- }
-
- updateTextSurface();
-}
-
-void Display::printASCIIString(const Common::String &str) {
- Common::String aStr;
-
- Common::String::const_iterator it;
- for (it = str.begin(); it != str.end(); ++it)
- aStr += APPLECHAR(*it);
-
- printString(aStr);
-}
-
void Display::drawChar(byte c, int x, int y) {
byte *buf = (byte *)_font->getPixels() + y * _font->pitch + x;
@@ -463,126 +438,63 @@ void Display::updateScreen() {
}
}
-Common::String Display::inputString(byte prompt) {
- Common::String s;
-
- if (prompt > 0)
- printString(Common::String(prompt));
-
- while (1) {
- byte b = inputKey();
-
- if (g_engine->shouldQuit())
- return 0;
-
- if (b == 0)
- continue;
-
- if (b == ('\r' | 0x80)) {
- s += b;
- printString(Common::String(b));
- return s;
- }
-
- if (b < 0xa0) {
- switch (b) {
- case Common::KEYCODE_BACKSPACE | 0x80:
- if (!s.empty()) {
- --_cursorPos;
- _textBuf[_cursorPos] = ' ' | 0x80;
- s.deleteLastChar();
- }
- break;
- };
- } else {
- s += b;
- printString(Common::String(b));
- }
- }
+void Display::home() {
+ memset(_textBuf, APPLECHAR(' '), kTextBufSize);
+ _cursorPos = 0;
}
-byte Display::convertKey(uint16 ascii) {
- ascii = toupper(ascii);
-
- if (ascii >= 0x80)
- return 0;
+void Display::moveCursorForward() {
+ ++_cursorPos;
- ascii |= 0x80;
+ if (_cursorPos >= kTextBufSize)
+ scrollUp();
+}
- if (ascii >= 0x80 && ascii <= 0xe0)
- return ascii;
+void Display::moveCursorBackward() {
+ --_cursorPos;
- return 0;
+ if (_cursorPos < 0)
+ _cursorPos = 0;
}
-byte Display::inputKey() {
- Common::EventManager *ev = g_system->getEventManager();
+void Display::moveCursorTo(const Common::Point &pos) {
+ _cursorPos = pos.y * 40 + pos.x;
- byte orgChar = _textBuf[_cursorPos];
- _textBuf[_cursorPos] = (orgChar & 0x3f) | 0x40;
+ if (_cursorPos >= kTextBufSize)
+ error("Cursor position (%i, %i) out of bounds", pos.x, pos.y);
+}
- byte key = 0;
+void Display::setCharAtCursor(byte c) {
+ _textBuf[_cursorPos] = c;
+}
- while (!g_engine->shouldQuit() && key == 0) {
- Common::Event event;
- if (ev->pollEvent(event)) {
- if (event.type != Common::EVENT_KEYDOWN)
- continue;
+void Display::scrollUp() {
+ memmove(_textBuf, _textBuf + 40, kTextBufSize - 40);
+ memset(_textBuf + kTextBufSize - 40, ' ' | 0x80, 40);
+ _cursorPos -= 40;
+}
- if (event.kbd.flags & Common::KBD_CTRL) {
- if (event.kbd.keycode == Common::KEYCODE_q)
- g_engine->quitGame();
- continue;
- }
+void Display::printString(const Common::String &str) {
+ Common::String::const_iterator c;
+ for (c = str.begin(); c != str.end(); ++c) {
+ byte b = *c;
- switch (event.kbd.keycode) {
- case Common::KEYCODE_BACKSPACE:
- case Common::KEYCODE_RETURN:
- key = convertKey(event.kbd.keycode);
- break;
- default:
- if (event.kbd.ascii >= 0x20 && event.kbd.ascii < 0x80)
- key = convertKey(event.kbd.ascii);
- };
+ if (*c == APPLECHAR('\r'))
+ _cursorPos = (_cursorPos / 40 + 1) * 40;
+ else if (b < 0x80 || b >= 0xa0) {
+ setCharAtCursor(b);
+ ++_cursorPos;
}
- updateTextSurface();
- updateScreen();
- g_system->updateScreen();
- g_system->delayMillis(16);
+ if (_cursorPos == kTextBufSize)
+ scrollUp();
}
- _textBuf[_cursorPos] = orgChar;
- return key;
-}
-
-void Display::delay(uint32 ms) {
- Common::EventManager *ev = g_system->getEventManager();
-
- uint32 start = g_system->getMillis();
-
- while (!g_engine->shouldQuit() && g_system->getMillis() - start < ms) {
- Common::Event event;
- if (ev->pollEvent(event)) {
- if (event.type == Common::EVENT_KEYDOWN && (event.kbd.flags & Common::KBD_CTRL)) {
- switch(event.kbd.keycode) {
- case Common::KEYCODE_q:
- g_engine->quitGame();
- break;
- default:
- break;
- }
- }
- }
- updateScreen();
- g_system->updateScreen();
- g_system->delayMillis(16);
- }
+ updateTextSurface();
}
-void Display::home() {
- memset(_textBuf, ' ' | 0x80, kTextBufSize);
- _cursorPos = 0;
+void Display::showCursor(bool enable) {
+ _showCursor = enable;
}
void Display::setCursorPos(Common::Point pos) {
diff --git a/engines/adl/display.h b/engines/adl/display.h
index 91d8b0ec97..91ae447cfd 100644
--- a/engines/adl/display.h
+++ b/engines/adl/display.h
@@ -52,20 +52,23 @@ public:
~Display();
void loadFrameBuffer(Common::ReadStream &stream);
void decodeFrameBuffer();
- void printString(const Common::String &str);
- void printASCIIString(const Common::String &str);
void updateScreen();
- Common::String inputString(byte prompt = 0);
- void delay(uint32 ms);
void setMode(Mode mode) { _mode = mode; }
- byte inputKey();
- void home();
void drawPixel(byte x, byte y, byte color);
void drawLine(Common::Point p1, Common::Point p2, byte color);
void clear(byte color);
void drawLineArt(const Common::Array<byte> &lineArt, Common::Point p, byte rotation = 0, byte scaling = 1, byte color = 0x7f);
void setCursorPos(Common::Point pos);
+ void home();
+ void moveCursorTo(const Common::Point &pos);
+ void moveCursorForward();
+ void moveCursorBackward();
+ void printString(const Common::String &str);
+ void setCharAtCursor(byte c);
+ void showCursor(bool enable);
+ void updateTextSurface();
+
private:
enum {
kWidth = 280,
@@ -85,12 +88,12 @@ private:
byte getPixelColor(byte x, byte color);
void drawChar(byte c, int x, int y);
void createFont();
- void updateTextSurface();
- byte convertKey(uint16 ascii);
void moveX(PixelPos &p, byte &color, bool left);
void moveY(PixelPos &p, bool down);
void drawNextPixel(Display::PixelPos &p, byte &color, byte bits, byte quadrant);
+ void scrollUp();
+
bool _scanlines;
byte *_frameBuf;
byte *_textBuf;
@@ -99,6 +102,7 @@ private:
Graphics::Surface *_font;
int _cursorPos;
Mode _mode;
+ bool _showCursor;
};
} // End of namespace Adl
diff --git a/engines/adl/hires1.cpp b/engines/adl/hires1.cpp
index ba6f19a8e4..591216698b 100644
--- a/engines/adl/hires1.cpp
+++ b/engines/adl/hires1.cpp
@@ -37,7 +37,6 @@
#include "adl/hires1.h"
#include "adl/display.h"
-#include "adl/parser.h"
namespace Adl {
@@ -98,7 +97,7 @@ void HiRes1Engine::runIntro() {
_display->setMode(Display::kModeHires);
_display->loadFrameBuffer(file);
_display->decodeFrameBuffer();
- _display->delay(4000);
+ delay(4000);
if (shouldQuit())
return;
@@ -113,21 +112,21 @@ void HiRes1Engine::runIntro() {
basic.seek(IDI_HR1_OFS_PD_TEXT_0);
str = readString(basic, '"');
- _display->printASCIIString(str + '\r');
+ printASCIIString(str + '\r');
basic.seek(IDI_HR1_OFS_PD_TEXT_1);
str = readString(basic, '"');
- _display->printASCIIString(str + "\r\r");
+ printASCIIString(str + "\r\r");
basic.seek(IDI_HR1_OFS_PD_TEXT_2);
str = readString(basic, '"');
- _display->printASCIIString(str + "\r\r");
+ printASCIIString(str + "\r\r");
basic.seek(IDI_HR1_OFS_PD_TEXT_3);
str = readString(basic, '"');
- _display->printASCIIString(str + '\r');
+ printASCIIString(str + '\r');
- _display->inputKey();
+ inputKey();
if (g_engine->shouldQuit())
return;
@@ -140,7 +139,7 @@ void HiRes1Engine::runIntro() {
while (1) {
_display->printString(str);
- Common::String s = _display->inputString();
+ Common::String s = inputString();
if (g_engine->shouldQuit())
break;
@@ -166,7 +165,7 @@ void HiRes1Engine::runIntro() {
while (pages[page] != 0) {
_display->home();
printStrings(file, pages[page++]);
- _display->inputString();
+ inputString();
if (g_engine->shouldQuit())
return;
@@ -175,7 +174,7 @@ void HiRes1Engine::runIntro() {
}
}
- _display->printASCIIString("\r");
+ printASCIIString("\r");
file.close();
@@ -188,7 +187,7 @@ void HiRes1Engine::runIntro() {
file.seek(0x1800);
_display->loadFrameBuffer(file);
_display->decodeFrameBuffer();
- _display->delay(2000);
+ delay(2000);
}
void HiRes1Engine::drawPic(Common::ReadStream &stream, Common::Point pos) {
@@ -294,8 +293,8 @@ void HiRes1Engine::initState() {
void HiRes1Engine::restartGame() {
initState();
_display->printString(_strings[IDI_HR1_STR_PRESS_RETURN]);
- _display->inputString(); // Missing in the original
- _display->printASCIIString("\r\r\r\r\r");
+ inputString(); // Missing in the original
+ printASCIIString("\r\r\r\r\r");
}
void HiRes1Engine::runGame() {
@@ -364,12 +363,12 @@ void HiRes1Engine::runGame() {
}
f.seek(0x3800);
- _parser->loadVerbs(f);
+ loadVerbs(f);
f.seek(0xf00);
- _parser->loadNouns(f);
+ loadNouns(f);
- _display->printASCIIString("\r\r\r\r\r");
+ printASCIIString("\r\r\r\r\r");
while (1) {
if (_isRestarting)
@@ -378,7 +377,7 @@ void HiRes1Engine::runGame() {
uint verb = 0, noun = 0;
clearScreen();
showRoom();
- _parser->getInput(verb, noun);
+ getInput(verb, noun);
if (!doOneCommand(_roomCommands, verb, noun))
printMessage(37);
diff --git a/engines/adl/module.mk b/engines/adl/module.mk
index 012b027b48..6acd06f6de 100644
--- a/engines/adl/module.mk
+++ b/engines/adl/module.mk
@@ -4,8 +4,7 @@ MODULE_OBJS := \
adl.o \
detection.o \
display.o \
- hires1.o \
- parser.o
+ hires1.o
MODULE_DIRS += \
engines/adl
diff --git a/engines/adl/parser.cpp b/engines/adl/parser.cpp
deleted file mode 100644
index a697301664..0000000000
--- a/engines/adl/parser.cpp
+++ /dev/null
@@ -1,168 +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 "adl/adl.h"
-#include "adl/parser.h"
-#include "adl/display.h"
-
-#include "engines/engine.h"
-
-#include "common/str.h"
-#include "common/stream.h"
-#include "common/debug.h"
-#include "common/textconsole.h"
-
-namespace Adl {
-
-Parser::Parser(AdlEngine &engine, Display &display) :
- _engine(engine),
- _display(display) {
-
-}
-
-void Parser::loadWords(Common::ReadStream &stream, WordMap &map) {
- uint index = 0;
-
- while (1) {
- ++index;
-
- byte buf[kWordSize];
-
- if (stream.read(buf, kWordSize) < kWordSize)
- error("Error reading word list");
-
- Common::String word((char *)buf, kWordSize);
-
- if (!map.contains(word))
- map[word] = index;
-
- byte synonyms = stream.readByte();
-
- if (stream.err() || stream.eos())
- error("Error reading word list");
-
- if (synonyms == 0xff)
- break;
-
- for (uint i = 0; i < synonyms; ++i) {
- if (stream.read((char *)buf, kWordSize) < kWordSize)
- error("Error reading word list");
-
- word = Common::String((char *)buf, kWordSize);
-
- if (!map.contains(word))
- map[word] = index;
- }
- }
-}
-
-Common::String Parser::getLine() {
- // Original engine uses a global here, which isn't reset between
- // calls and may not match actual mode
- bool textMode = false;
-
- while (1) {
- Common::String line = _display.inputString(APPLECHAR('?'));
-
- if (g_engine->shouldQuit())
- return "";
-
- if ((byte)line[0] == ('\r' | 0x80)) {
- textMode = !textMode;
- _display.setMode(textMode ? Display::kModeText : Display::kModeMixed);
- continue;
- }
-
- // Remove the return
- line.deleteLastChar();
- return line;
- }
-}
-
-Common::String Parser::getWord(const Common::String &line, uint &index) {
- Common::String str;
-
- for (uint i = 0; i < 8; ++i)
- str += APPLECHAR(' ');
-
- int copied = 0;
-
- // Skip initial whitespace
- while (1) {
- if (index == line.size())
- return str;
- if (line[index] != APPLECHAR(' '))
- break;
- ++index;
- }
-
- // Copy up to 8 characters
- while (1) {
- if (copied < 8)
- str.setChar(line[index], copied++);
-
- index++;
-
- if (index == line.size() || line[index] == APPLECHAR(' '))
- return str;
- }
-}
-
-void Parser::getInput(uint &verb, uint &noun) {
- while (1) {
- _display.printString(_engine.getEngineString(IDI_STR_ENTER_COMMAND));
- Common::String line = getLine();
-
- if (g_engine->shouldQuit())
- return;
-
- uint index = 0;
- Common::String verbStr = getWord(line, index);
-
- if (!_verbs.contains(verbStr)) {
- Common::String err = _engine.getEngineString(IDI_STR_VERB_ERROR);
- for (uint i = 0; i < verbStr.size(); ++i)
- err.setChar(verbStr[i], i + 19);
- _display.printString(err);
- continue;
- }
-
- verb = _verbs[verbStr];
-
- Common::String nounStr = getWord(line, index);
-
- if (!_nouns.contains(nounStr)) {
- Common::String err = _engine.getEngineString(IDI_STR_NOUN_ERROR);
- for (uint i = 0; i < verbStr.size(); ++i)
- err.setChar(verbStr[i], i + 19);
- for (uint i = 0; i < nounStr.size(); ++i)
- err.setChar(nounStr[i], i + 30);
- _display.printString(err);
- continue;
- }
-
- noun = _nouns[nounStr];
- return;
- }
-}
-
-} // End of namespace Adl
diff --git a/engines/adl/parser.h b/engines/adl/parser.h
deleted file mode 100644
index 3c191d90f6..0000000000
--- a/engines/adl/parser.h
+++ /dev/null
@@ -1,66 +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 ADL_PARSER_H
-#define ADL_PARSER_H
-
-#include "common/types.h"
-#include "common/hashmap.h"
-#include "common/hash-str.h"
-
-namespace Common {
-class ReadStream;
-class String;
-}
-
-namespace Adl {
-
-class Display;
-
-class Parser {
-public:
- Parser(AdlEngine &engine, Display &display);
-
- void loadVerbs(Common::ReadStream &stream) { loadWords(stream, _verbs); }
- void loadNouns(Common::ReadStream &stream) { loadWords(stream, _nouns); }
- void getInput(uint &verb, uint &noun);
-
-private:
- enum {
- kWordSize = 8
- };
-
- typedef Common::HashMap<Common::String, uint> WordMap;
-
- void loadWords(Common::ReadStream &stream, WordMap &map);
- Common::String getLine();
- Common::String getWord(const Common::String &line, uint &index);
-
- AdlEngine &_engine;
- Display &_display;
- WordMap _verbs;
- WordMap _nouns;
-};
-
-} // End of namespace Adl
-
-#endif