Merge branch 'master' into TAN
This commit is contained in:
18 files changed
+167
-54
No files matched your search
@@ -12,7 +12,7 @@
|
||||
;
|
||||
; Output:
|
||||
; - .A - $00 for equal, $01 for FAC1 > RAM, $FF for FAC1 < RAM
|
||||
; - flags N/Z, depending on whether FAC1 is 0, positive, or negative
|
||||
; - flags N/Z, Z=1 if equal, N=1 if FAC1 < RAM, Z=0, N=0 if FAC1 > RAM
|
||||
;
|
||||
; Notes:
|
||||
; - uses vector at $24, leaves FAC1 and FAC2 unchanged (Codebase64)
|
||||
@@ -28,9 +28,6 @@ FCOMP:
|
||||
sta INDEX+2
|
||||
sty INDEX+3
|
||||
|
||||
jsr sgn_FAC1_A ; Set N/Z flag for FAC1 and store on stack
|
||||
php
|
||||
|
||||
ldy #$01
|
||||
lda (INDEX+2),Y
|
||||
eor FAC1_sign ; Check if signs are different
|
||||
@@ -69,7 +66,6 @@ FCOMP:
|
||||
|
||||
FCOMP_equal:
|
||||
lda #$00
|
||||
plp
|
||||
rts
|
||||
|
||||
|
||||
@@ -78,7 +74,6 @@ FCOMP_less_than:
|
||||
bpl FCOMP_FF
|
||||
FCOMP_01:
|
||||
lda #$01
|
||||
plp
|
||||
rts
|
||||
|
||||
FCOMP_greater_than:
|
||||
@@ -86,5 +81,4 @@ FCOMP_greater_than:
|
||||
bpl FCOMP_01
|
||||
FCOMP_FF:
|
||||
lda #$FF
|
||||
plp
|
||||
rts
|
||||
@@ -0,0 +1,4 @@
|
||||
This is an important floating point math routine, documented in many places.
|
||||
|
||||
Usage example:
|
||||
- https://www.lemon64.com/forum/viewtopic.php?t=10492
|
||||
@@ -0,0 +1,55 @@
|
||||
;; #LAYOUT# STD * #TAKE
|
||||
;; #LAYOUT# * BASIC_0 #TAKE
|
||||
;; #LAYOUT# * * #IGNORE
|
||||
|
||||
;
|
||||
; Math package - sine of FAC1 in radians
|
||||
;
|
||||
; See also:
|
||||
; - [CM64] Computes Mapping the Commodore 64 - page 210 - XXX address does not match
|
||||
; - 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/SIN
|
||||
|
||||
|
||||
|
||||
sin_FAC1:
|
||||
|
||||
jsr mov_FAC1_FAC2 ; FAC1 <- X / (2*pi) (X2)
|
||||
ldy #>const_DOUBLE_PI
|
||||
lda #<const_DOUBLE_PI
|
||||
jsr mov_MEM_FAC1
|
||||
jsr div_FAC2_FAC1
|
||||
|
||||
jsr mov_FAC1_FAC2 ; FAC2 <- X2
|
||||
jsr int_FAC1 ; FAC1 <- INT(X2)
|
||||
jsr sub_FAC2_FAC1 ; FAC1 <- X2 - INT(X2) (F)
|
||||
|
||||
ldy #>const_QUARTER
|
||||
lda #<const_QUARTER
|
||||
jsr FCOMP
|
||||
bmi sin_next ; FAC1 < 0.25
|
||||
|
||||
ldy #>sin_three_quarters
|
||||
lda #<sin_three_quarters
|
||||
jsr FCOMP
|
||||
bmi sin_q23 ; FAC1 < 0.75
|
||||
|
||||
jsr mov_FAC1_FAC2 ; FAC1 <- FAC1 - 1.0
|
||||
ldy #>const_ONE
|
||||
lda #<const_ONE
|
||||
jsr mov_MEM_FAC1
|
||||
jsr sub_FAC2_FAC1
|
||||
+bra sin_next
|
||||
|
||||
sin_q23:
|
||||
ldy #>const_HALF
|
||||
lda #<const_HALF
|
||||
jsr sub_MEM_FAC1 ; FAC1 <- 0.5 - FAC1
|
||||
|
||||
; FALLTHROUGH
|
||||
|
||||
sin_next:
|
||||
ldy #>poly_sin
|
||||
lda #<poly_sin
|
||||
jmp poly1_FAC1
|
||||
@@ -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
|
||||
@@ -0,0 +1,3 @@
|
||||
This is an important floating point math routine, documented in many places.
|
||||
|
||||
XXX - try to find real-life example
|
||||
@@ -0,0 +1,23 @@
|
||||
;; #LAYOUT# STD * #TAKE
|
||||
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
|
||||
;; #LAYOUT# * BASIC_0 #TAKE
|
||||
;; #LAYOUT# * * #IGNORE
|
||||
|
||||
; Polynomial for the atn function
|
||||
|
||||
poly_atn:
|
||||
|
||||
!byte $0B ; series length - 1
|
||||
|
||||
+PUT_CONST_POLY_ATN_1
|
||||
+PUT_CONST_POLY_ATN_2
|
||||
+PUT_CONST_POLY_ATN_3
|
||||
+PUT_CONST_POLY_ATN_4
|
||||
+PUT_CONST_POLY_ATN_5
|
||||
+PUT_CONST_POLY_ATN_6
|
||||
+PUT_CONST_POLY_ATN_7
|
||||
+PUT_CONST_POLY_ATN_8
|
||||
+PUT_CONST_POLY_ATN_9
|
||||
+PUT_CONST_POLY_ATN_10
|
||||
+PUT_CONST_POLY_ATN_11
|
||||
+PUT_CONST_POLY_ATN_12
|
||||
@@ -0,0 +1,23 @@
|
||||
;; #LAYOUT# STD * #TAKE
|
||||
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
|
||||
;; #LAYOUT# * BASIC_0 #TAKE
|
||||
;; #LAYOUT# * * #IGNORE
|
||||
|
||||
; Polynomial for the sine function
|
||||
|
||||
|
||||
poly_sin:
|
||||
|
||||
!byte $05 ; series length - 1
|
||||
|
||||
+PUT_CONST_POLY_SIN_1
|
||||
+PUT_CONST_POLY_SIN_2
|
||||
+PUT_CONST_POLY_SIN_3
|
||||
+PUT_CONST_POLY_SIN_4
|
||||
+PUT_CONST_POLY_SIN_5
|
||||
+PUT_CONST_POLY_SIN_6
|
||||
|
||||
|
||||
; Constant 0.75 needed for sine calculation
|
||||
sin_three_quarters:
|
||||
!byte $80, $40, $00, $00, $00
|
||||
Reference in new issue
Block a user