Namtable woes

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
User avatar
battagline
Posts: 152
Joined: Wed Sep 05, 2018 11:13 am
Location: Colorado
Contact:

Namtable woes

Post by battagline »

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:

Code: Select all

.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
Attachments
nesteroids.nes
Notice the left column has the letter 'B' which is tile #2 in my CHR
(40.02 KiB) Downloaded 126 times
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: Namtable woes

Post by dougeff »

Are you sure PPU control $2000 is set to +1 mode and not +32 mode?

xxxx x0xx

This bit should be zero.
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
battagline
Posts: 152
Joined: Wed Sep 05, 2018 11:13 am
Location: Colorado
Contact:

Re: Namtable woes

Post by battagline »

dougeff wrote:Are you sure PPU control $2000 is set to +1 mode and not +32 mode?

xxxx x0xx

This bit should be zero.
It was set to 0 because I'm writing to PPU Address $2000. Is that not right?

Thanks
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
User avatar
battagline
Posts: 152
Joined: Wed Sep 05, 2018 11:13 am
Location: Colorado
Contact:

Re: Namtable woes

Post by battagline »

dougeff wrote:Are you sure PPU control $2000 is set to +1 mode and not +32 mode?

xxxx x0xx

This bit should be zero.
Actually you were right. I was setting $2000 to #%10011100 earlier than I thought I was.

Thanks!
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
Post Reply