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
).