1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-25 16:31:42 +00:00

Bring fully into 8086 conformance.

This commit is contained in:
Thomas Harte 2023-11-08 22:16:12 -05:00
parent 502b9d2023
commit 38933aa079

View File

@ -133,42 +133,19 @@ void daa(
uint8_t &al,
ContextT &context
) {
/*
(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 old_CF OR CarryFromLastAddition; (* CF OR carry from AL AL + 6 *)
AF 1;
ELSE
AF 0;
FI;
IF ((old_AL > 99H) or old_CF = 1)
THEN
AL AL + 60H;
CF 1;
ELSE
CF 0;
FI;
*/
/*
The CF and AF flags are set if the adjustment of the value results in a
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;
bool top_exceeded_threshold;
if constexpr (ContextT::model == Model::i8086) {
top_exceeded_threshold = al > (context.flags.template flag<Flag::AuxiliaryCarry>() ? 0x9f : 0x99);
} else {
top_exceeded_threshold = al > 0x99;
}
if((al & 0x0f) > 0x09 || context.flags.template flag<Flag::AuxiliaryCarry>()) {
al += 0x06;
context.flags.template set_from<Flag::AuxiliaryCarry>(1);
}
if(old_al > 0x99 || context.flags.template flag<Flag::Carry>()) {
if(top_exceeded_threshold || context.flags.template flag<Flag::Carry>()) {
al += 0x60;
context.flags.template set_from<Flag::Carry>(1);
}