Applying the BBC Master's flicker-free algorithm to the other versions
Once you've seen the smoother animation and flicker-free ships in BBC Master and Apple II Elite, it does tend to make the older versions look a little less sophisticated. Luckily, the changes that Bell and Braben made for these versions don't require any fancy hardware or more memory; instead, it's all down to an improved ship-drawing algorithm, as explained in the deep dive on flicker-free ship drawing (which you probably want to read before exploring the code below).
This means it's relatively straightforward to backport these changes into all the other versions of Acornsoft Elite, even the Acorn Electron version and Angus Duggan's Elite-A. You can play the flicker-free versions via the releases page, either in a browser or on real hardware; it's interesting to see the differences on-screen. I have also backported the algorithm to the Commodore 64 version; see the GitHub repository for flicker-free Elite on the Commodore 64 for details.
There are three steps to the backporting process:
- Free up enough memory for the flicker-free code
- Copy the LSPUT line-drawing routine from the Master
- Update the SHPPT and LL9 routines to support the flicker-free algorithm
Interestingly, this backporting process is identical for all the original versions of Elite (i.e. cassette, disc, Electron, 6502 Second Processor and Elite-A). The only difference is that in some cases, we have to move routines around to prevent the extra code from breaking branch instructions that would otherwise have to reach too far. The code changes themselves are the same, as they all share the same SHPPT and LL9 routines.
This is true even for the 6502 Second Processor version, which normally uses a line-queueing system when drawing ships, but we can replace this with the same flicker-free code as the other versions because the flicker-free algorithm draws lines by calling LL30, and this routine still draws a line, even on the Second Processor version, so dropping in the new algorithm just works.
Let's look at these three steps in turn. To be specific, let's look at backporting the flicker-free algorithm to the BBC Micro cassette version. To see the code differences for the other versions, you can check out the flicker-free branches in the accompanying repositories, but the updated routines in all versions are essentially the same as in the code below.
1. Finding enough memory
Altogether, the flicker-free changes only require a small number of extra bytes compared to the original versions - in the BBC Micro cassette version, for example, we only need to find eight more bytes. That said, memory usage is famously tight in Elite, so this is easier said than done.
Luckily, all the versions of Elite that have serious memory constraints also contain an unused routine that the authors forgot to remove - it's a duplicate of MULTU that is never called. Removing this routine (or just commenting out the required number of instructions) easily gives us the space we need, even in Elite-A, where only half of the duplicate routine is left in the flight code for us to remove.
So, step 1 is to comment out a big enough chunk of this routine. Simple.
2. Copying over LSPUT
As part of the new algorithm in the Master, there's an extra routine called LSPUT, which draws a line, adding the line to the ship line heap (potentially replacing one of the lines already there), and then erasing the line that we just replaced. We need to port this over for the flicker-free code to call, which we can do by simply copying LSPUT directly from the Master, and inserting it after the last stage of the LL9 routine.
So, step 2 is to copy LSPUT from the Master and into the version we are updating. Easy.
3. Updating SHPPT and LL9
The SHPPT routine draws ships as points for when they are far away, and the LL9 routine draws them as wireframes when they are closer. As the final step of backporting the new algorithm, we need to update both of these routines so that instead of erasing the whole ship before redrawing the whole ship again, they instead use the new LSPUT routine to draw and erase ships one line at a time.
Below you can see every single code change that we need to make to convert the BBC Micro cassette version to the flicker-free algorithm (specifically, the changes are in SHPPT and parts 1, 9, 10, 11 and 12 of LL9).
So, step 3 is to make the changes below... and then we're done.
Exploring the code below
To explore the code changes below, simply click a routine header to expand it, and click it again to shrink it back. Within the code that appears, the original and flicker-free code are shown side-by-side. You can tap one side to expand it, and tap it again to go back to showing both sides. Each side is sideways scrollable, so you can read the comments on small screens.
It might look like a lot of code, but that's because I've included all the routines in full, so you can see the differences in situ. There are surprisingly few differences between the two versions (especially when you realise that parts 2 to 8 of LL9 are completely unchanged). This is a delightfully simple change that makes a very noticeable improvement to the graphics, and without perceivable loss. That's well worth the effort of backporting, I'd say.
Name: SHPPT Type: Subroutine Category: Drawing ships Summary: Draw a distant ship as a point rather than a full wireframe
Name: LL9 (Part 1 of 12) Type: Subroutine Category: Drawing ships Summary: Draw ship: Check if ship is exploding, check if ship is in front