gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/libc/targets/mos6502/nes/sdcc_bcall.s
1 .include "global.s"
2 .include "mapper_macros.s"
3
4 .define .tempA "(REGTEMP+7)"
5
6 ;
7 ; Banked call support function.
8 ;
9 ;
10 ; For a banked call to function "func", sdcc will generate the following sequence:
11 ;
12 ; jsr __sdcc_bcall <-- Call to this support function
13 ; .db b_func <-- Bank of func
14 ; .dw func-1 <-- Address of func - 1.
15 ;
16 ___sdcc_bcall::
17 ; save potential function parameter in A
18 sta *.tempA
19 ; Store old return address to *.tmp, and add +3 to return address on stack (to skip parameters)
20 pla
21 sta *.tmp
22 clc
23 adc #3
24 tay
25 pla
26 sta *.tmp+1
27 adc #0
28 pha
29 tya
30 pha
31 ; Save old bank on stack
32 lda *__current_bank
33 pha
34 ; Perform banked call
35 jsr 2$
36 ; Returned from banked call
37 sta *.tempA
38 pla
39 sta *__current_bank
40 SWITCH_PRG0_A
41 ; restore potential function return value to A
42 lda *.tempA
43 ; Return to original bank
44 rts
45 2$:
46 ldy #0x03
47 ; Read address (stored after jsr ___sdcc_bcall and bank number)
48 lda [*.tmp],y
49 pha
50 dey
51 lda [*.tmp],y
52 pha
53 dey
54 ; Read bank number (stored after jsr ___sdcc_bcall)
55 lda [*.tmp],y
56 ; Switch bank
57 sta *__current_bank
58 SWITCH_PRG0_A
59 ; restore potential function parameter to A
60 lda *.tempA
61 ; Jump to banked function via RTS
62 rts
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.