diff options
author | Ian C <ianc@noddybox.co.uk> | 2012-04-03 22:50:43 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2012-04-03 22:50:43 +0000 |
commit | 6d1c25245c7d10df82548055bbec2f2612cdb619 (patch) | |
tree | b900425dfc69792b1576cfcf13690f718cea727a /src | |
parent | 39a55c3b475f83508d67012b8dbbb0676fdd70d3 (diff) |
Some more emulation fixes.
Diffstat (limited to 'src')
-rw-r--r-- | src/Noddybox.Emulation.EightBit.Z80/Z80CpuBaseOpcodes.cs | 62 | ||||
-rw-r--r-- | src/Noddybox.Emulation.EightBit.Z80/Z80CpuDecodeED.cs | 2 |
2 files changed, 54 insertions, 10 deletions
diff --git a/src/Noddybox.Emulation.EightBit.Z80/Z80CpuBaseOpcodes.cs b/src/Noddybox.Emulation.EightBit.Z80/Z80CpuBaseOpcodes.cs index cc02e94..eed7258 100644 --- a/src/Noddybox.Emulation.EightBit.Z80/Z80CpuBaseOpcodes.cs +++ b/src/Noddybox.Emulation.EightBit.Z80/Z80CpuBaseOpcodes.cs @@ -789,17 +789,21 @@ namespace Noddybox.Emulation.EightBit.Z80 HL.reg++;
BC.reg--;
+ ClearFlag(Z80Flags.HalfCarry | Z80Flags.Neg | Z80Flags.Hidden | Z80Flags.PV);
+
if (BC.reg != 0)
{
- ClearFlag(Z80Flags.HalfCarry | Z80Flags.Neg);
SetFlag(Z80Flags.PV);
}
- else
+
+ b += A;
+
+ if ((b & 2) == 2)
{
- ClearFlag(Z80Flags.HalfCarry | Z80Flags.Neg | Z80Flags.PV);
+ F |= Z80Flags.Hidden5;
}
- F |= H35table[A + b];
+ F |= (Z80Flags)(b & 8);
}
/// <summary>
@@ -831,11 +835,18 @@ namespace Noddybox.Emulation.EightBit.Z80 /// </summary>
private void CPI()
{
- Z80Flags c = F & Z80Flags.Carry;
byte b = memory.Read(HL.reg);
+ byte tmp = (byte)(A - b);
+ int w = A - b;
+
+ if (w < 0)
+ {
+ w += 0x200;
+ }
+
+ int lookup = ((A & 0x08) >> 3) | ((b & 0x08) >> 2) | ((tmp & 0x08) >> 1);
- CP(b);
- F |= c;
+ F = (F & Z80Flags.Carry) | SZtable[w] | Z80Flags.Neg | halfcarry_sub_table[lookup];
HL.reg++;
BC.reg--;
@@ -848,6 +859,18 @@ namespace Noddybox.Emulation.EightBit.Z80 {
ClearFlag(Z80Flags.PV);
}
+
+ if ((F & Z80Flags.HalfCarry) == Z80Flags.HalfCarry)
+ {
+ tmp--;
+ }
+
+ if ((tmp & 2) == 2)
+ {
+ F |= Z80Flags.Hidden5;
+ }
+
+ F |= (Z80Flags)(tmp & 8);
}
/// <summary>
@@ -855,11 +878,18 @@ namespace Noddybox.Emulation.EightBit.Z80 /// </summary>
private void CPD()
{
- Z80Flags c = F & Z80Flags.Carry;
byte b = memory.Read(HL.reg);
+ byte tmp = (byte)(A - b);
+ int w = A - b;
+
+ if (w < 0)
+ {
+ w += 0x200;
+ }
- CP(b);
- F |= c;
+ int lookup = ((A & 0x08) >> 3) | ((b & 0x08) >> 2) | ((tmp & 0x08) >> 1);
+
+ F = (F & Z80Flags.Carry) | SZtable[w] | Z80Flags.Neg | halfcarry_sub_table[lookup];
HL.reg--;
BC.reg--;
@@ -872,6 +902,18 @@ namespace Noddybox.Emulation.EightBit.Z80 {
ClearFlag(Z80Flags.PV);
}
+
+ if ((F & Z80Flags.HalfCarry) == Z80Flags.HalfCarry)
+ {
+ tmp--;
+ }
+
+ if ((tmp & 2) == 2)
+ {
+ F |= Z80Flags.Hidden5;
+ }
+
+ F |= (Z80Flags)(tmp & 8);
}
/// <summary>
diff --git a/src/Noddybox.Emulation.EightBit.Z80/Z80CpuDecodeED.cs b/src/Noddybox.Emulation.EightBit.Z80/Z80CpuDecodeED.cs index f9cc84e..7ad170c 100644 --- a/src/Noddybox.Emulation.EightBit.Z80/Z80CpuDecodeED.cs +++ b/src/Noddybox.Emulation.EightBit.Z80/Z80CpuDecodeED.cs @@ -376,6 +376,8 @@ namespace Noddybox.Emulation.EightBit.Z80 case 0x78: // IN A,(C)
clock.Add(12);
A = device.Read(BC.reg);
+ F &= Z80Flags.Carry;
+ F |= PSZtable[A] | H35table[A];
break;
case 0x79: // OUT (C),A
|