NESDev and Strangulation Records messageboards
Forum Index | FAQ | New User | Login | Search

Previous ThreadView All ThreadsNext Thread*Show in Threaded Mode


Subjectgarbage tiles on startup new  
Posted bynimling
Posted on9/27/03 06:51 AM
From IP35.12.17.175  



hello,

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):

main:

cld ; clear decimal flag
sei ; disable interrupts
ldx #$FF ; ensure stack is pointing to top
txs
inx

jsr waitvb
stx $2000
stx $2001 ; this SHOULD disable the PPU during startup

; clear $0000-$07FF in RAM.
ldy #$07
sty <$01
lda #$00
sta <$00

clr_ram:
sta [$00],y ; clear $100 bytes
dey
bne clr_ram

dec <$01
bpl clr_ram

;Initialize the Palette

lda #$3f
sta $2006
lda #$00
sta $2006
tay
do_pal:
lda palette,y
sta $2007
iny
cpy #$20
bne do_pal

;clear out $0000-$1FFF in VRAM
lda #0
sta $2006
sta $2006
ldy #$20
cleartiles1:
ldx #0
cleartiles2:
sta $2007
inx
bne cleartiles2
dey
bne cleartiles1

tiles: ; setup the pattern table
lda #0
sta $2006
sta $2006

ldy #0
tiles1:
lda tileset, y
sta $2007
iny
cpy #$30
bne tiles1

inits:
ldy #0
inits1:
lda initdata, y
sta P1.PX, y
lda initsprites, y
sta P1A.Y, y
iny
cpy #$10
bne inits1

lda #7
sta $4014

jsr waitvb
;!Initialize the PPU!
lda #%10000000 ;NMI on Vblank on!
sta $2000
lda #%00010100 ;sprites on, no clipping
sta $2001
cli

-----

Other than the glitch on startup, the game otherwise functions normally.




SubjectRe: garbage tiles on startup new  
Posted byMemblers
Posted on9/27/03 08:06 AM
From IP68.58.99.218  



You've forgotten to clear all the nametable memory. (VRAM $2000-$2FFF) It's easy to overlook, since most emulators will clear it for you. (I'm guilty of this as well sometimes, heheh)

Also, a few more things to note (which are also very easy to miss when testing in an emulator):
Set the sprite RAM address before doing the sprite DMA. (LDA #0 / STA $2003) You'll probably want to do the sprite DMA during the NMI or main loop also (if done during the NMI, bear in mind that it costs 512 CPU cycles), I've heard some NES models lose their sprite-RAM contents if it's not refreshed for a while.

What's the CLI for? You'll need to set $4017 depending on your IRQ source. Another little obscure feature. I know #$C0 should be written to it if you're using internal IRQs (like from the DPCM channel), and I think it should be #$00 if you're using IRQs from a mapper.

I hope that helps, and good luck with your game. :-)




SubjectRe: garbage tiles on startup new  
Posted byMemblers
Posted on9/27/03 08:10 AM
From IP68.58.99.218  



Also, I forgot to mention something.

The stuff you're seeing in the top-left corner are the sprites. If the sprite-RAM is all zeros, and there is a tile #0 in the pattern table, then all those sprites will be displayed and crammed into the corner up there. (X and Y position zero)




SubjectRe: garbage tiles on startup  
Posted byMemblers
Posted on9/27/03 08:15 AM
From IP68.58.99.218  



Oh yeah, ONE MORE THING, heheh.

Do this at the beginning (after the SEI/CLD)

wait:
lda $2002
bpl wait

wait2:
lda $2002
bpl wait2

All games do that, I guess it gives the PPU some time to warm up or something. And I just noticed you said your tile #0 in the pattern table is blank, so all I can say is use FCEUltra and look at your sprite memory ($0700-$07FF apparantly), then you should see what's up with it.




SubjectRe: garbage tiles on startup new  
Posted bynimling
Posted on9/27/03 3:51 PM
From IP35.12.24.236  



Thanks! It works perfectly now.




Previous ThreadView All ThreadsNext Thread*Show in Threaded Mode
Jump to

Memblers' homepage             Contact Me

Forums powered by WWWThreads Demo