From 3507b09207bb945319e020d5b9d0814f8d9f62ea Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Tue, 1 Feb 2022 22:00:33 +0100 Subject: [PATCH] Optimize PETSCII conversion in charwin --- include/c64/charwin.c | 10 ++++++---- oscar64/Declaration.cpp | 23 +++++++++++++++++++++-- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/include/c64/charwin.c b/include/c64/charwin.c index 1b0d3d2..eb913f2 100644 --- a/include/c64/charwin.c +++ b/include/c64/charwin.c @@ -181,17 +181,19 @@ bool cwin_cursor_backward(CharWin * win) return false; } -static char p2smap[] = {0x00, 0x20, 0x00, 0x40, 0x00, 0x60, 0x40, 0x60}; -static char s2pmap[] = {0x40, 0x20, 0x60, 0xb0, 0x40, 0x20, 0x60, 0xb0}; +//static char p2smap[] = {0x00, 0x20, 0x00, 0x40, 0x00, 0x60, 0x40, 0x60}; +static char p2smap[] = {0x00, 0x00, 0x40, 0x20, 0x80, 0xc0, 0x80, 0x80}; +//static char s2pmap[] = {0x40, 0x20, 0x60, 0xa0, 0x40, 0x20, 0x60, 0xa0}; +static char s2pmap[] = {0x40, 0x00, 0x20, 0xc0, 0xc0, 0x80, 0xa0, 0x40}; static inline char p2s(char ch) { - return (ch & 0x1f) | p2smap[ch >> 5]; + return ch ^ p2smap[ch >> 5]; } static inline char s2p(char ch) { - return (ch & 0x1f) | s2pmap[ch >> 5]; + return ch ^ s2pmap[ch >> 5]; } void cwin_read_string(CharWin * win, char * buffer) diff --git a/oscar64/Declaration.cpp b/oscar64/Declaration.cpp index 9d10f12..fb20c3a 100644 --- a/oscar64/Declaration.cpp +++ b/oscar64/Declaration.cpp @@ -226,7 +226,7 @@ Expression* Expression::ConstantFold(Errors * errors) return ex; } } - else if (mLeft->mDecType->mType == DT_CONST_INTEGER) + else if (mLeft->mDecType->mType == DT_TYPE_INTEGER) { if (mRight->mDecValue->mType == DT_CONST_FLOAT) { @@ -238,8 +238,27 @@ Expression* Expression::ConstantFold(Errors * errors) ex->mDecType = mLeft->mDecType; return ex; } + else if (mRight->mDecValue->mType == DT_CONST_INTEGER) + { + int64 sval = 1ULL << (8 * mLeft->mDecType->mSize); + int64 v = mRight->mDecValue->mInteger & (sval - 1); + + if (mLeft->mDecType->mFlags & DTF_SIGNED) + { + if (v & (sval >> 1)) + v -= sval; + } + + Expression* ex = new Expression(mLocation, EX_CONSTANT); + Declaration* dec = new Declaration(mLocation, DT_CONST_INTEGER); + dec->mBase = mLeft->mDecType; + dec->mInteger = v; + ex->mDecValue = dec; + ex->mDecType = mLeft->mDecType; + return ex; + } } - else if (mLeft->mDecType->mType == DT_CONST_FLOAT) + else if (mLeft->mDecType->mType == DT_TYPE_FLOAT) { if (mRight->mDecValue->mType == DT_CONST_INTEGER) {