summaryrefslogtreecommitdiff
path: root/src/Noddybox.Emulation.EightBit.Z80/Z80CpuBaseOpcodes.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Noddybox.Emulation.EightBit.Z80/Z80CpuBaseOpcodes.cs')
-rw-r--r--src/Noddybox.Emulation.EightBit.Z80/Z80CpuBaseOpcodes.cs84
1 files changed, 56 insertions, 28 deletions
diff --git a/src/Noddybox.Emulation.EightBit.Z80/Z80CpuBaseOpcodes.cs b/src/Noddybox.Emulation.EightBit.Z80/Z80CpuBaseOpcodes.cs
index eed7258..02824b9 100644
--- a/src/Noddybox.Emulation.EightBit.Z80/Z80CpuBaseOpcodes.cs
+++ b/src/Noddybox.Emulation.EightBit.Z80/Z80CpuBaseOpcodes.cs
@@ -817,17 +817,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>
@@ -921,30 +925,26 @@ namespace Noddybox.Emulation.EightBit.Z80
/// </summary>
private void INI()
{
- int w;
+ byte w;
byte b = device.Read(BC.reg);
memory.Write(HL.reg, b);
BC.high--;
HL.reg++;
- F = SZtable[BC.high] | H35table[BC.high];
+ w = (byte)(BC.low + b + 1);
- w = BC.low + b;
+ F = SZtable[BC.high] | H35table[BC.high] | Ptable[(w & 0x07) ^ BC.high];
- if ((w & 0x80) == 0x80)
+ if ((b & 0x80) == 0x80)
{
SetFlag(Z80Flags.Neg);
}
- if ((w & 0x100) == 0x100)
+ if (w < b)
{
SetFlag(Z80Flags.Carry | Z80Flags.HalfCarry);
}
- else
- {
- ClearFlag(Z80Flags.Carry | Z80Flags.HalfCarry);
- }
}
/// <summary>
@@ -952,30 +952,26 @@ namespace Noddybox.Emulation.EightBit.Z80
/// </summary>
private void IND()
{
- int w;
+ byte w;
byte b = device.Read(BC.reg);
memory.Write(HL.reg, b);
BC.high--;
HL.reg--;
- F = SZtable[BC.high] | H35table[BC.high];
+ w = (byte)(BC.low + b - 1);
- w = BC.low + b;
+ F = SZtable[BC.high] | H35table[BC.high] | Ptable[(w & 0x07) ^ BC.high];
- if ((w & 0x80) == 0x80)
+ if ((b & 0x80) == 0x80)
{
SetFlag(Z80Flags.Neg);
}
- if ((w & 0x100) == 0x100)
+ if (w < b)
{
SetFlag(Z80Flags.Carry | Z80Flags.HalfCarry);
}
- else
- {
- ClearFlag(Z80Flags.Carry | Z80Flags.HalfCarry);
- }
}
/// <summary>
@@ -983,12 +979,28 @@ namespace Noddybox.Emulation.EightBit.Z80
/// </summary>
private void OUTI()
{
- device.Write(BC.reg, memory.Read(HL.reg));
+ BC.high--;
+
+ byte b = memory.Read(HL.reg);
+ byte w = b;
+
+ device.Write(BC.reg, b);
HL.reg++;
- BC.high--;
- F = SZtable[BC.high] | H35table[BC.high];
+ w += HL.low;
+
+ F = SZtable[BC.high] | H35table[BC.high] | Ptable[(w & 0x07) ^ BC.high];
+
+ if ((b & 0x80) == 0x80)
+ {
+ SetFlag(Z80Flags.Neg);
+ }
+
+ if (w < b)
+ {
+ SetFlag(Z80Flags.Carry | Z80Flags.HalfCarry);
+ }
}
/// <summary>
@@ -996,12 +1008,28 @@ namespace Noddybox.Emulation.EightBit.Z80
/// </summary>
private void OUTD()
{
- device.Write(BC.reg, memory.Read(HL.reg));
+ BC.high--;
+
+ byte b = memory.Read(HL.reg);
+ byte w = b;
+
+ device.Write(BC.reg, b);
HL.reg--;
- BC.high--;
- F = SZtable[BC.high] | H35table[BC.high] | Z80Flags.Neg;
+ w += HL.low;
+
+ F = SZtable[BC.high] | H35table[BC.high] | Ptable[(w & 0x07) ^ BC.high];
+
+ if ((b & 0x80) == 0x80)
+ {
+ SetFlag(Z80Flags.Neg);
+ }
+
+ if (w < b)
+ {
+ SetFlag(Z80Flags.Carry | Z80Flags.HalfCarry);
+ }
}
#endregion