Indirect addressing without index possible?

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

Post Reply
User avatar
DRW
Posts: 2225
Joined: Sat Sep 07, 2013 2:59 pm

Indirect addressing without index possible?

Post by DRW »

When I use indirect addressing, I usually have a pointer variable and the Y register as an offset index:

Code: Select all

LDA (Pointer), Y
Is there any way to omit the Y register?

I'd like to be able to do something like this:

Code: Select all

LDA (Pointer)
But it tells me it's an illegal addressing mode, so I have to circumvent it with:

Code: Select all

LDY #0
LDA (Pointer), Y
Is this the only way or is there a better way to use indirect addressing without an offset?
My game "City Trouble":
Gameplay video: https://youtu.be/Eee0yurkIW4
Download (ROM, manual, artworks): http://www.denny-r-walter.de/city.html
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Indirect addressing without index possible?

Post by tepples »

The other way is to develop for the Lynx (65C02), TurboGrafx-16 (HuC6280), or Super NES (65816) instead.
User avatar
DRW
Posts: 2225
Joined: Sat Sep 07, 2013 2:59 pm

Re: Indirect addressing without index possible?

Post by DRW »

So, on 6502, there's no way to shorten this expression?
My game "City Trouble":
Gameplay video: https://youtu.be/Eee0yurkIW4
Download (ROM, manual, artworks): http://www.denny-r-walter.de/city.html
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Indirect addressing without index possible?

Post by Dwedit »

Pretty much nope. Unless you'd rather use X=0 and use the (nn,X) addressing mode (which is slower) instead.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
DRW
Posts: 2225
Joined: Sat Sep 07, 2013 2:59 pm

Re: Indirect addressing without index possible?

Post by DRW »

Nah, that wouldn't be an alternative.

Alright, looks like I have to keep doing it the old way.

Thanks.
My game "City Trouble":
Gameplay video: https://youtu.be/Eee0yurkIW4
Download (ROM, manual, artworks): http://www.denny-r-walter.de/city.html
Garth
Posts: 246
Joined: Wed Nov 30, 2016 4:45 pm
Location: Southern California
Contact:

Re: Indirect addressing without index possible?

Post by Garth »

The 65c02 (CMOS) has the (ZP) addressing mode (ie, without the indexing); but something you can do for the NMOS 6502, if the code is in RAM instead of ROM, is to do self-modifying code where you make the pointer variable be the operand of the instruction itself. This has the added benefits of speed and of saving precious ZP space.
http://WilsonMinesCo.com/ lots of 6502 resources
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Re: Indirect addressing without index possible?

Post by psycopathicteen »

Self-modifying code.
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: Indirect addressing without index possible?

Post by dougeff »

psycopathicteen is right. You can have a short subroutine in the RAM...

LDA $0000 ;absolute
RTS

To change the pointer, you overwrite the absolute address.

Then, you JSR here to get the value.
nesdoug.com -- blog/tutorial on programming for the NES
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Indirect addressing without index possible?

Post by tepples »

But you also have only 2048 bytes of RAM. When is preserving Y worth 4 bytes of RAM and the 12-cycle overhead of a JSR/RTS pair?
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Indirect addressing without index possible?

Post by tokumaru »

Unless you can store the whole subroutine/loop in RAM (so that JSR/RTS aren't executed repeatedly), it's better to just backup Y in ZP, load it with 0, do the indirect access and restore Y, with a total overhead of 8 cycles, instead of 12.
Post Reply