walter.preuninger wrote:
Is it safe to determine the size of RAM by writing a value to a location, reading it back and if they are the same, you have a RAM address?
No. See above replies about mirroring and the effects of parasitic capacitance.
Quote:
Is it possible to programmatically determine which chip you have, such as a 6551,8250, 16450, 16550 etc?
Not usually. Certain hardware assumptions have to exist in the firmware in order to make such a determination. In PC hardware, the 8250/16450 type UART is assumed to be at specific locations in the I/O memory map because that is how the standard evolved in the PC-XT and latter.
In the case of a home-brew machine, the designer knows what is or isn't present, and what could be present, because s/he designed the circuit that way. I use NXP UARTs in my designs, and place them into the mempry map at specific places. So it's relatively easy to determine if a UART is present or absent at a particular address—test writes to certain register locations, followed by a significant delay, followed by reads of those locations make the determination. It works because of my choice of UART, not due to clever programming.
With plug-in cards, it gets more involved. Most plug-in cards for PC hardware have some ROM for boot code and the PC's BIOS has hooks that look for "option ROMs" during POST. If an option ROM is found some code is executed in it that among other things, tells the system about the hardware on the card. You can do the same thing in a 65C02/65C816 system if you are willing to add the necessary complexity.
Speaking of the 65C816, as it can address more than 64KB, an interesting "mirroring" problem arises that wouldn't affect the 65C02: "phantom" banks. In a system in which, say, only bits 0-3 of the bank are demultiplexed (demuxed), a blind write/read to an extended address can't conclusively determine if the address actually exists. In such a case, only extended address bits
A16-A19 are being generated. Hence a bank bit pattern of
%yyyyxxxx looks exactly the same as
%0000xxxx, where
yyyy is any non-zero pattern.
yyyy would correspond to
A20-A23 if the bank were fully demuxed.