asm conversions to float

This commit is contained in:
Irmen de Jong 2018-12-12 01:13:13 +01:00
parent d6cf8bcce0
commit 584cc1dedb
5 changed files with 116 additions and 27 deletions

View File

@ -1,4 +1,4 @@
; %import c64utils
%import c64utils
%option enable_floats
%output raw
%launcher none

View File

@ -3,13 +3,70 @@
~ main {
sub start() {
return ending(true) ;; @todo fix argument passing!
sub ending(success: ubyte) {
c64scr.print_byte_decimal(success)
c64scr.print_byte_decimal(success)
c64scr.print_byte_decimal(success)
c64.CHROUT('\n')
}
ubyte ub1
byte b1
uword uw1
word w1
float f1
ub1=0
f1=ub1
c64.FPRINTLN()
ub1=255
f1=ub1
c64.FPRINTLN()
c64.CHROUT('\n')
b1=0
f1=b1
c64.FPRINTLN()
b1=-123
f1=b1
c64.FPRINTLN()
c64.CHROUT('\n')
uw1 = 0
f1 = uw1
c64.FPRINTLN()
uw1 = 1
f1 = uw1
c64.FPRINTLN()
uw1 = 255
f1 = uw1
c64.FPRINTLN()
uw1 = 32768
f1 = uw1
c64.FPRINTLN()
uw1 = 65535
f1 = uw1
c64.FPRINTLN()
uw1 = 0
f1 = uw1
c64.FPRINTLN()
c64.CHROUT('\n')
w1 = 1
f1 = w1
c64.FPRINTLN()
w1 = 255
f1 = w1
c64.FPRINTLN()
w1 = 32767
f1 = w1
c64.FPRINTLN()
w1 = -32768
f1 = w1
c64.FPRINTLN()
w1 = -1
f1 = w1
c64.FPRINTLN()
w1 = -255
f1 = w1
c64.FPRINTLN()
w1 = -256
f1 = w1
c64.FPRINTLN()
}
}

View File

@ -117,7 +117,7 @@ asmsub FAREADMEM () -> clobbers(A,Y) -> () = $ba90 ; load mflpt value from me
asmsub MOVFA () -> clobbers(A,X) -> () = $bbfc ; copy fac2 to fac1
asmsub MOVAF () -> clobbers(A,X) -> () = $bc0c ; copy fac1 to fac2 (rounded)
asmsub MOVEF () -> clobbers(A,X) -> () = $bc0f ; copy fac1 to fac2
asmsub FTOMEMXY (mflpt: uword @ XY) -> clobbers(A,Y) -> () = $bbd4 ; store fac1 to memory X/Y as 5-byte mflpt
asmsub MOVMF (mflpt: uword @ XY) -> clobbers(A,Y) -> () = $bbd4 ; store fac1 to memory X/Y as 5-byte mflpt
; fac1-> signed word in Y/A (might throw ILLEGAL QUANTITY)
; (tip: use c64flt.FTOSWRDAY to get A/Y output; lo/hi switched to normal little endian order)
@ -130,7 +130,7 @@ asmsub GETADR () -> clobbers(X) -> (ubyte @ Y, ubyte @ A) = $b7f7
asmsub QINT () -> clobbers(A,X,Y) -> () = $bc9b ; fac1 -> 4-byte signed integer in 98-101 ($62-$65), with the MSB FIRST.
asmsub AYINT () -> clobbers(A,X,Y) -> () = $b1bf ; fac1-> signed word in 100-101 ($64-$65) MSB FIRST. (might throw ILLEGAL QUANTITY)
; signed word in Y/A -> float in fac1
; GIVAYF: signed word in Y/A (note different lsb/msb order) -> float in fac1
; (tip: use c64flt.GIVAYFAY to use A/Y input; lo/hi switched to normal order)
; there is also c64flt.GIVUAYF - unsigned word in A/Y (lo/hi) to fac1
; there is also c64flt.FREADS32 that reads from 98-101 ($62-$65) MSB FIRST

View File

@ -221,7 +221,7 @@ asmsub FREADS24AXY (lo: ubyte @ A, mid: ubyte @ X, hi: ubyte @ Y) -> clobbers(
}}
}
asmsub GIVUAYF (value: uword @ AY) -> clobbers(A,X,Y) -> () {
asmsub GIVUAYFAY (value: uword @ AY) -> clobbers(A,X,Y) -> () {
; ---- unsigned 16 bit word in A/Y (lo/hi) to fac1
%asm {{
sty $62
@ -235,9 +235,9 @@ asmsub GIVUAYF (value: uword @ AY) -> clobbers(A,X,Y) -> () {
asmsub GIVAYFAY (value: uword @ AY) -> clobbers(A,X,Y) -> () {
; ---- signed 16 bit word in A/Y (lo/hi) to float in fac1
%asm {{
sta c64.SCRATCH_ZPB1
sta c64.SCRATCH_ZPREG
tya
ldy c64.SCRATCH_ZPB1
ldy c64.SCRATCH_ZPREG
jmp c64.GIVAYF ; this uses the inverse order, Y/A
}}
}
@ -246,9 +246,9 @@ asmsub FTOSWRDAY () -> clobbers(X) -> (uword @ AY) {
; ---- fac1 to signed word in A/Y
%asm {{
jsr c64.FTOSWORDYA ; note the inverse Y/A order
sta c64.SCRATCH_ZPB1
sta c64.SCRATCH_ZPREG
tya
ldy c64.SCRATCH_ZPB1
ldy c64.SCRATCH_ZPREG
rts
}}
}
@ -303,7 +303,7 @@ asmsub float_add_one (mflt: uword @ XY) -> clobbers(A,X,Y) -> () {
jsr c64.FADD ; fac1 += 1
ldx c64.SCRATCH_ZPB1
ldy c64.SCRATCH_ZPREG
jmp c64.FTOMEMXY ; float XY = fac1
jmp c64.MOVMF ; float XY = fac1
}}
}
@ -320,7 +320,7 @@ asmsub float_sub_one (mflt: uword @ XY) -> clobbers(A,X,Y) -> () {
jsr c64.FSUB ; fac1 = float XY - 1
ldx c64.SCRATCH_ZPB1
ldy c64.SCRATCH_ZPREG
jmp c64.FTOMEMXY ; float XY = fac1
jmp c64.MOVMF ; float XY = fac1
}}
}
@ -336,7 +336,7 @@ asmsub float_add_SW1_to_XY (mflt: uword @ XY) -> clobbers(A,X,Y) -> () {
jsr c64.FADD ; fac1 += SCRATCH_ZPWORD1
ldx c64.SCRATCH_ZPB1
ldy c64.SCRATCH_ZPREG
jmp c64.FTOMEMXY ; float XY = fac1
jmp c64.MOVMF ; float XY = fac1
}}
}
@ -353,7 +353,7 @@ asmsub float_sub_SW1_from_XY (mflt: uword @ XY) -> clobbers(A,X,Y) -> () {
jsr c64.FSUB ; fac1 = float XY - SCRATCH_ZPWORD1
ldx c64.SCRATCH_ZPB1
ldy c64.SCRATCH_ZPREG
jmp c64.FTOMEMXY ; float XY = fac1
jmp c64.MOVMF ; float XY = fac1
}}
}

View File

@ -12,6 +12,7 @@
; note: the following ZP scratch registers must be the same as in c64lib
memory ubyte SCRATCH_ZPB1 = $02 ; scratch byte 1 in ZP
memory ubyte SCRATCH_ZPREG = $03 ; scratch register in ZP
memory ubyte SCRATCH_ZPREGX = $50 ; temp storage for X register (stack pointer)
memory uword SCRATCH_ZPWORD1 = $fb ; scratch word in ZP ($fb/$fc)
memory uword SCRATCH_ZPWORD2 = $fd ; scratch word in ZP ($fd/$fe)
const uword ESTACK_LO = $ce00
@ -38,23 +39,52 @@ ror2_word .proc
; @todo: move float operations to their own library (only included when floats are enabled)
ub2float .proc
; -- convert ubyte in SCRATCH_ZPB1 to float at address A/Y
; clobbers A, Y
stx SCRATCH_ZPREGX
sta SCRATCH_ZPWORD2
sty SCRATCH_ZPWORD1+1
ldy SCRATCH_ZPB1
jsr c64.FREADUY
_fac_to_mem ldx SCRATCH_ZPWORD2
ldy SCRATCH_ZPWORD2+1
jsr c64.MOVMF
ldx SCRATCH_ZPREGX
rts
.warn "not implemented"
.pend
b2float .proc
rts
.warn "not implemented"
; -- convert byte in SCRATCH_ZPB1 to float at address A/Y
; clobbers A, Y
stx SCRATCH_ZPREGX
sta SCRATCH_ZPWORD2
sty SCRATCH_ZPWORD2+1
lda SCRATCH_ZPB1
jsr c64.FREADSA
jmp ub2float._fac_to_mem
.pend
uw2float .proc
rts
.warn "not implemented"
; -- convert uword in SCRATCH_ZPWORD1 to float at address A/Y
stx SCRATCH_ZPREGX
sta SCRATCH_ZPWORD2
sty SCRATCH_ZPWORD2+1
lda SCRATCH_ZPWORD1
ldy SCRATCH_ZPWORD1+1
jsr c64flt.GIVUAYFAY
jmp ub2float._fac_to_mem
.pend
w2float .proc
; -- convert word in SCRATCH_ZPWORD1 to float at address A/Y
stx SCRATCH_ZPREGX
sta SCRATCH_ZPWORD2
sty SCRATCH_ZPWORD2+1
ldy SCRATCH_ZPWORD1
lda SCRATCH_ZPWORD1+1
jsr c64.GIVAYF
jmp ub2float._fac_to_mem
rts
.warn "not implemented"
.pend
push_float .proc
@ -726,7 +756,7 @@ func_rndf .proc
jsr c64.RND ; rng into fac1
ldx #<_rndf_rnum5
ldy #>_rndf_rnum5
jsr c64.FTOMEMXY ; fac1 to mem X/Y
jsr c64.MOVMF ; fac1 to mem X/Y
ldx SCRATCH_ZPREG
lda #<_rndf_rnum5
ldy #>_rndf_rnum5
@ -775,7 +805,9 @@ func_str2byte .proc
; result += digitvalue
; return result
func_str2ubyte jmp func_str2uword
func_str2ubyte .proc
jmp func_str2uword
.pend
func_str2uword .proc
;-- convert string (address on stack) to uword number