summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Noddybox.Emulation.EightBit.Z80/Z80CpuBaseOpcodes.cs84
-rw-r--r--src/Noddybox.Emulation.EightBit.Z80/Z80CpuDecodeByte.cs6
-rw-r--r--src/Noddybox.Emulation.EightBit.Z80/Z80CpuDecodeED.cs8
3 files changed, 63 insertions, 35 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
diff --git a/src/Noddybox.Emulation.EightBit.Z80/Z80CpuDecodeByte.cs b/src/Noddybox.Emulation.EightBit.Z80/Z80CpuDecodeByte.cs
index 63ccc15..fe38625 100644
--- a/src/Noddybox.Emulation.EightBit.Z80/Z80CpuDecodeByte.cs
+++ b/src/Noddybox.Emulation.EightBit.Z80/Z80CpuDecodeByte.cs
@@ -1110,7 +1110,7 @@ namespace Noddybox.Emulation.EightBit.Z80
break;
case 0xc7: // RST 0
- RST(0);
+ RST(0x00);
break;
case 0xc8: // RET Z
@@ -1164,7 +1164,7 @@ namespace Noddybox.Emulation.EightBit.Z80
break;
case 0xcf: // RST 8
- RST(8);
+ RST(0x08);
break;
case 0xd0: // RET NC
@@ -1396,7 +1396,7 @@ namespace Noddybox.Emulation.EightBit.Z80
break;
case 0xff: // RST 38
- RST(0x18);
+ RST(0x38);
break;
default:
diff --git a/src/Noddybox.Emulation.EightBit.Z80/Z80CpuDecodeED.cs b/src/Noddybox.Emulation.EightBit.Z80/Z80CpuDecodeED.cs
index 7ad170c..6efba57 100644
--- a/src/Noddybox.Emulation.EightBit.Z80/Z80CpuDecodeED.cs
+++ b/src/Noddybox.Emulation.EightBit.Z80/Z80CpuDecodeED.cs
@@ -484,7 +484,7 @@ namespace Noddybox.Emulation.EightBit.Z80
case 0xb2: // INIR
clock.Add(16);
INI();
- if (BC.reg > 0)
+ if (BC.high > 0)
{
clock.Add(5);
PC -= 2;
@@ -494,7 +494,7 @@ namespace Noddybox.Emulation.EightBit.Z80
case 0xb3: // OTIR
clock.Add(16);
OUTI();
- if (BC.reg > 0)
+ if (BC.high > 0)
{
clock.Add(5);
PC -= 2;
@@ -524,7 +524,7 @@ namespace Noddybox.Emulation.EightBit.Z80
case 0xba: // INDR
clock.Add(16);
IND();
- if (BC.reg > 0)
+ if (BC.high > 0)
{
clock.Add(5);
PC -= 2;
@@ -534,7 +534,7 @@ namespace Noddybox.Emulation.EightBit.Z80
case 0xbb: // OTDR
clock.Add(16);
OUTD();
- if (BC.reg > 0)
+ if (BC.high > 0)
{
clock.Add(5);
PC -= 2;