I have been putting together my first game project, and have run into a slight graphical glitch. From what I read, all writes to VRAM should be executed during vblank, and in most emulators the code I have works.. I tried the game in nestopia. When I perform a hard reset (power on/off, or on load), occasionally one or two garbage tiles appear on-screen. Also, in PAL mode (or any mode where the top 8 scanlines are visible), the second entry in pattern table appears 100% of the time in the top left corner (bg is supposed to be disabled). The first entry in PT is a blank, and there are three entries total. My startup code looks something like this (compiler is nesasm):
cld ; clear decimal flag
sei ; disable interrupts
ldx #$FF ; ensure stack is pointing to top
stx $2001 ; this SHOULD disable the PPU during startup
; clear $0000-$07FF in RAM.
sta [$00],y ; clear $100 bytes
;Initialize the Palette
;clear out $0000-$1FFF in VRAM
tiles: ; setup the pattern table
lda tileset, y
lda initdata, y
sta P1.PX, y
lda initsprites, y
sta P1A.Y, y
;!Initialize the PPU!
lda #%10000000 ;NMI on Vblank on!
lda #%00010100 ;sprites on, no clipping
Other than the glitch on startup, the game otherwise functions normally.