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

Setting position with $2006 not working

Setting position with $2006 not working
by on (#49332)
Hello again.

I seem to be getting along quite nicely in my first nesdev adventure. However, I'm having some trouble. I am trying to display some bg characters by writing to $2007. It seems to be working ok, but I can't seem to be able to set the position. I try writing the offsets to $2006 just before but it doesn't seem to have any effect (or not have the right effect at all) on the position of the characters. Is there something special I need to keep in mind while I do this?

by on (#49333)
Where do you want to position them?

If you wanted, say, to draw a tile that we'll number $10 in the middle of the screen twice, you'd want to do this:

LDA #$21 ;PPU will start at $21AF, which is around the center of the screen...
STA $2006
LDA #$AF
STA $2006

LDA #$10 ;Write the tile twice to have 2 $10's appearing
STA $2007
STA $2007

by on (#49334)
This is pretty much what I'm doing right now. I'm using Blargg's example from this thread as a basis: http://nesdev.com/bbs/viewtopic.php?t=4860 but when I do the $2006 sets, it doesn't seem to work. It just always displays in the topleft.

by on (#49336)
Ok, so I added

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


After doing the writes to $2006 and how it's working. What exactly does writing two 0s to $2005 do?

by on (#49338)
The writes to $2005 reset the VRAM address such that (0, 0) is scrolled into the top left corner. Ordinarily, you shouldn't write to $2005 until AFTER all writes to $2006 and $2007 for this frame:
Code:
nmi:
  inc retraces
  pha
  txa
  pha
  ; [...]
  lda #$21
  sta PPUADDR
  lda #$AF
  sta PPUADDR
  lda #$01
  sta PPUDATA
  lda #$02
  sta PPUDATA
  ; [...]
  lda #0
  sta PPUSCROLL
  sta PPUSCROLL
  ; [...]
  pla
  tax
  pla
  rti