mirror of
https://github.com/irmen/prog8.git
synced 2026-04-21 02:16:41 +00:00
cx16: added cx16.push_rambank/rombank and cx16.pop_rambank/rombank for easy temporary bank switching
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
======= ============================================= ===========
|
||||
|
||||
|
||||
@@ -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
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user