[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
software clock better than hardware clock
- Subject: software clock better than hardware clock
- From: gids.rs@sasktel.net
- Date: Fri, 28 Dec 2012 21:52:30 -0800 (PST)
- Complaints-to: groups-abuse@google.com
- Injection-date: Sat, 29 Dec 2012 05:52:30 +0000
- Injection-info: glegroupsg2000goo.googlegroups.com; posting-host=142.165.85.213; posting-account=U4TNXwoAAABP4nIJHynAJZ69O_f3LY2g
- Newsgroups: comp.sys.apple2
- User-agent: G2/1.0
I was playing around with interrupts to find different uses for interrupts. One of the big questions I wanted to answer was, how much processing power does a computer use to update the seconds of a clock and display it on the screen, and how much time is left until the next interrupt comes from the next second.
On a IIGS there is a one-second interrupt register, that initiates an interrupt, well, you guessed it, every second.
But the standard way would be to read the clock, do some math to convert the returned digits to screen digits, then display them to the screen.
The reading of the clock and converting the numbers to screen digits take a very long time in computer time.
A much simpler method and uses far less processing power is to use software to keep track of the seconds and minutes, then read the real clock once the clock strikes on the hour. For computers without clocks, the house is updated by software and the clock read is ignored.
A very simple routine that has each digit already converted to a screen character but also counts from 0 to 9 looks like this:
*One Second Interrupt points to here
SED
CLC
LDA ONESECDIG ; ones digit of the seconds
ADC #1
AND #$F
STA ONESECDIG
BEQ SECTENS ; tens digit of the seconds
ORA #$B0
STA $426
CLD
RTS ; if only the ones digit is updated, we are already finished
; you can see how this is a far cry of way fewer cycles than from reading from a real clock
SECTENS LDA TENSECDIG
ADC #0
CMP #7
BCC RESETTENSEC
LDA #0
RESETTENSEC STA TENSECDIG
BEQ ONEMINDIG
ORA #$B0
STA $425
LDA #$B0
STA $426
CLD
RTS
ONEMINDIG EQU * ; ones digit of the minute
This short routine not only counts from o to 59, but already has the digits converted, and, displays the seconds on the screen without the time consuming routine of reading the clock and converting the numbers to screen digits.
The routine to set up the interrupts has to be done for this software clock as well as if reading from a real clock so no extra overhead is needed for this software clock.
Just wanted to write this to show that hardware is not always better. The entire software clock routine and display routine is about 3-1/2 times this size. And it is still smaller than the clock read routine, conversion routine and display routine of a real clock.
Rob