diff --git a/InstructionSets/x86/Implementation/BCD.hpp b/InstructionSets/x86/Implementation/BCD.hpp index f939edd84..d28bb8c2b 100644 --- a/InstructionSets/x86/Implementation/BCD.hpp +++ b/InstructionSets/x86/Implementation/BCD.hpp @@ -104,18 +104,27 @@ void daas( ContextT &context ) { bool top_exceeded_threshold; - if constexpr (ContextT::model == Model::i8086) { + constexpr bool is_8086 = ContextT::model == Model::i8086; + if constexpr (is_8086) { top_exceeded_threshold = al > (context.flags.template flag() ? 0x9f : 0x99); } else { top_exceeded_threshold = al > 0x99; } + const auto initial_cf = context.flags.template flag(); if((al & 0x0f) > 0x09 || context.flags.template flag()) { - if constexpr (add) al += 0x06; else al -= 0x06; + const auto prior_al = al; + if constexpr (add) { + al += 0x06; + if(!is_8086 && al < prior_al) context.flags.template set_from(1); + } else { + al -= 0x06; + if(!is_8086 && al > prior_al) context.flags.template set_from(1); + } context.flags.template set_from(1); } - if(top_exceeded_threshold || context.flags.template flag()) { + if(top_exceeded_threshold || initial_cf) { if constexpr (add) al += 0x60; else al -= 0x60; context.flags.template set_from(1); } diff --git a/OSBindings/Mac/Clock SignalTests/8088Tests.mm b/OSBindings/Mac/Clock SignalTests/8088Tests.mm index b23695c05..2beeb73a3 100644 --- a/OSBindings/Mac/Clock SignalTests/8088Tests.mm +++ b/OSBindings/Mac/Clock SignalTests/8088Tests.mm @@ -38,7 +38,6 @@ NSSet *const allowList = [NSSet setWithArray:@[ // @"F7.7.json.gz", // IDIV word // @"00.json.gz", -// @"2F.json.gz", // DAS // @"61.json.gz", // POPA // @"69.json.gz", // IMUL // @"81.0.json.gz", // ADD @@ -386,7 +385,7 @@ void apply_execution_test( NSDictionary *metadata ) { // NSLog(@"%@", test[@"hash"]); - if([test[@"hash"] isEqualToString:@"3744dfa0a1386ef97ddd25c67bad150ba05beb3b"]) { + if([test[@"hash"] isEqualToString:@"453ef52b02539ada0b78a7bdc319c4d7d06fc0a2"]) { printf(""); }