float type improvements

This commit is contained in:
Irmen de Jong 2017-12-25 02:29:14 +01:00
parent d0f5a9789b
commit 548f4fc2c6
3 changed files with 40 additions and 20 deletions

View File

@ -643,9 +643,24 @@ class CodeGenerator:
self.p("\t\tst{:s} {}".format(r_register[0].lower(), lv_string)) self.p("\t\tst{:s} {}".format(r_register[0].lower(), lv_string))
self.p("\t\tst{:s} {}+1".format(r_register[1].lower(), lv_string)) self.p("\t\tst{:s} {}+1".format(r_register[1].lower(), lv_string))
elif lv.datatype == DataType.FLOAT: elif lv.datatype == DataType.FLOAT:
# assigning a register to a float requires ROM routines # assigning a register to a float requires c64 ROM routines
if r_register in REGISTER_WORDS: if r_register in REGISTER_WORDS:
raise CodeError("cannot yet assign register pair to float", r_register) # XXX reg pair -> float def do_rom_calls():
self.p("\t\tjsr c64util.GIVUAYF") # uword AY -> fac1
self.p("\t\tldx #<" + lv_string)
self.p("\t\tldy #>" + lv_string)
self.p("\t\tjsr c64.FTOMEMXY") # fac1 -> memory XY
if r_register == "AY":
with self.preserving_registers({'A', 'X', 'Y'}):
do_rom_calls()
elif r_register == "AX":
with self.preserving_registers({'A', 'X', 'Y'}):
self.p("\t\tpha\n\t\ttxa\n\t\ttay\n\t\tpla") # X->Y (so we have AY now)
do_rom_calls()
else: # XY
with self.preserving_registers({'A', 'X', 'Y'}):
self.p("\t\ttxa") # X->A (so we have AY now)
do_rom_calls()
elif r_register in "AXY": elif r_register in "AXY":
def do_rom_calls(): def do_rom_calls():

View File

@ -272,16 +272,16 @@ start
memfloat = cword2 memfloat = cword2
; @todo float assignments that require ROM functions or shims: ; @todo float assignments that require ROM functions or shims:
; memfloat = Y memfloat = Y
; memfloat = XY memfloat = XY
; uninitfloat = Y uninitfloat = Y
; uninitfloat = XY uninitfloat = XY
; initfloat2 = Y initfloat2 = Y
; initfloat2 = XY initfloat2 = XY
; initfloat2 = initbyte2 ;initfloat2 = initbyte2 ; @todo support
; initfloat2 = initword2 ;initfloat2 = initword2 ; @todo support
; initfloat1 = uninitfloat ;initfloat1 = uninitfloat ; @todo support
; initfloat1 = initfloat2 ;initfloat1 = initfloat2 ; @todo support
return return
} }

View File

@ -136,11 +136,11 @@ start
c64.FPRINTLN!() c64.FPRINTLN!()
reg_to_float reg_to_float
c64.CHROUT!(13) c64.CHROUT!('\n')
A=34 A=33
X=99 X=44
Y=121 Y=55
my_float = A my_float = A
c64.MOVFM(#my_float) c64.MOVFM(#my_float)
@ -154,13 +154,18 @@ reg_to_float
c64.MOVFM(#my_float) c64.MOVFM(#my_float)
c64.FPRINTLN() c64.FPRINTLN()
XY = 56789 XY = 11122
;my_float = XY ; @todo support my_float = XY
c64.MOVFM(#my_float) c64.MOVFM(#my_float)
c64.FPRINTLN() c64.FPRINTLN()
AX = 33221 AX = 33344
;my_float = AX ; @todo support my_float = AX
c64.MOVFM(#my_float)
c64.FPRINTLN()
AY = 55566
my_float = AY
c64.MOVFM(#my_float) c64.MOVFM(#my_float)
c64.FPRINTLN() c64.FPRINTLN()