From 74d1943cee4f278cd4fbc2acd593c108cc5f0d6b Mon Sep 17 00:00:00 2001 From: Rikard Nordgren Date: Sat, 31 Jan 2026 14:48:09 +0100 Subject: [PATCH] Update int_FAC1 --- src/basic/math/bccc.int_FAC1.jmp.s | 8 ---- src/basic/math/bccc.int_FAC1.s | 34 ++++++++++++++++ src/basic/math/int_FAC1.s | 65 ------------------------------ 3 files changed, 34 insertions(+), 73 deletions(-) delete mode 100644 src/basic/math/bccc.int_FAC1.jmp.s create mode 100644 src/basic/math/bccc.int_FAC1.s delete mode 100644 src/basic/math/int_FAC1.s diff --git a/src/basic/math/bccc.int_FAC1.jmp.s b/src/basic/math/bccc.int_FAC1.jmp.s deleted file mode 100644 index c6e6e130..00000000 --- a/src/basic/math/bccc.int_FAC1.jmp.s +++ /dev/null @@ -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 diff --git a/src/basic/math/bccc.int_FAC1.s b/src/basic/math/bccc.int_FAC1.s new file mode 100644 index 00000000..0e0ba3f1 --- /dev/null +++ b/src/basic/math/bccc.int_FAC1.s @@ -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 diff --git a/src/basic/math/int_FAC1.s b/src/basic/math/int_FAC1.s deleted file mode 100644 index 8e37b9ed..00000000 --- a/src/basic/math/int_FAC1.s +++ /dev/null @@ -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 - 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