| View previous topic :: View next topic |
| Author |
Message |
Master of C64


Joined: 22 Oct 2004 Age: 40 Posts: 1073 Location: Hixson, TN USA
|
Posted: Thu Nov 24, 2011 1:53 am Post subject: LDA ($ADDR), Y vs LDA ($ADDR, X) |
|
|
As I get more into my project, I am running across some issues where I am not understanding some of the idiosyncrasies of the 6502.
So, I think I understand how
works. But when would you use
Every time I google it, I get specs on the commands and not real examples of when to use it. Using it in a game situation might be helpful too.
Anyone want to give me a 1 minute explanation?
Thanks! |
|
| Back to top |
|
 |
Grandmaster of C64


Joined: 13 Jan 2003 Posts: 1965
|
Posted: Thu Nov 24, 2011 2:26 am Post subject: |
|
|
There hardly is any use of the 2nd one, that's why you hardly see any examples. |
|
| Back to top |
|
 |
Grandmaster of C64


Joined: 24 Jul 2006 Posts: 2784 Location: Mourrial esti de tabarnak
|
Posted: Thu Nov 24, 2011 5:28 am Post subject: |
|
|
AFAIK, the first one takes the value at address $ADDR, then adds Y to that value and loads it into the accumulator.
The second one takes the value at address $ADDR plus X, does not add anything to it then loads it into the accumulator.
Ergo, in the first case, Y is added to the obtained value, in the second case, X is added to the target address.
Also, I believe there is a bug with the second one should the sum of $ADDR plus X result in going to the next 256 bytes page.
Since the bug has apparently been fixed in CMOS versions of the 6502 (not that it matters too much since the 64 uses the 6510 which is NMOS only) then you can get completely different results in a 1541 drive whose CPU has been replaced during repairs.
Its also a complete bugger with VIC-20s that have a 65C02 or with CMD drives. _________________ I have a crystal ball... it is rectangular in shape, made of beige plastic with a tag on it that says Tektronix TDS 1002. |
|
| Back to top |
|
 |
Immortal Grandmaster of C64

Joined: 13 Oct 2004 Posts: 4792
|
Posted: Thu Nov 24, 2011 7:42 am Post subject: |
|
|
oh dear... _________________ |
|
| Back to top |
|
 |
Newbie

Joined: 15 Mar 2010 Age: 39 Posts: 43 Location: Canada
|
Posted: Thu Nov 24, 2011 8:38 am Post subject: |
|
|
Both these commands are 2-byte dealies meant for use with zero page locations. To use a precise example:
LDA ($FB),Y
If location $FB is 0, $FC is 4, and Y is 40, then you'll be loading the first character on the 2nd row of the screen. ($FB) points to a specific address (in this case the start of the screen) and from there, you can use Y to reach anywhere within a page's distance from that pointer. VERY useful. Simply modify $FB and/or $FC when the need arises.
LDA ($FB,X)
If location $FB is 40, $FC is 4, and X is 0, then you'll ALSO be loading the first character on the 2nd row of the screen. ($FB) still points to a specific address (in this case the start of the 2ND screen row) but that can ONLY be accessed when you're using an X index of 0.
If X=2 above, then the value fetched would be wherever ($FD) pointed to. The X is "indexed" BEFORE the pointer is looked up. This relatively useless command exists so a table of pointers can exist in zero page, with the X register used to specify which pointer we want.
This command is best left forgotten, but does have one good use: If the Y register is in use, yet you need to directly check something like ($ZP),Y assuming Y=0 (but isn't) you can use ($ZP,X) when X=0 instead. |
|
| Back to top |
|
 |
Über Groupie


Joined: 20 Oct 2011 Age: 48 Posts: 342 Location: Netherlands
|
Posted: Thu Nov 24, 2011 8:42 am Post subject: Re: LDA ($ADDR), Y vs LDA ($ADDR, X) |
|
|
| cbmeeks wrote: |
Every time I google it, I get specs on the commands and not real examples of when to use it. Using it in a game situation might be helpful too.
Anyone want to give me a 1 minute explanation?
Thanks!
|
ZeroPage Indexed Indirect is supported by quite a few instructions, but has only a few real-life applications. It allows you to setup a series of zero-page pointers to memory addresses and manipulate them using X as the index to that table.
For example you could, when switching/setting memory for the screen location, create a table of 8 addresses for 8 sprite pointers. Then you could write a generic routine to manipulate a sprite, by passing it the sprite number and desired sprite-offset.
The routine could then acces the sprite pointer through the indextable in zero-page, without knowing which bank was in use.
EDIT: Removed stuff about Absolute Indexed indirect babble.
Last edited by Mogwai on Thu Nov 24, 2011 9:05 am; edited 2 times in total |
|
| Back to top |
|
 |
Immortal Grandmaster of C64

Joined: 13 Oct 2004 Posts: 4792
|
Posted: Thu Nov 24, 2011 8:46 am Post subject: |
|
|
| Quote: | LDA ($ADDR,X) is NOT supported!
Absolute Indexed Indirect addressing only 'knows' JMP($ADDR,X) where ADDR is a 16 bit (2 byte) operand. That one is great for using Jump-tables. |
wtf _________________
|
|
| Back to top |
|
 |
Über Groupie


Joined: 20 Oct 2011 Age: 48 Posts: 342 Location: Netherlands
|
Posted: Thu Nov 24, 2011 8:47 am Post subject: |
|
|
| groepaz wrote: | | oh dear... |
 |
|
| Back to top |
|
 |
Über Groupie


Joined: 20 Oct 2011 Age: 48 Posts: 342 Location: Netherlands
|
Posted: Thu Nov 24, 2011 8:49 am Post subject: |
|
|
| groepaz wrote: | | Quote: | LDA ($ADDR,X) is NOT supported!
Absolute Indexed Indirect addressing only 'knows' JMP($ADDR,X) where ADDR is a 16 bit (2 byte) operand. That one is great for using Jump-tables. |
wtf |
I put some explanation there about zeropage/none zeropage... Probably while you wrote the reply, but:
*double checking as we speak and will edit ASAP*
I wrote the stuff about JMP($1234,X) from memory and memory can fail.
Though I just found this reference: Absolute Indexed Indirect
I can't find it in another document.
I stand corrected!
(and we should report this error to Wikipedia )
Last edited by Mogwai on Thu Nov 24, 2011 9:08 am; edited 1 time in total |
|
| Back to top |
|
 |
Immortal Grandmaster of C64

Joined: 13 Oct 2004 Posts: 4792
|
Posted: Thu Nov 24, 2011 9:04 am Post subject: |
|
|
hint:
| Quote: | | I am running across some issues where I am not understanding some of the idiosyncrasies of the 6502. |
... the 65816 has JMP(abs,x), the 6502 doesnt. _________________
|
|
| Back to top |
|
 |
Über Groupie


Joined: 20 Oct 2011 Age: 48 Posts: 342 Location: Netherlands
|
Posted: Thu Nov 24, 2011 9:07 am Post subject: |
|
|
| groepaz wrote: | hint:
| Quote: | | I am running across some issues where I am not understanding some of the idiosyncrasies of the 6502. |
... the 65816 has JMP(abs,x), the 6502 doesnt. |
Yes! That's where it must have come from. I'm getting old.... |
|
| Back to top |
|
 |
Forum Junkie

Joined: 17 Jun 2006 Posts: 544
|
Posted: Thu Nov 24, 2011 9:08 am Post subject: Re: LDA ($ADDR), Y vs LDA ($ADDR, X) |
|
|
| Mogwai wrote: |
LDA ($ADDR,X) where $ADDR is not zeropage, is NOT supported!
Absolute Indexed Indirect addressing only 'knows' JMP($ADDR,X) where ADDR is a 16 bit (2 byte) operand. That one is great for using Jump-tables.
|
Actually LDA($ZP,X) IS supported, there is no JMP($ZP,X). There are only TWO JMP addressing modes, absolute and indirect. Absolute is JMP $ADDR and indirect is JMP ($ADDR) (note there is NO X in this addressing mode) BOTH of these are 3 byte commands.
Only JMP and JSR can use the indirect addressing mode. LDA on the other hand uses (Indirect,X) and (Indirect),Y also known as Index Indirect and Indirect Indexed (yeah confusing) Both of these can ONLY use Zero Page addresses.
(Indirect, X) adds the X value FIRST then indirects.
(Indirect), Y indirects FIRST then indexes
(Indirect, X) is useful if you have a table of addresses.
(Indirect), y is useful if you have an address to a table. _________________
|
|
| Back to top |
|
 |
Forum Junkie

Joined: 17 Jun 2006 Posts: 544
|
Posted: Thu Nov 24, 2011 9:10 am Post subject: |
|
|
| Mogwai wrote: |
(and we should report this error to Wikipedia ) |
Now, if only there was SOME way to do that. Or even better if there was some way to just fix it.
Darn... I wish there was a way... _________________
|
|
| Back to top |
|
 |
Über Groupie


Joined: 20 Oct 2011 Age: 48 Posts: 342 Location: Netherlands
|
Posted: Thu Nov 24, 2011 9:17 am Post subject: |
|
|
| THEWIZ wrote: | | Mogwai wrote: |
(and we should report this error to Wikipedia ) |
Now, if only there was SOME way to do that. Or even better if there was some way to just fix it.
Darn... I wish there was a way... |
Just edited the entry... |
|
| Back to top |
|
 |
Grandmaster of C64


Joined: 24 Jul 2006 Posts: 2784 Location: Mourrial esti de tabarnak
|
Posted: Thu Nov 24, 2011 11:25 pm Post subject: |
|
|
| groepaz wrote: | | oh dear... |
This says it all about you...
I know I was wrong but instead of explaining you just make fun of my lack of knowledge.
Now...
AFAIK:
LDA ($ADDR), y
CPU looks at address $ADDR and uses the content as a 2 byte vector, adds Y to that vector, loads the content of the value stored at address (vector + Y) into the accumulator.
LDA ($ADDR, X)
CPU looks at address $ADDR + X and uses the content as a 2 byte vector, loads the content of the value stored at addres (vector) into the accumulator. _________________
I have a crystal ball... it is rectangular in shape, made of beige plastic with a tag on it that says Tektronix TDS 1002. |
|
| Back to top |
|
 |
Immortal Grandmaster of C64

Joined: 13 Oct 2004 Posts: 4792
|
Posted: Thu Nov 24, 2011 11:35 pm Post subject: |
|
|
congrats for rephrasing Lee73s post =P _________________ |
|
| Back to top |
|
 |
Grandmaster of C64


Joined: 24 Jul 2006 Posts: 2784 Location: Mourrial esti de tabarnak
|
Posted: Fri Nov 25, 2011 12:06 am Post subject: |
|
|
| groepaz wrote: | | congrats for rephrasing Lee73s post =P |
Thank you for confirming I got it right this time.
So kind and courteous of you!
People have such good manners here. _________________
I have a crystal ball... it is rectangular in shape, made of beige plastic with a tag on it that says Tektronix TDS 1002. |
|
| Back to top |
|
 |
Master of C64


Joined: 22 Oct 2004 Age: 40 Posts: 1073 Location: Hixson, TN USA
|
Posted: Sun Nov 27, 2011 3:36 am Post subject: |
|
|
Thanks to everyone for posting information. Reading posts here on Lemon for the last few days has helped me reevaluate how I am coding my project. Which means back to the drawing board for some things but at least I am understanding it more. |
|
| Back to top |
|
 |
|