This code sometimes allowed an IRQ through at power. It didn't at reset if the APU mode was $80 before reset, so a game with this sort of code at reset that used mode $80 exclusively would reset reliably, even if it failed at power. I used an APU-based timer to find out how long the two VBL loops waited total and it was usually ~27331 clocks, only occasionally ~57113.
Code: Select all
reset:
: bit $2002 ; wait for VBL flag
bpl :-
: bit $2002 ; wait for VBL flag again
bpl :-
lda #$80
sta $4017
cli
sei
For whatever reason, the VBL flag was set most of the time at power today. Does the game in question sometimes fail to work on a NES until reset is pressed?
Does NMI (lda #$80 sta $2000) work predictably before 30,000 CPU cycles? Or must programs spin on $2002 and potentially miss several vblanks in a row?
A $2002 spin loop will never wait more than VBL period*2, since it can never suppress two VBL flag settings in a row. Writes to $2000 before +29658 are also ignored, so NMI can't be used immediately either. $2007 works immediately, just $2006 doesn't. So you can begin accessing VRAM $0001 upwards immediately (what PPUADDR powers up with).