summaryrefslogtreecommitdiff
path: root/z80_decode.c
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2021-08-24 22:11:02 +0000
committerIan C <ianc@noddybox.co.uk>2021-08-24 22:11:02 +0000
commit799e5f977ef34218e3e5c817ae5f5a571ac4c930 (patch)
tree1389178d1ce5655a08137c2bcf7bba9816edfed8 /z80_decode.c
parente584ad6f47489504bcdb8889645ab32121ae5197 (diff)
Fixed SCF, CCF and DAA so they pass documented flag tests.
Diffstat (limited to 'z80_decode.c')
-rw-r--r--z80_decode.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/z80_decode.c b/z80_decode.c
index c642783..e19f593 100644
--- a/z80_decode.c
+++ b/z80_decode.c
@@ -963,35 +963,36 @@ do { \
static void DAA (Z80 *cpu)
{
Z80Byte add=0;
- Z80Byte carry=0;
+ Z80Byte carry=cpu->AF.b.lo&C_Z80;
Z80Byte nf=cpu->AF.b.lo&N_Z80;
Z80Byte acc=cpu->AF.b.hi;
- if (acc>0x99 || IS_C)
+ if (acc > 0x99 || IS_C)
{
add|=0x60;
- carry=C_Z80;
+
+ if (acc > 0x99)
+ {
+ carry=C_Z80;
+ }
}
- if ((acc&0xf)>0x9 || IS_H)
+ if ((acc&0xf) > 0x9 || IS_H)
{
add|=0x06;
}
if (nf)
{
- cpu->AF.b.hi-=add;
+ SUB8(add);
}
else
{
- cpu->AF.b.hi+=add;
+ ADD8(add);
}
- cpu->AF.b.lo=PSZtable[cpu->AF.b.hi]
- | carry
- | nf
- | ((acc^cpu->AF.b.hi)&H_Z80)
- | (cpu->AF.b.hi&(B3_Z80|B5_Z80));
+ cpu->AF.b.lo = (cpu->AF.b.lo & ~(C_Z80|P_Z80)) | carry |
+ Ptable[cpu->AF.b.hi];
}
/* ---------------------------------------- HANDLERS FOR ED OPCODES
@@ -2053,7 +2054,7 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0x37: /* SCF */
TSTATE(4);
- cpu->AF.b.lo=(cpu->AF.b.lo&(S_Z80|Z_Z80|P_Z80))
+ cpu->AF.b.lo=(cpu->AF.b.lo&(S_Z80|Z_Z80|P_Z80))
| C_Z80
| (cpu->AF.b.hi&(B3_Z80|B5_Z80));
break;
@@ -2095,6 +2096,8 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0x3f: /* CCF */
TSTATE(4);
+ CLRFLAG(N_Z80);
+
if (CARRY)
SETFLAG(H_Z80);
else