This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Updating background tiles

Updating background tiles
by on (#158641)
What is the standard process to update just some of the background tiles? Say the score or remove a door, open a status panel etc.
Re: Updating background tiles
by on (#158642)
I think the most popular way to do it is to put the changes in a buffer and turn on a flag that signalize that there are BG updates to be done next NMI. In the NMI handler you need to have some code that updates the nametable according to the contents in the buffer if the flag is set, and then clear the flag again. This wiki page explains it. This way you can update the buffer at anytime since the actual update won't happen until the next NMI anyway.

You can have one buffer for BG, one for palette and so on, and a flag for them each in the NMI.
Re: Updating background tiles
by on (#158644)
Another common approach is to use a generic buffer, where each entry is a VRAM address, an increment mode, a byte count, and then the actual data. Then, all your NMI handler has to do in order to manage all kinds of VRAM updates is write the address to $2006, set an increment mode (1 or 32) and loop the specified amount of times copying bytes to $2007. If you need to transfer a lot of data, you can optimize this setup a lot, mainly by unrolling the but copy loop and jumping to somewhere in the middle of it depending on the amount of bytes that need to be copied.
Re: Updating background tiles
by on (#158661)
Oh that saves a lot of RAM to have all VRAM stuff use the same buffer (except sprites I guess since it usually goes into $0200 for OAM DMA). Non-VRAM things like shadow registers for $2000 and $2001 can have their own variables though.