Update log_FAC1
This commit is contained in:
1 parent
84eded300c
commit
d50bba16c9
5 files changed
+61
-40
No files matched your search
@@ -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 |
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
; Error codes
|
||||
;
|
||||
|
||||
err_illegal_quantity = $0E
|
||||
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
|
||||
@@ -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 ; Get pointer to SQR(0.5)
|
||||
ldy #>const_INV_SQR_2
|
||||
|
||||
ldy #>const_INV_SQR_2 ; FAC1 <- FAC1 + sqrt(0.5)
|
||||
lda #<const_INV_SQR_2
|
||||
jsr add_MEM_FAC1
|
||||
; Calculate (F - SQR(.5)) / (F + SQR(.5))
|
||||
|
||||
ldy #>const_SQR_2 ; FAC1 <- sqrt(2.0) / FAC1
|
||||
lda #<const_SQR_2
|
||||
jsr div_MEM_FAC1
|
||||
|
||||
ldy #>const_ONE ; FAC1 <- 1.0 - FAC1
|
||||
lda #<const_ONE
|
||||
jsr sub_MEM_FAC1
|
||||
|
||||
ldy #>poly_log ; FAC1 <- log_poly(FAC1)
|
||||
lda #<poly_log
|
||||
jsr poly1_FAC1
|
||||
|
||||
ldy #>const_NEG_HALF ; FAC1 <- FAC1 - 0.5
|
||||
lda #<const_NEG_HALF
|
||||
jsr add_MEM_FAC1
|
||||
|
||||
jsr mov_FAC1_FAC2 ; FAC2 <- FAC1
|
||||
|
||||
pla ; FAC1 <- N
|
||||
sec
|
||||
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
|
||||
jsr add_MEM_FAC1 ; Add to FAC1
|
||||
lda #<const_SQR_2 ; Get SQR(2.)
|
||||
ldy #>const_SQR_2
|
||||
jsr div_MEM_FAC1
|
||||
lda #<const_ONE
|
||||
ldy #>const_ONE
|
||||
jsr sub_MEM_FAC1
|
||||
lda #<poly_log
|
||||
ldy #>poly_log
|
||||
jsr poly1_FAC1 ; Evaluate approximation polynomial
|
||||
lda #<const_NEG_HALF ; Add in last constant
|
||||
ldy #>const_NEG_HALF
|
||||
jsr add_MEM_FAC1
|
||||
pla ; Get exponent back
|
||||
jsr FINLOG ; Add it in
|
||||
MULLN2:
|
||||
lda #<const_LOG_2 ; Multiply result by log(2.0)
|
||||
ldy #>const_LOG_2
|
||||
|
||||
; FALLTHROUGH to mul_MEM_FAC1
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
+4
-3
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user