ADL: Remove APPLECHAR macro

This commit is contained in:
Walter van Niftrik 2018-08-02 10:56:49 +02:00
parent 0cd761086a
commit ce8a840933
13 changed files with 75 additions and 64 deletions

View file

@ -182,7 +182,7 @@ Common::String AdlEngine::inputString(byte prompt) const {
Common::String native; Common::String native;
for (uint i = 0; i < line.size(); ++i) for (uint i = 0; i < line.size(); ++i)
native += APPLECHAR(line[i]); native += _display->asciiToNative(line[i]);
_display->printString(native); _display->printString(native);
// Set pause flag to activate regular behaviour of delay and inputKey // Set pause flag to activate regular behaviour of delay and inputKey
@ -214,7 +214,7 @@ Common::String AdlEngine::inputString(byte prompt) const {
case Common::KEYCODE_BACKSPACE | 0x80: case Common::KEYCODE_BACKSPACE | 0x80:
if (!s.empty()) { if (!s.empty()) {
_display->moveCursorBackward(); _display->moveCursorBackward();
_display->setCharAtCursor(APPLECHAR(' ')); _display->setCharAtCursor(_display->asciiToNative(' '));
s.deleteLastChar(); s.deleteLastChar();
} }
break; break;
@ -233,7 +233,7 @@ byte AdlEngine::inputKey(bool showCursor) const {
// If debug script is active, we fake a return press for the text overflow handling // If debug script is active, we fake a return press for the text overflow handling
if (_inputScript && !_scriptPaused) if (_inputScript && !_scriptPaused)
return APPLECHAR('\r'); return _display->asciiToNative('\r');
if (showCursor) if (showCursor)
_display->showCursor(true); _display->showCursor(true);
@ -257,7 +257,7 @@ byte AdlEngine::inputKey(bool showCursor) const {
// If debug script was activated in the meantime, abort input // If debug script was activated in the meantime, abort input
if (_inputScript && !_scriptPaused) if (_inputScript && !_scriptPaused)
return APPLECHAR('\r'); return _display->asciiToNative('\r');
_display->copyTextSurface(); _display->copyTextSurface();
g_system->delayMillis(16); g_system->delayMillis(16);
@ -991,7 +991,7 @@ byte AdlEngine::convertKey(uint16 ascii) const {
Common::String AdlEngine::getLine() { Common::String AdlEngine::getLine() {
while (1) { while (1) {
Common::String line = inputString(APPLECHAR('?')); Common::String line = inputString(_display->asciiToNative('?'));
if (shouldQuit() || _isRestoring) if (shouldQuit() || _isRestoring)
return Common::String(); return Common::String();
@ -1010,9 +1010,10 @@ Common::String AdlEngine::getLine() {
Common::String AdlEngine::getWord(const Common::String &line, uint &index) const { Common::String AdlEngine::getWord(const Common::String &line, uint &index) const {
Common::String str; Common::String str;
const char spaceChar = _display->asciiToNative(' ');
for (uint i = 0; i < 8; ++i) for (uint i = 0; i < 8; ++i)
str += APPLECHAR(' '); str += spaceChar;
int copied = 0; int copied = 0;
@ -1020,7 +1021,7 @@ Common::String AdlEngine::getWord(const Common::String &line, uint &index) const
while (1) { while (1) {
if (index == line.size()) if (index == line.size())
return str; return str;
if (line[index] != APPLECHAR(' ')) if (line[index] != spaceChar)
break; break;
++index; ++index;
} }
@ -1032,7 +1033,7 @@ Common::String AdlEngine::getWord(const Common::String &line, uint &index) const
index++; index++;
if (index == line.size() || line[index] == APPLECHAR(' ')) if (index == line.size() || line[index] == spaceChar)
return str; return str;
} }
} }
@ -1249,7 +1250,7 @@ int AdlEngine::o_restart(ScriptEnv &e) {
_display->printString(_strings.playAgain); _display->printString(_strings.playAgain);
Common::String input = inputString(); Common::String input = inputString();
if (input.size() == 0 || input[0] != APPLECHAR('N')) { if (input.size() == 0 || input[0] != _display->asciiToNative('N')) {
_isRestarting = true; _isRestarting = true;
_graphics->clearScreen(); _graphics->clearScreen();
_display->copyGfxSurface(); _display->copyGfxSurface();

View file

@ -101,7 +101,7 @@ void AdlEngine_v2::advanceClock() {
} }
void AdlEngine_v2::checkTextOverflow(char c) { void AdlEngine_v2::checkTextOverflow(char c) {
if (c != APPLECHAR('\r')) if (c != _display->asciiToNative('\r'))
return; return;
++_linesPrinted; ++_linesPrinted;
@ -135,7 +135,7 @@ void AdlEngine_v2::handleTextOverflow() {
if (shouldQuit()) if (shouldQuit())
return; return;
if (key == APPLECHAR('\r')) if (key == _display->asciiToNative('\r'))
break; break;
bell(3); bell(3);
@ -158,16 +158,19 @@ void AdlEngine_v2::printString(const Common::String &str) {
uint startPos = 0; uint startPos = 0;
uint pos = 0; uint pos = 0;
const char spaceChar = _display->asciiToNative(' ');
const char returnChar = _display->asciiToNative('\r');
while (pos < s.size()) { while (pos < s.size()) {
s.setChar(APPLECHAR(s[pos]), pos); s.setChar(_display->asciiToNative(s[pos]), pos);
if (pos == endPos) { if (pos == endPos) {
while (s[pos] != APPLECHAR(' ') && s[pos] != APPLECHAR('\r')) { while (s[pos] != spaceChar && s[pos] != returnChar) {
if (pos-- == startPos) if (pos-- == startPos)
error("Word wrapping failed"); error("Word wrapping failed");
} }
s.setChar(APPLECHAR('\r'), pos); s.setChar(returnChar, pos);
endPos = pos + textWidth; endPos = pos + textWidth;
startPos = pos + 1; startPos = pos + 1;
} }
@ -180,8 +183,8 @@ void AdlEngine_v2::printString(const Common::String &str) {
_display->printChar(s[pos]); _display->printChar(s[pos]);
} }
checkTextOverflow(APPLECHAR('\r')); checkTextOverflow(returnChar);
_display->printChar(APPLECHAR('\r')); _display->printChar(returnChar);
_display->copyTextSurface(); _display->copyTextSurface();
} }
@ -565,10 +568,12 @@ int AdlEngine_v2::o_tellTime(ScriptEnv &e) {
Common::String time = _strings_v2.time; Common::String time = _strings_v2.time;
time.setChar(APPLECHAR('0') + _state.time.hours / 10, 12); const char zeroChar = _display->asciiToNative('0');
time.setChar(APPLECHAR('0') + _state.time.hours % 10, 13);
time.setChar(APPLECHAR('0') + _state.time.minutes / 10, 15); time.setChar(zeroChar + _state.time.hours / 10, 12);
time.setChar(APPLECHAR('0') + _state.time.minutes % 10, 16); time.setChar(zeroChar + _state.time.hours % 10, 13);
time.setChar(zeroChar + _state.time.minutes / 10, 15);
time.setChar(zeroChar + _state.time.minutes % 10, 16);
printString(time); printString(time);
@ -611,8 +616,8 @@ int AdlEngine_v2::askForSlot(const Common::String &question) {
if (shouldQuit()) if (shouldQuit())
return -1; return -1;
if (input.size() > 0 && input[0] >= APPLECHAR('A') && input[0] <= APPLECHAR('O')) if (input.size() > 0 && input[0] >= _display->asciiToNative('A') && input[0] <= _display->asciiToNative('O'))
return input[0] - APPLECHAR('A'); return input[0] - _display->asciiToNative('A');
} }
} }

View file

@ -528,7 +528,7 @@ int AdlEngine_v4::o_save(ScriptEnv &e) {
if (shouldQuit()) if (shouldQuit())
return -1; return -1;
if (key != APPLECHAR('Y')) if (key != _display->asciiToNative('Y'))
return 0; return 0;
const int slot = askForSlot(_strings_v2.saveInsert); const int slot = askForSlot(_strings_v2.saveInsert);
@ -569,9 +569,9 @@ int AdlEngine_v4::o_restart(ScriptEnv &e) {
if (shouldQuit()) if (shouldQuit())
return -1; return -1;
if (input.firstChar() == APPLECHAR('N')) { if (input.firstChar() == _display->asciiToNative('N')) {
return o_quit(e); return o_quit(e);
} else if (input.firstChar() == APPLECHAR('Y')) { } else if (input.firstChar() == _display->asciiToNative('Y')) {
// The original game loads a special save game from volume 3 // The original game loads a special save game from volume 3
initState(); initState();
// Long jump // Long jump

View file

@ -115,7 +115,7 @@ int AdlEngine_v5::o_setTextMode(ScriptEnv &e) {
switch (e.arg(1)) { switch (e.arg(1)) {
case 1: case 1:
if (_linesPrinted != 0) { if (_linesPrinted != 0) {
_display->printChar(APPLECHAR(' ')); _display->printChar(_display->asciiToNative(' '));
handleTextOverflow(); handleTextOverflow();
_display->moveCursorTo(Common::Point(0, 23)); _display->moveCursorTo(Common::Point(0, 23));
_maxLines = 4; _maxLines = 4;

View file

@ -58,20 +58,20 @@ Common::String Console::toAscii(const Common::String &str) {
return ascii; return ascii;
} }
Common::String Console::toAppleWord(const Common::String &str) { Common::String Console::toNative(const Common::String &str) {
Common::String apple(str); Common::String native(str);
if (apple.size() > IDI_WORD_SIZE) if (native.size() > IDI_WORD_SIZE)
apple.erase(IDI_WORD_SIZE); native.erase(IDI_WORD_SIZE);
apple.toUppercase(); native.toUppercase();
for (uint i = 0; i < apple.size(); ++i) for (uint i = 0; i < native.size(); ++i)
apple.setChar(APPLECHAR(apple[i]), i); native.setChar(_engine->_display->asciiToNative(native[i]), i);
while (apple.size() < IDI_WORD_SIZE) while (native.size() < IDI_WORD_SIZE)
apple += APPLECHAR(' '); native += _engine->_display->asciiToNative(' ');
return apple; return native;
} }
bool Console::Cmd_Verbs(int argc, const char **argv) { bool Console::Cmd_Verbs(int argc, const char **argv) {
@ -270,7 +270,7 @@ bool Console::Cmd_GiveItem(int argc, const char **argv) {
if (*end != 0) { if (*end != 0) {
Common::Array<Item *> matches; Common::Array<Item *> matches;
Common::String name = toAppleWord(argv[1]); Common::String name = toNative(argv[1]);
if (!_engine->_nouns.contains(name)) { if (!_engine->_nouns.contains(name)) {
debugPrintf("Item '%s' not found\n", argv[1]); debugPrintf("Item '%s' not found\n", argv[1]);

View file

@ -41,7 +41,7 @@ public:
Console(AdlEngine *engine); Console(AdlEngine *engine);
static Common::String toAscii(const Common::String &str); static Common::String toAscii(const Common::String &str);
static Common::String toAppleWord(const Common::String &str); Common::String toNative(const Common::String &str);
private: private:
bool Cmd_Nouns(int argc, const char **argv); bool Cmd_Nouns(int argc, const char **argv);

View file

@ -53,7 +53,7 @@ void Display::createTextBuffer(uint textWidth, uint textHeight) {
_textHeight = textHeight; _textHeight = textHeight;
_textBuf = new byte[textWidth * textHeight]; _textBuf = new byte[textWidth * textHeight];
memset(_textBuf, asciiToNative(' '), textWidth * textHeight); memset(_textBuf, (byte)asciiToNative(' '), textWidth * textHeight);
} }
void Display::setMode(Display::Mode mode) { void Display::setMode(Display::Mode mode) {
@ -88,7 +88,7 @@ void Display::copyGfxSurface() {
} }
void Display::home() { void Display::home() {
memset(_textBuf, asciiToNative(' '), _textWidth * _textHeight); memset(_textBuf, (byte)asciiToNative(' '), _textWidth * _textHeight);
_cursorPos = 0; _cursorPos = 0;
} }

View file

@ -23,9 +23,6 @@
#ifndef ADL_DISPLAY_H #ifndef ADL_DISPLAY_H
#define ADL_DISPLAY_H #define ADL_DISPLAY_H
// REMOVE
#define APPLECHAR(C) (char)(C | 0x80)
#include "common/types.h" #include "common/types.h"
namespace Common { namespace Common {

View file

@ -239,9 +239,9 @@ void Display_A2::clear(byte color) {
// FIXME: This does not currently update the surfaces // FIXME: This does not currently update the surfaces
void Display_A2::printChar(char c) { void Display_A2::printChar(char c) {
if (c == APPLECHAR('\r')) if (c == Display_A2::asciiToNative('\r'))
_cursorPos = (_cursorPos / Display_A2::kTextWidth + 1) * Display_A2::kTextWidth; _cursorPos = (_cursorPos / Display_A2::kTextWidth + 1) * Display_A2::kTextWidth;
else if (c == APPLECHAR('\a')) { else if (c == Display_A2::asciiToNative('\a')) {
copyTextSurface(); copyTextSurface();
static_cast<AdlEngine *>(g_engine)->bell(); static_cast<AdlEngine *>(g_engine)->bell();
} else if ((byte)c < 0x80 || (byte)c >= 0xa0) { } else if ((byte)c < 0x80 || (byte)c >= 0xa0) {

View file

@ -214,10 +214,10 @@ void HiRes1Engine::runIntro() {
if (s.empty()) if (s.empty())
continue; continue;
if (s[0] == APPLECHAR('I')) { if (s[0] == _display->asciiToNative('I')) {
instructions = true; instructions = true;
break; break;
} else if (s[0] == APPLECHAR('G')) { } else if (s[0] == _display->asciiToNative('G')) {
break; break;
} }
} }
@ -397,8 +397,9 @@ void HiRes1Engine::printString(const Common::String &str) {
} }
Common::String HiRes1Engine::loadMessage(uint idx) const { Common::String HiRes1Engine::loadMessage(uint idx) const {
const char returnChar = _display->asciiToNative('\r');
StreamPtr stream(_messages[idx]->createReadStream()); StreamPtr stream(_messages[idx]->createReadStream());
return readString(*stream, APPLECHAR('\r')) + APPLECHAR('\r'); return readString(*stream, returnChar) + returnChar;
} }
void HiRes1Engine::printMessage(uint idx) { void HiRes1Engine::printMessage(uint idx) {
@ -487,14 +488,17 @@ void HiRes1Engine::showRoom() {
void HiRes1Engine::wordWrap(Common::String &str) const { void HiRes1Engine::wordWrap(Common::String &str) const {
uint end = 39; uint end = 39;
const char spaceChar = _display->asciiToNative(' ');
const char returnChar = _display->asciiToNative('\r');
while (1) { while (1) {
if (str.size() <= end) if (str.size() <= end)
return; return;
while (str[end] != APPLECHAR(' ')) while (str[end] != spaceChar)
--end; --end;
str.setChar(APPLECHAR('\r'), end); str.setChar(returnChar, end);
end += 40; end += 40;
} }
} }

View file

@ -244,7 +244,7 @@ void HiRes4Engine::runIntroAdvise(Common::SeekableReadStream &menu) {
} }
_display->moveCursorTo(Common::Point(32, 18)); _display->moveCursorTo(Common::Point(32, 18));
_display->printChar(APPLECHAR(cursor[cursorIdx])); _display->printChar(_display->asciiToNative(cursor[cursorIdx]));
_display->copyTextSurface(); _display->copyTextSurface();
g_system->delayMillis(25); g_system->delayMillis(25);
cursorIdx = (cursorIdx + 1) % cursor.size(); cursorIdx = (cursorIdx + 1) % cursor.size();
@ -450,11 +450,11 @@ void HiRes4Engine::runIntro() {
if (shouldQuit()) if (shouldQuit())
return; return;
if (key == APPLECHAR('1')) { if (key == _display->asciiToNative('1')) {
StreamPtr instructions(files->createReadStream("INSTRUCTIONS")); StreamPtr instructions(files->createReadStream("INSTRUCTIONS"));
runIntroInstructions(*instructions); runIntroInstructions(*instructions);
break; break;
} else if (key == APPLECHAR('2')) { } else if (key == _display->asciiToNative('2')) {
StreamPtr adventure(files->createReadStream("THE ADVENTURE")); StreamPtr adventure(files->createReadStream("THE ADVENTURE"));
runIntroLoading(*adventure); runIntroLoading(*adventure);
return; return;

View file

@ -261,7 +261,7 @@ void HiRes5Engine::runIntro() {
Common::String cmd(inputString()); Common::String cmd(inputString());
// We ignore the backup and format menu options // We ignore the backup and format menu options
if (!cmd.empty() && cmd[0] == APPLECHAR('1')) if (!cmd.empty() && cmd[0] == _display->asciiToNative('1'))
break; break;
}; };
} }

View file

@ -216,7 +216,7 @@ void HiRes6Engine::runIntro() {
error("Failed to open disk volume 0"); error("Failed to open disk volume 0");
stream.reset(files->createReadStream("\010\010\010\010\010\010")); stream.reset(files->createReadStream("\010\010\010\010\010\010"));
Common::String copyright(readStringAt(*stream, 0x103, APPLECHAR('\r'))); Common::String copyright(readStringAt(*stream, 0x103, _display->asciiToNative('\r')));
delete files; delete files;
@ -339,13 +339,15 @@ Common::String HiRes6Engine::formatVerbError(const Common::String &verb) const {
for (uint i = 0; i < verb.size(); ++i) for (uint i = 0; i < verb.size(); ++i)
err.setChar(verb[i], i + 24); err.setChar(verb[i], i + 24);
err.setChar(APPLECHAR(' '), 32); const char spaceChar = _display->asciiToNative(' ');
err.setChar(spaceChar, 32);
uint i = 24; uint i = 24;
while (err[i] != APPLECHAR(' ')) while (err[i] != spaceChar)
++i; ++i;
err.setChar(APPLECHAR('.'), i); err.setChar(_display->asciiToNative('.'), i);
return err; return err;
} }
@ -356,16 +358,18 @@ Common::String HiRes6Engine::formatNounError(const Common::String &verb, const C
for (uint i = 0; i < noun.size(); ++i) for (uint i = 0; i < noun.size(); ++i)
err.setChar(noun[i], i + 24); err.setChar(noun[i], i + 24);
const char spaceChar = _display->asciiToNative(' ');
for (uint i = 35; i > 31; --i) for (uint i = 35; i > 31; --i)
err.setChar(APPLECHAR(' '), i); err.setChar(spaceChar, i);
uint i = 24; uint i = 24;
while (err[i] != APPLECHAR(' ')) while (err[i] != spaceChar)
++i; ++i;
err.setChar(APPLECHAR('I'), i + 1); err.setChar(_display->asciiToNative('I'), i + 1);
err.setChar(APPLECHAR('S'), i + 2); err.setChar(_display->asciiToNative('S'), i + 2);
err.setChar(APPLECHAR('.'), i + 3); err.setChar(_display->asciiToNative('.'), i + 3);
return err; return err;
} }
@ -409,7 +413,7 @@ void HiRes6Engine::printString(const Common::String &str) {
if (getVar(2) == 0xff) { if (getVar(2) == 0xff) {
if (getVar(26) == 0) { if (getVar(26) == 0) {
// This checks for special room description string " " // This checks for special room description string " "
if (str.size() == 1 && APPLECHAR(str[0]) == APPLECHAR(' ')) { if (str.size() == 1 && _display->asciiToNative(str[0]) == _display->asciiToNative(' ')) {
setVar(2, 160); setVar(2, 160);
} else { } else {
AdlEngine_v5::printString(s); AdlEngine_v5::printString(s);