migrated to ACME assembler

commit 145d64aa6e78838ed07cefed372f0ad6a4687e97
Author: FeralChild64 <you@example.com>
Date:   Sun Sep 20 20:16:57 2020 +0200

    ACME adaptation

commit 885209d7822286744ea53232ae7461472a01d5d6
Author: FeralChild64 <you@example.com>
Date:   Sun Sep 20 19:57:25 2020 +0200

    ACME adaptation

commit 334d84486bc603551887e7cbeb59d329f2224cc7
Author: FeralChild64 <you@example.com>
Date:   Sun Sep 20 18:29:15 2020 +0200

    ACME adaptation

commit b5966f49bcd8f0ca79cbec93819a31238924707e
Author: FeralChild64 <you@example.com>
Date:   Sun Sep 20 18:09:31 2020 +0200

    ACME adaptation

commit 786536a93a5eab5e676fca99625b4eb094a554e7
Author: FeralChild64 <you@example.com>
Date:   Sun Sep 20 17:24:48 2020 +0200

    ACME adaptation

commit 704c70dfb1f5d68775d6f3da220803b8a3990f56
Author: FeralChild64 <you@example.com>
Date:   Sun Sep 20 15:07:12 2020 +0200

    ACME adaptation

commit 136874964c9083b375f151475310f9636871fc72
Author: FeralChild64 <you@example.com>
Date:   Sun Sep 20 14:45:14 2020 +0200

    ACME adaptation

commit 8eca0d5700b72d04336e72c5cd3a68e18b85f96d
Author: FeralChild64 <you@example.com>
Date:   Sun Sep 20 14:06:52 2020 +0200

    ACME adaptation

commit 11d29eb7ee318239d782f85498b6d0524624d5c4
Author: FeralChild64 <you@example.com>
Date:   Sun Sep 20 13:56:45 2020 +0200

    ACME apaptation

commit c9b5e5e04cceb92c66bc027e6440bc0f7c5a499f
Author: FeralChild64 <you@example.com>
Date:   Sun Sep 20 13:49:04 2020 +0200

    ACME adaptation

commit f5cc254cbc921f07863807468cb3fe26b410b409
Author: FeralChild64 <you@example.com>
Date:   Sun Sep 20 13:01:18 2020 +0200

    ACME adaptation

commit e135a27bf9c30cc0965379c954564e06406303b1
Author: FeralChild64 <you@example.com>
Date:   Sat Sep 19 21:55:01 2020 +0200

    ACME adaptation

commit e9dfddf90d9e2795e88b7da40ae050d733faeb56
Author: FeralChild64 <you@example.com>
Date:   Sat Sep 19 21:48:47 2020 +0200

    Makefile fix

commit 07030104c65cf5e5beeacf6d629ccb9245e58657
Author: FeralChild64 <you@example.com>
Date:   Sat Sep 19 21:42:00 2020 +0200

    ACME adaptation

commit f824362ee5bcfbffca86c430b57773b2ffd65655
Author: FeralChild64 <you@example.com>
Date:   Sat Sep 19 20:14:56 2020 +0200

    ACME adaptation

commit 3a3c59007dcd4940d89b8669f34ca56b61c25fdf
Author: FeralChild64 <you@example.com>
Date:   Fri Sep 18 21:51:45 2020 +0200

    ACME adaptation

commit 6790ef7bc88a41de2881c69b7524dd4ab8c74b5d
Author: FeralChild64 <you@example.com>
Date:   Fri Sep 18 20:35:23 2020 +0200

    ACME adaptation

commit 38ad18b90e9ec713aa7ca49576b3388ce1733357
Author: FeralChild64 <you@example.com>
Date:   Fri Sep 18 18:46:20 2020 +0200

    ACME adaptation

commit 541340371122a9702f7b2d9771c298223cffd0e9
Author: FeralChild64 <you@example.com>
Date:   Fri Sep 18 16:49:46 2020 +0200

    ACME adaptation

commit 25cfd5e186459be1a260d3eb8cfff767838de370
Author: FeralChild64 <you@example.com>
Date:   Thu Sep 17 20:13:33 2020 +0200

    ACME adaptation

commit f61599444d5b1d03d8fd8e4a6a7c3b85069bedb3
Author: FeralChild64 <you@example.com>
Date:   Thu Sep 17 19:29:23 2020 +0200

    ACME adaptation

commit b290be31ec7bb2e5723607697da1bbc621c84429
Author: FeralChild64 <you@example.com>
Date:   Thu Sep 17 17:20:14 2020 +0200

    ACME adaptation

commit 877be9e856880d98fd4bcb25b42aaaacda9dc463
Author: FeralChild64 <you@example.com>
Date:   Wed Sep 16 21:47:38 2020 +0200

    ACME adaptation

commit bb20edaf85d386e41d5c2f715b745b68fbd3362e
Author: FeralChild64 <you@example.com>
Date:   Wed Sep 16 21:31:30 2020 +0200

    ACME adaptation

commit c5d31bd8685abce37c8e254d15aac20bd1570d9f
Author: FeralChild64 <you@example.com>
Date:   Wed Sep 16 18:40:49 2020 +0200

    ACME adaptation

commit 29349826b38f8a89649171559dc8cf24c560aff1
Author: FeralChild64 <you@example.com>
Date:   Mon Sep 14 23:35:47 2020 +0200

    ACME adaptation

commit 8bcd6a621c4b11766d0cf34f79858ba90a67248e
Author: FeralChild64 <you@example.com>
Date:   Mon Sep 14 22:52:25 2020 +0200

    ACME adaptation

commit e87a69edc2ce4bfcc460c31e08dcc352a985f88d
Author: FeralChild64 <you@example.com>
Date:   Mon Sep 14 22:43:27 2020 +0200

    ACME adaptation

commit f49a097bd52e96d00b866c02bda7121e4543233c
Author: FeralChild64 <you@example.com>
Date:   Mon Sep 14 19:02:07 2020 +0200

    ACME adaptation

commit fa0e9214a633b8e8f867cc70925b390940dcd426
Author: FeralChild64 <you@example.com>
Date:   Mon Sep 14 17:47:19 2020 +0200

    ACME adaptation

commit 1b763b91e7a03e426227129c7f22f0ce57a4c197
Author: FeralChild64 <you@example.com>
Date:   Mon Sep 14 17:17:10 2020 +0200

    ACME adaptation

commit e92a4b57b232cd85eb1e71090b8a89c7c8461ebc
Author: FeralChild64 <you@example.com>
Date:   Mon Sep 14 17:15:37 2020 +0200

    ACME adaptation

commit de3c693e8a7e73ea5289198946058e3240894e6a
Author: FeralChild64 <you@example.com>
Date:   Mon Sep 14 17:10:05 2020 +0200

    ACME adaptation

commit f9bd7ae0f04e932d613be9ed5cb19af9be5d338e
Author: FeralChild64 <you@example.com>
Date:   Sun Sep 13 14:34:44 2020 +0200

    ACME adaptation

commit 694dee52555dbfc2b1f7f452a9671ff51106c057
Author: FeralChild64 <you@example.com>
Date:   Sun Sep 13 14:16:14 2020 +0200

    ACME adaptation

commit 0af2c55edfcd22942d9f25417eb0d35f55b71604
Author: FeralChild64 <you@example.com>
Date:   Fri Sep 11 17:38:09 2020 +0200

    ACME adaptation

commit 2015e17334bd56a1e8a13a5abc098d9c2e7ea44f
Author: FeralChild64 <you@example.com>
Date:   Fri Sep 11 16:46:05 2020 +0200

    ACME adaptation

commit b1e972162798d60f4483cd6cc261e856c20c2c8c
Author: FeralChild64 <you@example.com>
Date:   Fri Sep 11 16:24:31 2020 +0200

    ACME adaptation

commit 9d027e868466901ba53bf074a79ec8cf16273021
Author: FeralChild64 <you@example.com>
Date:   Fri Sep 11 15:04:31 2020 +0200

    ACME adaptation

commit 957186deddd1aa4f3b4f1aa1f421e4239a584e57
Author: FeralChild64 <you@example.com>
Date:   Thu Sep 10 22:49:07 2020 +0200

    ACME adaptation

commit b8060f67a455cfac109f08d96b62c360d693b931
Author: FeralChild64 <you@example.com>
Date:   Wed Sep 9 23:07:28 2020 +0200

    ACME adaptation

commit e54d004568f44bbfe5c070ef1d7cf3544112e497
Author: FeralChild64 <you@example.com>
Date:   Wed Sep 9 22:58:20 2020 +0200

    ACME adaptation

commit f90b77f073c5a605cb31c6ee451f65c8a8aff7d8
Author: FeralChild64 <you@example.com>
Date:   Wed Sep 9 22:12:09 2020 +0200

    ACME adaptation

commit b211bb4afcd9c58fe1f5c92f3007717d611cd531
Author: FeralChild64 <you@example.com>
Date:   Wed Sep 9 22:01:40 2020 +0200

    ACME adaptation

commit 8d7ea343b07e9e08e5f77f3c414758a6cffd0440
Author: FeralChild64 <you@example.com>
Date:   Wed Sep 9 21:38:34 2020 +0200

    ACME adaptation

commit 46413eb0d92d6400aba0ff8dfe556e61e8a44d78
Author: FeralChild64 <you@example.com>
Date:   Wed Sep 9 21:07:47 2020 +0200

    ACME adaptation

commit 9f98f69ecc21f7b74a5eb89e247f5a2c6fcb655d
Author: FeralChild64 <you@example.com>
Date:   Wed Sep 9 20:05:03 2020 +0200

    ACME adaptation

commit 7bb9f1cadc682c7e0a4a6796739d860d473ca110
Author: FeralChild64 <you@example.com>
Date:   Wed Sep 9 19:55:12 2020 +0200

    ACME adaptation

commit 5fc115392b5bdca6b56f67ad866b1884d2d2bdf8
Author: FeralChild64 <you@example.com>
Date:   Wed Sep 9 19:31:10 2020 +0200

    ACME adaptation

commit b7940fc60e568d859df9e3156f6bacc6d685b2cc
Author: FeralChild64 <you@example.com>
Date:   Wed Sep 9 19:16:09 2020 +0200

    ACME adaptation

commit 56288cb97197561afa0816b29c134ec1190e8eab
Author: FeralChild64 <you@example.com>
Date:   Wed Sep 9 18:48:23 2020 +0200

    ACME adaptation

commit 10401a60fc7922a53d782120ef6795d889140218
Author: FeralChild64 <you@example.com>
Date:   Wed Sep 9 16:34:16 2020 +0200

    ACME adaptation

commit 8ce76e4d2b56837a691ae84b1a412a2ae32a157b
Author: FeralChild64 <you@example.com>
Date:   Wed Sep 9 16:20:44 2020 +0200

    ACME adaptation

commit 33fade899fa6172ea6b5b5f6683bb61f544429fd
Author: FeralChild64 <you@example.com>
Date:   Wed Sep 9 15:28:46 2020 +0200

    ACME adaptation

commit a416f04734402fcfbc57a933731376df2e0180a1
Author: FeralChild64 <you@example.com>
Date:   Wed Sep 9 12:40:03 2020 +0200

    ACME adaptation

commit f8daee005b1d29f6912723be2ac94bc5fbeb0508
Author: FeralChild64 <you@example.com>
Date:   Mon Sep 7 23:29:54 2020 +0200

    ACME adaptation

commit 83fe6bdd0b08a44fdbfc6eefe323a4b194ccaf5b
Author: FeralChild64 <you@example.com>
Date:   Mon Sep 7 22:23:16 2020 +0200

    ACME adaptation

commit cb1f75620b9c83000a15c9c7f7acefdfee79a979
Author: FeralChild64 <you@example.com>
Date:   Mon Sep 7 19:23:12 2020 +0200

    ACME adaptation

commit e524d517c933ae1f0aeb49764d307fadb4845025
Author: FeralChild64 <you@example.com>
Date:   Sun Sep 6 08:24:25 2020 +0200

    ACME adaptation - replaced comments

commit 2ab572c3a21f4a78a7312d0e684bc11d91d1717a
Author: FeralChild64 <you@example.com>
Date:   Sat Sep 5 17:59:10 2020 +0200

    ACME adaptation - replaced the assembler
This commit is contained in:
FeralChild64 committed 2020-09-20 20:22:36 +02:00
1 parent bfc8291e41
commit c8d255130c
685 files changed
+15835 -16296

No files matched your search

+25 -25
View File
@@ -1,46 +1,46 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Math package - add FAC2 to FAC1, subtraction part
//
;
; Math package - add FAC2 to FAC1, subtraction part
;
// XXX test this
; XXX test this
add_FAC2_FAC1_sub:
// First verify that |FAC1| > |FAC2|, branch to proper variant if it is not
// We ignore FACOV here. Note, that exponents are already equalized
; First verify that |FAC1| > |FAC2|, branch to proper variant if it is not
; We ignore FACOV here. Note, that exponents are already equalized
lda FAC1_mantissa+0
cmp FAC2_mantissa+0
bcc add_FAC2_FAC1_sub_rev // if FAC1 < FAC2, branch
bne !+ // if FAC1 > FAC2, branch
bcc add_FAC2_FAC1_sub_rev ; if FAC1 < FAC2, branch
bne @1 ; if FAC1 > FAC2, branch
lda FAC1_mantissa+1
cmp FAC2_mantissa+1
bcc add_FAC2_FAC1_sub_rev // if FAC1 < FAC2, branch
bne !+ // if FAC1 > FAC2, branch
bcc add_FAC2_FAC1_sub_rev ; if FAC1 < FAC2, branch
bne @1 ; if FAC1 > FAC2, branch
lda FAC1_mantissa+2
cmp FAC2_mantissa+2
bcc add_FAC2_FAC1_sub_rev // if FAC1 < FAC2, branch
bne !+ // if FAC1 > FAC2, branch
bcc add_FAC2_FAC1_sub_rev ; if FAC1 < FAC2, branch
bne @1 ; if FAC1 > FAC2, branch
lda FAC1_mantissa+3
cmp FAC2_mantissa+3
bcc add_FAC2_FAC1_sub_rev // if FAC1 < FAC2, branch
bne !+ // if FAC1 > FAC2, branch
bcc add_FAC2_FAC1_sub_rev ; if FAC1 < FAC2, branch
bne @1 ; if FAC1 > FAC2, branch
// If we are here, than FAC1 is equal to FAC2 - so just set FAC1 to 0
; If we are here, than FAC1 is equal to FAC2 - so just set FAC1 to 0
lda #$00
sta FAC1_exponent
rts
!:
// Perform the subtration, FAC1 = FAC1 - FAC2
@1:
; Perform the subtration, FAC1 = FAC1 - FAC2
sec
lda FAC1_mantissa+3
@@ -59,17 +59,17 @@ add_FAC2_FAC1_sub:
sbc FAC2_mantissa+0
sta FAC1_mantissa+0
// Exponent should never need adaptation here
; Exponent should never need adaptation here
jmp normal_FAC1
add_FAC2_FAC1_sub_rev:
// Since |FAC1| < |FAC2|, toggle FAC1 sign before subtraction
; Since |FAC1| < |FAC2|, toggle FAC1 sign before subtraction
jsr toggle_sign_FAC1_skipcheck
// Perform the subtration, FAC1 = FAC2 - FAC1
; Perform the subtration, FAC1 = FAC2 - FAC1
sec
lda #$00
@@ -92,6 +92,6 @@ add_FAC2_FAC1_sub_rev:
sbc FAC1_mantissa+0
sta FAC1_mantissa+0
// Exponent should never need adaptation here
; Exponent should never need adaptation here
jmp normal_FAC1
+27 -27
View File
@@ -1,44 +1,44 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Math package - align FAC1 and FAC2 exponents for addition
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 115
// - https://www.c64-wiki.com/wiki/BASIC-ROM
;
; Math package - align FAC1 and FAC2 exponents for addition
;
; See also:
; - [CM64] Computes Mapping the Commodore 64 - page 115
; - https://www.c64-wiki.com/wiki/BASIC-ROM
add_align_exponents:
// XXX assume here none of the exponents is 0, check if this is true for orignal ROMs
; XXX assume here none of the exponents is 0, check if this is true for orignal ROMs
lda FAC1_exponent
cmp FAC2_exponent
beq add_align_exponents_done // branch if exponents the same
beq add_align_exponents_done ; branch if exponents the same
bcs add_align_exponent_FAC2
// FALLTROUGH
; FALLTROUGH
add_align_exponent_FAC1:
// First check the exponent difference
; First check the exponent difference
lda FAC2_exponent
sec
sbc FAC1_exponent
cmp #$28
bcs add_align_exponent_FAC1_zero // branch if difference is very high
bcs add_align_exponent_FAC1_zero ; branch if difference is very high
cmp #$08
bcc add_align_exponent_FAC1_bit
// FALLTROUGH
; FALLTROUGH
add_align_exponent_FAC1_byte:
// Add 8 to exponent, divide mantissa by 256
; Add 8 to exponent, divide mantissa by 256
lda FAC1_exponent
clc
@@ -56,11 +56,11 @@ add_align_exponent_FAC1_byte:
lda #$00
sta FAC1_mantissa+0
beq add_align_exponent_FAC1 // branch always - next iteration
beq add_align_exponent_FAC1 ; branch always - next iteration
add_align_exponent_FAC1_bit:
// Increment exponent, divide mantissa by 2
; Increment exponent, divide mantissa by 2
inc FAC1_exponent
@@ -73,7 +73,7 @@ add_align_exponent_FAC1_bit:
lda FAC1_exponent
cmp FAC2_exponent
bne add_align_exponent_FAC1_bit // branch if next iteration needed
bne add_align_exponent_FAC1_bit ; branch if next iteration needed
rts
@@ -90,7 +90,7 @@ add_align_exponent_FAC1_zero:
lda FAC2_exponent
sta FAC1_exponent
// FALLTROUGH
; FALLTROUGH
add_align_exponents_done:
@@ -100,22 +100,22 @@ add_align_exponents_done:
add_align_exponent_FAC2:
// First check the exponent difference, Carry already set here
; First check the exponent difference, Carry already set here
lda FAC1_exponent
sbc FAC2_exponent
cmp #$20
bcs add_align_exponent_FAC2_zero // branch if difference is very high
bcs add_align_exponent_FAC2_zero ; branch if difference is very high
cmp #$08
bcc add_align_exponent_FAC2_bit
// FALLTROUGH
; FALLTROUGH
add_align_exponent_FAC2_byte:
// Add 8 to exponent, divide mantissa by 256
; Add 8 to exponent, divide mantissa by 256
lda FAC2_exponent
clc
@@ -131,11 +131,11 @@ add_align_exponent_FAC2_byte:
lda #$00
sta FAC2_mantissa+0
beq add_align_exponent_FAC2 // branch always - next iteration
beq add_align_exponent_FAC2 ; branch always - next iteration
add_align_exponent_FAC2_bit:
// Increment exponent, divide mantissa by 2
; Increment exponent, divide mantissa by 2
inc FAC2_exponent
@@ -147,7 +147,7 @@ add_align_exponent_FAC2_bit:
lda FAC1_exponent
cmp FAC2_exponent
bne add_align_exponent_FAC2_bit // branch if next iteration needed
bne add_align_exponent_FAC2_bit ; branch if next iteration needed
rts
+9 -9
View File
@@ -1,13 +1,13 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Math package - add 0.5 to FAC1
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 112
;
; Math package - add 0.5 to FAC1
;
; See also:
; - [CM64] Computes Mapping the Commodore 64 - page 112
add_HALF_FAC1:
+17 -17
View File
@@ -1,23 +1,23 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Math package - subtract FAC1 from memory variable
//
// Input:
// - .A - address low byte
// - .Y - address high byte
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 112
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
;
; Math package - subtract FAC1 from memory variable
;
; Input:
; - .A - address low byte
; - .Y - address high byte
;
; See also:
; - [CM64] Computes Mapping the Commodore 64 - page 112
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
;
sub_MEM_FAC1:
jsr mov_MEM_FAC2
// FALLTROUGH to sub_FAC2_FAC1
; FALLTROUGH to sub_FAC2_FAC1
+15 -15
View File
@@ -1,25 +1,25 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Math package - subtract FAC1 from FAC2
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 112
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
;
; Math package - subtract FAC1 from FAC2
;
; See also:
; - [CM64] Computes Mapping the Commodore 64 - page 112
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
;
// XXX test this
; XXX test this
sub_FAC2_FAC1:
// Toggle FAC1 sign
; Toggle FAC1 sign
lda FAC1_sign
eor #$FF
sta FAC1_sign
// Perform addition
; Perform addition
jmp add_FAC2_FAC1
+5 -5
View File
@@ -1,9 +1,9 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
// Just a compatibility jump - our routine is longer than original one
; Just a compatibility jump - our routine is longer than original one
jmp add_align_exponents
+17 -17
View File
@@ -1,23 +1,23 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Math package - add memory variable to FAC1
//
// Input:
// - .A - address low byte
// - .Y - address high byte
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 112
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
;
; Math package - add memory variable to FAC1
;
; Input:
; - .A - address low byte
; - .Y - address high byte
;
; See also:
; - [CM64] Computes Mapping the Commodore 64 - page 112
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
;
add_MEM_FAC1:
jsr mov_MEM_FAC2
// FALLTROUGH to add_FAC2_FAC1
; FALLTROUGH to add_FAC2_FAC1
+31 -31
View File
@@ -1,49 +1,49 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Math package - add FAC2 to FAC1
//
// Input:
// - .A - must load FAC1 exponent ($61) beforehand to set the zero flag
//
// Note:
// - load FAC2 after FAC1, or mimic the Kernals sign comparison (XXX do we need it?)
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 112
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
;
; Math package - add FAC2 to FAC1
;
; Input:
; - .A - must load FAC1 exponent ($61) beforehand to set the zero flag
;
; Note:
; - load FAC2 after FAC1, or mimic the Kernals sign comparison (XXX do we need it?)
;
; See also:
; - [CM64] Computes Mapping the Commodore 64 - page 112
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
;
// XXX test this
; XXX test this
add_FAC2_FAC1:
// Check if FAC2 is 0; if so leave FAC1 without changes
; Check if FAC2 is 0; if so leave FAC1 without changes
lda FAC2_exponent
beq add_FAC2_FAC1_done
// If FAC1 is 0, if so just copy FAC2 to FAC1
; If FAC1 is 0, if so just copy FAC2 to FAC1
lda FAC1_exponent
beq_16 mov_FAC2_FAC1
+beq mov_FAC2_FAC1
// Make sure the exponents are aligned
; Make sure the exponents are aligned
jsr add_align_exponents
// Check whether signs are the same
; Check whether signs are the same
lda FAC1_sign
eor FAC2_sign
bmi_16 add_FAC2_FAC1_sub // branch if signs are opposite
+bmi add_FAC2_FAC1_sub ; branch if signs are opposite
// Perform the addition
; Perform the addition
clc
lda FAC2_mantissa+3
@@ -62,14 +62,14 @@ add_FAC2_FAC1:
adc FAC1_mantissa+0
sta FAC1_mantissa+0
bcc_16 normal_FAC1 // end if no need to adapt the exponent
+bcc normal_FAC1 ; end if no need to adapt the exponent
inc FAC1_exponent
bne add_FAC2_FAC1_adapt_mantissa // end if no overflow
bne add_FAC2_FAC1_adapt_mantissa ; end if no overflow
// FALLTROUGH
; FALLTROUGH
set_FAC1_max: // entry used by other routines too
set_FAC1_max: ; entry used by other routines too
lda #$FF
sta FAC1_exponent
@@ -78,7 +78,7 @@ set_FAC1_max: // entry used by other routines too
sta FAC1_mantissa+1
sta FAC1_mantissa+0
// FALLTROUGH
; FALLTROUGH
add_FAC2_FAC1_done:
+5 -5
View File
@@ -1,8 +1,8 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
// Just a compatibility jump - our routine is longer than original one
; Just a compatibility jump - our routine is longer than original one
jmp normal_FAC1
+20 -20
View File
@@ -1,26 +1,26 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Math package - multiplies FAC1 by RAM
//
// Input:
// - .A - address low byte
// - .Y - address high byte
//
// Note:
// - C64 Wiki calls it FMULT, this looks like a mistake
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 113
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
;
; Math package - multiplies FAC1 by RAM
;
; Input:
; - .A - address low byte
; - .Y - address high byte
;
; Note:
; - C64 Wiki calls it FMULT, this looks like a mistake
;
; See also:
; - [CM64] Computes Mapping the Commodore 64 - page 113
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
;
mul_MEM_FAC1:
jsr mov_MEM_FAC2
// FALLTROUGH to mul_FAC2_FAC1
; FALLTROUGH to mul_FAC2_FAC1
+5 -5
View File
@@ -1,8 +1,8 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
// Just a compatibility jump - our routine is longer than original one
; Just a compatibility jump - our routine is longer than original one
jmp mul_FAC2_FAC1
+5 -5
View File
@@ -1,8 +1,8 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
// Just a compatibility jump - our routine is longer than original one
; Just a compatibility jump - our routine is longer than original one
jmp mov_MEM_FAC2
+17 -17
View File
@@ -1,38 +1,38 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Math package - multiply FAC1 by 10
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 114
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
;
; Math package - multiply FAC1 by 10
;
; See also:
; - [CM64] Computes Mapping the Commodore 64 - page 114
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
;
mul10_FAC1:
// Handle special case of FAC1 equal 0
; Handle special case of FAC1 equal 0
lda FAC1_exponent
beq mul10_FAC1_done
// Start by multiplying FAC1 by 2
; Start by multiplying FAC1 by 2
jsr mul10_FAC1_mul2
// Move FAC1 to FAC2, so that FAC1 = FAC2 = 2 * initial
; Move FAC1 to FAC2, so that FAC1 = FAC2 = 2 * initial
jsr mov_FAC1_FAC2
// Multiply FAC1 by 4
; Multiply FAC1 by 4
jsr mul10_FAC1_mul2
jsr mul10_FAC1_mul2
// Now we have FAC1 = 8 * initial and FAC2 = 2 * initial; so just add these 2 values
; Now we have FAC1 = 8 * initial and FAC2 = 2 * initial; so just add these 2 values
jmp add_FAC2_FAC1
+16 -16
View File
@@ -1,22 +1,22 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Math package - divide FAC1 by 10, result is always positive
//
// Notes:
// - shifts FAC1 to FAC2, loads FAC1 with the constant 10, falls through to the division routine
;
; Math package - divide FAC1 by 10, result is always positive
;
; Notes:
; - shifts FAC1 to FAC2, loads FAC1 with the constant 10, falls through to the division routine
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 114
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
;
; See also:
; - [CM64] Computes Mapping the Commodore 64 - page 114
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
;
// XXX test this
; XXX test this
div10_FAC1_p:
+17 -17
View File
@@ -1,23 +1,23 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Math package - divide RAM by FAC1
//
// Input:
// - .A - address low byte
// - .Y - address high byte
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 114
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
;
; Math package - divide RAM by FAC1
;
; Input:
; - .A - address low byte
; - .Y - address high byte
;
; See also:
; - [CM64] Computes Mapping the Commodore 64 - page 114
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
;
div_MEM_FAC1:
jsr mov_MEM_FAC2
// FALLTROUGH to div_FAC2_FAC1
; FALLTROUGH to div_FAC2_FAC1
+37 -37
View File
@@ -1,75 +1,75 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Math package - divide FAC2 (dividend) by FAC1 (divisor)
//
// Input:
// - .A - must load FAC1 exponent ($61) beforehand to set the zero flag (but our routine does not need this)
//
// Output:
// - FAC1
//
// Note:
// - some documentation suggest this is a division leaving quotient and remainder (left in FAC2),
// but it seems (experimentation) that this is not true
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 114
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
;
; Math package - divide FAC2 (dividend) by FAC1 (divisor)
;
; Input:
; - .A - must load FAC1 exponent ($61) beforehand to set the zero flag (but our routine does not need this)
;
; Output:
; - FAC1
;
; Note:
; - some documentation suggest this is a division leaving quotient and remainder (left in FAC2),
; but it seems (experimentation) that this is not true
;
; See also:
; - [CM64] Computes Mapping the Commodore 64 - page 114
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
;
div_FAC2_FAC1:
// 'Pamiętaj, cholero - nie dziel przez zero!' - ancient polish proverb
; 'Pamiętaj, cholero - nie dziel przez zero!' - ancient polish proverb
lda FAC1_exponent
beq_16 do_DIVISION_BY_ZERO_error
+beq do_DIVISION_BY_ZERO_error
// Handle special case - dividing 0 by non-zero value
; Handle special case - dividing 0 by non-zero value
lda FAC2_exponent
beq_16 set_FAC1_zero
+beq set_FAC1_zero
// Multiply signs
; Multiply signs
lda FAC1_sign
eor FAC2_sign
sta FAC1_sign
// Subtract the exponents
; Subtract the exponents
lda #$A0 // correction for bias and FAC2 digits
lda #$A0 ; correction for bias and FAC2 digits
sta RESHO+0
lda #$00
sta RESHO+1
lda FAC2_exponent // add FAC2 exponent to temporary variable
lda FAC2_exponent ; add FAC2 exponent to temporary variable
jsr muldiv_RESHO_01_add_A
lda RESHO+0 // subtract FAC1 exponent from temporary variable
lda RESHO+0 ; subtract FAC1 exponent from temporary variable
sec
sbc FAC1_exponent
sta RESHO+0
bcs !+
bcs @1
dec RESHO+1
!:
@1:
lda RESHO+1
bmi_16 set_FAC1_zero // result too low, set 0 and quit
+bmi set_FAC1_zero ; result too low, set 0 and quit
lda RESHO+0
sta FAC1_exponent
// Divide the mantissas
; Divide the mantissas
jsr div_FAC1_denorm
jsr muldiv_RESHO_set_0
jsr div_mantissas
// Copy the result to FAC1 - XXX we probably already have similar code somewhere...
; Copy the result to FAC1 - XXX we probably already have similar code somewhere...
lda FAC2_mantissa+3
sta FAC1_mantissa+3
@@ -80,6 +80,6 @@ div_FAC2_FAC1:
lda FAC2_mantissa+0
sta FAC1_mantissa+0
// Normalize and quit
; Normalize and quit
jmp normal_FAC1
+5 -5
View File
@@ -1,9 +1,9 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
// Just a compatibility jump - our routine is longer than original one
; Just a compatibility jump - our routine is longer than original one
jmp round_FAC1
+18 -18
View File
@@ -1,26 +1,26 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Math package - evaluate FAC1 sign, to .A
//
// Output:
// - .A - 0 for FAC1 equal 0, 1 for FAC1 > 0, -1 for FAC1 < 0
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 115
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
;
; Math package - evaluate FAC1 sign, to .A
;
; Output:
; - .A - 0 for FAC1 equal 0, 1 for FAC1 > 0, -1 for FAC1 < 0
;
; See also:
; - [CM64] Computes Mapping the Commodore 64 - page 115
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
;
sgn_FAC1_A:
lda FAC1_exponent
beq !+
beq @1
lda FAC1_sign
bne !+
bne @1
lda #$01
!:
@1:
rts
+16 -16
View File
@@ -1,22 +1,22 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Math package - square root of FAC1
//
// Note:
// - transfers FAC1 to FAC2 and falls through to SQR2
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 117
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
;
; Math package - square root of FAC1
;
; Note:
; - transfers FAC1 to FAC2 and falls through to SQR2
;
; See also:
; - [CM64] Computes Mapping the Commodore 64 - page 117
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
;
sqr_FAC1:
jsr mov_FAC1_FAC2
// FALLLTROUGH to sqr_FAC2
; FALLLTROUGH to sqr_FAC2
+18 -18
View File
@@ -1,24 +1,24 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Math package - set FAC1 as RAM raised to the power of FAC2
//
// Input:
// - .A - address low byte
// - .Y - address high byte
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 117 (FPWRT)
// - https://www.c64-wiki.com/wiki/BASIC-ROM
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
;
; Math package - set FAC1 as RAM raised to the power of FAC2
;
; Input:
; - .A - address low byte
; - .Y - address high byte
;
; See also:
; - [CM64] Computes Mapping the Commodore 64 - page 117 (FPWRT)
; - https://www.c64-wiki.com/wiki/BASIC-ROM
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
;
pwr_FAC2_MEM:
jsr mov_MEM_FAC1
// FALLTROUGH to pwr_FAC2_FAC1
; FALLTROUGH to pwr_FAC2_FAC1
+19 -15
View File
@@ -1,27 +1,31 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Math package - toggle FAC1 sign (if not 0)
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 117
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
//
;
; Math package - toggle FAC1 sign (if not 0)
;
; See also:
; - [CM64] Computes Mapping the Commodore 64 - page 117
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
;
toggle_sign_FAC1:
lda FAC1_exponent
beq !+ // do not toggle the sign if value is 0
beq toggle_sign_FAC1_end ; do not toggle the sign if value is 0
// FALLTROUGH
; FALLTROUGH
toggle_sign_FAC1_skipcheck: // entry for other routines
toggle_sign_FAC1_skipcheck: ; entry for other routines
lda FAC1_sign
eor #$FF
sta FAC1_sign
!:
; FALLTROUGH
toggle_sign_FAC1_end:
rts
+19 -19
View File
@@ -1,33 +1,33 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Math package - denormalize FAC1 mantissa and adapt its exponent accordingly for division
//
;
; Math package - denormalize FAC1 mantissa and adapt its exponent accordingly for division
;
div_FAC1_denorm:
// Set FACOV to 0, no need for increased precision here
; Set FACOV to 0, no need for increased precision here
lda #$00
sta FACOV
// Start by moving whole bytes, if possible
; Start by moving whole bytes, if possible
lda FAC1_mantissa+3
bne div_FAC1_denorm_by_bit // branch if last byte of mantissa is non-zero
bne div_FAC1_denorm_by_bit ; branch if last byte of mantissa is non-zero
lda FAC1_exponent
cmp #$08
bcc div_FAC1_denorm_by_bit // branch if not suitable to increment exponent by 8
bcc div_FAC1_denorm_by_bit ; branch if not suitable to increment exponent by 8
// Increment exponent
; Increment exponent
sbc #$08 // Carry already sec
sbc #$08 ; Carry already sec
sta FAC1_exponent
// Move mantissa bytes
; Move mantissa bytes
lda FAC1_mantissa+2
sta FAC1_mantissa+3
@@ -38,22 +38,22 @@ div_FAC1_denorm:
lda #$00
sta FAC1_mantissa+0
beq div_FAC1_denorm // branch always
beq div_FAC1_denorm ; branch always
div_FAC1_denorm_by_bit:
lda FAC1_mantissa+3
and #$01
bne div_FAC1_denorm_done // branch if lowest bit of mantissa is already 1
bne div_FAC1_denorm_done ; branch if lowest bit of mantissa is already 1
lda FAC1_exponent
beq div_FAC1_denorm_done // branch if not suitable to decrement exponent
beq div_FAC1_denorm_done ; branch if not suitable to decrement exponent
// Decrement exponent
; Decrement exponent
dec FAC1_exponent
// Move mantissa bits
; Move mantissa bits
clc
ror FAC1_mantissa+0
@@ -61,7 +61,7 @@ div_FAC1_denorm_by_bit:
ror FAC1_mantissa+2
ror FAC1_mantissa+3
bcc div_FAC1_denorm_by_bit // branch always
bcc div_FAC1_denorm_by_bit ; branch always
div_FAC1_denorm_done:
+21 -21
View File
@@ -1,41 +1,41 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
// Math package - 32-bit mantissa division, based on code by Verz
//
// divident: FAC2_mantissa, divisor: FAC1_mantissa (without FACOV), result: FAC2_mantissa, remainder: RESHO
// temporary storage: INDEX+0, INDEX+1, INDEX+2, INDEX+3
//
// RESHO (remainder) should be set to 0 before
//
// see https://codebase64.org/doku.php?id=base:24bit_division_24-bit_result
; Math package - 32-bit mantissa division, based on code by Verz
;
; divident: FAC2_mantissa, divisor: FAC1_mantissa (without FACOV), result: FAC2_mantissa, remainder: RESHO
; temporary storage: INDEX+0, INDEX+1, INDEX+2, INDEX+3
;
; RESHO (remainder) should be set to 0 before
;
; see https://codebase64.org/doku.php?id=base:24bit_division_24-bit_result
// XXX test this
; XXX test this
div_mantissas:
ldx #32 // repeat for each bit
ldx #32 ; repeat for each bit
// FALLTROUGH
; FALLTROUGH
div_mantissas_loop:
// Multiply divident by 2, msb -> Carry
; Multiply divident by 2, msb -> Carry
asl FAC2_mantissa+3
rol FAC2_mantissa+2
rol FAC2_mantissa+1
rol FAC2_mantissa+0
// Multiply remainder by 2, lsb <- Carry
; Multiply remainder by 2, lsb <- Carry
rol RESHO+3
rol RESHO+2
rol RESHO+1
rol RESHO+0
// Subtract divisor from the remainder, result to INDEX and .Y
; Subtract divisor from the remainder, result to INDEX and .Y
sec
lda RESHO+3
@@ -53,10 +53,10 @@ div_mantissas_loop:
lda RESHO+0
sbc FAC1_mantissa+0
bcc div_mantissas_skip // if Carry is not set then divisor did not fit in remainder yet
bcc div_mantissas_skip ; if Carry is not set then divisor did not fit in remainder yet
sta INDEX+0
// Save subtraction result as new remainder
; Save subtraction result as new remainder
lda INDEX+3
sta RESHO+3
@@ -70,11 +70,11 @@ div_mantissas_loop:
lda INDEX+0
sta RESHO+0
// Increment result cause divisor fit in 1 times
; Increment result cause divisor fit in 1 times
inc FAC2_mantissa+3
// FALLTROUGH
; FALLTROUGH
div_mantissas_skip:
+13 -13
View File
@@ -1,20 +1,20 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Random number generator routine
//
// Input:
// - FAC1 (0 - reinitialize the seed with random value, negative - create seed from FAC1)
//
// Output:
// - FAC1
//
;
; Random number generator routine
;
; Input:
; - FAC1 (0 - reinitialize the seed with random value, negative - create seed from FAC1)
;
; Output:
; - FAC1
;
rnd_FAC1:
jsr sgn_FAC1_A
// FALLTROUGH to rnd_A
; FALLTROUGH to rnd_A
+17 -17
View File
@@ -1,26 +1,26 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Random number generator routine
//
// Input:
// - .A (0 - reinitialize the seed with random value, $80 or above - create seed from FAC1)
//
// Output:
// - FAC1
//
// See also:
// - https://www.atarimagazines.com/compute/issue72/random_numbers.php
//
;
; Random number generator routine
;
; Input:
; - .A (0 - reinitialize the seed with random value, $80 or above - create seed from FAC1)
;
; Output:
; - FAC1
;
; See also:
; - https://www.atarimagazines.com/compute/issue72/random_numbers.php
;
rnd_A:
cmp #$00
beq_16 rnd_seed_init
+beq rnd_seed_init
cmp #$80
bcc_16 rnd_generate
+bcc rnd_generate
jmp rnd_seed_from_FAC1
+18 -18
View File
@@ -1,17 +1,17 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// A fast pseudorandom generator, modified idea from:
// - https://codebase64.org/doku.php?id=base:32bit_galois_lfsr
//
// Output:
// - FAC1
//
// See also:
// - https://www.atarimagazines.com/compute/issue72/random_numbers.php
//
;
; A fast pseudorandom generator, modified idea from:
; - https://codebase64.org/doku.php?id=base:32bit_galois_lfsr
;
; Output:
; - FAC1
;
; See also:
; - https://www.atarimagazines.com/compute/issue72/random_numbers.php
;
rnd_generate:
@@ -38,13 +38,13 @@ rnd_generate:
eor #$04
sta RNDX+4
sec // make sure Carry is always set, for adc
sec ; make sure Carry is always set, for adc
// FALLTROUGH
; FALLTROUGH
rnd_generate_copy:
// Copy the generated number to FAC1, mangle it a little
; Copy the generated number to FAC1, mangle it a little
lda RNDX+3
adc #$C6
@@ -63,7 +63,7 @@ rnd_generate_copy:
rol
sta FAC1_mantissa+3
// FALLTROUGH
; FALLTROUGH
rnd_generate_finalize:
@@ -71,7 +71,7 @@ rnd_generate_finalize:
sta FAC1_sign
lda #$80
sta FACOV // just to prevent 0 after normalization
sta FACOV ; just to prevent 0 after normalization
sta FAC1_exponent
jmp normal_FAC1
+8 -8
View File
@@ -1,16 +1,16 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Multiply FAC1 by 2, do not normalize
//
;
; Multiply FAC1 by 2, do not normalize
;
mul10_FAC1_mul2:
// Increment the exponent
; Increment the exponent
inc FAC1_exponent
beq_16 set_FAC1_max
+beq set_FAC1_max
rts
+55 -55
View File
@@ -1,21 +1,21 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Math package - multiplies FAC1 by FAC2
//
// Input:
// - .A - must load FAC1 exponent ($61) beforehand to set the zero flag
//
// Note:
// - load FAC2 after FAC1, or mimic the Kernals sign comparison (XXX do we need it?)
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 113 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
//
;
; Math package - multiplies FAC1 by FAC2
;
; Input:
; - .A - must load FAC1 exponent ($61) beforehand to set the zero flag
;
; Note:
; - load FAC2 after FAC1, or mimic the Kernals sign comparison (XXX do we need it?)
;
; See also:
; - [CM64] Computes Mapping the Commodore 64 - page 113 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
;
set_FAC1_zero:
@@ -28,23 +28,23 @@ mul_FAC2_FAC1_done:
mul_FAC2_FAC1:
// First handle special case of multiplying by 0
; First handle special case of multiplying by 0
lda FAC1_exponent
beq mul_FAC2_FAC1_done
lda FAC2_exponent
bne !+
bne @1
sta FAC1_exponent
beq mul_FAC2_FAC1_done
!:
// Multiply signs
@1:
; Multiply signs
lda FAC1_sign
eor FAC2_sign
sta FAC1_sign
// Add the exponents (subtract the bias) - XXX can this be optimized somehow?
; Add the exponents (subtract the bias) - XXX can this be optimized somehow?
jsr muldiv_RESHO_set_0
@@ -55,58 +55,58 @@ mul_FAC2_FAC1:
jsr muldiv_RESHO_01_add_A
lda RESHO+0
sbc #$80 // we need to correct double BIAS
sbc #$80 ; we need to correct double BIAS
sta RESHO+0
bcs !+
bcs @2
lda RESHO+1
sbc #$00
bcc set_FAC1_zero
sta RESHO+1
!:
@2:
lda RESHO+1
bne_16 set_FAC1_max // overflow
+bne set_FAC1_max ; overflow
lda RESHO+0
sta FAC1_exponent
// Multiply the mantissas
; Multiply the mantissas
jsr muldiv_RESHO_set_0
clc
// XXX maybe we should preserve .X on stack? this will not cost us too much
; XXX maybe we should preserve .X on stack? this will not cost us too much
lda FACOV
jsr mul_FAC2_FAC1_by_A
jsr mul_FAC2_FAC1_shift
bcc !+
bcc @3
inc RESHO+0
!:
@3:
lda FAC1_mantissa+3
jsr mul_FAC2_FAC1_by_A
jsr mul_FAC2_FAC1_shift
bcc !+
bcc @4
inc RESHO+0
!:
@4:
lda FAC1_mantissa+2
jsr mul_FAC2_FAC1_by_A
jsr mul_FAC2_FAC1_shift
bcc !+
bcc @5
inc RESHO+0
!:
@5:
lda FAC1_mantissa+1
jsr mul_FAC2_FAC1_by_A
jsr mul_FAC2_FAC1_shift
bcc !+
bcc @6
inc RESHO+0
!:
@6:
lda FAC1_mantissa+0
jsr mul_FAC2_FAC1_by_A
jsr mul_FAC2_FAC1_shift
bcc !+
bcc @7
inc RESHO+0
!:
// Copy RESHO to FAC1 mantissa
@7:
; Copy RESHO to FAC1 mantissa
lda RESHO+4
sta FACOV
@@ -119,12 +119,12 @@ mul_FAC2_FAC1:
lda RESHO+0
sta FAC1_mantissa+0
// Correct the exponent
; Correct the exponent
lda FAC1_exponent
clc
adc #$08
bcs_16 set_FAC1_max // branch if overflow
+bcs set_FAC1_max ; branch if overflow
sta FAC1_exponent
jmp normal_FAC1
@@ -133,7 +133,7 @@ mul_FAC2_FAC1_by_A:
beq mul_FAC2_FAC1_by_A_done
sta INDEX+3
// Multiply FAC2_mantissa+3
; Multiply FAC2_mantissa+3
lda FAC2_mantissa+3
jsr mul_FAC2_FAC1_8x8
@@ -143,14 +143,14 @@ mul_FAC2_FAC1_by_A:
txa
adc RESHO+3
sta RESHO+3
bcc !+
bcc @8
inc RESHO+2
bne !+
bne @8
inc RESHO+1
bne !+
bne @8
inc RESHO+0
!:
// Multiply FAC2_mantissa+2
@8:
; Multiply FAC2_mantissa+2
lda FAC2_mantissa+2
jsr mul_FAC2_FAC1_8x8
@@ -160,12 +160,12 @@ mul_FAC2_FAC1_by_A:
txa
adc RESHO+2
sta RESHO+2
bcc !+
bcc @9
inc RESHO+1
bne !+
bne @9
inc RESHO+0
!:
// Multiply FAC2_mantissa+1
@9:
; Multiply FAC2_mantissa+1
lda FAC2_mantissa+1
jsr mul_FAC2_FAC1_8x8
@@ -175,10 +175,10 @@ mul_FAC2_FAC1_by_A:
txa
adc RESHO+1
sta RESHO+1
bcc !+
bcc @10
inc RESHO+0
!:
// Multiply FAC2_mantissa+0
@10:
; Multiply FAC2_mantissa+0
lda FAC2_mantissa+0
jsr mul_FAC2_FAC1_8x8
@@ -188,7 +188,7 @@ mul_FAC2_FAC1_by_A:
adc RESHO+0
sta RESHO+0
// FALLTROUGH
; FALLTROUGH
mul_FAC2_FAC1_by_A_done:
+42 -43
View File
@@ -1,20 +1,20 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Helper routine, based on code by djmips (fast version) from:
// - https://codebase64.org/doku.php?id=base:8bit_multiplication_16bit_product_fast_no_tables
// or by code by Graham (small version) from:
// - https://codebase64.org/doku.php?id=base:short_8bit_multiplication_16bit_product
//
// input: .A (and Zero flag set according to .A), INDEX+3
// output: .X (high byte), .A (low byte), carry always clear
//
;
; Helper routine, based on code by djmips (fast version) from:
; - https://codebase64.org/doku.php?id=base:8bit_multiplication_16bit_product_fast_no_tables
; or by code by Graham (small version) from:
; - https://codebase64.org/doku.php?id=base:short_8bit_multiplication_16bit_product
;
; input: .A (and Zero flag set according to .A), INDEX+3
; output: .X (high byte), .A (low byte), carry always clear
;
mul_FAC2_FAC1_8x8:
// Special cases - handle multiplication by 0
; Special cases - handle multiplication by 0
beq mul_FAC2_FAC1_8x8_zero
sta INDEX+2
@@ -22,54 +22,54 @@ mul_FAC2_FAC1_8x8:
lda INDEX+3
beq mul_FAC2_FAC1_8x8_zero
// Multiply INDEX+2 * INDEX+3
; Multiply INDEX+2 * INDEX+3
#if !HAS_SMALL_BASIC
!ifndef HAS_SMALL_BASIC {
// Fast multiplication routine
; Fast multiplication routine
lda #$00
dec INDEX+3 // decrement because we will be adding with carry set for speed (an extra one)
dec INDEX+3 ; decrement because we will be adding with carry set for speed (an extra one)
ror INDEX+2
bcc !+
bcc @1
adc INDEX+3
!:
@1:
ror
ror INDEX+2
bcc !+
bcc @2
adc INDEX+3
!:
@2:
ror
ror INDEX+2
bcc !+
bcc @3
adc INDEX+3
!:
@3:
ror
ror INDEX+2
bcc !+
bcc @4
adc INDEX+3
!:
@4:
ror
ror INDEX+2
bcc !+
bcc @5
adc INDEX+3
!:
@5:
ror
ror INDEX+2
bcc !+
bcc @6
adc INDEX+3
!:
@6:
ror
ror INDEX+2
bcc !+
bcc @7
adc INDEX+3
!:
@7:
ror
ror INDEX+2
bcc !+
bcc @8
adc INDEX+3
!:
@8:
ror
ror INDEX+2
inc INDEX+3
@@ -77,32 +77,31 @@ mul_FAC2_FAC1_8x8:
tax
lda INDEX+2
#else
} else {
// Small multiplication routine
; Small multiplication routine
lda #$00
ldx #$08
clc
!:
bcc !+
@9:
bcc @10
clc
adc INDEX+3
!:
@10:
ror
ror INDEX+2
dex
bpl !--
bpl @9
ldx INDEX+2
// Reverse return byte order, to match fast version
// (such order is easier top handle for the callers)
; Reverse return byte order, to match fast version
; (such order is easier top handle for the callers)
stx INDEX+2
tax
lda INDEX+2
#endif
}
clc
rts
+17 -17
View File
@@ -1,22 +1,22 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Shift RESHO by one byte - for multiplication
//
;
; Shift RESHO by one byte - for multiplication
;
mul_FAC2_FAC1_shift:
// Check if rounding is needed
; Check if rounding is needed
php
clc
lda RESHO+4
bpl !+
bpl @1
sec
!:
// Copy bytes
@1:
; Copy bytes
lda RESHO+3
sta RESHO+4
@@ -28,19 +28,19 @@ mul_FAC2_FAC1_shift:
sta RESHO+1
lda #$00
sta RESHO+0
bcc !+
bcc @2
// Perform rounding
; Perform rounding
inc RESHO+4
bne !+
bne @2
inc RESHO+3
bne !+
bne @2
inc RESHO+2
bne !+
bne @2
inc RESHO+1
bne !+
bne @2
inc RESHO+0
!:
@2:
plp
rts
+8 -8
View File
@@ -1,10 +1,10 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Math package - helper routines for RESHO manipulation
//
;
; Math package - helper routines for RESHO manipulation
;
muldiv_RESHO_set_0:
@@ -24,7 +24,7 @@ muldiv_RESHO_01_add_A:
clc
adc RESHO+0
sta RESHO+0
bcc !+
bcc @1
inc RESHO+1
!:
@1:
rts
+32 -32
View File
@@ -1,48 +1,48 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Math package - normalize FAC1
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 113
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
;
; Math package - normalize FAC1
;
; See also:
; - [CM64] Computes Mapping the Commodore 64 - page 113
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
;
// XXX test this
; XXX test this
normal_FAC1:
lda FAC1_exponent
beq normal_FAC1_end // branch if our float is 0
beq normal_FAC1_end ; branch if our float is 0
// FALLTROUGH
; FALLTROUGH
normal_FAC1_check_mantissa_byte:
lda FAC1_mantissa+0
beq normal_FAC1_by_byte // branch if we can move the whole byte
beq normal_FAC1_by_byte ; branch if we can move the whole byte
// FALLTROUGH
; FALLTROUGH
normal_FAC1_check_mantissa_bit:
lda FAC1_mantissa+0 // XXX optimize for 65CE02?
lda FAC1_mantissa+0 ; XXX optimize for 65CE02?
and #$80
bne normal_FAC1_end // branch if already normalized
bne normal_FAC1_end ; branch if already normalized
// FALLTROUGH
; FALLTROUGH
normal_FAC1_by_bit:
// Decrement the exponent
; Decrement the exponent
dec FAC1_exponent
beq normal_FAC1_end // exponent reached 0, nothing more to do
beq normal_FAC1_end ; exponent reached 0, nothing more to do
// Multiply the mantissa by 2
; Multiply the mantissa by 2
asl FACOV
rol FAC1_mantissa+3
@@ -50,23 +50,23 @@ normal_FAC1_by_bit:
rol FAC1_mantissa+1
rol FAC1_mantissa+0
bcc normal_FAC1_check_mantissa_bit // branch if next iteration needed
bcc normal_FAC1_check_mantissa_bit ; branch if next iteration needed
rts
normal_FAC1_by_byte:
// First decrement the exponent by 8, but not below 0
; First decrement the exponent by 8, but not below 0
lda FAC1_exponent
sec
sbc #$08
bcs !+
bcs @1
lda #$00
!:
@1:
sta FAC1_exponent
beq normal_FAC1_end // branch if our float reached 0
beq normal_FAC1_end ; branch if our float reached 0
// Now multiply the mantissa by 8 by moving the whole bytes
; Now multiply the mantissa by 8 by moving the whole bytes
lda FAC1_mantissa+1
sta FAC1_mantissa+0
@@ -81,20 +81,20 @@ normal_FAC1_by_byte:
lda #$00
sta FACOV
// Now check if mantissa is not 0
; Now check if mantissa is not 0
ora FAC1_mantissa+0
ora FAC1_mantissa+1
ora FAC1_mantissa+2
ora FAC1_mantissa+3
bne normal_FAC1_check_mantissa_byte // not 0 - branch to next iteration
bne normal_FAC1_check_mantissa_byte ; not 0 - branch to next iteration
// Our mantissa reached 0 - mark exponent as 0 and finish
; Our mantissa reached 0 - mark exponent as 0 and finish
sta FAC1_exponent
// FALLTROUGH
; FALLTROUGH
normal_FAC1_end:
+7 -7
View File
@@ -1,11 +1,11 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Initialize random seed using values from FAC1,
// afterwards generate random number in FAC1
//
;
; Initialize random seed using values from FAC1,
; afterwards generate random number in FAC1
;
rnd_seed_from_FAC1:
+18 -18
View File
@@ -1,33 +1,33 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# X16 * #IGNORE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# X16 * #IGNORE
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Initialize random seed, afterwards generate random number in FAC1,
// try to gather as much entropy from different sources as possible
//
;
; Initialize random seed, afterwards generate random number in FAC1,
; try to gather as much entropy from different sources as possible
;
rnd_seed_init:
eor CIA1_TIMALO // timer used for IRQ generation, use potential entropy from .A
eor CIA1_TIMALO ; timer used for IRQ generation, use potential entropy from .A
sta RNDX+3
txa // .X might contain some entropy
eor VIC_RASTER // lowest 8 bits of current raster line
txa ; .X might contain some entropy
eor VIC_RASTER ; lowest 8 bits of current raster line
sta RNDX+1
tya // .Y might contain some entropy
tya ; .Y might contain some entropy
eor CIA1_TIMAHI
sta RNDX+4
lda TIME+2 // byte from jiffy counter might be useful too
eor SID_RANDOM // not sure if SID set correctly, but it will not hurt
#if CONFIG_MB_MEGA_65
eor VIC_XPOS // not sure if VIC-IV visible, but it will not hurt
#endif
lda TIME+2 ; byte from jiffy counter might be useful too
eor SID_RANDOM ; not sure if SID set correctly, but it will not hurt
!ifdef CONFIG_MB_M65 {
eor VIC_XPOS ; not sure if VIC-IV visible, but it will not hurt
}
sta RNDX+2
// RNDX+0 will be overwritten by generator
; RNDX+0 will be overwritten by generator
jmp rnd_generate
+20 -20
View File
@@ -1,31 +1,31 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
//
// Math package - rounds FAC1 before copying
//
// See also:
// - [CM64] Computes Mapping the Commodore 64 - page 115
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
//
;
; Math package - rounds FAC1 before copying
;
; See also:
; - [CM64] Computes Mapping the Commodore 64 - page 115
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
;
// XXX test this
; XXX test this
round_FAC1:
// If number is 0, do not do anything
; If number is 0, do not do anything
lda FAC1_exponent
beq round_FAC1_done
lda FACOV
bpl round_FAC1_zero_FACOV // branch if it is enough to clear FACOV
bpl round_FAC1_zero_FACOV ; branch if it is enough to clear FACOV
// Increment the 4 bytes of matissa
; Increment the 4 bytes of matissa
// Curse you, who invented this format! Had the mantissa been little endian,
// we could have used INW on 65C02 and above, the code would have been smaller!
; Curse you, who invented this format! Had the mantissa been little endian,
; we could have used INW on 65C02 and above, the code would have been smaller!
inc FAC1_mantissa+3
bne round_FAC1_zero_FACOV
@@ -36,25 +36,25 @@ round_FAC1:
inc FAC1_mantissa+0
bne round_FAC1_zero_FACOV
// If we are here, it means mantissa is 0; put it to minimum allowed and increment exponent
; If we are here, it means mantissa is 0; put it to minimum allowed and increment exponent
lda #$80
sta FAC1_mantissa+0
inc FAC1_exponent
bne round_FAC1_zero_FACOV
// If we are here, it means the exponent wrapped around to $00; put it back to $FF
; If we are here, it means the exponent wrapped around to $00; put it back to $FF
dec FAC1_exponent
// FALLTROUGH
; FALLTROUGH
round_FAC1_zero_FACOV:
lda #$00
sta FACOV
// FALLTROUGH
; FALLTROUGH
round_FAC1_done: