It is currently Mon Oct 23, 2017 9:19 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Sat Apr 29, 2017 9:13 am 
Offline
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1405
When I use indirect addressing, I usually have a pointer variable and the Y register as an offset index:
Code:
LDA (Pointer), Y

Is there any way to omit the Y register?

I'd like to be able to do something like this:
Code:
LDA (Pointer)

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

Is this the only way or is there a better way to use indirect addressing without an offset?

_________________
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg


Top
 Profile  
 
PostPosted: Sat Apr 29, 2017 9:18 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19122
Location: NE Indiana, USA (NTSC)
The other way is to develop for the Lynx (65C02), TurboGrafx-16 (HuC6280), or Super NES (65816) instead.


Top
 Profile  
 
PostPosted: Sat Apr 29, 2017 9:33 am 
Offline
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1405
So, on 6502, there's no way to shorten this expression?

_________________
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg


Top
 Profile  
 
PostPosted: Sat Apr 29, 2017 9:37 am 
Offline
User avatar

Joined: Fri Nov 19, 2004 7:35 pm
Posts: 3944
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!


Top
 Profile  
 
PostPosted: Sat Apr 29, 2017 9:52 am 
Offline
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1405
Nah, that wouldn't be an alternative.

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

Thanks.

_________________
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg


Top
 Profile  
 
PostPosted: Sat Apr 29, 2017 2:48 pm 
Offline

Joined: Wed Nov 30, 2016 4:45 pm
Posts: 89
Location: Southern California
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


Top
 Profile  
 
PostPosted: Sat Apr 29, 2017 2:57 pm 
Offline

Joined: Wed May 19, 2010 6:12 pm
Posts: 2295
Self-modifying code.


Top
 Profile  
 
PostPosted: Sat Apr 29, 2017 4:54 pm 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 1787
Location: DIGDUG
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


Top
 Profile  
 
PostPosted: Sun Apr 30, 2017 5:22 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19122
Location: NE Indiana, USA (NTSC)
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?


Top
 Profile  
 
PostPosted: Sun Apr 30, 2017 8:16 am 
Offline
User avatar

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: Bing [Bot] and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group