Jeroen Duel

Gameboy tileset editor

Introduction

I build this tool for my own convience. The gameboy does not load and render an image the way modern operating systems do. To draw graphics on the screen of the gameboy a developer has to write binary data to specific memory locations. This tool converts the tiles drawn on the screen to a .csv file containing to said binary data in C syntax. I copy the code from this .csv file into my source code. If I want to edit the tileset I can simply upload the previous generated .csv file. I then make my edit and download it again.

Fig 1. Bitwise Bytefoolish tiles in the tileset editor

Graphics on the gameboy

On the gameboy the graphics are made out of tiles. A tile on the gameboy is 8 by 8 pixels. Each pixel of a tile can have one of four values: %00, %01, %10, %11. Which color a value represents depends on the selected palette. On the original gameboy the developer can only pick from 4 colors to make up a palette. The gameboy color however let's the developer pick from 32768 colors!

The tiles are stored in the gameboy memory at location $8000–$97FF. So let's do some math. Since each pixel can have one of four values it fits in 2 bits. Multiply it with the size of a tile (8 x 8) and the number of bits needed for a tile is 128. Or in a more common unit: 16 bytes. If we divide the 6144 bytes of the tilemap memory by the 16 bytes for a tile we end up with 384 tiles. But there is a catch! The tilemap, a location in memory where each byte represents a place on the screen, can only hold a value of 0 to 255. So the last 128 bytes would not be adressable where it not there is a special switch to toggle between 2 tilemaps. The table below shows which tilemap value refers to which tile in memory depending on wether the switch is on or off.

block VRAM adresses LCDC.4=1 (switch on) LCDC.4=0 (switch off)
0 $8000–$87FF 0–127
1 $8000–$87FF 128–255 0–127
2 $8000–$87FF 127–255

So what's has the tilemap to do with the tileset editor? Well the giveaway is that only 256 tiles are selectable from memory at any time.* That's why I made the tile list in the tileset editor only 256 tiles long. This way I am not temped to create more tiles than I have available.

* Okay, an experienced developer could toggle the tilemap switch in a STATS interrupt to swap the tilemaps during a render on the screen.

Want to see the result?