From 299d1bdab8e3d4b8170f33a244733a1821ef3fd1 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Wed, 2 Jan 2019 03:18:32 +0100 Subject: [PATCH] fixed for loop with step size >1 --- compiler/examples/sprites.p8 | 41 +++++++------- compiler/examples/test.p8 | 66 ++++------------------ compiler/src/prog8/compiler/Compiler.kt | 2 +- compiler/src/prog8/parser/prog8Lexer.java | 2 +- compiler/src/prog8/parser/prog8Parser.java | 2 +- prog8lib/c64lib.p8 | 12 +++- 6 files changed, 44 insertions(+), 81 deletions(-) diff --git a/compiler/examples/sprites.p8 b/compiler/examples/sprites.p8 index fce18ac57..992fe26ce 100644 --- a/compiler/examples/sprites.p8 +++ b/compiler/examples/sprites.p8 @@ -1,10 +1,11 @@ -%import c64lib %import c64utils -%option force_output, enable_floats +%option enable_floats ~ spritedata $0a00 { - %option force_output ; make sure the data appears in the program + ; this memory block contains the sprite data + ; it must start on an address aligned to 64 bytes. + %option force_output ; make sure the data in this block appears in the resulting program ubyte[63] balloonsprite = [ %00000000,%01111111,%00000000, %00000001,%11111111,%11000000, @@ -39,21 +40,22 @@ c64.STROUT("balloon sprites!\n") c64.STROUT("...we are all floating...\n") - c64.SPRPTR0 = $0a00//64 - c64.SPRPTR1 = $0a00//64 - c64.SPRPTR2 = $0a00//64 - c64.SPRPTR3 = $0a00//64 - c64.SPRPTR4 = $0a00//64 - c64.SPRPTR5 = $0a00//64 - c64.SPRPTR6 = $0a00//64 - c64.SPRPTR7 = $0a00//64 + const uword sprite_address_ptr = $0a00 // 64 ; @todo " &balloonsprite // 64" + c64.SPRPTR0 = sprite_address_ptr + c64.SPRPTR1 = sprite_address_ptr + c64.SPRPTR2 = sprite_address_ptr + c64.SPRPTR3 = sprite_address_ptr + c64.SPRPTR4 = sprite_address_ptr + c64.SPRPTR5 = sprite_address_ptr + c64.SPRPTR6 = sprite_address_ptr + c64.SPRPTR7 = sprite_address_ptr for ubyte i in 0 to 7 { @(SP0X+i*2) = 50+25*i @(SP0Y+i*2) = rnd() } - c64.SPENA = 255 ; enable all sprites + c64.SPENA = 255 ; enable all sprites c64utils.set_rasterirq(51) ; enable animation } } @@ -63,16 +65,13 @@ sub irq() { c64.EXTCOL-- ; float up & wobble horizontally - - ; @todo for loop with step 2 doesn't work - - for ubyte i in 0 to 7 { - @(main.SP0Y+i+i)-- + for ubyte i in 0 to 14 step 2 { + @(main.SP0Y+i)-- ubyte r = rnd() - if r>208 - @(main.SP0X+i+i)++ - else if r<48 - @(main.SP0X+i+i)-- + if r>200 + @(main.SP0X+i)++ + else if r<40 + @(main.SP0X+i)-- } c64.EXTCOL++ } diff --git a/compiler/examples/test.p8 b/compiler/examples/test.p8 index 2642257c1..ea566af04 100644 --- a/compiler/examples/test.p8 +++ b/compiler/examples/test.p8 @@ -3,61 +3,19 @@ ~ main { sub start() { - uword uw1 = 0 - uword uw2 = $77ff - uword uw3 = $55aa - word w1 = 0 - word w2 = $22ff - word w3 = $55aa - memory uword muw1 = $2000 - memory uword muw2 = $3000 - memory uword muw3 = $4000 - memory word mw1 = $4100 - memory word mw2 = $4200 - memory word mw3 = $4300 - uword[3] uwarr = $55aa - word[3] warr = $55aa - memory uword[3] muwarr = $4400 - memory word[3] mwarr = $4500 + for ubyte j in 0 to 7 step 2 { ; @todo wrong bytecode generated!! + vm_write_num(j) + vm_write_char('\n') + ;c64scr.print_ub(j) + ;c64.CHROUT('\n') + } - muw3 = $55aa - uwarr[0] = $55aa - uwarr[1] = $55aa - uwarr[2] = $55aa - muwarr[0] = $55aa - muwarr[1] = $55aa - muwarr[2] = $55aa - mwarr[0] = $55aa - mwarr[1] = $55aa - mwarr[2] = $55aa - - uw1 = uw2 + $55aa ;52649 - c64scr.print_uw(uw1) - c64.CHROUT('\n') - - uw1 = uw2 + uw3 ;52649 - c64scr.print_uw(uw1) - c64.CHROUT('\n') - - uw1 = uw2 + muw3 ;52649 - c64scr.print_uw(uw1) - c64.CHROUT('\n') - -; uw1 = uw2 + uwarr[2] ;52649 -; c64scr.print_uw(uw1) -; c64.CHROUT('\n') - - -; w1 = w2 + $55aa ; 30889 -; c64scr.print_w(w1) -; c64.CHROUT('\n') -; w1 = w2 + w3 ; 30889 -; c64scr.print_w(w1) -; c64.CHROUT('\n') -; -; uwarr[2] = uwarr[1] + $55aa -; uwarr[2] = uwarr[1] + uw3 -; uwarr[2] = uwarr[1] + uwarr[1] + for ubyte j in 10 to 3 step -2 { ; @todo wrong bytecode generated!! + vm_write_num(j) + vm_write_char('\n') + ;c64scr.print_ub(j) + ;c64.CHROUT('\n') + } } } diff --git a/compiler/src/prog8/compiler/Compiler.kt b/compiler/src/prog8/compiler/Compiler.kt index d9e2b79b0..eb437b5c6 100644 --- a/compiler/src/prog8/compiler/Compiler.kt +++ b/compiler/src/prog8/compiler/Compiler.kt @@ -1802,7 +1802,7 @@ private class StatementTranslator(private val prog: IntermediateProgram, range.step>1 -> { prog.instr(opcodePushvar(varDt), callLabel = varname) prog.instr(opcodePush(varDt), Value(varDt, range.step)) - prog.instr(opcodeSub(varDt)) + prog.instr(opcodeAdd(varDt)) prog.instr(opcodePopvar(varDt), callLabel = varname) } range.step<1 -> { diff --git a/compiler/src/prog8/parser/prog8Lexer.java b/compiler/src/prog8/parser/prog8Lexer.java index 80f62ac4d..d3f9d0e85 100644 --- a/compiler/src/prog8/parser/prog8Lexer.java +++ b/compiler/src/prog8/parser/prog8Lexer.java @@ -1,4 +1,4 @@ -// Generated from /home/irmen/Projects/prog8/compiler/antlr/prog8.g4 by ANTLR 4.7.2 +// Generated from ../antlr/prog8.g4 by ANTLR 4.7.2 package prog8.parser; import org.antlr.v4.runtime.Lexer; import org.antlr.v4.runtime.CharStream; diff --git a/compiler/src/prog8/parser/prog8Parser.java b/compiler/src/prog8/parser/prog8Parser.java index 70453cf40..5c1ef4bda 100644 --- a/compiler/src/prog8/parser/prog8Parser.java +++ b/compiler/src/prog8/parser/prog8Parser.java @@ -1,4 +1,4 @@ -// Generated from /home/irmen/Projects/prog8/compiler/antlr/prog8.g4 by ANTLR 4.7.2 +// Generated from ../antlr/prog8.g4 by ANTLR 4.7.2 package prog8.parser; import org.antlr.v4.runtime.atn.*; import org.antlr.v4.runtime.dfa.DFA; diff --git a/prog8lib/c64lib.p8 b/prog8lib/c64lib.p8 index 974b19b2e..39951288b 100644 --- a/prog8lib/c64lib.p8 +++ b/prog8lib/c64lib.p8 @@ -27,10 +27,12 @@ memory uword RESET_VEC = $FFFC ; 6502 reset vector, determined by the kernal if banked in memory uword IRQ_VEC = $FFFE ; 6502 interrupt vector, determined by the kernal if banked in - const uword Screen = $0400 ; default character screen matrix @todo matrix/array? needs to support array size > 255 - const uword Colors = $d800 ; character screen colors @todo matrix/array? needs to support array size > 255 + ; the default addresses for the character screen chars and colors + const uword Screen = $0400 ; @todo matrix/array? needs to support array size > 255 + const uword Colors = $d800 ; @todo matrix/array? needs to support array size > 255 - memory ubyte SPRPTR0 = 2040 ; default sprite pointers (store address of sprite / 64) + ; the default locations of the 8 sprite pointers (store address of sprite / 64) + memory ubyte SPRPTR0 = 2040 memory ubyte SPRPTR1 = 2041 memory ubyte SPRPTR2 = 2042 memory ubyte SPRPTR3 = 2043 @@ -132,6 +134,10 @@ ; ---- end of CIA registers ---- +; @todo SID sound chip registers + + + ; ---- C64 basic and kernal ROM float constants and functions ---- ; note: the fac1 and fac2 are working registers and take 6 bytes each,