Count your RAM banks

Tutorials and help articles.

(Posts require approval. See pinned post.)
Forum rules
Post guides, tutorials, and other instructional content here.

This topic area requires approval, so please be patient while we review content to make sure it fits the expectations for this topic area.

Tech support questions should be asked in Hardware or Software support.
Lorin Millsap
Posts: 193
Joined: Wed Apr 29, 2020 6:46 pm

Count your RAM banks

Post 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
Wavicle
Posts: 284
Joined: Sun Feb 21, 2021 2:40 am

Count your RAM banks

Post 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 ?

Wavicle
Posts: 284
Joined: Sun Feb 21, 2021 2:40 am

Count your RAM banks

Post 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.

rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

Count your RAM banks

Post 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...

 

rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

Count your RAM banks

Post by rje »

Ed Minchau
Posts: 503
Joined: Sat Jul 11, 2020 3:30 pm

Count your RAM banks

Post 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.

Elektron72
Posts: 137
Joined: Tue Jun 30, 2020 3:47 pm

Count your RAM banks

Post 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.

rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

Count your RAM banks

Post 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.

Screech
Posts: 8
Joined: Fri Jan 01, 2021 5:35 pm

Re: Count your RAM banks

Post 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.
User avatar
ahenry3068
Posts: 1144
Joined: Tue Apr 04, 2023 9:57 pm

Re: Count your RAM banks

Post 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"
Last edited by ahenry3068 on Fri May 10, 2024 11:28 pm, edited 2 times in total.
Post Reply