// ------------------------------------------------------------------------------------------------- // Gets dissasembly source // ------------------------------------------------------------------------------------------------- public void UpdateGetDissasemblyLines() { if (instrs == null) { return; } DissasemblyLines.Clear(); int instructionOffset = 0; //Math.Max(0,disasmline - (maxlines/2) ); DissasemblyLinesPC = 0; for (int index = 0; index < instrs.Length; index++) { eZ80Disassembler.DisassembledInstruction di = instrs[index + instructionOffset]; int addr = (dissassemblyBaseAddress + di.StartPosition); //if (lineNumber >= maxlines) // break; Labels.Label l = Labels.GetLabel(ref MainForm.banks, addr); if (l != null) { if (!l.label.Contains(".")) { DissasemblyLines.Add(new linebuildData(-1, "")); DissasemblyLines.Add(new linebuildData(-1, "; **************************************************************************")); DissasemblyLines.Add(new linebuildData(-1, "; " + l.label)); DissasemblyLines.Add(new linebuildData(-1, "; **************************************************************************")); } DissasemblyLines.Add(new linebuildData(-1, l.label + ":")); } bool useComment = true; string Comment = "; "; for (int i = 0; i < di.Length; i++) { Comment = Comment + disassemblyMemory[di.StartPosition + i].ToString("X2") + " "; } /* * string addrstr = addr.ToString("X4") + " "; * for (int i = 0; i < di.Length; i++) * { * addrstr = addrstr + disassemblyMemory[di.StartPosition + 5].ToString("X2") + " "; * } */ //add address label //if (l != null) // addrstr = addrstr + l.label; //disassemblyData[index].Address = addrstr; // do value string dis = di.ToString(); Match m = addrRegex.Match(dis); if (m.Success) { int jaddr; if (int.TryParse(m.Value, NumberStyles.AllowHexSpecifier, null, out jaddr)) { l = null; int offset; if (Labels.GetLabelWithOffset(ref MainForm.banks, jaddr, out l, out offset)) { if (Program.InStepMode) { MainForm.myWatches.AddLocalWatch(l); } if (offset == 0) { dis = dis.Replace(m.Value, l.label); } else { if (offset < 16 && offset > (-16)) { dis = dis.Replace(m.Value, l.label + "+" + offset); } } } } } string line = " " + dis; if (useComment) { while (line.Length < 40) { line = line + " "; } line = line + Comment; } if (index == disasmline) { DissasemblyLinesPC = DissasemblyLines.Count; } DissasemblyLines.Add(new linebuildData(addr, line)); } }
/// ------------------------------------------------------------------------------------------------- /// <summary> Updates the given items. </summary> /// /// <remarks> 12/09/2018. </remarks> /// /// <param name="items"> The items. </param> /// ------------------------------------------------------------------------------------------------- void UIUpdate(string[] items, int pc) { //bool updated = false; for (int a = 0; a < items.Count() && a < disassemblyData.Count(); a++) { Match m = disRegex.Match(items[a]); if (m.Success) { DissasemblyDataGrid.Rows[a].DefaultCellStyle.BackColor = System.Drawing.Color.White; //group 3 is disassebly int addr = 0; Labels.Label l = null; if (int.TryParse(m.Groups[1].Value, NumberStyles.AllowHexSpecifier, null, out addr)) { l = Labels.GetLabel(addr); } if (addr == pc) { DissasemblyDataGrid.Rows[a].DefaultCellStyle.BackColor = System.Drawing.Color.LightBlue; } if (l != null) { disassemblyData[a].Address = m.Groups[1].Value + " " + m.Groups[2].Value + " " + l.label + ":"; } else { disassemblyData[a].Address = m.Groups[1].Value + " " + m.Groups[2].Value; } string dis = m.Groups[3].Value; m = addrRegex.Match(dis); if (m.Success) { if (int.TryParse(m.Value, NumberStyles.AllowHexSpecifier, null, out addr)) { l = null; int offset; if (Labels.GetLabelWithOffset(addr, out l, out offset)) { if (Program.InStepMode) { MainForm.myWatches.AddLocalWatch(l); } if (offset == 0) { dis = dis.Replace(m.Value, l.label) + " ;" + m.Value; } else { dis = dis.Replace(m.Value, l.label + "+" + offset) + " ;" + m.Value; } } } } disassemblyData[a].Value = dis; //updated = true; } } //after disasm then update watch if (Program.InStepMode) { if (MainForm.myMemoryWatch != null) { MainForm.myMemoryWatch.UpdateMemory(); } } }
/// ------------------------------------------------------------------------------------------------- /// <summary> Updates the given items. </summary> /// /// <remarks> 12/09/2018. </remarks> /// /// <param name="items"> The items. </param> /// ------------------------------------------------------------------------------------------------- void UIUpdate(int disaddr, byte[] data) { int pc = MainForm.myNewRegisters.GetRegisterValueint(Registers.Z80Register.pc); int offset = -1; int foundline = -1; do { offset++; } while ((foundline = DisasmWithOffset(ref data, disaddr, pc, offset)) < 0); disasmline = foundline; //goto next instruction SyncEmulator(); StepEmulator(); int instructionOffset = Math.Max(0, disasmline - 15); for (int index = 0; index < 30; index++) { eZ80Disassembler.DisassembledInstruction di = instrs[index + instructionOffset]; int addr = (dissassemblyBaseAddress + di.StartPosition); string addrstr = addr.ToString("X4") + " "; Labels.Label l = Labels.GetLabel(ref MainForm.banks, addr); for (int i = 0; i < di.Length; i++) { addrstr = addrstr + data[di.StartPosition + i + 5].ToString("X2") + " "; } //add address label if (l != null) { addrstr = addrstr + l.label; } disassemblyData[index].Address = addrstr; // do value string dis = di.ToString(); Match m = addrRegex.Match(dis); if (m.Success) { int jaddr; if (int.TryParse(m.Value, NumberStyles.AllowHexSpecifier, null, out jaddr)) { l = null; int voffset; if (Labels.GetLabelWithOffset(ref MainForm.banks, jaddr, out l, out voffset)) { if (Program.InStepMode) { MainForm.myWatches.AddLocalWatch(l); } if (voffset == 0) { dis = dis.Replace(m.Value, l.label) + " ;" + m.Value; } else { //dis = dis.Replace(m.Value, l.label+"+"+offset)+ " ;"+m.Value; } } } } disassemblyData[index].Value = dis; DissasemblyDataGrid.Rows[index].DefaultCellStyle.ForeColor = System.Drawing.Color.Black; // mark the next instruction to run if (addr == GetEmulatorPC()) { DissasemblyDataGrid.Rows[index].DefaultCellStyle.ForeColor = System.Drawing.Color.Red; } else { DissasemblyDataGrid.Rows[index].DefaultCellStyle.ForeColor = System.Drawing.Color.Black; } //mark the current z80 pc instruction if (addr == pc) { DissasemblyDataGrid.Rows[index].DefaultCellStyle.BackColor = System.Drawing.Color.LightBlue; } else { DissasemblyDataGrid.Rows[index].DefaultCellStyle.BackColor = System.Drawing.Color.White; } } DissasemblyDataGrid.Invalidate(); Invalidate(); UpdateGetDissasemblyLines(); MainForm.sourceCodeView.UpdateDismWindow(); /* * //bool updated = false; * for (int a=0;a<items.Count() && a<disassemblyData.Count();a++) * { * Match m = disRegex.Match(items[a]); * if (m.Success) * { * DissasemblyDataGrid.Rows[a].DefaultCellStyle.BackColor = System.Drawing.Color.White; * * //group 3 is disassebly * int addr = 0; * Labels.Label l = null; * if (int.TryParse(m.Groups[1].Value, NumberStyles.AllowHexSpecifier, null, out addr)) * { * l = Labels.GetLabel(addr); * } * * if (addr == pc) * DissasemblyDataGrid.Rows[a].DefaultCellStyle.BackColor = System.Drawing.Color.LightBlue; * * * * if (l != null) * { * disassemblyData[a].Address = m.Groups[1].Value + " "+m.Groups[2].Value+" "+l.label+":"; * } * else * { * disassemblyData[a].Address = m.Groups[1].Value + " "+m.Groups[2].Value; * } * * * * string dis = m.Groups[3].Value; * m = addrRegex.Match(dis); * * if (m.Success) * { * if (int.TryParse(m.Value, NumberStyles.AllowHexSpecifier, null, out addr)) * { * l = null; * int offset; * if (Labels.GetLabelWithOffset(addr,out l, out offset)) * { * if (Program.InStepMode) * MainForm.myWatches.AddLocalWatch(l); * * * if (offset == 0) * { * dis = dis.Replace(m.Value, l.label) + " ;"+m.Value; * } * else * { * dis = dis.Replace(m.Value, l.label+"+"+offset)+ " ;"+m.Value; * } * } * * } * * * } * disassemblyData[a].Value = dis; * * //updated = true; * } * } * * * * //after disasm then update watch * if (Program.InStepMode) * { * if (MainForm.myMemoryWatch != null) * { * MainForm.myMemoryWatch.UpdateMemory(); * } * * } * */ }