How to copy 400h bytes of name table and attribute data?
I found this one in a tutorial :
But in that way the code will depend on a fixed address of name table, in the above exmple it will be $E000.
So here is my solution :
But I want to know if there is any better way?
Thanks in advance
I found this one in a 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
LDA #$00
STA <$00
LDA #$E0
STA <$01
LDY #$00 ; start out at 0
LDX #$04
LoadBackgroundLoop:
LDA [$00], y ; load data from address (background + the value in
STA $2007 ; write to PPU
INY ; Y = Y + 1
BNE LoadBackgroundLoop
INC <$01
DEX
BNE LoadBackgroundLoop
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 #$00
STA <$00
LDA #$E0
STA <$01
LDY #$00 ; start out at 0
LDX #$04
LoadBackgroundLoop:
LDA [$00], y ; load data from address (background + the value in
STA $2007 ; write to PPU
INY ; Y = Y + 1
BNE LoadBackgroundLoop
INC <$01
DEX
BNE LoadBackgroundLoop
But in that way the code will depend on a fixed address of name table, in the above exmple it will be $E000.
So here is my solution :
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
LDX #$00
nam_loop1:
LDA nam_att, X ; Load first 100 bytes of name table and attribute data
STA $2007
INX
CPX #$00 ; Loop runs 100 times
BNE nam_loop1
nam_loop2:
LDA nam_att+256, X ; Load second 100 bytes of name table and attribute data
STA $2007
INX
CPX #$00
BNE nam_loop2
nam_loop3:
LDA nam_att+512, X ; Load third 100 bytes of name table and attribute data
STA $2007
INX
CPX #$00
BNE nam_loop3
nam_loop4:
LDA nam_att+768, X ; Load forth 100 bytes of name table and attribute data
STA $2007
INX
CPX #$00
BNE nam_loop4
LDA #$20
STA $2006 ; Write the high byte of $2000 address
LDA #$00
STA $2006 ; Write the low byte of $2000 address
LDX #$00
nam_loop1:
LDA nam_att, X ; Load first 100 bytes of name table and attribute data
STA $2007
INX
CPX #$00 ; Loop runs 100 times
BNE nam_loop1
nam_loop2:
LDA nam_att+256, X ; Load second 100 bytes of name table and attribute data
STA $2007
INX
CPX #$00
BNE nam_loop2
nam_loop3:
LDA nam_att+512, X ; Load third 100 bytes of name table and attribute data
STA $2007
INX
CPX #$00
BNE nam_loop3
nam_loop4:
LDA nam_att+768, X ; Load forth 100 bytes of name table and attribute data
STA $2007
INX
CPX #$00
BNE nam_loop4
But I want to know if there is any better way?
Thanks in advance