★ APPLICATIONS ★ PROGRAMMATION ★ INTERRUPTS DEMONSTRATION (PERSONAL COMPUTING TODAY) ★![]() |
| Interrupts Demonstration (Personal Computing Today) | Applications Programmation |
The CPC464 has the facility for direct program interrupts which, combined with the windowing and sound queue facilities, form the base of a very powerful feature. David Ellis explains. The Amstrad CPC464 has an invaluable and innovative feature which allows you to call up program interrupts directly from BASIC. Up to four interrupt timers can be set which are referred to the 'master system clock', a quartz-controlled timing system which synchronizes all the events in the computer. The variable 'TIME' holds a value corresponding to the number of seconds the computer has been running or the time since a RESET. The timer is not updated during cassette operations so its use as a real time clock is somewhat restricted, although using the timer alone can be useful. The following routine will make a program run for a specified time: 10 START = TIME:SECONDS = 60When the program is RUN, line 10 will set the variable START to the value returned by TIME. The variable SECONDS is set to the required length and the program 'proper' is contained in lines 30 up to the WEND statement signalling the end of the sequence of operations. Try running some sort of program (even 30 PRINT "TIME") and you will see that it runs for exactly one minute. |
| Line | Effect |
| 20,30 | Set up the four text windows |
| 40 | Sets up graphic window |
| 50-80 | Set up window colours |
| 90-130 | Set up the strings and variables |
| 140-180 | Create six tone envelopes |
| 190-220 | Set up interrupts |
| 230-330 | Main program loops |
Be careful when using interrupts and keyboard scanning, since the use of LINE INPUT or INPUT will disable all the interrupts. Use INKEY$ instead.
Interrupt 0 services the graphics window every 2/5ths of a second, interrupt 1 occurs every 3/5ths of a second and scrolls a message across the screen. Interrupt 2 occurs every 4/5ths of a second and prints the calculation on line 3010. Interrupt 3 services the sound routine which plays different notes. The three numbers after 'QUEUE' show the number of free spaces in each of the three channels.
The main program allows you to swap the windows over, print out all the ASCII character set and to flick the border colour through each of 27 shades.
PROGRAM LISTINGS:
Program 1 Main
Call repetition
It is more useful to be able to call a subroutine repeatedly and this is achieved by the use of the EVERY command. Program 2 uses this command to sound a note at one second intervals. In effect Program 2 is two programs running simultaneously, which is known as multi-tasking.
When using the SOUND command you must be careful to allow enough time for the sound to be played. In Program 2 the sound duration is 4/5ths of a second and as the subroutine is called only once a second, it has ample time in which to finish playing. Try setting the duration to 200 in the sound command. Once the four spaces in the sound queue are filled the computer will get 'hung up' at subroutine 1000. As explained in the article on Amstrad sound elsewhere in this issue, trying to put a sound into the queue when it is full will also put the computer into a wait state whether or not you are using interrupts.
If you now add a second interrupt (Program 3) it will cause the border colour to change every two seconds. Add Programs 4 and 5 to give five programs running simultaneously. The main program prints out the time in 300ths of a second, program 2 sounds a note every second (interrupt 0), program 3 changes the border colour (interrupt 1) and programs 4 and 5 draw diagonal lines on the screen (interrupts 2 and 3). The subroutines are very short and there is no problem performing the operations in one subroutine before the next interrupt is due.
If you were to amend the program thus:
Add yet another interrupt and see what happens:
In such a situation the commands DI (disable interrupts) and EI (enable interrupts) can be used. If you change line 1000 in the program to:
Finally I have included a program which demonstrates the use of the four interrupts to drive the four different programs using Amstrad's windowing system and the sound queueing facility. This is explained fully in the section entitled 'How it runs'.
| ![]() |
|