diff --git a/codeGenIntermediate/src/prog8/codegen/intermediate/IRCodeGen.kt b/codeGenIntermediate/src/prog8/codegen/intermediate/IRCodeGen.kt index b1c138026..669cf778f 100644 --- a/codeGenIntermediate/src/prog8/codegen/intermediate/IRCodeGen.kt +++ b/codeGenIntermediate/src/prog8/codegen/intermediate/IRCodeGen.kt @@ -915,15 +915,18 @@ class IRCodeGen( } } + val repeatLabel = createLabelName() + val skipRepeatLabel = createLabelName() val code = IRCodeChunk(repeat.position) val counterReg = vmRegisters.nextFree() val vmDt = vmType(repeat.count.type) code += expressionEval.translateExpression(repeat.count, counterReg, -1) - val repeatLabel = createLabelName() + code += IRCodeInstruction(Opcode.BZ, vmDt, reg1=counterReg, labelSymbol = skipRepeatLabel) code += IRCodeLabel(repeatLabel) code += translateNode(repeat.statements) code += IRCodeInstruction(Opcode.DEC, vmDt, reg1=counterReg) code += IRCodeInstruction(Opcode.BNZ, vmDt, reg1=counterReg, labelSymbol = repeatLabel) + code += IRCodeLabel(skipRepeatLabel) return code } diff --git a/compiler/res/prog8lib/virtual/textio.p8 b/compiler/res/prog8lib/virtual/textio.p8 index 67cb3a2ae..21ccc76c3 100644 --- a/compiler/res/prog8lib/virtual/textio.p8 +++ b/compiler/res/prog8lib/virtual/textio.p8 @@ -120,4 +120,19 @@ sub input_chars (uword buffer) -> ubyte { }} } +sub plot (ubyte col, ubyte row) { + ; use ANSI escape sequence to position the cursor + txt.chrout(27) + txt.chrout('[') + txt.print_ub(row) + txt.chrout(';') + txt.print_ub(col) + txt.chrout('H') +} + +sub setchr (ubyte col, ubyte row, ubyte char) { + plot(col, row) + txt.chrout(char) +} + } diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 1f92383f8..312108fc9 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,8 +3,6 @@ TODO For next release ^^^^^^^^^^^^^^^^ -- fix examples/vm/textelite.p8 having wrong randomization? (starts with wrong planet) - ... diff --git a/examples/test.p8 b/examples/test.p8 index ff45dfe83..542ce6d37 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -5,28 +5,65 @@ main { sub start() { - uword[] words = [1111,2222,0,4444,3333] + ubyte v1 = 1 + uword v2 = 1 - txt.print_ub(all(words)) - txt.nl() - txt.print_ub(any(words)) - txt.nl() - sort(words) + ubyte counterb + uword counter - uword ww - for ww in words { - txt.print_uw(ww) - txt.spc() + repeat v1-1 { + txt.print("!") } - txt.nl() - reverse(words) - for ww in words { - txt.print_uw(ww) - txt.spc() + repeat v2-1 { + txt.print("?") } - txt.nl() + for counterb in 0 to v1 { + txt.print("y1") + } + for counter in 0 to v2 { + txt.print("y2") + } + + repeat v1 { + txt.print("ok1") + } + + repeat v2 { + txt.print("ok2") + } + + repeat v1-1 { + txt.print("!") + } + + repeat v2-1 { + txt.print("?") + } + + while v1-1 { + txt.print("%") + } + + while v2-1 { + txt.print("*") + } + + + for counterb in 0 to v1-1 { + txt.print("@") + } + for counter in 0 to v2-1 { + txt.print("y#") + } + + repeat 0 { + txt.print("zero1") + } + repeat $0000 { + txt.print("zero2") + } } } diff --git a/examples/textelite.p8 b/examples/textelite.p8 index 54918453c..6420926f9 100644 --- a/examples/textelite.p8 +++ b/examples/textelite.p8 @@ -22,6 +22,7 @@ main { txt.lowercase() txt.print("\u000c\n --- TextElite v1.2 ---\n") + planet.set_seed(0, 0) galaxy.travel_to(1, numforLave) market.init(0) ; Lave's market is seeded with 0 ship.init() diff --git a/examples/vm/bouncegfx.p8 b/examples/vm/bouncegfx.p8 index c5d52381c..38c3865f5 100644 --- a/examples/vm/bouncegfx.p8 +++ b/examples/vm/bouncegfx.p8 @@ -1,6 +1,3 @@ -%import textio -%zeropage basicsafe - ; NOTE: meant to test to virtual machine output target (use -target virtual) main { @@ -24,6 +21,7 @@ main { repeat { fade() plot_particles() + sys.wait(1) sys.waitvsync() } diff --git a/examples/vm/pixelshader.p8 b/examples/vm/pixelshader.p8 index df9147634..77a87d49f 100644 --- a/examples/vm/pixelshader.p8 +++ b/examples/vm/pixelshader.p8 @@ -1,6 +1,3 @@ -%import textio -%zeropage basicsafe - ; NOTE: meant to test to virtual machine output target (use -target virtual) main { @@ -23,6 +20,9 @@ main { yy++ } shifter+=4 + + sys.wait(1) + sys.waitvsync() } } } diff --git a/examples/vm/sincos.p8 b/examples/vm/sincos.p8 index 348bc732c..008f6f423 100644 --- a/examples/vm/sincos.p8 +++ b/examples/vm/sincos.p8 @@ -1,5 +1,4 @@ %import math -%import textio ; Draw sine and cosine graphs. The sine and cosine functions are table lookups ; where the tables are generated by 64tass list functions. @@ -27,8 +26,7 @@ main { sys.gfx_clear(0) circles() - repeat { - } + sys.wait(120) } sub sincos255() { diff --git a/examples/vm/textelite.p8 b/examples/vm/textelite.p8 index 6110597cd..1cb19fdb5 100644 --- a/examples/vm/textelite.p8 +++ b/examples/vm/textelite.p8 @@ -14,9 +14,10 @@ main { sub start() { txt.lowercase() - txt.print("--- TextElite v1.2 ---\n") - txt.print("VirtualMachine edition: no disk saving, bad text layout!\n") + txt.print("\n--- TextElite v1.2 ---\n") + txt.print("VirtualMachine edition: no disk saving, bad market table layout!\n") + planet.set_seed(0, 0) galaxy.travel_to(1, numforLave) market.init(0) ; Lave's market is seeded with 0 ship.init() @@ -435,11 +436,10 @@ galaxy { ubyte py = planet.y uword current_name = &planet.name ubyte pn = 0 - uword scaling = 8 + uword scaling = 2 if local - scaling = 2 + scaling = 1 - scaling /= 2 init(number) txt.clear_screen() txt.print("Galaxy #") @@ -457,7 +457,7 @@ galaxy { ubyte distance = planet.distance(px, py) if distance <= max_distance { planet.name = make_current_planet_name() - planet.name[0] |= 32 ; uppercase first letter + planet.name[0] = string.upperchar(planet.name[0]) uword tx = planet.x uword ty = planet.y if local { @@ -465,27 +465,30 @@ galaxy { ty = ty + 24 - py } tx /= scaling - ty /= scaling*2 + ty /= scaling*4 ubyte sx = lsb(tx) ubyte sy = lsb(ty) ubyte char = '*' if planet.number==current_planet char = '%' if local or planet.number==current_planet { - ;; NOT SUPPORTED txt.plot(2+sx-2, 2+sy+1) + txt.plot(2+sx-2, 2+sy+1) txt.print(current_name) if distance { - ;; NOT SUPPORTED txt.plot(2+sx-2, 2+sy+2) + txt.plot(2+sx-2, 2+sy+2) util.print_10s(distance) txt.print(" LY") } } - ;; NOT SUPPROTED txt.setchr(2+sx, 2+sy, char) + txt.setchr(2+sx, 2+sy, char) } pn++ } until pn==0 - ;; NOT SUPPORTED txt.plot(0,36) + if local + txt.plot(0, 20) + else + txt.plot(0, 33) txt.nl() travel_to(number, current_planet) @@ -603,18 +606,6 @@ galaxy { rol(xl) return mkword(xh, xl) } - - sub debug_seed() { - txt.print("\ngalaxy #") - txt.print_ub(number) - txt.print("\ngalaxy seed0=") - txt.print_uwhex(galaxy.seed[0], true) - txt.print("\ngalaxy seed1=") - txt.print_uwhex(galaxy.seed[1], true) - txt.print("\ngalaxy seed2=") - txt.print_uwhex(galaxy.seed[2], true) - txt.nl() - } } planet { @@ -723,7 +714,7 @@ planet { } } randname[nx] = 0 - randname[0] |= 32 ; uppercase first letter + randname[0] = string.upperchar(randname[0]) return randname } @@ -795,12 +786,12 @@ planet { source_ptr = source_stack[stack_ptr] } else { if c == $b0 { - @(result_ptr) = name[0] | 32 + @(result_ptr) = string.upperchar(name[0]) result_ptr++ concat_string(&name + 1) } else if c == $b1 { - @(result_ptr) = name[0] | 32 + @(result_ptr) = string.upperchar(name[0]) result_ptr++ ubyte ni for ni in 1 to len(name) { @@ -914,9 +905,10 @@ planet { } sub print_name_uppercase() { - ubyte c - for c in name - txt.chrout(c | 32) + str uppername = "????????" + uppername = name + void string.upper(uppername) + txt.print(uppername) } sub getword(ubyte listnum, ubyte wordidx) -> uword { @@ -933,8 +925,8 @@ util { if pc == 0 return true ; to lowercase for case insensitive compare: - pc &= 127 - sc &= 127 + pc = string.lowerchar(pc) + sc = string.lowerchar(sc) if pc != sc return false prefixptr++