NintendoAge http://nintendoage.com/forum/ -Sqooner Nerdy Nights week 8 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=33274 2014-04-02T18:40:48 -05.00 bunnyboy 24 ]]> Nerdy Nights week 8 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=33274 2014-04-02T13:51:35 -05.00 bunnyboy 24 Originally posted by: thefox

Originally posted by: Mega Mario Man

Thanks 3GenGames and thefox! It makes a bit more sense now. Don't have the full grasp of the [] yet, but what 3Gen mentions make sense to me.
Here's an example:

Let's say the memory (RAM) is laid out as follows:
Address    Value
-------    -----
$0010      $12
$0011      $34
$0066      $78
$3468      $9A
Let's also start with Y = $56 for the sake of the example.

Now, LDA $10,Y would load A from the address $10+Y = $10+$56 = $66, so A = $78.

If you do LDA [$10],Y, 6502 first fetches a 16-bit address from memory at $10 and $11. The address, in this case, is $3412 (6502 is little-endian, meaning the low byte of address is stored first in memory). It then takes that address and adds Y to it. Result is $3412 + Y = $3412 + $56 = $3468. Finally, it fetches the byte from this address, so in this case, A = $9A.

Note that even though you can use a 16-bit address with the LDA aaaa,Y addressing mode, LDA (aa),Y only accepts 8-bit addresses (in other words, the address must be on the zero page).

Also note that many other assemblers use the notation LDA ($10),Y for the exact same thing that is LDA [$10],Y in NESASM.

Finally note that names like pointerLo, pointerHi, background, etc. are just fancy names for memory addresses to make the code easier to write and understand. In this case, you could create symbols like pointerLo=$10 and pointerHi=$11, but I left them out to make the example easier to grasp. The pointers I get, I have used them in other languages. In the case of #HIGH(background), I wasn't for sure if background was a term that NES 6502 knew itself or was it actually refering to the subroutine holding the background data.

I like your example showing the difference betweem LDA [$10],Y and LDA $10,Y. Visualizing the results is a perfect way to explain this. In fact, I really don't understand a lot of the tutorials until I dig into the source code from the tutorial and change values. Then I can see the results of what I just changed in the emulator. That's when the light bulb turns on!

'm very much a visual learner as opposed to reading. Seeing the code on screen and reading the explanations of what it does confuses me. Actually tinkering with the code and checking the results is where I learn the most.


]]>
Nerdy Nights week 8 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=33274 2014-04-02T13:05:09 -05.00 bunnyboy 24 Originally posted by: Mega Mario Man

Thanks 3GenGames and thefox! It makes a bit more sense now. Don't have the full grasp of the [] yet, but what 3Gen mentions make sense to me. Here's an example:

Let's say the memory (RAM) is laid out as follows:
Address    Value
-------    -----
$0010      $12
$0011      $34
$0066      $78
$3468      $9A
Let's also start with Y = $56 for the sake of the example.

Now, LDA $10,Y would load A from the address $10+Y = $10+$56 = $66, so A = $78.

If you do LDA [$10],Y, 6502 first fetches a 16-bit address from memory at $10 and $11. The address, in this case, is $3412 (6502 is little-endian, meaning the low byte of address is stored first in memory). It then takes that address and adds Y to it. Result is $3412 + Y = $3412 + $56 = $3468. Finally, it fetches the byte from this address, so in this case, A = $9A.

Note that even though you can use a 16-bit address with the LDA aaaa,Y addressing mode, LDA (aa),Y only accepts 8-bit addresses (in other words, the address must be on the zero page).

Also note that many other assemblers use the notation LDA ($10),Y for the exact same thing that is LDA [$10],Y in NESASM.

Finally note that names like pointerLo, pointerHi, background, etc. are just fancy names for memory addresses to make the code easier to write and understand. In this case, you could create symbols like pointerLo=$10 and pointerHi=$11, but I left them out to make the example easier to grasp. ]]>
Nerdy Nights week 8 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=33274 2014-04-01T09:18:48 -05.00 bunnyboy 24 Nerdy Nights week 8 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=33274 2014-04-01T08:12:37 -05.00 bunnyboy 24 Originally posted by: Mega Mario Man

Is there a correct time to use #LOW(background) instead of #$00, or are they the same? In this case it doesn't matter much, because the code expects the lowbyte to be $00, otherwise it doesn't work. But it would be preferable to use LOW(background) for clarity. In some assemblers you can define an ASSERT, so that if "background" is moved to some other place and is no more aligned to a 256-byte page, the code would no longer compile (which lets you know that there's a problem and you have to fix it).

LOW() and HIGH() are NESASM specific operations, other assemblers most often use <background and >background for the same purpose ("<" = low, ">" = high).

]]>
Nerdy Nights week 8 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=33274 2014-03-31T17:22:45 -05.00 bunnyboy 24
2: [] addressing mode means "Look at where zeropage (variable name in []) points to and adds Y to it. The INC doesn't need brackets because we don't care wtf it points to, it just need to be incremented so our data is pulled right from the pointer location. Pointer is a 2 byte variable. low and high attached just say which byte it is we are accessing, with the low byte being the pointer it's self. ]]>
Nerdy Nights week 8 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=33274 2014-03-31T17:18:28 -05.00 bunnyboy 24
Question(s) 1: In the line of "LDA #HIGH(background)", can I assume that #HIGH and (background) is understood by the system? Did we tell the system to understand this in our code somewhere or does it just know? Is there a correct time to use #LOW(background) instead of #$00, or are they the same?

Question 2: The brackets [] are confusing me around the pointerLo. Why does that pointer get brackets and pointerHi not? I keep reading the Indirect Indexed Mode, but I get more confused each time.

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 ]]>
Nerdy Nights week 8 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=33274 2013-08-15T14:48:57 -05.00 bunnyboy 24
Updating background tiles with the screen on (during vblank) is only needed if you're updating some sort of gameplay background graphics while one is playing the game. ]]>
Nerdy Nights week 8 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=33274 2013-08-15T11:36:13 -05.00 bunnyboy 24 Originally posted by: Mario's Right Nut

Originally posted by: LucasWeatherby

Originally posted by: Mario's Right Nut

Or, simply switch off the background and do it all at once.


I was under the impression you couldnt change the entire background in one NMI?
Not in NMI, but if you turn off the background, you can do whatever you want. 

It's buried in here or one of my other tutorials somewhere.

http://nintendoage.com/forum/messageview.cfm?catid=22&th...
 
Hmm... I have yet to go thru your tutorials. I was hoping to finish with this tutorial 8 and then start fresh with yours. It appears that they build onto eachother. Should I just save my question until I make it through all of your tutorials? I have the pong game almost completely finished besides having a title screen and a game over screen...

]]>
Nerdy Nights week 8 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=33274 2013-08-15T10:37:36 -05.00 bunnyboy 24 Originally posted by: LucasWeatherby

Originally posted by: Mario's Right Nut

Or, simply switch off the background and do it all at once.


I was under the impression you couldnt change the entire background in one NMI? Not in NMI, but if you turn off the background, you can do whatever you want. 

It's buried in here or one of my other tutorials somewhere.

http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=38605

]]>