6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Jul 05, 2024 2:55 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Fri May 17, 2019 7:06 pm 
Offline

Joined: Wed Apr 10, 2019 7:46 pm
Posts: 3
So I'm trying to do lda SPCData1, x, where SPCData1 is a label to data that starts at address $048000 (unfortunately that can't be moved around).

When I look at the disassembly however, I see lda $8000,x, and it gets the data at $008000. Basically, it's accessing the wrong bank

According to this 65816 reference, I can fix this if I take the DBR and fill it with a value of $04. There doesn't seem to be a way to transfer a value directly to the DBR, but it seems that what I can do is:
    1. Put the value $04 into A (which is in 8-bit mode)
    2. Push A onto the stack
    3. Pull from the stack into DBR.

After that, lda SPCData1, x should get the right data.

Of course, I would want to restore the original value of the DBR as well so as to not affect any of the other loads and stores in the program, so I would wrap the sequence I just described with another push and pull.

Thus, the code I think would look something like this:

Code:
    ...
    phb                     ; Back up the DBR
    lda     #$04            ; Put new value in DBR
    pha                 
    plb     
    lda     SPCData1, x     ; Get the correct byte
    plb                     ; Restore original DBR value
    ...


I've tried this code out and it seems to work, but is my implementation inefficient?

Even if my code achieves what I want, I would rather want to know if there is a more efficient way to accomplish my goals (and it never hurts to learn something new :wink: ).


Top
 Profile  
Reply with quote  
PostPosted: Fri May 17, 2019 7:22 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1696
Location: Sacramento, CA
Use the AL (Absolute Long),x address mode with LDA, opcode $BF.

The object code would look like this:
BF 00 80 04

No need to play with the DBR.

Your assembler and disassembler would need to support 65816 opcodes. You could also use .db or similar directives to stuff it into the source manually.

Daryl

_________________
Please visit my website -> https://sbc.rictor.org/


Top
 Profile  
Reply with quote  
PostPosted: Fri May 17, 2019 7:49 pm 
Offline

Joined: Wed Apr 10, 2019 7:46 pm
Posts: 3
I looked up that addressing mode in the 65816 manual, and if I were accessing a raw address I could do something like lda $048000, x

But it's not quite clear how to do the same with a label. What does the syntax look like? I'm using the ca65 assembler if it's specific to that.

Also, I probably should've included this in the context, but that lda is actually inside a loop, and the manual says "it is more efficient to use the shorter sixteen-bit addressing modes, provided that the data bank register has been appropriately set".

So speed wise, would it be better to modify the DBR since that lda is called like 2^16 times?


Top
 Profile  
Reply with quote  
PostPosted: Fri May 17, 2019 8:23 pm 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
rchoudhary wrote:
Also, I probably should've included this in the context, but that lda is actually inside a loop, and the manual says "it is more efficient to use the shorter sixteen-bit addressing modes, provided that the data bank register has been appropriately set".

So speed wise, would it be better to modify the DBR since that lda is called like 2^16 times?

Well, then, "yes", "of course". At a minimum you're going from a 4 byte instruction down to a 3 byte one. There's "25% increase" right there.

Just look at the cycle count differences of the instructions you're using to discern which would be better.


Top
 Profile  
Reply with quote  
PostPosted: Fri May 17, 2019 9:43 pm 
Offline

Joined: Thu Apr 11, 2019 12:31 pm
Posts: 33
In CA65 I think you can prefix the label with f: for a far address.


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

All times are UTC


Who is online

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