INTERRUPT-INTERCEPT
Simon Liston, Walthamstow, London.
from Your Computer, March 1983

THE ZX SPECTRUM produces an interrupt every 0.02 seconds. The Spectrum ROM
uses this interrupt to increment the FRAMES system variable and also to see
if any keys are being pressed. This short machine-code program causes the
micro to CALL address 63479 on each of these interrupts. I have written a
real-time clock to illustrate one possible use of this facility.

First, reserve some memory: type CLEAR 63400. Next, POKE the 23 bytes of the
Interrupt-Intercept into locations 65040-65062. Now, POKE the machine code
for the real-time clock into locations 63479-63665. Check what you have POKEd
with the listing, then SAVE the code you have entered. Next, enter:
	RANDOMIZE USR 65040

You should now have a random time displayed in the top right-hand corner of
the screen. Hours, minutes and seconds are stored in packed-bed format. Their
respective addresses are: 63667, 63668, 63669.

Setting the time, for example, 11:44:13 is done as follows:
	POKE 63667,1*16+1
	POKE 63668,4*16+4
	POKE 63669,1*16+3
Note that you must have a self-contained machine-code program at locations
63479-64760; that is, unless you know exactly what you are doing, you should
save all the registers and do not alter any system variables.

It is a good idea to end your routine not with EI / RET but with JP 38h; this
causes control to be passed to the usual interrupt routine.

The clock program given will keep good time so long as LOAD, SAVE, BEEP, COPY
or the printer are not used. Some other ideas: On every interrupt, print the
value of the system variable PPC to show you the line number being
interpreted; this provides a simple trace mechanism. Or set SCR_CT to 255 on
every interrupt; this will stop the Scroll? function being erased. Why not
have a delay loop on every interrupt? This will slow down program execution 
if it is not slow enough already.
