mirror of
https://github.com/irmen/prog8.git
synced 2024-12-23 09:32:43 +00:00
fix forloop 6502 codegen in case of descending word values
This commit is contained in:
parent
6055b8c3dc
commit
6b6427492d
@ -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
|
||||
@ -286,7 +269,6 @@ $endLabel""")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> throw AssemblyError("range expression can only be byte or word")
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
@ -1,34 +1,56 @@
|
||||
%import string
|
||||
%import textio
|
||||
%import conv
|
||||
|
||||
%zeropage basicsafe
|
||||
%option no_sysinit
|
||||
|
||||
main {
|
||||
|
||||
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() {
|
||||
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()
|
||||
print_hiscores()
|
||||
ubyte r = check_score(7500)
|
||||
print_hiscores()
|
||||
}
|
||||
|
||||
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()
|
||||
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()
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user