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

Increment PPU address by a number

Increment PPU address by a number
by on (#241802)
Hello to everyone, I'm creating a new prototype for NES. I've an "action space matrix" where the player can move in 4 directions as you can see in the image.

Image

I need to change the background into the matrix at runtime with some wall sprites. The matrix PPU address start at 2103 and it end at 2376. I created a loop to change the background tile by tile, row by row:

;2103 -> 2116
;2120 -> 2136
;...
;2303 -> 2376


Code:
generate_random_walls:
  lda $2002             
  lda #$21
  sta $2006             
  lda #$03
  sta $2006             

  ldx #$00
  ldy #$00
.gen_random_walls_loop:
    lda #$C2
    sta $2007
    inx
    cpx #$14
    bne .gen_random_walls_loop

    .go_next_row:


when the loop goes to #$16 on the X register I need to "jump" from $2116 to $2120 and continue to write on PPU that auto increment by one every time. So, what's the best way to do that? I've to reset the address in this way at next row? Or there is a more efficent way?

Code:
lda $2002             
  lda #$21
  sta $2020             
  lda #$03
  sta $2006             


Thanks a lot! :)
Re: Increment PPU address by a number
by on (#241825)
User: please do not make duplicate posts. Please see this thread for details of technical problems this forum is currently encountering, which could lead to duplicate posts: viewtopic.php?f=13&t=19133

Moderator: lock thread, duplicate post reference: viewtopic.php?f=2&t=19202