1
0
mirror of https://github.com/irmen/prog8.git synced 2025-04-28 04:37:46 +00:00

added cx16.getrambank() / getrombank() to retrieve the current ram and rom bank numbers.

This commit is contained in:
Irmen de Jong 2021-12-04 15:27:54 +01:00
parent 397f98513b
commit 20401b99d8
2 changed files with 36 additions and 34 deletions
compiler/res/prog8lib/cx16
examples

@ -381,6 +381,20 @@ inline asmsub rambank(ubyte bank @A) {
}}
}
inline asmsub getrombank() -> ubyte @A {
; -- get the current rom bank
%asm {{
lda $01 ; rom bank register (v39+, used to be cx16.d1prb $9f60 in v38)
}}
}
inline asmsub getrambank() -> ubyte @A {
; -- get the current ram bank
%asm {{
lda $00 ; ram bank register (v39+, used to be cx16.d1pra $9f61 in v38)
}}
}
asmsub numbanks() -> ubyte @A {
; -- uses MEMTOP's cx16 extension to query the number of available RAM banks. (each is 8 Kb)
%asm {{

@ -1,43 +1,31 @@
%import textio
%zeropage basicsafe
%option no_sysinit
main {
ubyte[64*3] palette
sub start() {
ubyte i
for i in 0 to len(palette)-1 {
palette[i] = 15
}
for i in 0 to len(palette)-1 {
txt.print_ubhex(palette[i], false)
}
txt.nl()
make_ehb_palette()
for i in 0 to len(palette)-1 {
txt.print_ubhex(palette[i], false)
}
txt.nl()
ubyte num_banks = cx16.numbanks()
txt.print("number of ram banks ")
txt.print_ub(num_banks)
txt.print(" = ")
txt.print_uw($0008*num_banks)
txt.print("kb\n")
print_banks()
cx16.rambank(55)
cx16.rombank(3)
print_banks()
}
sub make_ehb_palette() {
; generate 32 additional Extra-Halfbrite colors in the cmap
uword palletteptr = &palette
uword ehbptr = palletteptr + 32*3
repeat 32 {
@(ehbptr) = @(palletteptr)>>1
ehbptr++
palletteptr++
@(ehbptr) = @(palletteptr)>>1
ehbptr++
palletteptr++
@(ehbptr) = @(palletteptr)>>1
ehbptr++
palletteptr++
}
sub print_banks() {
ubyte rambank = cx16.getrambank()
ubyte rombank = cx16.getrombank()
cx16.rombank(0) ; enable kernal
txt.print("ram bank ")
txt.print_ub(rambank)
txt.nl()
txt.print("rom bank ")
txt.print_ub(rombank)
txt.nl()
cx16.rombank(rombank)
}
}