So I'm trying my hand at sprite-0 hit detection but I instantly run into a problem. It seems my loop for detecting the hit only branches on the correct scanline (32, though the OAM Y value is set to 28) the very first frame I test for it. After that it always branches when on scanline 246.
What am I missing? I'm testing this on a "clean" slate so to say. That is I'm not doing this in my game project, as it would make solving the issue even harder.
Here's the source for my NMI routine. I've attached my test rom as well.
Setting a break point at C116 should show you where the branch happens.
Thanks for reading this!
Code: Select all
NMI: pha txa pha tya pha ldx #0 stx PPUMASK ; disable rendering lda #<(OAM_buffer) ; load OAM buffer into PPU sta PPUOAMADDR lda #>(OAM_buffer) sta OAMDMA lda #%10010000 ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1 sta PPUCTRL lda #%00011110 ; enable sprites, enable background, no clipping on left side, emphasis on blue sta PPUMASK @wait_sprite0: lda PPUSTATUS and #%01000000 beq @wait_sprite0 ; TODO: We've hit sprite 0. now do something. ; for some reason, this only seems to hit the right scanline the very first time. ; after that, it's always at around 246. what am I doing wrong? inc frame_cnt ; inc frame_cnt to get out of waitNMI loop. pla tay pla tax pla rti