So I'm at a point in the development of my current project where I'm going to need more than 8kb of CHR data. I'm using MMC1, which can obviously only swap 4k banks. This is more than the amount of tiles I need to switch out at a given time, so CHR-RAM seems like the better option (i.e SNROM)
The wiki has a good article, but really only covers switching entire pages of CHR data, so I don't really know go about doing something like, say, load a specific tile in a specific spot in the PPU, i.e for animation.
I feel like this is way easier than I think it is and that I'm just missing something, but how do you guys organize and load your CHR data? Are there any other techniques I should know about?
Switching to CHR-RAM for the first time. A few questions...
Moderator: Moderators
- rainwarrior
- Posts: 8734
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: Switching to CHR-RAM for the first time. A few questions
Every tile is 16 bytes of data. You write to CHR RAM through $2007, just like nametables, only the address is in the $0000-1FFF range. (Also like nametables, only do when rendering is off or during vblank.)Sogona wrote:I don't really know go about doing something like, say, load a specific tile in a specific spot in the PPU, i.e for animation.
Example code to update tile $63: (found at address $0630, kind of easy to multiply by 16 bytes in hex.)
Code: Select all
lda $2002
lda #$06
sta $2006
lda #$30
sta $2006
ldy #0
:
lda (data), Y
sta $2007
iny
cpy #16
bcc :-
Re: Switching to CHR-RAM for the first time. A few questions
The MMC1 will not help you with animating single tiles, since it can only swap 256 tiles (4KB) at a time (no existing mapper will switch units smaller than 1KB, or 64 tiles), so you're stuck with manually writing 16 bytes per tile to $2007 if you really need small updates. You can of course write tiles progressively to a hidden 4KB page across several vblanks and swap that in when you're done updating all the tiles you need.
Another thing you can do with this setup is draw different animation frames to each 4KB banks beforehand (tiles that don't animate will look the same across all banks), and switch between pages as the game runs to animate the background. This way you can easily do simple animations like water running, leaves blowing, coins spinning, and all sorts of things that make places look more dynamic.
Another thing you can do with this setup is draw different animation frames to each 4KB banks beforehand (tiles that don't animate will look the same across all banks), and switch between pages as the game runs to animate the background. This way you can easily do simple animations like water running, leaves blowing, coins spinning, and all sorts of things that make places look more dynamic.
Re: Switching to CHR-RAM for the first time. A few questions
Yeah, this makes sense, I just don't know how to go about abstracting it for use with any given tile.rainwarrior wrote:Every tile is 16 bytes of data. You write to CHR RAM through $2007, just like nametables, only the address is in the $0000-1FFF range. (Also like nametables, only do when rendering is off or during vblank.)Sogona wrote:I don't really know go about doing something like, say, load a specific tile in a specific spot in the PPU, i.e for animation.
Example code to update tile $63: (found at address $0630, kind of easy to multiply by 16 bytes in hex.)Code: Select all
lda $2002 lda #$06 sta $2006 lda #$30 sta $2006 ldy #0 : lda (data), Y sta $2007 iny cpy #16 bcc :-
Do most people treat animated tiles like regular animations? Like:
Code: Select all
AnimatedTile0:
.dw AnimatedTile0_0, AnimatedTile0_1, AnimatedTile0_2, AnimatedTie0_3
AnimatedTile0_1:
.db ;16 bytes of tile data