/// <summary> /// Updates pointers to the newly patched PPU loader. /// </summary> private void UpdateMiscPointers(AddressLabels labels) { ////int InitTitleGFX = 0xC603; ////Prg_WriteWord(0xC54D, InitTitleGFX); // Update jsr InitTitleGFX ////Prg_WriteWord(0xC573, 0xC608); // Update jsr InitBrinstarGFX ////Prg_WriteWord(0xC58B, 0xC60d); // Update jsr InitNorfairGFX ////Prg_WriteWord(0xC5A3, 0xC612); // Update jsr InitTourianGFX ////Prg_WriteWord(0xC5BE, 0xC617); // Update jsr InitKraidGFX ////Prg_WriteWord(0xC5CB, 0xC61C); // Update jsr InitRidleyGFX ////Prg_WriteWord(0xC5D5, InitTitleGFX); // Update jsr InitGFX6 // Todo: with support for .PATCH, this can actually be done via the ASM WriteLabel(0xC54D, labels, "InitTitleGFX"); WriteLabel(0xC573, labels, "InitBrinstarGFX"); // Update jsr InitBrinstarGFX WriteLabel(0xC58B, labels, "InitNorfairGFX"); // Update jsr InitNorfairGFX WriteLabel(0xC5A3, labels, "InitTourianGFX"); // Update jsr InitTourianGFX WriteLabel(0xC5BE, labels, "InitKraidGFX"); // Update jsr InitKraidGFX WriteLabel(0xC5CB, labels, "InitRidleyGFX"); // Update jsr InitRidleyGFX WriteLabel(0xC54D, labels, "InitTitleGFX"); ////// Update jsr InitGFX7 (called 3 times in title page bank: title, password, end of game) ////enhancedRomData[0x1135] = (byte)(InitTitleGFX & 0xFF); ////enhancedRomData[0x1136] = (byte)(InitTitleGFX >> 8); ////enhancedRomData[0x1378] = (byte)(InitTitleGFX & 0xFF); ////enhancedRomData[0x1379] = (byte)(InitTitleGFX >> 8); ////enhancedRomData[0x13B9] = (byte)(InitTitleGFX & 0xFF); ////enhancedRomData[0x13BA] = (byte)(InitTitleGFX >> 8); WriteLabel(0, 0x9125, labels, "InitTitleGFX"); WriteLabel(0, 0x9368, labels, "InitTitleGFX"); WriteLabel(0, 0x93A9, labels, "InitTitleGFX"); }
private void PreformRoomAsmPatch() { var labels = new AddressLabels(); var Asm = EnhancerResources.RoomDataHack; var assembler = new Assembler("RoomDataHack", Asm, StandardFileSystem.FileSystem) { Labels = labels }; var bin = assembler.Assemble(); var errors = assembler.GetErrors(); if (errors.Count > 0) { throw new EnhancerException("Room data hack ASM patch failed to assemble with " + errors.Count.ToString() + " errors. First error: " + errors[0].Message + " on line " + errors[0].LineNumber.ToString()); } var patches = assembler.GetPatchSegments(); for (int i = 0; i < patches.Count; i++) { var patch = patches[i]; Array.Copy(bin, patch.Start, enhancedRomData, patch.PatchOffset, patch.Length); } }
private void PerformAsmPatches() { { // First try ////// Pre-assembled code ////var ppuLoaderAsm = EnhancerResources.PPU_Loader; ////var NmiHijackAsm = EnhancerResources.NMI_Hijack; ////// Apply ASM patches ////Array.Copy(ppuLoaderAsm, 0, enhancedRomData, PpuLoader_Offset, ppuLoaderAsm.Length); ////Array.Copy(NmiHijackAsm, 0, enhancedRomData, NmiHijack_Offset, NmiHijackAsm.Length); ////enhancedRomData[ChrSwapSize_Offset] |= ChrSwapMode_4k; ////// Patch pointers to updated routines ////UpdateMiscPointers(); } { // Second try ////// ASM patches ////var ppuLoaderSource = EnhancerResources.PpuLoader_ASM; ////var assm = new Assembler("Ppu Loader", ppuLoaderSource, StandardFileSystem.FileSystem); ////var ppuLoaderAsm = assm.Assemble(); ////var nmiHijockSource = EnhancerResources.NmiHijack_ASM_unused; ////assm = new Assembler("NMI Hijack", nmiHijockSource, StandardFileSystem.FileSystem); ////var NmiHijackAsm = assm.Assemble(); ////// Patch pointers to updated routines ////UpdateMiscPointers(); } var labels = new AddressLabels(); var ppuLoaderAsm = EnhancerResources.PpuLoader_ASM; var assembler = new Assembler("PPU Loader", ppuLoaderAsm, StandardFileSystem.FileSystem); assembler.Labels = labels; var bin = assembler.Assemble(); var errors = assembler.GetErrors(); if (errors.Count > 0) { throw new EnhancerException("PPU Loader ASM patch failed to assemble with " + errors.Count.ToString() + " errors. First error: " + errors[0].Message + " on line " + errors[0].LineNumber.ToString()); } var patches = assembler.GetPatchSegments(); for (int i = 0; i < patches.Count; i++) { var patch = patches[i]; Array.Copy(bin, patch.Start, enhancedRomData, patch.PatchOffset, patch.Length); } // Patch pointers to updated routines UpdateMiscPointers(labels); FixCreditsPatternUsage(); }
private ushort?TryGetLabelValue(AddressLabels labels, string labelName) { const int fixedBank = 0x0F; var bank = (BankLabels)labels.Banks[fixedBank]; foreach (var label in bank.Labels) { // Key is address // Value contains name if (label.Value.labelName.Equals(labelName, StringComparison.Ordinal)) { return(label.Key); } } return(null); }
/// <summary>Writes a pointer to the specified address in the specified bank.</summary> private void WriteLabel(int bank, int ptrAddress, AddressLabels labels, string labelName) { const int ptrFilter = 0x3FFF; ushort?labelValue = TryGetLabelValue(labels, labelName); int bankOffset = 0x10 + 0x4000 * bank; if (labelValue == null) { throw new EnhancerException("The label \"" + labelName + "\" was not found in the applied ASM patch."); } else { ptrAddress = (ptrAddress & ptrFilter) + bankOffset; enhancedRomData[ptrAddress] = (byte)(labelValue.Value); enhancedRomData[ptrAddress + 1] = (byte)(labelValue.Value >> 8); } }
/////// <summary> /////// Updates pointers to the newly patched PPU loader. /////// </summary> ////private void UpdateMiscPointers() { // Done: comment out this unneeded method //// int InitTitleGFX = 0xC603; //// Prg_WriteWord(0xC54D, InitTitleGFX); // Update jsr InitTitleGFX //// Prg_WriteWord(0xC573, 0xC608); // Update jsr InitBrinstarGFX //// Prg_WriteWord(0xC58B, 0xC60d); // Update jsr InitNorfairGFX //// Prg_WriteWord(0xC5A3, 0xC612); // Update jsr InitTourianGFX //// Prg_WriteWord(0xC5BE, 0xC617); // Update jsr InitKraidGFX //// Prg_WriteWord(0xC5CB, 0xC61C); // Update jsr InitRidleyGFX //// Prg_WriteWord(0xC5D5, InitTitleGFX); // Update jsr InitGFX6 //// // Update jsr InitGFX7 (called 3 times in title page bank: title, password, end of game) //// enhancedRomData[0x1135] = (byte)(InitTitleGFX & 0xFF); //// enhancedRomData[0x1136] = (byte)(InitTitleGFX >> 8); //// enhancedRomData[0x1378] = (byte)(InitTitleGFX & 0xFF); //// enhancedRomData[0x1379] = (byte)(InitTitleGFX >> 8); //// enhancedRomData[0x13B9] = (byte)(InitTitleGFX & 0xFF); //// enhancedRomData[0x13BA] = (byte)(InitTitleGFX >> 8); ////} /// <summary>Writes a pointer to the specified address in the last bank.</summary> private void WriteLabel(int ptrAddress, AddressLabels labels, string labelName) { WriteLabel(0xF, ptrAddress, labels, labelName); }