fix screen 512 tiles

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
tonma
Posts: 23
Joined: Tue Mar 28, 2017 6:26 am
Contact:

fix screen 512 tiles

Post by tonma »

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 ?
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: fix screen 512 tiles

Post by tokumaru »

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.
tonma
Posts: 23
Joined: Tue Mar 28, 2017 6:26 am
Contact:

Re: fix screen 512 tiles

Post by tonma »

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

Re: fix screen 512 tiles

Post by tonma »

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: Select all

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: Select all

PPU_CTRL = 0x90;
			Sprite_Hit();
			PPU_CTRL = 0x80;
Sprite Hit :

Code: Select all

_Sprite_Hit:
Sprite0:
	lda $2002
	and #$40
	bne Sprite0
Sprite0b:
	lda $2002
	and #$40
	beq Sprite0b
	rts
User avatar
Bregalad
Posts: 8056
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Re: fix screen 512 tiles

Post by Bregalad »

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

Re: fix screen 512 tiles

Post by tokumaru »

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.
tonma
Posts: 23
Joined: Tue Mar 28, 2017 6:26 am
Contact:

Re: fix screen 512 tiles

Post by tonma »

Thanks, I think I get it now.
It's working well on emulator, need to test on real hardware now.
User avatar
Myask
Posts: 965
Joined: Sat Jul 12, 2014 3:04 pm

Re: fix screen 512 tiles

Post by Myask »

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.
Post Reply