Wednesday, February 23, 2022

KIMdle: Sorta-Wordle for the KIM-1

UPDATE: I'm trying to solve a debouncing bug for someone who reported it, though I can't reproduce it. If you have a similar issue on real hardware, please try the version up now.

Wordle mania (trademark, probably, of the New York Times) continues. My wife and I, who bonded over word games and later got married because that's how you pick a good life partner, play daily on a private instance, except that she's 19 hours ahead so she has to be careful not to give out spoilers. Retro has gotten into the action. There are Wordle ports for Windows 3.1, Palm Pilots, Game Boys and at least three versions for the Commodore 64, such as this, this and this poop themed one called Turdle, ha ha ha.

Still, however, while these ports ditch dependence on JavaScript and HTML, they still rely on other modern conveniences such as, you know, a screen, a keyboard, and multiple kilobytes of RAM.

You see where I'm going with this.

This is KIMdle, a semi-Wordle for the KIM-1. If you are unfamiliar with the MOS (later Commodore) KIM-1, it was the original 1976 single-board computer for the 8-bit MOS Technology 6502 CPU. It ran at 1MHz, had 1KB (1,024 bytes) of RAM, provided six seven-segment LEDs as a "display" and a hex keypad as input, and was very popular because it was one of the least expensive ways at the time to build your own microcomputer.
KIMdle works on a real unexpanded KIM with just the baseline LEDs and hex keypad (if you feel like keying in a dump or converting it to paper tape). No cheating, no tricks. You can actually play it. It's 100% 6502 assembly language.

To fit this into 1K of RAM with a dictionary — and actually, since I don't like putting code where the processor stack is, it's limited to 768 bytes — required some significant compromises, which is why I call it "sorta-" and "semi-Wordle."

This space limit meant there was no way to have a custom routine to drive the LEDs because I'd blow too much memory budget just on that (letter shapes, timing, etc., and keep in mind not every letter is legibly representable on a seven-segment LED). I would have to restrict myself to ROM routines, most importantly SCANDS, the routine the KIM's built-in monitor uses to display hexadecimal data. That meant limiting the game to letters A-F, plus 0, 1, and 5, because those can substitute for O, I and S. This also reduced the dictionary substantially, allowing single letters to be stored efficiently in a single nybble, and lets the player enter any valid guess directly on the keypad. (As I was writing this up it occurred to me 2 could substitute for Z, but that wouldn't help the dictionary a great deal.) I brute-forced /usr/share/dict/words with a Perl script and hand-edited the extract to only include words that actually appeared in my real Webster's dictionary. A few are obscure, but they're all real! There are 41 of them. The dictionary thus takes up a mere 123 bytes (I had to waste the unused nybble).

The space limit also meant two changes to gameplay, one minor and one major. The minor change is that KIMdle doesn't check if you've entered a legal word; you can enter AAAAA or BBBBB or 55555 and it will accept them. Many of the other small computer ports don't do this either, so this deficiency is hardly unusual. However, the major change is that KIMdle only reports letters you got right in the right place, not any letters that are right but out of place.

The simple reason for that is that the game was already occupying almost all of $0200 through $03ff (the words and temporary data occupy most of zero page) — KIM-1's 1K RAM ends at $0400 — and the search algorithm wasn't going to fit. Plus, it would have to do more bookkeeping than it currently does, too, which also has a memory cost. I could have squeezed a bit more out of the code by not having trivial encryption for the dictionary, but an innocent glance at the hex data shouldn't be an insta-spoiler, and any space I would have recovered in the processor stack (even if it fit) wouldn't be worth the inconvenience to debugging.

On top of that, how would you help the player distinguish a letter that's valid from a letter that's valid but misplaced? There are only seven segments; there's no other way to mark the LED. Plus, those are the same set of LEDs you're trying to enter your next guess into. I toyed with an "alternator" routine that would blink misplaced letters, but this required overhead of its own to display a second set of data and properly overlay it with the new guess the player is keying in, plus the additional code needed in the game loop. So I gave up and KIMdle just tells you what you got totally right and leaves it at that.

At this point some of you will say that I am cheating, because this is a substantial enough deviation to no longer qualify as Wordle. I can't really argue with this assertion, but you've still got a word game reminiscent of Wordle playing on a 1976 single board computer with less RAM than some modern TV remotes, and you don't even need a terminal or a keyboard.

Okay, so you want to play this. If you don't have a KIM-1 or clone but you do have a Commodore 64 or a Commodore 64 emulator, you can use the Incredible KIMplement (which is what I used to get the port up). It runs just dandy in VICE. Another simple emulator which will run KIMdle on your terminal session is this one, which should build on pretty much anything.

To build KIMdle itself you'll need a cross-assembler. Install xa65, either from your distro package manager or downloading it. It has no prerequisites or dependencies other than a C compiler and make, and is very portable. Other cross-assemblers may work, but I don't guarantee it.

Now, grab the source. There are two assembler files in this Github gist. The first one is the game itself; the second is the dictionary. If you are using KIMplement, they already encode a starting address in the file. If you are using another emulator or an actual real KIM, remove the initial .word pseudo-op so this isn't emitted to the output. Then,

xa -o kimdle kimdle.s
xa -o words words.s

If you're planning to load this into a real KIM, the simplest method is to then hexdump those files and key them in by hand. This is labourious but (with the relatively small length) not insane. If you have a serial connection, though, a better solution is paper tape and there are tools to do this conversion, or you can emit commands to the KIM's TTY (which is how I did it); words starts at $0003 and kimdle starts at $0200.

However, let's proceed assuming you're just playing with it in an emulator. If you do this in KIMplement, specify they are "KIMplement format" when loading them and the emulator will automatically use the encoded starting address. Otherwise, load words to $0003 and kimdle to $0200 (remember to assemble them without that leading .word pseudo-op). Once this is done, type 0200 g on the keypad (or, on the TTY emulator I linked above, press CTRL-G). The machine will appear to do nothing, but it's actually waiting for you to press GO (g/CTRL-G) again to seed its simple little RNG. Then the game will begin.

You get six guesses, as in regular Wordle. The display starts off 888880 (the eights represent "blanks" and the 0 means you are on your first guess). Enter letters with A-F, 0, 1 and 5. If you make an error, press GO to clear the line. When you enter five letters, KIMdle will keep the letters you got right in the right place, but will erase everything else back to "blanks," and the guess counter will advance.

If you hit guess 7, KIMdle will display the word. If you got it right, KIMdle will say you aCEd it, with your score. Press RS to reset and quit (on KIMplement, press the Commodore key twice), or any other keypad key to start a new game.

Yes, that's an actual picture of KIMdle playing on my Revision F KIM-1. I look forward to Wordle played in binary on the front panel of an IMSAI 8080. Someone should get on this. I can't be the only one this crazy.

Thursday, February 17, 2022

Refurb weekend: Texas Instruments Silent 700 Model 745 teletype

The first terminal I ever used was a teletype. Somehow my buddy when we were in high school got a hold of this weird "printer typewriter" which was none other than one of the famous Texas Instruments Silent 700 series.

For those of you unfamiliar with teletypes, which are more properly known as teleprinters, the concept is exactly like it sounds: they're terminal devices ("tele") that use paper ("type") instead of a screen. Everything you receive or type (though some models lack a keyboard and were receive-only) is dumped in hard copy. To the Teletype Corporation's everlasting chagrin the term "teletype" became genericized, much like Kleenex or Xerox, and the abbreviation "TTY" is a contraction which survives to this day as a terminal identifier in pretty much every Un*xy thing. While TTYs have been replaced as consoles by so-called "glass" terminals, or by client computers with serial ports, they are still used occasionally in the airline industry and as assistive devices in the form of TDD/TTYs. (Teletype Corporation, for its part, was absorbed into its parent — AT&T, by way of Western Electric — after AT&T was broken apart in 1982 and became "AT&T Teletype" before full dissolution in 1990.)

Unlike classic units such as the Teletype Model 33, probably best known today in its "automatic send and receive" variant as the Model 33 ASR or ASR-33, which were essentially automatic typewriters with noise, size and weight to match, the Silent 700 was indeed comparatively silent because it uses a thermal printhead instead of impact printing. It prints five pixel by seven pixel dot matrix characters in 80 character lines. Texas Instruments released the first Silent 700 models in 1971.

The initial generation of Silent 700s are shown above. By 1972 TI offered 14 separate configurations with varying feature sets. Among others, the Model 710 was the basic Keyboard Send-Receive "KSR" model, effectively a clone of the IBM 1051/1052 teletype; the Models 721, 722 and 731 were all receive-only devices; and the Model 725 was the deluxe luggable unit with a spiffy black hardcase and a built-in acoustic coupler.
Remember that this was the era of the Bell System where hooking up your own devices directly to a consumer telephone line was a no-no, so you just took your hotel phone handset, jammed it right into the microphone and speaker cups and manually dialed in. While this got around the Bell System's notorious anal-retentiveness, it also limited data rates to around 300 baud, though this was not much handicap at the time. However, the Model 720 was the one most of us would recognize as a "modern terminal" with a newfangled EIA RS-232B connector, ASCII support (as opposed to Baudot), and a riproaring speed of 30 characters per second. Some units like the Model 723 were parallel instead of serial. Lowercase was an optional addon, though as the printout above shows, on these units TI just used smaller versions of uppercase letters (now you know where the TI 99/4 got that from).
In 1973 TI simplified its product line, reducing it to the baseline Baudot Model 732 and US-ASCII Model 733 in two flavours: KSR, the traditional terminal, and a new ASR "Automatic Send-Receive" version, which bolted twin cassette decks to the unit for automatically sending and recording data (much more convenient than paper tape, and a 1975 Computerworld ad directly said so). The tape decks featured automatic search and duplication capabilities and each cassette stored 144,000 characters per side. Both KSRs and ASRs could be optionally equipped with the acoustic coupler which fit into the unoccupied space on the right side of the terminal. This second generation had a new keyboard as well with colour-coded keys as opposed to the uniform grey of the first generation models.

TI expanded the ASR further in 1974 into the Model 742 Programmable Data Terminal ("PDT") which could be programmed in a simple form entry language called TICOL. During data entry, the format is printed line-by-line and the operator fills in the blanks provided which the program can check for type, size or range, or perform simple calculations or comparisons. TICOL could also operate on data received from a remote site once it had been downloaded. The original Model 742 had 2K of RAM and offered TICOL I, which had 74 instructions; it was upgraded in 1976 to 4K of RAM and TICOL II with an additional 56 instructions. Programs were stored on tape and could automatically chain to the next module. An optional polling system could call out to remote 742s and pull data locally.

And, just to complete the product line, TI introduced a reengineered portable unit the same year for $2595 (about $13,560 in 2022 dollars). Not much smaller than the first generation units, the Model 735 was a trim 25 pounds, comfortably luggable by data entry specialists on anabolic steroids, or anyone whose medical plan included a free hernia truss. It came with the acoustic coupler and RS-232C connection standard and ran up to 300 baud. It could fit under airline seats of the time, but remember that you could fit a lot more under airline seats of the time than today. (Heck, I could probably have fit under one.)
The Model 735 must not have been too popular because TI replaced it in short order with a third-generation portable in 1975, the smaller, lighter (13 pound) and cheaper ($1995) Model 745. This was possible because of its 2MHz TMS 8080 microprocessor (a clone of the Intel 8080 TI produced to quickly get into the CPU market) and other, smaller chips replacing the bulkier discrete logic in earlier units. TI paired it with the Model 743 KSR, mostly the same unit, but with a different keyboard, ASR-33 current loop option, and optional modem to connect to a 110/300 baud Bell CDT-type DAA ("data access arrangement," used in those days as an isolating device from the phone line) instead of the 110/300 baud acoustic coupler. The Model 743 did not come with a case and despite being slightly smaller and even a couple pounds lighter was intended only for desktop use. Both the Model 743 and 745 could be equipped with different keyboards, including APL, ASCII and katakana (!), or no keyboard at all to turn them into receive-only devices. TI dropped the 742 PDT around this time, but kept the 733 ASR in the product catalogue along with a new Model 750 RO "receive-only" based on the 743 but in a different, even smaller form factor. Interestingly, parity was set permanently at the factory (even was standard, but odd and mark were BTO options).
My personal device, and the one I first used way back when (we have no idea where it went, sadly), is a Model 745. I picked this one up to play with but had yet to do a great deal with it.
The slim case with a nice padded grip (could even fit under today's airplane seats) clips onto the bottom panel with storage for the power cord in the top. Very thoughtful.
And here's the unit itself. It's a bit dirty and slightly yellowed, and there's a crack in the keyboard frame which was bugging me, but these were cosmetic. Since right now I'm busy inventorying and moving items into storage, however, I tested it out to see how well it was working. The unit powers up and responds to keys, though compared to a glass terminal the Silent 700 isn't all that silent due to the power supply hum (normal, per the service manual) and internal cooling fan.
Still, the electronics seem to work, but the print is very faint (on 8.5" thermal paper) and the printhead is clearly dirty. I think we'll want to give this unit a little TLC before finding it temporary storage. That means, after all that long wind up, it's time for ... a Refurb Weekend!
The 743/745 service manual is available from Bitsavers. Incredibly, the official process for cleaning the printhead is to soak bond paper in alcohol and print a few lines with it, so I dug out the 91% isopropanol and took a sheet out of the laser printer.
After a little trouble getting the wet paper to feed in (kept slipping), I banged out the invisible Great American Novel and blotted the platen dry, then refed back in the thermal paper.
Definitely cleaner now, but still faint.
While the service manual explains how the contrast can be adjusted, it only does so with the top case off. However, the contrast adjust is perfectly accessible from the side.
A flashlight shows the pot which can be manipulated with a jeweler's flathead screwdriver. I cranked it a bit to the right.
Excellent! Still, we'll have to take the top case off to get at the broken keyboard frame, so we undo the four flathead screws under the machine. One was a bit tough going and wouldn't come out of the case. We'll come back to this.
With the top case and the paper door off, we can see the paper feed mechanism and the keyboard.
The top half of the unit contains several very large capacitors and the cooling fan (not surprising, it can draw about 75 watts). Don't put your finger anywhere near this area if you have it plugged in and especially running: if you don't shock yourself on the electrolytics, you'll cut yourself on the blades.
The warning about the high voltage is hidden by the wires, but the 2A fuse rating should tip you off, and if it doesn't, those 200 microfarad capacitors certainly would. The acoustic coupler in the top case is connected by the grey wire and twin yellow wires on the right. Under those cables is the 15-pin EIA connector, which can be passively turned into a more typical DE-9 RS-232 connector. TI sold an official connection kit but I've got some modular connectors around here that will do just fine. The nearby jumper may need to be disconnected to enable this.
The broken frame just comes off by freeing its side clips, showing the top white connector wired to the mainboard, and the black retaining clips holding the keyboard in. There are three on the top and bottom, left, right and middle. The service manual says the keyboards can be swapped out by pushing the keyboard towards the rear until it is free of the front clips. This is actually quite difficult to do (and even harder to get back in) but I wanted to have a quick look at the electronics while I had it open.
The underside of the keyboard with obviously hand-routed traces (nice rounded arcs). The logic board is now exposed.
I blew a little dust out of here but the mainboard was well-preserved for all that. Oddly, this unit has an AMD 8080A (AM9080APC) CPU instead of the original TMS 8080, a drop-in replacement for the Intel 8080A, but we do see a TMS 5504 (TMS5504NL) I/O and timer chip. This device is one of the few public manifestations of Texas Instruments' TMS 5500 family which was supposed to be their first original 8-bit processor series. Instead, the product line got completely scotched to put resources into the TMS 9900 and beat Intel's new 16-bit 8086 design to market, which it did in 1976, but not without a lot of technical consternation (another story for another day). I'm not aware of the 5500 CPU ever being produced — let alone any shipping products that actually used one — but the presence of the 5504 suggests the Model 745 may have been initially designed around it. Both chips carry 1979 date codes, which probably explains why an AMD chip is here because Texas Instruments was likely not producing any more 8080s by that time. Nearby is the 4K ROM, a TMS 4732 (TMS4732NL) with a 1980 date code, and just below the 5504 is the TMS 4036 (TMS4036NL) 64x8 SRAM with a 1979 date code, providing a whopping 64 bytes of memory directly accessible to the CPU. A piezo beeper is at the far left. Earlier versions of the Model 745 had two 1K ROMs instead.
So, that weird screw. Turns out (I didn't do this) the metal crimped cap on the plastic tunnel for that screw snapped off. It took a little work to get it off the screw and back on the plastic, and it still doesn't align right, but at least the screw moves normally and no longer jams.
Cleaned and reassembled with the repaired keyboard frame back on. Another successful Refurb Weekend in the can!
As a postscript, TI introduced bubble memory and a larger keyboard to the line in 1977 with the Model 765 portable and Model 763 KSR, the first commercial products ever to have the famous storage medium. Bubble memory wasn't ever fast (in fact, the machine capped it at 2400 baud) but it didn't have to be for this application, and was non-volatile to boot, effectively making them smaller and shock-proof replacements for the older ASRs. The 763/765s were dramatically faster units that could accept serial rates from 110 baud to 9600 baud, though the Model 765's acoustic coupler was still 110/330 baud. A special "ASR mode" allowed them to record and playback keystrokes just like the old cassette system, but now entirely in solid-state. In these units the 8080 was demoted to servicing the keyboard and printer, and a TMS 9980 controller handled communications (via a TMS 9902) and bubble memory access, driving the 8080 over a 9600bps internal connection (the two CPUs did not share a bus and were otherwise independent). The bubble memory stored from 20,000 to 80,000 characters depending on configuration and could be edited as "files" in-place; the 763/765 could also accept operator commands typed on the console. However, as we've seen from the date codes, the older 743/745 units were still in production alongside.

Bubble memory didn't have a long lifespan as an industry storage fad, causing TI to replace the 760 series with the 780 series in 1980 alongside the new wide-carriage OMNI 800 family. Although technically descended from the 763/765, they were closer in architecture to the 743/745 in that the TMS 9980 was now entirely absent and the 8080 was once again the only CPU on board, which also made them cheaper. For the first time they also printed proper lowercase letters, though they lacked true descenders, and could print up to 140 characters a second. The Model 785 was the base portable model, with an integrated 1200 baud acoustic coupler; the 787 substituted a 1200 baud modem, while the 783 omitted either and served as the standard KSR. Although all of them printed "international character sets," only the Model 783 (and its receive-only descendent, the Model 781) had katakana support, and only Models 781 and 783 supported an additional 1000-character buffer. The OMNI came in the Model 820 and 825 KSRs along with receive-only Models 810, 820 RO and 825 RO.

The final generation of Silent 700s came out in 1983 and were newly based on an 8MHz TMS 7041 microcontroller, part of the 8-bit TMS 7700 family with integrated RAM, 4K ROM and onboard UART, thus jettisoning the older 8080-based architecture completely. The base unit was the new ultraportable 5.9-pound Model 707, which had a built-in 300 baud modem, cartridge expansion for built-in programs (including "auto access cartridges" with preprogrammed credentials for answerback), and a 132-column carriage on standard 8.5" paper using a compressed printhead. A lead-acid battery pack and external acoustic coupler were optional. The Model 703 was the spiritual KSR variant of the 707 with a 9600bps serial port instead of the internal modem; the 1985 703 RO and 707 RO were receive-only devices. The last Silent 700 was the 700/1200 BPS in 1987, which merged the 703's serial port with the 707's modem and upgraded it to 1200 baud. Sales advertisements for these final Silent 700s were seen as late as 1990.

Friday, February 4, 2022

Overbite Android 0.2.6

UPDATE: I've received a couple reports the .apk doesn't install. The actual reason is that the keys, and thus the author signature, have changed and Android doesn't let you replace an app with another app signed by "someone else." Delete the old version and install this one fresh rather than installing it over the old one. Sorry about the inconvenience.

Overbite Android 0.2.6 is available, the (persistently alpha-quality) native Gopher client for Android. This is merely a maintenance update for version 0.2.5 to fix visual issues with dark mode and Android 12, and a couple edge crashes. The screenshot is from my Pixel 6 Pro (the camera still crashes on it, Google, damn your eyes) running Android 12 but this release will still work with and is tested all the way back to 4.0.3 (Ice Cream Sandwich). After all, this is a retrocomputing blog! Source code for Android Studio (built with Bumblebee) is available under the BSD license.

Unfortunately, it is likely that 0.2.x will be the last release of Overbite Android to support OS versions prior to 9.0 (Pie). This is because right now I'm running Android Studio on an M1 Mac (hoping to get it working properly on my Talos II, but not there yet) and it is apparently not possible to run API 27 or earlier under the emulator. (I tried myself and it just dies immediately. There should be a way to make it run within a full system emulator, but it doesn't.) For testing purposes I dug out an Intel MacBook Air with a previous version of Android Studio, booted up a emulated Galaxy Nexus with 4.0.3 and checked the APK installs and runs, but this is rather inconvenient to test with for obvious reasons, and Google doesn't make it easy for you to keep working with old Android versions if you're trying to also support new ones. For the time being, though, I still think supporting a 10+ year old release of a mobile operating system is pretty darn good, and if I do any other 0.2.x bugfixes I will at least test them to the extent I can on Android 4 before release.

Yes, I know Overbite Android still doesn't do downloads yet. This is largely laziness on my part, since I'm only scratching the itches I personally have, and I haven't needed to download files via Gopher to any of my Android devices so far. But that's probably the major feature I plan to introduce in 0.3 when I get some time to sit down and actually write the support.

Old releases compatible back to Android 1.5 (Cupcake) are still available, including source code.