Update round_FAC1

This commit is contained in:
Rikard Nordgren authored and FeralChild64 committed 2026-04-12 13:13:18 +02:00
1 parent 7a37b76d10
commit e56e1cf1ac
6 files changed
+37 -75

No files matched your search

-10
View File
@@ -1,10 +0,0 @@
;; #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
round_FAC1:
jmp round_FAC1_impl
+33
View File
@@ -0,0 +1,33 @@
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
; This file is under the MIT license, it contains code released by Microsoft Corporation.
; See LICENSE for more information.
; Math package - rounds FAC1 before copying
;
; This is verified to be identical to the original Microsoft implementation where it was named ROUND.
;
; Alternative entry point: INCRND to increment mantissa and normalize if carry
;
; See also:
; - [CM64] Computes Mapping the Commodore 64 - page 115
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
;
round_FAC1:
lda FAC1_exponent ; Zero?
beq MOVRTS ; Yes. Done rounding
asl FACOV ; ROUND?
bcc MOVRTS ; No. MSB off.
INCRND:
jsr inc_FAC1 ; Yes, add one to LSB
bne MOVRTS ; No carry means done
jmp RNDSHF ; Squeeze MSB in and RTS
; CF=1 since inc_FAC1 doesn't touch CF
-61
View File
@@ -1,61 +0,0 @@
;; #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
;
; XXX test this
round_FAC1_impl:
; 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
; 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!
inc FAC1_mantissa+3
bne round_FAC1_zero_FACOV
inc FAC1_mantissa+2
bne round_FAC1_zero_FACOV
inc FAC1_mantissa+1
bne round_FAC1_zero_FACOV
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
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
dec FAC1_exponent
; FALLTROUGH
round_FAC1_zero_FACOV:
lda #$00
sta FACOV
; FALLTROUGH
round_FAC1_done:
rts