diff --git a/compiler/res/prog8lib/c64/syslib.p8 b/compiler/res/prog8lib/c64/syslib.p8 index 0ac1e328d..eaf38f22f 100644 --- a/compiler/res/prog8lib/c64/syslib.p8 +++ b/compiler/res/prog8lib/c64/syslib.p8 @@ -259,6 +259,16 @@ asmsub init_system() { }} } +asmsub reset_system() { + ; Soft-reset the system back to Basic prompt. + %asm {{ + sei + lda #14 + sta $01 ; bank the kernal in + jmp (c64.RESET_VEC) + }} +} + asmsub set_irqvec_excl() clobbers(A) { %asm {{ sei diff --git a/compiler/res/prog8lib/cx16/syslib.p8 b/compiler/res/prog8lib/cx16/syslib.p8 index b9b458014..bb53d4769 100644 --- a/compiler/res/prog8lib/cx16/syslib.p8 +++ b/compiler/res/prog8lib/cx16/syslib.p8 @@ -277,4 +277,15 @@ asmsub init_system() { }} } +asmsub reset_system() { + ; Soft-reset the system back to Basic prompt. + %asm {{ + sei + lda #14 + sta $01 + stz cx16.d1prb ; bank the kernal in + jmp (cx16.RESET_VEC) + }} +} + } diff --git a/compiler/res/prog8lib/cx16/textio.p8 b/compiler/res/prog8lib/cx16/textio.p8 index c626a337a..ab1fe967e 100644 --- a/compiler/res/prog8lib/cx16/textio.p8 +++ b/compiler/res/prog8lib/cx16/textio.p8 @@ -154,6 +154,13 @@ asmsub scroll_left (ubyte dummy @ Pc) clobbers(A, Y) { ; ---- scroll the whole screen 1 character to the left ; contents of the rightmost column are unchanged, you should clear/refill this yourself ; Carry flag is a dummy on the cx16 + %asm {{ + phx + jsr c64.SCREEN + + plx + rts + }} } asmsub scroll_right (ubyte dummy @ Pc) clobbers(A) { @@ -166,6 +173,7 @@ asmsub scroll_up (ubyte dummy @ Pc) clobbers(A, Y) { ; ---- scroll the whole screen 1 character up ; contents of the bottom row are unchanged, you should refill/clear this yourself ; Carry flag is a dummy on the cx16 + ; TODO maybe a version without using intermediate buffer is faster? (avoid double store/read) %asm {{ phx jsr c64.SCREEN @@ -265,6 +273,7 @@ asmsub scroll_down (ubyte dummy @ Pc) clobbers(A, Y) { ; ---- scroll the whole screen 1 character down ; contents of the top row are unchanged, you should refill/clear this yourself ; Carry flag is a dummy on the cx16 + ; TODO maybe a version without using intermediate buffer is faster? (avoid double store/read) %asm {{ phx jsr c64.SCREEN diff --git a/compiler/src/prog8/compiler/target/CompilationTarget.kt b/compiler/src/prog8/compiler/target/CompilationTarget.kt index 090a7df37..8baf073a3 100644 --- a/compiler/src/prog8/compiler/target/CompilationTarget.kt +++ b/compiler/src/prog8/compiler/target/CompilationTarget.kt @@ -17,8 +17,8 @@ internal interface CompilationTarget { fun encodeString(str: String, altEncoding: Boolean): List fun decodeString(bytes: List, altEncoding: Boolean): String fun asmGenerator(program: Program, errors: ErrorReporter, zp: Zeropage, options: CompilationOptions, path: Path): IAssemblyGenerator - val asmForSystemReset: String val initProcName: String? + val resetProcName: String? companion object { lateinit var instance: CompilationTarget @@ -35,8 +35,8 @@ internal object C64Target: CompilationTarget { if(altEncoding) Petscii.decodeScreencode(bytes, true) else Petscii.decodePetscii(bytes, true) override fun asmGenerator(program: Program, errors: ErrorReporter, zp: Zeropage, options: CompilationOptions, path: Path) = AsmGen(program, errors, zp, options, path) - override val asmForSystemReset = " sei | lda #14 | sta $1 | jmp (c64.RESET_VEC)" override val initProcName = "c64.init_system" + override val resetProcName = "c64.reset_system" } internal object Cx16Target: CompilationTarget { @@ -48,6 +48,6 @@ internal object Cx16Target: CompilationTarget { if(altEncoding) Petscii.decodeScreencode(bytes, true) else Petscii.decodePetscii(bytes, true) override fun asmGenerator(program: Program, errors: ErrorReporter, zp: Zeropage, options: CompilationOptions, path: Path) = AsmGen(program, errors, zp, options, path) - override val asmForSystemReset = " sei | stz cx16.d1prb | jmp (cx16.RESET_VEC)" override val initProcName = "cx16.init_system" + override val resetProcName = "cx16.reset_system" } diff --git a/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt index 8bbcfa30e..fb61d722a 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt @@ -163,7 +163,7 @@ internal class AsmGen(private val program: Program, } Zeropage.ExitProgramStrategy.SYSTEM_RESET -> { out(" jsr main.start\t; call program entrypoint") - out(CompilationTarget.instance.asmForSystemReset) + out(" jmp ${CompilationTarget.instance.resetProcName}") } } } diff --git a/examples/test.p8 b/examples/test.p8 index 0a3f88055..1abc3a21d 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,7 +1,7 @@ %import syslib ; %import graphics %import textio -%zeropage basicsafe +; %zeropage basicsafe main { @@ -16,9 +16,9 @@ main { ; } ; } - repeat 60 { - txt.setcc(rnd() % 80, 59, 81, 5) - txt.scroll_up(true) + repeat txt.DEFAULT_WIDTH { + txt.setcc(txt.DEFAULT_WIDTH-1, rnd() % txt.DEFAULT_HEIGHT, 81, 2) + txt.scroll_left(true) repeat 5000 { x++