Getting keyboard working - WIP
This commit is contained in:
@@ -77,7 +77,8 @@ namespace Core.Cpu
|
||||
IFF1 = false;
|
||||
IFF2 = false;
|
||||
InterruptMode = 0;
|
||||
TotalTStates = 0; // Reset the system clock!
|
||||
TotalTStates = 0;
|
||||
//_memory.CleanRAMData();
|
||||
}
|
||||
|
||||
public int RequestInterrupt()
|
||||
@@ -1109,7 +1110,9 @@ namespace Core.Cpu
|
||||
HL.Word = HL_Prime.Word;
|
||||
HL_Prime.Word = tempHL;
|
||||
|
||||
return 4; // Takes 4 T-States
|
||||
return 4;
|
||||
case 0xDD:
|
||||
return ExecuteDDPrefix();
|
||||
case 0xDE: // SBC A, n
|
||||
Sbc(FetchByte());
|
||||
return 7;
|
||||
@@ -1361,8 +1364,15 @@ namespace Core.Cpu
|
||||
// Shift left, and loop the falling bit back into Bit 0
|
||||
val = (byte)((val << 1) | (carryOut ? 1 : 0));
|
||||
break;
|
||||
case 7: // SRL (Shift Right Logical)
|
||||
// 1. Grab Bit 0 before it falls off to set the Carry flag
|
||||
carryOut = (val & 0x01) != 0;
|
||||
|
||||
// (We will add RRC, RL, RR, SLA, SRA, SRL here as the ROM asks for them!)
|
||||
// 2. Shift the byte right by 1.
|
||||
// (In C#, a standard right shift on a positive byte automatically pads Bit 7 with a 0)
|
||||
val = (byte)(val >> 1);
|
||||
break;
|
||||
// (We will add RRC, RL, RR, SLA, SRA, here as the ROM asks for them!)
|
||||
default:
|
||||
throw new NotImplementedException($"CB Shift instruction type {shiftType} not implemented!");
|
||||
}
|
||||
@@ -1402,6 +1412,24 @@ namespace Core.Cpu
|
||||
return (regIndex == 6) ? 15 : 8;
|
||||
}
|
||||
|
||||
private int ExecuteDDPrefix()
|
||||
{
|
||||
byte ddOpcode = FetchByte(); // Fetch the actual instruction after 0xDD
|
||||
|
||||
switch (ddOpcode)
|
||||
{
|
||||
case 0x21: // LD IX, nn
|
||||
byte low = FetchByte();
|
||||
byte high = FetchByte();
|
||||
IX.Word = (ushort)((high << 8) | low);
|
||||
|
||||
return 14; // 14 T-States
|
||||
|
||||
default:
|
||||
throw new NotImplementedException($"DD Prefix opcode 0x{ddOpcode:X2} not implemented!");
|
||||
}
|
||||
}
|
||||
|
||||
private int ExecuteFDPrefix()
|
||||
{
|
||||
byte opcode = FetchByte();
|
||||
@@ -1439,6 +1467,39 @@ namespace Core.Cpu
|
||||
BC.High = _memory.Read(targetAddress);
|
||||
return 19; // Takes 19 T-States
|
||||
}
|
||||
case 0x4E: // LD C, (IY+d)
|
||||
// 1. Fetch the displacement byte and cast it to a signed sbyte
|
||||
sbyte offset4E = (sbyte)FetchByte();
|
||||
|
||||
// 2. Calculate the final address (IY + offset)
|
||||
ushort address4E = (ushort)(IY.Word + offset4E);
|
||||
|
||||
// 3. Read the memory and store it in C
|
||||
BC.Low = _memory.Read(address4E);
|
||||
|
||||
return 19;
|
||||
case 0x56: // LD D, (IY+d)
|
||||
// 1. Fetch the displacement byte and cast it to a signed sbyte
|
||||
sbyte offset56 = (sbyte)FetchByte();
|
||||
|
||||
// 2. Calculate the final address (IY + offset)
|
||||
ushort address56 = (ushort)(IY.Word + offset56);
|
||||
|
||||
// 3. Read the memory and store it in D (the high byte of DE)
|
||||
DE.High = _memory.Read(address56);
|
||||
|
||||
return 19;
|
||||
case 0x5E: // LD E, (IY+d)
|
||||
// 1. Fetch the displacement byte and cast it to a signed sbyte
|
||||
sbyte offset5E = (sbyte)FetchByte();
|
||||
|
||||
// 2. Calculate the final address (IY + offset)
|
||||
ushort address5E = (ushort)(IY.Word + offset5E);
|
||||
|
||||
// 3. Read the memory and store it in E (the low byte of DE)
|
||||
DE.Low = _memory.Read(address5E);
|
||||
|
||||
return 19;
|
||||
case 0x6E: // LD L, (IY+d)
|
||||
sbyte displacementVal = (sbyte)FetchByte();
|
||||
ushort targetAddr = (ushort)(IY.Word + displacementVal);
|
||||
|
||||
@@ -4,5 +4,6 @@
|
||||
{
|
||||
byte Read(ushort address);
|
||||
void Write(ushort address, byte value);
|
||||
void CleanRAMData();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user