From 548f4fc2c69fd07b190891a95cebb8ca93df6fd6 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 25 Dec 2017 02:29:14 +0100 Subject: [PATCH] float type improvements --- il65/codegen.py | 19 +++++++++++++++++-- testsource/dtypes.ill | 20 ++++++++++---------- testsource/floats.ill | 21 +++++++++++++-------- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/il65/codegen.py b/il65/codegen.py index 1699e4a5c..a47f0ece8 100644 --- a/il65/codegen.py +++ b/il65/codegen.py @@ -643,9 +643,24 @@ class CodeGenerator: 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)) 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: - 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": def do_rom_calls(): diff --git a/testsource/dtypes.ill b/testsource/dtypes.ill index 735b6f481..79390b6b1 100644 --- a/testsource/dtypes.ill +++ b/testsource/dtypes.ill @@ -272,16 +272,16 @@ start memfloat = cword2 ; @todo float assignments that require ROM functions or shims: - ; memfloat = Y - ; memfloat = XY - ; uninitfloat = Y - ; uninitfloat = XY - ; initfloat2 = Y - ; initfloat2 = XY - ; initfloat2 = initbyte2 - ; initfloat2 = initword2 - ; initfloat1 = uninitfloat - ; initfloat1 = initfloat2 + memfloat = Y + memfloat = XY + uninitfloat = Y + uninitfloat = XY + initfloat2 = Y + initfloat2 = XY + ;initfloat2 = initbyte2 ; @todo support + ;initfloat2 = initword2 ; @todo support + ;initfloat1 = uninitfloat ; @todo support + ;initfloat1 = initfloat2 ; @todo support return } diff --git a/testsource/floats.ill b/testsource/floats.ill index ff4744392..70b0a6d80 100644 --- a/testsource/floats.ill +++ b/testsource/floats.ill @@ -136,11 +136,11 @@ start c64.FPRINTLN!() reg_to_float - c64.CHROUT!(13) + c64.CHROUT!('\n') - A=34 - X=99 - Y=121 + A=33 + X=44 + Y=55 my_float = A c64.MOVFM(#my_float) @@ -154,13 +154,18 @@ reg_to_float c64.MOVFM(#my_float) c64.FPRINTLN() - XY = 56789 - ;my_float = XY ; @todo support + XY = 11122 + my_float = XY c64.MOVFM(#my_float) c64.FPRINTLN() - AX = 33221 - ;my_float = AX ; @todo support + AX = 33344 + my_float = AX + c64.MOVFM(#my_float) + c64.FPRINTLN() + + AY = 55566 + my_float = AY c64.MOVFM(#my_float) c64.FPRINTLN()