cx16: added cx16.push_rambank/rombank and cx16.pop_rambank/rombank for easy temporary bank switching

This commit is contained in:
Irmen de Jong
2025-04-06 15:33:35 +02:00
parent b72877d59d
commit 69c96ad99b
4 changed files with 49 additions and 31 deletions
+36
View File
@@ -757,6 +757,42 @@ inline asmsub getrambank() -> ubyte @A {
}}
}
inline asmsub push_rombank(ubyte newbank @A) clobbers(Y) {
; push the current rombank on the stack and makes the given rom bank active
; combined with pop_rombank() makes for easy temporary rom bank switch
%asm {{
ldy $01
phy
sta $01
}}
}
inline asmsub pop_rombank() {
; sets the current rom bank back to what was stored previously on the stack
%asm {{
pla
sta $01
}}
}
inline asmsub push_rambank(ubyte newbank @A) clobbers(Y) {
; push the current hiram bank on the stack and makes the given hiram bank active
; combined with pop_rombank() makes for easy temporary hiram bank switch
%asm {{
ldy $00
phy
sta $00
}}
}
inline asmsub pop_rambank() {
; sets the current hiram bank back to what was stored previously on the stack
%asm {{
pla
sta $00
}}
}
asmsub numbanks() clobbers(X) -> uword @AY {
; -- Returns the number of available RAM banks according to the kernal (each bank is 8 Kb).
; Note that the number of such banks can be 256 so a word is returned.
+3 -1
View File
@@ -37,7 +37,9 @@ system get banks (returns byte) set banks
======= ============================================= ===========
c64 ``c64.getbanks()`` ``c64.banks(x)``
c128 ``c128.getbanks()`` ``c128.banks(x)``
cx16 ``cx16.getrombank()`` , ``cx16.getrambank()`` ``cx16.rombank(x)`` , ``cx16.rambank(x)``
cx16 ``cx16.getrombank()`` , ``cx16.getrambank()`` ``cx16.rombank(x)`` , ``cx16.rambank(x)`` ,
``cx16.push_rombank(x)``, ``cx16.pop_rombank()`` ,
``cx16.push_rambank(x)``, ``cx16.pop_rambank()``
other N/A N/A
======= ============================================= ===========
+2 -2
View File
@@ -14,12 +14,12 @@ main {
; load the example libraries in hiram banks 4 and 5
; in this example these are constants, but you can also specify
; a variable for the bank so you can vary the bank where the routine is loaded.
cx16.rambank(4)
cx16.push_rambank(4) ; remember the original ram bank, switch to 4
void diskio.load("library1.prg", $a000)
cx16.rambank(5)
void diskio.load("library2.prg", $a000)
cx16.rambank(1)
cx16.pop_rambank() ; restore orig rambank.
; call a routine from the Audio rom bank:
bool success = audio_init()
+8 -28
View File
@@ -1,42 +1,22 @@
%import test_stack
%import textio
%zeropage basicsafe
%option no_sysinit, romable
main {
sub start() {
str name = "irmen" ; there a re no memory-mepped strings.
ubyte[] array = [11,22,33,44]
&ubyte[20] marray = $2000
uword @shared pointer = $4000
sys.memset($2000, 20, 55)
txt.print(name)
txt.spc()
txt.print_ub(array[1])
txt.spc()
txt.print_ub(marray[1])
@($a000) = 123
txt.print_ub(@($a000))
txt.nl()
name[2] = '!'
marray[1] = '!' ; TODO should be allowed because memory mapped to non-rom area
array[1], marray[1] = multi()
cx16.push_rambank(10)
txt.print_ub(@($a000))
txt.nl()
cx16.pop_rambank()
cx16.r0L=1
pointer[cx16.r0L] = 99
txt.print(name)
txt.spc()
txt.print_ub(array[1])
txt.spc()
txt.print_ub(marray[1])
txt.print_ub(@($a000))
txt.nl()
}
sub multi() -> ubyte, ubyte {
cx16.r0++
return 65,66
}
}