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

Sprite 0 Bug

Sprite 0 Bug
by on (#226298)
So, I just got done rewriting my code, so that it could fix a few problems with the code (mainly adding stuff to the NMI), until I got to a section where it uses a sprite 0 split, instead of splitting the screen like it did before so it could show a dialogue box and the background, it's now pushing down the background, so it can display the box. It's a little hard to explain, so here's a drawing of it:

Background:
\\\\\\\\\\\\\\\\\\\\\\\\\\\
\ _________________\
\ _________________\
\ _________________\
\ _________________\
\ _________________\
\ _________________\
\ _________________\
\\\\\\\\\\\\\\\\\\\\\\\\\\\

Before with the box:
---------------------------
|__________________|
|__________________|
---------------------------
\ _________________\
\ _________________\
\ _________________\
\ _________________\
\\\\\\\\\\\\\\\\\\\\\\\\\\\

Now with the box:

---------------------------
|__________________|
|__________________|
---------------------------
\\\\\\\\\\\\\\\\\\\\\\\\\\\
\ _________________\
\ _________________\
\ _________________\
\ _________________\

I hope you guys understand what I mean
Re: Sprite 0 Bug
by on (#226299)
It looks like you're setting the Y-scroll to 0 at the sprite 0 hit. That's not what you want. Set the scroll to the background position you want to see.
Re: Sprite 0 Bug
by on (#226302)
That only seems to move the box around, which is not what I meant (unless I'm doing it wrong).
Re: Sprite 0 Bug
by on (#226303)
It would help to explain exactly what your code is doing - from your description, I can only assume that you're doing a pair of writes to $2006 to point the VRAM address at the beginning of a nametable and then trying to set X/Y scroll using $2005, something which will not work because vertical scroll only updates once per frame (unless you use special tricks, like those described on the PPU scrolling wiki page).
Re: Sprite 0 Bug
by on (#226306)
It would really help if you could show us what the code around the sprite 0 hit detection looks like.
Re: Sprite 0 Bug
by on (#226307)
Thanks! It works now!
I've removed the $2006 writes and that was the problem! :D

Here's how it was

Code:
NMI
   lda #$00
   sta $2006
   sta $2006   
   sta $2005
   sta $2005   

;other NMI stuff       

sprite0
   lda #$40
.waitnospr0
   bit $2002
   bvs .waitnospr0
.waitspr0
   bit $2002
   bvc .waitspr0   
   ldx #$00
.waitscan
   inx
   cpx #$78
   bne .waitscan
   ldx #$00
   lda #$00
   sta $2006
   sta $2006   
   lda scrollh
   sta $2005
   lda scrollv
   sta $2005   
   rts