It is currently Thu Jun 22, 2017 10:14 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Wed Mar 08, 2017 2:17 pm 
Offline

Joined: Thu Jul 23, 2015 7:54 pm
Posts: 127
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?


Top
 Profile  
 
PostPosted: Wed Mar 08, 2017 2:23 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5304
Location: Canada
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.

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.)

Example code to update tile $63: (found at address $0630, kind of easy to multiply by 16 bytes in hex.)
Code:
   lda $2002
   lda #$06
   sta $2006
   lda #$30
   sta $2006
   ldy #0
   :
      lda (data), Y
      sta $2007
      iny
      cpy #16
      bcc :-


Top
 Profile  
 
PostPosted: Wed Mar 08, 2017 3:35 pm 
Online
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 9744
Location: Rio de Janeiro - Brazil
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.


Top
 Profile  
 
PostPosted: Wed Mar 08, 2017 6:51 pm 
Offline

Joined: Thu Jul 23, 2015 7:54 pm
Posts: 127
rainwarrior wrote:
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.

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.)

Example code to update tile $63: (found at address $0630, kind of easy to multiply by 16 bytes in hex.)
Code:
   lda $2002
   lda #$06
   sta $2006
   lda #$30
   sta $2006
   ldy #0
   :
      lda (data), Y
      sta $2007
      iny
      cpy #16
      bcc :-

Yeah, this makes sense, I just don't know how to go about abstracting it for use with any given tile.

Do most people treat animated tiles like regular animations? Like:
Code:
AnimatedTile0:
  .dw AnimatedTile0_0, AnimatedTile0_1, AnimatedTile0_2, AnimatedTie0_3

AnimatedTile0_1:
  .db ;16 bytes of tile data

And then just have another table of where in the CHR-RAM to store each tile? I was trying to avoid hard-codng, but it kinda seems inevitable.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group