public void Find(string text) { char[] splitChars = new char[] { '\n', '\r' }; string[] lines = text.Split(splitChars); List <string> cleaned = new List <string>(); foreach (string line in lines) { string line2 = line.Trim(); if (line2 != "") { cleaned.Add(line2.ToUpper()); } } //MessageBox.Show(String.Join("\r\n", cleaned.ToArray())); if (cleaned.Count == 0) { return; } int i = this.SelectedIndex; i++; while ((decodedInstrs.Count - i) >= cleaned.Count) { bool success = true; for (int j = 0; j < cleaned.Count; j++) { DecodedInstr instr = decodedInstrs[i + j]; string targetStr = instr.String.ToUpper(); if (targetStr.IndexOf(cleaned[j]) < 0) { success = false; break; } } if (success) { this.SelectedIndex = i; Invalidate(); MakeSelectionVisible(); break; } else { ++i; } } }
public void Disassemble() { if (nes == null) { return; } decodedInstrs.Clear(); decodeMap.Clear(); int addr = 0x8000; while (addr <= 0xFFFF) { int count = 0x10000 - addr; StringBuilder sb = new StringBuilder(); int bytes; if (Disassembler.DisassembleOne(nes.Mem, addr, count, sb, out bytes)) { DecodedInstr instr = new DecodedInstr(); instr.Address = addr; instr.Bytes = new byte[bytes]; for (int i = 0; i < bytes; ++i) { instr.Bytes[i] = nes.Mem.Read(addr + i); } instr.String = sb.ToString(); decodedInstrs.Add(instr); decodeMap[(ushort)addr] = decodedInstrs.Count - 1; addr += bytes; } else { byte value = nes.Mem.Read(addr); Disassembler.DB(sb, addr, value); DecodedInstr instr = new DecodedInstr(); instr.Address = addr; instr.Bytes = new byte[1]; instr.Bytes[0] = value; instr.String = sb.ToString(); decodedInstrs.Add(instr); decodeMap[(ushort)addr] = decodedInstrs.Count - 1; addr += 1; } } Console.WriteLine("Decoded {0} instrs for disassembler", decodedInstrs.Count); }
public void Disassemble() { if (nes == null) return; decodedInstrs.Clear(); decodeMap.Clear(); int addr = 0x8000; while (addr <= 0xFFFF) { int count = 0x10000 - addr; StringBuilder sb = new StringBuilder(); int bytes; if (Disassembler.DisassembleOne(nes.Mem, addr, count, sb, out bytes)) { DecodedInstr instr = new DecodedInstr(); instr.Address = addr; instr.Bytes = new byte[bytes]; for (int i = 0; i < bytes; ++i) instr.Bytes[i] = nes.Mem.Read(addr + i); instr.String = sb.ToString(); decodedInstrs.Add(instr); decodeMap[(ushort)addr] = decodedInstrs.Count - 1; addr += bytes; } else { byte value = nes.Mem.Read(addr); Disassembler.DB(sb, addr, value); DecodedInstr instr = new DecodedInstr(); instr.Address = addr; instr.Bytes = new byte[1]; instr.Bytes[0] = value; instr.String = sb.ToString(); decodedInstrs.Add(instr); decodeMap[(ushort)addr] = decodedInstrs.Count - 1; addr += 1; } } Console.WriteLine("Decoded {0} instrs for disassembler", decodedInstrs.Count); }
protected override void OnPaint(PaintEventArgs pe) { base.OnPaint(pe); if (nes == null) { return; } Graphics g = pe.Graphics; g.Clear(Color.White); Size clientSize = this.ClientSize; //Console.WriteLine(clientRect.Height); // TODO: Start depending on where scrollbound is? I dunno. int y = -Scroll; int lineHeight = GetLineHeight(g); for (int i = StartAddress; i < decodedInstrs.Count; ++i) { if (y < -lineHeight) { y += lineHeight; continue; } DecodedInstr inst = decodedInstrs[i]; bool isBP = nes.Cpu.Breakpoints.GetBreakpoint((ushort)inst.Address) != null; bool isPC = nes.Cpu.PC == inst.Address; bool isSelected = (i == SelectedIndex); Color bg = Color.White; Color fg = Color.Black; if (isPC) { bg = Color.FromArgb(0xFF, 0xEE, 0x00); } else if (isBP) { bg = Color.DarkRed; fg = Color.White; } if (bg != Color.White) { g.FillRectangle(new SolidBrush(bg), new Rectangle(0, y, clientSize.Width, lineHeight)); } g.DrawString(inst.String, fnt, new SolidBrush(fg), 20, y); Pen p = new Pen(Color.Black); p.DashStyle = DashStyle.Dot; if (isSelected) { g.DrawRectangle(p, new Rectangle(0, y, clientSize.Width - 1, lineHeight)); } if (isBP || isPC) { if (bpImage != null && arrowImage != null) { int bpX = (int)Math.Round((20 - bpImage.Width) / 2.0); int bpY = (int)Math.Round(y + (lineHeight - bpImage.Height) / 2.0); RectangleF destRect = new RectangleF(bpX, bpY, bpImage.Width, bpImage.Height); if (isBP) { g.DrawImage(bpImage, destRect); } if (isPC) { g.DrawImage(arrowImage, destRect); } } } y += lineHeight; if (y > clientSize.Height) { break; } } }