Discrepancy between nametables...

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
JoeGtake2
Posts: 333
Joined: Tue Jul 01, 2014 4:02 pm

Discrepancy between nametables...

Post by JoeGtake2 »

So this is a strange one...

I'm using horizontal mirroring. Originally, I'd used my main nametable (at $2000) pretty much exclusively. I've since decided to use the nametable at $2800 to handle my sub-menu so that I can easily preserve things like destructable terrain on a screen (don't have to reload the screen now, just shift to the other nametable).

Works fine for the most part except for one glaring thing.

So when the menu loads, game does a quick check to see what inventory items have been attained and either draws them or draws a *blank square* in their space. While the screen is turned off, if the inventory item bit is checked, it might originally have loaded the blank tile to $20A4, $20A5, $20C4 and $20C5. This worked fine.

Now, I'm transitioning to write it at $28A4, $28A5, $28C4 and $28C5. I know these are the correct addresses. However, when doing this, it draws this with a weird offset and not where it should. I've also tried in place making sure that the scroll is set to 0, but that didn't fix it.

Code is pretty simple - looks like:

Code: Select all


LDA #$28
STA $2006
LDA #$a4
STA $2006
LDA #$f5 ;; the tile
STA $2007

Should this essentially do the exact same as $20 and $a4 respectively when that other nametable is showing? Anyone think of why this might not yield the same visual result?
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Discrepancy between nametables...

Post by lidnariq »

Use a debugging emulator with a nametable viewer, set a breakpoint on the write, and see what exact address it ends up at?
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: Discrepancy between nametables...

Post by dougeff »

Some possibilities...

Typo...LDA #$a4 could be LDA $a4

Flip flop on the 'latch' wrong, one too many or too few 2005 and/or 2006 writes somewhere.

Wrong timing...trying to write during rendering.

Should be easy to spot in FCEUXs debugger. Set a breakpoint for writes to PPU in the range you want, look at the code around the write....look at the current PPU address set....look at the current scanline.
nesdoug.com -- blog/tutorial on programming for the NES
JoeGtake2
Posts: 333
Joined: Tue Jul 01, 2014 4:02 pm

Re: Discrepancy between nametables...

Post by JoeGtake2 »

Huh - thanks for the suggestions. Oddly enough, it was the matter of rendering not being turned off...strange. Tracing it through, it SHOULD be off at this point, but sure enough when I sandwiched a write between a render off - on, worked fine.

This problem didn't manifest when using the first nametable, which is equally curious. But this seems to have fixed it.

Thanks!
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Discrepancy between nametables...

Post by tokumaru »

The fact that you're having to turn rendering off and on to perform this update can be an indication that something else is wrong though.

Normally, if you're only using the regular amount of vblank time, you shouldn't *need* to turn rendering off. Some people choose to turn referring off during vblank just to be safe, but it's not mandatory. If your update only works this way, it could mean you're consistently using more time than available during vblank (in which case updates performed before the problematic one would succeed just fine), or that you're simply picking the wrong time (i.e. during rendering) to do this update.

This is definitely something you should look into, and not assume everything is fine because forcing the PPU off apparently fixes it.

Can you show us a little more code to contextualize those $2006/7 writes? Are you doing this in the NMI handler? What other takes are being performed in this handler?
JoeGtake2
Posts: 333
Joined: Tue Jul 01, 2014 4:02 pm

Re: Discrepancy between nametables...

Post by JoeGtake2 »

I'll keep an eye, but this is happening when screen is off - fade out -> screen off -> new screen load (including this function) -> screen on -> fade up.
Post Reply