fix clobbering of A when restoring X or Y from stack

This commit is contained in:
Irmen de Jong 2020-12-22 04:52:46 +01:00
parent c70b4daf87
commit a40b3134f4
7 changed files with 17 additions and 13 deletions

View File

@ -584,16 +584,16 @@ internal class AsmGen(private val program: Program,
CpuRegister.A -> out(" pla")
CpuRegister.X -> {
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 -> {
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 {
when (register) {
CpuRegister.A -> out(" sta _prog8_regsaveA")
CpuRegister.A -> out(" lda _prog8_regsaveA")
CpuRegister.X -> out(" ldx _prog8_regsaveX")
CpuRegister.Y -> out(" ldy _prog8_regsaveY")
}

View File

@ -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!
val sub = stmt.target.targetSubroutine(program.namespace) ?: throw AssemblyError("undefined subroutine ${stmt.target}")
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)
asmgen.saveRegister(CpuRegister.X, (stmt as Node).definingSubroutine()!!, true)
asmgen.saveRegister(CpuRegister.X, (stmt as Node).definingSubroutine()!!, regSaveOnStack)
val subName = asmgen.asmSymbolName(stmt.target)
if(stmt.args.isNotEmpty()) {
@ -64,7 +65,7 @@ internal class FunctionCallAsmGen(private val program: Program, private val asmg
}
asmgen.out(" jsr $subName")
if(saveX)
asmgen.restoreRegister(CpuRegister.X, true)
asmgen.restoreRegister(CpuRegister.X, regSaveOnStack)
}
private fun registerArgsViaStackEvaluation(stmt: IFunctionCall, sub: Subroutine) {

View File

@ -8,6 +8,8 @@
%import bmp_module
;; %import ci_module
; TODO WHY is this 400 bytes larger than a few hours ago?
main {
sub start() {
; trick to check if we're running on sdcard or host system shared folder

View File

@ -7,8 +7,6 @@
; staged speed increase
; some simple sound effects
; TODO BROKEN: DOESN'T REGISTER KEYSTROKES ANYMORE (CAN'T START GAME)
%target c64
%import syslib

View File

@ -71,9 +71,13 @@ _y .byte 0
sub start () {
while c64.CHRIN() {
; read the rest of the entry until the end
}
txt.print("status 8: ")
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
; set_8_pixels_opaque_OLD(111,222,33)

View File

@ -10,9 +10,6 @@
; Note: this program is compatible with C64 and CX16.
; TODO BROKEN IN VICE WHEN LOADING WITHOUT DISK: PRINTS WEIRD CHARACTERS FOR IO-ERROR
main {
const ubyte numforLave = 7 ; Lave is 7th generated planet in galaxy one

View File

@ -4,6 +4,8 @@
%import test_stack
%zeropage floatsafe
; TODO WHY is this a couple of 100 bytes larger than a few hours ago?
main {
sub start() {