'DAA implementation according to the (well tested) MAME Z80 cpu core. rdbyte data_8, a_reg mov nibble, data_8 mov data_16, data_8 'Save for auxiliary flag test and nibble, #15 'Isolate low nibble of accumulator test flags, #%00000010 wz 'Test negative flag ' if_nz jmp :das 'N flag is set if_nz add lmm_pc, #(7*4) 'N flag is set (LMM JMP :das) :daa 'N flag is clear test flags, #aux_bit wz if_nz cmp nibble, #$09 wc 'aux isn't set; is nibble > $9 ? if_ae add data_8, #$06 'aux was set or nibble is > $9 => add $6 test flags, #carry_bit wz if_nz cmp data_8, #$99 wc 'carry isn't set; is data > $99 ? if_ae add data_8, #$60 'carry was set or data is > $99 => add $66 ' jmp :flags 'Do the flags add lmm_pc, #(6*4) 'Do the flags (LMM JMP :fags) :das test flags, #aux_bit wz if_nz cmp nibble, #$09 wc 'aux isn't set; is nibble > $9 ? if_ae sub data_8, #$06 'aux was set or nibble is > $9 => subtract $6 test flags, #carry_bit wz if_nz cmp data_8, #$99 wc 'carry isn't set; is data > $99 ? if_ae sub data_8, #$60 'carry was set or data is > $99 => subtract $66 :flags and flags, #%00000011 'Preserve old CF and NF cmp data_8, #$99 wc muxnc flags, #carry_bit 'Set carry if result > 99 xor data_16, data_8 and data_16, #aux_bit 'If bit #4 of result changed or flags, data_16 'Set the aux flag and data_8, #$FF wz, wc muxz flags, #zero_bit 'Set Z80 zero flag from Props zero muxnc flags, #parity_bit test data_8, #$80 wz muxnz flags, #sign_bit wrbyte data_8, a_reg jmp #fetch