It is currently Tue Oct 17, 2017 4:46 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Animated tiles bank?
PostPosted: Fri Jul 01, 2016 10:48 am 
Offline

Joined: Thu Nov 24, 2011 7:16 am
Posts: 156
I noticed that in many NES games in the memory bank of the tiles, there are animated tiles. For example, in Super Mario Bros. 2, the herb tiles are animated.

How do they do that?

I thought that creating two banks of different sprites, and exchanging alternatively get done, but it is not possible as it is necessary to do this while the PPU this off.

All I've done is make color palettes, rotate or change screen colors. This is easy to do. But I gain my intentions.

Based on cc65 ... how you could get animated tiles?

Help!


Top
 Profile  
 
 Post subject: Re: Animated tiles bank?
PostPosted: Fri Jul 01, 2016 11:02 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19084
Location: NE Indiana, USA (NTSC)
Super Mario Bros. 2 and Super Mario Bros. 3 animate their tile sets by switching banks of CHR ROM into $0800-$0FFF using MMC3. Other games do it by uploading small chunks of tiles to CHR RAM every vblank.

Thus begins a mapper choice interview:

Do you plan on making your game available on cartridge? Are you already using or planning to use other features for which an MMC3-class mapper would be convenient, such as multiple scroll splits or bankswitched DPCM samples? How many tiles do you plan to animate, and how often do they change?


Top
 Profile  
 
 Post subject: Re: Animated tiles bank?
PostPosted: Fri Jul 01, 2016 11:08 am 
Offline

Joined: Thu Nov 24, 2011 7:16 am
Posts: 156
tepples wrote:
Super Mario Bros. 2 and Super Mario Bros. 3 animate their tile sets by switching banks of CHR ROM into $0800-$0FFF using MMC3. Other games do it by uploading small chunks of tiles to CHR RAM every vblank.

Thus begins a mapper choice interview:

Do you plan on making your game available on cartridge? Are you already using or planning to use other features for which an MMC3-class mapper would be convenient, such as multiple scroll splits or bankswitched DPCM samples? How many tiles do you plan to animate, and how often do they change?


I'm using UNROM.

The animation is 2 tiles (water)

The display is static.


Top
 Profile  
 
 Post subject: Re: Animated tiles bank?
PostPosted: Fri Jul 01, 2016 11:15 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19084
Location: NE Indiana, USA (NTSC)
A 2-tile animation can be performed by uploading each pair of water tiles to CHR RAM during vblank. True, "it is necessary to do this while the PPU this off", but you get about 2200 cycles of "the PPU this off" during each vblank.


Top
 Profile  
 
 Post subject: Re: Animated tiles bank?
PostPosted: Fri Jul 01, 2016 11:23 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5709
Location: Canada
Look for a mapper with CHR banking. This lets you swap sets of tiles with minimal effort.

Edit: oh, sorry, I had the tab open a while I guess. :P Already been some replies.


Top
 Profile  
 
 Post subject: Re: Animated tiles bank?
PostPosted: Fri Jul 01, 2016 4:15 pm 
Offline

Joined: Thu Nov 24, 2011 7:16 am
Posts: 156
tepples wrote:
A 2-tile animation can be performed by uploading each pair of water tiles to CHR RAM during vblank. True, "it is necessary to do this while the PPU this off", but you get about 2200 cycles of "the PPU this off" during each vblank.


Mmmm... no idea how to do that


Top
 Profile  
 
 Post subject: Re: Animated tiles bank?
PostPosted: Fri Jul 01, 2016 4:23 pm 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 1768
Location: DIGDUG
A tile = a 16 byte section in the PPU (between adresses 0-$1fff)

Tile #0 = addresses 0-$10.

You have time to do 200 writes to the PPU (with very efficient code), that would be 20 12 tiles you could completely change, per frame.

Link to discussion on how many PPU writes per V-blank...

viewtopic.php?f=2&t=13284

Edit, sorry, bad hexadecimal math.

_________________
nesdoug.com -- blog/tutorial on programming for the NES


Last edited by dougeff on Fri Jul 01, 2016 6:13 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Animated tiles bank?
PostPosted: Fri Jul 01, 2016 6:01 pm 
Offline

Joined: Thu Aug 12, 2010 3:43 am
Posts: 1589
tepples wrote:
A 2-tile animation can be performed by uploading each pair of water tiles to CHR RAM during vblank. True, "it is necessary to do this while the PPU this off", but you get about 2200 cycles of "the PPU this off" during each vblank.

Alternatively, find an excuse to have more animated tiles to justify bank swithing. Just look at Return of the Joker =P (there's a reason it reuses those clouds and flames often)


Top
 Profile  
 
 Post subject: Re: Animated tiles bank?
PostPosted: Sat Jul 02, 2016 3:19 am 
Online
Site Admin
User avatar

Joined: Mon Sep 20, 2004 6:04 am
Posts: 3470
Location: Indianapolis
Diskover wrote:
Based on cc65 ... how you could get animated tiles?


You do it the same way you would handle nametables updates for scrolling, palette updates, etc, but instead of writing the nametable, you write to the pattern table. If you're coding in C, we might need to know more about how your NMI/vblank routine is being handled.

You might consider writing this part in assembly, unless the C code turns out fast enough (you'll have to look at the code it generates). 2 tiles is only 32 bytes, so you shouldn't need to sweat about optimizations at all, unless you need more vblank time for other things. With a completely naive, non-optimized kind of loop like this, it would take 16~18 cycles (depends if you cross page boundaries) per byte. Running it 32 times takes "only" 18*32 = 576 cycles, which is about 1/4th of the available vblank time.
Code:
 ldy #0
@loop:
 lda (addr),y
 sta $2007
 iny
 cpy #$20
 bne @loop

To use that, you would first set $2006 to point to the tiles you're updating, and every time you want to change the animation frame, just change the pointer in the "addr" variable to point to your new tiles. In the interest of keeping things simple, you can run that every vblank, if the pointer hasn't changed it will rewrite the same data with no visible change, that won't hurt anything.

edit: And of course after using $2006/$2007 like this, you'll want to reset the $2006 and $2005 registers before vblank ends.


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

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 5 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