diff --git a/STATUS.md b/STATUS.md index de65c125..952a0e9e 100644 --- a/STATUS.md +++ b/STATUS.md @@ -227,7 +227,7 @@ Floating point mathematical routines - not official, but well known and broadly | `$BBCA` | `mov_r_FAC1_TMP1` | PARTIAL | not fully tested yet | | `$BBD0` | `mov_r_FAC1_VAR` | PARTIAL | not fully tested yet | | `$BBD4` | `mov_r_FAC1_MEM` | PARTIAL | not fully tested yet | -| `$BBFC` | `mov_FAC2_FAC1` | DONE | | +| `$BBFC` | `mov_FAC2_FAC1` | DONE | From the Microsoft BASIC, original name: MOVFA | | `$BC0C` | `mov_r_FAC1_FAC2` | DONE | From the Microsoft BASIC, original name: MOVAF | | `$BC0F` | `mov_FAC1_FAC2` | DONE | From the Microsoft BASIC, original name: MOVEF | | `$BC1B` | `round_FAC1` | PARTIAL | not fully tested yet | diff --git a/src/basic/math_mov/bbfc.mov_FAC2_FAC1.s b/src/basic/math_mov/bbfc.mov_FAC2_FAC1.s index c320e722..7da15a4f 100644 --- a/src/basic/math_mov/bbfc.mov_FAC2_FAC1.s +++ b/src/basic/math_mov/bbfc.mov_FAC2_FAC1.s @@ -3,6 +3,45 @@ ;; #LAYOUT# * BASIC_0 #TAKE ;; #LAYOUT# * * #IGNORE -; Just a compatibility jump - our routine is longer than original one +; This file is under the MIT license, it contains code released by Microsoft Corporation. +; See LICENSE for more information. - jmp mov_FAC2_FAC1 +; Math package - Copy FAC2 to FAC1 +; +; This is verified to be identical to the original Microsoft implementation where it was named MOVFA. +; +; It has an alternative entry point at mov_FAC2_FAC1_sign (original: MOVFA1) that instead of copying the sign uses A for the copied sign. +; +; Output (found by experimentation): +; - .A - FAC1 exponent +; - .X - always 0 +; +; Preserves: +; - .Y +; +; See also: +; - [CM64] Computes Mapping the Commodore 64 - page 115 +; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic +; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics +; + + +mov_FAC2_FAC1: + ; Copy the sign + + lda FAC2_sign + +mov_FAC2_FAC1_sign: + sta FAC2_sign + + ; Copy the mantissa and the exponent + + ldx #5 + +@1 + lda FAC2_exponent - 1,X + sta FAC1_exponent - 1,X + dex + bne @1 + stx FACOV ; Always 0 + rts diff --git a/src/basic/math_mov/mov_FAC2_FAC1.s b/src/basic/math_mov/mov_FAC2_FAC1.s deleted file mode 100644 index b860cac2..00000000 --- a/src/basic/math_mov/mov_FAC2_FAC1.s +++ /dev/null @@ -1,49 +0,0 @@ -;; #LAYOUT# STD * #TAKE -;; #LAYOUT# * BASIC_0 #TAKE -;; #LAYOUT# * * #IGNORE - -; -; Math package - copy FAC2 to FAC1 -; -; Output (found by experimentation): -; - .A - FAC1 exponent -; - .X - always 0 -; -; Preserves: -; - .Y -; -; See also: -; - [CM64] Computes Mapping the Commodore 64 - page 115 -; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic -; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics -; - -mov_FAC2_FAC1: - - ; Copy the mantissa - - lda FAC2_mantissa+3 - sta FAC1_mantissa+3 - lda FAC2_mantissa+2 - sta FAC1_mantissa+2 - lda FAC2_mantissa+1 - sta FAC1_mantissa+1 - lda FAC2_mantissa+0 - sta FAC1_mantissa+0 - - ; Copy the sign - - lda FAC2_sign - sta FAC1_sign - - ; Copy the exponent - - lda FAC2_exponent - sta FAC1_exponent - - ; Clear FACOV - - ldx #$00 - stx FACOV - - rts diff --git a/tools/similarity.c b/tools/similarity.c index 7f1e3b51..d608e378 100644 --- a/tools/similarity.c +++ b/tools/similarity.c @@ -22,7 +22,7 @@ int phase_mask[MAX_SIZE+MAX_SIZE]; #define NUM_CHUNKS 1 // Pairs of start, end memory addresses of known exact similarity with the open source Microsoft BASIC -unsigned short microsoft_basic_chunks[NUM_CHUNKS * 2] = {0xBC0C, 0xBC1A}; +unsigned short microsoft_basic_chunks[NUM_CHUNKS * 2] = {0xBBFC, 0xBC1A}; int main(int argc,char **argv)