gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/libc/targets/mos6502/far_ptr.s
1 .module far_ptr
2
3 .include "global.s"
4 .include "mapper_macros.s"
5
6 .area GBDKOVR (PAG, OVR)
7 _to_far_ptr_PARM_2:: .ds 2
8
9 .area _ZP
10 ___call_banked_ptr::
11 ___call_banked_addr:: .ds 2
12 ___call_banked_bank:: .ds 2
13
14 .area _HOME
15
16 _to_far_ptr::
17 ; XA is input 16-bit offset
18 ; XA is also 16-bit return value -> nothing to move for lower 16 bits
19 ; Move bank number
20 ldy *_to_far_ptr_PARM_2
21 sty *___SDCC_m6502_ret2
22 ; Upper byte always zero - but could be used by calling function expecting int32
23 ldy #0x00
24 sty *___SDCC_m6502_ret3
25 rts
26
27 ___call__banked::
28 ; save potential function parameter in A
29 sta *.tmp
30 ; Save old bank on stack
31 lda *__current_bank
32 pha
33 ; Set new bank
34 lda *___call_banked_bank
35 sta *__current_bank
36 SWITCH_PRG0_A
37 ; restore potential function parameter to A
38 lda *.tmp
39 ; Perform banked call
40 jsr 1$
41 ; Returned from banked call
42 ; save potential function return value in A
43 sta *.tmp
44 ; pull old bank and switch back
45 pla
46 sta *__current_bank
47 SWITCH_PRG0_A
48 ; restore potential function return value to A
49 lda *.tmp
50 rts
51 1$:
52 jmp [*___call_banked_addr]
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.