From dbc603322e5a010293a799adb2a6842eab779e0d Mon Sep 17 00:00:00 2001 From: Rikard Nordgren Date: Thu, 29 Jan 2026 20:19:36 +0100 Subject: [PATCH] Update inv_FAC1 --- STATUS.md | 2 +- src/basic/math/b947.inv_FAC1.s | 44 +++++++++++++++++++++++++ src/basic/math/b947.inv_FAC1_mantissa.s | 36 -------------------- tools/similarity.c | 2 +- 4 files changed, 46 insertions(+), 38 deletions(-) create mode 100644 src/basic/math/b947.inv_FAC1.s delete mode 100644 src/basic/math/b947.inv_FAC1_mantissa.s diff --git a/STATUS.md b/STATUS.md index ff2a3d89..0e484ed3 100644 --- a/STATUS.md +++ b/STATUS.md @@ -211,7 +211,7 @@ Floating point mathematical routines - not official, but well known and broadly | `$B867` | `add_MEM_FAC1` | DONE | | | `$B86A` | `add_FAC2_FAC1` | DONE | | | `$B8FE` | `normal_FAC1` | DONE | | -| `$B947` | `inv_FAC1_mantissa` | DONE | | +| `$B947` | `inv_FAC1_mantissa` | DONE | From the Microsoft BASIC, original name: NEGFAC | | `$B96F` | `inc_FAC1` | DONE | From the Microsoft BASIC, original name: INCFAC | | `$B9EA` | `log_FAC1` | PARTIAL | not fully tested yet | | `$BA28` | `mul_MEM_FAC1` | DONE | | diff --git a/src/basic/math/b947.inv_FAC1.s b/src/basic/math/b947.inv_FAC1.s new file mode 100644 index 00000000..828a1382 --- /dev/null +++ b/src/basic/math/b947.inv_FAC1.s @@ -0,0 +1,44 @@ +;; #LAYOUT# STD * #TAKE +;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000 +;; #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 - neg (2s complement) FAC1 +; +; This is verified to be identical to the original Microsoft implementation where it was named NEGFAC. +; +; The alternative entry point neg_FAC1_mantissa (NEGFCH) will negate only the mantissa +; +; See also: +; - https://www.c64-wiki.com/wiki/BASIC-ROM +; - https://sta.c64.org/cbm64basconv.html +; + +neg_FAC1: + lda FAC1_sign + eor #$FF + sta FAC1_sign + +neg_FAC1_mantissa: + + lda FAC1_mantissa+0 + eor #$FF + sta FAC1_mantissa+0 + lda FAC1_mantissa+1 + eor #$FF + sta FAC1_mantissa+1 + lda FAC1_mantissa+2 + eor #$FF + sta FAC1_mantissa+2 + lda FAC1_mantissa+3 + eor #$FF + sta FAC1_mantissa+3 + lda FACOV + eor #$FF + sta FACOV + bne inc_FAC1_ret + + ; Fallthrough to inc_FAC1 diff --git a/src/basic/math/b947.inv_FAC1_mantissa.s b/src/basic/math/b947.inv_FAC1_mantissa.s deleted file mode 100644 index ce7429f5..00000000 --- a/src/basic/math/b947.inv_FAC1_mantissa.s +++ /dev/null @@ -1,36 +0,0 @@ -;; #LAYOUT# STD * #TAKE -;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000 -;; #LAYOUT# * BASIC_0 #TAKE -;; #LAYOUT# * * #IGNORE - -; -; Math package - invert FAC1 mantissa -; -; See also: -; - [CM64] Computes Mapping the Commodore 64 - page 113 -; - https://www.c64-wiki.com/wiki/BASIC-ROM -; - https://sta.c64.org/cbm64basconv.html -; - -; 2-complement the FAC1 mantissa -; The 4 byte mantissa is treated as an integer in big endian form - - -inv_FAC1_mantissa: - - ldx #3 -@1: lda FAC1_mantissa,X - eor #$FF - sta FAC1_mantissa,X - dex - bpl @1 - - inc FAC1_mantissa+3 - bne @2 - inc FAC1_mantissa+2 - bne @2 - inc FAC1_mantissa+1 - bne @2 - inc FAC1_mantissa - -@2: rts diff --git a/tools/similarity.c b/tools/similarity.c index 2fbbb228..66de278b 100644 --- a/tools/similarity.c +++ b/tools/similarity.c @@ -24,7 +24,7 @@ int phase_mask[MAX_SIZE+MAX_SIZE]; // Pairs of start, end memory addresses of known exact similarity with the open source Microsoft BASIC unsigned short microsoft_basic_chunks[NUM_CHUNKS * 2] = { 0xB849, 0xB84F, - 0xB96F, 0xB97D, + 0xB947, 0xB97D, 0xBBA2, 0xBC1A, 0xBC58, 0xBC5A };