summaryrefslogtreecommitdiff
path: root/z80_decode.c
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2006-09-05 00:00:30 +0000
committerIan C <ianc@noddybox.co.uk>2006-09-05 00:00:30 +0000
commit3261fd65167abc52aefa288ac71a1dc14b82ad16 (patch)
treeabf0f272f2058ca6e3b4ce53ddf29a89cd9dfe1e /z80_decode.c
parentffc9461219052c7ccbb4f96f35dfdc2f0c4c6808 (diff)
Passes all normal tests expect for daa,cpl,scf,ccf group.
Fails quite a few undocumented flag tests.
Diffstat (limited to 'z80_decode.c')
-rw-r--r--z80_decode.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/z80_decode.c b/z80_decode.c
index 74a8c1f..c94f092 100644
--- a/z80_decode.c
+++ b/z80_decode.c
@@ -4,9 +4,6 @@
Copyright (C) 2006 Ian Cowburn <ianc@noddybox.co.uk>
- Some of the opcode routines are based on the Z80 emulation from FUSE,
- Copyright (c) 1999-2003 Philip Kendall
-
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
@@ -948,34 +945,43 @@ do { \
/* ---------------------------------------- DAA
*/
-/* This code based on the DAA opcode from FUSE, (c) Philip Kendall
+/* This alogrithm is based on info from
+ http://www.worldofspectrum.org/faq/reference/z80reference.htm
*/
static void DAA (Z80 *cpu)
{
Z80Byte add=0;
- Z80Byte carry=CARRY;
-
- if ((IS_H) || ((cpu->AF.b[HI] & 0x0f)>9)) add=6;
+ Z80Byte carry=0;
+ Z80Byte nf=cpu->AF.b[LO]&N_Z80;
+ Z80Byte acc=cpu->AF.b[HI];
- if (carry || (cpu->AF.b[HI] > 0x9f)) add|=0x60;
+ if (acc>0x99 || IS_C)
+ {
+ add|=0x60;
+ carry=C_Z80;
+ }
- if (cpu->AF.b[HI] > 0x99 ) carry=1;
+ if ((acc&0xf)>0x9 || IS_H)
+ {
+ add|=0x06;
+ }
- if (IS_N)
+ if (nf)
{
- SUB8(add);
+ cpu->AF.b[HI]-=add;
}
else
{
- if ((cpu->AF.b[HI]>0x90) && ((cpu->AF.b[HI] & 0x0f)>9)) add|=0x60;
- ADD8(add);
+ cpu->AF.b[HI]+=add;
}
- cpu->AF.b[LO] = (cpu->AF.b[LO] & ~(C_Z80|P_Z80))
- | carry | Ptable[cpu->AF.b[HI]];
+ 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));
}
-
/* ---------------------------------------- HANDLERS FOR ED OPCODES
*/
static void DecodeED(Z80 *cpu, Z80Byte opcode)
@@ -1534,7 +1540,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0xb1: /* CPIR */
TSTATE(16);
CPI;
- if (cpu->BC.w)
+ if (cpu->BC.w && !IS_Z)
{
TSTATE(5);
cpu->PC-=2;
@@ -1574,7 +1580,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0xb9: /* CPDR */
TSTATE(16);
CPD;
- if (cpu->BC.w)
+ if (cpu->BC.w && !IS_Z)
{
TSTATE(5);
cpu->PC-=2;