From 488f5b150333d89aff0d63f423e101f3eb3939a8 Mon Sep 17 00:00:00 2001 From: Rikard Nordgren Date: Wed, 9 Apr 2025 22:03:09 +0200 Subject: [PATCH] Add log_FAC1 --- STATUS.md | 2 +- src/,,config_ultimate64.s | 4 +- src/basic/,stubs_math/b9ea.log_FAC1.s | 30 --------- src/basic/{,stubs_math => math}/b9ea.interop | 0 src/basic/math/b9ea.log_FAC1.s | 64 +++++++++++++++++++ src/basic/math/poly_log.s | 15 +++++ ...20803504F334813504F334808000000080317217F8 | 1 + strings/A9E5A0B9 | 3 + strings/B9200FBBA9 | 3 + strings/B92067B8 | 3 + strings/E0A0E220 | 3 + 11 files changed, 95 insertions(+), 33 deletions(-) delete mode 100644 src/basic/,stubs_math/b9ea.log_FAC1.s rename src/basic/{,stubs_math => math}/b9ea.interop (100%) create mode 100644 src/basic/math/b9ea.log_FAC1.s create mode 100644 src/basic/math/poly_log.s create mode 100644 strings/18608100000000037F5E56CB7980139B0B6480763893168238AA3B20803504F334813504F334808000000080317217F8 create mode 100644 strings/A9E5A0B9 create mode 100644 strings/B9200FBBA9 create mode 100644 strings/B92067B8 create mode 100644 strings/E0A0E220 diff --git a/STATUS.md b/STATUS.md index eefbbbb9..0f402fd3 100644 --- a/STATUS.md +++ b/STATUS.md @@ -212,7 +212,7 @@ Floating point mathematical routines - not official, but well known and broadly | `$B86A` | `add_FAC2_FAC1` | DONE | | | `$B8FE` | `normal_FAC1` | DONE | | | `$B947` | `inv_FAC1_mantissa` | DONE | | -| `$B9EA` | `log_FAC1` | NOT DONE | | +| `$B9EA` | `log_FAC1` | PARTIAL | not fully tested yet | | `$BA28` | `mul_MEM_FAC1` | DONE | | | `$BA2B` | `mul_FAC2_FAC1` | DONE | | | `$BA8C` | `mov_MEM_FAC2` | DONE | | diff --git a/src/,,config_ultimate64.s b/src/,,config_ultimate64.s index 109788c1..e292e4b0 100644 --- a/src/,,config_ultimate64.s +++ b/src/,,config_ultimate64.s @@ -96,8 +96,8 @@ ; --- Eye candy ;; #CONFIG# COLORS_BRAND YES -;; #CONFIG# BANNER_SIMPLE NO -;; #CONFIG# BANNER_FANCY YES +;; #CONFIG# BANNER_SIMPLE YES +;; #CONFIG# BANNER_FANCY NO ;; #CONFIG# SHOW_FEATURES YES diff --git a/src/basic/,stubs_math/b9ea.log_FAC1.s b/src/basic/,stubs_math/b9ea.log_FAC1.s deleted file mode 100644 index b2c293d4..00000000 --- a/src/basic/,stubs_math/b9ea.log_FAC1.s +++ /dev/null @@ -1,30 +0,0 @@ -;; #LAYOUT# STD * #TAKE -;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000 -;; #LAYOUT# * BASIC_0 #TAKE -;; #LAYOUT# * * #IGNORE - -; -; Math package - natural logarigthm -; -; -; See also: -; - [CM64] Computes Mapping the Commodore 64 - page 113 -; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic -; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics -; - -; XXX provide implementation - -log_FAC1: - - +STUB_IMPLEMENTATION - - -poly_log: - - !byte $03 ; series length - 1 - - +PUT_CONST_POLY_LOG_1 - +PUT_CONST_POLY_LOG_2 - +PUT_CONST_POLY_LOG_3 - +PUT_CONST_POLY_LOG_4 diff --git a/src/basic/,stubs_math/b9ea.interop b/src/basic/math/b9ea.interop similarity index 100% rename from src/basic/,stubs_math/b9ea.interop rename to src/basic/math/b9ea.interop diff --git a/src/basic/math/b9ea.log_FAC1.s b/src/basic/math/b9ea.log_FAC1.s new file mode 100644 index 00000000..9f2f609d --- /dev/null +++ b/src/basic/math/b9ea.log_FAC1.s @@ -0,0 +1,64 @@ +;; #LAYOUT# STD * #TAKE +;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000 +;; #LAYOUT# * BASIC_0 #TAKE +;; #LAYOUT# * * #IGNORE + +; +; Math package - natural logarigthm of FAC1 +; +; +; See also: +; - [CM64] Computes Mapping the Commodore 64 - page 113 +; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic +; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics +; - https://www.c64-wiki.com/wiki/LOG +; +; Calculate log of FAC1 +; Algorithm: +; 1. Separate exponent and significand of FAC1. N = exponent, XF = significand +; 2. T = 1.0 - sqrt(2.0) / (XF + sqrt(0.5)) +; 3. Apply polynomial 0.43425594189 * T7 + 0.57658454124 * T5 + 0.96180075919 * T3 + 2.8853900731 * T - 0.5 giving log2(XF) +; 4. N + log2(XF) giving log2(X) +; 5. Multiply by LOG(2) giving LOG(X) + + + +log_FAC1: + lda FAC1_exponent ; Store exponent for later + pha + + ldx #$80 ; Set exponent to 0 so that FAC1 becomes XF + stx FAC1_exponent + + ldy #>const_INV_SQR_2 ; FAC1 <- FAC1 + sqrt(0.5) + lda #const_SQR_2 ; FAC1 <- sqrt(2.0) / FAC1 + lda #const_ONE ; FAC1 <- 1.0 - FAC1 + lda #poly_log ; FAC1 <- log_poly(FAC1) + lda #const_NEG_HALF ; FAC1 <- FAC1 - 0.5 + lda #const_LOG_2 ; FAC1 <- FAC1 * log(2.0) + lda #