NES tile format

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
NES tile format
by on (#98164)
Hello Everyone,
I am making a tile editor and tile map editor that currently only supports the sega genesis.
The way it works is it stores a true color tile and it will automatically reduce it to the selected palette (There will be a choice of dithering algorithms or no dithering at all right now it only supports floyd steiburg).
I do not know of any editors that are able to do this and I was thinking about just how useful this technology is and I realized that this should not be limited to just one platform.
Alot of retro game systems use a tile and a palette so I would not have to re-invent the wheel.
Another advantage is when making a cross platform game there would be no need to rework the graphics
and speaking of not having to redo graphics another advantage of this is if you need to add a last minute tile and there are no good color to use all you would have to do is add the tile and the palette can automatically adjust it's self (it will be able to automatically find an optimal palette for the tiles).
Sorry if this ended up as an advertisement I was trying to describe the program it will be free and open source.
So I was just wondering how the NES stores the palette and tiles and what are the RGB values for the palette on the sega genesis they are simply in steps of 36.
As you can tell I am much more familiar with the sega genesis hardware than the NES hardware.
Also plane mapping is plane mapping a byte or a word that stores what each tile goes where and nothing else? On the sega genesis plane mapping has a few flags like which palette row to use and if the tile is flipped either vertically or horizontally or both and a priority bit.
Re: NES tile format
by on (#98166)
The "correct NES palette" is a very complex problem for people used to RGB. The video signal is generated directly in the composite domain, with hue in steps of 30 degrees in the YUV plane and four predefined brightnesses per hue. Different TVs decode them differently (which is also a problem with RGB VDPs, but composite encoding and decoding have historically been glossed over on most of those systems). This topic should get you started on what's involved.

The tile format itself is a lot simpler, but it's planar, not packed. If you've ever looked at Game Boy or SMS tiles, you should have no trouble figuring out planar. The palette consists of one background color, four sets of three colors for the background, and four sets of three colors for the sprites. Each background color set is assigned to a 16x16 pixel (2x2 tile) area, not an individual 8x8 pixel tile like on the Genesis, Super NES, GBC, and GBA, so tiles have to be reassigned to color sets on a 16x16 pixel basis, not 8x8, which is why so many NES games had background objects the size of the Image blocks in Super Mario Bros. series.
Re: NES tile format
by on (#98167)
Thank you It seems like it should not be too hard to add support for the NES. Hope to finish my program soon.
Edit: I was browsing the wiki and you call them name tables I called them plane mapping in my post sorry about that. Well either way thanks for the helpful link I am reading more about the PPU right now.
Re: NES tile format
by on (#98175)
The name tables (plane mapping) have 1 byte per tile, so they hold just tile indexes and nothing more. There's no priority control for background tiles and they can't be flipped, but a separate table (the attribute table) is used to specify what palettes are used for which tiles. Each byte in the attribute table selects 4 palettes for an area of 4x4 tiles, where each 2x2 tiles uses the same palette. There's one mapper though, the MMC5 (it's very complex and was used in very few games), which has a special mode that allows individual tiles to use any of the 4 palettes. Maybe you want to consider supporting that mapper in your application.
Re: NES tile format
by on (#98189)
There is also 8tools and Famitile. You can make your own if you don't like these other ones much (that is why I wrote Famitile so you can write another one if you dislike 8tools and Famitile), but these others are also free and open source software. I may include the feature of automatically reducing and finding optimal palette in my program too if I know best algorithm so thank you.

(About RGB palettes: Famitile has the default palette of VirtuaNES built-in, although perhaps it would be a good idea to allow RGB palettes to be loaded as well. I do not know if the 8tools nametable editor supports this, but the 8tools tile editor you can enter any RGB colors you want to. My suggestion for your program is perhaps include a default palette for NES and also allow loading custom RGB palettes.)
Re: NES tile format
by on (#98196)
I am glad to hear that you are adding that feature to famitile I do not want to reinvert the wheel but you editor seems to be totally different then mine.
My program is GUI based and written using c++ and FLTK (good gui library) for the gui stuff
Image
You can either edit the tile directly by clicking on the palette bar and click on the tile (right) or select an rgb value and click on the left tile and then the right tile will update. I picked a color that would caused alot of dithering artifacts on purpose even with all the artifacts it looks good when zoomed out all the way. Also thank you for the advice on how to work with an NES palette I never thought about using a palette file I thought about calculating the rgb values real time but using a file does seem like the better option. How would that work? How would my program know how to convert NES palette values to rgb values to the correct palette entry from the file?
Re: NES tile format
by on (#98202)
nintendo8 wrote:
I am glad to hear that you are adding that feature to famitile I do not want to reinvert the wheel but you editor seems to be totally different then mine. I did not understand what was going on.
My program is GUI based and written using c++ and FLTK (good gui library) for the gui stuff
And that is the same reason I suggest that we can both make up the program, and there can be other programs with similar features; to use whatever is preferred by a different user! (At least the file formats are common enough.) Yours is a proper GUI, mine is more like vi

Quote:
Also thank you for the advice on how to work with an NES palette I never thought about using a palette file I thought about calculating the rgb values real time but using a file does seem like the better option. How would that work? How would my program know how to convert NES palette values to rgb values to the correct palette entry from the file?
What I did is just import the palette (in the format described on the wiki under .pal) from VirtuaNES and converted it into a C header file, although it ought to allow external files to be loaded to (I will add it and you should probably add feature like that too).

So basically, you have the NES palette with sixteen entries (actual NES requires entry 0, 4, 8, and 12 to be the same as each other), and then select whether you are using 0/1/2/3, 4/5/6/7, 8/9/10/11, or 12/13/14/15 for editing so still only four colors per tile and thirteen colors per screen.

You should support at least standard NES nametables, although you can add support for MMC5 nametables as well if you want to (Famitile does support both standard and MMC5 nametables; 8tools appears to support only standard nametables but tepples can reply if I am wrong about this).
Re: NES tile format
by on (#98297)
So it seems that the palette is more complicated then I thought I used the code from the link posted earlier viewtopic.php?f=3&t=8209
and here is what I got
Image
I am aware that the NES only does 4 colors per row I just wanted to see what all the colors look like at the same time I will fix it soon.
This All the colors of the NES without setting the emphasis bits my program does support emphasis bits I hope people will understand that when they save the palette and use it in a NES program that the emphasis bits won't be set and it has nothing do with the palette file. They need to set them manually as emphasis bits is global.
Re: NES tile format
by on (#98298)
It appears you have the hues out of order.
Re: NES tile format
by on (#98343)
Ok I fixed that hues glitch now on to add tiles support.
Re: NES tile format
by on (#98355)
nintendo8 wrote:
I am aware that the NES only does 4 colors per row I just wanted to see what all the colors look like at the same time I will fix it soon.
This All the colors of the NES without setting the emphasis bits my program does support emphasis bits I hope people will understand that when they save the palette and use it in a NES program that the emphasis bits won't be set and it has nothing do with the palette file. They need to set them manually as emphasis bits is global.


Why is the "emphasis bits" a slider? Shouldn't it be arranged as four checkboxes instead? (sort of [ ] B/W [ ] Red [ ] Green [ ] Blue)
Re: NES tile format
by on (#98396)
usr_share wrote:
Why is the "emphasis bits" a slider? Shouldn't it be arranged as four checkboxes instead? (sort of [ ] B/W [ ] Red [ ] Green [ ] Blue)

Edit: This next part is total bogus
From what I know the emphasis bits cannot be combined on the NES, so checkboxes could confuse people into thinking that this can be done. On a slider you can only have one option selected at a time. However I would recommend making a drop down menu for the color emphasis and a checkbox for the monochrome option like this:
Code:
Color emphasis:
> Red
> Green
> Blue

Monochrome Mode []


Of course when Monochrome Mode is selected the drop down menu for the color emphasis needs to be inactive.
Edit2: At least that would make sense, if the NES PPU didn't behave differently. Thanks to thefox and usr_share for the reminder!
Re: NES tile format
by on (#98398)
Grumskiz wrote:
From what I know the emphasis bits cannot be combined on the NES, so checkboxes could confuse people into thinking that this can be done.

Not true, they can be combined just fine. (FYI: FCEUX doesn't emulate this part right, it only allows one of the emphasis bits to affect the output.)
Re: NES tile format
by on (#98400)
Grumskiz wrote:
From what I know the emphasis bits cannot be combined on the NES, so checkboxes could confuse people into thinking that this can be done.


They can. In fact, some developers have their games set all the emphasis bits -- this makes the colors quite a bit darker.

Quote:
Of course when Monochrome Mode is selected the drop down menu for the color emphasis needs to be inactive.


They don't. Quoting the wiki's "PPU registers" page,
Quote:
In either case, the tint bits are applied after grayscale, which means they still tint the gray image.


-- that is, the tint bits can be enabled (and will make sense) even in grayscale mode.
Re: NES tile format
by on (#98402)
Also remember that the emphasis bits on RGB PPUs shoot that color component up to 100%.
Re: NES tile format
by on (#98438)
Hrm, I was wrong then. Sorry, if my mistake caused any confusion. Time to read up on some of the wiki pages again :P

@thefox
Yeah I think I remember trying out if they can be combined. Since I have no way of testing on real hardware I used FCEUX. I guess it wasn't the best choice.
Re: NES tile format
by on (#98441)
Grumskiz wrote:
Since I have no way of testing on real hardware I used FCEUX. I guess it wasn't the best choice.

FCEUX is a great development tool because of all the debugging features, but it shouldn't be your ONLY emulator, as its fairly inaccurate in several areas.
Re: NES tile format
by on (#98443)
@tokumaru
It isn't. Or to be honest, it isn't anymore. I now use the linux version of nestopia for testing "if something works" and when I don't need any of the debugging tools that FCEUX offers.
From what I know it is just as accurate as the Windows version. (Though NSF playback appears to be buggy sometimes..)
Unfortunately Nintendulator (isn't it the most accurate?) does not work properly for me using the Wine software. It does not respond to any keyboard input. I could maybe try to use a virtual windows machine, but that would defeat the purpose of quickly testing something in an emulator.

Back to Topic:
I have to agree with usr_share now that I think about it. With the possible combination of emphasis bits a slider to select them seems odd and inconvenient.

One last thing a little off-topic:
Can someone name me some examples of games that combine all the emphasis bits? Maybe I have never paid any attention to it or I just don't know the games. Are there any official ones by Nintendo or is it just third-party or unlicensed/homebrew stuff?
Re: NES tile format
by on (#98446)
All Eurocom games (James Bond Jr., Jungle Book, etc), Felix the Cat.
Re: NES tile format
by on (#98447)
Just Breed doesn't work on Famicom TVs or Famicom Titler because Just Breed turns on all three tint bits, and that results in a solid white screen on the RGB PPU used in those products.
Re: NES tile format
by on (#98484)
Grumskiz wrote:
Hrm, I was wrong then. Sorry, if my mistake caused any confusion. Time to read up on some of the wiki pages again :P

No you did not cause conusion I already knew that the de-empesis bits can be put together. Anyways I will change the slider to boxes (the slider went up to 7 I can understand how that can make combining de-ephessis bits confusing). Also one thing that needs to be done before I release the program is an undo buffer sometimes while testing the program one thing I found annoying is not being able to undo stuff. How high priority do all you users think an undo buffer is? Also I almost finished image importing that should make things easier if somebody wants to use a real photograph in an NES game or Sega Genesis game. Also my program now my program supports the NES tile format. If anybody has anything else that should be in my program please post it.