This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

What does lda #>oam do?

What does lda #>oam do?
by on (#225121)
So I was looking through some code that was posted on this forum. I can't remember who's code it was (sorry about that), but there was list accumulator load:

lda #>oam

What does the #> mean. I've been googling around for it, but I just can't seem to find it anywhere.

Thanks for your help,
Re: What does lda #>oam do?
by on (#225124)
It depends on the assembler, so you should always refer to your assembler documentation.

>thing usually means "get the high byte of thing". Likewise, <thing means "get the low byte of thing". The # obviously means immediate addressing, thus the accumulator will end up holding the high (or low) byte of wherever thing is located. The high and low bytes are calculated at assemble-time, not run-time. Better demonstrated with pseudocode, I suppose:

Assume oam is a variable that resides somewhere -- say in RAM, at address $0520. Thus:

  lda #<oam   ; equivalent to lda #$20
  lda #>oam   ; equivalent to lda #$05

Likewise, if you were to not use immediate addressing, and had this instead...
  lda <oam    ; equivalent to lda $20
  lda >oam    ; equivalent to lda $05

Make sense?
Re: What does lda #>oam do?
by on (#225126)
Ok, that makes sense. I've been looking through the documentation online, and just haven't been able to find it listed. I'm using ca65 btw.

Thanks for your help!
Re: What does lda #>oam do?
by on (#225128)
The documentation for this feature in ca65 is here, in two places (sort of):

Pseudo functions:

With regards to the latter, in ca65 you can alternately say this, which may make more sense to you:

  lda #.hibyte(oam)   ; same as lda #>oam
  lda #.lobyte(oam)   ; same as lda #<oam

Note that it's lobyte, not lowbyte (i.e. no "w" in "low").

The "shorthand" syntax is what a lot of assemblers have used for the past ~40 years.
Re: What does lda #>oam do?
by on (#225129)
If the next line is sta #4014 (or sta OAMDMA) you might also need to know that oam has to be aligned to a single page (i.e. <oam =$00) to work properly with the DMA hardware accessed by writing the high byte of its address to $4014.
Re: What does lda #>oam do?
by on (#225147)
Most people use $0200-$02FF as their OAM buffer, but you can use any page of RAM (or even ROM!) for that purpose. Naming that array, as you would any other variable, allows you to access the OAM buffer by name, instead of by address, and lda #>oam will get the page number for the buffer, which can be used to start an OAM DMA.

The advantage of doing it that way is that if you ever decide to move the OAM buffer to another page, you just need to change the variable declaration, because the sprite routines and the DMA code are not using hardcoded addresses.