Update log_FAC1

This commit is contained in:
Rikard Nordgren authored and FeralChild64 committed 2026-04-29 21:18:16 +02:00
1 parent 84eded300c
commit d50bba16c9
5 files changed
+61 -40

No files matched your search

+1 -1
View File
@@ -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 | | `$B947` | `inv_FAC1_mantissa` | DONE | From the Microsoft BASIC, original name: NEGFAC |
| `$B96F` | `inc_FAC1` | DONE | From the Microsoft BASIC, original name: INCFAC | | `$B96F` | `inc_FAC1` | DONE | From the Microsoft BASIC, original name: INCFAC |
| `$B983` | `shiftr_FAC1` | DONE | From the Microsoft BASIC, original name: SHIFTR | | `$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 | | `$BA28` | `mul_MEM_FAC1` | DONE | From the Microsoft BASIC, original name: FMULT |
| `$BA2B` | `mul_FAC2_FAC1` | DONE | From the Microsoft BASIC, original name: FMULTT | | `$BA2B` | `mul_FAC2_FAC1` | DONE | From the Microsoft BASIC, original name: FMULTT |
| `$BA8C` | `mov_MEM_FAC2` | DONE | From the Microsoft BASIC, original name: CONUPK | | `$BA8C` | `mov_MEM_FAC2` | DONE | From the Microsoft BASIC, original name: CONUPK |
+1
View File
@@ -12,6 +12,7 @@
; Error codes ; Error codes
; ;
err_illegal_quantity = $0E
err_overflow = $0F err_overflow = $0F
; ;
@@ -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
+38 -36
View File
@@ -3,9 +3,12 @@
;; #LAYOUT# * BASIC_0 #TAKE ;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE ;; #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 ; Math package - natural logarigthm of FAC1
; ;
; This is verified to be identical to the original Microsoft implementation where it was named LOG.
; ;
; See also: ; See also:
; - [CM64] Computes Mapping the Commodore 64 - page 113 ; - [CM64] Computes Mapping the Commodore 64 - page 113
@@ -26,44 +29,43 @@
log_FAC1: log_FAC1:
lda FAC1_exponent ; Store exponent for later
pha
ldx #$80 ; Set exponent to 0 so that FAC1 becomes XF jsr sgn_FAC1_A ; Is it positive
stx FAC1_exponent 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 ; Get pointer to SQR(0.5)
ldy #>const_INV_SQR_2
ldy #>const_INV_SQR_2 ; FAC1 <- FAC1 + sqrt(0.5) ; Calculate (F - SQR(.5)) / (F + SQR(.5))
lda #<const_INV_SQR_2
jsr add_MEM_FAC1
ldy #>const_SQR_2 ; FAC1 <- sqrt(2.0) / FAC1 jsr add_MEM_FAC1 ; Add to FAC1
lda #<const_SQR_2 lda #<const_SQR_2 ; Get SQR(2.)
jsr div_MEM_FAC1 ldy #>const_SQR_2
jsr div_MEM_FAC1
ldy #>const_ONE ; FAC1 <- 1.0 - FAC1 lda #<const_ONE
lda #<const_ONE ldy #>const_ONE
jsr sub_MEM_FAC1 jsr sub_MEM_FAC1
lda #<poly_log
ldy #>poly_log ; FAC1 <- log_poly(FAC1) ldy #>poly_log
lda #<poly_log jsr poly1_FAC1 ; Evaluate approximation polynomial
jsr poly1_FAC1 lda #<const_NEG_HALF ; Add in last constant
ldy #>const_NEG_HALF
ldy #>const_NEG_HALF ; FAC1 <- FAC1 - 0.5 jsr add_MEM_FAC1
lda #<const_NEG_HALF pla ; Get exponent back
jsr add_MEM_FAC1 jsr FINLOG ; Add it in
MULLN2:
jsr mov_FAC1_FAC2 ; FAC2 <- FAC1 lda #<const_LOG_2 ; Multiply result by log(2.0)
ldy #>const_LOG_2
pla ; FAC1 <- N
sec ; FALLTHROUGH to mul_MEM_FAC1
sbc #$80
jsr convert_A_to_FAC1
jsr add_FAC2_FAC1 ; FAC1 <- FAC1 + FAC2
ldy #>const_LOG_2 ; FAC1 <- FAC1 * log(2.0)
lda #<const_LOG_2
jmp mul_MEM_FAC1
} else { } else {
+4 -3
View File
@@ -20,14 +20,15 @@ int matches[MAX_SIZE];
int phase_mask[MAX_SIZE+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 // Pairs of start, end memory addresses of known exact similarity with the open source Microsoft BASIC
unsigned short microsoft_basic_chunks[NUM_CHUNKS * 2] = { unsigned short microsoft_basic_chunks[NUM_CHUNKS * 2] = {
0xB248, 0xB24C,
0xB391, 0xB39D, 0xB391, 0xB39D,
0xB3A2, 0xB3A5, 0xB3A2, 0xB3A5,
0xB849, 0xB97D, 0xB849, 0xB97D,
0xB983, 0xB9D5, 0xB983, 0xB9D5,
0xBA28, 0xBCF2, 0xB9EA, 0xBCF2,
0xBD7E, 0xBD90, 0xBD7E, 0xBD90,
0xBDB3, 0xBDC1, 0xBDB3, 0xBDC1,
0xBDDD, 0xBF51, 0xBDDD, 0xBF51,