diff --git a/compiler/res/prog8lib/cx16/syslib.p8 b/compiler/res/prog8lib/cx16/syslib.p8 index 49efbe478..2666ec067 100644 --- a/compiler/res/prog8lib/cx16/syslib.p8 +++ b/compiler/res/prog8lib/cx16/syslib.p8 @@ -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 {{ diff --git a/examples/test.p8 b/examples/test.p8 index cc244151a..d804ba571 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -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) } - }