Vivek_Kakashi wrote:
tokumaru can u plz tell me what exactly is the difference between CHR ROM and CHR RAM or some tutorial on this topic.....
You probably know that NES carts have two different chips: one for the program and one for the graphics. So far you have probably used CHR-ROM, which means that the graphics chip is ROM (Read Only Memory): it contains all the tiles that are going to be used in the game, and those tiles can't be changed.
But in some carts, the graphics chip is RAM, which can be written. This means that your program is free to manipulate the tile data, you can overwrite and modify tiles at will as the program runs.
At first, the big difference is that when you use CHR-ROM the tiles are always there, ready for you to use. But with CHR-RAM, when the console is turned on there is nothing there, because RAM loses its contents when there is no power. So you have to put your graphics there before you can use them.
QUICK GUIDE TO CONVERTING YOUR 8KB CHR-ROM PROJECT TO USE CHR-RAM:
Step 1: Modify the iNES header to indicate that there are no CHR pages (set the number of CHR pages to 0).
Step 2: Remove the CHR data from the end of the file. If you have an "incbin" command after the interrupt vectors, remove it. I you are joining the PRG and CHR with a "copy /b" command after assembling, don't.
Step 3: Put the CHR data in the middle of the code, along with other data you might have. It's supposed to be data inside your program now, so that you can read it. It is important that you still have 8KB of PRG-ROM free (if you don't you might want to use a mapper like UNROM, for more PRG-ROM space). Do something like this:
Code:
TileData:
.incbin "tiles.chr"
Step 4: Copy the data from PRG-ROM to CHR-RAM during the initialization of your program. The following code copies the whole 8KB:
Code:
lda #<TileData
sta Pointer+0
lda #>TileData
sta Pointer+1
lda #$00
sta $2006
sta $2006
ldy #$00
ldx #$20
-CopyByte:
lda (Pointer), y
sta $2007
iny
bne -CopyByte
inc Pointer+1
dex
bne -CopyByte
Note that this is a PPU operation, it suffers from the same limitations as as writing to palette RAM or to the name tables: it can only be done during VBlank or with rendering turned off. Also note that tiles take a lot of space (16 bytes each), so there is a limit to how much you can change during VBlank depending on what else is being done during that time.