diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/ForLoopsAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/ForLoopsAsmGen.kt index deb7b64cd..5906c3ae3 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/ForLoopsAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/ForLoopsAsmGen.kt @@ -249,23 +249,6 @@ $endLabel""") $loopLabel""") asmgen.translate(stmt.statements) - if(iterableDt==DataType.ARRAY_UW) { - asmgen.out(""" - lda $varname - sec - sbc #<${stepsize.absoluteValue} - sta $varname - lda $varname+1 - sbc #>${stepsize.absoluteValue} - sta $varname+1 -$modifiedLabel cmp #0 ; modified - bcc $endLabel - bne $loopLabel - lda $varname -$modifiedLabel2 cmp #0 ; modified - bcs $loopLabel -$endLabel""") - } else { asmgen.out(""" lda $varname sec @@ -283,7 +266,6 @@ $modifiedLabel sbc #0 ; modified eor #$80 + bpl $loopLabel $endLabel""") - } } } } diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 2cd306b14..b156ff607 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -1,8 +1,6 @@ TODO ==== -- codegen: fix endless loop uword n=0 :: for uword i in 10 downto n step -3 - - investigate if the hiscores issue on the forum is a compiler bug or not. - IR: instructions that do type conversion (SZ etc, CONCAT, SGN) should put the result in a DIFFERENT register. diff --git a/examples/test.p8 b/examples/test.p8 index 9db4dd57e..538293f83 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,34 +1,56 @@ +%import string %import textio +%import conv + %zeropage basicsafe -%option no_sysinit main { - sub start() { - uword n=0 - uword i - txt.print("ascending:\n") - n=10 - for i in 0 to n step 3 { - cx16.r0++ - txt.print(" i=") - txt.print_uw(i) - txt.spc() - txt.print(" n=") - txt.print_uw(n) - txt.nl() - } - txt.print("descending:\n") - n=0 - for i in 10 downto n step -3 { - cx16.r0++ - txt.print(" i=") - txt.print_uw(i) - txt.spc() - txt.print(" n=") - txt.print_uw(n) - txt.nl() - } - } +str[10] names = ["1??","2??","3??","4??","5??","6??","7??","8??","9??","a??"] +str[10] scores = ["9000","8000","7000","6000","5000","4000","3000","2000","1000","50"] +str p_str = "winner" +uword top_score + +sub start() { + print_hiscores() + ubyte r = check_score(7500) + print_hiscores() } +sub check_score(uword score) -> ubyte { + ubyte n + ubyte i + str tmp = "?????" + + if score < top_score { + return(10) } + else { + for n in 0 to 9 { + if score > conv.str2uword(scores[n]) { + for i in 8 to n step -1 { + names[i+1] = names[i] + scores[i+1] = scores[i] + } + ;string.copy(p_str,names[n]) + ;conv.str_uw0(score) + ;string.copy(conv.string_out,scores[n]) + return(n) + } + } + } +} + +sub print_hiscores() { + ubyte n + for n in 0 to 9 { + txt.print_ub(n) + txt.spc() + txt.print(names[n]) + txt.spc() + txt.print(scores[n]) + txt.nl() + } + txt.nl() +} + +}