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 »

I guess in this case a custom version of the routine is unlikely so using the ROM vector would be safe.

The real hardware does not mirror the ram. So if you attempted to read or write banks that don’t exist what you will get is garbage.


Sent from my iPhone using Tapatalk
Elektron72
Posts: 137
Joined: Tue Jun 30, 2020 3:47 pm

Count your RAM banks

Post by Elektron72 »



43 minutes ago, Lorin Millsap said:




I guess in this case a custom version of the routine is unlikely so using the ROM vector would be safe.



The ROM vectors for routines that have RAM vectors are simply indirect jumps through the RAM vectors, so I don't think it would make a difference if the ROM vectors were used even if this routine had a RAM vector. For example, the ROM vector for OPEN (a routine that has a RAM vector) contains this:


Quote




jmp ($031a)



As $031A is the RAM vector for OPEN, the way the routine is called makes no difference.

Additionally, considering that there is no way to perform an indirect JSR, using the vector table in ROM is usually more convenient than trying to directly access the RAM vectors.

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

Count your RAM banks

Post by rje »



2 hours ago, Wavicle said:




Your thinking isn't far off though. You can see how KERNAL does it here.



Ah.  If you can write to it and then read it back, the bank exists.  I think I'll modify my algo...  better yet, I'll use MEMTOP.

 

Lorin Millsap
Posts: 193
Joined: Wed Apr 29, 2020 6:46 pm

Count your RAM banks

Post by Lorin Millsap »

Ah.  If you can write to it and then read it back, the bank exists.  I think I'll modify my algo...  better yet, I'll use MEMTOP.
 

A lot of this is a good approach to a full RAM test.


Sent from my iPhone using Tapatalk
Wavicle
Posts: 284
Joined: Sun Feb 21, 2021 2:40 am

Count your RAM banks

Post by Wavicle »



13 hours ago, rje said:




Ah.  If you can write to it and then read it back, the bank exists.  I think I'll modify my algo...  better yet, I'll use MEMTOP.



 



Not exactly. That algorithm actually writes to the banked memory and then checks to see if that value appears in bank zero. If so, then the bank does not exist and loop exits. I've annotated what I think the code is doing here:


    stz ram_bank    ; Switch to bank 0
    ldx $a000       ; Create 'magic X' value by adding
    inx             ; 1 to whatever is @ bank 0 offset 0
    lda #1          ; Set A to begin at bank 1

:    sta ram_bank    ; Switch to bank specified by A
    ldy $a000       ; Save value at bank A offset 0
    stx $a000       ; Write 'magic X' value to offset 0
    stz ram_bank    ; Switch to bank 0
    cpx $a000       ; Check if 'magic X' is mysteriously here
    sta ram_bank    ; Switch back to bank A
    sty $a000       ; Restore original value
    beq :+          ; If 'magic X' was found, we're done.
    asl             ; Double # of banks considered


I'm not quite sure how to get the forum software to format that with a monospace font, but I think you can get the general idea.

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

Count your RAM banks

Post by rje »


Lorin Said:


Quote




A lot of this is a good approach to a full RAM test.



That sounds fun.  I'll extend my dumper.

 


9 hours ago, Wavicle said:




Not exactly. That algorithm actually writes to the banked memory and then checks to see if that value appears in bank zero. If so, then the bank does not exist and loop exits. I've annotated what I think the code is doing here:



  ...



I'm not quite sure how to get the forum software to format that with a monospace font, but I think you can get the general idea.



Use [ code ] and [ / code ] (sans spaces).

Thank you for that, by the way.

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

Count your RAM banks

Post by rje »


It seems that the bank routine in MEMTOP is slightly incorrect, then?

Due to the ASL, if there is 1536K of banked RAM, e.g. 3 chips, then MEMTOP will only report 1024K, won't it?

 

Lorin Millsap
Posts: 193
Joined: Wed Apr 29, 2020 6:46 pm

Count your RAM banks

Post by Lorin Millsap »

Not exactly. That algorithm actually writes to the banked memory and then checks to see if that value appears in bank zero. If so, then the bank does not exist and loop exits. I've annotated what I think the code is doing here:     stz ram_bank    ; Switch to bank 0     ldx $a000       ; Create 'magic X' value by adding     inx             ; 1 to whatever is @ bank 0 offset 0     lda #1          ; Set A to begin at bank 1  :    sta ram_bank    ; Switch to bank specified by A     ldy $a000       ; Save value at bank A offset 0     stx $a000       ; Write 'magic X' value to offset 0     stz ram_bank    ; Switch to bank 0     cpx $a000       ; Check if 'magic X' is mysteriously here     sta ram_bank    ; Switch back to bank A     sty $a000       ; Restore original value     beq :+          ; If 'magic X' was found, we're done.     asl             ; Double # of banks considered I'm not quite sure how to get the forum software to format that with a monospace font, but I think you can get the general idea.
That’s interesting. I might need to bring that up with Micheal. Because what should happen if you try to access banks that don’t actually exist is the CS lines will not connect to anything. If the CPU writes a nonexistent address then no CS line is ever asserted so the data will just float on the buss till it gets changed by something driving the buss. On a read again since no CS line goes active the buss will just kinda float. Unused banks do not mirror.   Sent from my iPhone using Tapatalk
Elektron72
Posts: 137
Joined: Tue Jun 30, 2020 3:47 pm

Count your RAM banks

Post by Elektron72 »



29 minutes ago, rje said:




It seems that the bank routine in MEMTOP is slightly incorrect, then?



Yes; it appears that the current version of MEMTOP assumes that the number of banks must be a power of two.


29 minutes ago, rje said:




Due to the ASL, if there is 1536K of banked RAM, e.g. 3 chips, then MEMTOP will only report 1024K, won't it?



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


4 minutes ago, Lorin Millsap said:




That’s interesting. I might need to bring that up with Micheal. Because what should happen if you try to access banks that don’t actually exist is the CS lines will float. If the CPU writes a nonexistent address then no CS line is ever driven so the data will just float on the buss till it gets changed by something driving the buss. On a read again since no CS line goes active the buss will just kinda float. Unused banks do not mirror.



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

User avatar
desertfish
Posts: 1096
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

Count your RAM banks

Post by desertfish »


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)

Post Reply