This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

2003 register

2003 register
by on (#222362)
I was looking at some source code that only writes to $2003 (zero) once during init, and never again.

All the other source code I've seen, writes zero just before OAM DMA.

Does anyone think this will cause problems?
Re: 2003 register
by on (#222363)
As long as the OAM DMA completes properly there shouldn't be a problem because it leaves the address back at 0 after cycling through them all. I think it's needed at init in case a reset happens in the middle of a DMA.

Though I would kind of wonder about badly done OAM DMA, like if you had it hanging out of vblank or something? Dunno what'd happen then, but that probably would cause other problems too.
Re: 2003 register
by on (#222365)
I'm pretty sure the PPU itself resets $2003 periodically (once per scanline or something) as part of the sprite evaluation process, so you aren't really required to, but you can do it just to be safe.
Re: 2003 register
by on (#222370)
tokumaru wrote:
I'm pretty sure the PPU itself resets $2003 periodically (once per scanline or something) as part of the sprite evaluation process, so you aren't really required to, but you can do it just to be safe.

https://wiki.nesdev.com/w/index.php/PPU ... evaluation

Quote:
If the sprite address (OAMADDR, $2003) is not zero at the beginning of the pre-render scanline, on the 2C02 an OAM hardware refresh bug will cause the first 8 bytes of OAM to be overwritten by the 8 bytes beginning at OAMADDR & $F8 before sprite evaluation begins.
Re: 2003 register
by on (#222375)
https://wiki.nesdev.com/w/index.php/PPU ... _.3E_write

Quote:
OAMADDR is set to 0 during each of ticks 257-320 (the sprite tile loading interval) of the pre-render and visible scanlines.

If you don't initialize $2003 at all, you might get a frame with corrupted sprites when you first enable rendering, but since OAMADDR is consistently reset to 0 at the end of every scanline, you can count on it being 0 before doing an OAM DMA during vblank, which means it will roll back to 0 once the DMA is done, and everything will be fine for the next frame.
Re: 2003 register
by on (#222382)
Ok. That helps.