From 6d1c25245c7d10df82548055bbec2f2612cdb619 Mon Sep 17 00:00:00 2001 From: Ian C Date: Tue, 3 Apr 2012 22:50:43 +0000 Subject: Some more emulation fixes. --- .../Z80CpuBaseOpcodes.cs | 62 ++++++++++++++++++---- .../Z80CpuDecodeED.cs | 2 + 2 files changed, 54 insertions(+), 10 deletions(-) (limited to 'src') 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); } /// @@ -831,11 +835,18 @@ namespace Noddybox.Emulation.EightBit.Z80 /// 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); } /// @@ -855,11 +878,18 @@ namespace Noddybox.Emulation.EightBit.Z80 /// 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); } /// 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 -- cgit v1.2.3