When I was looking through rainwarrior's ca65 template, setting up the nametable seemed pretty straight forward. He was using the x and y register and looping 960 times doing a STA on $2007. I was able to play around with that code and thought I understood it. But when I'm trying that in the game I'm working on, it seems to only be setting the left column of background tiles.
I'm calling this proc on reset:
I'm calling this proc on reset:
Code:
.proc load_background
stx nametable_reg_x
sty nametable_reg_y
lda PPU_STATUS ; PPU_STATUS = $2002
lda #$20
sta PPU_ADDR ; PPU_ADDR = $2006
lda #$00
sta PPU_ADDR ; PPU_ADDR = $2006
ldx #32 ; start out at 0
lda #2
background_x_loop:
ldy #30
background_y_loop:
sta PPU_DATA ; PPU_DATA = $2007
dey
bpl background_y_loop ; loop until y == -1
dex
bpl background_x_loop ; loop until x == -1
ldx nametable_reg_x
ldy nametable_reg_y
rts
.endproc
stx nametable_reg_x
sty nametable_reg_y
lda PPU_STATUS ; PPU_STATUS = $2002
lda #$20
sta PPU_ADDR ; PPU_ADDR = $2006
lda #$00
sta PPU_ADDR ; PPU_ADDR = $2006
ldx #32 ; start out at 0
lda #2
background_x_loop:
ldy #30
background_y_loop:
sta PPU_DATA ; PPU_DATA = $2007
dey
bpl background_y_loop ; loop until y == -1
dex
bpl background_x_loop ; loop until x == -1
ldx nametable_reg_x
ldy nametable_reg_y
rts
.endproc