diff --git a/STATUS.md b/STATUS.md index 4e5acc7a..28ea4e50 100644 --- a/STATUS.md +++ b/STATUS.md @@ -202,7 +202,7 @@ Floating point mathematical routines - not official, but well known and broadly | `$BA2B` | `mul_FAC2_FAC1` | PARTIAL | not testeed yet | | `$BA8C` | `mov_MEM_FAC2` | DONE | | | `$BA90` | `get_FAC2_via_INDEX` | NOT DONE | | -| `$BAE2` | `mul10_FAC1` | NOT DONE | | +| `$BAE2` | `mul10_FAC1` | PARTIAL | not tested yet | | `$BAFE` | `div10_FAC1_p` | PARTIAL | needs `div_FAC2_FAC1` | | `$BB0F` | `div_MEM_FAC1` | PARTIAL | needs `div_FAC2_FAC1` | | `$BB12` | `div_FAC2_FAC1` | NOT DONE | some work already started | diff --git a/c64/basic/,stubs_math/bae2.mul10_FAC1.s b/c64/basic/,stubs_math/bae2.mul10_FAC1.s deleted file mode 100644 index 4d6e570d..00000000 --- a/c64/basic/,stubs_math/bae2.mul10_FAC1.s +++ /dev/null @@ -1,18 +0,0 @@ -// #LAYOUT# STD * #TAKE -// #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000 -// #LAYOUT# * BASIC_0 #TAKE -// #LAYOUT# * * #IGNORE - -// -// Math package - multiply FAC1 by 10 -// -// See also: -// - [CM64] Computes Mapping the Commodore 64 - page 114 -// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic -// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics -// - -// XXX provide implementation - -mul10_FAC1: - STUB_IMPLEMENTATION() diff --git a/c64/basic/,stubs_math/bae2.interop b/c64/basic/math/bae2.interop similarity index 100% rename from c64/basic/,stubs_math/bae2.interop rename to c64/basic/math/bae2.interop diff --git a/c64/basic/math/bae2.mul10_FAC1.s b/c64/basic/math/bae2.mul10_FAC1.s new file mode 100644 index 00000000..96f21fe7 --- /dev/null +++ b/c64/basic/math/bae2.mul10_FAC1.s @@ -0,0 +1,43 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000 +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Math package - multiply FAC1 by 10 +// +// See also: +// - [CM64] Computes Mapping the Commodore 64 - page 114 +// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic +// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics +// + +// XXX test this + +mul10_FAC1: + + // Handle special case of FAC1 equal 0 + + lda FAC1_exponent + beq mul10_FAC1_done + + // Start by multiplying FAC1 by 2 + + jsr mul10_FAC1_mul2 + + // Move FAC1 to FAC2, so that FAC1 = FAC2 = 2 * initial + + jsr mov_FAC1_FAC2 + + // Multiply FAC1 by 4 + + jsr mul10_FAC1_mul2 + jsr mul10_FAC1_mul2 + + // Now we have FAC1 = 8 * initial and FAC2 = 2 * initial; so just add these 2 values + + jmp add_FAC2_FAC1 + +mul10_FAC1_done: + + rts diff --git a/c64/basic/math/mul10_FAC1_mul2.s b/c64/basic/math/mul10_FAC1_mul2.s new file mode 100644 index 00000000..c70514c8 --- /dev/null +++ b/c64/basic/math/mul10_FAC1_mul2.s @@ -0,0 +1,25 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Multiply FAC1 by 2, do not normalize +// + +mul10_FAC1_mul2: + + // First handle the mantissa + + asl FACOV + rol FAC1_mantissa+3 + rol FAC1_mantissa+2 + rol FAC1_mantissa+1 + rol FAC1_mantissa+0 + bcc !+ + + // We need to increment the exponent + + inc FAC1_exponent + bcs_16 set_FAC1_max + + rts