From 085fba137f97c376f293029cba5e868438efd24f Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Thu, 6 Jan 2022 16:26:19 +0100 Subject: [PATCH] optimize aligned address arithmetic --- include/c64/keyboard.c | 17 ++++++++++++++--- include/c64/keyboard.h | 9 +++++++++ oscar64/NativeCodeGenerator.cpp | 13 +++++++++++-- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/include/c64/keyboard.c b/include/c64/keyboard.c index 5a7ad2f..055e0af 100644 --- a/include/c64/keyboard.c +++ b/include/c64/keyboard.c @@ -26,6 +26,18 @@ const char keyb_codes[128] = { byte keyb_matrix[8], keyb_key; static byte keyb_pmatrix[8]; +bool key_pressed(char code) +{ + return !(keyb_matrix[code >> 3] & (1 << (code & 7))); +} + +bool key_shift(void) +{ + return + !(keyb_matrix[6] & 0x10) || + !(keyb_matrix[1] & 0x80); +} + void keyb_poll(void) { cia1.ddra = 0xff; @@ -65,9 +77,8 @@ void keyb_poll(void) } } - keyb_key |= ~(((keyb_matrix[6] << 3) & keyb_matrix[1]) >> 1) & 0x40; -// if (keyb_key && (!(keyb_matrix[1] & 0x80) || (!(keyb_matrix[6] & 0x10)))) -// keyb_key |= 0x40; + if (keyb_key && (!(keyb_matrix[1] & 0x80) || (!(keyb_matrix[6] & 0x10)))) + keyb_key |= 0x40; } else { diff --git a/include/c64/keyboard.h b/include/c64/keyboard.h index e040e4d..d0ae0b5 100644 --- a/include/c64/keyboard.h +++ b/include/c64/keyboard.h @@ -23,6 +23,11 @@ #define KEY_F6 (139) #define KEY_F8 (140) +#define KEY_CODE_CSR_RIGHT (2) +#define KEY_CODE_CSR_DOWN (7) +#define KEY_CODE_LSHIFT (15) +#define KEY_CODE_RSHIFT (48) + // map of keyboard codes to PETSCII, first 64 without shift // second 64 with shift @@ -38,6 +43,10 @@ extern byte keyb_key; void keyb_poll(void); +inline bool key_pressed(char code); + +inline bool key_shift(void); + #pragma compile("keyboard.c") #endif diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index 9919eda..2060722 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -10205,8 +10205,6 @@ bool NativeCodeBasicBlock::OptimizeSimpleLoopInvariant(NativeCodeProcedure* proc bool NativeCodeBasicBlock::OptimizeSimpleLoopInvariant(NativeCodeProcedure* proc, NativeCodeBasicBlock* prevBlock, NativeCodeBasicBlock* exitBlock) { - return false; - bool changed = false; int ai = 0; @@ -13485,7 +13483,18 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(int pass) #endif #endif +#if 1 + if (pass > 1 && mIns[i].mMode == ASMIM_IMMEDIATE_ADDRESS && mIns[i].mLinkerObject && (mIns[i].mFlags & NCIF_LOWER) && !(mIns[i].mAddress & 0xff) && !(mIns[i].mLinkerObject->mAlignment & 0xff)) + { + mIns[i].mMode = ASMIM_IMMEDIATE; + mIns[i].mAddress = 0; + mIns[i].mLinkerObject = nullptr; + mIns[i].mFlags &= ~NCIF_LOWER; + progress = true; + } #endif +#endif + } if (progress)