XXIIVV
Nasu on Plan 9 picture
14P10 — Nasu on Plan 9

Character Memory format of Famicom roms spritesheets.

The chr file format contains a series of bits equivalent to pixels for each tile in the spreadsheet of a rom. A chr tile is 8x8 pixels, the data for each tile is made up of 128 bits, where the first 64 bits are the first color, the next 64 bits the second color, and where the colors overlap result in the third color, for a total of 4 colors including the background.

0000 1e3f 3f3f 3f1e 78fc fcfc fc78 0000

If you're looking for a simple editor and ANSI C implementation, see Nasu and Exed. To convert an image into sprites, see Dito. You will find this datatype in most of the tools ecosystem.

C Integration

Drawing a 2-bit sprite

Uint8 icon[16] = {
	0x38, 0x7c, 0xfe, 0xfe, 0xfe, 0x7c, 0x38, 0x00,
	0x38, 0x7c, 0xfe, 0xfe, 0xfe, 0x7c, 0x38, 0x00
};

Chrs are 8x8 bitmaps with a maximum of 4 colors.

void
drawchr(Uint32 *dst, int x, int y, Uint8 *sprite)
{
	int v, h;
	for(v = 0; v < 8; v++)
		for(h = 0; h < 8; h++) {
			int ch1 = ((sprite[v] >> h) & 0x1);
			int ch2 = (((sprite[v + 8] >> h) & 0x1) << 1);
			putpixel(dst, x + 7 - h, y + v, ch1 + ch2);
		}
}

Drawing a 1-bit sprite

Uint8 icon[8] = {0x38, 0x7c, 0xfe, 0xfe, 0xfe, 0x7c, 0x38, 0x00};

Icns are 8x8 monochromatic bitmaps, or half of a chr.

void
drawicn(Uint32 *dst, int x, int y, Uint8 *sprite, int fg, int bg)
{
	int v, h;
	for(v = 0; v < 8; v++)
		for(h = 0; h < 8; h++) {
			int ch1 = (sprite[v] >> (7 - h)) & 0x1;
			putpixel(dst, x + h, y + v, ch1 ? fg : bg);
		}
}
— Submit an edit to chr_format.htm(46 lines)

incoming(9): tools exed dito dotgrid moogle noodle nasu left meta

Last update on 14P10, edited 5 times. +24/32fh ----|-