From 157484d94bd3ed2e86ad4420f4a73a2d28148de9 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 17 Oct 2020 16:09:14 +0200 Subject: [PATCH] adapted p8 code to restricted array indexing --- compiler/src/prog8/compiler/Main.kt | 2 +- examples/cube3d-sprites.p8 | 3 +- examples/primes.p8 | 3 +- examples/sprites.p8 | 9 ++-- examples/tehtriz.p8 | 3 +- examples/test.p8 | 71 +---------------------------- examples/testarrays.p8 | 40 ++++++++-------- examples/textelite.p8 | 31 ++++++++----- examples/turtle-gfx.p8 | 3 ++ 9 files changed, 56 insertions(+), 109 deletions(-) diff --git a/compiler/src/prog8/compiler/Main.kt b/compiler/src/prog8/compiler/Main.kt index bae223d0c..239f5ca10 100644 --- a/compiler/src/prog8/compiler/Main.kt +++ b/compiler/src/prog8/compiler/Main.kt @@ -221,7 +221,7 @@ private fun writeAssembly(programAst: Program, errors: ErrorReporter, outputDir: programAst.processAstBeforeAsmGeneration(errors) errors.handle() - printAst(programAst) // TODO + // printAst(programAst) CompilationTarget.instance.machine.initializeZeropage(compilerOptions) val assembly = CompilationTarget.instance.asmGenerator( diff --git a/examples/cube3d-sprites.p8 b/examples/cube3d-sprites.p8 index 6f935f136..bdc89ff43 100644 --- a/examples/cube3d-sprites.p8 +++ b/examples/cube3d-sprites.p8 @@ -166,7 +166,8 @@ main { else c64.SPRPTR[i] = $2000/64 ; small ball - c64.SPCOL[i] = spritecolors[(zc>>13) as byte + 4] ; further away=darker color + ubyte sci = (zc>>13) as ubyte + 4 ; TODO is index for array + c64.SPCOL[i] = spritecolors[sci] ; further away=darker color } } } diff --git a/examples/primes.p8 b/examples/primes.p8 index 91a95e0ac..67b3836cc 100644 --- a/examples/primes.p8 +++ b/examples/primes.p8 @@ -43,7 +43,8 @@ main { while multiple < len(sieve) { - sieve[lsb(multiple)] = true + ubyte si = lsb(multiple) ; TODO is index for array + sieve[si] = true multiple += candidate_prime } return candidate_prime diff --git a/examples/sprites.p8 b/examples/sprites.p8 index 90598dff7..2cccbdd9b 100644 --- a/examples/sprites.p8 +++ b/examples/sprites.p8 @@ -41,8 +41,10 @@ main { ubyte @zp i for i in 0 to 7 { c64.SPRPTR[i] = $0a00 / 64 - c64.SPXY[i*2] = 50+25*i - c64.SPXY[i*2+1] = rnd() + ubyte twoi = i*2 ; TODO is index for array + c64.SPXY[twoi] = 50+25*i + twoi++ ; TODO is index for array + c64.SPXY[twoi] = rnd() } c64.SPENA = 255 ; enable all sprites @@ -59,7 +61,8 @@ irq { ; float up & wobble horizontally ubyte @zp i for i in 0 to 14 step 2 { - c64.SPXY[i+1]-- + ubyte ipp=i+1 ; TODO is index for array + c64.SPXY[ipp]-- ubyte @zp r = rnd() if r>200 c64.SPXY[i]++ diff --git a/examples/tehtriz.p8 b/examples/tehtriz.p8 index 1188e699c..8c970e158 100644 --- a/examples/tehtriz.p8 +++ b/examples/tehtriz.p8 @@ -219,7 +219,8 @@ waitkey: blocklogic.collapse(linepos) lines += num_lines uword[] scores = [10, 25, 50, 100] ; can never clear more than 4 lines - score += scores[num_lines-1] + ubyte scorei = num_lines-1 ; TODO is index for array + score += scores[scorei] speedlevel = 1+lsb(lines/10) drawScore() } diff --git a/examples/test.p8 b/examples/test.p8 index 73d2653fe..00be206a3 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,81 +1,12 @@ %import textio %import conv +%import floats %zeropage basicsafe main { - %option force_output sub start() { - str hex1 = "aap2" - str hex2 = "aap1je" - str hex3 = "aap1JE" - str hex4 = "aap3333" - -; byte result -; result = strcmp(hex1, hex1) -; txt.print_b(result) -; txt.chrout('\n') -; result = strcmp(hex1, hex1) -; txt.print_b(result) -; txt.chrout('\n') -; result = strcmp(hex1, hex2) -; txt.print_b(result) -; txt.chrout('\n') -; result = strcmp(hex1, hex3) -; txt.print_b(result) -; txt.chrout('\n') -; result = strcmp(hex1, hex4) -; txt.print_b(result) -; txt.chrout('\n') -; txt.chrout('\n') - - if hex1==hex2 - txt.print("1 fail ==\n") - else - txt.print("1 ok not ==\n") -endlab1: - if hex1!=hex2 - txt.print("2 ok !==\n") - else - txt.print("2 fail not !=\n") -endlab2: - if hex1>=hex2 - txt.print("3 ok >=\n") - else - txt.print("3 fail not >=\n") -endlab3: - if hex1<=hex2 - txt.print("4 fail <=\n") - else - txt.print("4 ok not <=\n") -endlab4: - if hex1>hex2 - txt.print("5 ok >\n") - else - txt.print("5 fail not >\n") -endlab5: - if hex1hex2) - txt.print(" 1?\n") - txt.print_ub(hex1=hex2) - txt.print(" 1?\n") - txt.print_ub(hex1<=hex2) - txt.print(" 0?\n") - testX() } diff --git a/examples/testarrays.p8 b/examples/testarrays.p8 index 2b2922097..ac4bc1fd1 100644 --- a/examples/testarrays.p8 +++ b/examples/testarrays.p8 @@ -83,20 +83,20 @@ main { uw=muwarray[bb] fl=mflarray[bb] - A=s1[bb*3] - ub=s1[bb*3] - bb=barray[bb*3] - ub=ubarray[bb*3] - ww=warray[bb*3] - uw=uwarray[bb*3] - fl=flarray[bb*3] - A=ms1[bb*3] - ub=ms1[bb*3] - bb=mbarray[bb*3] - ub=mubarray[bb*3] - ww=mwarray[bb*3] - uw=muwarray[bb*3] - fl=mflarray[bb*3] +; A=s1[bb*3] +; ub=s1[bb*3] +; bb=barray[bb*3] +; ub=ubarray[bb*3] +; ww=warray[bb*3] +; uw=uwarray[bb*3] +; fl=flarray[bb*3] +; A=ms1[bb*3] +; ub=ms1[bb*3] +; bb=mbarray[bb*3] +; ub=mubarray[bb*3] +; ww=mwarray[bb*3] +; uw=muwarray[bb*3] +; fl=mflarray[bb*3] ; write array barray[2]++ @@ -132,11 +132,11 @@ main { uwarray[bb] = uw flarray[bb] = fl - s1[bb*3] = ub - barray[bb*3] = bb - ubarray[bb*3] = ub - warray[bb*3] = ww - uwarray[bb*3] = uw - flarray[bb*3] = fl +; s1[bb*3] = ub +; barray[bb*3] = bb +; ubarray[bb*3] = ub +; warray[bb*3] = ww +; uwarray[bb*3] = uw +; flarray[bb*3] = fl } } diff --git a/examples/textelite.p8 b/examples/textelite.p8 index 460d16ba3..bafa0b4d9 100644 --- a/examples/textelite.p8 +++ b/examples/textelite.p8 @@ -9,7 +9,7 @@ ; Note: this program is compatible with C64 and CX16. - +; TODO error check on load, now wipes cash and fuel etc when load fails ; TODO finalize and test save/load game function main { @@ -360,7 +360,8 @@ market { util.print_10s(current_price[ci]) txt.print(" ") txt.print_ub(current_quantity[ci]) - txt.print(unitnames[units[ci]]) + ubyte ui = units[ci] ; TODO is index for array + txt.print(unitnames[ui]) txt.print(" ") txt.print_ub(ship.cargohold[ci]) txt.chrout('\n') @@ -505,28 +506,33 @@ galaxy { sub make_current_planet_name() -> str { ubyte ni = 0 str name = " " ; max 8 + ubyte pn_pair1_p1 = pn_pair1+1 ; TODO is index for array + ubyte pn_pair2_p1 = pn_pair2+1 ; TODO is index for array + ubyte pn_pair3_p1 = pn_pair3+1 ; TODO is index for array + ubyte pn_pair4_p1 = pn_pair4+1 ; TODO is index for array + if pn_pairs[pn_pair1] != '.' { name[ni] = pn_pairs[pn_pair1] ni++ } - if pn_pairs[pn_pair1+1] != '.' { - name[ni] = pn_pairs[pn_pair1+1] + if pn_pairs[pn_pair1_p1] != '.' { + name[ni] = pn_pairs[pn_pair1_p1] ni++ } if pn_pairs[pn_pair2] != '.' { name[ni] = pn_pairs[pn_pair2] ni++ } - if pn_pairs[pn_pair2+1] != '.' { - name[ni] = pn_pairs[pn_pair2+1] + if pn_pairs[pn_pair2_p1] != '.' { + name[ni] = pn_pairs[pn_pair2_p1] ni++ } if pn_pairs[pn_pair3] != '.' { name[ni] = pn_pairs[pn_pair3] ni++ } - if pn_pairs[pn_pair3+1] != '.' { - name[ni] = pn_pairs[pn_pair3+1] + if pn_pairs[pn_pair3_p1] != '.' { + name[ni] = pn_pairs[pn_pair3_p1] ni++ } @@ -535,8 +541,8 @@ galaxy { name[ni] = pn_pairs[pn_pair4] ni++ } - if pn_pairs[pn_pair4+1] != '.' { - name[ni] = pn_pairs[pn_pair4+1] + if pn_pairs[pn_pair4_p1] != '.' { + name[ni] = pn_pairs[pn_pair4_p1] ni++ } } @@ -704,8 +710,9 @@ planet { name[nx] = pairs0[x] nx++ } - if pairs0[x+1] != '.' { - name[nx] = pairs0[x+1] + x++ ; TODO is index for array + if pairs0[x] != '.' { + name[nx] = pairs0[x] nx++ } } diff --git a/examples/turtle-gfx.p8 b/examples/turtle-gfx.p8 index 688eadbed..80143a839 100644 --- a/examples/turtle-gfx.p8 +++ b/examples/turtle-gfx.p8 @@ -3,6 +3,9 @@ %import graphics %zeropage floatsafe +; TODO Fix broken line output + + main { sub start() {