From 79d0fb0b52d5a68e535d98badba560c6e1498cd3 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Wed, 8 Feb 2023 00:51:34 +0100 Subject: [PATCH] cx16.numbanks() now returns a word because the result can be >255 --- compiler/res/prog8lib/cx16/syslib.p8 | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/compiler/res/prog8lib/cx16/syslib.p8 b/compiler/res/prog8lib/cx16/syslib.p8 index a0d072d3c..94f965a78 100644 --- a/compiler/res/prog8lib/cx16/syslib.p8 +++ b/compiler/res/prog8lib/cx16/syslib.p8 @@ -460,15 +460,23 @@ inline asmsub getrambank() -> ubyte @A { }} } -asmsub numbanks() -> ubyte @A { +asmsub numbanks() -> uword @AY { ; -- uses MEMTOP's cx16 extension to query the number of available RAM banks. (each is 8 Kb) - ; Note: when 0 is returned, it doesn't mean 'zero banks', instead it means 256 banks (=2Mb banked RAM), + ; Note that the number of such banks can be bigger than 255 so a word is returned, but mostly + ; the A register could suffice as the lsb. + ; The maximum number of banks is 256 = 2 Megabytes of banked Ram aka Hiram. (Y=1 and A=0 in this case). + ; MEMTOP itself reports 0 in this case which we change into 256 for convenience. + ; It reporting 0 doesn't mean 'zero banks', instead it means 256 banks (=2Mb banked RAM), ; as there is no X16 without at least 1 page of banked RAM. %asm {{ phx sec jsr c64.MEMTOP - plx + ldy #0 + cmp #0 + bne + + iny ++ plx rts }} }