From 5127e416437586ea9ec030db73e9cc5859595b85 Mon Sep 17 00:00:00 2001 From: Rikard Nordgren Date: Tue, 14 Apr 2026 21:00:25 +0200 Subject: [PATCH] Update poly2_FAC1 --- STATUS.md | 2 +- src/basic/math_trans/e059.poly2_FAC1.s | 80 ++++++++++++-------------- tools/similarity.c | 2 +- 3 files changed, 40 insertions(+), 44 deletions(-) diff --git a/STATUS.md b/STATUS.md index 22f7a032..08650c8b 100644 --- a/STATUS.md +++ b/STATUS.md @@ -258,7 +258,7 @@ Floating point mathematical routines - not official, but well known and broadly | `$BFB4` | `toggle_sign_FAC1` | DONE | From the Microsoft BASIC, original name: NEGOP | | `$BFED` | `exp_FAC1` | NOT DONE | | | `$E043` | `poly1_FAC1` | DONE | From the Microsoft BASIC, original name: POLYX | -| `$E059` | `poly2_FAC1` | PARTIAL | not fully tested yet | +| `$E059` | `poly2_FAC1` | DONE | From the Microsoft BASIC, original name: POLY | | `$E097` | `rnd_FAC1` | DONE | | | `$E09A` | `rnd_A` | DONE | | | `$E0BE` | `rnd_generate` | DONE | | diff --git a/src/basic/math_trans/e059.poly2_FAC1.s b/src/basic/math_trans/e059.poly2_FAC1.s index 64617c7b..3755ee5f 100644 --- a/src/basic/math_trans/e059.poly2_FAC1.s +++ b/src/basic/math_trans/e059.poly2_FAC1.s @@ -2,9 +2,13 @@ ;; #LAYOUT# * BASIC_0 #TAKE ;; #LAYOUT# * * #IGNORE -; +; This file is under the MIT license, it contains code released by Microsoft Corporation. +; See LICENSE for more information. + ; Math package - evaluate polynomial with odd and even powers for FAC1 value ; +; This is verified to be identical to the original Microsoft implementation where it was named POLY. +; ; Input: ; - .A - table address low byte ; - .Y - table address low byte @@ -28,48 +32,40 @@ poly2_FAC1: - jsr store_YA_in_ZP + sta POLYPT + sty POLYPT+1 + +POLY1: + jsr mov_r_FAC1_TMP2 ; Save FAC1 + lda (POLYPT),Y + sta DEGREE + ldy POLYPT + iny + tya + bne POLY3 + inc POLYPT+1 +POLY3: + sta POLYPT + ldy POLYPT+1 +POLY2: + jsr mul_MEM_FAC1 + lda POLYPT ; Get current pointer + ldy POLYPT+1 + clc + adc #5 + bcc POLY4 + iny +POLY4: + sta POLYPT + sty POLYPT+1 + jsr add_MEM_FAC1 ; Add in constant + lda #TEMPF2 + dec DEGREE ; Done? + bne POLY2 +RANDRT: + rts ; Yes -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 } else { diff --git a/tools/similarity.c b/tools/similarity.c index 81f586c5..77821498 100644 --- a/tools/similarity.c +++ b/tools/similarity.c @@ -32,7 +32,7 @@ unsigned short microsoft_basic_chunks[NUM_CHUNKS * 2] = { 0xBDB3, 0xBDC1, 0xBDDD, 0xBF51, 0xBFB4, 0xBFEC, - 0xE043, 0xE058, + 0xE043, 0xE08C, 0xE264, 0xE2C2, // Two byte gap here is an optimization 0xE2C5, 0xE37A, };