diff --git a/.gitignore b/.gitignore index ec8f081..dfd6d07 100644 --- a/.gitignore +++ b/.gitignore @@ -353,3 +353,4 @@ make/oscar64 *.mapd *.idb oscar64/Releasex64/oscar64.vcxproj.FileListAbsolute.txt +/oscar64/Debugx64 diff --git a/oscar64/DiskImage.cpp b/oscar64/DiskImage.cpp index 0bbe7f4..d8d4b4c 100644 --- a/oscar64/DiskImage.cpp +++ b/oscar64/DiskImage.cpp @@ -31,6 +31,8 @@ static char A2P(char ch) DiskImage::DiskImage(const char* fname) { + mInterleave = 10; + for (int i = 0; i < 41; i++) for (int j = 0; j < 21; j++) memset(mSectors[i][j], 0, 256); @@ -104,7 +106,7 @@ int DiskImage::AllocBAMSector(int track, int sector) if (dp[0] > 0) { - sector += 4; + sector += mInterleave; if (sector >= SectorsPerTrack[track]) sector -= SectorsPerTrack[track]; @@ -228,8 +230,10 @@ void DiskImage::CloseFile(void) } -bool DiskImage::WriteFile(const char* fname, bool compressed) +bool DiskImage::WriteFile(const char* fname, bool compressed, int interleave) { + mInterleave = interleave; + FILE* file; fopen_s(&file, fname, "rb"); if (file) diff --git a/oscar64/DiskImage.h b/oscar64/DiskImage.h index 6541630..19ed9d0 100644 --- a/oscar64/DiskImage.h +++ b/oscar64/DiskImage.h @@ -14,7 +14,7 @@ public: void CloseFile(void); int WriteBytes(const uint8* data, ptrdiff_t size); - bool WriteFile(const char* fname, bool compressed); + bool WriteFile(const char* fname, bool compressed, int interleave); protected: uint8 mSectors[41][21][256]; @@ -24,6 +24,6 @@ protected: int AllocBAMTrack(int track); uint8 * mDirEntry; - int mTrack, mSector, mBytes; + int mTrack, mSector, mBytes, mInterleave; }; diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index 65e669c..51ec116 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -21752,6 +21752,8 @@ bool NativeCodeBasicBlock::PropagateSinglePath(void) live |= LIVE_CPU_REG_X; if (mExitRequiredRegs[CPU_REG_Y]) live |= LIVE_CPU_REG_Y; + if (mExitRequiredRegs[CPU_REG_C]) + live |= LIVE_CPU_REG_C; int i = 0; while (i < mIns.Size()) @@ -31250,7 +31252,7 @@ bool NativeCodeBasicBlock::MoveStoreXUp(int at) if (mIns[at - 1].mMode == ASMIM_ABSOLUTE_X && inc) { - if (mIns[at - 1].mLinkerObject && mIns[at - 1].mLinkerObject->mSize > 255) + if (!mIns[at - 1].mLinkerObject || mIns[at - 1].mLinkerObject->mSize > 255) return done; } @@ -34888,16 +34890,24 @@ bool NativeCodeBasicBlock::OptimizeSimpleLoopInvariant(NativeCodeProcedure* proc else t = ASMIT_INX; - mIns[i].mType = ASMIT_NOP; - mIns[i].mMode = ASMIM_IMPLIED; - - if (needRecheck) + if (i < ei) { - mIns[ei].mLive |= LIVE_CPU_REG_A; - mIns.Insert(ei + 1, NativeCodeInstruction(mIns[ei].mIns, ASMIT_ORA, ASMIM_IMMEDIATE, 0)); - } + mIns[i].mType = ASMIT_NOP; + mIns[i].mMode = ASMIM_IMPLIED; - mIns.Insert(ei + 1, NativeCodeInstruction(mIns[i].mIns, t)); + if (needRecheck) + { + mIns[ei].mLive |= LIVE_CPU_REG_A; + mIns.Insert(ei + 1, NativeCodeInstruction(mIns[ei].mIns, ASMIT_ORA, ASMIM_IMMEDIATE, 0)); + } + + mIns.Insert(ei + 1, NativeCodeInstruction(mIns[i].mIns, t)); + } + else + { + mIns[i].mType = t; + mIns[i].mMode = ASMIM_IMPLIED; + } for (int i = 0; i < mIns.Size(); i++) mIns[i].mLive |= LIVE_CPU_REG_X; @@ -42402,10 +42412,10 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass progress = true; } else if ( - mIns[i + 0].mType == ASMIT_STA && + mIns[i + 0].mType == ASMIT_STA && mIns[i + 1].IsShiftOrInc() && - mIns[i + 2].mType == ASMIT_LDA && mIns[i + 2].SameEffectiveAddress(mIns[i + 0]) && - !mIns[i + 2].SameEffectiveAddress(mIns[i + 1]) && + mIns[i + 2].mType == ASMIT_LDA && mIns[i + 2].SameEffectiveAddress(mIns[i + 0]) && + !mIns[i + 2].SameEffectiveAddress(mIns[i + 1]) && !(mIns[i + 2].mMode == ASMIM_INDIRECT_Y && mIns[i + 1].mMode == ASMIM_ZERO_PAGE && (mIns[i + 1].mAddress == mIns[i + 2].mAddress || mIns[i + 1].mAddress == mIns[i + 2].mAddress + 1)) && !(mIns[i + 2].mLive & LIVE_CPU_REG_Z)) { @@ -42509,7 +42519,7 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass } else if ( mIns[i + 0].ChangesAccuAndFlag() && (mIns[i + 0].mMode == ASMIM_IMMEDIATE || mIns[i + 0].mMode == ASMIM_ZERO_PAGE) && - mIns[i + 1].mType == ASMIT_LDY && + mIns[i + 1].mType == ASMIT_LDY && mIns[i + 2].mType == ASMIT_ORA && mIns[i + 2].mMode == ASMIM_IMMEDIATE && mIns[i + 2].mAddress == 0) { mIns[i + 2] = mIns[i + 0]; @@ -43236,7 +43246,26 @@ 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 + 2].mType == ASMIT_TXA && !(mIns[i + 2].mLive & LIVE_CPU_REG_A) && + (mIns[i + 0].mType == ASMIT_INX || mIns[i + 0].mType == ASMIT_DEX) && + !mIns[i + 1].ChangesXReg() && !mIns[i + 1].ChangesZFlag()) + { + mIns[i + 0].mLive |= LIVE_CPU_REG_Z; + mIns[i + 1].mLive |= LIVE_CPU_REG_Z; + mIns[i + 2].mType = ASMIT_NOP; mIns[i + 2].mMode = ASMIM_IMPLIED; + progress = true; + } + else if ( + mIns[i + 2].mType == ASMIT_TYA && !(mIns[i + 2].mLive & LIVE_CPU_REG_A) && + (mIns[i + 0].mType == ASMIT_INY || mIns[i + 0].mType == ASMIT_DEY) && + !mIns[i + 1].ChangesYReg() && !mIns[i + 1].ChangesZFlag()) + { + mIns[i + 0].mLive |= LIVE_CPU_REG_Z; + mIns[i + 1].mLive |= LIVE_CPU_REG_Z; + mIns[i + 2].mType = ASMIT_NOP; mIns[i + 2].mMode = ASMIM_IMPLIED; + progress = true; + } else if ( mIns[i + 0].mType == ASMIT_STA && mIns[i + 0].mMode == ASMIM_ZERO_PAGE && mIns[i + 1].mType == ASMIT_LDA && mIns[i + 1].mMode == ASMIM_ZERO_PAGE && @@ -44717,6 +44746,21 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass progress = true; } #endif +#if 1 + else if ( + mIns[i + 0].mType == ASMIT_LDX && + mIns[i + 1].mType == ASMIT_DEX && + mIns[i + 2].mType == ASMIT_STX && mIns[i + 2].SameEffectiveAddress(mIns[i + 0]) && HasAsmInstructionMode(ASMIT_DEC, mIns[i + 0].mMode) && + mIns[i + 3].mType == ASMIT_TXA && !(mIns[i + 3].mLive & LIVE_CPU_REG_X)) + { + mIns[i + 0].mType = ASMIT_DEC; + mIns[i + 1].mType = ASMIT_NOP; mIns[i + 1].mMode = ASMIM_IMPLIED; + mIns[i + 2].mType = ASMIT_LDA; mIns[i + 2].mLive = mIns[i + 3].mLive; + mIns[i + 3].mType = ASMIT_NOP; mIns[i + 3].mMode = ASMIM_IMPLIED; + + progress = true; + } +#endif #if 1 else if ( mIns[i + 0].mType == ASMIT_LDA && mIns[i + 0].mMode == ASMIM_IMMEDIATE && @@ -48249,7 +48293,7 @@ void NativeCodeProcedure::Compile(InterCodeProcedure* proc) mInterProc = proc; mInterProc->mLinkerObject->mNativeProc = this; - CheckFunc = !strcmp(mInterProc->mIdent->mString, "longor"); + CheckFunc = !strcmp(mInterProc->mIdent->mString, "read_decompress"); int nblocks = proc->mBlocks.Size(); tblocks = new NativeCodeBasicBlock * [nblocks]; diff --git a/oscar64/oscar64.cpp b/oscar64/oscar64.cpp index 5e2f9d4..2f147c0 100644 --- a/oscar64/oscar64.cpp +++ b/oscar64/oscar64.cpp @@ -67,6 +67,7 @@ int main2(int argc, const char** argv) { char basePath[200], crtPath[200], includePath[200], targetPath[200], diskPath[200]; char strProductName[100], strProductVersion[200]; + int dataFileInterleave = 10; #ifdef _WIN32 GetProductAndVersion(strProductName, strProductVersion); @@ -152,6 +153,10 @@ int main2(int argc, const char** argv) dataFiles.Push(arg + 4); dataFileCompressed.Push(true); } + else if (arg[1] == 'f' && arg[2] == 'i' && arg[3] == '=') + { + dataFileInterleave = atoi(arg + 4); + } else if (arg[1] == 'o' && arg[2] == '=') { strcpy_s(targetPath, arg + 3); @@ -512,7 +517,7 @@ int main2(int argc, const char** argv) { for (int i = 0; i < dataFiles.Size(); i++) { - if (!d64->WriteFile(dataFiles[i], dataFileCompressed[i])) + if (!d64->WriteFile(dataFiles[i], dataFileCompressed[i], dataFileInterleave)) { printf("Could not embed disk file %s\n", dataFiles[i]); return 20;