From c11a52b2782b673437bc979b62e8bd25c7b3e0cc Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 3 Nov 2024 21:52:04 +0100 Subject: [PATCH] added cx16 banking example --- docs/source/technical.rst | 4 ++++ docs/source/todo.rst | 2 -- examples/cx16/banking/Makefile | 13 ++++++++++++ examples/cx16/banking/library1.asm | 26 +++++++++++++++++++++++ examples/cx16/banking/library2.asm | 26 +++++++++++++++++++++++ examples/cx16/banking/program.p8 | 34 ++++++++++++++++++++++++++++++ 6 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 examples/cx16/banking/Makefile create mode 100644 examples/cx16/banking/library1.asm create mode 100644 examples/cx16/banking/library2.asm create mode 100644 examples/cx16/banking/program.p8 diff --git a/docs/source/technical.rst b/docs/source/technical.rst index fadb46d5d..8c77308bc 100644 --- a/docs/source/technical.rst +++ b/docs/source/technical.rst @@ -53,6 +53,10 @@ compilation targets, and not all targets even have banking or support this. As a on the Commander X16, prog8 will use the JSRFAR kernal routine for this. On the Commodore 128, a similar call exists. Other compilation targets don't have banking or prog8 doesn't yet support automatic bank selection on them. +There's a "banking" (not financial) example for the Commander X16 that shows a possible application +of the romsub with bank support, check out the `bank example code `_ . + + Notice that the symbol for this routine in the assembly source code will still be defined as usual. The bank number is not translated into assembly (only as a comment):: diff --git a/docs/source/todo.rst b/docs/source/todo.rst index e2f4fee02..aad76d5bb 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -1,8 +1,6 @@ TODO ==== -add example for cx16 that compiles and loads libraries in different ram banks and calls romsub from rom and ram banks automatically - add support for banked romsubs on the C64 as well (banks basic/kernal rom in/out) rename 'romsub' to 'extsub' ? keep romsub as alias? diff --git a/examples/cx16/banking/Makefile b/examples/cx16/banking/Makefile new file mode 100644 index 000000000..e75f4e651 --- /dev/null +++ b/examples/cx16/banking/Makefile @@ -0,0 +1,13 @@ +.PHONY: all clean zip run + +all: PROGRAM.PRG + +PROGRAM.PRG: library1.asm library2.asm program.p8 + 64tass --case-sensitive --ascii --long-branch library1.asm -o LIBRARY1.PRG + 64tass --case-sensitive --ascii --long-branch library2.asm -o LIBRARY2.PRG + prog8c -target cx16 program.p8 + mv program.prg PROGRAM.PRG + +run: PROGRAM.PRG + x16emu -scale 2 -run -prg PROGRAM.PRG + diff --git a/examples/cx16/banking/library1.asm b/examples/cx16/banking/library1.asm new file mode 100644 index 000000000..545b6056a --- /dev/null +++ b/examples/cx16/banking/library1.asm @@ -0,0 +1,26 @@ +.cpu 'w65c02' +.enc 'none' + +* = $a000 + +CHROUT = $ffd2 + +message_pointer = $02 + +routine1: + lda #message + sta message_pointer+1 + ldy #0 +- lda (message_pointer),y + beq + + jsr CHROUT + iny + bne - ++ lda #<12345 + ldy #>12345 + rts + +message: + .text "hello from routine 1",13,0 diff --git a/examples/cx16/banking/library2.asm b/examples/cx16/banking/library2.asm new file mode 100644 index 000000000..3e44c2751 --- /dev/null +++ b/examples/cx16/banking/library2.asm @@ -0,0 +1,26 @@ +.cpu 'w65c02' +.enc 'none' + +* = $a000 + +CHROUT = $ffd2 + +message_pointer = $02 + +routine1: + lda #message + sta message_pointer+1 + ldy #0 +- lda (message_pointer),y + beq + + jsr CHROUT + iny + bne - ++ lda #<44444 + ldy #>44444 + rts + +message: + .text "hello from routine 2",13,0 diff --git a/examples/cx16/banking/program.p8 b/examples/cx16/banking/program.p8 new file mode 100644 index 000000000..e90a20c0f --- /dev/null +++ b/examples/cx16/banking/program.p8 @@ -0,0 +1,34 @@ +%import textio +%import diskio + +%option no_sysinit +%zeropage basicsafe + +main { + romsub @bank 4 $A000 = lib_routine1(ubyte value @A) clobbers(X) -> uword @AY + romsub @bank 5 $A000 = lib_routine2(ubyte value @A) clobbers(X) -> uword @AY + romsub @bank 10 $C09F = audio_init() -> bool @A + + sub start() { + + ; load the example libraries in hiram banks 4 and 5 + cx16.rambank(4) + void diskio.load("library1.prg", $a000) + cx16.rambank(5) + void diskio.load("library2.prg", $a000) + + cx16.rambank(1) + + ; call a routine from the Audio rom bank: + bool success = audio_init() + + ; call hiram banked loaded routines: + cx16.r0 = lib_routine1(11) + txt.print_uw(cx16.r0) + txt.nl() + + cx16.r0 = lib_routine2(99) + txt.print_uw(cx16.r0) + txt.nl() + } +}