It is currently Sat Feb 24, 2018 11:13 pm

 All times are UTC - 7 hours

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Advanced Nerdy Nights #3: a simple questionPosted: Wed Apr 26, 2017 8:15 am

Joined: Wed Apr 26, 2017 8:02 am
Posts: 4
Hi everyone,

I'm a web developer and NES gamer who suddendly started wondering how those amazing games were coded. I've been studing Nerdy Nights tutorials and I have a question about one line of code I hope someone can ask. It's the tutorial about scrolling, example 4. Code is as follows

Code:
DrawNewColumn:
LDA scroll       ; calculate new column address using scroll register
LSR A
LSR A
LSR A            ; shift right 3 times = divide by 8
STA columnLow    ; \$00 to \$1F, screen is 32 tiles wide

LDA nametable     ; calculate new column address using current nametable
EOR #\$01          ; invert low bit, A = \$00 or \$01
ASL A             ; shift up, A = \$00 or \$02
ASL A             ; \$00 or \$04
CLC
STA columnHigh    ; now address = \$20 or \$24 for nametable 0 or 1

LDA columnNumber  ; column number * 32 = column data offset
ASL A
ASL A
ASL A
ASL A
ASL A
STA sourceLow
LDA columnNumber
AND #%11111000
LSR A
LSR A
LSR A
STA sourceHigh

LDA sourceLow       ; column data start + offset = address to load column data from
CLC
STA sourceLow
LDA sourceHigh
STA sourceHigh

DrawColumn:
LDA #%00000100        ; set to increment +32 mode
STA \$2000

LDA \$2002             ; read PPU status to reset the high/low latch
LDA columnHigh
STA \$2006             ; write the high byte of column address
LDA columnLow
STA \$2006             ; write the low byte of column address
LDX #\$1E              ; copy 30 bytes
LDY #\$00
DrawColumnLoop:
LDA [sourceLow], y
STA \$2007
INY
DEX
BNE DrawColumnLoop

RTS

It took me two hours to figure it out but I've still a question. The line I don't understand is this one near the bottom:

LDA [sourceLow], y

The question is:
Why sourceHigh is not used (only sourceLow is being used) to fetch background tiles in DrawColumnLoop ?

Maybe I don't understand the code but previously you add #LOW(columnData) to sourceLow and #HIGH(columnData) to sourceHigh to get the address but then I see that only sourceLow is being used.

Any reply would be really appreciated. Thanks to all!

Top

 Post subject: Re: Advanced Nerdy Nights #3: a simple questionPosted: Wed Apr 26, 2017 8:24 am

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10305
Location: Rio de Janeiro - Brazil
viktor77 wrote:
Why sourceHigh is not used (only sourceLow is being used) to fetch background tiles in DrawColumnLoop ?

It's implicit. You only need to tell the CPU where the lower byte of the pointer is, and it knows that the next byte contains the rest of the pointer. Both bytes are being used but since pointers are always contiguous the instruction only needs to indicate where the pointer starts.

Top

 Post subject: Re: Advanced Nerdy Nights #3: a simple questionPosted: Wed Apr 26, 2017 8:28 am

Joined: Wed Apr 26, 2017 8:02 am
Posts: 4
Thank you tokumaru for such a quick and accurate answer! Now I can keep on, thanks again!

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 3 posts ]

 All times are UTC - 7 hours

#### Who is online

Users browsing this forum: Google [Bot] and 1 guest

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

Search for:
 Jump to:  Select a forum ------------------ NES / Famicom    NESdev    NESemdev    NES Graphics    NES Music    Homebrew Projects       2017 NESdev Competition       2016 NESdev Competition       2014 NESdev Competition       2011 NESdev Competition    Newbie Help Center    NES Hardware and Flash Equipment       Reproduction    NESdev International       FCdev       NESdev China       NESdev Middle East Other    General Stuff    Membler Industries    Other Retro Dev       SNESdev       GBDev    Test Forum Site Issues    phpBB Issues    Web Issues    nesdevWiki