Merge pull request #78 from rikardn/POLY

Add poly1 and poly2
This commit is contained in:
FeralChild64 authored and GitHub committed 2025-02-05 21:53:05 +01:00
commit 98bb75bd60
9 files changed
+84 -35

No files matched your search

-28
View File
@@ -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
File renamed without changes.
@@ -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
File renamed without changes.
+69
View File
@@ -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