1
0
mirror of https://github.com/TomHarte/CLK.git synced 2026-04-26 03:29:40 +00:00

Imports SBCD and NBCD tests, and fixes corresponding operation.

This commit is contained in:
Thomas Harte
2019-06-28 19:39:08 -04:00
parent c5039a4719
commit 241d29ff7c
2 changed files with 150 additions and 13 deletions
@@ -376,7 +376,9 @@ template <class T, bool dtack_is_implicit, bool signal_will_perform> void Proces
zero_result_ |= result & 0xff;
extend_flag_ = carry_flag_ = uint_fast32_t(result & ~0xff);
negative_flag_ = result & 0x80;
overflow_flag_ = add_overflow() & 0x80;
const int unadjusted_result = destination + source + (extend_flag_ ? 1 : 0);
overflow_flag_ = ~unadjusted_result & result & 0x80;
// Store the result.
active_program_->destination->halves.low.halves.low = uint8_t(result);
@@ -1507,17 +1509,18 @@ template <class T, bool dtack_is_implicit, bool signal_will_perform> void Proces
#define sbcd() \
/* Perform the BCD arithmetic by evaluating the two nibbles separately. */ \
int result = (destination & 0xf) - (source & 0xf) - (extend_flag_ ? 1 : 0); \
if(result > 0x09) result -= 0x06; \
result += (destination & 0xf0) - (source & 0xf0); \
if(result > 0x99) result -= 0x60; \
\
/* Set all flags essentially as if this were normal subtraction. */ \
zero_result_ |= result & 0xff; \
extend_flag_ = carry_flag_ = decltype(carry_flag_)(result & ~0xff); \
negative_flag_ = result & 0x80; \
overflow_flag_ = sub_overflow() & 0x80; \
\
/* Store the result. */ \
if((result & 0x1f) > 0x09) result -= 0x06; \
result += (destination & 0xf0) - (source & 0xf0); \
if((result & 0x1ff) > 0x99) result -= 0x60; \
\
/* Set all flags essentially as if this were normal subtraction. */ \
zero_result_ |= result & 0xff; \
extend_flag_ = carry_flag_ = decltype(carry_flag_)(result & ~0xff); \
negative_flag_ = result & 0x80; \
const int unadjusted_result = destination - source - (extend_flag_ ? 1 : 0); \
overflow_flag_ = unadjusted_result &~ result & 0x80; \
\
/* Store the result. */ \
active_program_->destination->halves.low.halves.low = uint8_t(result);
/*