Welcome

Games

As stated before, the DMGPlus will start Linux and then immediately look at the cartridge to figure out what type it is. If it's a GameBoy cartridge, GNUBoy is responsible for running it.

The thing is that I wanted this to work with any GameBoy cartridge, existing or new, that you stick into the DMGPlus, so having a stack of ROM files and selecting the correct ROM file for the cartridge that is inserted wouldn't work. Also, dumping the inserted cartridge to a file before runnning it would be too slow. No, Gnuboy would have to be modified to read the cartridge as it executes.

This is somewhat tricky. Taking the cartridge read routines and redirecting them to the real cartridge over SPI works, but as the chain Gnuboy -> SPI -> cartridge is a lot longer than in the original GameBoy, this would be too slow. I decided to compromise: as soon as a new region on the cartridge is accessed, GnuBoy will read this region from the cart, then cache it and execute from this cache. Reading everything once is fast enough to not interrupt the flow of the game, and executing from cache is fast enough to keep the emulation running at real time speed.

This has the disadvantage that games that do funny stuff with the memory map suddenly won't run anymore: for instance, I have an old 64-in-1 pirate cart that just crashes. In other words: the amount of GameBoy games the DMGPlus can run is slightly lower than on an original GameBoy. On the other hand: Gnuboy has no problems emulating a Game Boy Color as well, and since the FPGA displays 16 colors instead of the original 8, Game Boy Color games actually look surprisingly good and are well-playable!

Now, what about the DMGPlus cartridges? Well, you might have noticed that these have weird and interesting colors. This is because they are modern reproduction cartridges, obtained on the Chinese market. Then, how did I manage to get the DMGPlus header and startup screens in there? Observe, the internals of one of the cartridges. This is Shantae:


The minimalistic PCB contains three things: a M29W640 8MByte flash chip, an M5M5256 32K RAM chip, and a blob chip that is a replacement for the MBC chip the original GB carts use. (The GameBoy can only access 32K of ROM directly, a MBC, or Multi-Bank Controller chip is needed to access more.)

Two things to note here. First of all, the flash chip is only specified up to 3.6V and they're abusing it as a 5V part here. Surprisingly, it works fairly well; I guess the manufacturing tolerances are good enough.

Secondly, Shantae uses save games, which are stored in cartridge RAM; the state of the cartridge RAM is normally maintained by an on-cartridge button cell battery. While this cart has a PCB location for such a button cell, it's left unpopulated. Still, the cartridge maintains save files just fine. How come? Turns out the ROM image for Shantae is modified. There's some additional code there: it presumably hooks into the save function and it copies the save RAM over to an otherwise unused sector of the 8M flash chip. When the cartridge starts up, there's another piece of code copying the saved games from flash back into save RAM. This way, they could save on the cost of the battery.

However, if the game can re-write the flash, this means that I can reprogram it as well. Turns out that I wasn't the only one who figured that out, there's a database of reproduction cartridges which also indicate if they're flashable, and after some more research I found out how to reflash mine. That's how I got the DMGPlus header and splash image on them.

While the logic handling an original GameBoy is pretty flexible and will handle most GameBoy cartridges you throw at it fairly well, the DMGPlus games are a lot less flexible. There's effectively a header that indicates the game is a DMGPlus game, plus a game name. The startup script simply checks this game name and starts the correct game. In other words: to get a new DMGPlus game to work, you need to add it to the internal SD-card of the DMGPlus first.

In theory I could have expanded on this: you could have a kernel driver that sees the cart as a block device, with DMGPlus games having a file system on them, which would then contain the binaries and data of the game so it could be ran off the cartridge. I didn't implement this. The first reason is practical: possibly because they're running off a too high voltage, the flash cartridges take a fair few retries to write without errors. The second one is more filosofical: I don't really see anyone else building one of these, so the only DMGPlus cartridges around will be the ones I create, so I can just as well save me the effort and edit my startup scripts directly.

Obviously, more games and emulators than the ones I currently have cartridges for are possible: in theory anything that can run on the Raspberry Pi should work. In practice, the hardware is a bit more limited: Quake 3 will run fine, for example, but the detailed levels are badly affected by the low-resolution monochrome screen and it's impossible to see where you are. Sega Genesis emulation is possible but hobbled by the low speed of the Pi Zero. Minecraft actually runs but assumes no one would ever have a screen as small as this one, and only shows the top left corner of the game.

« Prev 4 Next »


© 2006-2021 Sprite_tm - Contact