Setting up a 24-bit pointer

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
simseventy
Posts: 5
Joined: Sun Oct 27, 2013 6:17 am

Setting up a 24-bit pointer

Post by simseventy »

Hi all,

A bit of advice if you please...

What's the typical way of setting up a pointer to a 24-bit address? I'm using the following method, which works well enough as far as I can tell, but I can't help but think there's a more elegant way of doing it.

Using WLA DX:

Code: Select all

lda #my_data_table  ; This resides at 01B820 in the ROM
sta my_pointer      ; Load offset of data into pointer. Pointer value = $20 $B8, so far so good.
lda #:my_data_table ; Get bank # of data
sta my_pointer + 2  ; Tack it onto the pointer, pointer now = $20 $B8 $01, great!
    
ldy #0
lda [my_pointer], y
sta my_variable     ; Works! But is there a more elegant way of setting up the pointer?
calima
Posts: 1745
Joined: Tue Oct 06, 2015 10:16 am

Re: Setting up a 24-bit pointer

Post by calima »

That is the way. If you don't want to see the extra write you could wrap it in a macro.
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: Setting up a 24-bit pointer

Post by dougeff »

You don't need y.

LDA [dp]

works too.
nesdoug.com -- blog/tutorial on programming for the NES
turboxray
Posts: 348
Joined: Thu Oct 31, 2019 12:56 am

Re: Setting up a 24-bit pointer

Post by turboxray »

That or self modifying code and (abs.long),y addressing mode. (assuming you need an index offset).
nocash
Posts: 1405
Joined: Fri Feb 24, 2012 12:09 pm
Contact:

Re: Setting up a 24-bit pointer

Post by nocash »

simseventy wrote: Tue Jan 28, 2020 9:03 am

Code: Select all

lda #my_data_table  ; This resides at 01B820 in the ROM
sta my_pointer      ; Load offset of data into pointer. Pointer value = $20 $B8, so far so good.
lda #:my_data_table ; Get bank # of data
sta my_pointer + 2  ; Tack it onto the pointer, pointer now = $20 $B8 $01, great!
That is setting up a 32bit pointer (assuming that happens to be A in 16bit mode, otherwise it won't work at all).
homepage - patreon - you can think of a bit as a bottle that is either half full or half empty
strat
Posts: 409
Joined: Mon Apr 07, 2008 6:08 pm
Location: Missouri

Re: Setting up a 24-bit pointer

Post by strat »

Couldn't it be done like

Code: Select all

sep #$20 ; 8-bit A
lda #Bank24
pha
plb	; data bank = Bank24
rep #$10 ; 16-bit X,Y or #$30 if you want 16-bit A also
ldy #Addr16
lda a:$0000,Y ; 16-bit load, we don't want to access the direct-page
This might save cycles over the "lda [dp]" method if used enough times in the loop.
simseventy
Posts: 5
Joined: Sun Oct 27, 2013 6:17 am

Re: Setting up a 24-bit pointer

Post by simseventy »

calima, dougeff, turboxray - thank you for your valuable insight, much appreciated! :)
nocash wrote: Tue Jan 28, 2020 8:37 pm That is setting up a 32bit pointer (assuming that happens to be A in 16bit mode, otherwise it won't work at all).
Of course, you are correct. With hindsight I should have phrased the topic title a little better!
strat wrote: Tue Jan 28, 2020 11:25 pm This might save cycles over the "lda [dp]" method if used enough times in the loop.
Thanks - I'll take a look at that method in detail a little later. I'm not hurting for cycles at the moment, but always interested in more efficient ways of doing things.
Post Reply