diff --git a/include/audio/sidfx.c b/include/audio/sidfx.c index 17ed27f..e04827b 100644 --- a/include/audio/sidfx.c +++ b/include/audio/sidfx.c @@ -13,8 +13,8 @@ enum SIDFXState static struct SIDFXChannel { SIDFX * com; - byte delay, cnt; - SIDFXState state; + byte delay, cnt, priority; + volatile SIDFXState state; unsigned freq, pwm; } channels[3]; @@ -25,21 +25,28 @@ void sidfx_init(void) { channels[i].com = nullptr; channels[i].state = SIDFX_IDLE; + channels[i].priority = 0; } } void sidfx_play(byte chn, SIDFX * fx, byte cnt) { - if (!channels[chn].com || channels[chn].com->priority <= fx->priority) - { - if (channels[chn].state == SIDFX_IDLE) - channels[chn].state = SIDFX_READY; - else - channels[chn].state = SIDFX_RESET_0; + SIDFXState ns = channels[chn].state; - channels[chn].com = fx; - channels[chn].cnt = cnt - 1; - } + if (ns == SIDFX_IDLE) + ns = SIDFX_READY; + else if (channels[chn].priority <= fx->priority) + ns = SIDFX_RESET_0; + else + return; + + channels[chn].state = SIDFX_IDLE; + + channels[chn].com = fx; + channels[chn].cnt = cnt - 1; + channels[chn].priority = fx->priority; + + channels[chn].state = ns; } void sidfx_stop(byte chn) diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index d638cef..d34cdcd 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -5521,6 +5521,13 @@ void InterCodeBasicBlock::UpdateLocalIntegerRangeSets(void) msize[ins->mSrc[0].mTemp] = int64max(msize[ins->mSrc[0].mTemp], ins->mSrc[0].mIntConst + InterTypeSize[ins->mDst.mType]); else if (ins->mCode == IC_STORE && ins->mSrc[1].mMemory == IM_INDIRECT && ins->mSrc[1].mTemp >= 0) msize[ins->mSrc[1].mTemp] = int64max(msize[ins->mSrc[1].mTemp], ins->mSrc[1].mIntConst + InterTypeSize[ins->mSrc[0].mType]); + else if (ins->mCode == IC_COPY) + { + if (ins->mSrc[0].mMemory == IM_INDIRECT && ins->mSrc[0].mTemp >= 0) + msize[ins->mSrc[0].mTemp] = ins->mConst.mOperandSize; + if (ins->mSrc[1].mMemory == IM_INDIRECT && ins->mSrc[1].mTemp >= 0) + msize[ins->mSrc[1].mTemp] = ins->mConst.mOperandSize; + } else if (ins->mCode == IC_LEA && ins->mSrc[1].mMemory != IM_INDIRECT && ins->mSrc[0].mTemp >= 0 && msize[ins->mDst.mTemp] > 0) { int asize = 0; diff --git a/oscar64/Linker.cpp b/oscar64/Linker.cpp index 914a50c..1d6c5dd 100644 --- a/oscar64/Linker.cpp +++ b/oscar64/Linker.cpp @@ -438,7 +438,7 @@ void Linker::Link(void) } } } - else + else if (obj->mSection->mType == LST_DATA) { memcpy(mMemory + obj->mAddress, obj->mData, obj->mSize); } diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index c5b53bb..b377670 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -11597,6 +11597,43 @@ bool NativeCodeBasicBlock::ExpandADCToBranch(NativeCodeProcedure* proc) break; } #endif +#if 1 + if (i + 4 < mIns.Size() && + mIns[i + 0].ChangesAccuAndFlag() && + mIns[i + 1].mType == ASMIT_CMP && mIns[i + 1].mMode == ASMIM_IMMEDIATE && mIns[i + 1].mAddress == 0x01 && + mIns[i + 2].mType == ASMIT_LDA && mIns[i + 2].mMode == ASMIM_IMMEDIATE && mIns[i + 2].mAddress == 0x00 && + mIns[i + 3].mType == ASMIT_ADC && mIns[i + 3].mMode == ASMIM_IMMEDIATE && mIns[i + 3].mAddress == 0xff && + mIns[i + 4].mType == ASMIT_AND && mIns[i + 4].mMode == ASMIM_IMMEDIATE) + { + char veq = mIns[i + 4].mAddress, vne = 0; + + changed = true; + + NativeCodeBasicBlock* eblock = proc->AllocateBlock(); + NativeCodeBasicBlock* neblock = proc->AllocateBlock(); + NativeCodeBasicBlock* rblock = proc->AllocateBlock(); + + rblock->mTrueJump = mTrueJump; + rblock->mFalseJump = mFalseJump; + rblock->mBranch = mBranch; + + for (int j = i + 5; j < mIns.Size(); j++) + rblock->mIns.Push(mIns[j]); + mIns.SetSize(i + 1); + + mTrueJump = neblock; + mFalseJump = eblock; + mBranch = ASMIT_BNE; + + if (veq != 0) + eblock->mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE, veq)); + neblock->mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE, vne)); + + eblock->Close(rblock, nullptr, ASMIT_JMP); + neblock->Close(rblock, nullptr, ASMIT_JMP); + break; + } +#endif #if 1 if (i + 12 < mIns.Size()) { @@ -12791,6 +12828,51 @@ bool NativeCodeBasicBlock::JoinTailCodeSequences(NativeCodeProcedure* proc, bool } } #endif +#if 1 + if (mIns.Size() >= 1 && mIns[0].mType == ASMIT_TAX && !(mIns[0].mLive & (LIVE_CPU_REG_A | LIVE_CPU_REG_Z))) + { + int i = 0; + while (i < mEntryBlocks.Size() && mEntryBlocks[i]->mIns.Size() > 0 && mEntryBlocks[i]->mIns.Last().mType == ASMIT_LDA && HasAsmInstructionMode(ASMIT_LDX, mEntryBlocks[i]->mIns.Last().mMode) && !mEntryBlocks[i]->mFalseJump) + i++; + if (i == mEntryBlocks.Size()) + { + for (int i = 0; i < mEntryBlocks.Size(); i++) + { + NativeCodeBasicBlock* b = mEntryBlocks[i]; + int sz = b->mIns.Size(); + b->mIns[sz - 1].mType = ASMIT_LDX; + b->mIns[sz - 1].mLive |= LIVE_CPU_REG_X; + changed = true; + } + + mIns[0].mType = ASMIT_NOP; mIns[0].mMode = ASMIM_IMPLIED; + } + } +#endif +#if 1 + if (mIns.Size() >= 1 && mIns[0].mMode == ASMIM_ABSOLUTE_X && !(mIns[0].mLive & (LIVE_CPU_REG_X | LIVE_CPU_REG_Z))) + { + int i = 0; + while (i < mEntryBlocks.Size() && mEntryBlocks[i]->mIns.Size() > 0 && mEntryBlocks[i]->mIns.Last().mType == ASMIT_LDX && mEntryBlocks[i]->mIns.Last().mMode == ASMIM_IMMEDIATE && !mEntryBlocks[i]->mFalseJump) + i++; + if (i == mEntryBlocks.Size()) + { + for (int i = 0; i < mEntryBlocks.Size(); i++) + { + NativeCodeBasicBlock* b = mEntryBlocks[i]; + int sz = b->mIns.Size(); + int index = b->mIns[sz - 1].mAddress; + b->mIns[sz - 1] = mIns[0]; + b->mIns[sz - 1].mMode = ASMIM_ABSOLUTE; + b->mIns[sz - 1].mAddress += index; + changed = true; + } + + mIns[0].mType = ASMIT_NOP; mIns[0].mMode = ASMIM_IMPLIED; + } + } +#endif + #if 1 if (mIns.Size() >= 1 && mIns.Last().mType == ASMIT_STA && mIns.Last().mMode == ASMIM_ZERO_PAGE && mTrueJump && mFalseJump && mTrueJump->mEntryRequiredRegs.Size() && mFalseJump->mEntryRequiredRegs.Size()) { @@ -19025,28 +19107,31 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass for (int i = 1; i < mIns.Size(); i++) { - if (mIns[i].mType == ASMIT_STX && (mIns[i].mMode == ASMIM_ZERO_PAGE || mIns[i].mMode == ASMIM_ABSOLUTE)) + if (!(mIns[i].mFlags & NCIF_VOLATILE)) { - if (MoveStoreXUp(i)) - changed = true; - } - else if (mIns[i].mType == ASMIT_LDX && mIns[i].mMode == ASMIM_ZERO_PAGE && !(mIns[i].mLive & LIVE_MEM)) - { - if (MoveLoadXUp(i)) - changed = true; - } - else if (mIns[i].mType == ASMIT_STY && (mIns[i].mMode == ASMIM_ZERO_PAGE || mIns[i].mMode == ASMIM_ABSOLUTE)) - { - if (i > 1 || mIns[0].mType != ASMIT_STX) + if (mIns[i].mType == ASMIT_STX && (mIns[i].mMode == ASMIM_ZERO_PAGE || mIns[i].mMode == ASMIM_ABSOLUTE)) { - if (MoveStoreYUp(i)) + if (MoveStoreXUp(i)) + changed = true; + } + else if (mIns[i].mType == ASMIT_LDX && mIns[i].mMode == ASMIM_ZERO_PAGE && !(mIns[i].mLive & LIVE_MEM)) + { + if (MoveLoadXUp(i)) + changed = true; + } + else if (mIns[i].mType == ASMIT_STY && (mIns[i].mMode == ASMIM_ZERO_PAGE || mIns[i].mMode == ASMIM_ABSOLUTE)) + { + if (i > 1 || mIns[0].mType != ASMIT_STX) + { + if (MoveStoreYUp(i)) + changed = true; + } + } + else if (mIns[i].mType == ASMIT_LDY && mIns[i].mMode == ASMIM_ZERO_PAGE && !(mIns[i].mLive & LIVE_MEM)) + { + if (MoveLoadYUp(i)) changed = true; } - } - else if (mIns[i].mType == ASMIT_LDY && mIns[i].mMode == ASMIM_ZERO_PAGE && !(mIns[i].mLive & LIVE_MEM)) - { - if (MoveLoadYUp(i)) - changed = true; } } CheckLive(); @@ -19568,6 +19653,11 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass mIns[i].mType = ASMIT_NOP; mIns[i].mMode = ASMIM_IMPLIED;; progress = true; } + else if (mIns[i].mType == ASMIT_EOR && mIns[i].mMode == ASMIM_IMMEDIATE && mIns[i].mAddress == 0x00 && (mIns[i].mLive & LIVE_CPU_REG_Z) == 0) + { + mIns[i].mType = ASMIT_NOP; mIns[i].mMode = ASMIM_IMPLIED;; + progress = true; + } else if (mIns[i].mType == ASMIT_ROR && mIns[i].mMode == ASMIM_IMPLIED && (mIns[i].mLive & (LIVE_CPU_REG_A | LIVE_CPU_REG_Z)) == 0) { mIns[i].mType = ASMIT_LSR; @@ -20760,6 +20850,15 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass mIns[i + 2].mType = ASMIT_NOP; mIns[i + 2].mMode = ASMIM_IMPLIED; progress = true; } + else if ( + mIns[i + 0].mType == ASMIT_ADC && mIns[i + 0].mMode == ASMIM_IMMEDIATE && mIns[i + 0].mAddress == 0 && + mIns[i + 1].mType == ASMIT_CLC && + mIns[i + 2].mType == ASMIT_ADC) + { + mIns[i + 0].mType = ASMIT_NOP; mIns[i + 0].mMode = ASMIM_IMPLIED; + mIns[i + 1].mType = ASMIT_NOP; mIns[i + 1].mMode = ASMIM_IMPLIED; + progress = true; + } else if ( mIns[i + 0].mType == ASMIT_STA && !(mIns[i + 0].mFlags & NCIF_VOLATILE) && mIns[i + 2].mType == ASMIT_STA && mIns[i + 0].SameEffectiveAddress(mIns[i + 2]) && @@ -23966,7 +24065,7 @@ void NativeCodeProcedure::Optimize(void) ResetVisited(); NativeRegisterDataSet data; - if (mEntryBlock->ValueForwarding(data, step > 0, step == 6)) + if (mEntryBlock->ValueForwarding(data, step > 0, step == 7)) changed = true; } while (changed); diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index f1128ea..bd94756 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -1151,7 +1151,10 @@ Declaration* Parser::ParseDeclaration(bool variable) } if (!(ndec->mFlags & DTF_EXTERN)) + { pdec->mFlags &= ~DTF_EXTERN; + pdec->mSection = ndec->mSection; + } ndec = pdec; } diff --git a/oscar64/oscar64.cpp b/oscar64/oscar64.cpp index 68a577d..007839e 100644 --- a/oscar64/oscar64.cpp +++ b/oscar64/oscar64.cpp @@ -74,7 +74,7 @@ int main2(int argc, const char** argv) #else strcpy(strProductName, "oscar64"); - strcpy(strProductVersion, "1.7.130"); + strcpy(strProductVersion, "1.7.131"); #ifdef __APPLE__ uint32_t length = sizeof(basePath); diff --git a/oscar64/oscar64.rc b/oscar64/oscar64.rc index 0c0b986..b9c1127 100644 --- a/oscar64/oscar64.rc +++ b/oscar64/oscar64.rc @@ -25,8 +25,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,7,130,0 - PRODUCTVERSION 1,7,130,0 + FILEVERSION 1,7,131,0 + PRODUCTVERSION 1,7,131,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -43,12 +43,12 @@ BEGIN BEGIN VALUE "CompanyName", "oscar64" VALUE "FileDescription", "oscar64 compiler" - VALUE "FileVersion", "1.7.130.0" + VALUE "FileVersion", "1.7.131.0" VALUE "InternalName", "oscar64.exe" VALUE "LegalCopyright", "Copyright (C) 2021" VALUE "OriginalFilename", "oscar64.exe" VALUE "ProductName", "oscar64" - VALUE "ProductVersion", "1.7.130.0" + VALUE "ProductVersion", "1.7.131.0" END END BLOCK "VarFileInfo" diff --git a/oscar64setup/oscar64setup.vdproj b/oscar64setup/oscar64setup.vdproj index 795b381..b91f794 100644 --- a/oscar64setup/oscar64setup.vdproj +++ b/oscar64setup/oscar64setup.vdproj @@ -4127,15 +4127,15 @@ { "Name" = "8:Microsoft Visual Studio" "ProductName" = "8:oscar64" - "ProductCode" = "8:{C50454FA-D0C4-42C0-9D55-B9CC69CB68CB}" - "PackageCode" = "8:{2B506600-BA1E-41A8-AC6E-BD9D54BC5EA0}" + "ProductCode" = "8:{0C6C4C06-0820-4C2F-B1B9-1E525CEC0D53}" + "PackageCode" = "8:{CE1DC98E-EB19-476E-9D59-CA1D561B38E9}" "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.7.130" + "ProductVersion" = "8:1.7.131" "Manufacturer" = "8:oscar64" "ARPHELPTELEPHONE" = "8:" "ARPHELPLINK" = "8:"