From 31203bc854656ff92844364903de9abee9daea8b Mon Sep 17 00:00:00 2001 From: Ian C Date: Wed, 7 Mar 2012 22:48:11 +0000 Subject: Safe-keeping commit. Currently debugging emulation using FUSE tests. --- .../Z80Disassembler.cs | 451 ++++++++++++--------- 1 file changed, 250 insertions(+), 201 deletions(-) (limited to 'src/Noddybox.Emulation.EightBit.Z80.Disassembler') diff --git a/src/Noddybox.Emulation.EightBit.Z80.Disassembler/Z80Disassembler.cs b/src/Noddybox.Emulation.EightBit.Z80.Disassembler/Z80Disassembler.cs index cdb378d..438b962 100644 --- a/src/Noddybox.Emulation.EightBit.Z80.Disassembler/Z80Disassembler.cs +++ b/src/Noddybox.Emulation.EightBit.Z80.Disassembler/Z80Disassembler.cs @@ -16,6 +16,7 @@ // Copyright (c) 2012 Ian Cowburn // using System; +using System.Text; namespace Noddybox.Emulation.EightBit.Z80.Disassembler { @@ -45,19 +46,28 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler #endregion - #region Private. Some of these routines are to support the original C code. + #region Private routines to support the original C code. private byte Z80_Dis_FetchByte(ref ushort addr) { - return memory.Read(addr++); + byte b = memory.Read(addr++); + + if (Hex.Length > 0) + { + Hex.Append(" "); + } + + Hex.AppendFormat("{0:x2}", b); + + return b; } - private ushort FetchWord(ref ushort addr) + private ushort Z80_Dis_FetchWord(ref ushort addr) { Register16 r = new Register16(0); - r.low = memory.Read(addr++); - r.high = memory.Read(addr++); + r.low = Z80_Dis_FetchByte(ref addr); + r.high = Z80_Dis_FetchByte(ref addr); return r.reg; } @@ -65,15 +75,75 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler private string Opcode {get; set;} private string Argument {get; set;} + private StringBuilder Hex {get; set;} + private void Z80_Dis_Set(string a, string b) { Opcode = a; Argument = b; } + private string PopString(string s, int count) + { + if (s.Length <= count) + { + return String.Empty; + } + else + { + return s.Substring(count); + } + } + + private string Z80_Dis_Printf(string fmt, params object[] o) + { + StringBuilder sb = new StringBuilder(); + int arg = 0; + + while(fmt.Length > 0) + { + if (fmt[0] == '%') + { + if (fmt[1] == 'd' || fmt[1] == 's') + { + sb.Append("{"); + sb.AppendFormat("{0}", arg++); + sb.Append("}"); + fmt = PopString(fmt, 2); + } + else if (fmt.StartsWith("%.2x")) + { + sb.Append("{"); + sb.AppendFormat("{0}:x2", arg++); + sb.Append("}"); + fmt = PopString(fmt, 4); + } + else if (fmt.StartsWith("%.4x")) + { + sb.Append("{"); + sb.AppendFormat("{0}:x4", arg++); + sb.Append("}"); + fmt = PopString(fmt, 4); + } + else + { + sb.Append(fmt[0]); + fmt = PopString(fmt, 1); + } + } + else + { + sb.Append(fmt[0]); + fmt = PopString(fmt, 1); + } + } + + return String.Format(sb.ToString(), o); + } + #endregion - #region Disassembler functions. This code pretty much pasted as-is from my original C version + #region Disassembler functions. This code pretty much pasted as-is from my original C version, with support routines to help. /* ---------------------------------------- CB xx BYTE OPCODES */ @@ -178,7 +248,7 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler { sbyte r; - r=(sbyte)Z80_Dis_FetchByte(z80,pc); + r=(sbyte)Z80_Dis_FetchByte(ref pc); if (r<0) return String.Format("(ix-{0:x2})",-r); @@ -206,37 +276,28 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler { case 0: return ("b"); - break; case 1: return ("c"); - break; case 2: return ("d"); - break; case 3: return ("e"); - break; case 4: return ("ixh"); - break; case 5: return ("ixl"); - break; case 6: - return (IX_RelStr(0, pc)); - break; + return (IX_RelStr(0, ref pc)); case 7: return ("a"); - break; default: return String.Format("BUG {0}", reg); - break; } } private void DIS_DD_NOP(byte op, ref ushort pc) { - dis_opcode_z80[op](op, pc); + dis_opcode_z80[op](op, ref pc); } private void DIS_ADD_IX_BC(byte op, ref ushort pc) @@ -251,14 +312,14 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler private void DIS_LD_IX_WORD(byte op, ref ushort pc) { - Z80_Dis_Set("ld", Z80_Dis_Printf("ix,$%.4x", Z80_Dis_FetchWord(pc))); + Z80_Dis_Set("ld", Z80_Dis_Printf("ix,$%.4x", Z80_Dis_FetchWord(ref pc))); } private void DIS_LD_ADDR_IX(byte op, ref ushort pc) { ushort w; - w = Z80_Dis_FetchWord(pc); + w = Z80_Dis_FetchWord(ref pc); Z80_Dis_Set("ld", Z80_Dis_Printf("($%.4x),ix", w)); } @@ -279,7 +340,7 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler private void DIS_LD_IXH_BYTE(byte op, ref ushort pc) { - Z80_Dis_Set("ld", Z80_Dis_Printf("ixh,$%.2x", Z80_Dis_FetchByte(pc))); + Z80_Dis_Set("ld", Z80_Dis_Printf("ixh,$%.2x", Z80_Dis_FetchByte(ref pc))); } private void DIS_ADD_IX_IX(byte op, ref ushort pc) @@ -291,7 +352,7 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler { ushort w; - w = Z80_Dis_FetchWord(pc); + w = Z80_Dis_FetchWord(ref pc); Z80_Dis_Set("ld", Z80_Dis_Printf("ix,($%.4x)", w)); } @@ -312,17 +373,17 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler private void DIS_LD_IXL_BYTE(byte op, ref ushort pc) { - Z80_Dis_Set("ld", Z80_Dis_Printf("ixl,$%.2x", Z80_Dis_FetchByte(pc))); + Z80_Dis_Set("ld", Z80_Dis_Printf("ixl,$%.2x", Z80_Dis_FetchByte(ref pc))); } private void DIS_INC_IIX(byte op, ref ushort pc) { - Z80_Dis_Set("inc", Z80_Dis_Printf("%s", IX_RelStr(op, pc))); + Z80_Dis_Set("inc", Z80_Dis_Printf("%s", IX_RelStr(op, ref pc))); } private void DIS_DEC_IIX(byte op, ref ushort pc) { - Z80_Dis_Set("dec", Z80_Dis_Printf("%s", IX_RelStr(op, pc))); + Z80_Dis_Set("dec", Z80_Dis_Printf("%s", IX_RelStr(op, ref pc))); } private void DIS_LD_IIX_BYTE(byte op, ref ushort pc) @@ -330,8 +391,8 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler string rel; int b; - rel = IX_RelStr(op, pc); - b = Z80_Dis_FetchByte(pc); + rel = IX_RelStr(op, ref pc); + b = Z80_Dis_FetchByte(ref pc); Z80_Dis_Set("ld", Z80_Dis_Printf("%s,$%.2x", rel, b)); } @@ -352,62 +413,62 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler /* IX can't be used as source and destination when reading z80ory */ if (dest_r==6) - { - dest=XR8(dest_r,pc); + { + dest=XR8(dest_r, ref pc); src=z80_dis_reg8[src_r]; - } + } else if (((dest_r==4)||(dest_r==5))&&(src_r==6)) - { + { dest=z80_dis_reg8[dest_r]; - src=XR8(src_r,pc); - } + src = XR8(src_r, ref pc); + } else - { - dest=XR8(dest_r,pc); - src=XR8(src_r,pc); - } + { + dest = XR8(dest_r, ref pc); + src = XR8(src_r, ref pc); + } Z80_Dis_Set("ld",Z80_Dis_Printf("%s,%s",dest,src)); } private void DIS_XADD_R8(byte op, ref ushort pc) { - Z80_Dis_Set("add", Z80_Dis_Printf("a,%s", XR8((op % 8), pc))); + Z80_Dis_Set("add", Z80_Dis_Printf("a,%s", XR8((op % 8), ref pc))); } private void DIS_XADC_R8(byte op, ref ushort pc) { - Z80_Dis_Set("adc", Z80_Dis_Printf("a,%s", XR8((op % 8), pc))); + Z80_Dis_Set("adc", Z80_Dis_Printf("a,%s", XR8((op % 8), ref pc))); } private void DIS_XSUB_R8(byte op, ref ushort pc) { - Z80_Dis_Set("sub", Z80_Dis_Printf("a,%s", XR8((op % 8), pc))); + Z80_Dis_Set("sub", Z80_Dis_Printf("a,%s", XR8((op % 8), ref pc))); } private void DIS_XSBC_R8(byte op, ref ushort pc) { - Z80_Dis_Set("sbc", Z80_Dis_Printf("a,%s", XR8((op % 8), pc))); + Z80_Dis_Set("sbc", Z80_Dis_Printf("a,%s", XR8((op % 8), ref pc))); } private void DIS_XAND_R8(byte op, ref ushort pc) { - Z80_Dis_Set("and", Z80_Dis_Printf("%s", XR8((op % 8), pc))); + Z80_Dis_Set("and", Z80_Dis_Printf("%s", XR8((op % 8), ref pc))); } private void DIS_XXOR_R8(byte op, ref ushort pc) { - Z80_Dis_Set("xor", Z80_Dis_Printf("%s", XR8((op % 8), pc))); + Z80_Dis_Set("xor", Z80_Dis_Printf("%s", XR8((op % 8), ref pc))); } private void DIS_X_OR_R8(byte op, ref ushort pc) { - Z80_Dis_Set("or", Z80_Dis_Printf("%s", XR8((op % 8), pc))); + Z80_Dis_Set("or", Z80_Dis_Printf("%s", XR8((op % 8), ref pc))); } private void DIS_XCP_R8(byte op, ref ushort pc) { - Z80_Dis_Set("cp", Z80_Dis_Printf("%s", XR8((op % 8), pc))); + Z80_Dis_Set("cp", Z80_Dis_Printf("%s", XR8((op % 8), ref pc))); } private void DIS_POP_IX(byte op, ref ushort pc) @@ -437,35 +498,35 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler private void DIS_DD_CB_DECODE(byte op, ref ushort pc) { - int nop; + byte nop; - cb_off = (sbyte)Z80_Dis_FetchByte(pc); - nop = Z80_Dis_FetchByte(pc); - dis_DD_CB_opcode[nop](nop, pc); + cb_off = (sbyte)Z80_Dis_FetchByte(ref pc); + nop = Z80_Dis_FetchByte(ref pc); + dis_DD_CB_opcode[nop](nop, ref pc); } private void DIS_DD_DD_DECODE(byte op, ref ushort pc) { - int nop; + byte nop; - nop = Z80_Dis_FetchByte(pc); - dis_DD_opcode[nop](nop, pc); + nop = Z80_Dis_FetchByte(ref pc); + dis_DD_opcode[nop](nop, ref pc); } private void DIS_DD_ED_DECODE(byte op, ref ushort pc) { - int nop; + byte nop; - nop = Z80_Dis_FetchByte(pc); - dis_ED_opcode[nop](nop, pc); + nop = Z80_Dis_FetchByte(ref pc); + dis_ED_opcode[nop](nop, ref pc); } private void DIS_DD_FD_DECODE(byte op, ref ushort pc) { - int nop; + byte nop; - nop = Z80_Dis_FetchByte(pc); - dis_FD_opcode[nop](nop, pc); + nop = Z80_Dis_FetchByte(ref pc); + dis_FD_opcode[nop](nop, ref pc); } @@ -479,10 +540,10 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler reg = (op % 8); if (reg == 6) - Z80_Dis_Set("rlc", Z80_Dis_Printf("%s", IX_RelStrCB(op, pc))); + Z80_Dis_Set("rlc", Z80_Dis_Printf("%s", IX_RelStrCB(op, ref pc))); else { - Z80_Dis_Set("rlc", Z80_Dis_Printf("%s[%s]", IX_RelStrCB(op, pc), z80_dis_reg8[reg])); + Z80_Dis_Set("rlc", Z80_Dis_Printf("%s[%s]", IX_RelStrCB(op, ref pc), z80_dis_reg8[reg])); } } @@ -493,9 +554,9 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler reg = (op % 8); if (reg == 6) - Z80_Dis_Set("rrc", Z80_Dis_Printf("%s", IX_RelStrCB(op, pc))); + Z80_Dis_Set("rrc", Z80_Dis_Printf("%s", IX_RelStrCB(op, ref pc))); else - Z80_Dis_Set("rrc", Z80_Dis_Printf("%s[%s]", IX_RelStrCB(op, pc), z80_dis_reg8[reg])); + Z80_Dis_Set("rrc", Z80_Dis_Printf("%s[%s]", IX_RelStrCB(op, ref pc), z80_dis_reg8[reg])); } private void DIS_RL_IX(byte op, ref ushort pc) @@ -505,9 +566,9 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler reg = (op % 8); if (reg == 6) - Z80_Dis_Set("rl", Z80_Dis_Printf("%s", IX_RelStrCB(op, pc))); + Z80_Dis_Set("rl", Z80_Dis_Printf("%s", IX_RelStrCB(op, ref pc))); else - Z80_Dis_Set("rl", Z80_Dis_Printf("%s[%s]", IX_RelStrCB(op, pc), z80_dis_reg8[reg])); + Z80_Dis_Set("rl", Z80_Dis_Printf("%s[%s]", IX_RelStrCB(op, ref pc), z80_dis_reg8[reg])); } private void DIS_RR_IX(byte op, ref ushort pc) @@ -517,9 +578,9 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler reg = (op % 8); if (reg == 6) - Z80_Dis_Set("rr", Z80_Dis_Printf("%s", IX_RelStrCB(op, pc))); + Z80_Dis_Set("rr", Z80_Dis_Printf("%s", IX_RelStrCB(op, ref pc))); else - Z80_Dis_Set("rr", Z80_Dis_Printf("%s[%s]", IX_RelStrCB(op, pc), z80_dis_reg8[reg])); + Z80_Dis_Set("rr", Z80_Dis_Printf("%s[%s]", IX_RelStrCB(op, ref pc), z80_dis_reg8[reg])); } private void DIS_SLA_IX(byte op, ref ushort pc) @@ -529,9 +590,9 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler reg = (op % 8); if (reg == 6) - Z80_Dis_Set("sla", Z80_Dis_Printf("%s", IX_RelStrCB(op, pc))); + Z80_Dis_Set("sla", Z80_Dis_Printf("%s", IX_RelStrCB(op, ref pc))); else - Z80_Dis_Set("sla", Z80_Dis_Printf("%s[%s]", IX_RelStrCB(op, pc), z80_dis_reg8[reg])); + Z80_Dis_Set("sla", Z80_Dis_Printf("%s[%s]", IX_RelStrCB(op, ref pc), z80_dis_reg8[reg])); } private void DIS_SRA_IX(byte op, ref ushort pc) @@ -541,9 +602,9 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler reg = (op % 8); if (reg == 6) - Z80_Dis_Set("sra", Z80_Dis_Printf("%s", IX_RelStrCB(op, pc))); + Z80_Dis_Set("sra", Z80_Dis_Printf("%s", IX_RelStrCB(op, ref pc))); else - Z80_Dis_Set("sra", Z80_Dis_Printf("%s[%s]", IX_RelStrCB(op, pc), z80_dis_reg8[reg])); + Z80_Dis_Set("sra", Z80_Dis_Printf("%s[%s]", IX_RelStrCB(op, ref pc), z80_dis_reg8[reg])); } private void DIS_SRL_IX(byte op, ref ushort pc) @@ -553,9 +614,9 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler reg = (op % 8); if (reg == 6) - Z80_Dis_Set("srl", Z80_Dis_Printf("%s", IX_RelStrCB(op, pc))); + Z80_Dis_Set("srl", Z80_Dis_Printf("%s", IX_RelStrCB(op, ref pc))); else - Z80_Dis_Set("srl", Z80_Dis_Printf("%s[%s]", IX_RelStrCB(op, pc), z80_dis_reg8[reg])); + Z80_Dis_Set("srl", Z80_Dis_Printf("%s[%s]", IX_RelStrCB(op, ref pc), z80_dis_reg8[reg])); } private void DIS_SLL_IX(byte op, ref ushort pc) @@ -565,9 +626,9 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler reg = (op % 8); if (reg == 6) - Z80_Dis_Set("sll", Z80_Dis_Printf("%s", IX_RelStrCB(op, pc))); + Z80_Dis_Set("sll", Z80_Dis_Printf("%s", IX_RelStrCB(op, ref pc))); else - Z80_Dis_Set("sll", Z80_Dis_Printf("%s[%s]", IX_RelStrCB(op, pc), z80_dis_reg8[reg])); + Z80_Dis_Set("sll", Z80_Dis_Printf("%s[%s]", IX_RelStrCB(op, ref pc), z80_dis_reg8[reg])); } private void DIS_BIT_IX(byte op, ref ushort pc) @@ -579,9 +640,9 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler bit = (op - 0x40) / 8; if (reg == 6) - Z80_Dis_Set("bit", Z80_Dis_Printf("%d,%s", bit, IX_RelStrCB(op, pc))); + Z80_Dis_Set("bit", Z80_Dis_Printf("%d,%s", bit, IX_RelStrCB(op, ref pc))); else - Z80_Dis_Set("bit", Z80_Dis_Printf("%d,%s[%s]", bit, IX_RelStrCB(op, pc), z80_dis_reg8[reg])); + Z80_Dis_Set("bit", Z80_Dis_Printf("%d,%s[%s]", bit, IX_RelStrCB(op, ref pc), z80_dis_reg8[reg])); } private void DIS_RES_IX(byte op, ref ushort pc) @@ -593,9 +654,9 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler bit = (op - 0x80) / 8; if (reg == 6) - Z80_Dis_Set("res", Z80_Dis_Printf("%d,%s", bit, IX_RelStrCB(op, pc))); + Z80_Dis_Set("res", Z80_Dis_Printf("%d,%s", bit, IX_RelStrCB(op, ref pc))); else - Z80_Dis_Set("res", Z80_Dis_Printf("%d,%s[%s]", bit, IX_RelStrCB(op, pc), z80_dis_reg8[reg])); + Z80_Dis_Set("res", Z80_Dis_Printf("%d,%s[%s]", bit, IX_RelStrCB(op, ref pc), z80_dis_reg8[reg])); } private void DIS_SET_IX(byte op, ref ushort pc) @@ -607,9 +668,9 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler bit = (op - 0xc0) / 8; if (reg == 6) - Z80_Dis_Set("set", Z80_Dis_Printf("%d,%s", bit, IX_RelStrCB(op, pc))); + Z80_Dis_Set("set", Z80_Dis_Printf("%d,%s", bit, IX_RelStrCB(op, ref pc))); else - Z80_Dis_Set("set", Z80_Dis_Printf("%d,%s[%s]", bit, IX_RelStrCB(op, pc), z80_dis_reg8[reg])); + Z80_Dis_Set("set", Z80_Dis_Printf("%d,%s[%s]", bit, IX_RelStrCB(op, ref pc), z80_dis_reg8[reg])); } @@ -622,28 +683,20 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler { case 0: return ("b"); - break; case 1: return ("c"); - break; case 2: return ("d"); - break; case 3: return ("e"); - break; case 4: return ("h"); - break; case 5: return ("l"); - break; case 6: return ("0"); - break; case 7: return ("a"); - break; } return "?"; @@ -675,7 +728,7 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler { ushort w; - w = Z80_Dis_FetchWord(pc); + w = Z80_Dis_FetchWord(ref pc); Z80_Dis_Set("ld", Z80_Dis_Printf("($%.4x),%s", w, z80_dis_reg16[(op - 0x40) / 16])); } @@ -708,7 +761,7 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler { ushort w; - w = Z80_Dis_FetchWord(pc); + w = Z80_Dis_FetchWord(ref pc); Z80_Dis_Set("ld", Z80_Dis_Printf("%s,($%.4x)", z80_dis_reg16[(op - 0x40) / 16], w)); } @@ -840,7 +893,7 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler { sbyte r; - r=(sbyte)Z80_Dis_FetchByte(z80,pc); + r=(sbyte)Z80_Dis_FetchByte(ref pc); if (r<0) return String.Format("(iy-${0:x2})",-r); @@ -868,37 +921,28 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler { case 0: return ("b"); - break; case 1: return ("c"); - break; case 2: return ("d"); - break; case 3: return ("e"); - break; case 4: return ("iyh"); - break; case 5: return ("iyl"); - break; case 6: - return (IY_RelStr(0, pc)); - break; + return (IY_RelStr(0, ref pc)); case 7: return ("a"); - break; default: return String.Format("BUG {0}", reg); - break; } } private void DIS_FD_NOP(byte op, ref ushort pc) { - dis_opcode_z80[op](op, pc); + dis_opcode_z80[op](op, ref pc); } private void DIS_ADD_IY_BC(byte op, ref ushort pc) @@ -913,14 +957,14 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler private void DIS_LD_IY_WORD(byte op, ref ushort pc) { - Z80_Dis_Set("ld", Z80_Dis_Printf("iy,$%.4x", Z80_Dis_FetchWord(pc))); + Z80_Dis_Set("ld", Z80_Dis_Printf("iy,$%.4x", Z80_Dis_FetchWord(ref pc))); } private void DIS_LD_ADDR_IY(byte op, ref ushort pc) { ushort w; - w = Z80_Dis_FetchWord(pc); + w = Z80_Dis_FetchWord(ref pc); Z80_Dis_Set("ld", Z80_Dis_Printf("($%.4x),iy", w)); } @@ -941,7 +985,7 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler private void DIS_LD_IYH_BYTE(byte op, ref ushort pc) { - Z80_Dis_Set("ld", Z80_Dis_Printf("iyh,$%.2x", Z80_Dis_FetchByte(pc))); + Z80_Dis_Set("ld", Z80_Dis_Printf("iyh,$%.2x", Z80_Dis_FetchByte(ref pc))); } private void DIS_ADD_IY_IY(byte op, ref ushort pc) @@ -953,7 +997,7 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler { ushort w; - w = Z80_Dis_FetchWord(pc); + w = Z80_Dis_FetchWord(ref pc); Z80_Dis_Set("ld", Z80_Dis_Printf("iy,($%.4x)", w)); } @@ -974,17 +1018,17 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler private void DIS_LD_IYL_BYTE(byte op, ref ushort pc) { - Z80_Dis_Set("ld", Z80_Dis_Printf("iyl,$%.2x", Z80_Dis_FetchByte(pc))); + Z80_Dis_Set("ld", Z80_Dis_Printf("iyl,$%.2x", Z80_Dis_FetchByte(ref pc))); } private void DIS_INC_IIY(byte op, ref ushort pc) { - Z80_Dis_Set("inc", Z80_Dis_Printf("%s", IY_RelStr(op, pc))); + Z80_Dis_Set("inc", Z80_Dis_Printf("%s", IY_RelStr(op, ref pc))); } private void DIS_DEC_IIY(byte op, ref ushort pc) { - Z80_Dis_Set("dec", Z80_Dis_Printf("%s", IY_RelStr(op, pc))); + Z80_Dis_Set("dec", Z80_Dis_Printf("%s", IY_RelStr(op, ref pc))); } private void DIS_LD_IIY_BYTE(byte op, ref ushort pc) @@ -992,8 +1036,8 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler string rel; int b; - rel = IY_RelStr(op, pc); - b = Z80_Dis_FetchByte(pc); + rel = IY_RelStr(op, ref pc); + b = Z80_Dis_FetchByte(ref pc); Z80_Dis_Set("ld", Z80_Dis_Printf("%s,$%.2x", rel, b)); } @@ -1015,18 +1059,18 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler */ if (dest_r==6) { - dest=YR8(z80,dest_r,pc); + dest=YR8(dest_r,ref pc); src=z80_dis_reg8[src_r]; } else if (((dest_r==4)||(dest_r==5))&&(src_r==6)) { dest=z80_dis_reg8[dest_r]; - src=YR8(z80,src_r,pc); + src=YR8(src_r,ref pc); } else { - dest=YR8(z80,dest_r,pc); - src=YR8(z80,src_r,pc); + dest=YR8(dest_r,ref pc); + src = YR8(src_r, ref pc); } Z80_Dis_Set("ld",Z80_Dis_Printf("%s,%s",dest,src)); @@ -1034,42 +1078,42 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler private void DIS_YADD_R8(byte op, ref ushort pc) { - Z80_Dis_Set("add", Z80_Dis_Printf("a,%s", YR8((op % 8), pc))); + Z80_Dis_Set("add", Z80_Dis_Printf("a,%s", YR8((op % 8), ref pc))); } private void DIS_YADC_R8(byte op, ref ushort pc) { - Z80_Dis_Set("adc", Z80_Dis_Printf("a,%s", YR8((op % 8), pc))); + Z80_Dis_Set("adc", Z80_Dis_Printf("a,%s", YR8((op % 8), ref pc))); } private void DIS_YSUB_R8(byte op, ref ushort pc) { - Z80_Dis_Set("sub", Z80_Dis_Printf("a,%s", YR8((op % 8), pc))); + Z80_Dis_Set("sub", Z80_Dis_Printf("a,%s", YR8((op % 8), ref pc))); } private void DIS_YSBC_R8(byte op, ref ushort pc) { - Z80_Dis_Set("sbc", Z80_Dis_Printf("a,%s", YR8((op % 8), pc))); + Z80_Dis_Set("sbc", Z80_Dis_Printf("a,%s", YR8((op % 8), ref pc))); } private void DIS_YAND_R8(byte op, ref ushort pc) { - Z80_Dis_Set("and", Z80_Dis_Printf("%s", YR8((op % 8), pc))); + Z80_Dis_Set("and", Z80_Dis_Printf("%s", YR8((op % 8), ref pc))); } private void DIS_YYOR_R8(byte op, ref ushort pc) { - Z80_Dis_Set("xor", Z80_Dis_Printf("%s", YR8((op % 8), pc))); + Z80_Dis_Set("xor", Z80_Dis_Printf("%s", YR8((op % 8), ref pc))); } private void DIS_Y_OR_R8(byte op, ref ushort pc) { - Z80_Dis_Set("or", Z80_Dis_Printf("%s", YR8((op % 8), pc))); + Z80_Dis_Set("or", Z80_Dis_Printf("%s", YR8((op % 8), ref pc))); } private void DIS_YCP_R8(byte op, ref ushort pc) { - Z80_Dis_Set("cp", Z80_Dis_Printf("%s", YR8((op % 8), pc))); + Z80_Dis_Set("cp", Z80_Dis_Printf("%s", YR8((op % 8), ref pc))); } private void DIS_POP_IY(byte op, ref ushort pc) @@ -1099,35 +1143,35 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler private void DIS_FD_CB_DECODE(byte op, ref ushort pc) { - int nop; + byte nop; - cb_off = (sbyte)Z80_Dis_FetchByte(pc); - nop = Z80_Dis_FetchByte(pc); - dis_FD_CB_opcode[nop](nop, pc); + cb_off = (sbyte)Z80_Dis_FetchByte(ref pc); + nop = Z80_Dis_FetchByte(ref pc); + dis_FD_CB_opcode[nop](nop, ref pc); } private void DIS_FD_DD_DECODE(byte op, ref ushort pc) { - int nop; + byte nop; - nop = Z80_Dis_FetchByte(pc); - dis_DD_opcode[nop](nop, pc); + nop = Z80_Dis_FetchByte(ref pc); + dis_DD_opcode[nop](nop, ref pc); } private void DIS_FD_ED_DECODE(byte op, ref ushort pc) { - int nop; + byte nop; - nop = Z80_Dis_FetchByte(pc); - dis_ED_opcode[nop](nop, pc); + nop = Z80_Dis_FetchByte(ref pc); + dis_ED_opcode[nop](nop, ref pc); } private void DIS_FD_FD_DECODE(byte op, ref ushort pc) { - int nop; + byte nop; - nop = Z80_Dis_FetchByte(pc); - dis_FD_opcode[nop](nop, pc); + nop = Z80_Dis_FetchByte(ref pc); + dis_FD_opcode[nop](nop, ref pc); } @@ -1141,9 +1185,9 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler reg = (op % 8); if (reg == 6) - Z80_Dis_Set("rlc", Z80_Dis_Printf("%s", IY_RelStrCB(op, pc))); + Z80_Dis_Set("rlc", Z80_Dis_Printf("%s", IY_RelStrCB(op, ref pc))); else - Z80_Dis_Set("rlc", Z80_Dis_Printf("%s[%s]", IY_RelStrCB(op, pc), z80_dis_reg8[reg])); + Z80_Dis_Set("rlc", Z80_Dis_Printf("%s[%s]", IY_RelStrCB(op, ref pc), z80_dis_reg8[reg])); } private void DIS_RRC_IY(byte op, ref ushort pc) @@ -1153,9 +1197,9 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler reg = (op % 8); if (reg == 6) - Z80_Dis_Set("rrc", Z80_Dis_Printf("%s", IY_RelStrCB(op, pc))); + Z80_Dis_Set("rrc", Z80_Dis_Printf("%s", IY_RelStrCB(op, ref pc))); else - Z80_Dis_Set("rrc", Z80_Dis_Printf("%s[%s]", IY_RelStrCB(op, pc), z80_dis_reg8[reg])); + Z80_Dis_Set("rrc", Z80_Dis_Printf("%s[%s]", IY_RelStrCB(op, ref pc), z80_dis_reg8[reg])); } private void DIS_RL_IY(byte op, ref ushort pc) @@ -1165,9 +1209,9 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler reg = (op % 8); if (reg == 6) - Z80_Dis_Set("rl", Z80_Dis_Printf("%s", IY_RelStrCB(op, pc))); + Z80_Dis_Set("rl", Z80_Dis_Printf("%s", IY_RelStrCB(op, ref pc))); else - Z80_Dis_Set("rl", Z80_Dis_Printf("%s[%s]", IY_RelStrCB(op, pc), z80_dis_reg8[reg])); + Z80_Dis_Set("rl", Z80_Dis_Printf("%s[%s]", IY_RelStrCB(op, ref pc), z80_dis_reg8[reg])); } private void DIS_RR_IY(byte op, ref ushort pc) @@ -1177,9 +1221,9 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler reg = (op % 8); if (reg == 6) - Z80_Dis_Set("rr", Z80_Dis_Printf("%s", IY_RelStrCB(op, pc))); + Z80_Dis_Set("rr", Z80_Dis_Printf("%s", IY_RelStrCB(op, ref pc))); else - Z80_Dis_Set("rr", Z80_Dis_Printf("%s[%s]", IY_RelStrCB(op, pc), z80_dis_reg8[reg])); + Z80_Dis_Set("rr", Z80_Dis_Printf("%s[%s]", IY_RelStrCB(op, ref pc), z80_dis_reg8[reg])); } private void DIS_SLA_IY(byte op, ref ushort pc) @@ -1189,9 +1233,9 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler reg = (op % 8); if (reg == 6) - Z80_Dis_Set("sla", Z80_Dis_Printf("%s", IY_RelStrCB(op, pc))); + Z80_Dis_Set("sla", Z80_Dis_Printf("%s", IY_RelStrCB(op, ref pc))); else - Z80_Dis_Set("sla", Z80_Dis_Printf("%s[%s]", IY_RelStrCB(op, pc), z80_dis_reg8[reg])); + Z80_Dis_Set("sla", Z80_Dis_Printf("%s[%s]", IY_RelStrCB(op, ref pc), z80_dis_reg8[reg])); } private void DIS_SRA_IY(byte op, ref ushort pc) @@ -1201,9 +1245,9 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler reg = (op % 8); if (reg == 6) - Z80_Dis_Set("sra", Z80_Dis_Printf("%s", IY_RelStrCB(op, pc))); + Z80_Dis_Set("sra", Z80_Dis_Printf("%s", IY_RelStrCB(op, ref pc))); else - Z80_Dis_Set("sra", Z80_Dis_Printf("%s[%s]", IY_RelStrCB(op, pc), z80_dis_reg8[reg])); + Z80_Dis_Set("sra", Z80_Dis_Printf("%s[%s]", IY_RelStrCB(op, ref pc), z80_dis_reg8[reg])); } private void DIS_SRL_IY(byte op, ref ushort pc) @@ -1213,9 +1257,9 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler reg = (op % 8); if (reg == 6) - Z80_Dis_Set("srl", Z80_Dis_Printf("%s", IY_RelStrCB(op, pc))); + Z80_Dis_Set("srl", Z80_Dis_Printf("%s", IY_RelStrCB(op, ref pc))); else - Z80_Dis_Set("srl", Z80_Dis_Printf("%s[%s]", IY_RelStrCB(op, pc), z80_dis_reg8[reg])); + Z80_Dis_Set("srl", Z80_Dis_Printf("%s[%s]", IY_RelStrCB(op, ref pc), z80_dis_reg8[reg])); } private void DIS_SLL_IY(byte op, ref ushort pc) @@ -1225,9 +1269,9 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler reg = (op % 8); if (reg == 6) - Z80_Dis_Set("sll", Z80_Dis_Printf("%s", IY_RelStrCB(op, pc))); + Z80_Dis_Set("sll", Z80_Dis_Printf("%s", IY_RelStrCB(op, ref pc))); else - Z80_Dis_Set("sll", Z80_Dis_Printf("%s[%s]", IY_RelStrCB(op, pc), z80_dis_reg8[reg])); + Z80_Dis_Set("sll", Z80_Dis_Printf("%s[%s]", IY_RelStrCB(op, ref pc), z80_dis_reg8[reg])); } private void DIS_BIT_IY(byte op, ref ushort pc) @@ -1239,9 +1283,9 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler bit = (op - 0x40) / 8; if (reg == 6) - Z80_Dis_Set("bit", Z80_Dis_Printf("%d,%s", bit, IY_RelStrCB(op, pc))); + Z80_Dis_Set("bit", Z80_Dis_Printf("%d,%s", bit, IY_RelStrCB(op, ref pc))); else - Z80_Dis_Set("bit", Z80_Dis_Printf("%d,%s[%s]", bit, IY_RelStrCB(op, pc), z80_dis_reg8[reg])); + Z80_Dis_Set("bit", Z80_Dis_Printf("%d,%s[%s]", bit, IY_RelStrCB(op, ref pc), z80_dis_reg8[reg])); } private void DIS_RES_IY(byte op, ref ushort pc) @@ -1253,9 +1297,9 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler bit = (op - 0x80) / 8; if (reg == 6) - Z80_Dis_Set("res", Z80_Dis_Printf("%d,%s", bit, IY_RelStrCB(op, pc))); + Z80_Dis_Set("res", Z80_Dis_Printf("%d,%s", bit, IY_RelStrCB(op, ref pc))); else - Z80_Dis_Set("res", Z80_Dis_Printf("%d,%s[%s]", bit, IY_RelStrCB(op, pc), z80_dis_reg8[reg])); + Z80_Dis_Set("res", Z80_Dis_Printf("%d,%s[%s]", bit, IY_RelStrCB(op, ref pc), z80_dis_reg8[reg])); } private void DIS_SET_IY(byte op, ref ushort pc) @@ -1267,9 +1311,9 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler bit = (op - 0xc0) / 8; if (reg == 6) - Z80_Dis_Set("set", Z80_Dis_Printf("%d,%s", bit, IY_RelStrCB(op, pc))); + Z80_Dis_Set("set", Z80_Dis_Printf("%d,%s", bit, IY_RelStrCB(op, ref pc))); else - Z80_Dis_Set("set", Z80_Dis_Printf("%d,%s[%s]", bit, IY_RelStrCB(op, pc), z80_dis_reg8[reg])); + Z80_Dis_Set("set", Z80_Dis_Printf("%d,%s[%s]", bit, IY_RelStrCB(op, ref pc), z80_dis_reg8[reg])); } @@ -1285,7 +1329,7 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler string reg; reg = z80_dis_reg16[(op & 0x30) / 0x10]; - Z80_Dis_Set("ld", Z80_Dis_Printf("%s,$%.4x", reg, Z80_Dis_FetchWord(pc))); + Z80_Dis_Set("ld", Z80_Dis_Printf("%s,$%.4x", reg, Z80_Dis_FetchWord(ref pc))); } private void DIS_LD_R16_A(byte op, ref ushort pc) @@ -1325,7 +1369,7 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler string reg; reg = z80_dis_reg8[(op & 0x38) / 0x8]; - Z80_Dis_Set("ld", Z80_Dis_Printf("%s,$%.2x", reg, Z80_Dis_FetchByte(pc))); + Z80_Dis_Set("ld", Z80_Dis_Printf("%s,$%.2x", reg, Z80_Dis_FetchByte(ref pc))); } private void DIS_RLCA(byte op, ref ushort pc) @@ -1371,7 +1415,7 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler { ushort n; - n = pc + (sbyte)memory.Read(pc) + 1; + n = (ushort)(pc + (sbyte)((memory.Read(pc) + 1))); pc++; Z80_Dis_Set("djnz", Z80_Dis_Printf("$%.4x", n)); } @@ -1385,7 +1429,7 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler { ushort n; - n = pc + (sbyte)memory.Read(pc) + 1; + n = (ushort)(pc + (sbyte)(memory.Read(pc) + 1)); pc++; Z80_Dis_Set("jr", Z80_Dis_Printf("$%.4x", n)); } @@ -1401,7 +1445,7 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler ushort n; con = z80_dis_condition[(op - 0x20) / 8]; - n = pc + (sbyte)memory.Read(pc) + 1; + n = (ushort)(pc + (sbyte)(memory.Read(pc) + 1)); pc++; Z80_Dis_Set("jr", Z80_Dis_Printf("%s,$%.4x", con, n)); } @@ -1410,7 +1454,7 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler { ushort w; - w = Z80_Dis_FetchWord(pc); + w = Z80_Dis_FetchWord(ref pc); Z80_Dis_Set("ld", Z80_Dis_Printf("($%.4x),hl", w)); } @@ -1423,7 +1467,7 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler { ushort w; - w = Z80_Dis_FetchWord(pc); + w = Z80_Dis_FetchWord(ref pc); Z80_Dis_Set("ld", Z80_Dis_Printf("hl,($%.4x)", w)); } @@ -1436,7 +1480,7 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler { ushort w; - w = Z80_Dis_FetchWord(pc); + w = Z80_Dis_FetchWord(ref pc); Z80_Dis_Set("ld", Z80_Dis_Printf("($%.4x),a", w)); } @@ -1449,7 +1493,7 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler { ushort w; - w = Z80_Dis_FetchWord(pc); + w = Z80_Dis_FetchWord(ref pc); Z80_Dis_Set("ld", Z80_Dis_Printf("a,($%.4x)", w)); } @@ -1551,7 +1595,7 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler reg = z80_dis_reg16[(op - 0xc0) / 16]; - if (!strcmp(reg, "sp")) + if (reg == "sp") reg = "af"; Z80_Dis_Set("pop", reg); @@ -1561,7 +1605,7 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler { ushort w; - w = Z80_Dis_FetchWord(pc); + w = Z80_Dis_FetchWord(ref pc); Z80_Dis_Set("jp", Z80_Dis_Printf("$%.4x", w)); } @@ -1571,7 +1615,7 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler reg = z80_dis_reg16[(op - 0xc0) / 16]; - if (!strcmp(reg, "sp")) + if (reg == "sp") reg = "af"; Z80_Dis_Set("push", reg); @@ -1579,7 +1623,7 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler private void DIS_ADD_A_BYTE(byte op, ref ushort pc) { - Z80_Dis_Set("add", Z80_Dis_Printf("a,$%.2x", Z80_Dis_FetchByte(pc))); + Z80_Dis_Set("add", Z80_Dis_Printf("a,$%.2x", Z80_Dis_FetchByte(ref pc))); } private void DIS_RST(byte op, ref ushort pc) @@ -1600,17 +1644,17 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler string con; ushort w; - w = Z80_Dis_FetchWord(pc); + w = Z80_Dis_FetchWord(ref pc); con = z80_dis_condition[(op - 0xc0) / 8]; Z80_Dis_Set("jp", Z80_Dis_Printf("%s,$%.4x", con, w)); } private void DIS_CB_DECODE(byte op, ref ushort pc) { - int nop; + byte nop; - nop = Z80_Dis_FetchByte(pc); - dis_CB_opcode[nop](nop, pc); + nop = Z80_Dis_FetchByte(ref pc); + dis_CB_opcode[nop](nop, ref pc); } private void DIS_CALL_CO(byte op, ref ushort pc) @@ -1618,7 +1662,7 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler string con; ushort w; - w = Z80_Dis_FetchWord(pc); + w = Z80_Dis_FetchWord(ref pc); con = z80_dis_condition[(op - 0xc0) / 8]; Z80_Dis_Set("call", Z80_Dis_Printf("%s,$%.4x", con, w)); } @@ -1627,23 +1671,23 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler { ushort w; - w = Z80_Dis_FetchWord(pc); + w = Z80_Dis_FetchWord(ref pc); Z80_Dis_Set("call", Z80_Dis_Printf("$%.4x", w)); } private void DIS_ADC_A_BYTE(byte op, ref ushort pc) { - Z80_Dis_Set("adc", Z80_Dis_Printf("a,$%.2x", Z80_Dis_FetchByte(pc))); + Z80_Dis_Set("adc", Z80_Dis_Printf("a,$%.2x", Z80_Dis_FetchByte(ref pc))); } private void DIS_OUT_BYTE_A(byte op, ref ushort pc) { - Z80_Dis_Set("out", Z80_Dis_Printf("($%.2x),a", Z80_Dis_FetchByte(pc))); + Z80_Dis_Set("out", Z80_Dis_Printf("($%.2x),a", Z80_Dis_FetchByte(ref pc))); } private void DIS_SUB_A_BYTE(byte op, ref ushort pc) { - Z80_Dis_Set("sub", Z80_Dis_Printf("a,$%.2x", Z80_Dis_FetchByte(pc))); + Z80_Dis_Set("sub", Z80_Dis_Printf("a,$%.2x", Z80_Dis_FetchByte(ref pc))); } private void DIS_EXX(byte op, ref ushort pc) @@ -1653,20 +1697,20 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler private void DIS_IN_A_BYTE(byte op, ref ushort pc) { - Z80_Dis_Set("in", Z80_Dis_Printf("a,($%.2x)", Z80_Dis_FetchByte(pc))); + Z80_Dis_Set("in", Z80_Dis_Printf("a,($%.2x)", Z80_Dis_FetchByte(ref pc))); } private void DIS_DD_DECODE(byte op, ref ushort pc) { - int nop; + byte nop; - nop = Z80_Dis_FetchByte(pc); - dis_DD_opcode[nop](nop, pc); + nop = Z80_Dis_FetchByte(ref pc); + dis_DD_opcode[nop](nop, ref pc); } private void DIS_SBC_A_BYTE(byte op, ref ushort pc) { - Z80_Dis_Set("sbc", Z80_Dis_Printf("a,$%.2x", Z80_Dis_FetchByte(pc))); + Z80_Dis_Set("sbc", Z80_Dis_Printf("a,$%.2x", Z80_Dis_FetchByte(ref pc))); } @@ -1677,7 +1721,7 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler private void DIS_AND_A_BYTE(byte op, ref ushort pc) { - Z80_Dis_Set("and", Z80_Dis_Printf("$%.2x", Z80_Dis_FetchByte(pc))); + Z80_Dis_Set("and", Z80_Dis_Printf("$%.2x", Z80_Dis_FetchByte(ref pc))); } private void DIS_JP_HL(byte op, ref ushort pc) @@ -1692,15 +1736,15 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler private void DIS_ED_DECODE(byte op, ref ushort pc) { - int nop; + byte nop; - nop = Z80_Dis_FetchByte(pc); - dis_ED_opcode[nop](nop, pc); + nop = Z80_Dis_FetchByte(ref pc); + dis_ED_opcode[nop](nop, ref pc); } private void DIS_XOR_A_BYTE(byte op, ref ushort pc) { - Z80_Dis_Set("xor", Z80_Dis_Printf("$%.2x", Z80_Dis_FetchByte(pc))); + Z80_Dis_Set("xor", Z80_Dis_Printf("$%.2x", Z80_Dis_FetchByte(ref pc))); } private void DIS_DI(byte op, ref ushort pc) @@ -1710,7 +1754,7 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler private void DIS_OR_A_BYTE(byte op, ref ushort pc) { - Z80_Dis_Set("or", Z80_Dis_Printf("$%.2x", Z80_Dis_FetchByte(pc))); + Z80_Dis_Set("or", Z80_Dis_Printf("$%.2x", Z80_Dis_FetchByte(ref pc))); } private void DIS_LD_SP_HL(byte op, ref ushort pc) @@ -1725,15 +1769,15 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler private void DIS_FD_DECODE(byte op, ref ushort pc) { - int nop; + byte nop; - nop = Z80_Dis_FetchByte(pc); - dis_FD_opcode[nop](nop, pc); + nop = Z80_Dis_FetchByte(ref pc); + dis_FD_opcode[nop](nop, ref pc); } private void DIS_CP_A_BYTE(byte op, ref ushort pc) { - Z80_Dis_Set("cp", Z80_Dis_Printf("$%.2x", Z80_Dis_FetchByte(pc))); + Z80_Dis_Set("cp", Z80_Dis_Printf("$%.2x", Z80_Dis_FetchByte(ref pc))); } #endregion @@ -1746,6 +1790,8 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler // Register16.Verify(); + Hex = new StringBuilder(); + // Setup function tables // dis_CB_opcode = new disassemble[0x100] @@ -2355,13 +2401,16 @@ namespace Noddybox.Emulation.EightBit.Z80.Disassembler public ushort Disassemble(ushort startAddress, out string address, out string opcode, out string hexdump) { - address = String.Empty; - opcode = String.Empty; - hexdump = String.Empty; - Opcode = String.Empty; - Argument = String.Empty; + address = String.Format("{0:X4}", startAddress); + + byte op = Z80_Dis_FetchByte(ref startAddress); + + Hex.Clear(); + + dis_opcode_z80[op](op, ref startAddress); - String.Format(address, "{0:X4}", address); + opcode = String.Format("{0} {1}", Opcode, Argument); + hexdump = Hex.ToString(); return startAddress; } -- cgit v1.2.3