The Apple II uses memory mapped I/O and soft switches to do many things. One thing has confused me though: why are some soft switches only activated when written to?
$C00C) turn on/off the 80-column display but these switches have to be written to to trigger. You would think that perhaps reading them would be the way to determine their state, but that is not the case. Instead, that is done by reading
But then you can look at something like
$C052) which turns off the mixed graphics and text (at the bottom) mode. These switches can be triggered by either a a read or a write. Once again, you cannot determine their state by reading them, but rather reading
I have been under the assumption that soft switches basically work by some special circuitry detecting if their address line is active and then the desired operation will happen. You would think that if a write was required, it would be because of the address lines first getting set up and then letting the
R/W signal from the 6502 pulsing to actually trigger the switch. But then why are there some that are R/W and some which are R/O?
The reason why I was recently thinking about this is because of how the 80-column display works. The hardware obviously needs to bank switch for every other column since the even columns are stored in bank 0 and the odd columns are stored in bank 1. What this means is that (I believe) calls to
$C001) are hit to bank switch for every other character and then need to be switched back so as not to confuse with the main bank 0 zero page, stack, etc. Of course, with bank switching you also are supposed to disable interrupts and then re-enable them when coming back to the main bank.
All this switching and interrupt handling takes a lot of cycles. When the 6502 does a read, it takes a minimum of 4 cycles. For a write, the processor effectively reads the address first before writing it which ends up taking at least 5 cycles. I started thinking why wouldn't the soft switches be implemented to support "read triggering" instead of the more expensive "write triggering"? Sure, it's a tiny fraction of time being spent for the extra cycle, but why not design it to save that tiny fraction? What would be the reason that they would have designed it only with write-triggered soft switches?
EDIT: while there are potential differences between read/write cycle times, they are identical for LDA/STA Absolute addressing which would have been the mode used for a soft switch anyway. As such, cycle concerns are invalid.