Update int_FAC1

This commit is contained in:
Rikard Nordgren authored and FeralChild64 committed 2026-02-01 18:35:00 +01:00
1 parent fa838d8fb2
commit 74d1943cee
3 files changed
+34 -73

No files matched your search

-8
View File
@@ -1,8 +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
jmp int_FAC1
+34
View File
@@ -0,0 +1,34 @@
;; #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 away the decimal to make an integer
;
; This is verified to be identical to the original Microsoft implementation where it was named INT.
;
; See also:
; - [CM64] Computes Mapping the Commodore 64 - page 116
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
;
int_FAC1:
lda FAC1_exponent
cmp #$A0
bcs clear_FAC1_rts
jsr QINT
sty FACOV
lda FAC1_sign
sty FAC1_sign
eor #$80
rol
lda #$A0
sta FAC1_exponent
lda FAC1_mantissa+3
sta CHARAC ; INTEGR in the original code ($07)
jmp abs_and_normal_FAC1
-65
View File
@@ -1,65 +0,0 @@
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
;
; Math package - rounds away the decimal to make an integer
;
; See also:
; - [CM64] Computes Mapping the Commodore 64 - page 116
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
;
int_FAC1:
lda FAC1_exponent
cmp #$81
bcc int_FAC1_zero ; exponent is 0 or lower so integer part is 0
cmp #$A0
bcs int_FAC1_out ; exponent is 32 or larger so the entire mantissa is part of the integer
tax
and #$07 ; low three bits of exponent is number of bits to keep
tay
txa
lsr ; Bits 4-5 of exponent is how many full mantissa bytes to keep
lsr
lsr
and #$03
tax
lda #$FF ; Create bit mask for first mantissa byte to change
@1: lsr
dey
bne @1
eor #$FF
and FAC1_mantissa,X
sta FAC1_mantissa,X
lda #0
@2: inx
cpx #$4
bcs @3
sta FAC1_mantissa,X
bcc @2
@3: lda FAC1_sign
bpl int_FAC1_out
lda #<const_ONE ; If negative subtract one
ldy #>const_ONE
jsr sub_MEM_FAC1 ; FAC1 = 1 - FAC1
lda #$FF
sta FAC1_sign ; FAC1 = FAC1 - 1
rts
; FIXME: Do we need to set FACOV to 0?
int_FAC1_zero:
lda #0
sta FAC1_exponent
int_FAC1_out:
rts