diff --git a/oscar64/Compiler.cpp b/oscar64/Compiler.cpp index 86df25c..ac66028 100644 --- a/oscar64/Compiler.cpp +++ b/oscar64/Compiler.cpp @@ -108,6 +108,30 @@ void Compiler::RegisterRuntime(const Location & loc, const Ident* ident) } } +void Compiler::CompileProcedure(InterCodeProcedure* proc) +{ + if (!proc->mCompiled) + { + proc->mCompiled = true; + + for (int i = 0; i < proc->mCalledFunctions.Size(); i++) + CompileProcedure(proc->mCalledFunctions[i]); + + if (proc->mNativeProcedure) + { + NativeCodeProcedure* ncproc = new NativeCodeProcedure(mNativeCodeGenerator); + ncproc->Compile(proc); + } + else + { + ByteCodeProcedure* bgproc = new ByteCodeProcedure(); + + bgproc->Compile(mByteCodeGenerator, proc); + mByteCodeFunctions.Push(bgproc); + } + } +} + bool Compiler::GenerateCode(void) { Location loc; @@ -274,7 +298,7 @@ bool Compiler::GenerateCode(void) } #endif - for (int i = mInterCodeModule->mProcedures.Size() - 1; i >=0; i--) + for (int i = 0; i < mInterCodeModule->mProcedures.Size(); i++) { InterCodeProcedure* proc = mInterCodeModule->mProcedures[i]; @@ -284,19 +308,7 @@ bool Compiler::GenerateCode(void) proc->Disassemble("final"); #endif - - if (proc->mNativeProcedure) - { - NativeCodeProcedure* ncproc = new NativeCodeProcedure(mNativeCodeGenerator); - ncproc->Compile(proc); - } - else - { - ByteCodeProcedure* bgproc = new ByteCodeProcedure(); - - bgproc->Compile(mByteCodeGenerator, proc); - mByteCodeFunctions.Push(bgproc); - } + CompileProcedure(proc); } LinkerObject* byteCodeObject = nullptr; diff --git a/oscar64/Compiler.h b/oscar64/Compiler.h index 7001d6f..2df5bcb 100644 --- a/oscar64/Compiler.h +++ b/oscar64/Compiler.h @@ -46,4 +46,6 @@ public: void AddDefine(const Ident* ident, const char* value); void RegisterRuntime(const Location& loc, const Ident* ident); + + void CompileProcedure(InterCodeProcedure* proc); }; diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index 73b4935..d9d8b85 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -8320,7 +8320,8 @@ InterCodeProcedure::InterCodeProcedure(InterCodeModule * mod, const Location & l mRenameTable(-1), mRenameUnionTable(-1), mGlobalRenameTable(-1), mValueForwardingTable(nullptr), mLocalVars(nullptr), mParamVars(nullptr), mModule(mod), mIdent(ident), mLinkerObject(linkerObject), - mNativeProcedure(false), mLeafProcedure(false), mCallsFunctionPointer(false), mCalledFunctions(nullptr), mFastCallProcedure(false), mInterrupt(false), mHardwareInterrupt(false) + mNativeProcedure(false), mLeafProcedure(false), mCallsFunctionPointer(false), mCalledFunctions(nullptr), mFastCallProcedure(false), + mInterrupt(false), mHardwareInterrupt(false), mCompiled(false) { mID = mModule->mProcedures.Size(); mModule->mProcedures.Push(this); diff --git a/oscar64/InterCode.h b/oscar64/InterCode.h index 6f3aae2..83a3e72 100644 --- a/oscar64/InterCode.h +++ b/oscar64/InterCode.h @@ -476,7 +476,7 @@ public: GrowingTypeArray mTemporaries; GrowingIntArray mTempOffset, mTempSizes; int mTempSize, mCommonFrameSize, mCallerSavedTemps; - bool mLeafProcedure, mNativeProcedure, mCallsFunctionPointer, mHasDynamicStack, mHasInlineAssembler, mCallsByteCode, mFastCallProcedure, mInterrupt, mHardwareInterrupt; + bool mLeafProcedure, mNativeProcedure, mCallsFunctionPointer, mHasDynamicStack, mHasInlineAssembler, mCallsByteCode, mFastCallProcedure, mInterrupt, mHardwareInterrupt, mCompiled; GrowingInterCodeProcedurePtrArray mCalledFunctions; InterCodeModule * mModule; diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index 934e1c6..62207b9 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -11227,8 +11227,9 @@ bool NativeCodeBasicBlock::OptimizeSimpleLoopInvariant(NativeCodeProcedure* proc { bool changed = false; + int sz = mIns.Size(); - if (mIns.Size() == 2 && (mBranch == ASMIT_BEQ || mBranch == ASMIT_BNE) && mIns[0].mType == ASMIT_LDA && mIns[1].mType == ASMIT_CMP && !(mIns[1].mFlags & NCIF_VOLATILE) && !(mIns[1].mLive & (LIVE_CPU_REG_A | LIVE_CPU_REG_C))) + if (sz == 2 && (mBranch == ASMIT_BEQ || mBranch == ASMIT_BNE) && mIns[0].mType == ASMIT_LDA && mIns[1].mType == ASMIT_CMP && !(mIns[1].mFlags & NCIF_VOLATILE) && !(mIns[1].mLive & (LIVE_CPU_REG_A | LIVE_CPU_REG_C))) { if (!prevBlock) return OptimizeSimpleLoopInvariant(proc); @@ -11239,6 +11240,21 @@ bool NativeCodeBasicBlock::OptimizeSimpleLoopInvariant(NativeCodeProcedure* proc return true; } + if (sz >= 3 && mIns[0].mType == ASMIT_LDY && mIns[sz - 2].mType == ASMIT_LDA && mIns[0].SameEffectiveAddress(mIns[sz - 2]) && + mIns[sz - 1].mType == ASMIT_CMP && HasAsmInstructionMode(ASMIT_CPY, mIns[sz - 1].mMode) && !(mIns[sz - 1].mLive & LIVE_CPU_REG_A)) + { + if (!prevBlock) + return OptimizeSimpleLoopInvariant(proc); + + mIns[sz - 2].mType = ASMIT_LDY; + mIns[sz - 1].mType = ASMIT_CPY; + + prevBlock->mIns.Push(mIns[0]); + mIns.Remove(0); + return true; + } + + int ai = 0; while (ai < mIns.Size() && !mIns[ai].ChangesAccu()) ai++; diff --git a/oscar64/oscar64.cpp b/oscar64/oscar64.cpp index d71ee6d..7a21605 100644 --- a/oscar64/oscar64.cpp +++ b/oscar64/oscar64.cpp @@ -73,7 +73,7 @@ int main2(int argc, const char** argv) #else strcpy(strProductName, "oscar64"); - strcpy(strProductVersion, "1.4.91"); + strcpy(strProductVersion, "1.4.92"); #ifdef __APPLE__ uint32_t length = sizeof(basePath); diff --git a/oscar64/oscar64.rc b/oscar64/oscar64.rc index 568f6dc..6bf2eba 100644 --- a/oscar64/oscar64.rc +++ b/oscar64/oscar64.rc @@ -25,8 +25,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,4,91,0 - PRODUCTVERSION 1,4,91,0 + FILEVERSION 1,4,92,0 + PRODUCTVERSION 1,4,92,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -43,12 +43,12 @@ BEGIN BEGIN VALUE "CompanyName", "oscar64" VALUE "FileDescription", "oscar64 compiler" - VALUE "FileVersion", "1.4.91.0" + VALUE "FileVersion", "1.4.92.0" VALUE "InternalName", "oscar64.exe" VALUE "LegalCopyright", "Copyright (C) 2021" VALUE "OriginalFilename", "oscar64.exe" VALUE "ProductName", "oscar64" - VALUE "ProductVersion", "1.4.91.0" + VALUE "ProductVersion", "1.4.92.0" END END BLOCK "VarFileInfo" diff --git a/oscar64setup/oscar64setup.vdproj b/oscar64setup/oscar64setup.vdproj index ff54213..b94e9ef 100644 --- a/oscar64setup/oscar64setup.vdproj +++ b/oscar64setup/oscar64setup.vdproj @@ -3752,15 +3752,15 @@ { "Name" = "8:Microsoft Visual Studio" "ProductName" = "8:oscar64" - "ProductCode" = "8:{957F0E7A-5C0E-4F4D-B6B3-21C4459CA152}" - "PackageCode" = "8:{C53FBC0A-F69A-4403-AF50-EED9DCFBF363}" + "ProductCode" = "8:{D70ACED5-5DDD-460B-B934-8B2F6C3F112B}" + "PackageCode" = "8:{E84DF4CA-580F-413D-A830-4499B996E9EC}" "UpgradeCode" = "8:{9AB61EFF-ACAC-4079-9950-8D96615CD4EF}" "AspNetVersion" = "8:2.0.50727.0" "RestartWWWService" = "11:FALSE" "RemovePreviousVersions" = "11:TRUE" "DetectNewerInstalledVersion" = "11:TRUE" "InstallAllUsers" = "11:FALSE" - "ProductVersion" = "8:1.4.91" + "ProductVersion" = "8:1.4.92" "Manufacturer" = "8:oscar64" "ARPHELPTELEPHONE" = "8:" "ARPHELPLINK" = "8:" @@ -4274,7 +4274,7 @@ { "{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_FB2E467BC172457785F4279BB0BFE8B6" { - "SourcePath" = "8:..\\Release\\oscar64.exe" + "SourcePath" = "8:..\\Debug\\oscar64.exe" "TargetName" = "8:" "Tag" = "8:" "Folder" = "8:_607E75AF0E2A4CB9908C4C39DF8FE6E4" diff --git a/samples/games/missile.c b/samples/games/missile.c index c07e529..8c894aa 100644 --- a/samples/games/missile.c +++ b/samples/games/missile.c @@ -833,7 +833,7 @@ int main(void) // Build to multicolor highres at top of screen rirq_build(&top, 3); - rirq_delay(&top, 10); + rirq_delay(&top, 9); rirq_write(&top, 1, &vic.ctrl1, VIC_CTRL1_BMM | VIC_CTRL1_DEN | VIC_CTRL1_RSEL | 3); rirq_write(&top, 2, &vic.memptr, 0x28); rirq_set(0, 57, &top); diff --git a/samples/memmap/easyflash.crt b/samples/memmap/easyflash.crt index fe8ad63..7966478 100644 Binary files a/samples/memmap/easyflash.crt and b/samples/memmap/easyflash.crt differ