Add int to float conversions
This commit is contained in:
1 parent
e41558ce33
commit
ee736cfcbc
16 files changed
+139
-56
No files matched your search
@@ -1,22 +0,0 @@
|
||||
;; #LAYOUT# STD * #TAKE
|
||||
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
|
||||
;; #LAYOUT# * BASIC_0 #TAKE
|
||||
;; #LAYOUT# * * #IGNORE
|
||||
|
||||
;
|
||||
; Math package - 16-bit signed integer to FAC1
|
||||
;
|
||||
; Output:
|
||||
; - .A - address high byte (XXX really, not the opposite?)
|
||||
; - .Y - address low byte
|
||||
;
|
||||
; See also:
|
||||
; - [CM64] Computes Mapping the Commodore 64 - page 107
|
||||
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
|
||||
;
|
||||
|
||||
; XXX provide implementation
|
||||
|
||||
GIVAYF:
|
||||
|
||||
+STUB_IMPLEMENTATION
|
||||
@@ -1,14 +0,0 @@
|
||||
;; #LAYOUT# STD * #TAKE
|
||||
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
|
||||
;; #LAYOUT# * BASIC_0 #TAKE
|
||||
;; #LAYOUT# * * #IGNORE
|
||||
|
||||
;
|
||||
; Math package - XXX
|
||||
;
|
||||
; - https://codebase64.org/doku.php?id=base:asm_include_file_for_basic_routines
|
||||
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
|
||||
;
|
||||
; XXX add name, label, documentation, implement, test
|
||||
|
||||
+STUB_IMPLEMENTATION
|
||||
@@ -1,13 +0,0 @@
|
||||
;; #LAYOUT# STD * #TAKE
|
||||
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
|
||||
;; #LAYOUT# * BASIC_0 #TAKE
|
||||
;; #LAYOUT# * * #IGNORE
|
||||
|
||||
;
|
||||
; Math package - XXX
|
||||
;
|
||||
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
|
||||
;
|
||||
; XXX add name, label, documentation, implement, test
|
||||
|
||||
+STUB_IMPLEMENTATION
|
||||
@@ -0,0 +1,27 @@
|
||||
;; #LAYOUT# STD * #TAKE
|
||||
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
|
||||
;; #LAYOUT# * BASIC_0 #TAKE
|
||||
;; #LAYOUT# * * #IGNORE
|
||||
|
||||
;
|
||||
; Math package - 16-bit signed integer to FAC1
|
||||
;
|
||||
; Output:
|
||||
; - .A - high byte
|
||||
; - .Y - low byte
|
||||
;
|
||||
; Sets the data type flag at $0D to "numeric", stores the number in the FAC1 mantissa
|
||||
; then calls convert_i16_to_FAC1
|
||||
;
|
||||
; See also:
|
||||
; - [CM64] Computes Mapping the Commodore 64 - page 107
|
||||
; - https://www.c64-wiki.com/wiki/GIVAYF
|
||||
;
|
||||
|
||||
|
||||
GIVAYF:
|
||||
ldx #$00
|
||||
stx $0D
|
||||
sty FAC1_mantissa
|
||||
sta FAC1_mantissa+1
|
||||
jmp convert_i16_to_FAC1
|
||||
File renamed without changes.
+11
-3
@@ -4,13 +4,21 @@
|
||||
;; #LAYOUT# * * #IGNORE
|
||||
|
||||
;
|
||||
; Math package - XXX
|
||||
; Math package - convert uint8 in Y to FAC1
|
||||
;
|
||||
; Input: Y - uint8 to convert to float
|
||||
; Result: FAC1
|
||||
;
|
||||
; Stores Y into first FAC1 mantissa byte, clears the second and calls convert_i16_to_FAC1
|
||||
;
|
||||
; - https://www.c64-wiki.com/wiki/BASIC-ROM
|
||||
; - https://sta.c64.org/cbm64basconv.html
|
||||
; - https://sourceforge.net/p/acme-crossass/code-0/38/tree/trunk/ACME_Lib/cbm/c64/float.a?force=True
|
||||
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
|
||||
;
|
||||
; XXX add name, label, documentation, implement, test
|
||||
|
||||
+STUB_IMPLEMENTATION
|
||||
convert_Y_to_FAC1:
|
||||
lda #$00
|
||||
sta FAC1_mantissa+1
|
||||
sty FAC1_mantissa
|
||||
jmp convert_i16_to_FAC1
|
||||
File renamed without changes.
@@ -0,0 +1,24 @@
|
||||
;; #LAYOUT# STD * #TAKE
|
||||
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
|
||||
;; #LAYOUT# * BASIC_0 #TAKE
|
||||
;; #LAYOUT# * * #IGNORE
|
||||
|
||||
;
|
||||
; Math package - convert int8 in A to FAC1
|
||||
;
|
||||
; Input: A - int8 to convert to float
|
||||
; Result: FAC1
|
||||
;
|
||||
; Sets first byte of FAC1 to A, sign extends A into tge second byte and falls through to convert_i16_to_FAC1
|
||||
;
|
||||
; - https://codebase64.org/doku.php?id=base:asm_include_file_for_basic_routines
|
||||
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
|
||||
;
|
||||
|
||||
|
||||
convert_A_to_FAC1:
|
||||
sta FAC1_mantissa
|
||||
jsr sign_extend_A_to_Y
|
||||
sty FAC1_mantissa+1
|
||||
+nop ; To not leave a gap to the fallthrough
|
||||
; Fall through to convert_i16_to_FAC1
|
||||
File renamed without changes.
@@ -0,0 +1,29 @@
|
||||
;; #LAYOUT# STD * #TAKE
|
||||
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
|
||||
;; #LAYOUT# * BASIC_0 #TAKE
|
||||
;; #LAYOUT# * * #IGNORE
|
||||
|
||||
;
|
||||
; Math package - Convert signed 16-bit integer to floating point
|
||||
;
|
||||
; - 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
|
||||
|
||||
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+1
|
||||
cmp #$80 ; Copy sign into carry
|
||||
rts
|
||||
File renamed without changes.
@@ -0,0 +1,24 @@
|
||||
;; #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
|
||||
bcs @1
|
||||
|
||||
; Handle signed int
|
||||
lda FAC1_mantissa+1 ; Clear sign bit of int 16
|
||||
and #$7F
|
||||
sta FAC1_mantissa+1
|
||||
ldy #>CONST_NEG_32768 ; Subtract with 32768 to invert negative number
|
||||
lda #<CONST_NEG_32768
|
||||
jsr add_MEM_FAC1
|
||||
@1: jmp normal_FAC1
|
||||
@@ -0,0 +1,13 @@
|
||||
;; #LAYOUT# STD * #TAKE
|
||||
;; #LAYOUT# * BASIC_0 #TAKE
|
||||
;; #LAYOUT# * * #IGNORE
|
||||
|
||||
;
|
||||
; Math package - helper function to sign extend accumulator into Y
|
||||
|
||||
sign_extend_A_to_Y:
|
||||
cmp #$80 ; Copy sign into carry
|
||||
ldy #$00 ; Y = $00
|
||||
bcc @1 ; Branch if not negative
|
||||
dey ; Y = $FF
|
||||
@1: rts
|
||||
Reference in new issue
Block a user