Language…
20 users online:  Ahrion, Anas,  Atari2.0, Beed28, CircleFriendo, crocodileman94, DanMario24YT, Golden Yoshi, Heitor Porfirio, King-Raze, Maw, Mohamad20ZX, ocked, OEO6, OrangeBronzeDaisy, Papangu, playagmes169, SMW Magic, steelsburg, yoshisisland - Guests: 306 - Bots: 469
Users: 64,795 (2,370 active)
Latest user: mathew

4bpp GFX Format

Yeah, I'm having some trouble decoding the 4bpp graphics file format It's acting all weird... Here's what I would expect to happen:

4 bits per each pixel, or 1 nybble is used for one pixel, so 2 bytes should control 4 pixels. That seems to be correct (I'm checking in transelhextion), the weird part comes next. When I make the first color use color 2 (0 indexed) and the rest of them use color 0, the first two bytes in the file are 00 and 87. If I make it use color 0 all across, I get 00 and 07. When I change the first pixel to color F, the bytes become 80 and 87. I can't see any discernible pattern here, it seems that different nybbles are controlling the same pixel depending on what the color is, but that makes no sense, so I guess I'm missing something?
If I remember correctly, the first byte that controls "half" of the color is in one area, and the second byte that controls the other "half" is x0F (maybe x1F) bytes after the first byte, or something similar that. That probably doesn't help much since I don't have my notes on hand, but I'll post a more informative reply if I can find them.
I should get a new layout.

Probably won't, though.
The format is actually pretty strange to work with, although I read a really good document somewhere that helped me understand. Which I can no longer find. Let me try and explain it.

Here's a sample .bin I'll be using to explain.

The first half of row 1 is controlled by four bytes. Assuming we're looking a .bin file, that would be 0x0, 0x1, 0x10, and 0x11. If we break those bytes into binary, we can see something like:

0x00 - AA = 10101010

0x01 - 66 = 01100110

0x10 - 1E = 00011110

0x11 - FE = 11111110

The actual colors in the file are then read going down those four bytes.

So that means the colors in the row are

1001 = 9
0101 = A
1101 = B
0011 = C
1011 = D
0111 = E
0000 = F

and those are the color values.

I know it's a bit hard to understand, but hopefully this will help.
Ah, I see. Thats... well it's super weird. Wouldn't it make more sense to have one nybble = 1 pixel? Anyways, thanks.
I am not sure if this is the reason they did it or not, but if you ever notice in yy-chr when you switch between 4bpp SNES, 2bpp GB (which the snes uses also), and 1bpp 16x16, nearby tiles tend to combine and spit into pairs. What this means is, in practical terms, combining lower color format tiles with higher color format tiles should be simpler.

Basically, for tiles, 1 4bpp = 2 2bpp = 4 1bpp
Your layout has been removed.
Originally posted by HuFlungDu
Ah, I see. Thats... well it's super weird. Wouldn't it make more sense to have one nybble = 1 pixel? Anyways, thanks.


The GFX formats in old consoles are never designed to be easily human readable, but to make the hardware as simple as possible. Packed pixel like you suggested is used for mode7 but only because there was no other way to do it. Having 2bpp/4bpp/8bpp follow the same general format must've simplified the h/w atleast a bit. Packed pixel would've required very unique handling of all three.
Here's a document I recommend regarding the BPP stff. If I remember correctly, ORing all the bitplanes will give you the index to the palette.
My blog. I could post stuff now and then

My Assembly for the SNES tutorial (it's actually finished now!)
Orrrr use this document/tutorial. It explains most bpp formats relevant to SMW hacking.
--------> Don't follow "Find Roy's Dignity", my hack. Because it's pretty outdated. <--------