Update sin_FAC1
This commit is contained in:
1 parent
cbba5e78fb
commit
1383c70ddc
3 files changed
+51
-41
No files matched your search
@@ -263,7 +263,7 @@ Floating point mathematical routines - not official, but well known and broadly
|
|||||||
| `$E09A` | `rnd_A` | DONE | |
|
| `$E09A` | `rnd_A` | DONE | |
|
||||||
| `$E0BE` | `rnd_generate` | DONE | |
|
| `$E0BE` | `rnd_generate` | DONE | |
|
||||||
| `$E264` | `cos_FAC1` | DONE | From the Microsoft BASIC, original name: COS |
|
| `$E264` | `cos_FAC1` | DONE | From the Microsoft BASIC, original name: COS |
|
||||||
| `$E26B` | `sin_FAC1` | PARTIAL | not fully tested yet |
|
| `$E26B` | `sin_FAC1` | DONE | From the Microsoft BASIC, original name: SIN |
|
||||||
| `$E2B4` | `tan_FAC1` | PARTIAL | not fully tested yet |
|
| `$E2B4` | `tan_FAC1` | PARTIAL | not fully tested yet |
|
||||||
| `$E30E` | `atn_FAC1` | DONE | From the Microsoft BASIC, original name: ATN |
|
| `$E30E` | `atn_FAC1` | DONE | From the Microsoft BASIC, original name: ATN |
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,22 @@
|
|||||||
;; #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 - sine of FAC1 in radians
|
; Math package - sine of FAC1 in radians
|
||||||
;
|
;
|
||||||
|
; This is verified to be identical to the original Microsoft implementation where it was named SIN.
|
||||||
|
;
|
||||||
|
; USE IDENTITIES TO GET FAC IN QUADRANTS I OR IV.
|
||||||
|
; THE FAC IS DIVIDED BY 2*PI AND THE INTEGER PART IS IGNORED
|
||||||
|
; BECAUSE SIN(X+2*PI)=SIN(X). THEN THE ARGUMENT CAN BE COMPARED
|
||||||
|
; WITH PI/2 BY COMPARING THE RESULT OF THE DIVISION
|
||||||
|
; WITH PI/2/(2*PI)=1/4.
|
||||||
|
; IDENTITIES ARE THEN USED TO GET THE RESULT IN QUADRANTS
|
||||||
|
; I OR IV. AN APPROXIMATION POLYNOMIAL IS THEN USED TO
|
||||||
|
; COMPUTE SIN(X).
|
||||||
|
;
|
||||||
; See also:
|
; See also:
|
||||||
; - [CM64] Computes Mapping the Commodore 64 - page 210 - XXX address does not match
|
; - [CM64] Computes Mapping the Commodore 64 - page 210 - XXX address does not match
|
||||||
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
|
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
|
||||||
@@ -17,44 +30,41 @@
|
|||||||
|
|
||||||
sin_FAC1:
|
sin_FAC1:
|
||||||
|
|
||||||
jsr mov_FAC1_FAC2 ; FAC1 <- X / (2*pi) (X2)
|
jsr mov_r_FAC1_FAC2
|
||||||
ldy #>const_DOUBLE_PI
|
lda #<const_DOUBLE_PI ; Get pointer to divisor
|
||||||
lda #<const_DOUBLE_PI
|
ldy #>const_DOUBLE_PI
|
||||||
jsr mov_MEM_FAC1
|
ldx FAC2_sign ; Get sign of result
|
||||||
jsr div_FAC2_FAC1
|
jsr div_FAC2_MEM
|
||||||
|
jsr mov_r_FAC1_FAC2 ; Get result into FAC2
|
||||||
jsr mov_FAC1_FAC2 ; FAC2 <- X2
|
jsr int_FAC1
|
||||||
jsr int_FAC1 ; FAC1 <- INT(X2)
|
lda #$00
|
||||||
jsr sub_FAC2_FAC1 ; FAC1 <- X2 - INT(X2) (F)
|
sta ARISGN ; Always have the same sign
|
||||||
|
jsr sub_FAC2_FAC1 ; Keep only the fractional part
|
||||||
ldy #>const_QUARTER
|
lda #<const_QUARTER ; Get pointer to 1/4
|
||||||
lda #<const_QUARTER
|
ldy #>const_QUARTER
|
||||||
jsr FCOMP
|
jsr sub_MEM_FAC1 ; Compute 1/4 - FAC1
|
||||||
bmi sin_next ; FAC1 < 0.25
|
lda FAC1_sign ; Save sign for later
|
||||||
|
pha
|
||||||
ldy #>sin_three_quarters
|
bpl SIN1 ; First quadrant
|
||||||
lda #<sin_three_quarters
|
jsr add_HALF_FAC1 ; Add 1/2 to FAC1
|
||||||
jsr FCOMP
|
lda FAC1_sign ; Sign is negative?
|
||||||
bmi sin_q23 ; FAC1 < 0.75
|
bmi SIN2
|
||||||
|
lda TANSGN ; Quadrants II and III come here
|
||||||
jsr mov_FAC1_FAC2 ; FAC1 <- FAC1 - 1.0
|
eor #$FF
|
||||||
ldy #>const_ONE
|
sta TANSGN
|
||||||
lda #<const_ONE
|
SIN1:
|
||||||
jsr mov_MEM_FAC1
|
jsr toggle_sign_FAC1 ; If positive, negate it
|
||||||
jsr sub_FAC2_FAC1
|
SIN2:
|
||||||
+bra sin_next
|
lda #<const_QUARTER ; Get pointer to 1/4
|
||||||
|
ldy #>const_QUARTER
|
||||||
sin_q23:
|
jsr add_MEM_FAC1 ; Add it in
|
||||||
ldy #>const_HALF
|
pla ; Get original quadrant
|
||||||
lda #<const_HALF
|
bpl SIN3
|
||||||
jsr sub_MEM_FAC1 ; FAC1 <- 0.5 - FAC1
|
jsr toggle_sign_FAC1 ; If negative, negate result
|
||||||
|
SIN3:
|
||||||
; FALLTHROUGH
|
lda #<poly_sin
|
||||||
|
ldy #>poly_sin
|
||||||
sin_next:
|
jmp poly1_FAC1 ; Do approximation polynomial
|
||||||
ldy #>poly_sin
|
|
||||||
lda #<poly_sin
|
|
||||||
jmp poly1_FAC1
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+1
-1
@@ -32,7 +32,7 @@ unsigned short microsoft_basic_chunks[NUM_CHUNKS * 2] = {
|
|||||||
0xBDB3, 0xBDC1,
|
0xBDB3, 0xBDC1,
|
||||||
0xBDDD, 0xBF51,
|
0xBDDD, 0xBF51,
|
||||||
0xBFB4, 0xBFEC,
|
0xBFB4, 0xBFEC,
|
||||||
0xE264, 0xE26A,
|
0xE264, 0xE2B3,
|
||||||
0xE2EF, 0xE37A,
|
0xE2EF, 0xE37A,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user