Some Sprite 0 hit weirdness

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

Some Sprite 0 hit weirdness

Post by JoeGtake2 »

Obviously, attempting to cram in some potential scrolling functionality into an engine not set up for it has proved to be a bit of a trial. But so far so good.

I went to add a sprite 0 hit to maintain the hud at the top of the screen. It's an easy enough concept, I get it. I had to add in a few caveats for the engine, so that it only does sprite 0 check if a flag is ticked, and tick and untick that, but other than that, everything seems like it should work.

And it *is* working, except the draw is getting corrupted. Where there should be a HUD, it seems to be overwritten with some junk graphic data (which remains static, as expected, while the level scrolls). It's absolutely the wait for the sprite 0 hit that is causing the issue, and I checked to see if I was gobbling up too much NMI time, but that doesn't seem to be the problem. What else might I check here to find what's being corrupted to end up causing this? Any thoughts, just based on what is described?

Thanks!
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: Some Sprite 0 hit weirdness

Post by dougeff »

Use a debugger.

Get a list of symbols, and find the address of just past the Sprite zero hit. Set a breakpoint for that. Then, set a breakpoint for writes to 2006 or 2007, which is probably causing the corruption (writes to PPU during rendering).
nesdoug.com -- blog/tutorial on programming for the NES
JoeGtake2
Posts: 333
Joined: Tue Jul 01, 2014 4:02 pm

Re: Some Sprite 0 hit weirdness

Post by JoeGtake2 »

Yeah - that was my instinct. That rogue 2006 writes without 2005 writes were the problem. But...simply disabling the zero sprite hit wait dismissed the problem. Curious.

I'll try that, though!
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Some Sprite 0 hit weirdness

Post by tokumaru »

When waiting for the sprite hit, are you first waiting for it to be cleared, and then set? Since the flag remains set all throughout vblank, you may end up prematurely triggering a split if you don't wait for the flag to be cleared first, which happens at the end of vblank.
JoeGtake2
Posts: 333
Joined: Tue Jul 01, 2014 4:02 pm

Re: Some Sprite 0 hit weirdness

Post by JoeGtake2 »

Ah - fixed it. Something stupid. Trying to read the sprite 0 check with drawing $2000 still set to 0 (at least, pretty sure that was it). Seems fixed now other than NOPing to get the timing so I don't get the flicker pixels. Thanks for the help - I think I just need to look at it with a cup of coffee. Love you guys!
Post Reply