PRINT PEEK 23732 + PEEK 23733 * 256 returns the address of the top of available memory available to BASIC by using a system variable. The BASIC ROM does a test to discover how much RAM is available.
PEEK 23733 returns the most significant 8 bits of the address (address lines A8 to A15).
In both cases, the result is only valid if a program has not changed these system variable values. So best to test immediately after reset or power on.
RS232 wrote: ↑Mon Jun 17, 2024 10:12 am
Print peek 23733
Result
128. 16k
127. Only 16k available on 48k
As stated, these are misleading. The system will normally return 127 or a random value greater than 127 if the ‘upper’ RAM is faulty. Or it will not get beyond the ‘copyright screen without crashing or freezing. If 127 is returned, it is not possible to tell if it is a 16K machine or a machine with more RAM, but where the ‘upper’ RAM is faulty.
Print peek 23733
Result
255. 48K of RAM detected. Likely a 48K or 128K machine.
127. 16K of RAM detected. Likely a 16K machine or a machine with more RAM, but where this RAM is faulty.
127*256+255=32767 plus address zero gives 32K or memory, 16K of ROM and 16K of RAM.
255*256+255=65535 plus address zero gives 64K or memory, 16K of ROM and 48K of RAM.
In all cases, this does not mean that all detected RAM is fully functional. The test performed by the BASIC ROM is not designed to fully test or detect faulty RAM. And it does not take into account any bank switched RAM, such as that available in the 128K machines.
RS232 wrote: ↑Mon Jun 17, 2024 10:12 am
Print Peek 23732+256*Peek 23733
32767 Correct for 16k but a lower number may indicate memory fault
32767 is correct for a 16K machine. Any result that gives a different value other than 32767 or 65535 indicates a RAM fault. And a result of 32767 on anything other than a 16K machine also indicates a RAM fault.
Mark