Sprite #0 split screen scrolling artifact

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

albailey
Posts: 177
Joined: Thu Jul 13, 2006 3:15 pm

Post by albailey »

I think I'm still not grasping one important concept. That is, when does the hit flag (bit 6) of $2002 go OFF.

The reason I am not grasping this, despite very good responses listed above, is that this piece of code invoked within the NMI works.

: BIT $2002
BVS :-
: BIT $2002
BVC :-

The Overflow flag gets set (BVS) and I loop again until it is cleared (BVC).
If I am on scanline 32, x position around 240 when sprite #0 is hit (the first loop, bit 6 gets set)

then does that means my second loop is waiting until the END of the NMI. Youch!!!

When I use this code, I can clearly see the screen being split properly, which doesnt jive with the responses I am reading, so I'm pretty sure I am clearly misundertanding what takes place during the second loop.

Al
User avatar
Disch
Posts: 1848
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch »

The first loop waits for sprite 0 hit to clear (turn off). This happens at the end of VBlank.

The second loop actually waits for sprite 0 to hit.

The reason you need the first loop is because if you try to wait for sprite 0 hit when it's still in VBlank, the flag may still be set from the previous frame -- so you'll get a "false positive" so to speak and will split the screen at the very top instead of mid-frame like you want.

You seem to be getting BVS and BVC mixed up. BVS will branch when V (sprite 0 hit flag) is set. When put in a loop like the ones you're using, that means it will keep looping as long as V is set -- therefore, BVS is really waiting for V to clear -- not waiting for it to become set.
albailey
Posts: 177
Joined: Thu Jul 13, 2006 3:15 pm

Post by albailey »

Ah OK.

I was mis-understanding 2 very important things.

1) I was miunderstanding the branches. I was mistakenly thinking they were branching forwards, lol. Thats just me being a fool.

2) I was misunderstanding thinking that the hit flag was cleared at the time the NMI was fired. This was a huge mis-understanding on my part, because if I thought it was clear then my first loop wouldnt even have been needed (and obviously it is).


The first loop waits until scanline #0 occurs.
The second loop waits until sprite #0 intersection occurs.

Got it. Time to update my code comments :)

I really appreciate all the responses. It greatly clarifies things for me.

Al
Post Reply