HomeTutorialsPrograms
1-Setup 4-Sound 7-FIFO Space Invaders
2-Framebuffer 5-SRAM 8-Interrupts DSEmu
3-Keys 6-Filesystems 9-Microphone  
Donate 10-Extended Rotation Background

Space Invaders Emulator v0.2

for Nintendo DS

12th June 2005: The emulator has been updated to include hardware scaling so everything fits in the screen. I've also added the correct colour overlays. Multiple display modes are available including horizontal or vertical play. Read below for details.

You probably guess from the sound files I was using in the Sound Tutorial what my first project was and here it is - an emulator for the original Space Invaders Arcade game.

The nice thing about this emulator is that (apart from the emulator code) 90% of the DS specific code is based on what I covered in the first six tutorials.

The original space invaders machine screen size is larger than the screen of the Nintendo DS. To work around this I use the Nintendo DS's hardware scaling facility. Unfortunately this is a very simple scaling algorithm and some of the text can appear strange in the scaled screen. To compensate for this I've added multiple different display options and you can pick the one you prefer using the 'Select' key. Here are some screenshots of the different modes:

Horizontal ScaledVertical Scaled
Space Invaders Horizontal
Scaled Space Invaders Vertical
Scaled
Horizontal Two Screen ScaledVertical Two Screen Scaled
Space Invaders Horizontal
Two Screen Scaled Space Invaders Vertical
Two Screen Scaled
Horizontal Two Screen UnscaledVertical Two Screen Unscaled
Space Invaders Horizontal
Two Screen Unscaled Space Invaders Vertical
Two Screen Unscaled

The unscaled modes do no scaling at all and so some parts appear on the second screen. But you get the advantage of seeing the game as it was meant to be. The scaled modes fit the screen across one or two screens. I mostly play the horizontal scaled version but put the others in mainly to play around with the different hardware scaling approaches.

The keys to use are different depending if you are playing in a horizontal mode or a vertical mode. The keys and their mappings to the Arcade equivalent are:

Horizontal ModeVertical ModeArcade Equivalent
UpRightDeposit coin
Left Shoulder ButtonLeft Shoulder ButtonPlayer 1 Start
Right Shoulder ButtonRight Shoulder ButtonPlayer 2 Start
LeftUpMove Left
RightDownMove Right
A ButtonB ButtonFire
StartStartReset Game
SelectSelectReset Game and cycle to next display mode
Close LidClose LidPause and turn off screens

This version of the emulator does not include the space invaders ROM. You'll need to get this yourself from your original Space Invaders arcade machine, or download it from an archive site. You should only download it if you own an original machine of course.

As the ROM is not included in the executable you'll need to 'merge' the files together. To do this you'll need:

This emulator expects the ROM to be in a single file, invaders.rom. If you download the ROM from an archive it may come in four seperate files. This need to be merged into one with commands like:

Windows
copy /b invaders.h+invaders.g+invaders.f+invaders.e invaders.rom

Unix
cat invaders.h invaders.g invaders.f invaders.e >invaders.rom

With the invaders.rom, space_invaders_no_rom.nds.gba and the contents of 'rom_tools.zip' in the same directory, run 'merge_rom.bat' if on Windows or 'merge_rom.sh' if on a Unix like operating system. This will generate a 'space_invaders.nds.gba' which can be written to your GBA flash linker cartridge and loaded on the DS using WifiMe, a PassMe or a flashed bios using FlashMe. It must be on a GBA flash cartridge as I store the ROM is loaded from the cartridge address space.

As an experimental way of loading the ROM, instead of using 'merge_rom.bat' you can write 'space_invaders_no_rom.nds.gba' to your GBA flash cartridge and store the 'invaders.rom' in the SRAM area of the cartridge. If the emulator can't find the ROM appended to it, it will attempt to load it from SRAM (the saved game area). My flash cartridge software requires saved games to be 64KB in size so I use 'padbin' to set the ROM to this size before writing it. the 'rom2sav.bat' and 'rom2sav.sh' utilities in rom_tools.zip does this.

This approach is experimental because it seems to cause some issues with displaying on some of the scaled modes. I'm looking into that.

Since the emulator is actually a generic 8080 emulator, other ROM's may partially work. I've successfully used ROM's other than invaders.rom and had them run. Unfortunately the machine-specific portions won't work (usually the controls, sound, colour, etc) but it's fun to see other games just run. I use the method of loading the ROM into the save area for quickly testing other ROM's.

Source code will be released when I tidy a few things up. The code for the emulation portion is based on the excellent Space Invaders Didactic Emulator. The SIDE site has lots of details about the arcade machine. It seems to run fast enough on the DS but I've yet to look at tuning or getting the timings correct.

As always, any comments or suggestions are welcomed. See my contact details below.

The emulator must be loaded from a GBA flash linker cartridge. It can't be downloaded directly via Wireless Multiboot onto a flashed firmware DS. This is because I load the sound files and ROM directly from the cartridge address. So to run it you'll need it on a GBA flash cartridge and boot via Wifime, PassMe or booting from a flashed firmware. Not downloaded wirelessly onto a flashed firmware. I'm looking into how to work around this.