Hacking Night Knight on the Spectrum Next

February 20, 2024 6 min read
Hacking Night Knight on the Spectrum Next

One of the awesome things about getting my hands on a Spectrum Next was being able to introduce it to my kids. Given that they are somewhat spoiled by "modern" creations, I needed to find something simple, yet fiendishly addictive for them to play. Night Knight was the obvious solution:

The game itself is beautiful in its simplicity. All you need to do is walk around turning the blue floor tiles a nice golden yellow colour whilst avoiding skeletons (and later archers and some sort of demon thing). It has only three controls - left, right and jump. Perfect for first time Spectrum users!

Except for one small issue - you see this screen a lot:

And when I say a lot, I do mean a lot. You get three lives and 60 seconds for each level, and that's really not a lot of lives or a lot of time. As infuriating as this is for an adult, it's soul destroying for a seven year old (the teenager simply refused to engage after a certain point).

So I did what anyone would do - I hacked the game so that we stood a chance of winning!

Hacking the game

The nice thing about computers such as the Spectrum Next is that they come batteries included when it comes to development tools. It's a simple task to see what code is running and to see the current contents of memory.

The tools are pretty basic though, and one of the features that I really missed (and would have saved me a lot of time) was the ability to progressively search memory. This is where you take a value (such as the number of lives remaining) and search memory for it. There will be a lot of hits (possibly even thousands). You then give a skeleton a big hug, and your remaining lives drops from 3 to 2. Now you search all the memory locations that previously held 3 and see which ones have changed to 2. Often this will isolate the memory location on the first try, but if you still get a couple of hits, then you repeat the process until you've been able to isolate the memory location of the number of lives.

Unfortunately I wasn't able to find a way to do this (could well be me) and I did it interactively in front of the TV, so really not the world's greatest dev experience. It was however a lot of fun...

So then, on to hacking the game. Without being able to search progressively, just searching for individual instances of 0x03 and 0x02 in memory was just not going to cut it. What was needed was a more unique value that would be less likely to keep cropping up.

A good option for this is the high score value. Basically you play the game until you have a nice high score and then you search in memory to find it. Let's give that a go here with my high score of 1000. Here's how you do it:

  1. Press the yellow NMI (Non Maskable Interrupt) button on the left hand side of the Spectrum

  2. Using the cursor keys select Debug Tools:

  3. Then select Memory Browser:

  4. This should now show you the contents of memory:

  5. Now, we want to search (Find) the memory contents of 1000. To do that, press F, then press H for Hex value. Now we need to convert 1000 in decimal into hex which is 0xe803. Punch that in and hit ENTER:

  6. You can check you've got the right location by trying to search for the Next one. If you could only find that value in one place, you can be almost certain that you've found the right spot. In my case, it turns up in two places, but I know this is the right one because I found it previously - it's just through the capture card the game is unplayable (badly lagged) so I can't get a half decent high score.

  7. We can be absolutely sure that we've got the right spot by changing the value. It doesn't matter what to, we just want to know we've found the right place. To do this press the EDIT button, and punch in 99 99 and press ENTER.

  8. Now we can exit and go back into the game by pressing BREAK three times. You'll see that the high score hasn't changed. That's because the code that redraws that part of the display hasn't been called yet, so it will still display the old value. Starting the game again will cause the Spectrum to redraw the display, and now you should have a very different high score:

  9. Now, that's all well and good, and you might be wondering why we want to play around with this value. After all, it doesn't make the game any easier and if anything, it just makes beating the score impossible. But there is a reason to this madness - most applications when they initialise themselves tend to put related values (such as the game state) in the same place. This means that if the high score is stored in this area, maybe the lives are as well!

  10. So lets jump back into the memory browser and go to the high score entry, which we can do with Address and entering the memory location 9D8D

  11. Currently we have three lives, so let's look around for the value 03 00. There are a few on that page, but the one that I saw first was at address 9DA2. Let's try changing that and see what happens. Let's try setting it to 9 (so 09 00). Again we can use the EDIT key to enter edit mode and press ENTER to complete the change. We can then press BREAK three times to get back into the game.

  12. Now initially it looks as though nothing has changed, but remember, the display only updates when something happens.

  13. Let's see what happens after we give a skeleton a hug...

  14. You can see that we now have 8 lives remaining - which makes sense because we just lost a life causing the screen to refresh.

Wrapping up

So now you can give yourself effectively unlimited lives! You can do something similar with the amount of time available, but I'll leave that as an exercise for the reader...

It's actually worth noting that despite my efforts, my seven year old refused to use my "trainer" and insisted on doing it with just the standard three lives. It took him a while, but ultimately he was the first (and so far only) person in the family to complete the demo. All credit to him and well deserved!

spectrum nexthacking
Peter Membrey
Written By Peter Membrey

Peter Membrey is a Chartered Fellow of the British Computer Society, a Chartered IT Professional and a Chartered Engineer. He has a doctorate in engineering and a masters degree in IT specialising in Information Security. He's co-authored over a dozen books and a number of research papers on a variety of topics. These days he is focusing his efforts on creating a more private Internet, raising awareness of STEM and helping people to reach their potential in the field.

Read next