News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: An issue with the NES PPU  (Read 1380 times)

Pennywise

  • Hero Member
  • *****
  • Posts: 2271
  • I'm curious
    • View Profile
    • Yojimbo's Translations
An issue with the NES PPU
« on: March 23, 2020, 10:49:09 am »


I'm having an issue with the screen moving down when calling a menu in certain areas. I'm not entirely sure why this is happening, but I think it has something to do with the PPU register $2002. Through tracing the code, I've noticed this glitch happens when $2002 gets sets to #$00 and I don't know enough about the NES PPU to understand what exactly is happening.

Disch

  • Hero Member
  • *****
  • Posts: 2787
  • NES Junkie
    • View Profile
Re: An issue with the NES PPU
« Reply #1 on: March 24, 2020, 06:38:07 pm »
It probably doesn't have anything to do with $2002, as that is just a register the game can poll for a few things -- namely sprite 0 hit.

Most likely culprit is code in between frames is taking too long and the game is missing its window to set the scroll.  X scroll looks fine because that is reset every scanline, but Y scroll is only reset at the start of the frame, and if the game doesn't specify what Y scroll it wants before that happens, the entire frame will be thrown off.

I would say watch writes to $2005.  They come in pairs -- first will be the X scroll and second will be the Y scroll.  Specifically, make sure the Y scroll happens before pixel ~200 of the prerender scanline (which is either "scanline -1" or "scanline 262" depending on how the emu shows it -- I honestly don't know).

Pennywise

  • Hero Member
  • *****
  • Posts: 2271
  • I'm curious
    • View Profile
    • Yojimbo's Translations
Re: An issue with the NES PPU
« Reply #2 on: March 24, 2020, 11:37:02 pm »
Ok, so after setting a write breakpoint for when the menu gets written to the PPU, and then setting a write breakpoint for when $2005 is written to, the scanline is -1. I guess it's like you said. So, I guess my options are to optimize the code or add a wait for vblank routine (I think that's the right term.)

Disch

  • Hero Member
  • *****
  • Posts: 2787
  • NES Junkie
    • View Profile
Re: An issue with the NES PPU
« Reply #3 on: March 25, 2020, 02:20:00 am »
To be clear, scanline -1 is OK as long as it's the first half of scanline -1.  So if you can shave ~40 or so cycles you'll probably be fine.


EDIT:  To be even more clear, the code that needs shaving is the code that runs between NMI and that $2005 write.  IE:  All the stuff that is happening during VBlank.  Optimizing other parts of the code won't do you any good.


EDIT 2:

If optimizing is not feasible, you can set a late scroll with some crafty mixing of $2005/2006 writes as outlined here:  https://wiki.nesdev.com/w/index.php/PPU_scrolling#Split_X.2FY_scroll
« Last Edit: March 25, 2020, 02:31:11 am by Disch »