From 306f694181ec8c23db7483424bf69e0bf28ecbae Mon Sep 17 00:00:00 2001 From: Rikard Nordgren Date: Mon, 3 Feb 2025 21:08:05 +0100 Subject: [PATCH] Add poly1 and poly2 --- STATUS.md | 4 +- src/aliases/,aliases_ram_lowmem.s | 2 +- src/basic/,stubs_math/e059.poly2_FAC1.s | 28 -------- src/basic/{,stubs_math => math}/e043.interop | 0 .../{,stubs_math => math}/e043.poly1_FAC1.s | 12 ++-- src/basic/{,stubs_math => math}/e059.interop | 0 src/basic/math/e059.poly2_FAC1.s | 69 +++++++++++++++++++ strings/0001020304050607 | 1 + strings/8524A52E | 3 + 9 files changed, 84 insertions(+), 35 deletions(-) delete mode 100644 src/basic/,stubs_math/e059.poly2_FAC1.s rename src/basic/{,stubs_math => math}/e043.interop (100%) rename src/basic/{,stubs_math => math}/e043.poly1_FAC1.s (59%) rename src/basic/{,stubs_math => math}/e059.interop (100%) create mode 100644 src/basic/math/e059.poly2_FAC1.s create mode 100644 strings/0001020304050607 create mode 100644 strings/8524A52E diff --git a/STATUS.md b/STATUS.md index d0f492f4..c59e0225 100644 --- a/STATUS.md +++ b/STATUS.md @@ -248,8 +248,8 @@ Floating point mathematical routines - not official, but well known and broadly | `$BF7B` | `pwr_FAC2_FAC1` | NOT DONE | | | `$BFB4` | `toggle_sign_FAC1` | DONE | | | `$BFED` | `exp_FAC1` | NOT DONE | | -| `$E043` | `poly1_FAC1` | NOT DONE | | -| `$E059` | `poly2_FAC1` | NOT DONE | | +| `$E043` | `poly1_FAC1` | PARTIAL | not fully tested yet | +| `$E059` | `poly2_FAC1` | PARTIAL | not fully tested yet | | `$E097` | `rnd_FAC1` | DONE | | | `$E09A` | `rnd_A` | DONE | | | `$E0BE` | `rnd_generate` | DONE | | diff --git a/src/aliases/,aliases_ram_lowmem.s b/src/aliases/,aliases_ram_lowmem.s index 2c6e08db..cc1b4ce7 100644 --- a/src/aliases/,aliases_ram_lowmem.s +++ b/src/aliases/,aliases_ram_lowmem.s @@ -63,7 +63,7 @@ !addr FAC1_mantissa = $62 ; $62 - $65 !addr FAC1_sign = $66 - !addr SGNFLG = $67 ; -- NOT IMPLEMENTED -- + !addr SGNFLG = $67 ; Also used as number of terms of series evaluation !addr BITS = $68 ; FAC1 overflow !addr __FAC2 = $69 ; $69-$6E floating point accumulator 2 [!] also used for memory move pointers diff --git a/src/basic/,stubs_math/e059.poly2_FAC1.s b/src/basic/,stubs_math/e059.poly2_FAC1.s deleted file mode 100644 index f7148ef3..00000000 --- a/src/basic/,stubs_math/e059.poly2_FAC1.s +++ /dev/null @@ -1,28 +0,0 @@ -;; #LAYOUT# STD * #TAKE -;; #LAYOUT# * BASIC_0 #TAKE -;; #LAYOUT# * * #IGNORE - -; -; Math package - evaluate polynomial with odd and even powers for FAC1 value -; -; Input: -; - .A - table address low byte -; - .Y - table address low byte -; - table format: -; - polynomial degree (8 bit integer) -; - oefficients (floats), starting from highest degree, times 1+degree -; -; Notes: -; - uses Horner method -; -; See also: -; - [CM64] Computes Mapping the Commodore 64 - page 207 -; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic -; - https://www.c64-wiki.com/wiki/POLY1 -; - -; XXX provide implementation - -poly2_FAC1: - - +STUB_IMPLEMENTATION diff --git a/src/basic/,stubs_math/e043.interop b/src/basic/math/e043.interop similarity index 100% rename from src/basic/,stubs_math/e043.interop rename to src/basic/math/e043.interop diff --git a/src/basic/,stubs_math/e043.poly1_FAC1.s b/src/basic/math/e043.poly1_FAC1.s similarity index 59% rename from src/basic/,stubs_math/e043.poly1_FAC1.s rename to src/basic/math/e043.poly1_FAC1.s index c4ca783b..6272cbd0 100644 --- a/src/basic/,stubs_math/e043.poly1_FAC1.s +++ b/src/basic/math/e043.poly1_FAC1.s @@ -19,10 +19,14 @@ ; - [CM64] Computes Mapping the Commodore 64 - page 206 ; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic ; - https://www.c64-wiki.com/wiki/POLY1 -; -; XXX provide implementation poly1_FAC1: - - +STUB_IMPLEMENTATION + jsr store_YA_in_ZP ; Store YA in second INDEX pointer + jsr mov_r_FAC1_TMP1 ; TMPF1 <- FAC1 (rounds) + jsr mov_FAC1_FAC2 ; FAC2 <- FAC1 + jsr mul_FAC2_FAC1 ; FAC1 <- FAC1 * FAC2 (x^2) + jsr poly2_table_in_index2 ; poly2: skip storing YA to ZP + ldy #$00 ; FAC1 <- FAC1 * TEMPF1 + lda #TEMPF1 + jmp mul_MEM_FAC1 diff --git a/src/basic/,stubs_math/e059.interop b/src/basic/math/e059.interop similarity index 100% rename from src/basic/,stubs_math/e059.interop rename to src/basic/math/e059.interop diff --git a/src/basic/math/e059.poly2_FAC1.s b/src/basic/math/e059.poly2_FAC1.s new file mode 100644 index 00000000..56b40bf9 --- /dev/null +++ b/src/basic/math/e059.poly2_FAC1.s @@ -0,0 +1,69 @@ +;; #LAYOUT# STD * #TAKE +;; #LAYOUT# * BASIC_0 #TAKE +;; #LAYOUT# * * #IGNORE + +; +; Math package - evaluate polynomial with odd and even powers for FAC1 value +; +; Input: +; - .A - table address low byte +; - .Y - table address low byte +; - FAC1 - value of the independent variable +; Outputs: FAC1 holds the calculated value +; Clobbers: X, Y, A, FAC2, TEMPF2 +; +; The polynomial table is formatted as: +; First one byte represents the degree of the polynomial +; Then comes an array of floating point number coefficients starting with the highest degree +; Horner's method is used for the calculation. + +; See also: +; - [CM64] Computes Mapping the Commodore 64 - page 207 +; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic +; - https://www.c64-wiki.com/wiki/POLY1 +; + + +poly2_FAC1: + jsr store_YA_in_ZP + +poly2_table_in_index2: ; Called from poly1 + ldy #$00 ; FAC1 -> TMPF2 + ldx #TEMPF2 + jsr mov_FAC1_MEM + + ldx #$80 ; 0 -> FAC1 + stx FAC1_exponent + + ldx #0 + lda (INDEX+2, x) ; degree (degree+1 = num coeffs) + sta SGNFLG ; number of terms register + inc INDEX+2 + bcc @1 + inc INDEX+3 + +@1: + lda INDEX+2 + ldy INDEX+3 + jsr add_MEM_FAC1 ; Add with coefficient + ldy #$00 + lda #TEMPF2 + jsr mul_MEM_FAC1 ; Multiply with x + + clc ; Add 5 to table pointer + lda #$05 + adc INDEX+2 + sta INDEX+2 + bcc @2 + inc INDEX+3 + +@2: + dec SGNFLG + bpl @1 + rts + + +store_YA_in_ZP: ; Used also by poly1 + sty INDEX+3 ; Store YA in second INDEX pointer + sta INDEX+2 + rts diff --git a/strings/0001020304050607 b/strings/0001020304050607 new file mode 100644 index 00000000..31ce54df --- /dev/null +++ b/strings/0001020304050607 @@ -0,0 +1 @@ +8 consecutive integers starting from 0. Non-copyrightable diff --git a/strings/8524A52E b/strings/8524A52E new file mode 100644 index 00000000..a6667b1d --- /dev/null +++ b/strings/8524A52E @@ -0,0 +1,3 @@ +STA $24 + LDA $2E $24 = INDEX + 2 and $2E VARTAB+1 + +storing and loading from two well known locations in the zero page. Trivial