It is currently Sun Jul 23, 2017 7:40 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: fix screen 512 tiles
PostPosted: Wed Apr 19, 2017 1:49 am 
Offline

Joined: Tue Mar 28, 2017 6:26 am
Posts: 17
Hi,
I'm using cc65 but I can add assembly code.

I have to display a image (without animation) for the title of a game but I have almost 512 tiles. I know I can use 8x16 sprites but with the limitation of 8 sprite per line.
Can we extend the chr bank to have more tiles? Or maybe draw pixel by pixel in vram ($2000 -> $2400) instead of tiles as the picture will not be animated ?


Top
 Profile  
 
 Post subject: Re: fix screen 512 tiles
PostPosted: Wed Apr 19, 2017 2:22 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 9792
Location: Rio de Janeiro - Brazil
You can use more than 256 tiles in one screen if you switch to the other pattern table mid-screen. For example you can use tiles from the first pattern table on scanlines 0 through 119, then trigger a sprite 0 hit on that scanline and tell the PPU to start using tiles from the second pattern table (i.e. use bit 4 of PPUCTRL), causing scanlines 120 through 239 to use another set of tiles. Then, during vblank, you write to PPUCTRL again to revert to the first pattern table for the start of the next frame.


Top
 Profile  
 
 Post subject: Re: fix screen 512 tiles
PostPosted: Wed Apr 19, 2017 4:19 am 
Offline

Joined: Tue Mar 28, 2017 6:26 am
Posts: 17
Thanks, I'll try this.


Top
 Profile  
 
 Post subject: Re: fix screen 512 tiles
PostPosted: Wed Apr 19, 2017 6:57 am 
Offline

Joined: Tue Mar 28, 2017 6:26 am
Posts: 17
I tried like you say : I draw first part of the screen with first pattern and the second pattern but this doesn't work

Code:
PPU_ADDRESS = 0x20;
   PPU_ADDRESS = 0x40;
   
   for( index = 0; index < 416; ++index ){
      PPU_DATA = tilehaut[index];
   }
   
   PPU_CTRL = 0x10;  %0001 0000
   PPU_CTRL = 0x10;
   
   PPU_ADDRESS = 0x21;
   PPU_ADDRESS = 0xE0;
   
   for( index = 0; index < 448; ++index ){
      PPU_DATA = tilebas[index];
   }


But I can make it inside my NMI with testing sprite hit from Nesdoug tutorial
Code:
PPU_CTRL = 0x90;
         Sprite_Hit();
         PPU_CTRL = 0x80;


Sprite Hit :
Code:
_Sprite_Hit:
Sprite0:
   lda $2002
   and #$40
   bne Sprite0
Sprite0b:
   lda $2002
   and #$40
   beq Sprite0b
   rts


Top
 Profile  
 
 Post subject: Re: fix screen 512 tiles
PostPosted: Wed Apr 19, 2017 7:03 am 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7105
Location: Jongny, VD, Switzerland
No, that's not how it works.
The status of the pattern table select bit in $2000 affects the rendering - that is what pattern table is shown when the PPU is rendering the frame. It's status has no effect when writing to $2007.

What tokumaru proposed is to split the screen in 2 regions, using a raster split technique. You want the $2000.4 bit to be '1' for one part of the screen and '0' for the other part, so you need to change this 2 times per frame. Perhaps the FAQ I wrote about the subject will be helpful. Especially the "Synchronizing with the PPU" chapter.


Top
 Profile  
 
 Post subject: Re: fix screen 512 tiles
PostPosted: Wed Apr 19, 2017 9:05 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 9792
Location: Rio de Janeiro - Brazil
Yeah, the pattern table selection affects what's displayed on the screen, it doesn't affect what the name tables can hold, which is always values between 0 and 255. Every frame, the PPU reads tile indices from the name tables and then fetches the corresponding patterns for displaying, so you can point to another pattern table mid-frame, causing the PPU to fetch different patterns for the same 256 indices, effectively giving you 512 tiles in a single screen.

For example, let's say that tile 0 of the first pattern table contains a circle, and tile 0 of the second pattern table contains a triangle. During vblank, you set the background to use the first PT, so every time the PPU finds the number 0 in the NT, it will draw a circle. Then comes the sprite 0 hit, and you tell the PPU to use tiles from the second PT for the background. From that point on, every time the PPU finds a 0 in the NT, it'll draw a triangle.

You have to keep switching the pattern tables like this every frame, because the PPU fetches everything for rendering every frame. Select the first PT for the background during vblank, then switch to the second PT after the sprite 0 hit.


Top
 Profile  
 
 Post subject: Re: fix screen 512 tiles
PostPosted: Thu Apr 20, 2017 11:40 pm 
Offline

Joined: Tue Mar 28, 2017 6:26 am
Posts: 17
Thanks, I think I get it now.
It's working well on emulator, need to test on real hardware now.


Top
 Profile  
 
 Post subject: Re: fix screen 512 tiles
PostPosted: Fri Apr 21, 2017 1:38 am 
Offline
User avatar

Joined: Sat Jul 12, 2014 3:04 pm
Posts: 890
tonma wrote:
Can we extend the chr bank to have more tiles?

Yes, you can have bankable CHR to have more than 512 tiles. You would generally have to change what banks are mapped in with raster timing, similarly to what others posted here.


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

All times are UTC - 7 hours


Who is online

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