APPLICATIONSPROGRAMMATION ★ INTERRUPTS DEMONSTRATION (PERSONAL COMPUTING TODAY) ★

Interrupts Demonstration (Personal Computing Today)Applications Programmation
★ Ce texte vous est présenté dans sa version originale ★ 
 ★ This text is presented to you in its original version ★ 
 ★ Este texto se presenta en su versión original ★ 
 ★ Dieser Text wird in seiner Originalfassung präsentiert ★ 

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 = 60
20 WHILE TIME<START + 300 * SECONDS
30-998 (operations to be performed)
999 WEND

When 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.

Call direct

The same result can be obtained directly by using the Amstrad interrupt command, AFTER, which arranges to call a subroutine at a determined time in the future. Four timers may be used (0-3) and the syntax is as follows: AFTER time 1/50th seconds, timer number, GOSUB line number. The value for time must be an integer between 1 and 32767 allowing a range between 1/50th second and 11 minutes.

Program 1 will set each of the four timers to call each of the four subroutines at 15 second intervals. Line 50 is a neat way of performing a repetition loop whilst avoiding the use of GOTO. The variable, TIME, will always be greater than zero, so the operations between the WHILE and WEND statements will always be in an endless loop.

HOW IT RUN

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-180Create six tone envelopes
190-220Set 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

10 AFTER 7 50,0 GOSUB 1000
20 AFTER 1500,1 GOSUB 2000
30 AFTER 2250,2 GOSUB 3000
40 AFTER 3000,3 GOSUB 4000
50 WHILE TIME > 0:PRINT "TESTING";:WEND
1000 PRINT : PRINT "THIS IS 1 5 SECONDS" : RETURN
2000 PRINT : PRINT "THIS IS 30 SECONDS" : RETURN
3000 PRINT : PRINT "THIS IS 45 SECONDS" : RETURN
4000 PRINT : PRINT "THIS IS 60 SECONDS" : RETURN

Program 2, first interrupt

10 EVERY 50 GOSUB 1000
100 WHILE TIME 0:PRINT TIME;:WEND
1000 SOUND 2,200,40:RETURN

Program 3, second interrupt

20 COLOR = 0: EVERY 100,1 GOSUB 2000
2000 BORDER COLOR:COLOR = COLOR + 1
2010 IF COLOR = 27 THEN COLOR = 0
2020 RETURN

Program 4, third interrupt

30 EVERY 25,2 GOSUB 3000
3000 ORIGIN 0,0:DRAW 640,250:RETURN

Program 5, fourth interrupt

40 EVERY 40,3 GOSUB 4000
4000 ORIGIN 640,0:DRAW 1 640,250:RETURN

What you actually put into the subroutines is up to you. Even if subroutine 1000 takes longer than 1 5 seconds to run it will still be interrupted by timer 1. This is because there is a priority order for interrupts. In descending order of priority this is: ESC key, DI-EI, TIMER 3, TIMER 2, TIMER 1, TIMER 0. This subject will be covered in more detail later in this article.

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:

10 EVERY 50,0 GOSUB 1000
100 WHILE TIME >0: PRINT "TESTING";: WEND
1000 FOR X = 1 TO 100: PRINT X;: NEXT: RETURN

and RUN it you will see that once the interrupt is called it overrides the main program loop at line 100. In other words, the interrupt routine will 'gobble up' all the available time and the main program will not get serviced at all!

Add yet another interrupt and see what happens:

20 EVERY 50, 1 GOSUB 2000
2000 PRINT "This is INTERRUPT 1”: RETURN

This time interrupt 1, having priority over interrupt 0, will put a stop to interrupt 0 before it manages to print out 100 numbers. Note, however, that interrupt 0 will continue from where it left off after interrupt 1 finishes. In some instances it will not matter that a subroutine is interrupted but sometimes it might be vital to complete one subroutine before another is started.

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:

1000 DI:FOR X = 1 TO 100: PRINT X;: NEXT:EI:RETURN

all of the 100 numbers will be printed out before being interrupted by interrupt 1. Nothing can override it, except of course the ESC key which has the highest priority of all.

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'.

PCT

★ PUBLISHER: Personal Computing Today
★ YEAR: 1985
★ CONFIG: 64K + AMSDOS
★ LANGUAGE:
★ LiCENCE: LISTING
★ AUTHOR: David ELLIS
 



★ AMSTRAD CPC ★ DOWNLOAD ★

Type-in/Listing:
» Interrupts  Demonstration    (Personal  Computing  Today)    ENGLISH    LISTINGDATE: 2025-10-28
DL: 18
TYPE: PDF
SiZE: 892Ko
NOTE: Supplied by archive.org ; 1 page/PDFlib v1.6

★ AMSTRAD CPC ★ A voir aussi sur CPCrulez , les sujets suivants pourront vous intéresser...

Lien(s):
» Applications » Abbreviations For Keywords (Popular Computing Weekly)
» Applications » Copy Key Utility (Computing With the Amstrad)
» Applications » The Key
» Applications » Keylist (Computer Schau)
» Applications » Tastaturübersetzung - Keytrans (CPC Amstrad International)
» Applications » Swift Software - Keyword
Je participe au site:
» Pour ce titre nous ne disposons de fichier executable sur CPC (Dump, Saisie du listing) , alors si vous avez ça dans vos cartons ou vous désirez usé vos petit doigts boudinés sur votre clavier faites le nous savoir.
» Vous avez des infos personnel ?
» Vous avez remarqué une erreur dans ce texte ?
» Aidez-nous à améliorer cette page : en nous contactant via le forum ou par email.

CPCrulez[Content Management System] v8.732-desktop/c
Page créée en 030 millisecondes et consultée 110 fois

L'Amstrad CPC est une machine 8 bits à base d'un Z80 à 4MHz. Le premier de la gamme fut le CPC 464 en 1984, équipé d'un lecteur de cassettes intégré il se plaçait en concurrent  du Commodore C64 beaucoup plus compliqué à utiliser et plus cher. Ce fut un réel succès et sorti cette même années le CPC 664 équipé d'un lecteur de disquettes trois pouces intégré. Sa vie fut de courte durée puisqu'en 1985 il fut remplacé par le CPC 6128 qui était plus compact, plus soigné et surtout qui avait 128Ko de RAM au lieu de 64Ko.