diff --git a/README.md b/README.md index b7ffa55..6d519a4 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,10 @@ The translation mode is selected in conio with the variable "giocharmap" and the Will switch to the lowercase PETSCII font and translate the strings while printing. +PETSCII string literals can also be generated using a "p" or "P" prefix such as: + + printf(p"Hello World\n"); + Input from the console will also be translated accordingly. ## Embedding binary data diff --git a/oscar64/InterCodeGenerator.cpp b/oscar64/InterCodeGenerator.cpp index c241742..57c3b64 100644 --- a/oscar64/InterCodeGenerator.cpp +++ b/oscar64/InterCodeGenerator.cpp @@ -2820,6 +2820,11 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Cannot cast void object to non void object"); return ExValue(exp->mLeft->mDecType, vr.mTemp, vr.mReference); } + else if (exp->mLeft->mDecType->IsIntegerType() && vr.mType->IsIntegerType()) + { + vr = Dereference(proc, block, vr); + return CoerceType(proc, block, vr, exp->mLeft->mDecType); + } else { vr = Dereference(proc, block, vr); diff --git a/oscar64/Scanner.cpp b/oscar64/Scanner.cpp index 246d44a..b0a6783 100644 --- a/oscar64/Scanner.cpp +++ b/oscar64/Scanner.cpp @@ -458,7 +458,7 @@ void Scanner::NextToken(void) else if (mToken == TK_LESS_THAN) { mOffset--; - StringToken('>'); + StringToken('>', 'a'); if (!mPreprocessor->OpenSource("Including", mTokenString, false)) mErrors->Error(mLocation, EERR_FILE_NOT_FOUND, "Could not open source file", mTokenString); } @@ -621,7 +621,7 @@ void Scanner::NextToken(void) else if (mToken == TK_LESS_THAN) { mOffset--; - StringToken('>'); + StringToken('>', 'a'); if (!mPreprocessor->EmbedData("Embedding", mTokenString, false, skip, limit)) mErrors->Error(mLocation, EERR_FILE_NOT_FOUND, "Could not open source file", mTokenString); } @@ -1021,10 +1021,10 @@ void Scanner::NextRawToken(void) break; case '\'': - CharToken(); + CharToken('a'); break; case '"': - StringToken(mTokenChar); + StringToken(mTokenChar, 'a'); break; case '#': @@ -1136,6 +1136,19 @@ void Scanner::NextRawToken(void) else break; } + if (n == 1) + { + if (mTokenChar == '"') + { + StringToken(mTokenChar, tkident[0]); + break; + } + else if (mTokenChar == '\'') + { + CharToken(tkident[0]); + break; + } + } tkident[n] = 0; if (n == 256) Error("Identifier exceeds max character limit"); @@ -1238,7 +1251,7 @@ void Scanner::Error(const char* error) mErrors->Error(mLocation, EERR_SYNTAX, error); } -void Scanner::StringToken(char terminator) +void Scanner::StringToken(char terminator, char mode) { int n = 0; @@ -1295,6 +1308,28 @@ void Scanner::StringToken(char terminator) if (mLine[mOffset] && mLine[mOffset] == terminator) { + switch (mode) + { + case 'a': + break; + case 'p': + for (int i = 0; i < n; i++) + { + if (mTokenString[i] >= 'A' && mTokenString[i] <= 'Z' || mTokenString[i] >= 'a' && mTokenString[i] <= 'z') + mTokenString[i] = mTokenString[i] ^ 0x20; + } + break; + case 'P': + for (int i = 0; i < n; i++) + { + if (mTokenString[i] >= 'A' && mTokenString[i] <= 'Z' || mTokenString[i] >= 'a' && mTokenString[i] <= 'z') + mTokenString[i] = (mTokenString[i] ^ 0x20) & 0xdf; + } + break; + default: + Error("Invalid string literal mode"); + } + mToken = TK_STRING; mOffset++; NextChar(); @@ -1308,7 +1343,7 @@ void Scanner::StringToken(char terminator) } -void Scanner::CharToken(void) +void Scanner::CharToken(char mode) { int n = 0; @@ -1356,6 +1391,22 @@ void Scanner::CharToken(void) } } + switch (mode) + { + case 'a': + break; + case 'p': + if (mTokenChar >= 'A' && mTokenChar <= 'Z' || mTokenChar >= 'a' && mTokenChar <= 'z') + mTokenChar = mTokenChar ^ 0x20; + break; + case 'P': + if (mTokenChar >= 'A' && mTokenChar <= 'Z' || mTokenChar >= 'a' && mTokenChar <= 'z') + mTokenChar = (mTokenChar ^ 0x20) & 0xdf; + break; + default: + Error("Invalid string literal mode"); + } + mTokenInteger = mTokenChar; if (mLine[mOffset] && mLine[mOffset] == '\'') diff --git a/oscar64/Scanner.h b/oscar64/Scanner.h index ec0743a..e9cbda1 100644 --- a/oscar64/Scanner.h +++ b/oscar64/Scanner.h @@ -226,8 +226,8 @@ protected: MacroDict* mDefines, * mDefineArguments; - void StringToken(char terminator); - void CharToken(void); + void StringToken(char terminator, char mode); + void CharToken(char mode); bool NextChar(void); void ParseNumberToken(void);