From e53661ce8a25587fd4fec8ffb87407557e4e0a49 Mon Sep 17 00:00:00 2001 From: Marc Parsons Date: Mon, 20 Apr 2026 01:19:47 +0100 Subject: [PATCH] Implemented a few more OpCodes. 0xDD19 next --- Core/Cpu/Z80.cs | 34 +++++++++++++++++++++++++++++++++- Desktop/DebuggerForm.cs | 11 +++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/Core/Cpu/Z80.cs b/Core/Cpu/Z80.cs index ca88462..a619d52 100644 --- a/Core/Cpu/Z80.cs +++ b/Core/Cpu/Z80.cs @@ -722,7 +722,7 @@ namespace Core.Cpu case 0x14: DE.High = Inc8(DE.High); return 4; // INC D case 0x1C: DE.Low = Inc8(DE.Low); return 4; // INC E case 0x1E: DE.Low = FetchByte(); // LD E, n - return 7; + return 7; case 0x24: HL.High = Inc8(HL.High); return 4; // INC H case 0x2C: HL.Low = Inc8(HL.Low); return 4; // INC L case 0x2E: // LD L, n @@ -1666,6 +1666,30 @@ namespace Core.Cpu SP = (ushort)((spHigh << 8) | spLow); return 20; + case 0xA0: // LDI + // 1. Read byte from (HL) + val = _memory.Read(HL.Word); + + // 2. Write byte to (DE) + _memory.Write(DE.Word, val); + + // 3. Increment memory pointers, Decrement byte counter + HL.Word++; + DE.Word++; + BC.Word--; + + // 4. Update Flags + // Preserve S (0x80), Z (0x40), and C (0x01). + // H (0x10) and N (0x02) are forcefully reset to 0. + AF.Low &= 0xC1; + + // P/V Flag (Bit 2) is set to 1 if BC is not 0 after the decrement + if (BC.Word != 0) + { + AF.Low |= 0x04; + } + + return 16; case 0xB0: // LDIR // 1. Read byte from (HL) val = _memory.Read(HL.Word); @@ -1935,6 +1959,10 @@ namespace Core.Cpu _memory.Write((ushort)(address22 + 1), IX.High); return 20; + case 0x23: // INC IX + // Increment the full 16-bit register. Do NOT touch AF.Low! + IX.Word++; + return 10; case 0x24: // INC IXH // Increment the high byte of IX and let the helper perfectly map the flags IX.High = Inc8(IX.High); @@ -1963,6 +1991,10 @@ namespace Core.Cpu IX.Word = (ushort)((ixHigh << 8) | ixLow); return 20; + case 0x2B: // DEC IX + // Decrement the full 16-bit register. The F register remains completely untouched. + IX.Word--; + return 10; case 0x2D: // DEC IXL IX.Low = Dec8(IX.Low); return 8; diff --git a/Desktop/DebuggerForm.cs b/Desktop/DebuggerForm.cs index 93e5546..d4f989b 100644 --- a/Desktop/DebuggerForm.cs +++ b/Desktop/DebuggerForm.cs @@ -849,6 +849,11 @@ namespace Desktop mnemonic = $"LD (0x{nn:X4}), IX"; instructionLength = 4; } + else if (ddOpcode == 0x23) // INC IX + { + mnemonic = "INC IX"; + instructionLength = 2; + } else if (ddOpcode == 0x24) // INC IXH { mnemonic = "INC IXH"; @@ -871,6 +876,11 @@ namespace Desktop mnemonic = $"LD IX, (0x{nn:X4})"; instructionLength = 4; } + else if (ddOpcode == 0x2B) // DEC IX + { + mnemonic = "DEC IX"; + instructionLength = 2; + } else if (ddOpcode == 0x2D) // DEC IXL { mnemonic = "DEC IXL"; @@ -1093,6 +1103,7 @@ namespace Desktop mnemonic = $"LD SP, (0x{nn:X4})"; instructionLength = 4; break; + case 0xA0: mnemonic = "LDI"; instructionLength = 2; break; case 0xB0: mnemonic = "LDIR"; instructionLength = 2;