diff --git a/c64/basic/math/add_align_exponents.s b/c64/basic/math/add_align_exponents.s index 3956ed9c..882cb337 100644 --- a/c64/basic/math/add_align_exponents.s +++ b/c64/basic/math/add_align_exponents.s @@ -9,8 +9,6 @@ // - [CM64] Computes Mapping the Commodore 64 - page 115 // - https://www.c64-wiki.com/wiki/BASIC-ROM -// XXX finish and test this - add_align_exponents: // XXX assume here none of the exponents is 0, check if this is true for orignal ROMs diff --git a/c64/basic/math/bb12.div_FAC2_FAC1.s b/c64/basic/math/bb12.div_FAC2_FAC1.s index 328a9005..5f9cf4d5 100644 --- a/c64/basic/math/bb12.div_FAC2_FAC1.s +++ b/c64/basic/math/bb12.div_FAC2_FAC1.s @@ -66,6 +66,7 @@ div_FAC2_FAC1: // Divide the mantissas + jsr div_FAC1_denorm jsr muldiv_RESHO_set_0 // XXX @@ -74,8 +75,3 @@ div_FAC2_FAC1: STUB_IMPLEMENTATION() - - - - -// XXX use 8-bit divide from here: https://codebase64.org/doku.php?id=base:8bit_divide_8bit_product diff --git a/c64/basic/math/div_FAC1_denorm.s b/c64/basic/math/div_FAC1_denorm.s new file mode 100644 index 00000000..5c40c4a8 --- /dev/null +++ b/c64/basic/math/div_FAC1_denorm.s @@ -0,0 +1,70 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Math package - denormalize FAC1 mantissa and adapt its exponent accordingly, +// so that division is more precise +// + +// XXX test this + +div_FAC1_denorm: + + // Start by moving whole bytes, if possible + + lda FACOV + bne div_FAC1_denorm_by_bit // branch if last byte of mantissa is non-zero + + lda FAC1_exponent + cmp #$09 + bcc div_FAC1_denorm_by_bit // branch if not suitable to decrement exponent by 8 + + // Decrement exponent + + sbc #$08 // Carry already set here + sta FAC1_exponent + + // Move mantissa bytes + + lda FAC1_mantissa+3 + sta FACOV + lda FAC1_mantissa+2 + sta FAC1_mantissa+3 + lda FAC1_mantissa+1 + sta FAC1_mantissa+2 + lda FAC1_mantissa+0 + sta FAC1_mantissa+1 + lda #$00 + sta FAC1_mantissa+0 + + beq div_FAC1_denorm // branch always + +div_FAC1_denorm_by_bit: + + lda FACOV + and #$01 + bne div_FAC1_denorm_done // branch if lowest bit of mantissa is already 1 + + lda FAC1_exponent + cmp #$02 + bcc div_FAC1_denorm_done // branch if not suitable to decrement exponent + + // Decrement exponent + + dec FAC1_exponent + + // Move mantissa bits + + clc + ror FAC1_mantissa+0 + ror FAC1_mantissa+1 + ror FAC1_mantissa+2 + ror FAC1_mantissa+3 + ror FACOV + + bcc div_FAC1_denorm_done // branch always + +div_FAC1_denorm_done: + + rts