add atn_FAC1
This commit is contained in:
1 parent
7563da19ab
commit
b5dc23579f
12 files changed
+83
-16
No files matched your search
@@ -256,7 +256,7 @@ Floating point mathematical routines - not official, but well known and broadly
|
||||
| `$E264` | `cos_FAC1` | PARTIAL | needs `sin_FAC1` |
|
||||
| `$E26B` | `sin_FAC1` | NOT DONE | some work already started |
|
||||
| `$E2B4` | `tan_FAC1` | NOT DONE | |
|
||||
| `$E30E` | `atn_FAC1` | NOT DONE | |
|
||||
| `$E30E` | `atn_FAC1` | PARTIAL | not fully tested yet |
|
||||
|
||||
<br />
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
;; #LAYOUT# STD * #TAKE
|
||||
;; #LAYOUT# * BASIC_0 #TAKE
|
||||
;; #LAYOUT# * * #IGNORE
|
||||
|
||||
;
|
||||
; Math package - arc tangent of FAC1
|
||||
;
|
||||
; See also:
|
||||
; - [CM64] Computes Mapping the Commodore 64 - page 211
|
||||
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
|
||||
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
|
||||
; - https://www.c64-wiki.com/wiki/ATN
|
||||
|
||||
; Algorithm:
|
||||
; 1. Save sign of x
|
||||
; 2. Calculate AX = |x| (we can use that arctan(-x) = -arctan(x)
|
||||
; 3. If AX > 1 set AX = 1/AX (we can use that arctan(x) = pi/2 - arctan(1/x) )
|
||||
; 4. Use polynomial to approximate arctan(AX) now since 0 <= AX <= 1
|
||||
; 5. Adjust sign of result and offset with pi/2 if needed as per above
|
||||
|
||||
|
||||
atn_FAC1:
|
||||
lda FAC1_sign ; Save sign of FAC1 on the stack
|
||||
pha
|
||||
lda #$00 ; FAC1 = abs(FAC1)
|
||||
sta FAC1_sign
|
||||
sta TEMPF1 ; AX not scaled
|
||||
|
||||
lda #<const_ONE
|
||||
ldy #>const_ONE
|
||||
jsr FCOMP
|
||||
bmi atn_skipscale
|
||||
|
||||
lda #<const_ONE
|
||||
ldy #>const_ONE
|
||||
jsr div_MEM_FAC1
|
||||
inc TEMPF1 ; AX scaled
|
||||
|
||||
atn_skipscale:
|
||||
lda #<poly_atn
|
||||
ldy #>poly_atn
|
||||
jsr poly1_FAC1
|
||||
|
||||
lda TEMPF1
|
||||
beq atn_skipoffset
|
||||
|
||||
lda #<const_HALF_PI
|
||||
ldy #>const_HALF_PI
|
||||
jsr sub_MEM_FAC1
|
||||
|
||||
atn_skipoffset:
|
||||
pla
|
||||
bpl atn_out
|
||||
jmp toggle_sign_FAC1
|
||||
|
||||
atn_out:
|
||||
rts
|
||||
File renamed without changes.
@@ -1,22 +1,10 @@
|
||||
;; #LAYOUT# STD * #TAKE
|
||||
;; #LAYOUT# * BASIC_0 #TAKE
|
||||
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
|
||||
;; #LAYOUT# * BASIC_0 #TAKE
|
||||
;; #LAYOUT# * * #IGNORE
|
||||
|
||||
;
|
||||
; Math package - arc tangent of FAC1
|
||||
;
|
||||
; See also:
|
||||
; - [CM64] Computes Mapping the Commodore 64 - page 211
|
||||
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
|
||||
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
|
||||
;
|
||||
; Polynomial for the atn function
|
||||
|
||||
; XXX provide implementation
|
||||
|
||||
atn_FAC1:
|
||||
|
||||
+STUB_IMPLEMENTATION
|
||||
|
||||
poly_atn:
|
||||
|
||||
!byte $0B ; series length - 1
|
||||
@@ -0,0 +1,3 @@
|
||||
$07 + LDA #$E0 + LDY #$E2 + JSR $B850 + PLA + BPL $03 + JMP $BFB4 + RTS
|
||||
|
||||
Load address of known constant into YA + call well known floating point function + branch on top of stack and call other well known floating point function.
|
||||
+1
@@ -0,0 +1 @@
|
||||
12 floating point numbers making upp the approximation polynomial for the ATN function. This polynomial is described in "Computer Approximations" by John Fraser Hart et al. (ISBN 0-88275-642-7) according to https://www.c64-wiki.com/wiki/POLY1
|
||||
@@ -0,0 +1,3 @@
|
||||
LDY #$B9 + JSR $BB0F
|
||||
|
||||
Partially set input and call well known floating point function
|
||||
@@ -0,0 +1,3 @@
|
||||
LDY #$E2 + JSR $B850
|
||||
|
||||
Partial load of input + call to known floating point function
|
||||
@@ -0,0 +1,3 @@
|
||||
LDA #$E0 + LDY #$E2 + JSR fragment
|
||||
|
||||
Load address of known constant and call some function
|
||||
@@ -0,0 +1,3 @@
|
||||
$B9 + JSR $BB0F
|
||||
|
||||
Fragment + call to well known floating point function
|
||||
@@ -0,0 +1,3 @@
|
||||
$BC + LDY #$B9 + JMP
|
||||
|
||||
Fragments
|
||||
@@ -0,0 +1,3 @@
|
||||
$DA + $A2 + LDA $66 + PHA
|
||||
|
||||
Fragment + push FAC1 sign on stack
|
||||
Reference in new issue
Block a user