mirror of
https://github.com/irmen/prog8.git
synced 2024-07-05 22:29:04 +00:00
fix clobbering of A when restoring X or Y from stack
This commit is contained in:
parent
c70b4daf87
commit
a40b3134f4
@ -584,16 +584,16 @@ internal class AsmGen(private val program: Program,
|
|||||||
CpuRegister.A -> out(" pla")
|
CpuRegister.A -> out(" pla")
|
||||||
CpuRegister.X -> {
|
CpuRegister.X -> {
|
||||||
if (CompilationTarget.instance.machine.cpu == CpuType.CPU65c02) out(" plx")
|
if (CompilationTarget.instance.machine.cpu == CpuType.CPU65c02) out(" plx")
|
||||||
else out(" pla | tax")
|
else out(" sta P8ZP_SCRATCH_REG | pla | tax | lda P8ZP_SCRATCH_REG")
|
||||||
}
|
}
|
||||||
CpuRegister.Y -> {
|
CpuRegister.Y -> {
|
||||||
if (CompilationTarget.instance.machine.cpu == CpuType.CPU65c02) out(" ply")
|
if (CompilationTarget.instance.machine.cpu == CpuType.CPU65c02) out(" ply")
|
||||||
else out(" pla | tay")
|
else out(" sta P8ZP_SCRATCH_REG | pla | tay | lda P8ZP_SCRATCH_REG")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
when (register) {
|
when (register) {
|
||||||
CpuRegister.A -> out(" sta _prog8_regsaveA")
|
CpuRegister.A -> out(" lda _prog8_regsaveA")
|
||||||
CpuRegister.X -> out(" ldx _prog8_regsaveX")
|
CpuRegister.X -> out(" ldx _prog8_regsaveX")
|
||||||
CpuRegister.Y -> out(" ldy _prog8_regsaveY")
|
CpuRegister.Y -> out(" ldy _prog8_regsaveY")
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,9 @@ internal class FunctionCallAsmGen(private val program: Program, private val asmg
|
|||||||
// does NOT output the code to deal with the result values!
|
// does NOT output the code to deal with the result values!
|
||||||
val sub = stmt.target.targetSubroutine(program.namespace) ?: throw AssemblyError("undefined subroutine ${stmt.target}")
|
val sub = stmt.target.targetSubroutine(program.namespace) ?: throw AssemblyError("undefined subroutine ${stmt.target}")
|
||||||
val saveX = sub.shouldSaveX()
|
val saveX = sub.shouldSaveX()
|
||||||
|
val regSaveOnStack = sub.asmAddress==null // rom-routines don't require registers to be saved on stack, normal subroutines do because they can contain nested calls
|
||||||
if(saveX)
|
if(saveX)
|
||||||
asmgen.saveRegister(CpuRegister.X, (stmt as Node).definingSubroutine()!!, true)
|
asmgen.saveRegister(CpuRegister.X, (stmt as Node).definingSubroutine()!!, regSaveOnStack)
|
||||||
|
|
||||||
val subName = asmgen.asmSymbolName(stmt.target)
|
val subName = asmgen.asmSymbolName(stmt.target)
|
||||||
if(stmt.args.isNotEmpty()) {
|
if(stmt.args.isNotEmpty()) {
|
||||||
@ -64,7 +65,7 @@ internal class FunctionCallAsmGen(private val program: Program, private val asmg
|
|||||||
}
|
}
|
||||||
asmgen.out(" jsr $subName")
|
asmgen.out(" jsr $subName")
|
||||||
if(saveX)
|
if(saveX)
|
||||||
asmgen.restoreRegister(CpuRegister.X, true)
|
asmgen.restoreRegister(CpuRegister.X, regSaveOnStack)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun registerArgsViaStackEvaluation(stmt: IFunctionCall, sub: Subroutine) {
|
private fun registerArgsViaStackEvaluation(stmt: IFunctionCall, sub: Subroutine) {
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
%import bmp_module
|
%import bmp_module
|
||||||
;; %import ci_module
|
;; %import ci_module
|
||||||
|
|
||||||
|
; TODO WHY is this 400 bytes larger than a few hours ago?
|
||||||
|
|
||||||
main {
|
main {
|
||||||
sub start() {
|
sub start() {
|
||||||
; trick to check if we're running on sdcard or host system shared folder
|
; trick to check if we're running on sdcard or host system shared folder
|
||||||
|
@ -7,8 +7,6 @@
|
|||||||
; staged speed increase
|
; staged speed increase
|
||||||
; some simple sound effects
|
; some simple sound effects
|
||||||
|
|
||||||
; TODO BROKEN: DOESN'T REGISTER KEYSTROKES ANYMORE (CAN'T START GAME)
|
|
||||||
|
|
||||||
|
|
||||||
%target c64
|
%target c64
|
||||||
%import syslib
|
%import syslib
|
||||||
|
@ -71,9 +71,13 @@ _y .byte 0
|
|||||||
|
|
||||||
sub start () {
|
sub start () {
|
||||||
|
|
||||||
while c64.CHRIN() {
|
txt.print("status 8: ")
|
||||||
; read the rest of the entry until the end
|
uword ss = diskio.status(8)
|
||||||
}
|
txt.print(ss)
|
||||||
|
txt.print("\nstatus 9: ")
|
||||||
|
ss = diskio.status(9)
|
||||||
|
txt.print(ss)
|
||||||
|
txt.chrout('\n')
|
||||||
|
|
||||||
; cx16.r0 = 65535
|
; cx16.r0 = 65535
|
||||||
; set_8_pixels_opaque_OLD(111,222,33)
|
; set_8_pixels_opaque_OLD(111,222,33)
|
||||||
|
@ -10,9 +10,6 @@
|
|||||||
|
|
||||||
; Note: this program is compatible with C64 and CX16.
|
; Note: this program is compatible with C64 and CX16.
|
||||||
|
|
||||||
; TODO BROKEN IN VICE WHEN LOADING WITHOUT DISK: PRINTS WEIRD CHARACTERS FOR IO-ERROR
|
|
||||||
|
|
||||||
|
|
||||||
main {
|
main {
|
||||||
|
|
||||||
const ubyte numforLave = 7 ; Lave is 7th generated planet in galaxy one
|
const ubyte numforLave = 7 ; Lave is 7th generated planet in galaxy one
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
%import test_stack
|
%import test_stack
|
||||||
%zeropage floatsafe
|
%zeropage floatsafe
|
||||||
|
|
||||||
|
; TODO WHY is this a couple of 100 bytes larger than a few hours ago?
|
||||||
|
|
||||||
main {
|
main {
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
|
Loading…
Reference in New Issue
Block a user