/// ------------------------------------------------------------------------------------------------- /// <summary> Gets a label. </summary> /// /// <remarks> 07/09/2018. </remarks> /// /// <param name="addr"> The address. </param> /// /// <returns> The label. </returns> /// ------------------------------------------------------------------------------------------------- public static Label GetLabel(ref int[] bankmap, int addr) { int bank = NextAddress.GetBankFromAddress(ref bankmap, addr); int longaddr = NextAddress.MakeLongAddress(bank, addr); foreach (Label l in labels) { if (longaddr == l.nextAddress.GetLongAddress()) { return(l); } } return(null); }
// ------------------------------------------------------------------------------------------------- // Patch dism memory with breakpoints // // \param [in,out] mem // The memory. // \param addr // The address. // \param length // The length. // ------------------------------------------------------------------------------------------------- private void PatchDismMemoryWithBreakpoints(ref byte[] mem, int addr, int length) { for (int i = 0; i < length; i++) { //looking for breakpoint instruction if (mem[i] == 0xc7) { int a = addr + i; int bank = NextAddress.GetBankFromAddress(ref MainForm.banks, a); int brk = Breakpoint.FindFreeBreakpointAddr(NextAddress.MakeLongAddress(bank, a)); if (brk >= 0) { //found a breakpoint so lets replace the memory bytes with the origional value. mem[i] = Breakpoint.breakpointData[brk].replaceopcode; } } } }
/// ------------------------------------------------------------------------------------------------- /// <summary> Gets function with offset. </summary> /// /// <remarks> 18/09/2018. </remarks> /// /// <param name="addr"> The address. </param> /// <param name="lab"> [out] The lab. </param> /// <param name="offset"> [out] The offset. </param> /// /// <returns> True if it succeeds, false if it fails. </returns> /// ------------------------------------------------------------------------------------------------- public static bool GetFunctionWithOffset(ref int[] bankmap, int addr, out Label lab, out int offset) { int bank = NextAddress.GetBankFromAddress(ref bankmap, addr); int longaddr = NextAddress.MakeLongAddress(bank, addr); lab = null; offset = 0; int best = int.MaxValue; int bestindex = -1; int index = 0; foreach (Label l in labels) { if (longaddr >= l.nextAddress.GetLongAddress() && l.function) { int off = longaddr - l.nextAddress.GetLongAddress(); if (off < best) { best = off; bestindex = index; } } index++; } if (bestindex < 0) { return(false); } lab = labels[bestindex]; offset = best; return(true); }