★ APPLICATIONS ★ DIVERS ★ Real Time Clock: Clock on with your Amstrad ★![]() |
| Real Time Clock (Computing with the Amstrad) | Applications Divers |
HAVE you ever been so engrossed in your programming that you've lost all track of time? I bet every programmer's had the annoying experience of missing an appointment in this way. Help's at hand though, with this machine code real time clock for the CPC series. Most people know of the Amstrad's internal clock system, constantly updating itself every 1 /300th of a second. It is very easy to access it from Basic by typing:
A better method would be to use Basic's EVERY routine to update our own clock every second. This would take the form:
The solution is to use a machine code routine which is called every second whatever the computer is doing at the time, be it running a program or waiting for a command to be input directly. This program will display the clock in the top left hand corner of window #7 in the form:
Once the ticker event has been initialised you will see. after a second, the time 12:00:01. This will continue to update itself every second whatever you do. This isn't a lot of good as it is, unless you started the clock at 12 o'clock, as it will not be displaying the correct time. However any clock worth its salt can be adjusted, and to change this one you must type:
The routine works by loading the E register with the hour, obtained from location &80AA, L with the minutes stored at &80AB and H with the seconds from &80AC. H, the seconds, is incremented first and tested to see if it's 60 and if it is then L, the minutes, is also incremented and H set to zero. If L is now 60 the hours in E are also incremented and the minutes in L reset to zero. Finally if the hours reach 13, E is set to 1 and the time can be printed. The display routine first stores the current position of the text cursor, switches to window #7 and moves the cursor to the top left corner. The hours, minutes and seconds in the E, L and H registers are printed and the cursor replaced. The machine code routine is called every second so there is a slight slowing down of the Amstrad when it is doing other tasks. The clock itself does not lose much time, except when the computer is doing certain tasks like accessing the disc drive or more noticeably the tape recorder, since the Amstrad switches interrupts off. It is therefore necessary to set the clock again if it does lose a lot of time. Problems can also occur if you are not working in the default stream #0, as the routine switches to this stream after it has displayed the time. The machine code can be saved on its own by typing:
Now there will be no excuse for missing meals or your favourite TV program because you didn't realise what the time was - because it will be there in front of your eyes! CWTA
|