Page 1 of 3
Howto get banked RAM size
Posted: Thu Oct 01, 2020 6:50 pm
by Stefan
Hi,
I'm working on X16 Edit, a text editor. There's a thread in Software Library Chat discussing the program in depth. My program uses banked RAM to store text that's edited.
However, I have a general question regarding the hardware.
It's said that the final product will have banked RAM of 512 KB expandable to 1 MB, 1.5 MB or 2 MB (by populating 1, 2 or 3 sockets).
Is there a way for a program to determine what memory banks are actually available?
If there is no other option, would it be possible to write a routine that tests certain memory addresses by first writing values and then reading them back?
I guess that approach could work, but it depends on what the hardware does when you access an unpopulated address in banked RAM.
A test routine would probably work if the data bus floats (returning a random value) or if it's tied high or low (returning ff or 00).
Howto get banked RAM size
Posted: Thu Oct 01, 2020 7:07 pm
by Ender
You can set the carry flag and then call memtop at $ff99. This will return the number of ram banks on A and a pointer to the top of memory in X and Y. Keep in mind that bank 0 is used by the kernal, so really only 1 on are free.
Howto get banked RAM size
Posted: Thu Oct 01, 2020 7:07 pm
by TomXP411
At present, you have to write to a memory cell and read its value back. If you assume you can take over all of upper memory (not necessarily a safe assumption), then you will need to write at least 3 values to each bank and then read them back.
What I'd probably do is write $00, $FF, bankno to each bank, then cycle back through and read them back. Every bank that gives you back the correct value has RAM in it.
You may also be able to shorten the test by just testing banks 64, 128, and 192, since the banked memory consists of 4 512K chips.
Howto get banked RAM size
Posted: Thu Oct 01, 2020 7:26 pm
by SlithyMatt
MEMTOP does not appear to work in the emulator, at least. You will need to simply test the higher banks. Bank 65 is a safe one, as it will be a mirror of bank 1 if there is only 512k (64 banks). Bank 64 will be a mirror of bank 0, so you don't want to mess with that without knowing first. So, I made this simple BASIC program that tells you (it would be similarly trivial to check at the beginning of an assembly program):
Here you can see that I poked the value 42 to the top of bank 65, then zero to the top of bank 1. Going back to bank 65, if it's no longer 42, then I know it was overwritten by the poke to bank 1, which it simply mirrors in the 512k configuration. If it was still 42 (as you can see in the screencap, it wasn't), then you can assume that all 256 banks are installed. AFAIK, there is no intention of having an in-between configuration (e.g. 1MB/128 banks).
Howto get banked RAM size
Posted: Thu Oct 01, 2020 7:34 pm
by TomXP411
7 minutes ago, SlithyMatt said:
AFAIK, there is no intention of having an in-between configuration (e.g. 1MB/128 banks).
Don't trust that, as people can install their own memory modules.
Howto get banked RAM size
Posted: Thu Oct 01, 2020 7:37 pm
by Ender
10 minutes ago, SlithyMatt said:
MEMTOP does not appear to work in the emulator, at least.
In what way? I just tested it and it seems to work for me.
Howto get banked RAM size
Posted: Thu Oct 01, 2020 7:49 pm
by SlithyMatt
10 minutes ago, Ender said:
In what way? I just tested it and it seems to work for me.
The code that I see when debugging R38 pre-built for Windows shows MEMTOP just being a function that reads from three memory addresses, which are all zero for me. Maybe if you use an earlier release or build from code it works?
Howto get banked RAM size
Posted: Thu Oct 01, 2020 7:58 pm
by Ender
This is with R38 right after returning from $ff99. You can see that $40 is in A.
Howto get banked RAM size
Posted: Thu Oct 01, 2020 8:15 pm
by SlithyMatt
Yep, I just get all zeros. Did you build the emulator yourself?
UPDATE: I restarted the emulator, and now it's working for me. It seems that MEMTOP is fragile, and may not work after running other programs.
Howto get banked RAM size
Posted: Thu Oct 01, 2020 8:21 pm
by SlithyMatt
P.S. The memory addresses MEMTOP returns are at $0259-$025B, which get put into X, Y, and A, respectively. So really, you can just peek at $025B for the bank count, but that address is subject to change with later ROM revisions, but MEMTOP should always be placed in the jump table at $FF99.