Timers, Events and State Machines
The code for Pacman is a series of event-driven state machines. The basic unit of measurement is the video interrupt which occurs at 60Hz (every 16.667 milliseconds). After game initialisation and self test the interrupt vector is set to #008d and this interrupt service routine (ISR) drives various events and timers. Interrupt Service Routine The video timer inerrupt performs the following functions in sequence: Disables interrupts Copies the audio frequency data to the hardware registers Updates the audio wave form registers Copies sprite attribute and location data to the hardware registers Reorders sprites if necessary A ghost that has just been eaten is the highest priority so the points are not hidden by other sprites Pacman is higher priority than the ghosts if he is powered up Updates counters Dispatches ISR tasks Drives the main state machine Mutes the sound if in demo mode Calls the sound effect update state machine Calls the songs state machine Re-enables interrupts and ret