diff options
| -rw-r--r-- | z80_decode.c | 27 | 
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 | 
