Editor's Note: In the version of Mr. Robinson's clock routine for 4.0 BASIC, the code has been moved up 38 (decimal) from the Upgrade version of Program I. Add a value of 38 to his POKEs and references for the 4.0 version. — RTM

How many times have you sat down at your computer to fiddle around for a few minutes, returning to the real world hours (or days) later. This is not always a problem and I don't mind being splattered with cold suppers, missing parties, or aggravating my wife. But one night, I had some free moments to ponder the problem of losing track of time. Wouldn't it be great, I thought, if I could always have the correct time on the screen.

I knew that my PET had a 1/60 second counter which is updated during the internal interrupt cycle and some routines to print out the time. I started to study the memory map in Osborne's PET/CBM Personal Computer Guide and found the following items: jiffy memory, clock correction routine and the location of the interrupt addresses.

I figured if I could revector the interrupt through a small machine language program, I could capitalize on all three items – the jiffy clock to keep track of time, the interrupt addresses to return to the correct location and the clock correction routine to make up for the lost time of my program, if necessary.

Some other investigation showed that the routines that print the TIME$ use a lot of processing time and interact with memory locations that Basic uses. I figured it would be best to handle it completely as a separate little program. Then, the more I thought about it, I realized that once the time was set, I could follow it with a simple series of little counters rather than keep having to do long divisions. This also has the advantage of being able to jump back to the normal program whenever there is no carry up to the next most significant clock digit. This saves over 50 percent of the time penalty of the screen clock.

To initialize the clock and load the machine language program, I wrote a small BASIC program. You can follow the explanations in the flowchart and the symbolic listing of the machine language program along with the listing of the BASIC program. The machine language program is short enough to load with pokes rather than entering it using the machine language monitor. You can enter and run this as a normal basic program and, while the clock is running, you can use most BASIC programs. There is a small time penalty to use this while running BASIC, but if you are programming or game playing, it is not critical.

Incidentally, since the program is synchronized with the jiffy counter, you are automatically using the PET's internal correction routine. On a three hour run against a stop watch, the PET gained two seconds (so much for my stop watch). Two words of caution when you are writing programs: first, if you hit return on the line the time is on it will be entered in the listing and, second, if you have to load a program from the cassette, turn the clock off (POKE 144, 46:POKE 145,230), load the program, and start the clock again (POKE 144,74:POKE 145,3). To reset the clock poke the correct time digits to locations 833-838.

Symbolic Listing Real Time on Screen

DEFINITIONS

LOTB = Least significant time bit— (Jiffy Counter)

TL0C1 Temporary holding location

TL0C2 Temporary holding location of prior jiffy count

BASE 1 - 7 Base of count, 10 or 6

IMAGE 1-7 Location of time in memory

SCT1-7 Screen locations of time

INITIALIZE

LDA LOTB

Initialize prior count set it ahead to next. 1 second. Note 1

ADC #05

STATL0C2

LDA#Start

Revector interrupt to start

STAIRQ Low

START

LDA #LOTB

Check jiffies see if we've reached next.1 sec

STATL0C1

CMPTL0C2

ADC #05

Yes-set TL0C2 for next. 1 sec, make sure that if more than 6 jiffs occurred we do not add too much

SBC TL0C2

ADCTL0C1

STA TL0C2

INC IMAGE.7

Increase. 1 sec memory location by 1

LDX#07

Initialize counter routine

COUNTER

LDA IMAGE.X

Check to see if we've reached limit of base which produces a carry

CMPBASE.X

BNE UPDATE INIT

No — then go to Update Init

LDA #00

Yes — place 0 in digit position

STA IMAGE.X

DEX

Go to next number in sequence

BEQ UPDATE INIT

If we have done all 7 digits go to screen update

INC IMAGE.X

Increment next digit by 1 (result of carry)

JMPCOUNTER

Go back and check this digit for carry

UPDATE INIT

LDX #07

Initialize the screen update routine

UPDATE

LDAIMAGE,X

Load time digit

ADC #$30

Convert to PET number code

STASCT,X

Store on screen

DEX

BNE UPDATE

Have we done 7 digits?—no go back to update

LDA #3A

Yes—load and store colon on screen

STA SCT,O

JMP IRQ

Return to PET IRQ routine

Note 1: The reason that five is added to the jiffy count and not six (to get the next 6/60 or .1 sec) is that we are incrementing when the prior count location is less than the jiffy count. If the increment occurred on equality then you would add six. The reason for this is that I do not know if the jiffy count can count two sometimes in which case the equality would not occur for up to 12.8 seconds — when the same binary digit again occurred. This is also the reason the program checks for more than six counts.