From 73c2206a1a23666ce4f7e083284bf18a784d74d0 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Mon, 30 Sep 2024 20:13:54 +0200 Subject: [PATCH] Improve bankof implementation --- oscar64/InterCodeGenerator.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/oscar64/InterCodeGenerator.cpp b/oscar64/InterCodeGenerator.cpp index a2ba9d8..e36b67b 100644 --- a/oscar64/InterCodeGenerator.cpp +++ b/oscar64/InterCodeGenerator.cpp @@ -3286,14 +3286,28 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* } case TK_BANKOF: { - LinkerRegion* rgn; - if (exp->mLeft->mDecValue->mSection && (rgn = mLinker->FindRegionOfSection(exp->mLeft->mDecValue->mSection))) + if (exp->mLeft->mDecValue) { - uint64 i = 0; - while (i < 64 && rgn->mCartridgeBanks != (1ULL << i)) - i++; - if (i < 64) + LinkerSection* section = nullptr; + + if (exp->mLeft->mDecValue->mSection) { + section = exp->mLeft->mDecValue->mSection; + } + else if (exp->mLeft->mDecValue->mType == DT_CONST_INTEGER) + { + section = proc->mLinkerObject->mSection; + } + + if (section) + { + LinkerRegion* rgn = mLinker->FindRegionOfSection(section); + uint64 i = 0; + while (i < 64 && rgn->mCartridgeBanks != (1ULL << i)) + i++; + if (i == 64) + i = 255; + ins->mCode = IC_CONSTANT; ins->mNumOperands = 0; ins->mConst.mType = IT_INT8;