04. Full background

Writing a full screen as an RLE compressed file.

I wrote another blog page, a while back, about importing a BMP file into NES Screen Tool. Here…

NES Screen Tool BMP Import

Usually, I don’t import BMP to NES Screen Tool. I find it difficult.

I use GIMP and make a graphic that is roughly 128×128, and change image mode to indexed, 4 color. Then I copy it and paste it into YY-CHR. Then, I need to redo the color indexing (with the color replace tool), then save the .chr file. NES Screen Tool can then open the .chr file. You might find some other method that suits you best.

BUT — I decided to redo it using my own graphics conversion tool, called NESIFIER.


So, in GIMP I resized the image smaller (about 160×160), but then padded the canvas size to 256×240.


Then I saved as .png. Open that in NESIFIER, selected 4 colors, and dither settings (Floyd-Steinberg, 10) and press “convert”. This is the result.


Notice that the number to the left of “Tiles” is 254. Good. We need it 255 or less. Then I save the tiles “save final CHR”, and save the tilemap “save nametable”, and save the palette “Palette/Save NES 16 bytes”.

Open NES Screen Tool and load all these files.

With NES Screen Tool I saved the tilemap , “Nametable/Save Nametable and Attributes/RLE packed as C header .h”. Now we can import it into the C code, with #include “NES_ST/Girl5.h”.

A full nametable is 1024 bytes. You don’t want to leave nametables uncompressed… you would very quickly run out of space. The RLE version is compressed to 339 bytes. The game code needs to decompress this Girl5.h file.

We can’t do this with the screen on, so turn it off, then set a starting address, and call the rle function.


vram_adr(NAMETABLE_A); // set the destination address, the top left of the screen

vram_unrle(Girl5); // decompress our rle file, copy to the screen. Girl5 is the name of the char array in the Girl5.h file.


So far, I’ve forgotten to mention the palette. NES Screen Tool can copy the palette to the clipboard, which I pasted into the C code. pal_bg() sets the palette for the Backgroud. The palette itself is just a byte array of 16 bytes. We pass the name of the array to pal_bg(palette_name) to copy it to the NES palette.





Fade In / Fade Out

neslib makes it easy to change the brightness of the screen. You can do this with pal_bright(), using a value between 0 (black) and 8 (white). 4 = normal.

I borrowed a function from Shiru’s “Chase” game, and it’s very easy to use.

pal_fade_to(0,4); // fade from black to normal

pal_fade_to(4,0); // fade from normal to black

And if you run the fade.nes file, you see that it fades in and out in an infinite loop. Fading could be used for transitions, like from the title to the game, or from level to level.



Side Note –

With the NESIFIER tool, you can also save tiles and tilemap as a DZ4 file, which is a compression format that I came up with. I haven’t integrated that into the neslib / nesdoug code yet, so you can just skip it and use the RLE format that came with neslib originally. But, DZ4 would work similarly. It can sometimes get better results than the RLE format.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s