A hand-holding exercise – the Nintendo DS

I’ve always been a fan of Nintendo’s portable game devices, from the early Game and Watch units to the various editions of the Game Boy. Dr Mario on the original Game Boy is still one of my favourite games to this day. I’d go as far as saying it’s better than Tetris – I once played it for so long that when I went to sleep and closed my eyes I could still see small pills falling downwards.

I’d already helped Nintendo along by getting a Game Boy Color and Game Boy Advance (which I picked up on a holiday in Japan), so when the chunky metallic blue Nintendo DS came on sale I got one. The launch titles weren’t too bad and showed what the touch screen brought to the party. I initially thought the dual screens and stylus were seen just gimmicks but they did bring some genuine innovation to handheld games.

Gameboy Color, Gameboy Advance, Nintendo DS and Nintendo DS Lite.
A family reunion.

I’d obtained flash cartridges for the DS’s ancestors. These let you put multiple dumps of ROM images on one cartridge – so you only needed one cartridge and didn’t have to carry all your games around with you. Apart from software piracy, they unlocked the world of home brew on these devices. The Game Boy Color and Game Boy Advance had a surprising amount of home brew software- I had versions of Jet Set Willy and Jet Pac for the Game Boy Color and a full Spectrum emulator for the Game Boy Advance. Outside of doing proper development work for Nintendo and having access to the official developer kits and hardware, flashcards were the only way for home brew developers to get their code running on the Game Boy and Game Boy Advance.

Jet Set Willy on the Gameboy Color.
Who needs a Vega Plus?

The first DS flash card I got was called the GBA Movie Player. This fitted into the DS’s GBA cartridge slot (Slot 2). It had to go here as it was too large to fit inside the native DS cartridge slot (Slot 1). The card had a full sized SD card slot which you could copy files on to. Nintendo had also implemented some security on the DS where you could only run code from Slot 1 if the correct RSA security signature was present. All legitimate DS cartridges had this signature so they could run on the device.

To get round this, a second device called a Passkey had to be fitted into Slot 1, alongside with an actual DS game. The passkey then used the signature from the real game to get the code running from the Slot 2 device. While this worked, it wasn’t an ideal solution as the DS would no longer lay flat on a surface as the Passkey and donor game hung out of Slot 1. The situation would eventually be improved by the continual shrinking of flash memory technology. SD cards were superseded by Micro SD cards. The size of these cards easily fit inside the Slot 1 cartridge form factor.

One Slot 1 flashcard went on to become the standard, the google or photoshop if you will – the R4. I bought an original one from a computer fair for £30 pounds. As befitting for a device that enables piracy, the R4 was copied and cloned and various knock off versions flooded the market. The R4 removed the need for a Slot 2 device and also did away with the need for the Passkey.

Nintendo DS flashcards.
The inevitable march of technology.

The R4 flashcard made piracy a lot easier on the device. I remember the guy who sold it to me at the computer fair telling me I could fill the Micro SD card with games and his genuine surprise when I told him that you could also run home brew titles like Lemmings DS or emulators on it too. Subsequent versions of the DS hardware and some games included more checks to stop games running if they were being played from one of these devices. Unsurprisingly newer cards were produced and in game protections were removed by the groups releasing game dumps for these devices.

It is fair to say that the original DS is not a looker. The chunky casing and styling was a nod back to the original dual screen Game and Watch devices. Nintendo released the much slinkier looking DS Lite. This was basically the original Nintendo DS put on a severe diet and taking styling pointers from Apple. I held out for a while before purchasing this as I was slightly miffed at buying the first version at full price only for this much improved version to turn up not much later. There is a lesson here – never buy the first version of a Nintendo product.

Nintendo DS and a DS Lite.
Sibling rivalry.

As I now had a chunky blue paperweight in my possession, I decided to perform some light surgery on it. Some clever people had managed to crack the security on the DS firmware so you could run Slot-1 code without the security signature. You just needed to re-flash the firmware. This involved removing the battery cover and jamming a metal screw into an innocuous hole inside the casing to short a connection – what could possibly go wrong? After a nervy few minutes, I ended up with a modded DS and not a chunky bricked blue paperweight.

Home brew development on the Nintendo DS was made possible by libnds – a subset of the devkitpro home brew development kit (this also supported other devices like the GP32 and Game Boy Advance). Installing this gave you a gcc style environment to compile C / C++ into the .nds file format that ran on the Nintendo DS. As this development kit was not officially sanctioned by Nintendo, accessing the features of the device had to be done from scratch and not using any copyrighted material. In earlier versions of libnds, the routines to handle and read locations from the stylus and touchscreen were not as accurate compared to that in commercial versions. As the developers unlocked the secrets of the device, these problems went away.

The first thing I managed to get running with the libnds development kit on my DS was a hacked up port of Quirky’s Chaos Advance. This itself was a port of the seminal ZX Spectrum game Chaos for the Game Boy Advance. This utilised the larger screen of the DS so you no longer had to scroll the screen around to see the full game board – the Spectrum screen resolution of 256 x 192 pixels (minus the border) was the same as the DS. It also added it some basic touch screen input so you could enter player names with an on screen keyboard or select spells.

I did the bulk of the work using an emulator – Dualis originally, then no$gba once it added more Nintendo DS features – as the workflow was much faster than having to compile the code, take the SD card out of the flash card, write the new .nds file from the PC to the SD card, put it back into the flashcard, turn the DS on and then select the file from the loader menu. You couldn’t completely avoid using real hardware as the emulators were still quite early on in their development so you could end up in situations where the emulator crashed running your code, whereas the DS didn’t and vice versa.

ChaosDS screen shot
While it’s all kicking off below, the upper screen is not being used to it’s full potential.

When I did encounter crashes or bugs either in the emulator I then had the fun or trying to track the problem down without a debugger. I’d been developing on Windows with Visual C++ for some years and had been spoiled rotten by it’s lovely debugger. I had to switch back to printf-ing debug output onto one of the screens with messages to see how far the code had gotten when the crash occurred – Got here, Got here1, Got here2 and so on. I used this as a divide and conquer mechanism to narrow down the section of code that was causing the issue.

Quirky eventually updated his GBA port to run on the Nintendo DS, negating the need for my hacked up version. This was not a wasted endeavour as it gave me a good grounding in developing homebrew on the Nintendo DS with libnds. I was now on the look out for a new project.

To be furthered…

So, about last year…

Turns out that I’m better at writing code than writing about code. Though that’s not too surprising if I’m honest. Documentation is always a chore and my past low tech attempts at chronicling events can be found in various unfinished diaries.

So to start 2019 with slightly better intentions – and yes, I’m aware it’s already mid February – let’s begin with some details on my latest release for the venerable ZX Spectrum, Your crackers, m’lord!

Towards the end of October last year, R-Tape took his special ceremonial horn off the wall, put it to his lips and let out a clarion call for submissions to the second edition of the Woot! Christmas tape magazine . I had an idea for something to do but couldn’t get it together in time as I was struck down with a chronic bout of level designer’s block. With the December deadline rapidly approaching, I went back to the drawing board.

So what to do in a short amount of time? I still wanted to knock a simple game together. I tend to favour writing puzzle games as they can be easier to implement in a short amount of time – especially if the main mechanic isn’t too complicated. Then, it’s just a matter of going through and adding all the levels.

By chance, I stumbled across a Scratch remake of Kiragames’ ‘Unblock Me’ by griffpatch. The aim of the game is to slide the pieces of wood vertically or horizontally to let you move the red block across the screen to the hole on the right hand side. The red block can only slide horizontally and the others can only slide in the direction they are oriented. It had a small level set, was challenging and the cleanly designed graphics would work well on the Spectrum.

griffpatch’s Scratch remake

Over the first weekend in December, I fired up my trusty text editor alongside with the z88dk C compiler and started work on my conversion. By Sunday afternoon, I had this garish prototype:

Crackers on acid!

It had a frontend (recycled from Thoroughly Modern Willy), 4 levels and the code to display the board – but you couldn’t move any of the crackers around or finish a level. Over the subsequent days, common sense prevailed and I settled on a more sedate set of cracker graphics. I also added the code to select a cracker (using the Spectrum’s BRIGHT attribute as an easy way to implement the selection cursor), move the cracker around the board vertically or horizontally and to detect when the red cracker was at the gap in the board which meant the level was finished.

The finished product.

With the game code sorted I set about playing the levels on the original to obtain the level data for the 28 remaining levels. These were pretty straightforward until the last 2, which had been sourced from a harder level of play. After some head scratching, I had the full level set and the skills to play test all the levels. For each level, I took screenshots of the game’s web page on starting and finishing a level so I could check I’d entered the level data in correctly and knew where I needed the crackers to end up to complete the level.

At this point, the only reference to Christmas was the cracker graphics. When you pull a cracker at Christmas, aside from the coloured paper crown you usually end up with a gift of dubious quality – usually a tiny notepad, some impossible joined metal loop puzzle or a red plastic fish with ‘psychic’ powers – and a piece of paper with a poor quality Christmas joke printed on it. I decided to source 32 cracker jokes, one for each level to display on completing a level. Fortunately the internet had my back with various web sites compiling lists of the best worst Christmas cracker jokes.

The main constraint for using a joke was whether I could fit the question and answer parts of the joke on one line. This proved challenging with an 8 x 8 pixel font, so I used Einar Saukas’ fzx font system support in z88dk to use a variable width font which let me squeeze more characters on to the line.

Just one of the 32 pieces of comedy gold strewn between the levels.

The name ‘Your crackers, m’lord’ comes from a sketch by the Two Ronnies (a popular UK comedy double act from the 1970s and 80s whose Christmas show was a big telly event back then). The sketch is in a similar vane to the classic ‘Fork handles / Four candles’ where the property of certain English phrases sounding identical to each other but meaning vastly different things is used to comic effect. In this case, the butler whilst serving courses of a meal to an aristocratic couple is saying nice things to his Lordship’s wife “Your sweet m’lady.” but is insulting to his Lordship “Your nuts m’lord.”Your crackers m’lord”.

This sketch also gave me the bare bones of a story to hang the game off. The reason you’re having to go to all this trouble moving these other crackers around is to satisfy your aristocratic employer’s demand for a red cracker with his festive food stuffs. I’m sure this was one of the sub plots of a Christmas edition of Downton Abbey one year.

For a rush job I was happy with the overall result. I’d like to thank griffpatch for his original Scratch game which provided the inspiration and source material for my conversion and R-Tape for compiling another Woot! tape magazine.

Statement of intent

Hello. This is the first post on my site. If you have high expectations, allow me to dash them quickly. This site will showcase new and current projects as well as  some of the older things I’ve worked on.

I’m currently writing code for the ZX Spectrum (an 8 bit computer from the UK) but have dabbled with 68000 assembly on the Amiga, lua games programming (through love) and homebrew on the Nintendo DS using libnds and gcc.