Implemented many more OpCodes - again, again!

This commit is contained in:
2026-04-13 22:51:20 +01:00
parent 9496c26004
commit 08d718f41e
2 changed files with 67 additions and 7 deletions

View File

@@ -449,6 +449,14 @@ namespace Core.Cpu
case 0x16: // LD D, n case 0x16: // LD D, n
DE.High = FetchByte(); DE.High = FetchByte();
return 7; return 7;
case 0x18: // JR d
sbyte jumpDistance = (sbyte)FetchByte();
// PC has already been incremented by FetchByte(), so it is
// pointing exactly where it needs to be for the relative addition.
PC = (ushort)(PC + jumpDistance);
return 12;
case 0x19: // ADD HL, DE case 0x19: // ADD HL, DE
Add16(DE.Word); Add16(DE.Word);
return 11; return 11;
@@ -646,6 +654,9 @@ namespace Core.Cpu
case 0xDE: // SBC A, n case 0xDE: // SBC A, n
Sbc(FetchByte()); Sbc(FetchByte());
return 7; return 7;
case 0xE9: // JP (HL)
PC = HL.Word;
return 4; // Takes 4 T-States
case 0xEB: // EX DE, HL case 0xEB: // EX DE, HL
ushort tempEx = DE.Word; ushort tempEx = DE.Word;
DE.Word = HL.Word; DE.Word = HL.Word;
@@ -856,11 +867,38 @@ namespace Core.Cpu
_memory.Write(targetAddress, memValRes4); _memory.Write(targetAddress, memValRes4);
return 23; return 23;
case 0xAE: // RES 5, (IY+d)
byte memValRes5 = _memory.Read(targetAddress);
// 0xDF is Binary 1101 1111
// ANDing perfectly preserves all other bits while forcing Bit 5 to 0
memValRes5 &= 0xDF;
_memory.Write(targetAddress, memValRes5);
return 23;
case 0xC6: // SET 0, (IY+d)
byte memValSet0 = _memory.Read(targetAddress);
// 0x01 is Binary 0000 0001
// ORing forces Bit 0 to 1 and perfectly preserves all other bits
memValSet0 |= 0x01;
_memory.Write(targetAddress, memValSet0);
return 23; // Takes 23 T-States
case 0xCE: // SET 1, (IY+d) case 0xCE: // SET 1, (IY+d)
memVal = _memory.Read(targetAddress); memVal = _memory.Read(targetAddress);
memVal |= 0x02; // 0x02 is Binary 0000 0010 (Bit 1) memVal |= 0x02; // 0x02 is Binary 0000 0010 (Bit 1)
_memory.Write(targetAddress, memVal); _memory.Write(targetAddress, memVal);
return 23; // Takes 23 T-States return 23;
case 0xE6: // SET 4, (IY+d)
byte memValSet4 = _memory.Read(targetAddress);
// 0x10 is Binary 0001 0000
// ORing perfectly preserves all other bits while forcing Bit 4 to 1
memValSet4 |= 0x10;
_memory.Write(targetAddress, memValSet4);
return 23;
default: default:
throw new NotImplementedException($"FD CB opcode {bitOpcode:X2} not implemented!"); throw new NotImplementedException($"FD CB opcode {bitOpcode:X2} not implemented!");

View File

@@ -282,6 +282,14 @@ namespace Desktop
mnemonic = $"LD D, 0x{dImm:X2}"; mnemonic = $"LD D, 0x{dImm:X2}";
instructionLength = 2; instructionLength = 2;
break; break;
case 0x18:
sbyte dUnconditional = (sbyte)_memoryBus.Read((ushort)(currentPc + 1));
// Calculate the target address based on the PC *after* this 2-byte instruction
ushort targetAddressUnconditional = (ushort)(currentPc + 2 + dUnconditional);
mnemonic = $"JR 0x{targetAddressUnconditional:X4}";
instructionLength = 2;
break;
case 0x19: case 0x19:
mnemonic = "ADD HL, DE"; mnemonic = "ADD HL, DE";
break; break;
@@ -453,6 +461,9 @@ namespace Desktop
mnemonic = $"SBC A, 0x{sbcValue:X2}"; mnemonic = $"SBC A, 0x{sbcValue:X2}";
instructionLength = 2; instructionLength = 2;
break; break;
case 0xE9:
mnemonic = "JP (HL)";
break;
case 0xEB: case 0xEB:
mnemonic = "EX DE, HL"; mnemonic = "EX DE, HL";
break; break;
@@ -578,14 +589,25 @@ namespace Desktop
sbyte d = (sbyte)_memoryBus.Read((ushort)(currentPc + 2)); sbyte d = (sbyte)_memoryBus.Read((ushort)(currentPc + 2));
byte cbOpcode = _memoryBus.Read((ushort)(currentPc + 3)); byte cbOpcode = _memoryBus.Read((ushort)(currentPc + 3));
string sign = d >= 0 ? "+" : ""; string sign = d >= 0 ? "+" : "";
if (cbOpcode == 0x8E)
if (cbOpcode == 0xCE) {
mnemonic = $"RES 1, (IY{sign}{d})";
}
else if (cbOpcode == 0xAE)
{
mnemonic = $"RES 5, (IY{sign}{d})";
}
else if (cbOpcode == 0xC6)
{
mnemonic = $"SET 0, (IY{sign}{d})";
}
else if (cbOpcode == 0xCE)
{ {
mnemonic = $"SET 1, (IY{sign}{d})"; mnemonic = $"SET 1, (IY{sign}{d})";
} }
else if (cbOpcode == 0x8E) else if (cbOpcode == 0xE6)
{ {
mnemonic = $"RES 1, (IY{sign}{d})"; mnemonic = $"SET 4, (IY{sign}{d})";
} }
else else
{ {