From 33355766b4689549ac60ee211017ffc66fa3dc2a Mon Sep 17 00:00:00 2001 From: Rikard Nordgren Date: Tue, 14 Apr 2026 20:57:05 +0200 Subject: [PATCH] Update poly1_FAC1 --- STATUS.md | 2 +- src/aliases/,aliases_ram_lowmem.s | 4 +++- src/basic/math_trans/e043.poly1_FAC1.s | 23 ++++++++++++++--------- tools/similarity.c | 3 ++- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/STATUS.md b/STATUS.md index e9093411..22f7a032 100644 --- a/STATUS.md +++ b/STATUS.md @@ -257,7 +257,7 @@ Floating point mathematical routines - not official, but well known and broadly | `$BF7B` | `pwr_FAC2_FAC1` | NOT DONE | | | `$BFB4` | `toggle_sign_FAC1` | DONE | From the Microsoft BASIC, original name: NEGOP | | `$BFED` | `exp_FAC1` | NOT DONE | | -| `$E043` | `poly1_FAC1` | PARTIAL | not fully tested yet | +| `$E043` | `poly1_FAC1` | DONE | From the Microsoft BASIC, original name: POLYX | | `$E059` | `poly2_FAC1` | PARTIAL | not fully tested yet | | `$E097` | `rnd_FAC1` | DONE | | | `$E09A` | `rnd_A` | DONE | | diff --git a/src/aliases/,aliases_ram_lowmem.s b/src/aliases/,aliases_ram_lowmem.s index d221f916..c1a01b9e 100644 --- a/src/aliases/,aliases_ram_lowmem.s +++ b/src/aliases/,aliases_ram_lowmem.s @@ -69,6 +69,7 @@ !addr FAC1_sign = $66 !addr SGNFLG = $67 ; Also used as number of terms of series evaluation + !addr DEGREE = SGNFLG !addr BITS = $68 ; FAC1 overflow !addr __FAC2 = $69 ; $69-$6E floating point accumulator 2 [!] also used for memory move pointers @@ -78,7 +79,8 @@ !addr ARISGN = $6F ; -- NOT IMPLEMENTED -- !addr FACOV = $70 ; FAC1 low order mantissa - !addr FBUFPT = $71 ; $71-$72 -- NOT IMPLEMENTED -- + !addr FBUFPT = $71 ; $71-$72 + !addr POLYPT = FBUFPT !addr CHRGET = $73 ; $73-$8A copied from $E3A2 during cold start !addr CHRGOT = $79 ; same area as CHRGET !addr TXTPTR = $7A ; $7A-$7B current BASIC statement pointer diff --git a/src/basic/math_trans/e043.poly1_FAC1.s b/src/basic/math_trans/e043.poly1_FAC1.s index 970c277e..f02422f3 100644 --- a/src/basic/math_trans/e043.poly1_FAC1.s +++ b/src/basic/math_trans/e043.poly1_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 powers only for FAC1 value ; +; This is verified to be identical to the original Microsoft implementation where it was named POLYX. +; ; Input: ; - .A - table address low byte ; - .Y - table address low byte @@ -25,14 +29,15 @@ poly1_FAC1: - 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 + sta POLYPT ; Retain polynomial pointer for later + sty POLYPT+1 + jsr mov_r_FAC1_TMP1 ; Save FAC1 in TMP1 + lda #TEMPF1 + jsr mul_MEM_FAC1 ; Compute x^2 + jsr POLY1 ; Compute P(x^2) + lda #TEMPF1 + jmp mul_MEM_FAC1 ; Multiply by FAC1 again } else { diff --git a/tools/similarity.c b/tools/similarity.c index d0f9acf9..81f586c5 100644 --- a/tools/similarity.c +++ b/tools/similarity.c @@ -20,7 +20,7 @@ int matches[MAX_SIZE]; int phase_mask[MAX_SIZE+MAX_SIZE]; -#define NUM_CHUNKS 11 +#define NUM_CHUNKS 12 // Pairs of start, end memory addresses of known exact similarity with the open source Microsoft BASIC unsigned short microsoft_basic_chunks[NUM_CHUNKS * 2] = { 0xB391, 0xB39D, @@ -32,6 +32,7 @@ unsigned short microsoft_basic_chunks[NUM_CHUNKS * 2] = { 0xBDB3, 0xBDC1, 0xBDDD, 0xBF51, 0xBFB4, 0xBFEC, + 0xE043, 0xE058, 0xE264, 0xE2C2, // Two byte gap here is an optimization 0xE2C5, 0xE37A, };