I’ve been looking for a decent project to get my teeth into on the Spectrum Next. Apart from my Next Z80 library routines, I’ve dabbled with a few demos, and considered writing a drawing package similar to Deluxe Paint. But on the whole have felt rather unenthusiastic about starting that project.
Last week inspiration hit me. I’ve already started porting the Z80 version of BBC Basic (by R.T.Russell) to my homebrew Z80 computer, the BSX. Why not port it to the Next?
Why BBC Basic?
BBC Basic is, in my honest opinion, a best-in-class BASIC interpreter. The original, written by Sophie Wilson, is fast, even on a 2Mhz BBC Micro, feels modern, and has a built-in 6502 assembler.
The Z80 version of BBC Basic was written by R.T.Russell. It picks up the mantle and provides equivalent levels of functionality and performance. And yes, it has a built-in Z80 assembler.
Whilst I love Sinclair BASIC, I feel that BBC Basic addresses many of its shortcomings, including the clunky editor, variable name limitations for strings and arrays, and performance.
“Ah”, I hear you say. “I can load a BBC Micro Core in my Next to run BBC Basic”. Yes of course you can do that, and it is an excellent core. You will of course be restricted to BBC Model B hardware in doing so.
The advantage of running BBC Basic native on the Next is that it can potentially take advantage of the Next’s advanced graphics and sound capabilities; hardware sprites, Layer 2 graphics, multiple AY chips, and of course the legendary 28Mhz Turbo mode.
The main challenges I forsee are:
- Time: I work full time, so will only be able to spend the odd hour here and there on this project
- Memory: BBC Basic and MOS occupy 32K of ROM. Ideally I need to fit this into 16K ROM banks
To put this into some context, the open source version of BBC Basic is for CP/M only – with no support for graphics and sound, and for the BSX version I’ve gone further and stripped out the CP/M support.
To create a minimally viable product, I’ll need to add graphics, sound, and file I/O support. And to match the richness of Next BASIC I’ll also need to add some Next-specific commands.
It’s a cool way to learn how to code the Next, and I can re-use some of the code, and much of the overall structure as I continue to port BBC Basic to my homebrew computer. I’ve also written a few library routines for the Next that I can re-use.
It is also a good project to nibble away at. Adding extra features often involves no more than a couple of pages of Z80, and there will always be a functional version I can run.
The state of play
Thankfully, as I’d already done a lot of the legwork porting this to the BSX, and have already set up my Spectrum Next toolchain, there was very little that needed to be done to get the core of BBC BASIC for Z80 up and running on the Next. I think it took me an afternoon to get it to compile, accept keyboard input, and run a BASIC program.
The project has got off to a good start, with the following features:
- Input: Interrupt driven keyboard scanning routine
- Text output
- Hardware text scrolling
- MODE, CLS, CLG, GCOL and COLOUR commands
- PLOT (single point to ULA and Layer 2)
- Vertical sync command (*FX 19)
- Next Turbo CPU speed command (*RUN)
- Debugging: A memory dump command (*MEMDUMP)
- Next Specific:
- Extended BASIC PUT and GET commands to read NEXTREG registers
I’m currently working on a memory map so that I can start to use memory paging, and am looking at getting some basic file I/O up and running. Just getting the “*.” command working would be a win at this point.
In addition, I’m trying to work out the best way to integrate the graphics modes into BASIC. The most obvious solution is to use MODE to switch between ULA and Layer 2 graphics, and support several discrete graphics modes.
The latest build is available here in my github account; this code is distributed under the terms of a zlib license as requested by R.T.Russell.
And as ever, I’ll be posting regular updates on Twitter as @breakintoprogram.