Monday, December 28, 2015

Sharp OZ/ZQ 7xx organizer code

Back when I was a grad student, my dad gave me a Sharp OZ 730 organizer. It had a Z80 processor, and could (slowly) run BASIC programs. Some folks figured out how to run assembly code on it, and then I figured out how to target it with C code, and I wrote most of a library, designed a file system that hid in hidden recesses of the device, prepared an SDK and wrote or co-wrote a bunch of apps: games, a serial terminal emulator, a function grapher (it's really nice and polished, as I just discovered on trying it out after many years), an ebook reader, a Greek New Testament, some utilities. I got a couple more Sharp organizers, as a guy from Sharp UK liked what I was doing. (I think he liked that one could hook up the device to a modem and use the terminal emulator to check email.) Eventually, the unit got discontinued.

Recently, I've been digging out my code archives. They're mostly now on github, though perhaps not always the latest version. The code is a messy mix of Z80 assembly and C. The SDK worked by launching a CP/M emulator, running the Hi-Tech C compiler in the emulator, and then running a peephole optimizer. With limited memory and CPU power, one had to do a lot of optimization. I remember looking carefully at the code-cycle charts for the assembly, and then doing nasty little things like storing variables inside self-modifying code (instead of allocating two bytes for a global variable and then accessing it with, say, ld bc,(address), the first time the variable is accessed, I can do ld bc,value and store the variable right inside the immediate value), and implementing some of these in the peephole optimizer.

My big kids have one organizer unit each, so a couple of weeks I ordered a $2 USB-serial adapter from banggood. It came today and I can once again transfer the apps to the device (the hard drive on the computer I used to use for development of this stuff failed, and my laptops don't have a serial port). Sharp still has the downloader software here (I run it on Win 8 x64 in Win98+Admin compatibility mode). I even put a ZMachine emulator (not written by me) on my son's so he can play Zork (purchased from GOG).

No comments: