I honestly tried search for "bank" and "banking" but could not find the answer I was looking for, and there is something missing in my head to grok it.
I have imaginary mapper:
1. fixed A000-FFFF bank
2. two variable banks at 8000-BFFF.
3. write 1 or 2 at 8000-FFFF will switch banks (no bus conflicts)
4. always start at bank 1
And now I'm in the bank 1 and I want to call routine 'foo' in bank too.
Okay, so I can switch banks.
Okay, so I understand _how_ banking work, my problem is what is the optimal approach. I can come up with something like this:
But now I lost original return address. Okay, save the return address and write some king of bank_rts and switch bank to the previous bank on the return. But it seems quite cumbersome.
And as an additional trouble, I use ca65 that uses C-style linking and using '.org' is not really a right way to go. And I _must_ have my 'switch_bank' on the same address.
Does anyone have any advice on that? What are common/optimal approaches? I don't even need the code, but process. Thank you, and sorry for dumb questions here.
P.S. I would really love to have wiki page with options of how banking can be implemented.
I have imaginary mapper:
1. fixed A000-FFFF bank
2. two variable banks at 8000-BFFF.
3. write 1 or 2 at 8000-FFFF will switch banks (no bus conflicts)
4. always start at bank 1
And now I'm in the bank 1 and I want to call routine 'foo' in bank too.
Code:
jsr foo1
jsr foo2 ; <-- foo2 is in bank 2
jsr foo2 ; <-- foo2 is in bank 2
Okay, so I can switch banks.
Code:
8100: jsr foo1
8102: lda #2
8104: sta $8000
; but it will not jump to the foo2 because code at $8106
; in second bank is completely different (or it is data)
8106: jsr foo2 ; <-- foo2 is in bank 2
8102: lda #2
8104: sta $8000
; but it will not jump to the foo2 because code at $8106
; in second bank is completely different (or it is data)
8106: jsr foo2 ; <-- foo2 is in bank 2
Okay, so I understand _how_ banking work, my problem is what is the optimal approach. I can come up with something like this:
Code:
jsr foo1
ldx #<foo2-1
ldy #>foo2-1
lda #2
jsr switch_bank
.proc switch_bank:
sta tmp1
; take out return address
pla
pla
; push method address on the stack
txa
pha
tya
pha
; and return there
rts
.endproc
ldx #<foo2-1
ldy #>foo2-1
lda #2
jsr switch_bank
.proc switch_bank:
sta tmp1
; take out return address
pla
pla
; push method address on the stack
txa
pha
tya
pha
; and return there
rts
.endproc
But now I lost original return address. Okay, save the return address and write some king of bank_rts and switch bank to the previous bank on the return. But it seems quite cumbersome.
And as an additional trouble, I use ca65 that uses C-style linking and using '.org' is not really a right way to go. And I _must_ have my 'switch_bank' on the same address.
Does anyone have any advice on that? What are common/optimal approaches? I don't even need the code, but process. Thank you, and sorry for dumb questions here.
P.S. I would really love to have wiki page with options of how banking can be implemented.