What's new

Emulating Game Boy Games With Custom/Colorized Sprites

NES_player4LIFE

Texture Pack Invader
Moderator
Category: <b>Gameboy</b><br><br>:: Home Blog
::Developer Shonumi
:: :: Emutalk post

Emulating Game Boy Games With Custom/Colorized Sprites
tetricolor.png


When it comes to emulation, one could certainly think that we’ve explored just about every aspect of the Game Boy so far. From multiplayer over the serial port, the Game Boy Printer, the Super Game Boy, the Game Boy Color Infrared Port, Rumble Carts, to even the accelerometers in Kirby’s Tilt ‘n’ Tumble: there isn’t much emulators can’t handle. However, there will always be new territory to uncover and explore, especially for those with creative minds. In the form of an enhancement or modification, custom sprites is one such example. An emulator with custom sprites has the ability to replace a game’s native graphics with data selected by the user. To my knowledge, no one has ever implemented such a feature into a Game Boy emulator. Until now that is.

Art History 101:

The original Game Boy, Game Boy Pocket, and the Japanese-only Game Boy Light were only capable of displaying graphics using four different shades of gray (this applies only to background tiles, sprites were restricted to 3 shades with one shade reserved for transparency). Each pixel was either completely on, 2/3 on, 1/3 on, or completely off. The monochrome palette lasted until the Super Game Boy came out, allowing games to be played with 32 (sometimes garrish) colored palettes, as well as custom ones. I never owned one, but I do remember having quite a few “Play It Loud” poster sheets that came with my Game Boy games advertising the Super Game Boy. Eventually the Game Boy Color came out allowing games to be played with colored palettes as well. Still, games that were not Game Boy Color only or backwards compatible games that did not fully utilize the Game Boy Color never really achieved significant colorizations, at least nothing that made them on par with native Game Boy Color games. There is a Game Boy Colorizer ROM hacking tool that aims to help hackers convert old DMG ROMs into fully capable GBC ROMs, but from what I have heard, it can be finnicky at best.

Currently, I am working on my own Game Boy emulator that I plan to call Game Boy Enhanced. It isn’t a very original or clever name, but this is my first emulator, so I can afford to be simple and straightforward. Since the project will introduce me to emulator programming, I do want it to be as accurate as I can make it, however, I don’t shy away from graphical enhancements when it comes to emulation. This is the future after all, so we might as well be able to make things shiny if we want to. At first, I was planning to have the usual assortment of enhancements that nearly every other emulator has: 2x-3x-4x nearest neighbor scaling, various scaling filters (the HQ family, SuperEagle, 2XSai), save states, and maybe built-in sound-ripping. However, one of the regulars on the Dolphin emulator forums suggested that it would be nice to allow custom sprites as a feature, and this got me thinking.

Dolphin is a pretty advanced emulator; it allows users to dump textures for games, edit them, and then load them into the game. This activity is quite popular in sprucing up old N64 games in the N64 emulation community, and the practice has extended to Gamecube and Wii games now too. I figured it would be possible to do the same with Game Boy Enhanced (GBE for short). Although there are a number of more pressing things to program for GBE, I decided to see if I could implement it anyway. The general theory is similar to how Dolphin operates. Based on the sprite’s raw pixel data, GBE generates a unique hash to represent it. GBE stores every hash in a list. When drawing a sprite, GBE compares the current hash against the list. If the hash is in the list, rather than drawing the pixel data obtained from Video RAM (VRAM), GBE will load the custom sprite data from a file. I will go in-depth more about that, but first GBE needs to allow users to get the sprites to modify in the first place.

Taking a dump:

GBE needs to dump the sprites as the game generates them. The general idea is to get the hash and compare it to what we already have in the list. If the hash is already in the list, there’s no need to dump the sprite again, so GBE ignores it. When it’s a brand new hash, GBE pulls the pixel data from VRAM and then saves that data to a BMP. The trick here is to make sure that the file is going to be as unique as the sprite itself, so GBE names it after the hash. This will help when loading the modified sprite as well. Since this work was fairly experimental, the hashes were simply 128-bit numbers converted to hexadecimal. That’s enough to create a unique hash for every possible 8×8 sprite possible as it takes 32 bytes (128-bits) for the Game Boy to represent an 8×8 sprite. 8×16 sprites have yet to be implemented in GBE, so I’m not worrying about that just yet.

Now here comes the fun part: editing tiny 8×8 bitmaps. Obviously there are a couple of challenges. The first is in determining what you’re looking at exactly. If you don’t have a discerning eye, it can be quite difficult to see the sprites you’re after. Of course enlarging the dumps in an image viewer helps, but most larger sprites are a combination of the 8×8 sprites. Visualizing which ones match together is not unlike a puzzle game in and of itself. The next thing to consider is how you want to edit these sprites. Since whatever data entered here supercedes the Game Boy’s color choice, custom sprites are not concerned with things like the palette. The colors in the BMP file are the final colors that will be output to the screen. If the custom sprites decide not to add color, they need only determine what shade of gray each pixel should be, irrespective of any programmed palette.

mario_sprite.png

It takes a keen eye to edit 8×8 sprites like this. Here we have Mario, obviously.

Once the sprites have been dumped and edited, the next step is to load them back into the emulator. It’s pretty much the reverse of what GBE does when dumping them. Whenever new sprite data is generated, GBE generates a hash for that and tries to load a BMP file named after that hash. Once the BMP file is loaded, it gets stored into a cache. GBE then updates a list of which hashes have already been used to get custom sprite data. The list ensures that the same hash isn’t used again to load the BMP file since the cache already contains the custom sprite data. Whenever GBE draws a sprite whose hash matches an entry on the list, GBE draws the custom sprite data pulled from the BMP instead of VRAM. With this, GBE effectively replaces the original pixel data without affecting the rest of the game.

custmsprite.png


The whole process of custom sprites:

Look at all the colors

The custom pixel data can be anything we choose; it can even exceed the color limits of the Game Boy Color. The limitations enforced on the original system need not apply to GBE, since the emulator has the final say over graphical output, not the original hardware. It’s easy to have a sprite use 10, 20, or even 30 different colors. Although it takes a bit of creativity, there’s nothing stopping sprites from taking on a 16-bit look and feel. The only issue is the screen size (160 x 144 pixels) which makes for relatively small sprites.

However, the possibilities don’t just end there. We can completely mod Game Boy games with this method to create custom pixel data for anything. Background tiles are stored and processed in the almost exact same manner as sprites. The method of generating hashes for background tiles and replacing background tiles with custom pixel data is identical, so it wasn’t hard to program GBE to manipulate the background as well. Now it’s possible to fully colorize original DMG games in a reliable manner. And yet there’s more; consider that this isn’t just a method a colorizing sprites, it’s a way to make the sprites look like whatever one wants them to look like. How about Tetris with Poke Balls? Super Daisy Land wherein Daisy saves Mario? Master Chief as Mega Man? Anyone with enough time and effort could alter or create just about anything.

If GBE ever catches on, I would hope this to be a defining feature, as it could prove popular within the ROM hacking community (even though, technically, the ROM data is not touched with this process). GBE isn’t quite ready for its public release as an open-source project however, as I’m reworking LCD emulation and increasing game compatibility at this moment, and most of the custom sprite code needs to be rewritten as well. It should up on Google Code within a month however, so anyone wanting to play around with this neat feature can have a go.

Other emulators are quite capable of adding this functionality themselves if so desired. The method described here is not specific to Game Boy Enhanced at all nor the original Game Boy games it emulates. GBC, GBA, NES, SNES, Genesis: basically any system that uses sprites can also use custom sprite data. As long as the emulator has some way to view the sprite data (which an emulator needs to, if it ever wants to draw that data onscreen), it can generate a hash and replace the necessary data. That’s not to say it would be easy to implement in every emulator, only that such possibilities do exist. Personally, I think this is an exciting opportunity for people and communities that want to see new life breathed into games that are now getting to be decades old. It could add interesting twists to games that we’ve already been playing for years. I very much look forward to seeing how people apply this technique in the future.

A video of custom sprites in action can be found on my YouTube channel. It’s only Tetris (and not my best game, mind you), and not everything is fully colorized. This is just a proof-of-concept demonstration until the underlying implementation is perfected. Still, it works, and that’s half the battle :)
 
Last edited:

Top