Hey fellow nesdevers.
I'm a little confused about the filling of the nametables.
I was following Roth's nerdy nights tutorial where he shows how to load a background like this:
Edit: It's Bunnyboy's nerdy nights tutorial.
And I was thinking "That's allot of Duplicate $24's. Why don't I write those in a loop to $2007.
I Tried it and It worked.
But then I thought the following: "What if I hardly want anything on the background layer and it would mostly be filled with $00's?"
So I tried the following:
This works but it "Moves" the entire nametable up until when I load the first tile.
I have to do this:
After the loop has ended to make it appear in the right spot.
I should be happy that it works and I am but I'm just curious to why this is?
I'm a little confused about the filling of the nametables.
I was following Roth's nerdy nights tutorial where he shows how to load a background like this:
Edit: It's Bunnyboy's nerdy nights tutorial.
Code:
LoadBackground:
LDA $2002 ; read PPU status to reset the high/low latch
LDA #$20
STA $2006 ; write the high byte of $2000 address
LDA #$00
STA $2006 ; write the low byte of $2000 address
LDX #$00 ; start out at 0
LoadBackgroundLoop:
LDA background, x ; load data from address (background + the value in x)
STA $2007 ; write to PPU
INX ; X = X + 1
CPX #$80 ; Compare X to hex $80, decimal 128 - copying 128 bytes
BNE LoadBackgroundLoop ; Branch to LoadBackgroundLoop if compare was Not Equal to zero
; if compare was equal to 128, keep going down
.nametable:
.db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
.db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky ($24 = sky)
.db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 2
.db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
.db $24,$24,$24,$24,$45,$45,$24,$24,$45,$45,$45,$45,$45,$45,$24,$24 ;;row 3
.db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$53,$54,$24,$24 ;;some brick tops
.db $24,$24,$24,$24,$47,$47,$24,$24,$47,$47,$47,$47,$47,$47,$24,$24 ;;row 4
.db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$55,$56,$24,$24 ;;brick bottoms
LDA $2002 ; read PPU status to reset the high/low latch
LDA #$20
STA $2006 ; write the high byte of $2000 address
LDA #$00
STA $2006 ; write the low byte of $2000 address
LDX #$00 ; start out at 0
LoadBackgroundLoop:
LDA background, x ; load data from address (background + the value in x)
STA $2007 ; write to PPU
INX ; X = X + 1
CPX #$80 ; Compare X to hex $80, decimal 128 - copying 128 bytes
BNE LoadBackgroundLoop ; Branch to LoadBackgroundLoop if compare was Not Equal to zero
; if compare was equal to 128, keep going down
.nametable:
.db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
.db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky ($24 = sky)
.db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 2
.db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
.db $24,$24,$24,$24,$45,$45,$24,$24,$45,$45,$45,$45,$45,$45,$24,$24 ;;row 3
.db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$53,$54,$24,$24 ;;some brick tops
.db $24,$24,$24,$24,$47,$47,$24,$24,$47,$47,$47,$47,$47,$47,$24,$24 ;;row 4
.db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$55,$56,$24,$24 ;;brick bottoms
And I was thinking "That's allot of Duplicate $24's. Why don't I write those in a loop to $2007.
I Tried it and It worked.
But then I thought the following: "What if I hardly want anything on the background layer and it would mostly be filled with $00's?"
So I tried the following:
Code:
LDA $2002 ; read PPU status to reset the high/low latch
LDA #$21
STA $2006 ; write the high byte of $21AF address (The location of where I want the background image to be)
LDA #$AF
STA $2006
STA $2007
/* Then use the same background loading loop as in the first example to fill till I got the desired about of tiles I want. */
LDA #$21
STA $2006 ; write the high byte of $21AF address (The location of where I want the background image to be)
LDA #$AF
STA $2006
STA $2007
/* Then use the same background loading loop as in the first example to fill till I got the desired about of tiles I want. */
This works but it "Moves" the entire nametable up until when I load the first tile.
I have to do this:
Code:
LDA $2002 ; read PPU status to reset the high/low latch
LDA #$20
STA $2006
LDA #$00
STA $2006
STA $2007
LDA #$20
STA $2006
LDA #$00
STA $2006
STA $2007
After the loop has ended to make it appear in the right spot.
I should be happy that it works and I am but I'm just curious to why this is?