mirror of
https://github.com/irmen/prog8.git
synced 2024-11-18 19:12:44 +00:00
fix crashes in peekw() and pokew()
This commit is contained in:
parent
4c080afb76
commit
bf1b2066b6
@ -1072,18 +1072,21 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
}
|
||||
is BinaryExpression -> {
|
||||
if(addrExpr.operator=="+" && addrExpr.left is IdentifierReference && addrExpr.right is NumericLiteralValue) {
|
||||
asmgen.saveRegisterLocal(CpuRegister.X, (fcall as Node).definingSubroutine()!!)
|
||||
asmgen.assignExpressionToRegister(fcall.args[1], RegisterOrPair.AX)
|
||||
val varname = asmgen.asmVariableName(addrExpr.left as IdentifierReference)
|
||||
val index = (addrExpr.right as NumericLiteralValue).number.toHex()
|
||||
asmgen.out("""
|
||||
ldy #$index
|
||||
sta ($varname),y
|
||||
txa
|
||||
iny
|
||||
sta ($varname),y""")
|
||||
asmgen.restoreRegisterLocal(CpuRegister.X)
|
||||
return
|
||||
if(asmgen.isZpVar(addrExpr.left as IdentifierReference)) {
|
||||
// pointervar is already in the zero page, no need to copy
|
||||
asmgen.saveRegisterLocal(CpuRegister.X, (fcall as Node).definingSubroutine()!!)
|
||||
asmgen.assignExpressionToRegister(fcall.args[1], RegisterOrPair.AX)
|
||||
val index = (addrExpr.right as NumericLiteralValue).number.toHex()
|
||||
asmgen.out("""
|
||||
ldy #$index
|
||||
sta ($varname),y
|
||||
txa
|
||||
iny
|
||||
sta ($varname),y""")
|
||||
asmgen.restoreRegisterLocal(CpuRegister.X)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1127,15 +1130,21 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
is BinaryExpression -> {
|
||||
if(addrExpr.operator=="+" && addrExpr.left is IdentifierReference && addrExpr.right is NumericLiteralValue) {
|
||||
val varname = asmgen.asmVariableName(addrExpr.left as IdentifierReference)
|
||||
val index = (addrExpr.right as NumericLiteralValue).number.toHex()
|
||||
asmgen.out("""
|
||||
ldy #$index
|
||||
lda ($varname),y
|
||||
pha
|
||||
iny
|
||||
lda ($varname),y
|
||||
tay
|
||||
pla""")
|
||||
if(asmgen.isZpVar(addrExpr.left as IdentifierReference)) {
|
||||
// pointervar is already in the zero page, no need to copy
|
||||
val index = (addrExpr.right as NumericLiteralValue).number.toHex()
|
||||
asmgen.out("""
|
||||
ldy #$index
|
||||
lda ($varname),y
|
||||
pha
|
||||
iny
|
||||
lda ($varname),y
|
||||
tay
|
||||
pla""")
|
||||
} else {
|
||||
asmgen.assignExpressionToRegister(fcall.args[0], RegisterOrPair.AY)
|
||||
asmgen.out(" jsr prog8_lib.func_peekw")
|
||||
}
|
||||
} else {
|
||||
asmgen.assignExpressionToRegister(fcall.args[0], RegisterOrPair.AY)
|
||||
asmgen.out(" jsr prog8_lib.func_peekw")
|
||||
|
@ -1,67 +1,22 @@
|
||||
%import textio
|
||||
%import string
|
||||
%zeropage basicsafe
|
||||
%zeropage dontuse
|
||||
%import test_stack
|
||||
%option no_sysinit
|
||||
|
||||
main {
|
||||
|
||||
sub start() {
|
||||
ubyte fromub = 120
|
||||
uword fromuw = 400
|
||||
byte fromb = 120
|
||||
word fromw = 400
|
||||
uword zz = $4000
|
||||
|
||||
uword counter
|
||||
byte bc
|
||||
ubyte ubc
|
||||
word wc
|
||||
uword uwc
|
||||
txt.print("hello")
|
||||
|
||||
counter = 0
|
||||
for bc in fromb to 0 step -1 {
|
||||
counter++
|
||||
txt.print_b(bc)
|
||||
txt.spc()
|
||||
}
|
||||
txt.nl()
|
||||
txt.print_uw(counter)
|
||||
txt.nl()
|
||||
txt.nl()
|
||||
txt.print_uwhex(peekw(zz+2), true)
|
||||
|
||||
counter = 0
|
||||
for ubc in fromub to 0 step -1 {
|
||||
counter++
|
||||
txt.print_ub(ubc)
|
||||
txt.spc()
|
||||
}
|
||||
txt.nl()
|
||||
txt.print_uw(counter)
|
||||
txt.nl()
|
||||
txt.nl()
|
||||
|
||||
counter = 0
|
||||
for wc in fromw to 0 step -1 {
|
||||
counter++
|
||||
txt.print_w(wc)
|
||||
txt.spc()
|
||||
}
|
||||
txt.nl()
|
||||
txt.print_uw(counter)
|
||||
txt.nl()
|
||||
txt.nl()
|
||||
|
||||
; TODO FIX THIS LOOP??
|
||||
counter = 0
|
||||
for uwc in fromuw to 0 step -1 {
|
||||
counter++
|
||||
txt.print_uw(uwc)
|
||||
txt.spc()
|
||||
}
|
||||
txt.nl()
|
||||
txt.print_uw(counter)
|
||||
txt.nl()
|
||||
txt.nl()
|
||||
@(zz+2) = lsb($ea31)
|
||||
@(zz+3) = msb($ea31)
|
||||
pokew(zz+2, $ea32) ; TODO fix crash
|
||||
zz = peekw(zz+2) ; TODO fix crash with asm
|
||||
txt.print_uwhex(zz, true)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user