I am trying to programatically detect the CGA card on old IBM 5150-ish PCs.
The Paku Paku game source code doesn't directly detect it. The strategy is to detect VGA, EGA, Tandy, PCJr, etc etc, then if none of those "hit", assume it is CGA. Similar code is found here: https://forum.vcfed.org/index.php?threads/is-there-a-way-to-detect-a-plantronics-colorplus-card-by-software.79115/ and here: https://www.brutman.com/forums/viewtopic.php?t=119
However I'm wondering if there is some way to directly detect the CGA card's presence?
I realize the IBM BIOS source code may have references to this but I'm not sure of exactly how it's doing it so I kind of gave up looking at that. I know that it's detecting between no video, MDA, and CGA, but I'm not sure if that is compatible with technology that did not exist when the BIOS was written. (Edit - please see Raffzahn's answer below, BIOS is not doing what i thought!!!)
The guide at http://www.tinyvga.com/6845 regarding the Motorola shows that most of the registers in the CGA's Motorola 6845 chip are write only, however the cursor addresses at registers 14 and 15 are both read/write.
I am wondering if I output data to register 14 at the 6845 I/O-portaddress, and read it back, using x86 OUT and IN instructions, would that be good evidence the machine had a CGA card?
What happens if you write to an I/O-port that doesn't exist in the hardware? Does it crash?