The '816 uses an 8-bit register (DBR) to select the data bank which can be modified by pulling from stack with a PLB instruction. The simplest way to change bank is ..
Code:
lda #BANK(xx)
pha
plb
.. but this will only work correctly if A is in 8-bit mode. In 16-bit mode it will leave a byte on the stack. You can change the register size to make it always work and restore the size at the end.
Code:
php
sep #$20
lda #BANK(xx)
pha
plb
plp
If X register is free then you could save a copy of the stack pointer and use PEA to push the bank on to the stack and use a TSX to restore the stack at the end.
Code:
tsx
pea #BANK(xx)
plb
txs
The use of X could be avoided by putting the bank as the second byte on the stack.
Code:
pea #BANK(xx)<<8
plb
plb
Another approach would be to install a small subroutine in the data bank consisting of ..
Code:
phk
plb
rtl
.. and JSL to it to copy the program bank (PBR) into the DBR.
Any other techniques I've missed?