Setting up a 24-bit pointer

Discussion of hardware and software development for Super NES and Super Famicom.

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 » Tue Jan 28, 2020 9:03 am

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: 1110
Joined: Tue Oct 06, 2015 10:16 am

Re: Setting up a 24-bit pointer

Post by calima » Tue Jan 28, 2020 11:18 am

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

Re: Setting up a 24-bit pointer

Post by dougeff » Tue Jan 28, 2020 11:22 am

You don't need y.

LDA [dp]

works too.
nesdoug.com -- blog/tutorial on programming for the NES

turboxray
Posts: 64
Joined: Thu Oct 31, 2019 12:56 am

Re: Setting up a 24-bit pointer

Post by turboxray » Tue Jan 28, 2020 4:08 pm

That or self modifying code and (abs.long),y addressing mode. (assuming you need an index offset).

nocash
Posts: 1201
Joined: Fri Feb 24, 2012 12:09 pm
Contact:

Re: Setting up a 24-bit pointer

Post by nocash » Tue Jan 28, 2020 8:37 pm

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: 354
Joined: Mon Apr 07, 2008 6:08 pm
Location: Missouri

Re: Setting up a 24-bit pointer

Post by strat » Tue Jan 28, 2020 11:25 pm

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 » Wed Jan 29, 2020 12:57 am

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