I know a bit of programming, but I'm new to ASM. I'm starting to understand the logic behind it.
I'm currently learning with the Nerdy Nights tutorial, and the NESASM3 assembler.
However, I'm confused when it comes to loading the background for my game (or actually, when it comes to anything handling 16-bit addresses with 8-bit registers, but let's stick to BG loading for now).
I found a few codes for loading BG, some of which I got to work, but I can't understand how they work.
I'm currently using this code:
Code: Select all
(...)
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 pointerLo ; put the low byte of the address of background into pointer
LDA #HIGH(background)
STA pointerHi ; put the high byte of the address into pointer
LDX #$00 ; start at pointer + 0
LDY #$00
OutsideLoop:
InsideLoop:
LDA [pointerLo], y ; copy one background byte from address in pointer plus Y
STA $2007 ; this runs 256 * 4 times
INY ; inside loop counter
CPY #$00
BNE InsideLoop ; run the inside loop 256 times before continuing down
INC pointerHi ; low byte went 0 to 256, so high byte needs to be changed now
INX
CPX #$04
BNE OutsideLoop ; run the outside loop 256 times before continuing down
(...)
.bank 1
.org $E000
background:
.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 ;;row 1
.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 ;
(...)
.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 ;;row 30
.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 ;
Could you tell me what "#HIGH(background)" means? I think it gets the high byte of the address of the first value after the "background" label, but i'm not sure.
And why "LDA [pointerLo], y" has "pointerLo" in []?
Also, is the "INC pointerHi" instruction of any use, since pointerHi isn't recalled elsewhere?
And why is the .org $E000 instruction important? If I remove it, I just get a grey screen, but from what I understand, the "#HIGH(background)" should make it useless.
So, if anyone could let me see this a little better, it would be awesome.
Thanks