THIS month we'll be taking a look at one way of using the Amstrad's four delay timers. These allow a program to be getting on with one task and then, after a specified delay, performing another. When this is done, it gets on with the job it was doing beforehand. - 10,20 The usual REMs. giving a hint as to what the program does and who was responsible for it.
- 30 Selects Mode 2. This makes the screen tidier and the text clearer.
- 40 Sets the numeric variables sum, routine, and flag to zero. This isn't strictly necessary as the Amstrad assumes that they are zero until they're assigned another value. It is. however, good programming practice.
- 50 This line uses the command AFTER to toll the micro to go and perform the subroutine at line 190. but only after a delay. In the meantime it can be doing something else. The delay is set by the first figure following the AFTER, the units being 1/50th of a second. Here the delay is to be 250 of these units, in other words 5 seconds. The 0 following the 250 tells the Amstrad which of its four timers, numbered 0 to 3. to use.
- 60 This time the AFTER is followed by the figures 500 and 1. This means that before the subroutine at line 240 is called there will have been a delay of 10 seconds, measured on timer number 1.
- 70,80 Use timers 2 and 3 to call the subroutines at lines 290 and 340 after delays of 15 and 20 seconds respectively.
- 90,100 Inform the user of the result of the previous lines. All four timers are set and are ticking away. As each runs out the appropriate subroutine is called. Meanwhile the program carries on.
- 120-140 Form a WHILE ... WEND loop which carries on cycling until the variable flag, previously set to 0. takes the value 1. This will only happen after the fourth subroutine has been called.
- 130 Each time round the loop sum is increased in value by 1. The loop keeps on going round, adding 1 to sum while in the background the timers are ticking away, awaiting their moment of glory.
- 160,170 The program only reaches these lines after the WHILE... WEND loop has stopped cycling. This happens after the fourth timer has called the final subroutine and it has set flag to 1.
- 180 Stops the program crashing into the subroutines. Try leaving it out and see what happens.
- 190-230 These form the first subroutine, called when timer 0 has counted out five seconds. When this happens the Amstrad interrupts what it is doing in the WHILE... WEND loop and performs this subroutine. It then takes up the main program from where it left off.
- 240-390 Make up the subroutines called by timers 1. 2 and 3. Each time the value of routine is increased by 1 and both sum and routine displayed.
- 380 Sets flag to 1. ending the WHILE .. WEND loop.
CWTA ★ AMSTRAD CPC ★ DOWNLOAD ★ |
|
CPCrulez[Content Management System] v8.7-desktop Page créée en 262 millisecondes et consultée 851 foisL'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. |
|
|