Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Commodore Time Clock in Basic (Programming Help)

155 views
Skip to first unread message

Christopher A. Haslage

unread,
Jan 6, 1999, 3:00:00 AM1/6/99
to

Heya Ppls:

I have a simple clock that keeps time, I use a gosub to get into
it and when you press a button it exits and goes to another part of
a program. But when I recall the clock it is the exact time (to the
second) of when I left it. (12:10:59 AM or such) It will count from
that point on until I press the button to exit the gosub...

Is there a simple clock program for the commie basic that keeps
exact time and uses the format (12:00:00 AM). I would assume it would
use ti$, using ti (no $) I would assume would be too fast. If you
have a suggestion or program, I would love to hear it! E-mail me
with suggestions.

Thanks,

Christopher Aaron Haslage
--
Christopher A. Haslage *"That was brilliant...* iv...@cleveland.freenet.edu
AKA Yakkov Silverman * ...what was that?"* kilo...@geocities.com
VP of Haslage Net Elect. *-- Elton John, 1987 --* kilo...@hotmail.com
----------- http://www.geocities.com/Hollywood/Lot/5039/intro.htm -----------

Jim Butterfield

unread,
Jan 6, 1999, 3:00:00 AM1/6/99
to
iv...@cleveland.Freenet.Edu (Christopher A. Haslage) wrote:

> I have a simple clock that keeps time, I use a gosub to get into
>it and when you press a button it exits and goes to another part of
>a program. But when I recall the clock it is the exact time (to the
>second) of when I left it. (12:10:59 AM or such) It will count from
>that point on until I press the button to exit the gosub...
>
> Is there a simple clock program for the commie basic that keeps
>exact time and uses the format (12:00:00 AM). I would assume it would
>use ti$, using ti (no $) I would assume would be too fast.

TI$ and TI are the same clock. The only diff is the way the data is
presented to you (and that you set TI$ rather than TI).

TI$ is handier if your objective is to present the time in "human
readable" format. TI measures in smaller steps (a jiffy is 1/60
second), but gives the same value: divide TI by 60 to get seconds,
divide by 60 again to get minutes, and once more to get hours.

Programmers like TI for timing events since you don't have to convert
hours-minutes-seconds; you can just subtract two readings to get the
time interval.

Watch both TI and TI$ carefully if you're crossing "midnight"; the
time resets to zero. A program which wants to calculate a future time
for scheduling purposes might fall foul of this. Suppose a "schedule"
is to be set up 10 seconds in the future .. and suppose that the TI$
value is 23:59:55 (with TI having the same value). A naive program
would plan to action the schedule when the clock shows 24:00:05, which
it never will (the program would be doing this with TI, in jiffies,
but the same applies). One of the earliest Commodore PET demo
programs showed the starship Enterprise moving through a star field ..
but this exact glitch caused the program to hang every few days.

> If you have a suggestion or program, I would love to hear it! E-mail me
>with suggestions.

I'll post rather than email, since others might find the answer
useful. If your objective is to show real time-of-day, your program
should simply take the value of TI$, prettying it up if desired. You
need to ensure that the user enters the correct time of day at the
start of this program, or before running it.

--Jim


Christopher A. King

unread,
Jan 6, 1999, 3:00:00 AM1/6/99
to
Christopher A. Haslage wrote:

> I have a simple clock that keeps time, I use a gosub to get into
> it and when you press a button it exits and goes to another part of
> a program. But when I recall the clock it is the exact time (to the
> second) of when I left it. (12:10:59 AM or such) It will count from
> that point on until I press the button to exit the gosub...

> Is there a simple clock program for the commie basic that keeps
> exact time and uses the format (12:00:00 AM). I would assume it would

> use ti$, using ti (no $) I would assume would be too fast. If you


> have a suggestion or program, I would love to hear it! E-mail me
> with suggestions.

A much more accurate clock exists in the CIA chips, but after having
been away from any programming on the C-64 for just about ten years now,
I can't remember for certain if it's accessible through BASIC, or how
it would be if it was. I only programmed in 6502 machine code back
then, and used that to initialize/read the CIA clock... in my application
I didn't display the clock per se, but simply set it to zero and timed
how a long a particular application had been running before it was
terminated. Granted, the jiffy clock probably would have been good
enough for this application, but at the time I was somewhat "geeked"
about using the one in the CIA. I still have the source code at home
(written using Merlin).

C.K.

Cameron Kaiser

unread,
Jan 6, 1999, 3:00:00 AM1/6/99
to
"Christopher A. King" <cki...@mail.ford.com> writes:

>A much more accurate clock exists in the CIA chips, but after having
>been away from any programming on the C-64 for just about ten years now,
>I can't remember for certain if it's accessible through BASIC, or how
>it would be if it was. I only programmed in 6502 machine code back
>then, and used that to initialize/read the CIA clock... in my application
>I didn't display the clock per se, but simply set it to zero and timed
>how a long a particular application had been running before it was
>terminated. Granted, the jiffy clock probably would have been good
>enough for this application, but at the time I was somewhat "geeked"
>about using the one in the CIA. I still have the source code at home
>(written using Merlin).

The TOD clock is accessible from BASIC, but not really *useable* from BASIC.
The latch feature does make it at least possible to get a reading without
the time changing on you.

--
Cameron Kaiser * cdkaiser.cris@com * powered by eight bits * operating on faith
-- supporting the Commodore 64/128: http://www.armory.com/~spectre/cwi/ --
head moderator comp.binaries.cbm * cbm special forces unit $ea31 (tincsf)
personal page http://calvin.ptloma.edu/~spectre/ * "when in doubt, take a pawn"

Cameron Kaiser

unread,
Jan 6, 1999, 3:00:00 AM1/6/99
to
iv...@cleveland.Freenet.Edu (Christopher A. Haslage) writes:

> Is there a simple clock program for the commie basic that keeps
>exact time and uses the format (12:00:00 AM). I would assume it would
>use ti$, using ti (no $) I would assume would be too fast. If you
>have a suggestion or program, I would love to hear it! E-mail me
>with suggestions.

Very easily done. You can use TI$ by simply adding in a translation step
to convert it to 120000-style time.

>>> begin program
63990 j=val(ti$):ap=1:ifj>125959thenj=j-120000:ap=2
63991 ifj<10000thenj=j+120000
63998 j$=right$("0"+mid$(str$(j),2),6):ap$=mid$("AP",ap,1)
63999 j$=left$(j$,2)+":"+mid$(j$,3,2)+":"+right$(j$,2)+" "+ap$+"M":return
>>> end program

j$ contains your clock, in AM/PM.

John Iannetta

unread,
Jan 7, 1999, 3:00:00 AM1/7/99
to
Cameron Kaiser said,

">>> begin program
63990 j=val(ti$):ap=1:ifj>125959thenj=j-120000:ap=2
63991 ifj<10000thenj=j+120000
63998 j$=right$("0"+mid$(str$(j),2),6):ap$=mid$("AP",ap,1)
63999 j$=left$(j$,2)+":"+mid$(j$,3,2)+":"+right$(j$,2)+" "+ap$+"M":return
>>> end program

j$ contains your clock, in AM/PM.".

So a half hour after midnight, the time will be 12:30:00 PM?

--
I pressed RETURN, and the message said, "Missing GOSUB".

John

John Iannetta

unread,
Jan 7, 1999, 3:00:00 AM1/7/99
to
Cameron Kaiser said,

"The TOD clock is accessible from BASIC, but not really *useable* from BASIC.
The latch feature does make it at least possible to get a reading without

the time changing on you.".

Oh, I don't know.

>> begin program
10 t=56328:rem cia1; 56584 for cia2
15 s=t+1:m=t+2:h=t+3:k=5/8:a$(1)="0":a$(2)="p":a$(3)="a"
":inputa$:ti$=a$:gosub800
18 gosub900:printj$:goto18
20 input:gosub900:printj$:goto20
800 rem set tod clock to ti$
810 f=128:t$=ti$:ift$<"12"thenf=.:goto830
820 r$=right$(t$,4):l=val(left$(t$,2))-12:t$=right$("0"+mid$(str$(l),2)+r$,6)
830 a=val(mid$(t$,2,1)):ifasc(t$)=49thena=a+16
840 ifleft$(t$,2)="00"thena=12
850 pokeh,f+a:a=val(mid$(t$,4,1))+16*val(mid$(t$,3,1)):pokem,a
860 a=val(mid$(t$,6,1))+16*val(mid$(t$,5,1)):pokes,a:poket,.
870 return
900 a=peek(h):x=(aand15)+(aand112)*k:x$=str$(x)
910 b=peek(m):y=(band15)+(band112)*k:y$=str$(y)
920 b=peek(s):z=(band15)+(band112)*k:z$=str$(z)
930 b=peek(t):j$=a$(1+(x>9))+mid$(x$,2)+":"+a$(1+(y>9))+mid$(y$,2)
940 j$=j$+":"+a$(1+(z>9))+mid$(z$,2)+" "+a$(3+(a>127))+"m"
950 return
>> end program

The above C-64 BASIC program prints the TOD clock's time to screen,
whenever <RETURN> is pressed. The subroutine at line 800 sets the TOD clock to
ti$. There is no correction for the defect that makes the TOD clocks follow:

11:59:59.9 AM

with

12:00:00.0 PM

instead of AM, althogh 0.1 seconds later, the clocks' PM will be correct. A
similar flaw exists for midnight.

The jiffy clock (ti and ti$) has better short term stability than do the
TOD clocks; the jiffy clock is derived from the computer's crystal oscillator.
A typical crystal has a frequency tolerance of 50 ppm (parts per million), and
a frequency temperature coefficient of 50 ppm over the specified temperature
range. In practice, the crystal frequency will probably never deviate more
than about 30 ppm. But if the computer is left on continuously, that means
over a minute each month. Also, a KERNAL bug adds an extra jiffy each day.
And the divisor used for CIA1's TIMER A does not give the closest match to 60
Hz; the number should be one less. But most importantly, the jiffy clock will
be temporarily stopped during RS-232 service, and during IEC (serial) bus
activity. And if you turn off the timer (as for fetching the character set
from character ROM), the jiffy clock will be stopped.

The TOD clocks use the power mains for frequency control. PAL users should
note that on reset and power-up, 60 Hz triggering is selected. If a = 56334
for CIA1, or 56590 for CIA2,

pokea,peek(a)or128

will selct 50 Hz triggering, and

pokea,peek(a)and127

will select 60 Hz triggering. The TOD clocks are hardware clocks, they run
even without I/O mapped into memory. Rumors that they run even with the C-64
turned off have not been confirmed.

The short term stability of the TOD clocks can be poor at times. The power
companies (in the USA, at least) frequently adjust alternator speed so that all
devices that use the power-line frequency for timekeeping purposes, keep
correct UCT (Coordinated Universal Time). But those huge dynamos cannot have
their speeds changed rapidly; a sudden heavy load will produce a frequency
change that won't be immediately corrected. But the C-64's TOD clocks, like
any electric clock that has a power cord, will give VERY close to the correct
time month-after-month, year-after-year.

Cameron Kaiser

unread,
Jan 8, 1999, 3:00:00 AM1/8/99
to
John Iannetta <73510...@CompuServe.COM> writes:

>>63990 j=val(ti$):ap=1:ifj>125959thenj=j-120000:ap=2
>>63991 ifj<10000thenj=j+120000
>>63998 j$=right$("0"+mid$(str$(j),2),6):ap$=mid$("AP",ap,1)
>>63999 j$=left$(j$,2)+":"+mid$(j$,3,2)+":"+right$(j$,2)+" "+ap$+"M":return

>>j$ contains your clock, in AM/PM.

> So a half hour after midnight, the time will be 12:30:00 PM?

How do you figure? I set TI$="002940" and ran a little loop I put around
the program, and when it got to 003000 it correctly showed 12:30:00 am.

Cameron Kaiser

unread,
Jan 8, 1999, 3:00:00 AM1/8/99
to
Cameron Kaiser <cdka...@delete.these.four.words.concentric.net> writes:

>>>63990 j=val(ti$):ap=1:ifj>125959thenj=j-120000:ap=2
>>>63991 ifj<10000thenj=j+120000
>>>63998 j$=right$("0"+mid$(str$(j),2),6):ap$=mid$("AP",ap,1)
>>>63999 j$=left$(j$,2)+":"+mid$(j$,3,2)+":"+right$(j$,2)+" "+ap$+"M":return
>>>j$ contains your clock, in AM/PM.

>>So a half hour after midnight, the time will be 12:30:00 PM?

>How do you figure? I set TI$="002940" and ran a little loop I put around
>the program, and when it got to 003000 it correctly showed 12:30:00 am.

Chris Haslage did find a bug, but it wasn't that; the 125959 means that
a half hour after *noon*, the time will be 12:30:00 AM. So (third time's a
charm):

>>> begin program
63990 j=val(ti$):ap=1:ifj>115959thenap=2
63991 ifj>125959thenj=j-120000
63992 ifj<10000thenj=j+120000


63998 j$=right$("0"+mid$(str$(j),2),6):ap$=mid$("AP",ap,1)
63999 j$=left$(j$,2)+":"+mid$(j$,3,2)+":"+right$(j$,2)+" "+ap$+"M":return

>>> end program

Phew! :-)

John Iannetta

unread,
Jan 9, 1999, 3:00:00 AM1/9/99
to
Cameron Kaiser said (quoting me),

"> So a half hour after midnight, the time will be 12:30:00 PM?

How do you figure? I set TI$="002940" and ran a little loop I put around

the program, and when it got to 003000 it correctly showed 12:30:00 am.".

The explanation is simple; I goofed! I meant to say "So a half-hour after
noon, the time will be 12:30:00 AM?", budecided that the "after noon" could be
confusing. So invoking the concept of symmetry (which, unfortunately, didn't
apply in this case), I made the aberrant statement that you quoted for all the
world to see. My head is bowed in shame (and also because I am sneezing).

But you corrected the bug; that was the intent of my post. And that is the
strength of these Newsgroups; up to 100 million eyes are reading every word
posted (to convert eyes to persons, divide by 2 and round off to an integer).
In this age of misinformation (where misinformation is easier to get than it
ever was), Newsgroup articles can be considered to have been proofread many
times.

John Iannetta

unread,
Jan 9, 1999, 3:00:00 AM1/9/99
to
DickC said,

"Excuse me....but the minute after 11:59:59 PM is 12:00 AM and the
daylight version becomes 12:00 PM. It has always been that way and I
don't understand the problem. It other words, midnight has always
been referred to as 12:00 AM and noon 12:00 PM."

Or...am I missing something in this thread?".

The convention in the USA is that noon is 12 AM and midnight is 12 PM. In
that regard, the two hardware TOD clocks have flaws (noon is 12 PM and midnight
is 12 AM).

Jim Butterfield

unread,
Jan 10, 1999, 3:00:00 AM1/10/99
to
John Iannetta (73510...@CompuServe.COM) wrote:

: The convention in the USA is that noon is 12 AM and midnight is 12 PM.

With all due respect, John, I ain't gonna ask YOU to program my VCR to
record those midnight movies .. :-)

--Jim


Greg King

unread,
Jan 14, 1999, 3:00:00 AM1/14/99
to
John Iannetta wrote:
> DickC said,
> > Excuse me, but the minute after 11:59:59 PM is 12:00 AM, and the
> > daylight version becomes 12:00 PM. It has always been that way, and I
> > don't understand the problem. In other words, midnight always has
> > been referred to as 12:00 AM, and noon as 12:00 PM.
> > Or, am I missing something in this thread?
>
> The convention in the USA is that noon is 12 AM, and midnight is 12 PM. In
> that regard, the two hardware TOD clocks have flaws (noon is 12 PM, and midnight
> is 12 AM).

That's the way it USED to be! It still SHOULD be that way
(AM and PM stand for the latin words which mean AFTER and BEFORE
the middle); but then, "AD 2001" should start the next millenium --
we know what people think about THAT, don't we!

I say that the road to "ruination" started with dial telephones.
The tenth number was marked as "0" instead of "10." Then, that number
moved from the "end" of the keypad to the "front" when calculators
were invented. Nowadays, we count fingers from one to ten --
but we count digits from "0" to "9!"

Therefore, the "unwashed masses" (in the USA) say that the second
millenium starts exactly at midnight, 12:00:00.0 AM, January 1, 2000.

P.S. Europeans say "1 January 2000;" both of us are lopsided,
it should be "2000 January 1" -- but,
we know what people think about that, don't we.

Kevin Reno

unread,
Jan 15, 1999, 3:00:00 AM1/15/99
to

Okay, we all know that midnight and noon are neither AM or PM
They are simply midnight and noon.

--
-------------------------------------------------------------------------------
whammo __ __ ____ ___ ___ ____
wha...@primenet.com /__)/__) / / / / /_ /\ / /_ /
/ / \ / / / / /__ / \/ /___ /-------------------------------------------------------------------------------

John Iannetta

unread,
Jan 16, 1999, 3:00:00 AM1/16/99
to
Jim Butterfield said (about my contention that noon is 12 AM, and that
midnight is 12 PM),

"With all due respect, John, I ain't gonna ask YOU to program my VCR to record

those midnight movies .. :-)".

I guess that that's the price that I pay for being VCR-impaired. I puzzled
over your post for a while; then it hit me all of a sudden. But nowhere in my
home is a VCR, digital clock radio, or similar device. I did find a digital
watch with a dead battery, though. So a call to an affluent neighbor confirmed
my darkest suspicions; VCR's (and probably almost ALL digital clocks/timers)
use 12 PM for noon and 12 AM for midnight.

Of course, it's EASIER (in either hardware or software) to use that
standard; when hours are incremented from 11 to 12, the AM/PM flag is flipped.
But to paraphrase Mark Twain, if you call a tail a leg, a horse still has four
legs. Because calling a tail a leg doesn't MAKE a tail a leg. I had always
considered 12 AM to be noon; it was indelibly engraved in my spine. I checked
an old (circa 1940) "Webster's Encyclopedic Dictionary", and saw that when it
is 9 AM in New York, it is 12 PM in Melbourne, Australia. A glance at a world
map shows that it is midnight in that city. But with the 24-hour clock being
used more and more, I suspect that determining what the noon/midnight standard
is may be difficult. The few attempts that I made were unavailing.

I also suspect that the reason that insurance policies take effect at 12:01
AM, is to avoid confronting the problem. But what if a written contract
contains language such as "Payment must be received no later than March 15,
1999, at 12 PM."? That makes finding the definition of 12 AM (or 12 PM) quite
important. But IF the standard had been (before the advent of digital
timekeeping) that 12 AM was noon and that 12 PM was midnight, does the
proliferation of digital clocks, VCR's, etc., that reverse that definition,
change that standard?

Q) How many Microsoft engineers does it take to change a light bulb?

A) None. They define darkness as the new standard.

0 new messages