I'm detemriend to leearn this in the minimal time I have available right now.
Looking at Nerdy Night Tutorial Week 6, it shows the following image:
Looking at the code, I see the entire background is loaded via this code:
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
Can someone please explain this to me? How does it know to get the specific coin image for the background? How does it know to loop the entire background?
Then I see the top 4 rows of sky and bricks are loaded with this code:
Code:
.org $E000
palette:
.db $22,$29,$1A,$0F, $22,$36,$17,$0F, $22,$30,$21,$0F, $22,$27,$17,$0F ;;background palette
.db $22,$1C,$15,$14, $22,$02,$38,$3C, $22,$1C,$15,$14, $22,$02,$38,$3C ;;sprite palette
sprites:
;vert tile attr horiz
.db $80, $32, $00, $80 ;sprite 0
.db $80, $33, $00, $88 ;sprite 1
.db $88, $34, $00, $80 ;sprite 2
.db $88, $35, $00, $88 ;sprite 3
background:
.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
.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
attribute:
.db %00000000, %00010000, %01010000, %00010000, %00000000, %00000000, %00000000, %00110000
.db $24,$24,$24,$24, $47,$47,$24,$24 ,$47,$47,$47,$47, $47,$47,$24,$24 ,$24,$24,$24,$24 ,$24,$24,$24,$24, $24,$24,$24,$24, $55,$56,$24,$24 ;;brick bottoms
I see it loads the palettes which will be used, I get that.
How does it know which sprites are loaded from memory? If they're all just loaded from a single .chr file, how is it getting one complete sprite at a time and not pulling random chunks from the file? How does it know specifically where that specific sprite's boundaries are within that .chr file to pull the correct data?
This is the most confusing part for me, the background section. How is this loaded exactly? Is it a full row of sky, another full row of sky, then a row with some brick tops and a row with some brick bottoms? I tried changing some of the $24 in row 3 to $45 but it didn't give me random brick tops instead of sky, the ROM never changed how it looked at all. I still had the same sky and bricks, nothing was different. Why? I even added a fifth row of brick bottoms and it didn't change anything, why? I'm assuming if I put the correct address reference for a sprite there, it'll put that piece of sprite on the screen in that position. Is that wrong?
Thanks again, this is really helping a lot.