Personal Computer News


Spectrum Interrupts Pause For Thought

 
Published in Personal Computer News #078

Spectrum Interrupts Pause For Thought

Q. I've been trying to write arcade programs for the ZX Spectrum, but I believe that you first need to understand Z80 interrupts.

Why are interrupts so important?

Kim Gerhardt
Birkenhead

A. Interrupts are exactly what they claim to be. The Spectrum's Z80 processor receives an interrupt every 20ms, and this forces it to suspend whatever it's doing and jump to 38 hex or 56 decimal. It then increments the system variable FRAMES, scans the keyboard to see if you're keying anything in, then goes back to what it was doing.

Now, although interrupts are first and foremost meant to aid the Spectrum's housekeeping, they can be very powerful for programming purposes. The reason is quite simple - because they stop the program for a short period, go and do something else, then return to the program without you noticing they provide a sort of multi-tasking facility. In the case of most micros, by the way, multi-tasking is doing two things at the same time, but not at the same instant.

The Z80 chip itself has three interrupt modes. Mode 0 allows the interrupting device to place one instruction on the data bus after the interrupt. Mode 1 jumps to 38 hex or 56 decimal, and is the one used by the Spectrum. In Mode 2 the Z80 expects the interrupting device to place one byte of data on the data bus, and this acts as the low order of the address. The Z80 takes the contents of the I, or 'interrupt vector register', as the high byte, and the Z80 obtains from this address a further address it will jump to.

This last is the crucial point. If you can change the I register to point to your own routine, Robert is your mother's brother. Cracking this is by no means easy, but there are plenty of books around that supply the information. Try Advanced Spectrum Machine Language by David Webb, published by Melbourne House. It's not the easiest book to get on with, but once you've got the hang of the basics, it's invaluable.

Kim Gerhardt