What does lda #>oam do?

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

Post Reply
User avatar
battagline
Posts: 152
Joined: Wed Sep 05, 2018 11:13 am
Location: Colorado
Contact:

What does lda #>oam do?

Post by battagline »

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:

Code: Select all

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,
Rick
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
User avatar
koitsu
Posts: 4203
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: What does lda #>oam do?

Post by koitsu »

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:

Code: Select all

  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...

Code: Select all

  lda <oam    ; equivalent to lda $20
  lda >oam    ; equivalent to lda $05
Make sense?
User avatar
battagline
Posts: 152
Joined: Wed Sep 05, 2018 11:13 am
Location: Colorado
Contact:

Re: What does lda #>oam do?

Post by battagline »

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!
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
User avatar
koitsu
Posts: 4203
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: What does lda #>oam do?

Post by koitsu »

The documentation for this feature in ca65 is here, in two places (sort of):

Expressions: https://www.cc65.org/doc/ca65-5.html#ss5.1
Pseudo functions: https://www.cc65.org/doc/ca65-10.html

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

Code: Select all

  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.
User avatar
rainwarrior
Posts: 8062
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: What does lda #>oam do?

Post by rainwarrior »

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.
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: What does lda #>oam do?

Post by tokumaru »

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.
Post Reply