Blog - 0x00


Old Computer Challenge - TC 2048 (1984) (ZX Spectrum 48K clone)

2024/08/02

Table of contents


#

I recently read about Old Computer Challenge (OCC), I thought It’d be a fun challenge to take. Here is a little description from their about page:

Old Computer Challenge community is a smol group of enthusiasts, who like to use old computer hardware and every year come together to challenge themselves in spending a single week in July exclusively with machines many would consider outdated.

In this years challenge it was a DIY, you could create your own OCC challenge. This was perfect for me because a few weeks ago my dad and I were able to power on his really old computer, a Timex Computer 2048 (1984) and I had the idea of writing modern software in Sinclair BASIC for this old hardware.

This blog is about the journey I took for the challenge.

Hardware #

As I previously mentioned, my idea was to write modern software for the Timex Computer 2048, which is a home computer from 1984. Mind you this computer has 48kB of memory, a Zilog Z80A @ 3.50 MHz CPU and no storage. If you wanted to store/load programs you’d need a cassette player and cassette tapes otherwise if you reset the computer you lose the program that you were writing. My dad also had the cassette player he used to load and save programs but sadly it wasn’t working, so there was no way for me to store or load the programs I wrote.

Timex Computer 2048

The keyboard #

So as you might see from the image above, although it’s a QWERTY keyboard it has several missing keys from the usual modern keyboard, such as the backspace, tab, caps lock, ctrl and alt keys. Also the key themselves on top of having the letter/number, they have 2 rows of words and symbols (one with black background) and outside of each key, above and below they have words and symbols too. Well, all of this wording HAS TO be accessed by the modifier keys, “SYMBL SHIFT” (black key) and “CAPS SHIFT”.

Lets say you want to write PRINT then you’d simply press the key “P”, and PRINT would appear on the screen, there is no way for you to type manually the keyword so if you are not used to (most likely you won’t be) type in this keyboard, you’ll spend a lot of time trying to find the right key with the keyword you are looking for, specially when each key have around 4 keywords/symbols you can choose from.

Lets play a little game, can you find the keyword INT and then THEN? Once you find them remember the key combination to access the keywords in those places :). Fun isn’t?

The keyboard quality is not the best either, I believe its some sort of membrane keyboard that maybe it uses rubber. Pressing keys is definitely not reliable, specially the spacebar where you have to not only press hard but make sure to press in the middle of the spacebar, anywhere else and it won’t register, also you can’t type too fast as it won’t register either. And you can’t just connect any keyboard, not at least with some custom hardware and software, it doesn’t have any USB or PS/2 port so using an external keyboard isn’t an option either.

Challenge #

For a while I wanted to write a modern program. I thought of something, probably ambitious, which was writing SHA256 algorithm in Sinclair BASIC (inspired by this “shallenge”). But when I started reading more about the implementation and the capabilities of BASIC I realized it was going to be way too complex for me. It was likely possible by using assembly but I wanted to use BASIC. So I had to think of another program to port to the TC 2048.

That’s when I decided to implement cowsay in Sinclair BASIC. It was a “modern” program that could easily be ported to the TC 2048 and be written in BASIC. I did find someone that ran cowsay for the ZX Spectrum Next which is a computer released on 2017 that is compatible with the older ZX Spectrum from 1982, though what I wanted to do was something different. What retrobits did was to take cowsay written in C, cross-compile it for the ZX Spectrum and ran it in an emulator. I’m planning to write it in plain Sinclair BASIC and running it on the actual hardware.

Developing #

I had already played around a bit with the TC 2048. I knew that the keyboard and typing was horrible, not only because of what I mentioned earlier but because every line of code requires to start with a line number because it doesn’t have any sort of text editor, so the number of the line determines where the line goes.

The ZX Spectrum BASIC programming manual says its a good practice to leave gaps between numbers which is why programs would usually start with line 10 and then line 20 and so on. So if you wanted to add a line of code ine between the instructions you could simply use any number between 10 and 20. Here is an example of a simple program:

10 LET a=10
15 LET b=15
20 PRINT a+b

The 8-Bit Guy has a good video (Youtube link) that goes more into depth about BASIC if you want to know a bit more.

Software #

Becuase the keyboard is bad and line numbers being annoying using, the actual hardware wasn’t an option. I looked on the internet for ways to write and run Sinclair BASIC with modern hardware so I could use a modern text editor with MY keyboard, what I found was a lot of dead links, dead domains and parked domains. Specially a lot of old freeware *shivers* incompatible with modern operating systems. (Mostly on World of Spectrum)

At first I couldn’t find any interpreter or compiler for Sinclair BASIC so my first approach to developing was using an emulator such as Fuse so I could just run it in my modern computer, which was fine except for the fact that it was such a good emulator that of course I couldn’t just manually type PRINT and emulated the keyboard too. I kept looking for different tools and then I found ZX Coder*, a website that emulates a ZX Spectrum and allows you to develop programs in Sinclair BASIC in the browser and run them easily. This is what I mainly used to develop cowsay.

As I was starting to program I realized I didn’t know much about BASIC and dealing with learning BASIC while also trying to figure out the logic for the program was going to be a bit hard, so instead I first wrote a cowsay implementation in Python as its a language I’m much more comfortable working with and from there try to implement it in Sinclair BASIC.

Here is the repository https://gitlab.com/0x00cl/basic-cowsay (cowsay.bas contains the Sinclair BASIC program)

* A note about ZX Coder is that printing “\” requires you to escape it so if you want to see it on the output you have to write “\\” while on Fuse (emulator) and TC 2048 you don’t need to escape it.

Running #

Once I had it working in ZX Coder I was ready to run it on an emulator and the actual hardware but I had a problem, how do I transfer the source code to them? I didn’t want to type it manually as it would be pain and take too much time and of course the idea is that others could also transfer the program without having to type it manually. In the sections below is how I got it running and transferred to the emulator and TC 2048.

Fuse (emulator) #

Fuse as an emulator has many options and ways to load programs, once of the options is reading/writing .tap files which are “tape” files. And this can be shared to load programs into different emulators, not only Fuse. But how do I turn my .bas file into a .tap file? There is an utility called bas2tap that converts a .bas file into a .tap file and so thats what I used to create the .tap file in the repository. I loaded the .tap file, tested it and worked perfectly. Here is the output:

Cowsay running in Fuse (ZX Spectrum emulator)

Running on the TC 2048 #

After being able to run on the emulator I wanted to run it on the actual hardware but there was a problem, the TC 2048 is so old that any connection it has was way too old for anything that I had. I couldn’t just load a .tap file or just any file, the ways to load programs was using the casette player and actually playing the casette to load it into the TC 2048, but trying to do it that way would be getting into a rabbit hole of converters. So while I was watching videos about the ZX Spectrum on how loading programs worked, one video showed that you could load programs using the cassette connection, which is basically a mono jack that can be connected with an aux cable, and transforming the program into a .wav file and playing with any audio/music player such as a phone. Once again I looked for a program that transformed tap to wav files and found this repository tap2wav.

I converted the .tap file into a .wav file, loaded it on my phone. Played it with a music player and loaded it into the TC 2048 (LOAD "") and it worked!

Cowsay running in the Timex Computer 2048

Conclusion #

It was fun learning more about retro computing and getting the program to load on such old hardware using a modern phone. It was not fun trying to find software such as the converters, interpreters, emulators, etc as many either had dead links, were freeware or simply .exe files (totally not a virus ;)) that wouldn’t work as they were written for older operating systems.

The keyboard as bad as it is, I did try typing the program manually and at some point I did get used to it and knew were the keywords were and got a little faster to type, still I wouldn’t want to develop anything with it, but now that I have a workflow (Using ZX Coder and converting .bas to .tap to load them into an emulator) developing might be easier.

In the future I might try a more ambitious project as this was my first time developing using Sinclair BASIC and the TC 2048.

I’m looking forward for next year OCC.