All systems that use the Atari 9 pin joystick standard make use of the following pins in consistent ways, with each direction and the fire button being connected to the ground pin when pushed.
1 - up
2 - down
3 - left
4 - right
6 - fire
8 - ground
However the Sega Master System also has a second fire button that connects pin 9 to ground.
In addition, the Kempston compatible interface available from ByteDelight for the ZX Spectrum (http://benophetinternet.nl/ebay/Kempston%20Joystick%202013%20manual%20small.jpg) can read a second button that connects pin 9 to ground.
Furthermore, (correct me if I'm wrong) the Commodore Amiga can also read a joystick button wired this way being pushed, as although it treats pin 9 as an analog input, the Amiga's analog pins are active low.
However, although the Cheetah Annihilator joystick used with the Commodore 64 GS (and compatible with a regular Commodore 64) was a 2 button joystick that used pin 9 for the second button, it connected it to the 5 volts on pin 7 instead as the Commodore 64 analog pins are active high.
Is there some circuit I could create (maybe using 74 series logic gates, transistors, capacitors and resistors) that could detect the absence of a voltage on pin 9 when plugged into a c64 that would allow me to create a 2 button joystick that would automatically work in all these scenarios? Or at least one with a switch that if it were set incorrectly would at least not cause any damage to any system it might be plugged into?
Edit: I understand that many other systems also use a variant of the Atari standard, but I'm primarily interested in building a joystick that only needs to support the ones I've mentioned in my question. It seems most systems with more than 1 joystick button connected a pin to ground somehow anyway (other than the C64), so a simple rewired pass through adapter might be usable elsewhere.
I guess the crux of my question involves how to detect the joystick is plugged into a C64 rather than something else and auto-switch accordingly without damaging any chips in the computer.