More OpCodes - working towards ZEXALL perfection
This commit is contained in:
@@ -6,6 +6,7 @@ namespace Core.Cpu
|
||||
{
|
||||
public partial class Z80
|
||||
{
|
||||
public bool IsZexDocMode { get; set; } = false;
|
||||
//T-State counter
|
||||
public long TotalTStates { get; set; }
|
||||
|
||||
@@ -47,6 +48,7 @@ namespace Core.Cpu
|
||||
public Func<ushort, long, int>? WaitStateCallback { get; set; }
|
||||
|
||||
//Misc Variables
|
||||
public bool EnableFastLoad { get; set; } = true;
|
||||
byte newFlags = 0;
|
||||
int result = 0;
|
||||
|
||||
@@ -194,10 +196,44 @@ namespace Core.Cpu
|
||||
|
||||
public int Step()
|
||||
{
|
||||
if (PC == 0x0556 && _tapManager.HasBlocks)
|
||||
if (IsZexDocMode && PC == 0x0005)
|
||||
{
|
||||
HandleInstantTapeLoad();
|
||||
return 100; // Return a dummy number of T-States for the hijacking
|
||||
// CP/M System Call Hook
|
||||
if (BC.Low == 2) // C = 2: Print a single character stored in register E
|
||||
{
|
||||
System.Diagnostics.Debug.Write((char)DE.Low);
|
||||
}
|
||||
else if (BC.Low == 9) // C = 9: Print a string starting at memory address DE, terminated by '$'
|
||||
{
|
||||
ushort addr = DE.Word;
|
||||
while (true)
|
||||
{
|
||||
char c = (char)ReadMemory(addr++);
|
||||
if (c == '$') break;
|
||||
System.Diagnostics.Debug.Write(c);
|
||||
}
|
||||
}
|
||||
|
||||
// Emulate a 'RET' instruction to return from the CALL 0x0005
|
||||
byte retLow = ReadMemory(SP);
|
||||
SP++;
|
||||
byte retHigh = ReadMemory(SP);
|
||||
SP++;
|
||||
PC = (ushort)((retHigh << 8) | retLow);
|
||||
|
||||
return 10; // Skip normal execution for this cycle
|
||||
}
|
||||
if (PC == 0x0556)
|
||||
{
|
||||
if (EnableFastLoad)
|
||||
{
|
||||
HandleInstantTapeLoad();
|
||||
return 100;
|
||||
}
|
||||
else
|
||||
{
|
||||
_tapManager.Play();
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch the next opcode and increment the Program Counter
|
||||
@@ -2819,7 +2855,7 @@ namespace Core.Cpu
|
||||
|
||||
AF.Low = newFlags;
|
||||
|
||||
return 19; // 19 T-States
|
||||
return 19;
|
||||
case 0xCB: // The FD CB nested prefix
|
||||
{
|
||||
sbyte displacement = (sbyte)FetchByte();
|
||||
@@ -2866,6 +2902,26 @@ namespace Core.Cpu
|
||||
throw new Exception("Invalid bitwise operation.");
|
||||
}
|
||||
}
|
||||
case 0xE1: // POP IY
|
||||
// 1. Read the Low byte from the current Stack Pointer, then increment SP
|
||||
IY.Low = ReadMemory(SP);
|
||||
SP++;
|
||||
|
||||
// 2. Read the High byte from the new Stack Pointer, then increment SP
|
||||
IY.High = ReadMemory(SP);
|
||||
SP++;
|
||||
|
||||
return 14; // 14 T-States
|
||||
case 0xE5: // PUSH IY
|
||||
// 1. Decrement SP and write the High byte
|
||||
SP--;
|
||||
WriteMemory(SP, IY.High);
|
||||
|
||||
// 2. Decrement SP again and write the Low byte
|
||||
SP--;
|
||||
WriteMemory(SP, IY.Low);
|
||||
|
||||
return 15; // 15 T-States
|
||||
default:
|
||||
throw new NotImplementedException($"FD prefix opcode {opcode:X2} at PC 0x{(PC - 2):X4} not implemented!");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user