]> git.sur5r.net Git - cc65/blob - libsrc/runtime/leave.s
few 6502 and some 65SC02 optimizations
[cc65] / libsrc / runtime / leave.s
1 ;  
2 ; Ullrich von Bassewitz, 06.08.1998
3 ; Christian Krueger, 11-Mar-2017, added 65SC02 optimization
4 ;
5 ; CC65 runtime: function epilogue
6 ;
7
8 ; exit a function.  pop stack and rts. The function comes in different
9 ; flavours that provide default values for the return val, or drop a local
10 ; stack frame with size in y.
11
12         .export         leave00, leave0, leavey00, leavey0, leavey
13         .export         leave
14         .import         addysp
15         .importzp       sp
16
17         .macpack        cpu
18
19 leave00:
20         lda     #0
21 leave0: ldx     #0
22         beq     leave
23
24 leavey00:
25         lda     #0              ; "return 0"
26 leavey0:
27         ldx     #0              ; return < 256
28 leavey:
29         jsr     addysp          ; drop stack frame
30
31 .if (.cpu .bitand ::CPU_ISET_65SC02)
32
33 leave:  tay                     ; save A a sec
34         lda     (sp)            ; that's the pushed arg size
35         sec                     ; Count the byte, the count's stored in
36         adc     sp
37         sta     sp
38         bcc     L1
39         inc     sp+1
40 L1:     tya                     ; Get return value back
41
42 .else
43
44 leave:  pha                     ; save A a sec
45         ldy     #0
46         lda     (sp),y          ; that's the pushed arg size
47         sec                     ; Count the byte, the count's stored in
48         adc     sp
49         sta     sp
50         bcc     L1
51         inc     sp+1
52 L1:     pla                     ; Get return value back
53
54 .endif
55         rts
56