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;
for (uint i = 0; i < line.size(); ++i)
native += APPLECHAR(line[i]);
native += _display->asciiToNative(line[i]);
_display->printString(native);
// 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:
if (!s.empty()) {
_display->moveCursorBackward();
_display->setCharAtCursor(APPLECHAR(' '));
_display->setCharAtCursor(_display->asciiToNative(' '));
s.deleteLastChar();
}
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 (_inputScript && !_scriptPaused)
return APPLECHAR('\r');
return _display->asciiToNative('\r');
if (showCursor)
_display->showCursor(true);
@ -257,7 +257,7 @@ byte AdlEngine::inputKey(bool showCursor) const {
// If debug script was activated in the meantime, abort input
if (_inputScript && !_scriptPaused)
return APPLECHAR('\r');
return _display->asciiToNative('\r');
_display->copyTextSurface();
g_system->delayMillis(16);
@ -991,7 +991,7 @@ byte AdlEngine::convertKey(uint16 ascii) const {
Common::String AdlEngine::getLine() {
while (1) {
Common::String line = inputString(APPLECHAR('?'));
Common::String line = inputString(_display->asciiToNative('?'));
if (shouldQuit() || _isRestoring)
return Common::String();
@ -1010,9 +1010,10 @@ Common::String AdlEngine::getLine() {
Common::String AdlEngine::getWord(const Common::String &line, uint &index) const {
Common::String str;
const char spaceChar = _display->asciiToNative(' ');
for (uint i = 0; i < 8; ++i)
str += APPLECHAR(' ');
str += spaceChar;
int copied = 0;
@ -1020,7 +1021,7 @@ Common::String AdlEngine::getWord(const Common::String &line, uint &index) const
while (1) {
if (index == line.size())
return str;
if (line[index] != APPLECHAR(' '))
if (line[index] != spaceChar)
break;
++index;
}
@ -1032,7 +1033,7 @@ Common::String AdlEngine::getWord(const Common::String &line, uint &index) const
index++;
if (index == line.size() || line[index] == APPLECHAR(' '))
if (index == line.size() || line[index] == spaceChar)
return str;
}
}
@ -1249,7 +1250,7 @@ int AdlEngine::o_restart(ScriptEnv &e) {
_display->printString(_strings.playAgain);
Common::String input = inputString();
if (input.size() == 0 || input[0] != APPLECHAR('N')) {
if (input.size() == 0 || input[0] != _display->asciiToNative('N')) {
_isRestarting = true;
_graphics->clearScreen();
_display->copyGfxSurface();

View File

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

View File

@ -528,7 +528,7 @@ int AdlEngine_v4::o_save(ScriptEnv &e) {
if (shouldQuit())
return -1;
if (key != APPLECHAR('Y'))
if (key != _display->asciiToNative('Y'))
return 0;
const int slot = askForSlot(_strings_v2.saveInsert);
@ -569,9 +569,9 @@ int AdlEngine_v4::o_restart(ScriptEnv &e) {
if (shouldQuit())
return -1;
if (input.firstChar() == APPLECHAR('N')) {
if (input.firstChar() == _display->asciiToNative('N')) {
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
initState();
// Long jump

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -216,7 +216,7 @@ void HiRes6Engine::runIntro() {
error("Failed to open disk volume 0");
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;
@ -339,13 +339,15 @@ Common::String HiRes6Engine::formatVerbError(const Common::String &verb) const {
for (uint i = 0; i < verb.size(); ++i)
err.setChar(verb[i], i + 24);
err.setChar(APPLECHAR(' '), 32);
const char spaceChar = _display->asciiToNative(' ');
err.setChar(spaceChar, 32);
uint i = 24;
while (err[i] != APPLECHAR(' '))
while (err[i] != spaceChar)
++i;
err.setChar(APPLECHAR('.'), i);
err.setChar(_display->asciiToNative('.'), i);
return err;
}
@ -356,16 +358,18 @@ Common::String HiRes6Engine::formatNounError(const Common::String &verb, const C
for (uint i = 0; i < noun.size(); ++i)
err.setChar(noun[i], i + 24);
const char spaceChar = _display->asciiToNative(' ');
for (uint i = 35; i > 31; --i)
err.setChar(APPLECHAR(' '), i);
err.setChar(spaceChar, i);
uint i = 24;
while (err[i] != APPLECHAR(' '))
while (err[i] != spaceChar)
++i;
err.setChar(APPLECHAR('I'), i + 1);
err.setChar(APPLECHAR('S'), i + 2);
err.setChar(APPLECHAR('.'), i + 3);
err.setChar(_display->asciiToNative('I'), i + 1);
err.setChar(_display->asciiToNative('S'), i + 2);
err.setChar(_display->asciiToNative('.'), i + 3);
return err;
}
@ -409,7 +413,7 @@ void HiRes6Engine::printString(const Common::String &str) {
if (getVar(2) == 0xff) {
if (getVar(26) == 0) {
// 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);
} else {
AdlEngine_v5::printString(s);