It is currently Fri Nov 15, 2019 3:01 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Fri Oct 18, 2019 10:01 am 
Offline
User avatar

Joined: Mon Sep 29, 2014 3:28 pm
Posts: 11
This is what I put together in order to clear the nametable then copy over some bytes. I'm wondering what improvements could be made by someone who actually knows what they are doing.

Code:
.PROC LoadBackgroundNametable
    ;first clear nametable ram
    lda _PPUSTATUS
    lda #$20
    sta _PPUADDR
    lda #$00
    sta _PPUADDR
    ldy #$00
  loadBackgroundNametableClearRAMLoopY:
    ldx #$00
  loadBackgroundNametableClearRAMLoopX:
    lda #$24
    sta _PPUDATA
    inx
    cpx #30
    bne loadBackgroundNametableClearRAMLoopX
    iny
    cpy #32
    bne loadBackgroundNametableClearRAMLoopY
    ; begin copying nametable bytes
    lda _PPUSTATUS
    lda #$20
    sta _PPUADDR
    lda #$00
    sta _PPUADDR
    ldx #$00
  loadBackgroundNametableLoop:
    lda _NAMETABLE, x
    sta _PPUDATA
    inx
    cpx #32    ; copy 32 bytes
    bne loadBackgroundNametableLoop

    rts

.ENDPROC


Top
 Profile  
 
PostPosted: Fri Oct 18, 2019 11:23 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 7629
Location: Canada
1. You seem to be setting rows of 30 tiles to 0 at a time? NES' background is 32 x 30, not 30 x 32. Not that it matters, since either way multiplies to 960, but conceptually this looks strange.

2. You're not setting the attribute bytes which determine which colours those tiles use. Normally when clearing the nametable you want to write a full 1024 bytes of 0 or whatever fill value you're using.

A common way to do that is have X count 256 times in an inner loop and and Y count 4 times in an outer loop (4 * 256 = 1024).

It's okay to think of it as 32 x 30 tiles + 64 extra bytes of attribute, and fine to write code that treats it that way, but it's often more expedient just to think of it as one contiguous block of memory.


Last edited by rainwarrior on Fri Oct 18, 2019 12:06 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Fri Oct 18, 2019 11:27 am 
Offline
User avatar

Joined: Tue Feb 27, 2018 10:41 am
Posts: 62
Location: Brazil
A short version for clear only the name table:
Code:
   lda #CLEAR_VALUE
   ldx #0
   ldy #>($3C0)
clear_page:
   sta PPUDATA
   inx
   bne clear_page
   dey
   bne clear_page
   ldy #<($3C0)
clear_frag:
   sta PPUDATA
   dey
   bne clear_frag


or to clear NT within Attribute Table:
Code:
   lda #CLEAR_VALUE
   ldx #0
   ldy #4 ; 4x256
clear_all:
   sta PPUDATA
   inx
   bne clear_all
   dey
   bne clear_all


If you gonna redraw the entire name table theres no need to clear it first.

_________________
itch.io | github


Top
 Profile  
 
PostPosted: Sat Oct 19, 2019 1:38 am 
Offline
User avatar

Joined: Mon Sep 29, 2014 3:28 pm
Posts: 11
thank you both, that was really helpful to read through. there's something amusing to me about how much more succinct and elegant your solutions are.

i think from now on i will take the advice of treating as a 1024 byte contiguous block of memory instead of how i was handling it before.


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

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 7 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