It is currently Wed Nov 22, 2017 9:56 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Fri Aug 11, 2017 9:29 pm 
Offline

Joined: Fri Oct 28, 2016 12:37 pm
Posts: 15
Reading along the Nerdy Nights tutorial (awesome guide) I came across this:
Quote:
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:
    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.


Top
 Profile  
 
PostPosted: Fri Aug 11, 2017 9:42 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5825
Location: Canada
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_attribute_tables


Top
 Profile  
 
PostPosted: Fri Aug 11, 2017 10:07 pm 
Offline

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


Top
 Profile  
 
PostPosted: Fri Aug 11, 2017 10:13 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5825
Location: Canada
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.


Top
 Profile  
 
PostPosted: Fri Aug 11, 2017 10:20 pm 
Offline

Joined: Fri Oct 28, 2016 12:37 pm
Posts: 15
doh, I understand now. Thank you : )


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group