Update convert_i16_to_FAC1
This commit is contained in:
1 parent
64ac8b2073
commit
94f8dfc822
4 files changed
+25
-43
No files matched your search
@@ -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
|
||||
@@ -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 #<CONST_NEG_32768
|
||||
jsr add_MEM_FAC1
|
||||
@1: jmp normal_FAC1
|
||||
Reference in new issue
Block a user