After pacman, I wanted to add the galaga sound (my favorite game !) to the new clock.


The galaga sound hardware is similar to pacman. But the code is completely different. You can find the disassembly of the sound rom here.
Unlike pacman, galaga sound is completely data driven. The wave table is also different.

PIC implementation

Galaga uses the 3 voices available from the hardware. This is different from Pacman which uses maximum 2 voices at a time (when playing a song), and keeps the third voice available for sound effects. This created a problem with the pic implementation, because the interrupt routine didn’t have enough time to compute the output for 3 voices.
After rewriting the interrupt routine with heavy optimization, 3 voices can be achieved. Several tricks are used to avoid the use of ‘if’ instructions, the wavetable is preloaded in a memory page (in order to avoid TBL* instructions), and finally the location in memory of the parameters is also carefully chosen, in order to detect the end of the data by a very simply comparison. Code is here.

The complete code source is available in the download section. The code is almost complete, it is just missing routines to switch between pacman and galaga sounds.