From 4825b4dc68362acdc94a8c3fd6cd2c2e862eeef6 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Tue, 10 Nov 2020 00:35:24 +0100 Subject: [PATCH] fix passing address of pass-by-reference assignment to a UWORD --- .../codegen/assignment/AssignmentAsmGen.kt | 8 ++++- examples/cx16/cobramk3-gfx.p8 | 5 +-- examples/test.p8 | 36 +++++-------------- 3 files changed, 18 insertions(+), 31 deletions(-) diff --git a/compiler/src/prog8/compiler/target/c64/codegen/assignment/AssignmentAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/assignment/AssignmentAsmGen.kt index 10005ffee..4b525444e 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/assignment/AssignmentAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/assignment/AssignmentAsmGen.kt @@ -48,7 +48,13 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen val variable = assign.source.asmVarname when (assign.target.datatype) { DataType.UBYTE, DataType.BYTE -> assignVariableByte(assign.target, variable) - DataType.UWORD, DataType.WORD -> assignVariableWord(assign.target, variable) + DataType.WORD -> assignVariableWord(assign.target, variable) + DataType.UWORD -> { + if(assign.source.datatype in PassByReferenceDatatypes) + assignAddressOf(assign.target, variable) + else + assignVariableWord(assign.target, variable) + } DataType.FLOAT -> assignVariableFloat(assign.target, variable) DataType.STR -> assignVariableString(assign.target, variable) else -> throw AssemblyError("unsupported assignment target type ${assign.target.datatype}") diff --git a/examples/cx16/cobramk3-gfx.p8 b/examples/cx16/cobramk3-gfx.p8 index c2a4148c5..ed8dabdea 100644 --- a/examples/cx16/cobramk3-gfx.p8 +++ b/examples/cx16/cobramk3-gfx.p8 @@ -3,7 +3,6 @@ %import conv ; TODO add all other Elite's ships, show their name, advance to next ship on keypress -; TODO doesn't draw anything on cx16 anymore... main { @@ -37,7 +36,7 @@ main { cx16.GRAPH_set_colors(1, 0, 0) draw_lines_hiddenremoval() - ;draw_lines() + ; draw_lines() anglex += 217 angley -= 505 @@ -225,6 +224,8 @@ main { shipdata { + %option force_output + ; Ship model data converted from BBC Elite's Cobra MK 3 ; downloaded from http://www.elitehomepage.org/archive/index.htm diff --git a/examples/test.p8 b/examples/test.p8 index 7ddc104b4..58c519284 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -7,37 +7,17 @@ main { sub start() { -; byte bb = 4 -; bb += sgn(bb+bb) -; txt.print_b(bb) -; txt.chrout('\n') -; -; word ww = 4 -; ww += sgn(ww+ww) -; txt.print_w(ww) -; txt.chrout('\n') + ubyte[100] array - float x = 4 - x += abs(x+x) - floats.print_f(x) + memset(array, len(array)-1, 255) + + ubyte xx + for xx in array { + txt.print_ubhex(xx, false) + txt.chrout(',') + } txt.chrout('\n') - x = 4 - x += sgn(x+x) ; TODO missing byte->float cast in assembly??? Also fucks up stack - x += sgn(x+x) ; TODO missing byte->float cast in assembly??? Also fucks up stack - x += sgn(x+x) ; TODO missing byte->float cast in assembly??? Also fucks up stack - floats.print_f(x) - txt.chrout('\n') - -; repeat 10 { -; float cosa = cos(t) -; float sina = sin(t) -; float cosb = cos(t*0.33) -; float sinb = sin(t*0.33) -; float cosc = cos(t*0.78) -; float sinc = sin(t*0.78) -; } - testX() }