6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Sep 21, 2024 2:35 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Thu Jan 17, 2019 3:26 pm 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
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?

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 18, 2019 1:28 am 
Offline

Joined: Mon May 21, 2018 8:09 pm
Posts: 1462
What this really boils down to is a reliable way of putting an arbitrary 8-bit value on the stack. If you usually use 16-bit indexes and 8-bit accumulator mode, then LDA, PHA, PLB will work fine.

If for some reason you don't know what mode you're in but the desired bank number is stored in RAM, then you can use LDA, PHA, PLB, PHB, PLA to leave the stack consistent. Or use an index register if you prefer. Incidentally this would also work on a big-endian machine, as long as stack and general RAM were accessed with the same byte order.

Of course, you could also just construct a 3-byte address in zero page and indirect through it. In some cases that could result in shorter code, though it'd probably also be slower.


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 18, 2019 9:54 am 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
Yes. its a shame DBR doesn't have any transfer opcodes associate with it. I quite like PEA/PLB/PLB as it doesn't affect any of A, X, Y or P.

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


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

All times are UTC


Who is online

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