Software, technology, sysadmin war stories, and more. Feed
Thursday, October 13, 2011

C-64, Apple II and TI-85 clocks, plus a bit of trig

TI$ on C-64 emulator I was spoiled by my C-64. It had a built-in real-time clock which was halfway decent. It was easy to set and easy to use. You just had to set TI$ to something appropriate like 201608. If you didn't initialize it, then it would show the time since you last reset.

Around this same time, I went to a school which had a bunch of Apple IIs. Unless I've been grossly misinformed, the IIe systems which were so common back then did not have a real-time clock on board. Perhaps there may have been a way to expand it somehow, but we sure didn't have any of those accessories.

At any rate, I got bored one day and decided to see if I could make a clock. It wouldn't just run in the background, but that didn't bother me. I think I started by playing with a "FOR T = 1 TO 1000: NEXT T" loop and played with the end value until it seemed about right. I hope I actually ran it for some number of seconds and then divided by that to spread out the error, but who knows. It's been a long time.

Anyway, with my magic number in hand, I now had a second! Now it was time to set up a bunch of counters and a loop with a bunch of tests in it. At the top of my loop was the delay, and then all of the rollover stuff happened: seconds and minutes roll at 60, hours at 24, and all of that.

I think I even made an array (with DIM and/or DATA, I guess) with the number of days in a month so then I could start thinking about dates. Days would roll at that position, and then the month would roll at 12, and all of this. I distinctly remember adding a simple "divisible by 4" test to handle leap years, not knowing about the additional 100 (nope) and 400 (yep) rules.

Again, all of this is for a clock which was loaded from a floppy and ran for maybe five minutes at a time between when I had finished the boring "typing class" stuff and before they let us go. Talk about overkill.

A couple of years later, I found myself with a TI-85 and time on my hands (yet another boring class). For the uninitiated, the TI-85 has a weird little programming language which resembles BASIC in some respects. It has the added benefit of being able to draw graphics without too much trouble.

That Apple II clock program had been straight text. I wanted to try my hand at making an analog clock using the 85's graphics commands. I knew enough from playing with sin and cos to know they could probably be coaxed into give me the right positions for my clock's hands.

I decided to only draw hour and minute hands for multiple reasons. First, there was no way to erase along the path of a previous line as far as I could tell from the manual, so every update needed a full clear-and-redraw. Second, actually drawing it tended to take more than a second, so it would fall behind.

The worst part about this particular exercise is that my loop was entirely reliant on the calculator's performance, and it seemed to vary according to my battery charge. As things wore on, you had to crank up the contrast and crank down the loop length since it would take too long.

It's stuff like this which makes me really understand what's going on with trig functions like cos and sin. All of the stuff from a math book is just a bunch of words until I find some way to apply it.