OK, this is a longer one, performing a couple of functions; first up, reading the switch matrix. Incidentally, the lines I've left uncommented are setup values for the PIA's.... and the reason I've left them uncommented is that I don't understand what it's doing 100%! It's one of those things that sometimes it's been explained (in various vintage and contemporary texts) and I'm sure I understand it, but I don't really. Since I don't ever need to change it, I'm ok with not knowing, but if someone wants a stab at it, have at it!
The first section reads the switch matrix by strobing a line, waiting/doing some housekeeping, and then reading the results from the PIA. There is something called propagation delay in interface chips, and the code is written to be long enough to allow this to happen so there are valid results waiting in the PIA register. There's references to $39, offset +5, and offset +$A. Since we know there are 5 physical switch columns in the machine according to the schematics, (labeled ST0-A, ST1-B, ST2-C,ST3-D,ST4-E) there's the offset 5, and the further offset $A (10, 2*5). The switches are pulsed in reverse strobe order, so the first pulse goes to ST4, and its ultimate destination will be $38, $3D, and if valid switch detected, $42. I call these columns history, initial, and action registers. Most of the time I swap the history and initial registers' monikers by mistake and I did so above (I think)..... the important register to me in software modding is the "action" register - this is the register that the foreground program reacts to. (The switch test uses one of the other registers, which is a way it can be fooled, as does the "fast react" solenoids, which will be covered in tomorrow's zero cross update).
If anyone is interested in exactly how the switch registers work I will make a separate message detailing that, where I'll trace a set of bytes through the entire routine. So far into the Galaxy code we've done a lot of back end stuff that frankly, you probably won't ever touch when modifying gameplay code.
Add to your memory map, SWITCH HISTORY 0034-0038, SWITCH INITIAL 0039-003D, SWITCH ACTION 003E-0042, and VIRTUAL ACTION 0043-0045. The virtual action switches are the timed switches from earlier in the zero cross; they appear as action columns only because the software activates them, thus why they are "virtual" switches. You WILL make use of these at some point in your mods (for instance, to turn off something that you turned on previously and need to run for a certain amount of time.... yes, you could use delay functions, but it's not as efficient, since the timing is built into the OS, might as well use it.... assuming there's free ones! There is at least one free in galaxy.)
Next up in the interrupt, there's some code that reacts to a blinking mask timeout which will start a player's score blinking after a certain amount of time elapsed without scoring. This is one of the times that something gets set in the foreground (the scoring) that the background (the blink reaction) will react to. Every time score happens, the blink timer is reset. In the background, every time the timer is zero, it flips the current player's blink mask (a flag that tells the game to either show a player's info, or just show blanks). It only does it for valid players in the game. So we've identified more memory locations for the memory map:
0061 VALID PLAYERS (1234 5xxx) - each set bit corresponds to the players 1-5. "Player 5" is the credit/ball in play display, and is only set valid/invalid in the self test and some other modes, never in game mode)
0062 P1 DISPLAY MASK ($FF=BLANK, $00=SHOW)
0063 P2 DISPLAY MASK ($FF=BLANK, $00=SHOW)
0064 P3 DISPLAY MASK ($FF=BLANK, $00=SHOW)
0065 P4 DISPLAY MASK ($FF=BLANK, $00=SHOW)
0066 P5 DISPLAY MASK ($FF=BLANK, $00=SHOW)
The final part of this portion of the zero cross is the section that handles blinking lamps. Update memory map: 0049 ? TIMER to 0049 LAMP BLINK TIMER. If you want faster blinking you can change the blink constant from #$0c to less, or make it slower. Different games use different constants here.
The blink code takes offsets from the lamp table +$11 to get it's info on which lamps to flip. So, the lamp table runs from $13-$1a, so the blink table runs from $24-2b. Add to memory map 0024-002A BLINK LAMP TABLE.
The final lines of code check another timer, which is the sound timer. When it's zero, time to process sounds, and its timer is 004C. Update the memory map from 004C ? TIMER to 004C SOUND TIMER.
Tomorrow, the rest (finally!) of the zero cross interrupt code. I will not be posting the sound code portion of it just yet, though, as it's rather long and convoluted. There's more processing done in the zero cross interrupt across all areas of the game than anywhere else.... it's hard to believe the entire interrupt gets processed 120 times a second. (Or, I guess, 100 times a second in 50 Hz countries).