Full screen background = 1K bytes?

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
casprog
Posts: 70
Joined: Fri Oct 28, 2016 12:37 pm

Full screen background = 1K bytes?

Post by casprog »

Reading along the Nerdy Nights tutorial (awesome guide) I came across this:
When we are using nested loops to copy entire backgrounds we want 256 x 4 = 1KB
http://nintendoage.com/forum/messagevie ... adid=33274

It then shows 4 passes of 256 reads/writes.

Isn't a full screen 960 bytes? 32 x 30 tiles?

I ended up writing something that loops 256 3 times, then finishes off the stragglers for the remaining 192 bytes.

Code: Select all

    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

    LDA #LOW(StartNametable)
    STA pointerLow
    LDA #HIGH(StartNametable)
    STA pointerHigh

    LDX #$00
    LDY #$00

LoadStartNametableLoop:
        LDA [pointerLow], y
        STA $2007
        INY
        ; nametable data will hold one full screen, or 32*30 bytes
        ; we need to check our x counter to determine when to stop reading "chunks" of 256 bytes
        ; if x is 3 we have already read 3 * 256 bytes, and only need the straggler 192 bytes
        ; otherwise we keep reading until y flips again (another 256 bytes read)
        CPX #$03
        BNE StartNametableChunk
        CPY #$C0
        BNE LoadStartNametableLoop
        JMP LoadStartNametableDone
StartNametableChunk:
        CPY #$00
        BNE LoadStartNametableLoop

        INC pointerHigh
        INX
        JMP LoadStartNametableLoop
LoadStartNametableDone:
My code is not as clean looking but it seems to load it all in. Curious if I'm doing this properly. Looking at the nametable viewer seems correct.
User avatar
rainwarrior
Posts: 8062
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Full screen background = 1K bytes?

Post by rainwarrior »

Following the 960 tiles, there is 64 bytes of "attribute" data that tells it which colour palettes to use for the tiles.

https://wiki.nesdev.com/w/index.php/PPU ... ute_tables
casprog
Posts: 70
Joined: Fri Oct 28, 2016 12:37 pm

Re: Full screen background = 1K bytes?

Post by casprog »

Thanks, just to help me get my head around this, I thought originally the attribute table would hold 60 bytes since there is one byte to color a 4x4 area at 960 tiles.

Where does the extra 4 bytes come from?
User avatar
rainwarrior
Posts: 8062
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Full screen background = 1K bytes?

Post by rainwarrior »

The page I linked should show how it's laid out, but the last "row" of 8 bytes wastes half its data. So, yes, there's only 60 bytes of attribute information, but it's still spread across 64 physical bytes.
casprog
Posts: 70
Joined: Fri Oct 28, 2016 12:37 pm

Re: Full screen background = 1K bytes?

Post by casprog »

doh, I understand now. Thank you : )
Post Reply