[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: software clock better than hardware clock
<gids.rs@sasktel.net> wrote:
> 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
In fact, all the interrupt has to do is increment the ASCII time, quitting
as soon as a digit doesn't carry out to the next digit.
This is a very simple routine, controlled by an "edit string" having the
maximum digit in each position and any other display characters desired.
For example, 12:59:59 for the time.
Since it stops propagating carries as soon as there isn't one, switching to
a simple move, it's very fast on the average.
However, interrupting software clocks are incompatible with software timed
routines, so they must have a way of counting interrupts not taken so they
don't lose time when interrupts are disabled for more than the interrupt
period. (Floppy disk I/O is an obvious case.)
A 6522 has both a timer that can be used to create regular interrupts and
another counter that can keep track of how many interrupt requests were
made while they were disabled, so the software clock doesn't lose time.
Of course, long-term timing accuracy is another matter, since the
computer's clock crystal is much less accurate than the "watch crystal"
used by a real-time clock.
-michael - NadaNet 3.1 and AppleCrate II: http://home.comcast.net/~mjmahon