diff --git a/STATUS.md b/STATUS.md index f6d74d3f..771f26a7 100644 --- a/STATUS.md +++ b/STATUS.md @@ -253,10 +253,10 @@ Floating point mathematical routines - not official, but well known and broadly | `$E097` | `rnd_FAC1` | DONE | | | `$E09A` | `rnd_A` | DONE | | | `$E0BE` | `rnd_generate` | DONE | | -| `$E264` | `cos_FAC1` | PARTIAL | needs `sin_FAC1` | -| `$E26B` | `sin_FAC1` | NOT DONE | some work already started | +| `$E264` | `cos_FAC1` | PARTIAL | not fully tested yet | +| `$E26B` | `sin_FAC1` | PARTIAL | not fully tested yet | | `$E2B4` | `tan_FAC1` | PARTIAL | not fully tested yet | -| `$E30E` | `atn_FAC1` | NOT DONE | | +| `$E30E` | `atn_FAC1` | PARTIAL | not fully tested yet |
diff --git a/src/basic/,stubs_math/e26b.sin_FAC1.s b/src/basic/,stubs_math/e26b.sin_FAC1.s deleted file mode 100644 index f1f2f340..00000000 --- a/src/basic/,stubs_math/e26b.sin_FAC1.s +++ /dev/null @@ -1,29 +0,0 @@ -;; #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 -; - -; XXX provide implementation - -sin_FAC1: - - +STUB_IMPLEMENTATION - -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 diff --git a/src/basic/math/FCOMP.s b/src/basic/math/FCOMP.s index 1a754efd..9c38d69d 100644 --- a/src/basic/math/FCOMP.s +++ b/src/basic/math/FCOMP.s @@ -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 diff --git a/src/basic/,stubs_math/e26b.interop b/src/basic/math/e26b.interop similarity index 100% rename from src/basic/,stubs_math/e26b.interop rename to src/basic/math/e26b.interop diff --git a/src/basic/math/e26b.sin_FAC1.s b/src/basic/math/e26b.sin_FAC1.s new file mode 100644 index 00000000..65c48f0f --- /dev/null +++ b/src/basic/math/e26b.sin_FAC1.s @@ -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_QUARTER + lda #sin_three_quarters + lda #const_ONE + lda #const_HALF + lda #poly_sin + lda # 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 + jsr FCOMP + bmi atn_skipscale + + lda #const_ONE + jsr div_MEM_FAC1 + inc TEMPF1 ; AX scaled + +atn_skipscale: + lda #poly_atn + jsr poly1_FAC1 + + lda TEMPF1 + beq atn_skipoffset + + lda #const_HALF_PI + jsr sub_MEM_FAC1 + +atn_skipoffset: + pla + bpl atn_out + jmp toggle_sign_FAC1 + +atn_out: + rts diff --git a/src/basic/,stubs_math/e30e.interop b/src/basic/math/e30e.interop similarity index 100% rename from src/basic/,stubs_math/e30e.interop rename to src/basic/math/e30e.interop diff --git a/src/basic/,stubs_math/e30e.atn_FAC1.s b/src/basic/math/poly_atn.s similarity index 56% rename from src/basic/,stubs_math/e30e.atn_FAC1.s rename to src/basic/math/poly_atn.s index 5c5d53f3..da8a2bbc 100644 --- a/src/basic/,stubs_math/e30e.atn_FAC1.s +++ b/src/basic/math/poly_atn.s @@ -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 diff --git a/src/basic/math/poly_sin.s b/src/basic/math/poly_sin.s new file mode 100644 index 00000000..1f37c2e6 --- /dev/null +++ b/src/basic/math/poly_sin.s @@ -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 diff --git a/strings/07A9E0A0E22050B86810034CB4BF60 b/strings/07A9E0A0E22050B86810034CB4BF60 new file mode 100644 index 00000000..dc79555c --- /dev/null +++ b/strings/07A9E0A0E22050B86810034CB4BF60 @@ -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. diff --git a/strings/0B76B383BDD3791EF4A6F57B83FCB0107C0C1F67CA7CDE53CBC17D1464704C7DB7EA517A7D6330887E7E9244993A7E4CCC91C77FAAAAAA138100000000 b/strings/0B76B383BDD3791EF4A6F57B83FCB0107C0C1F67CA7CDE53CBC17D1464704C7DB7EA517A7D6330887E7E9244993A7E4CCC91C77FAAAAAA138100000000 new file mode 100644 index 00000000..9680dddc --- /dev/null +++ b/strings/0B76B383BDD3791EF4A6F57B83FCB0107C0C1F67CA7CDE53CBC17D1464704C7DB7EA517A7D6330887E7E9244993A7E4CCC91C77FAAAAAA138100000000 @@ -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 diff --git a/strings/85248425A0 b/strings/85248425A0 new file mode 100644 index 00000000..86536202 --- /dev/null +++ b/strings/85248425A0 @@ -0,0 +1,3 @@ +STA $24 + STY $25 + LDY fragment + +Store YA to well known vector address in the zero page diff --git a/strings/A0B9200FBB b/strings/A0B9200FBB new file mode 100644 index 00000000..804e875a --- /dev/null +++ b/strings/A0B9200FBB @@ -0,0 +1,3 @@ +LDY #$B9 + JSR $BB0F + +Partially set input and call well known floating point function diff --git a/strings/A0E22050B8 b/strings/A0E22050B8 new file mode 100644 index 00000000..47f18913 --- /dev/null +++ b/strings/A0E22050B8 @@ -0,0 +1,3 @@ +LDY #$E2 + JSR $B850 + +Partial load of input + call to known floating point function diff --git a/strings/A9E0A0E220 b/strings/A9E0A0E220 new file mode 100644 index 00000000..c53b5c2c --- /dev/null +++ b/strings/A9E0A0E220 @@ -0,0 +1,3 @@ +LDA #$E0 + LDY #$E2 + JSR fragment + +Load address of known constant and call some function diff --git a/strings/B9200FBB b/strings/B9200FBB new file mode 100644 index 00000000..9b0a1caa --- /dev/null +++ b/strings/B9200FBB @@ -0,0 +1,3 @@ +$B9 + JSR $BB0F + +Fragment + call to well known floating point function diff --git a/strings/BCA0B920 b/strings/BCA0B920 new file mode 100644 index 00000000..d951ea5b --- /dev/null +++ b/strings/BCA0B920 @@ -0,0 +1,3 @@ +$BC + LDY #$B9 + JMP + +Fragments diff --git a/strings/DAA2A56648 b/strings/DAA2A56648 new file mode 100644 index 00000000..bc36bdde --- /dev/null +++ b/strings/DAA2A56648 @@ -0,0 +1,3 @@ +$DA + $A2 + LDA $66 + PHA + +Fragment + push FAC1 sign on stack