diff --git a/STATUS.md b/STATUS.md index 84d399ac..4c0b23c7 100644 --- a/STATUS.md +++ b/STATUS.md @@ -218,7 +218,7 @@ Floating point mathematical routines - not official, but well known and broadly | `$B947` | `inv_FAC1_mantissa` | DONE | From the Microsoft BASIC, original name: NEGFAC | | `$B96F` | `inc_FAC1` | DONE | From the Microsoft BASIC, original name: INCFAC | | `$B983` | `shiftr_FAC1` | DONE | From the Microsoft BASIC, original name: SHIFTR | -| `$B9EA` | `log_FAC1` | PARTIAL | not fully tested yet | +| `$B9EA` | `log_FAC1` | DONE | From the Microsoft BASIC, original name: LOG | | `$BA28` | `mul_MEM_FAC1` | DONE | From the Microsoft BASIC, original name: FMULT | | `$BA2B` | `mul_FAC2_FAC1` | DONE | From the Microsoft BASIC, original name: FMULTT | | `$BA8C` | `mov_MEM_FAC2` | DONE | From the Microsoft BASIC, original name: CONUPK | diff --git a/src/basic/,basic_aliases.s b/src/basic/,basic_aliases.s index 948cbb0b..52a5f091 100644 --- a/src/basic/,basic_aliases.s +++ b/src/basic/,basic_aliases.s @@ -12,6 +12,7 @@ ; Error codes ; +err_illegal_quantity = $0E err_overflow = $0F ; diff --git a/src/basic/math/b248.illegal_quantity_error.s b/src/basic/math/b248.illegal_quantity_error.s new file mode 100644 index 00000000..f4cd1841 --- /dev/null +++ b/src/basic/math/b248.illegal_quantity_error.s @@ -0,0 +1,17 @@ +;; #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 - overflow error +; +; This is verified to be identical to the original Microsoft implementation where it was named FCERR. +; + +illegal_quantity_error: + + ldx #err_illegal_quantity + jmp error diff --git a/src/basic/math_trans/b9ea.log_FAC1.s b/src/basic/math_trans/b9ea.log_FAC1.s index 8b023ccf..1acd7348 100644 --- a/src/basic/math_trans/b9ea.log_FAC1.s +++ b/src/basic/math_trans/b9ea.log_FAC1.s @@ -3,9 +3,12 @@ ;; #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 - natural logarigthm of FAC1 ; +; This is verified to be identical to the original Microsoft implementation where it was named LOG. ; ; See also: ; - [CM64] Computes Mapping the Commodore 64 - page 113 @@ -26,44 +29,43 @@ log_FAC1: - lda FAC1_exponent ; Store exponent for later - pha - ldx #$80 ; Set exponent to 0 so that FAC1 becomes XF - stx FAC1_exponent + jsr sgn_FAC1_A ; Is it positive + beq LOGERR + bpl LOG1 +LOGERR: + jmp illegal_quantity_error ; Can't tolerate neg or zero +LOG1: + lda FAC1_exponent + sbc #$7F ; Remove bias (carry is off) + pha ; Save awhile + lda #$80 + sta FAC1_exponent ; Result is FAC1 in range [0.5,1] + lda #const_INV_SQR_2 - ldy #>const_INV_SQR_2 ; FAC1 <- FAC1 + sqrt(0.5) - lda #const_SQR_2 ; FAC1 <- sqrt(2.0) / FAC1 - lda #const_ONE ; FAC1 <- 1.0 - FAC1 - lda #poly_log ; FAC1 <- log_poly(FAC1) - lda #const_NEG_HALF ; FAC1 <- FAC1 - 0.5 - lda #const_LOG_2 ; FAC1 <- FAC1 * log(2.0) - lda #const_SQR_2 + jsr div_MEM_FAC1 + lda #const_ONE + jsr sub_MEM_FAC1 + lda #poly_log + jsr poly1_FAC1 ; Evaluate approximation polynomial + lda #const_NEG_HALF + jsr add_MEM_FAC1 + pla ; Get exponent back + jsr FINLOG ; Add it in +MULLN2: + lda #const_LOG_2 + + ; FALLTHROUGH to mul_MEM_FAC1 } else { diff --git a/tools/similarity.c b/tools/similarity.c index 1232d187..26579973 100644 --- a/tools/similarity.c +++ b/tools/similarity.c @@ -20,14 +20,15 @@ int matches[MAX_SIZE]; int phase_mask[MAX_SIZE+MAX_SIZE]; -#define NUM_CHUNKS 13 +#define NUM_CHUNKS 14 // Pairs of start, end memory addresses of known exact similarity with the open source Microsoft BASIC unsigned short microsoft_basic_chunks[NUM_CHUNKS * 2] = { + 0xB248, 0xB24C, 0xB391, 0xB39D, 0xB3A2, 0xB3A5, 0xB849, 0xB97D, - 0xB983, 0xB9D5, - 0xBA28, 0xBCF2, + 0xB983, 0xB9D5, + 0xB9EA, 0xBCF2, 0xBD7E, 0xBD90, 0xBDB3, 0xBDC1, 0xBDDD, 0xBF51,