diff --git a/STATUS.md b/STATUS.md index e9a4f499..37517541 100644 --- a/STATUS.md +++ b/STATUS.md @@ -237,7 +237,7 @@ Floating point mathematical routines - not official, but well known and broadly | `$BC2B` | `sgn_FAC1_A` | DONE | From the Microsoft BASIC, original name: SIGN | | `$BC39` | `sgn_FAC1` | DONE | From the Microsoft BASIC, original name: SGN | | `$BC3C` | `convert_A_to_FAC1` | DONE | From the Microsoft BASIC, original name: FLOAT | -| `$BC44` | `convert_i16_to_FAC1` | DONE | | +| `$BC44` | `convert_i16_to_FAC1` | DONE | From the Microsoft BASIC, original name: FLOATS | | `$BC58` | `abs_FAC1` | DONE | From the Microsoft BASIC, original name: ABS | | `$BC5B` | `FCOMP` | DONE | | | `$BC9B` | `QINT` | DONE | From the Microsoft BASIC, original name: QINT | diff --git a/src/basic/math/bc44.convert_i16_to_FAC1.s b/src/basic/math/bc44.convert_i16_to_FAC1.s index 94ef1c27..c53ae75f 100644 --- a/src/basic/math/bc44.convert_i16_to_FAC1.s +++ b/src/basic/math/bc44.convert_i16_to_FAC1.s @@ -3,27 +3,34 @@ ;; #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 - Convert signed 16-bit integer to floating point ; +; This is verified to be identical to the original Microsoft implementation where it was named FLOATS. +; ; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics ; - https://www.c64-wiki.com/wiki/GIVAYF (which calls this function) ; ; Convert the signed 16-bit integer in FAC1 mantissa ($62:$63) -; into a floating point number in FAC1 - -; NOTE: -; According to https://c64os.com/post/floatingpointmath at $BC49 -; Assume FAC1_mantissa+0 and +1. X=exponent and C=0 if negative and C=1 if positive +; into a floating point number in FAC1. Assume X=exponent +; +; Alternative entry points: +; FLOATC: Assume FAC1_mantissa+0 and +1 loaded. Assume CF=0 if negative and C=1 if positive +; FLOATB: as for FLOATC and do not clear FAC1_mantissa+2 and +3 and set sign and FACOV to A convert_i16_to_FAC1: - ldx #$90 - jsr carry - jmp convert_i16_expsign_to_FAC1 ; This should be at $BC49 (see note above) - - -carry: - lda FAC1_mantissa - cmp #$80 ; Copy sign into carry - rts + lda FAC1_mantissa+0 + eor #$FF + rol ; CF = Complement of sign +FLOATC: + lda #0 + sta FAC1_mantissa+3 + sta FAC1_mantissa+2 +FLOATB: + stx FAC1_exponent + sta FACOV + sta FAC1_sign + jmp abs_and_normal_FAC1 diff --git a/src/basic/math/convert_i16_expsign_to_FAC1.s b/src/basic/math/convert_i16_expsign_to_FAC1.s deleted file mode 100644 index 53dbd390..00000000 --- a/src/basic/math/convert_i16_expsign_to_FAC1.s +++ /dev/null @@ -1,24 +0,0 @@ -;; #LAYOUT# STD * #TAKE -;; #LAYOUT# * BASIC_0 #TAKE -;; #LAYOUT# * * #IGNORE - -; -; Math package - convert i16 with exponent in X and sign in C to FAC1 - -convert_i16_expsign_to_FAC1: - - lda #$00 - sta FAC1_mantissa+2 ; Clear high bytes of mantissa - sta FAC1_mantissa+3 - stx FAC1_exponent - sta FAC1_sign - bcc @1 - - ; Handle signed int - lda FAC1_mantissa ; Clear sign bit of int 16 - and #$7F - sta FAC1_mantissa - ldy #>CONST_NEG_32768 ; Subtract with 32768 to invert negative number - lda #