summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2021-08-24 22:16:13 +0000
committerIan C <ianc@noddybox.co.uk>2021-08-24 22:16:13 +0000
commitdf01ff2a4604dee74cfa71f9770adb7be0f29815 (patch)
treead681f87c7ce7a9c76a517be21fd276d90c6c590
parent8c16b55565a8a80defea7df192c23acf9ad89537 (diff)
Updated Z80 decode with latest version.
-rw-r--r--source/z80_decode.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/source/z80_decode.c b/source/z80_decode.c
index f5c7352..da2fee0 100644
--- a/source/z80_decode.c
+++ b/source/z80_decode.c
@@ -19,7 +19,7 @@
-------------------------------------------------------------------------
- $Id: z80_decode.c 4 2006-10-04 23:05:43Z ianc $
+ $Id: z80_decode.c 48 2021-08-24 22:11:02Z ianc $
*/
#include <stdlib.h>
@@ -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