diff --git a/include/petscii.h b/include/petscii.h new file mode 100644 index 0000000..fd3d317 --- /dev/null +++ b/include/petscii.h @@ -0,0 +1,5 @@ +/* petscii upper charset */ + +#pragma charmap(97, 65, 26) +#pragma charmap(65, 97, 26) + diff --git a/oscar64/Errors.h b/oscar64/Errors.h index bc63c8f..86e7216 100644 --- a/oscar64/Errors.h +++ b/oscar64/Errors.h @@ -48,6 +48,7 @@ enum ErrorID EERR_ASM_INVALD_OPERAND, EERR_ASM_INVALID_INSTRUCTION, EERR_ASM_INVALID_MODE, + EERR_PRAGMA_PARAMETER, EERR_INVALID_PREPROCESSOR, }; diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index 09659a2..68a4f1a 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -2531,6 +2531,47 @@ void Parser::ParsePragma(void) } ConsumeToken(TK_CLOSE_PARENTHESIS); } + else if (!strcmp(mScanner->mTokenIdent->mString, "charmap")) + { + mScanner->NextToken(); + ConsumeToken(TK_OPEN_PARENTHESIS); + if (mScanner->mToken == TK_INTEGER) + { + int cindex = mScanner->mTokenInteger; + mScanner->NextToken(); + ConsumeToken(TK_COMMA); + + if (mScanner->mToken == TK_INTEGER) + { + int ccode = mScanner->mTokenInteger; + int ccount = 1; + mScanner->NextToken(); + if (ConsumeTokenIf(TK_COMMA)) + { + if (mScanner->mToken == TK_INTEGER) + { + ccount = mScanner->mTokenInteger; + mScanner->NextToken(); + } + else + mErrors->Error(mScanner->mLocation, EERR_PRAGMA_PARAMETER, "Character run expected"); + } + + for (int i = 0; i < ccount; i++) + { + mScanner->mCharMap[cindex] = ccode; + cindex = (cindex + 1) & 255; + ccode = (ccode + 1) & 255; + } + } + else + mErrors->Error(mScanner->mLocation, EERR_PRAGMA_PARAMETER, "Character code expected"); + } + else + mErrors->Error(mScanner->mLocation, EERR_PRAGMA_PARAMETER, "Character index expected"); + + ConsumeToken(TK_CLOSE_PARENTHESIS); + } else { mScanner->NextToken(); diff --git a/oscar64/Scanner.cpp b/oscar64/Scanner.cpp index 5c053bf..6377b6d 100644 --- a/oscar64/Scanner.cpp +++ b/oscar64/Scanner.cpp @@ -259,6 +259,9 @@ Scanner::Scanner(Errors* errors, Preprocessor* preprocessor) mDefines = new MacroDict(); mDefineArguments = nullptr; + for (int i = 0; i < 256; i++) + mCharMap[i] = i; + NextChar(); NextToken(); @@ -1079,7 +1082,7 @@ void Scanner::StringToken(char terminator) } } - mTokenString[n++] = mTokenChar; + mTokenString[n++] = mCharMap[mTokenChar]; } mTokenString[n] = 0; @@ -1147,6 +1150,8 @@ void Scanner::CharToken(void) } } + mTokenChar = mCharMap[mTokenChar]; + mTokenInteger = mTokenChar; if (mLine[mOffset] && mLine[mOffset] == '\'') diff --git a/oscar64/Scanner.h b/oscar64/Scanner.h index ad69491..ef531a9 100644 --- a/oscar64/Scanner.h +++ b/oscar64/Scanner.h @@ -180,6 +180,8 @@ public: int mOffset; const char * mLine; + char mCharMap[256]; + const Ident * mTokenIdent; char mTokenString[1024], mTokenChar;