private void StepNextInstruction(NetworkStream stream) { // Fetch bank data byte[] banks = NextNetworkHelpers.GetCurrentBanks(stream); var regs = NextNetworkHelpers.GetNextState(stream); // Grab 5 bytes from around the current PC byte bank = banks[(byte)(regs[5] >> 13)]; UInt16 offset = (UInt16)(regs[5] & 0x1FFF); byte[] data = NextNetworkHelpers.GetData(stream, bank, offset, 5); // We now want to insert a breakpoint after the current instruction //although we will of course need to handle the instructions that change the PC //like ret (the Z80.cs should have code to support this) UInt64 address = bank * 8192ul + offset; SpectrumNextMemory memInfo = new SpectrumNextMemory(); memInfo.Init(data, address); D_Z80 z80 = new D_Z80(); UInt64 olength = z80.GetLength(memInfo, address); address += olength; bank = (byte)(address / 8192); offset = (UInt16)(address & 0x1FFF); // Send command to insert a breakpoint NextNetworkHelpers.SetBreakpoint(stream, 0, bank, offset); NextNetworkHelpers.SendResume(stream); }
void DataRecieved(byte[] data, byte bank, UInt16 offset) { // Disassemble the data.... UInt64 remaining = (UInt64)data.Length; UInt64 address = bank * 8192ul + offset; SpectrumNextMemory memInfo = new SpectrumNextMemory(); memInfo.Init(data, address); D_Z80 z80 = new D_Z80(); StringBuilder s = new StringBuilder(); while (remaining > 0) { UInt64 length = z80.Disassemble(memInfo, address, out string mnemonic); if (length == 0 || length > remaining) { break; } StringBuilder b = new StringBuilder(); remaining -= length; for (UInt64 a = 0; a < length; a++) { if (memInfo.FetchByte(address + a, out byte by)) { b.Append(String.Format("{0:X2} ", by)); } else { b.Append("?? "); } } for (UInt64 a = length; a < 5; a++) { b.Append(" "); } s.AppendLine($"{String.Format("{0:X8}", address)}\t{b.ToString()}\t{mnemonic}"); address += length; } Disassembly.Text = s.ToString(); }