Increment PPU address by a number

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

Locked
User avatar
kikutano
Posts: 111
Joined: Sat May 26, 2018 6:14 am
Location: Italy

Increment PPU address by a number

Post by kikutano » Thu Aug 15, 2019 8:05 am

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: Select all

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: Select all

lda $2002             
  lda #$21
  sta $2020             
  lda #$03
  sta $2006             
Thanks a lot! :)

User avatar
koitsu
Posts: 4217
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: Increment PPU address by a number

Post by koitsu » Thu Aug 15, 2019 3:19 pm

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

Locked