From 5060f0bb19e7cd2ab0208aab98bedfdceb627904 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Thu, 15 Oct 2020 22:15:00 +0200 Subject: [PATCH] fixed assigning a memory byte from an array --- .../codegen/assignment/AssignmentAsmGen.kt | 3 +- docs/source/todo.rst | 1 + examples/test.p8 | 46 +++++++++++++------ 3 files changed, 35 insertions(+), 15 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 fcab2f0f9..52f0f9ce3 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/assignment/AssignmentAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/assignment/AssignmentAsmGen.kt @@ -1220,6 +1220,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen asmgen.storeByteIntoPointer(addressExpr, ldaInstructionArg) } else -> { + asmgen.out(" lda $ldaInstructionArg | pha") asmgen.translateExpression(addressExpr) asmgen.out(""" inx @@ -1227,8 +1228,8 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen sta P8ZP_SCRATCH_W2 lda P8ESTACK_HI,x sta P8ZP_SCRATCH_W2+1 - lda $ldaInstructionArg ldy #0 + pla sta (P8ZP_SCRATCH_W2),y""") } } diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 31063ccd2..93be5a19e 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -5,6 +5,7 @@ TODO - get rid of all other TODO's in the code ;-) - introduce strcmp() - modify string comparsion expressions to use strcmp() automatically +- only allow array indexing via a number, a variable, or a typecast of one of those (eliminate complex expression calcs for array indexing, force explicit use of an index variable) - implement @stack for asmsub parameters - make it possible to use cpu opcodes such as 'nop' as variable names by prefixing all asm vars with something such as '_' - option to load the built-in library files from a directory instead of the embedded ones (for easier library development/debugging) diff --git a/examples/test.p8 b/examples/test.p8 index 00ec99059..b5ec166ee 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,12 +1,42 @@ %import textio -%import diskio +%import conv %zeropage basicsafe main { sub start() { - dinges.travel_to(5) + str num1 = "01234" + str num2 = @"01234" + str hex1 = "a04E" + str hex2 = "$a04E" + str hex3 = @"a04E" + str hex4 = @"$a04E" + +; txt.print(num1) +; txt.chrout('\n') +; txt.print(num2) +; txt.chrout('\n') +; txt.print(hex1) +; txt.chrout('\n') +; txt.print(hex2) +; txt.chrout('\n') +; txt.print(hex3) +; txt.chrout('\n') +; txt.print(hex4) +; txt.chrout('\n') + + ubyte cc + for cc in 0 to len(hex3)-1 { + @($0410+cc) = hex3[cc] + txt.setchr(16+cc,2,hex3[cc]) + } + + for cc in 0 to len(hex4)-1 { + @($0420+cc) = hex4[cc] + txt.setchr(32+cc,2,hex4[cc]) + } + testX() } @@ -25,15 +55,3 @@ _saveX .byte 0 }} } } - - -dinges { - - sub foo(ubyte x) { - } - - sub travel_to(ubyte d2) { - ubyte travel_to=d2 - foo(travel_to) - } - }