lostcarpark: (Lego Spaceman)
lostcarpark ([personal profile] lostcarpark) wrote2012-12-30 03:37 am

The PiQL Project

I've posted about this on Facebook, but the trouble with FB messages is they tend to get lost in the clutter, so LJ seems to be a more suitable home for these posts.

Like many of my generation, I have been, and remain, a fan of the 8-bit microcomputers of the 1980s. They were small, cheap, and easy to use. Most importantly, when you switched them on, you were immediately faced with a programming language (usually BASIC). These computers helped to breed a generation of computer programmers. When I went to university, a significant proportion of my class had some previous programming knowledge. Today, by contrast, a higher proportion of college students may be computer literate, but I think the proportion who start a computer science course already knowing a programming language is much lower.

There is, however, once beacon of hope... the Raspberry Pi. It is dirt cheap ($25 for the basic model, or $35 for the more advanced one), and a great introduction to programming (even if that programming is in Python, a language I have no great fondness for). The only downside is that unlike the old '80s micros, it has no case or keyboard. If only we could find a way to combine the two.

This is where the idea struck me: take a 1980s computer, and replace the internals with the tiny Raspberry Pi circuit board. A little Googling shows it's not a terribly original idea. Several people have done it for the Commodore 64 and the Sinclair ZX Spectrum. But I bet nobody has done it for the Sinclair QL.

I'm sure only a handful of people remember the QL. After the success of the ZX Spectrum, Sinclair attempted to move into the business market. It was a brilliant concept, but flawed in a number of ways, and after a string of delays, it was a commercial flop. However, it included a number of innovations that influenced many later computers, and it still has a significant fan base.

Most importantly, it was, in my opinion, one of the most elegant computers of its era. Here's a photo:

Sinclair QL Case

The first step was to get hold of a QL case. One thing I wasn't prepared to do is destroy a working QL, since there won't be any more of them. So I needed to find either a non-working one, or an empty case. There was only one place to look: eBay. QLs don't come up very often, and broken ones even less so, so after six months of waiting and following links to old QL software packages, a QL case came up for auction. There doesn't seem to be a lot of demand, as I ended up getting it for £3.99 (I was willing to go significantly higher - I won't tell you what the maximum bid I'd put on it was).

Of course, there's more to this project than just slapping a Pi inside an old case. The defining characteristic of 1980s machines was the way everything was self contained. You didn't have a separate keyboard and computer case. The project will be pretty pointless if I can't make the QL keyboard control the Pi. And I'm afraid this won't be as simple as plugging in a USB cable. The QL was connected to its keybaord by two ribbon cables, one with 11 wires, and the other with nine. Pressing a key shorts the connections between a wire from each cable, so the computer knows which key has been pressed.

Fortunately, this is pretty much the same way modern keyboards work. The only difference is there is a circuit in the keyboard that detects which key has been pressed and converts it into a keycode that gets sent down the USB cable.

Three solutions present themselves:

1. The Pi has a number of general purpose IO pins that can be connected to external hardware and accessed by software on the Pi. This solution would be attractive, as it doesn't require any extra hardware, but it would mean writing a custom keyboard driver. I would like to be able to run multiple OSs, so a custom driver would be needed for each one.

2. Since the keyboard works more or less the same way as a modern one, why not use the controller circuit from a modern USB keyboard? This would then be connected to one of the Pi's USB prots inside the case. The key mappings would be different, so we'd need some custom key mappings, but this shouldn't be too great a problem.

3. There's a cheap USB development board called the Teensy. It offers plenty of IO ports and could easily handle the QL keyboard, and there is sample code available for making it behave like a standard USB PC keyboard. This has the advantage that all the mappings for the QL key layout could be handled before the keycode gets sent to the Pi, so no mappings would be needed. At $16-$19 depending on model, it's also a cheap option. Another advantage of this is that it could take control of the LEDs on the front of the case.

I'm still looking into which of these is the best approach, but the third seems the most elegant and is looking attractive.

Once I get the keyboard working, the only other difficulty will be to connect all the ports to the QL case. I would like to use the original port locations on the case as far as possible, and hopefully avoid cutting any new holes if I can.

First, the right side of the QL case held two microdrives. Although it might be useful for one-off conversions of QL software or data, I don't hold much hope of getting a Pi to read microdrives, so I intend to put SD card readers in the microdrive slots.

At the back of the case is the following:

Two ports for networking. The QL used an odd form of networking that daisy chained QLs using 3.5mm jacks. Fortunately the hole is big enough that one of these should accommodate an RJ45 cable. The other I might make an audio out, as the QL only had an internal speaker, no headphone or mic sockets.

The next socket is power. The Pi takes it's power from a USB socket. However, I plan to have a powered USB hub, so I need a power supply for both of those. I'm debating whether to put the transformer inside the case.

The next sockets are RGB and UHF for monitor and/or TV output. The Pi has two video outputs, a HDMI and a composite video, so these will be routed to these ports.

The next ports are SER1, SER2, CTL1 and CTL2, which were for serial devices and joystick ports, though oddly they all used UK style phone sockets. These will all become USB ports.

The final port at the back is for ROM cartridges. I'm thinking this should be connected to the Pi's internal SD card slot, allowing easy change of OS by swapping SD cards.

It should be interesting to run a QL emulator on the Pi. Even emulating a 68K, the Pi should be many times faster than the original QL.

This is all rather conceptual at the moment. The first step is to solve the keyboard problem. Should be interesting!

[identity profile] peadarog.livejournal.com 2012-12-30 04:10 pm (UTC)(link)
That's a cool project, James! Best of luck with it.

[identity profile] surliminal.livejournal.com 2012-12-31 12:19 am (UTC)(link)
Jeez I had to use a QL on loan from my Uni to (try to) programme in Pascal on it for a year. Elegantis not the word I would have used tho the may have been more about the micro cassette set than he keyboard.. I was EXTREMELY glad to move n to a PC.

[identity profile] lostcarpark.livejournal.com 2013-01-04 09:32 am (UTC)(link)
I know what you mean - the microdrive was one of the reasons the QL didn't take off. I had a disk drive add-on for mine, which made a huge difference. I plan to house SD card readers in the microdrive slots. However, by "elegant", I was referring to the sleek case design and sculpted shape of the keys, rather than anything to do with how the computer operated.