From 3261fd65167abc52aefa288ac71a1dc14b82ad16 Mon Sep 17 00:00:00 2001 From: Ian C Date: Tue, 5 Sep 2006 00:00:30 +0000 Subject: Passes all normal tests expect for daa,cpl,scf,ccf group. Fails quite a few undocumented flag tests. --- z80_decode.c | 42 ++++++++++++++++++++++++------------------ 1 file 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 - 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; -- cgit v1.2.3