Page 2 of 4

Count your RAM banks

Posted: Wed Apr 07, 2021 12:37 am
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

Count your RAM banks

Posted: Wed Apr 07, 2021 1:29 am
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.


Count your RAM banks

Posted: Wed Apr 07, 2021 2:55 am
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.

 


Count your RAM banks

Posted: Wed Apr 07, 2021 3:42 am
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

Count your RAM banks

Posted: Wed Apr 07, 2021 4:26 am
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.


Count your RAM banks

Posted: Wed Apr 07, 2021 1:04 pm
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.


Count your RAM banks

Posted: Wed Apr 07, 2021 2:14 pm
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?

 


Count your RAM banks

Posted: Wed Apr 07, 2021 2:41 pm
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

Count your RAM banks

Posted: Wed Apr 07, 2021 2:48 pm
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).


Count your RAM banks

Posted: Wed Apr 07, 2021 5:54 pm
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)