(solved) load a .nam without a blank frame causing a "flash"

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

lazerbeat
Posts: 64
Joined: Tue Jul 09, 2013 7:13 am

(solved) load a .nam without a blank frame causing a "flash"

Post by lazerbeat »

Ive been looking as a .rom nocarrier made called gallerynes to load a sequence of .nam files. I am trying to remove the blank frame each time a new .nam is loaded.

I can't work out how to approach it though as I assume you need to vblank before loading a new .nam so it loads cleanly but the vblank is causing the blank frame?

I have put a pastebin here of the code.

http://pastebin.com/p50y8HER

What I am eventually trying to do is create a little rom to load a series of say 10 .nam files to make little full screen "page flip" animations like in the high hopes demo by aspect. The effect shown here

https://youtu.be/eQ-OcS2Gwvk?t=72

And as far as I can work out, there isn't a blank frame shown during the "animation"

Anyone know where I would start?

thanks!
Last edited by lazerbeat on Sat Mar 12, 2016 5:06 am, edited 1 time in total.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: How to load a .nam without a blank frame causing a "flas

Post by tokumaru »

Normally, the blank frames between different screens are there because vblank doesn't provide enough time to change large amounts of VRAM data, so rendering has to be turned off to give the programmer full access to VRAM.

If the name tables are not being scrolled, you could instead load the new graphics progressively to the hidden name table across several frames during vblank (like, 128 or so bytes per vblank, instead of the whole 1024 bytes at once), and then switch to that name table when you're done. This technique is called "double buffering".
lazerbeat
Posts: 64
Joined: Tue Jul 09, 2013 7:13 am

Re: How to load a .nam without a blank frame causing a "flas

Post by lazerbeat »

Thats awesome, I will give that a try. I am sorry if this is a silly question, would I need to reload the attribute table as well or just the .nam file?
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: How to load a .nam without a blank frame causing a "flas

Post by tokumaru »

lazerbeat wrote:would I need to reload the attribute table as well
If the image uses more than 4 colors, yes, you probably have to modify the attribute table as well.
or just the .nam file?
How big are your .nam files? If they're 1024 bytes, the attribute table is included, if not, they'll be 960 bytes.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: How to load a .nam without a blank frame causing a "flas

Post by tepples »

Use both nametables. While you are showing one in $2000-$23FF, load the other to $2C00-$2FFF, 128 bytes at a time. Then when it's done, switch to the other nametable and its pattern table by changing the value written to PPUCTRL ($2000). Then vice versa.
lazerbeat
Posts: 64
Joined: Tue Jul 09, 2013 7:13 am

Re: How to load a .nam without a blank frame causing a "flas

Post by lazerbeat »

or just the .nam file?
How big are your .nam files? If they're 1024 bytes, the attribute table is included, if not, they'll be 960 bytes.[/quote]

They are 1024. Ok so I can set a counter for 8 frames, load 128 bytes each frame then transfer everything and reset the counter and in theory no flicker?

Nice little project for this week.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: How to load a .nam without a blank frame causing a "flas

Post by tokumaru »

You're gonna need some extra variables in order to keep track of the extra state this will require. For example, if the program currently uses a single name table, this is hardcoded into the program. To change this you'll need a variable to indicate which name table is being displayed, so you can toggle this setting as necessary.

You'll also probably need a flag indicating whether a name table is being updated behind the scenes or not. This flag will be used by the NMI handler to decide whether it should transfer a 128-byte chunk of data or not.
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: How to load a .nam without a blank frame causing a "flas

Post by dougeff »

I don't mind the flicker. It's one frame of black screen. It doesn't seem so bad to me. Seems like a lot of unnecessary programming just to avoid it.
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: How to load a .nam without a blank frame causing a "flas

Post by tokumaru »

dougeff wrote:Seems like a lot of unnecessary programming just to avoid it.
I disagree. For a beginner, it's good practice, and for more experienced coders, it shouldn't take more than 30 minutes to do.
lazerbeat
Posts: 64
Joined: Tue Jul 09, 2013 7:13 am

Re: How to load a .nam without a blank frame causing a "flas

Post by lazerbeat »

Actually, I had a follow up question. If the 2nd name table is being loaded "off screen" why is is necessary to load it 128 bytes at a time?

I totally trust you guys that it IS necessary, I would just clearly like to understand why.
lazigamer
Posts: 23
Joined: Mon Oct 10, 2011 9:05 am

Re: How to load a .nam without a blank frame causing a "flas

Post by lazigamer »

Because the register that holds the PPU address is used internally by the PPU when rendering, so the value becomes unstable. This is true even for writing to VRAM that is not being used in the current display. As far as the number of bytes to write to the PPU, since you can only do that in Vblank when the display is on you have about 2300 cycles to do it and depending on how optimized your code is for speed you can write around 128~150ish bytes at a time.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: How to load a .nam without a blank frame causing a "flas

Post by rainwarrior »

lazerbeat wrote:Actually, I had a follow up question. If the 2nd name table is being loaded "off screen" why is is necessary to load it 128 bytes at a time?

I totally trust you guys that it IS necessary, I would just clearly like to understand why.
You have a few thousand cycles in vblank where the NES is not drawing the screen. This is the only time you have to access the PPU. Any other time during the frame and the PPU is busy drawing the screen; trying to send data to it while it's doing that will corrupt your nametables and rendering.
lazerbeat
Posts: 64
Joined: Tue Jul 09, 2013 7:13 am

Re: How to load a .nam without a blank frame causing a "flas

Post by lazerbeat »

Right so even if you are writing to the name table the PPU isn't currently displaying
rainwarrior wrote: You have a few thousand cycles in vblank where the NES is not drawing the screen. This is the only time you have to access the PPU. Any other time during the frame and the PPU is busy drawing the screen; trying to send data to it while it's doing that will corrupt your nametables and rendering.
Thanks I didn't realize this applied even when writing to the nametable the PPU ISN'T currently displaying.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: How to load a .nam without a blank frame causing a "flas

Post by tokumaru »

A hidden name table is still part of the same memory as the visible name table, and that memory cannot be used for anything else while the PPU is rendering the picture.
ccovell
Posts: 1045
Joined: Sun Mar 19, 2006 9:44 pm
Location: Japan
Contact:

Re: How to load a .nam without a blank frame causing a "flas

Post by ccovell »

My old demos, Motion / Flame do this nametable double-buffering and flipping, if you want to check out the code for them (though ignore any bad coding practices that you find. ;-D)

http://www.chrismcovell.com/data/anims.zip

Image
Post Reply