$0xx0: the final 0. how do I change it?

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
$0xx0: the final 0. how do I change it?
by on (#12369)
Hi all,

this is my first post! i have a specific question about VROM addressing. i am working off of the Challenge Games NESDEV.htm tutorial and i understand that to write tile $0xx0 (where xx is a byte) in the pattern tables to name table #0 in the PPU, you have to do this to the CPU:

Make sure bit 4 of $2000 is set to 0.
Write #$20 to $2006
Write #$00 to $2006
Write #$xx to $2007

My question is what about tiles $0xx1-$0xxF? How do i access them?

By the way, I am using yy-chr.
Thanks

by on (#12371)
That code you pasted will write to the NAME tables, not to the pattern tables.

Anyway... accessing PPU memory is pretty straightforward. First you write the address you want to access to $2006, then you write you stuff to $2007 and it gets placed in PPU memory at the desired address.

Therefore... to change ppu$1346 in the pattern tables, you'd do the following:

Code:
LDA #$13   ; high byte of $1346
STA $2006  ; write high byte first
LDA #$46   ; low byte of $1346
STA $2006  ; write low byte -- PPU address is now $1346

LDA whatever
STA $2007  ; 'whatever' will be written to ppu$1346


You can write to any ppu address by changing which values you write to $2006.

by on (#12377)
writing data to the name tables is what i want to do. i have loaded the .chr data into the pattern tables already using .incbin.

what i am trying to do is display an image on the screen as the background. let's say i want to display the tile stored in address $0200 on the screen, in the upper left corner. i understand that you have to do something like this....

Code:
lda #$20             ; high byte of name table #0 address
sta $2006
lda #$00             ; low byte of name table #0 address
sta $2006
lda #$20             ; the xx in $0xx0
sta $2007


is this correct? if so, what i want to know is, what else do i have to do if i also want to access tiles stores in $0201, $0202, $0203, and so on? if not then i have already gotten something wrong. by the way thanks for your help.

by on (#12380)
Oooh, okay. I misunderstood.

Your example is correct. The thing that might be throwing you off is that every tile is 16 bytes. So 'tile $00' actually uses ALL of $x000 - $x00F in the pattern tables (not just $x000).

You mentioned using YY-chr. For something which might help you visualize this... open up YY-chr and press the '+' button. This will move the display from offset $0000 to 0001. You'll notice the image doesn't get "normal" again until you get to offset $0010 (because that's the start of the next tile)

by on (#12381)
ah! it all makes sense!

by on (#12385)
Disch wrote:
So 'tile $00' actually uses ALL of $x000 - $x00F in the pattern tables (not just $x000).


Is that why when ever you have a graphic in the $00 tile and you load a name tables it comes up on the whole screen on every tile. How do you avoid this? and why does it happen?

by on (#12386)
nineTENdo wrote:
Is that why when ever you have a graphic in the $00 tile and you load a name tables it comes up on the whole screen on every tile. How do you avoid this?

By filling the nametable with a tile other than $00. For instance, Super Mario Bros. has a 0 digit glyph in $00 but a space in $24, and it fills the nametable (except the attributes) with $24.

by on (#12392)
nineTENdo wrote:
and why does it happen?

It happens because the name table can never be "empty". It must have a value for each position. Most emulators set them all to 0, resulting in tile 0 beeing displayed all over. As for a real NES, don't expect the tables to be cleared with a certain value on power up, there will most likely be random values, resulting in random tiles.

As tepples said, if you don't want it to happen you must write code to fill the name table with something else. You'll be doing that anyway to draw your game's screens, so, no worries.

Never expect RAM to have defined values at start-up, always set them yourself.