From 2d2c696aa45c2d571396634e6e82c031b1d94d88 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Thu, 10 Oct 2024 16:12:35 +0200 Subject: [PATCH] Add sprite pad tile import --- README.md | 6 ++++++ oscar64/NativeCodeGenerator.cpp | 36 ++++++++++++++++++++++++++++----- oscar64/Preprocessor.cpp | 21 +++++++++++++++++++ oscar64/Preprocessor.h | 3 ++- oscar64/Scanner.cpp | 2 ++ 5 files changed, 62 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 284356f..4d8cd9b 100644 --- a/README.md +++ b/README.md @@ -395,6 +395,12 @@ Imports the attribute data Imports the sprite data and compresses it using lzo compression + const char SpriteTiles[] = { + #embed spd_tiles "sprites.spd" + }; + +Imports the sprite tile index table in byte form + ### Console input and output diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index 6f14239..1c039b7 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -3899,7 +3899,7 @@ bool NativeCodeInstruction::ValueForwarding(NativeRegisterDataSet& data, AsmInsT break; case ASMIT_LDX: - if (data.mRegs[CPU_REG_X].mMode == NRDM_ZERO_PAGE && data.mRegs[CPU_REG_X].mValue == mAddress) + if (data.mRegs[CPU_REG_X].mMode == NRDM_ZERO_PAGE && data.mRegs[CPU_REG_X].mValue == mAddress && !(mLive & LIVE_CPU_REG_Z)) { mType = ASMIT_NOP; mMode = ASMIM_IMPLIED; @@ -3961,7 +3961,7 @@ bool NativeCodeInstruction::ValueForwarding(NativeRegisterDataSet& data, AsmInsT break; case ASMIT_LDY: - if (data.mRegs[CPU_REG_Y].mMode == NRDM_ZERO_PAGE && data.mRegs[CPU_REG_Y].mValue == mAddress) + if (data.mRegs[CPU_REG_Y].mMode == NRDM_ZERO_PAGE && data.mRegs[CPU_REG_Y].mValue == mAddress && !(mLive & LIVE_CPU_REG_Z)) { mType = ASMIT_NOP; mMode = ASMIM_IMPLIED; @@ -34958,7 +34958,20 @@ bool NativeCodeBasicBlock::IndexXYValueForwarding(int xreg, int xoffset, int xva { if (mIns[i].mAddress == xreg) { - if (xoffset <= 3) + if (xoffset == 0) + { + if (!(mIns[i].mLive & LIVE_CPU_REG_Z)) + { + mIns[i].mType = ASMIT_NOP; mIns[i].mMode = ASMIM_IMPLIED; + changed = true; + } + else if (!(mIns[i].mLive & LIVE_CPU_REG_A)) + { + mIns[i].mType = ASMIT_TXA; mIns[i].mMode = ASMIM_IMPLIED; + changed = true; + } + } + else if (xoffset <= 3) { mIns[i].mType = ASMIT_NOP; mIns[i].mMode = ASMIM_IMPLIED; for (int j = 0; j < xoffset; j++) @@ -34999,7 +35012,20 @@ bool NativeCodeBasicBlock::IndexXYValueForwarding(int xreg, int xoffset, int xva { if (mIns[i].mAddress == yreg) { - if (yoffset <= 3) + if (yoffset == 0) + { + if (!(mIns[i].mLive & LIVE_CPU_REG_Z)) + { + mIns[i].mType = ASMIT_NOP; mIns[i].mMode = ASMIM_IMPLIED; + changed = true; + } + else if (!(mIns[i].mLive & LIVE_CPU_REG_A)) + { + mIns[i].mType = ASMIT_TYA; mIns[i].mMode = ASMIM_IMPLIED; + changed = true; + } + } + else if (yoffset <= 3) { mIns[i].mType = ASMIT_NOP; mIns[i].mMode = ASMIM_IMPLIED; for (int j = 0; j < yoffset; j++) @@ -51463,7 +51489,7 @@ void NativeCodeProcedure::Compile(InterCodeProcedure* proc) mInterProc = proc; mInterProc->mLinkerObject->mNativeProc = this; - CheckFunc = !strcmp(mInterProc->mIdent->mString, "main"); + CheckFunc = !strcmp(mInterProc->mIdent->mString, "fighter_status"); int nblocks = proc->mBlocks.Size(); tblocks = new NativeCodeBasicBlock * [nblocks]; diff --git a/oscar64/Preprocessor.cpp b/oscar64/Preprocessor.cpp index c849559..ec1b83b 100644 --- a/oscar64/Preprocessor.cpp +++ b/oscar64/Preprocessor.cpp @@ -420,6 +420,7 @@ void SourceFile::ReadSpritePad(Errors* errors, const Location& location, SourceF if (spdHeader.mID[0] == 'S' && spdHeader.mID[1] == 'P' && spdHeader.mID[2] == 'D') { int numSprites = 0; + int numTiles = 0, tileSize = 0; switch (spdHeader.mVersion[0]) { @@ -428,6 +429,8 @@ void SourceFile::ReadSpritePad(Errors* errors, const Location& location, SourceF SPDHeader5 spdHeader5; fread(&spdHeader5, sizeof(SPDHeader5), 1, mFile); numSprites = spdHeader5.mNumSprites; + numTiles = spdHeader5.mNumTiles; + tileSize = spdHeader5.mTileHeight * spdHeader5.mTileWidth; break; } case 3: @@ -435,6 +438,8 @@ void SourceFile::ReadSpritePad(Errors* errors, const Location& location, SourceF SPDHeader3 spdHeader3; fread(&spdHeader3, sizeof(SPDHeader3), 1, mFile); numSprites = spdHeader3.mNumSprites; + numTiles = spdHeader3.mNumTiles; + tileSize = spdHeader3.mTileHeight * spdHeader3.mTileWidth; break; } case 1: @@ -454,6 +459,21 @@ void SourceFile::ReadSpritePad(Errors* errors, const Location& location, SourceF mLimit = 64 * numSprites; return; } + else if (decoder == SFD_SPD_TILES) + { + fseek(mFile, 64 * numSprites, SEEK_CUR); + mMemSize = numTiles * tileSize; + mLimit = mMemSize; + mMemPos = 0; + mMemData = new uint8[mMemSize]; + for (int i = 0; i < mMemSize; i++) + { + int16 d; + fread(&d, 2, 1, mFile); + mMemData[i] = uint8(d); + } + return; + } } else errors->Error(location, EERR_UNIMPLEMENTED, "SPD file format not recognized"); @@ -725,6 +745,7 @@ void SourceFile::Limit(Errors* errors, const Location& location, SourceFileDecod break; case SFD_SPD_SPRITES: + case SFD_SPD_TILES: ReadSpritePad(errors, location, decoder); break; diff --git a/oscar64/Preprocessor.h b/oscar64/Preprocessor.h index 57966fb..b571964 100644 --- a/oscar64/Preprocessor.h +++ b/oscar64/Preprocessor.h @@ -34,7 +34,8 @@ enum SourceFileDecoder SFD_CTM_TILES_16, SFD_CTM_MAP_8, SFD_CTM_MAP_16, - SFD_SPD_SPRITES + SFD_SPD_SPRITES, + SFD_SPD_TILES, }; class SourceFile diff --git a/oscar64/Scanner.cpp b/oscar64/Scanner.cpp index 1418a87..4621b4d 100644 --- a/oscar64/Scanner.cpp +++ b/oscar64/Scanner.cpp @@ -986,6 +986,8 @@ void Scanner::NextPreToken(void) decoder = SFD_CTM_MAP_16; else if (!strcmp(mTokenIdent->mString, "spd_sprites")) decoder = SFD_SPD_SPRITES; + else if (!strcmp(mTokenIdent->mString, "spd_tiles")) + decoder = SFD_SPD_TILES; else mErrors->Error(mLocation, EERR_FILE_NOT_FOUND, "Invalid embed compression mode", mTokenIdent);