It is currently Mon May 20, 2019 8:09 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sat Mar 02, 2019 7:09 am 
Offline

Joined: Sun Jan 02, 2011 9:58 pm
Posts: 13
Hi, I'm trying to plan out some stuff for my game but I'm away from my computer this weekend so I'm doing pseudo-code on paper for now. I've got a couple of quick questions about certain opcodes that I don't 100% understand after reading the opcode reference docs.

TXS & TSX:

Do these function the same PHA & PLA, the opcode reference makes it seem like they don't but I'm not sure. I think PHA decrements the stack pointer & copies the value of A into that memory location, vice versa for pull A. Do TXS & TSX work like that or do they just copy data to/from the current stack pointer location without changing the stack pointer?

Indexed Indirect vs Indirect Indexed:

I'm not sure I understand how Indexed Indirect works. Indirect indexed I think I understand works as follows:

Let's say myPointer is at $0000,$0001 and storing the address $6000, and Y is $01.
LDA (myPointer), y
So that is then looking at memory location $6001 and loading it into A.

Let's say myPointer is at $0000,$0001, and X is $02.
LDA (myPointer, x)
Is that looking at $0002,$0003. Then treating the values stored there as a pointer, looking at wherever they point to and loading it into A? That's what the reference reads like to me, but I'm not sure if that's what's actually going on.


Top
 Profile  
 
PostPosted: Sat Mar 02, 2019 7:46 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 11345
Location: Rio de Janeiro - Brazil
While PHA and PLA deal with the contents of the stack, TXS and TSX deal with the stack pointer, which is a register the indicates where the top of the stack is. As a beginner, you'll hardly ever manipulate the stack pointer besides initializing it to $FF at the beginning of the program. Stack manipulation is necessary in advanced programming techniques you shouldn't be concerned about for now.

Your understanding of Indirect indexed is correct. Indexed Indirect addressing is hardly used by anyone. Most 6502 programmers even question the reason for its existence at one point or another. You got it right, though. It lets you use a table of pointers in ZP, but the only real world example of that being useful that most NES programmers can think of is pointing to the individual tracks of a song in a music engine.


Top
 Profile  
 
PostPosted: Sat Mar 02, 2019 7:56 am 
Offline

Joined: Sun Jan 02, 2011 9:58 pm
Posts: 13
Thank you very much for the clarifications.


Top
 Profile  
 
PostPosted: Sun Mar 03, 2019 10:31 pm 
Offline

Joined: Wed Nov 30, 2016 4:45 pm
Posts: 135
Location: Southern California
tokumaru wrote:
ect. Indexed Indirect addressing is hardly used by anyone. Most 6502 programmers even question the reason for its existence at one point or another. You got it right, though. It lets you use a table of pointers in ZP, but the only real world example of that being useful that most NES programmers can think of is pointing to the individual tracks of a song in a music engine.

(zp,X) is used constantly in the Forth programming language, for accessing memory whose address is on the data stack, where X is the stack pointer. The data stack, which is ZP-resident to get not only the efficiency but also the extra addressing modes, is in a sense an array. It is not a table. Although a (X) addressing mode would be interesting (as would (A) and (Y)), some of the occurrences of (DP,X) having the base address are other than 0, some being 2 and some being 4, for accessing the 2nd or 3rd cell on the stack. Top of stack is accessed by (0,X). So far, I've had no reason to go further, like (6,X) etc. like I have with DP,X (which is not indirect). The page-1 hardware stack is still used for return addresses, and, on occasion, temporary data storage too. Forth's habit of keeping the data stack separate from the return stack solves certain problems and streamlines operations.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources


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

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 4 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