1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-25 18:30:07 +00:00

Improve DAA.

This commit is contained in:
Thomas Harte 2023-10-09 14:42:32 -04:00
parent 1b9e6e8c8e
commit 0bf2099a70

View File

@ -294,15 +294,21 @@ inline void aas(CPU::RegisterPair16 &ax, Status &status) {
inline void daa(uint8_t &al, Status &status) {
/*
(as modified by https://www.felixcloutier.com/x86/daa ...)
old_AL AL;
old_CF CF;
CF 0;
IF (((AL AND 0FH) > 9) or AF = 1)
THEN
AL AL + 6;
CF CF OR CarryFromLastAddition; (* CF OR carry from AL AL + 6 *)
CF old_CF OR CarryFromLastAddition; (* CF OR carry from AL AL + 6 *)
AF 1;
ELSE
AF 0;
FI;
IF ((AL AND F0H) > 90H) or CF = 1)
IF ((old_AL > 99H) or old_CF = 1)
THEN
AL AL + 60H;
CF 1;
@ -315,15 +321,19 @@ inline void daa(uint8_t &al, Status &status) {
decimal carry in either digit of the result (see the Operation section above).
The SF, ZF, and PF flags are set according to the result. The OF flag is undefined.
*/
const uint8_t old_al = al;
const auto old_carry = status.carry;
status.carry = 0;
if((al & 0x0f) > 0x09 || status.auxiliary_carry) {
status.carry |= al > 0xf9;
status.carry = old_carry | (al > 0xf9);
al += 0x06;
status.auxiliary_carry = 1;
} else {
status.auxiliary_carry = 0;
}
if((al & 0xf0) > 0x90 || status.carry) {
if(old_al > 0x99 || old_carry) {
al += 0x60;
status.carry = 1;
} else {