
The 25¢ Apple II Real Time Clock (1981) - lisper
https://www.atarimagazines.com/compute/issue9/030_1_THE_25C_APPLE_II_REAL_TIME_CLOCK.php
======
lisper
Author here. This was the first article I ever published. I was 16 years old
when I wrote it, and reading it today makes me cringe a little. AMA.

~~~
classichasclass
Why? I wouldn't have guessed your age from the article at all, in fact. I
wrote several submissions for COMPUTE!'s Gazette when I was in high school.
Yeah, I could have improved the prose and tone a bit, but the tech was sound
or it wouldn't have gotten through the editorial process. It's a shame type-in
mags and the old hobbyist journals have died, because it was a great way to
encourage writing, it was fun to see your name in print, you had a coding
standard that was public to aspire to and you made some okay money.

~~~
lisper
Why what? Why does it make me cringe? Mainly the section headings. "All about
interrupts" followed by "More about interrupts." If the first section was
_all_ about interrupts then there shouldn't be any _more_ to say about it.

Yeah, I know, I can be pretty hard on myself :-) (And I did say it made me
cringe _a little_. I'm mostly pretty proud of what I did back then.)

~~~
jacobush
I thought the headings were a pretty good humourous addition

~~~
lisper
Thank you! :-)

------
segfaultbuserr
Well-written article.

But professionally, although most Real Time Clock module does generate
interrupts, it's misleading to call this simple circuit a "Real Time Clock",
there is no "Real Time". It's better to use the term "counter", or "timer".

~~~
lisper
"The 25c clock" seemed like a snappier title than "A simple hack that lets an
Apple II keep track of real time (while it's powered on) and do some basic
multitasking" even though that would have been more accurate.

~~~
NikkiA
Given that it's a second off after every 16 seconds (interrupt tate: 59.939Hz,
assumed rate: 60Hz), it's not even really keeping track of time while powered
on.

~~~
lisper
You need to check your math. It loses about 1.5 minutes per day on a naive
implementation. Very few people left their computer running all the time in
those days. (Also, it's pretty to fix the problem in software.)

~~~
NikkiA
You're right that my math is off, it loses 0.06s every minute, so a second
every 16 minutes, still not 'real time'.

~~~
mmjaa
In those days, having a clocking mechanism which produced consistent time -
i.e. a monotonic clock - was of quite high value. On boot up, it was typical
to ask the user what time it was, and continue with the program.

But then how do you measure time since boot? With simple hacks like this of
course. Also, this hack allowed a form of multi-tasking, an 8-bit feature
quite well targeted back then.

Consistency was key in such clocks, not necessarily accuracy. The fact of the
drift is not important, since it was consistent and could be accomodated for
in software - as many peripherals of the day, indeed, required.

------
NikkiA
It's not a RTC though. it's just a 59.939/60 second tick.

------
Taniwha
Grabbing the mains to get a 60hz clock is a mutch older hack, pdp11s did that
before apple 2s did this,and I'm sure others did it before DEC did

~~~
matthewowen
Fun things happen if you do this and run your hardware outside the US: most
countries use 50hz mains AC.

~~~
Someone
Fun things also happen if that frequency isn’t what you think it is. EU clocks
derived from the 50Hz signal, for example, ran up to 6 minutes slow in March
2018 ([https://www.theverge.com/2018/3/8/17095440/europe-clocks-
run...](https://www.theverge.com/2018/3/8/17095440/europe-clocks-running-slow-
electricity-frequency-kosovo-serbia))

And of course, it also is “fun” when you accidentally do not only pick up the
frequency of mains power, but also its voltage in your electronics.

------
mmjaa
>a lot more than just a clock, it's a cheap way of doing a lot of expensive
things, right in line with Apple tradition.

Ah, for the Apple of 1981.

~~~
scarface74
Was the Apple really cheap in 1981 compared to its contemporaries? By 1985 it
was the most expensive 8 bit computer being sold if I remember correctly. I
had a //e.

~~~
NikkiA
In europe the //e was considered one of the most expensive 'home' computers,
to the point that it was only really colleges that had any.

~~~
mmjaa
My first (and best) 8-bit machine cost me $400, but I had to literally drive
across the nullabor to get it (Perth->Melbourne). I suppose the fuel costs
could have been put into a full-blown Apple system, but then I wouldn't have
driven across the nullabor with my first computer (Oric-1), plugging into
every TV I can find along the way ..

------
sehugg
WWVB (the NIST atomic clock signal) encodes at 1 bit per second, it would be
easy to hook a receiver up to the cassette port and decode this -- I'd guess
someone even tried this back in the day. Though you have to wait 60 seconds
for a full timestamp, and doing it in the background might be tricky.

~~~
CamperBob2
The Apple II cassette port had layers of awesomeness to it that still go
unappreciated today, even by the platform's hardcore devotees.

For one thing, it was about as fast as a Commodore 64 _disk drive_ , although
that was due more to incompetent engineering on Commodore's part than
brilliant engineering on Woz's part. (There was plenty of unpicked low-hanging
fruit in Woz's own Disk II system.)

For another, you could connect it to an old telephone hybrid and get a free
1200-baud modem, albeit a nonstandard one. Perfectly adequate for allowing two
Apples to talk to each other.

And yes, I don't see why you couldn't rig it up to decode WWV(B) transmissions
with a minimal amount of external hardware, especially in conjunction with an
interrupt-driven timer like the one described in the article.

~~~
ChickeNES
> There was plenty of unpicked low-hanging fruit in Woz's own Disk II system.

Do you have more details about this? Usually when the Disk II is brought up
it's praised for its simpleness and utility.

~~~
djmips
I'm guessing what could be considered low-hanging fruit would be that the
original 4&4 encoding was later surpassed by much more efficient 6&2 encoding
a few years later. And even then, the 6&2 encoding scheme chosen wasn't ideal
as it took too long to decode. Later intrepid programmers were able to decode
an alternate scheme of 6&2 in time to read an entire track within the
revolution of the disk and get closer to ideal performance and data density.

------
tlb
Using the NMI (non-maskable interrupt) on an Apple II is so wrong! The disk
software relied on precise timing of instruction sequences to read and write
bits on the disk. If you have interrupts going, reads will fail and writes
will corrupt the sector being written and possibly the next sector.

~~~
Narishma
It's mentioned in the article.

------
simias
I don't know much about the Apple II but I'm surprised that external circuitry
is required to effectively count the number of frames. Isn't there already a
way to count the number of frames without hardware hack on this computer?

Beyond that, an RTC without battery backup to maintain the time across reboots
might not be extremely useful. Given the low precision I'd consider this more
like a hardware timer than an RTC, but I'm probably splitting hairs now.

It's still a cool hack nonetheless, it's always refreshing to see how simple
and straightforward it is to hack these old machines, both in hardware and
software. Can you imagine doing something like that on a modern system? I
mean, it's doable but it'll take more than three lines of assembly to get it
to work correctly.

~~~
sehugg
Nope. You can't even write a busy loop that syncs with the frame rate because
the ][ lacks a VSYNC flag. Some modern demos manage to read the beam position,
though -- they look at values on the bus left over by the video circuitry when
the bus is floating (the "vapor lock" hack)

~~~
djmips
The technique is from 1982 by Bob Bishop.
[http://rich12345.tripod.com/aiivideo/softalk.html](http://rich12345.tripod.com/aiivideo/softalk.html)

~~~
sehugg
Ah, thanks -- I must have missed that issue! :)

------
dev_dull
> _traditionally require boards full of parts to implement, but are done with
> only one or two inexpensive chips._

I’m surprised there’s nothing about Wozniak in this. The guy used to look at
circuit boards as a kid and redesign them to use less chips... for fun! As a
kid!

------
ars
> For instance, the analog to digital conversion for the game paddles would
> normally cost at least $25, but is done on the Apple with a single
> inexpensive timer chip.

I discovered this back in the day when I modified a breakout clone to use
keyboard input instead of a paddle (joystick) which I didn't own: The game ran
much much much faster, and because I had never ran it using a paddle I didn't
realize for quite a while that it wasn't supposed to run that fast, and I
thought I was just bad at the game.

------
snops
Not what I was expecting, normally I would expect a real time clock to keep
running when the system was turned off, so you would be able to have accurate
current date/time.

I'm also very surprised to see that apparently the Apple II didn't have
something like this built in already, were all delays implemented as busy
loops?

~~~
pvg
_the Apple II didn 't have something like this built in already_

I don't think any of the popular 8-bit machines did. It might make more sense
if you consider it from the other end - what would you do with an accurate
date and time on such a machine?

~~~
snops
Ah, by "this" I meant the articles 60Hz timer, not the proper date/time
peripheral I imagined the article to be from the title.

For a 60Hz timer, just being able to have a delay without needing to count all
the instructions in between when programming.

~~~
pvg
The Apple //e had a way to track vertical retrace but that's a fairly late
model. It was a sort of 'interrupt-free' system anyway so given that and its
overall slowness, cycle counting ends up being the practical default.

