Page 3 of 4
Count your RAM banks
Posted: Wed Apr 07, 2021 6:22 pm
by Lorin Millsap
is it even physically possible to have a non-power-of-two number of banks? [emoji848] Having an odd number of mem chips on the board somehow seems "off" to me (but i'm a noob regarding that so yeah)
Absolutely. There is nothing about the design that limits that. In fact the base 512k is just one.
Sent from my iPhone using Tapatalk
Count your RAM banks
Posted: Wed Apr 07, 2021 6:27 pm
by Wavicle
3 hours ago, Elektron72 said:
Yes; it appears that the current version of MEMTOP assumes that the number of banks must be a power of two.
The behavior I've predicted is actually worse: I think it will report 2048K. After testing for the existence of bank 128 (which will succeed), it will left-shift the value in A, which will cause it to contain zero upon return (side note: a zero in A from MEMTOP indicates 256 banks).
At this point, I think it's clear that the entire MEMTOP routine needs to be rewritten. Someone should open a GitHub issue about this (I might do that later today).
If I put on my computer science hat, I would point out that a binary search has the same time complexity, O(log N), as the current implementation.
If I put on my software engineer hat, I would point out that a binary search is rather a lot of easy-to-get-wrong code just for counting available memory banks.
If I put on my computer engineer hat, I would point out that there is probably a minimum increment that could be checked, probably around 64K, which would significantly reduce the size of a linear search while still getting the right number.
Having close to zero 6502 experience, I'm not the right person to fix it in any case
?
Count your RAM banks
Posted: Wed Apr 07, 2021 6:43 pm
by Wavicle
33 minutes ago, desertfish said:
is it even physically possible to have a non-power-of-two number of banks? ? Having an odd number of mem chips on the board somehow seems "off" to me (but i'm a noob regarding that so yeah)
In general parallel bus RAM chips usually have a power of 2 memory size. I'm not 100% certain of this, but I suspect that it is probably so that there are no invalid combinations of their address wires. Off the top of my head, I cannot recall seeing such a RAM chip that was not sized as a power of 2.
Seeing a non-power (or even multiple) of 2 RAM chips on a design is reasonably common. Usually all of the memory components are the same size, but this is mostly done to save on production costs.
Count your RAM banks
Posted: Wed Apr 07, 2021 8:59 pm
by rje
Banked RAM consists of up to four RAM chips, each with 512K of static RAM, if I understand correctly.
Chip 1: Banks 0-63. Always present (required, since Bank 0 is used by the OS).
Chip 2: Banks 64-127.
Chip 3: Banks 128-191.
Chip 4: Banks 192-255.
Thus, a test would check one bank as a proxy for each 512K segment (say, banks 65, 129, and 193), and see if it can write/read that bank.
I wonder if a 256K static RAM would fit in those spots... horrors...
Count your RAM banks
Posted: Wed Apr 07, 2021 9:16 pm
by rje
Count your RAM banks
Posted: Thu Apr 08, 2021 1:24 am
by Ed Minchau
4 hours ago, rje said:
Banked RAM consists of up to four RAM chips, each with 512K of static RAM, if I understand correctly.
Chip 1: Banks 0-63. Always present (required, since Bank 0 is used by the OS).
Chip 2: Banks 64-127.
Chip 3: Banks 128-191.
Chip 4: Banks 192-255.
Thus, a test would check one bank as a proxy for each 512K segment (say, banks 65, 129, and 193), and see if it can write/read that bank.
I wonder if a 256K static RAM would fit in those spots... horrors...
Is 3 RAM chips even going to be an option? My understanding was they'd only be selling 512k, 1M, and 2M variants.
Count your RAM banks
Posted: Thu Apr 08, 2021 1:29 am
by Elektron72
3 minutes ago, Ed Minchau said:
Is 3 RAM chips even going to be an option? My understanding was they'd only be selling 512k, 1M, and 2M variants.
The way I interpreted the FAQ is that all Commander X16s will be sold with 512K; any additional RAM must be added by the user.
Count your RAM banks
Posted: Thu Apr 08, 2021 2:36 am
by rje
That's right. The X16 only comes with 512K of the banked RAM. It's socketed so it's easy to add more, and (if I recall right) they're less than $10 apiece.
Re: Count your RAM banks
Posted: Fri May 10, 2024 7:01 pm
by Screech
On the off chance someone is looking to do this in BASIC:
10 BC=0:I=0
15 BANK I
20 IF PEEK($A000)=160 THEN GOTO 40
30 BC=BC+1:I=I+1:GOTO 15
40 PRINT"TOTAL BANKS:";BC
50 PRINT"TOTAL HI-RAM:";(BC*8);"K"
It's not the most elegant way, and if you're planning on using that much ram in basic, you may want to consider assembly. But this worked for me.
Re: Count your RAM banks
Posted: Fri May 10, 2024 11:26 pm
by ahenry3068
Screech wrote: ↑Fri May 10, 2024 7:01 pm
On the off chance someone is looking to do this in BASIC:
10 BC=0:I=0
15 BANK I
20 IF PEEK($A000)=160 THEN GOTO 40
30 BC=BC+1:I=I+1:GOTO 15
40 PRINT"TOTAL BANKS:";BC
50 PRINT"TOTAL HI-RAM:";(BC*8);"K"
It's not the most elegant way, and if you're planning on using that much ram in basic, you may want to consider assembly. But this worked for me.
This is a bit more elegant.
10 MT = $FF99
20 AR = $30C
30 XR = $30D
40 YR = $30E
50 PR = $30F
60 POKE PR, 1 : REM Set the Carry Flag
70 SYS MT : REM Call the Memory Address $FF99 (ROM MEMTOP)
80 BC = PEEK(AR)
90 IF BC=0 THEN BC=256
110 PRINT "TOTAL BANKS";BC
115 PRINT "HIGHEST BANK #";BC-1
120 PRINT BC*8192;" BYTES OF HIRAM"