Highlighting and tape loading PC-1500 BASIC programs on the web
Friday, 9th May 2025
I don't think I've had a proper dose of "man-flu" since COVID and I haven't missed it at all. This journal entry has been written in a state of sleep deprivation whilst being tanked up on Lucozade and Lemsip (expiry date: March 2020) so hopefully it still makes some degree of sense.
In my current state the most obvious project is to subject myself to the banshee howls of tape loading. I've implemented some degree of tape loading support to my site before by taking tokenised BBC BASIC programs and running them through a web service that converts them to UEF files that can be played back in the browser with PlayUEF, and with my recent interest in the Sharp PC-1500 it would seem like a sensible idea to do something similar for that computer.
Unfortunately, whilst PlayUEF is a superb piece of software for loading Acorn software, it is less ideal for the Sharp PC-1500. This isn't a limitation of the UEF format itself, it's just that Sharp PC-1500 programs are stored at a different base frequency (1270Hz instead of 1200Hz), use a 0° phase instead of 180° phase, and repeat the wave patterns for 0 bits and 1 bits four times longer than the BBC Micro format ("300 baud" mode instead of "1200 baud" mode). None of those features were supported by PlayUEF, however it is open source software so I hacked them into my own fork of the project.
Note that I do say "hacked", as PlayUEF does take some shortcuts when generating the resulting waveform that I found a bit awkward to work around. For example, it needs to allocate a buffer to write the wave file to and so needs to know the number of samples in the resulting wave file to do so. It normally does this by multiplying the number of wave cycles in the file by the number of samples per cycle, but that only works if the number of samples per cycle remains constant through the file (which they won't if we're changing the frequency on the fly) and the number of cycles per bit also needs to remain consistent (which it won't if we're outputting four times as many wave cycles for the Sharp PC-1500 when compared to BBC Micro).
In the end I worked around this with a two-pass solution: the first time around a zero-byte buffer is allocated and written to (which appears to work?) and the final length is calculated by adding up the total number of samples. The second time around the buffer is allocated the total number of samples it requires.
Whilst this works and the end result loads fine onto an actual Sharp PC-1500, the code is now a bit of a mess and there are a lot of nifty visualisations and "fast loading" tricks that only make sense to the BBC Micro but are still baked into PlayUEF. For my own use I might make a less sexy alternative to PlayUEF that just converts a UEF to a wave for loading via the web. However, for now it works as-is.
To support all this I also needed way to tokenise (and detokenise) Sharp PC-1500 BASIC programs and convert the resulting binary into a UEF tape image. To do this I've knocked together a couple of PHP classes, sharp_pc1500_basic and sharp_pc1500_tape that do the work and these files can be downloaded in sharp-pc-1500-php.zip.
Here are some examples of how this works (click the "Load file as tape image" to hear the beautiful sounds):