mirror of
https://github.com/irmen/prog8.git
synced 2024-11-18 19:12:44 +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.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")
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user