Jump to content

Photo

Indirect Addressing Question


4 replies to this topic

#1 BNE Jeff OFFLINE  

BNE Jeff

    Moonsweeper

  • 385 posts
  • Location:$5787

Posted Fri May 17, 2019 2:53 PM

Good Afternoon,

 

Got an indirect addressing question I'm wondering if someone could help me with.  I'm used to doing indirect addressing by doing something like 

        lda #<(Player0Gfx)
        sta Player0Ptr
        lda #>(Player0Gfx)
        sta Player0Ptr+1

then that's the address for my graphics pointer.  Uses two bytes of RAM.  But currently, I'm working on something that has 14 graphics pointers using 28 bytes of RAM, 14 of which are the same number because its all on the same page.  Looking over lda in the 6502 guide I notice this syntax: 

Indirect,X LDA ($44,X) $A1 2 6
Indirect,Y LDA ($44),Y $B1 2 5+

It looks to me like y is an indexed lda.  But the x example looks like x might be representing the page.  Is that what its doing?  Could I just skip the Player0Ptr+1.  Then when loading graphics have something like:

 ldx #$FB  ;The page all my graphics happen to be on.
 lda (Player0Ptr,x) ; which is #<(Player0Gfx)
 sta GRP0


					
					

Edited by BNE Jeff, Fri May 17, 2019 2:55 PM.


#2 Nukey Shay OFFLINE  

Nukey Shay

    Sheik Yerbouti

  • 21,967 posts
  • Location:The land of Gorch

Posted Sat May 18, 2019 1:36 AM

Radically different address modes.

 

You know that the y register is added to the base address specified by the argument for (indirect),y.  Notice where the brackets are?

With (indirect,x) the value of x determines which base address to use from a group of base addresses.

;if $82 holds #0, $83 holds #$FF...

ldx #2

lda ($80,x)

;A is loaded from address $FF00

 

Since zero page is usually in short supply on most platforms, this address mode is far less useful than (indirect),y



#3 Nukey Shay OFFLINE  

Nukey Shay

    Sheik Yerbouti

  • 21,967 posts
  • Location:The land of Gorch

Posted Sat May 18, 2019 1:46 AM

Tho it is a handy way to burn 6 cycles in 2 bytes if you know the value of x and the contents of A are unimportant.



#4 BNE Jeff OFFLINE  

BNE Jeff

    Moonsweeper

  • Topic Starter
  • 385 posts
  • Location:$5787

Posted Sun May 19, 2019 4:57 AM

OK Thanks..  Took me a while to digest that.  So does this mode only allow a nonindexed pointer address, and only in page 0?


So in any case am I stuck with using the two bytes?



#5 Nukey Shay OFFLINE  

Nukey Shay

    Sheik Yerbouti

  • 21,967 posts
  • Location:The land of Gorch

Posted Today, 12:51 AM

Correct.

 

And yeah, you are stuck with using 2 bytes for either address mode. Tho you can usually repurpose those for temp Ram outside of the kernel...so long as you reset them before their display area(s) begin.

 

Have you looked at Alien?  That game uses a single byte for each sprite as a pointer to 2 page long data tables.  Slower than (ind),y but more Ram efficient. Another drawback is that sprites car limited to that 512-byte range instead of being allowed anywhere in Rom.






0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users