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…


Usually, I don’t import BMP to NES Screen Tool. I use GIMP and make a graphic that is 128×128, and change 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.

I’m using the same graphics (Girl3.chr), and I’ve saved my NES Screen Tool (.nss) file as a compressed rle file, “Nametable/Save Nametable and Attributes/RLE packed as C header .h”. Now we can import it into the C code, and print it to the background.

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 588 bytes. The game code needs to decompress this Girl3.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(Girl3); // decompress our rle file, copy to the screen. Girl3 is the name of the char array in the Girl3.h file.


So far, I’ve forgotten to mention the palette. I had to change it to make it brown shades. I’m going to discuss this in more detail later. pal_bg() sets the palette for the BG.





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.



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 )

Google photo

You are commenting using your Google 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