adapted p8 code to restricted array indexing

This commit is contained in:
Irmen de Jong 2020-10-17 16:09:14 +02:00
parent 7626c9fff7
commit 157484d94b
9 changed files with 56 additions and 109 deletions

View File

@ -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(

View File

@ -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
}
}
}

View File

@ -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

View File

@ -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]++

View File

@ -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()
}

View File

@ -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 hex1<hex2
txt.print("5 fail <\n")
else
txt.print("6 ok not <\n")
endlab6:
txt.chrout('\n')
txt.print_ub(hex1==hex2)
txt.print(" 0?\n")
txt.print_ub(hex1!=hex2)
txt.print(" 1?\n")
txt.print_ub(hex1>hex2)
txt.print(" 1?\n")
txt.print_ub(hex1<hex2)
txt.print(" 0?\n")
txt.print_ub(hex1>=hex2)
txt.print(" 1?\n")
txt.print_ub(hex1<=hex2)
txt.print(" 0?\n")
testX()
}

View File

@ -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
}
}

View File

@ -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++
}
}

View File

@ -3,6 +3,9 @@
%import graphics
%zeropage floatsafe
; TODO Fix broken line output
main {
sub start() {