It is currently Sun Sep 23, 2018 4:15 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 33 posts ]  Go to page Previous  1, 2, 3
Author Message
PostPosted: Sun Aug 19, 2018 12:57 am 
Offline
User avatar

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 3606
Location: Mountain View, CA
tepples wrote:
This particular bubble sort routine could have been done just as easily with lda (tab),y, seeing as Y doesn't need to be saved (the next instruction overwrites it anyway), and X=$00 isn't used farther down.

I'm glad that addresses what the OP asked. :|

RIP me doing the other examples, especially if this is going to be a point of contention. If you want to see the other examples, buy the book. :D

Signed,
The Guy Who Tries To Stay On Topic and Does What Other People Politely Ask For


Top
 Profile  
 
PostPosted: Sun Aug 19, 2018 4:13 am 
Offline
Formerly WheelInventor

Joined: Thu Apr 14, 2016 2:55 am
Posts: 1779
Location: Gothenburg, Sweden
Well i learned a couple of things, so thanks for the insight!

primarily a method to sorting in 6502 (never touched that before - yes i haven't done my homework :oops: ). Sorting is quite expensive in a game context, but i'd think sorting very short lists of say 4 options could be used in ocassionally called pathfinding and action priority sequencing routines for AI for example. That could perhaps allow for less rigid, more context aware priority chains.

Let's say we want to sort 1 such sequence each for a number of actors using a loaddr pointer. Wouldn't that be the perfect occasion to use lda (sequenceTable, x)?
(that also means we can't set x to 0 just yet like in the example).

_________________
http://www.frankengraphics.com - personal NES blog


Top
 Profile  
 
PostPosted: Mon Aug 20, 2018 2:58 pm 
Offline

Joined: Wed Nov 30, 2016 4:45 pm
Posts: 112
Location: Southern California
truffly wrote:
But why would you ever need to use indexed indirect addressing with the X register? What practical purpose does this serve? There has to be some situation where this feature would prove useful, otherwise I'd assume it wouldn't be featured in the processor design. Have you ever used indexed indirect addressing in your programs? Do you think it is particularly useful, or do you think indirect indexed addressing is a better tool?

(ZP,X) is used all the time in the Forth programming language which uses a data stack in ZP that's separate from the return stack in page 1. Keeping them separate like this solves certain problems in passing stacked data to and from nested subroutines. X is used as the stack pointer. Then suppose you want to read the content of the memory pointed to by the top stack two-byte cell. Regardless of the current depth of the ZP data stack, do LDA (0,X). (We make X point to the top of the stack, not one position past it like the S register does for the hardware stack.) If you want to read the content of memory pointed to by the second-on-stack two-byte cell, it's LDA(2,X), again regardless of the current data-stack depth. You may find benefits in doing things this way in assembly language too. This, and tons more, is discussed in detail in my treatise on 6502 stacks (plural, not just the page-1 hardware stack), at http://wilsonminesco.com/stacks/ .

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 33 posts ]  Go to page Previous  1, 2, 3

All times are UTC - 7 hours


Who is online

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