From 5b890847e55accdd7bea5dfdcac03b21326f4a8c Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 5 Apr 2021 23:12:10 +0200 Subject: [PATCH] make sure BASIC rom is banked in again when program exits --- compiler/res/prog8lib/cx16/syslib.p8 | 2 -- .../compiler/target/cpu6502/codegen/AsmGen.kt | 7 ++++++- examples/test.p8 | 14 ++++---------- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/compiler/res/prog8lib/cx16/syslib.p8 b/compiler/res/prog8lib/cx16/syslib.p8 index 0fecb24fa..1728e98c2 100644 --- a/compiler/res/prog8lib/cx16/syslib.p8 +++ b/compiler/res/prog8lib/cx16/syslib.p8 @@ -517,8 +517,6 @@ asmsub init_system() { jsr c64.CHROUT lda #147 ; clear screen jsr c64.CHROUT - ldx #4 - stx $01 ; select rom bank 4 (enable basic again) lda #0 tax tay diff --git a/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt b/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt index 5ee41fdb6..f84178bd5 100644 --- a/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt +++ b/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt @@ -157,7 +157,12 @@ internal class AsmGen(private val program: Program, pha""") } - jmp("main.start") + // make sure that on the cx16 and c64, basic rom is banked in again when we exit the program + when(compTarget.name) { + Cx16Target.name -> out(" jsr main.start | lda #4 | sta $01 | rts") + C64Target.name -> out(" jsr main.start | lda #31 | sta $01 | rts") + else -> jmp("main.start") + } } private fun slaballocations() { diff --git a/examples/test.p8 b/examples/test.p8 index 2b79458ce..fdaca91db 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,22 +1,15 @@ %import textio %import floats -%zeropage dontuse +%zeropage basicsafe main { sub start() { + ;cx16.rombank(4) float f1 = 9.9999 float f2 = 8.8888 float f3 = 0.1111 - %asm {{ - phx - ldy #f1 - jsr $FE42 - jsr $FE7B - plx - }} f3=cos(f3) floats.print_f(f1) @@ -28,9 +21,10 @@ main { f3 = cos(f3) floats.print_f(f3) + cx16.rombank(0) + txt.print("ok!\n") sys.wait(2*60) - } }