]> git.sur5r.net Git - cc65/blob - libsrc/runtime/push.s
This commit was generated by cvs2svn to compensate for changes in r2,
[cc65] / libsrc / runtime / push.s
1 ;
2 ; Ullrich von Bassewitz, 05.08.1998
3 ;
4 ; CC65 runtime: Push ints onto the stack
5 ;
6
7 ;
8 ; push/pop things on stack
9 ;
10         .export         push0, push1, push2, push3, push4, push5
11         .export         push6, push7, pusha0, pushaFF, pushax
12         .export         pusha, pushaysp, pushc0, pushc1, pushc2
13         .importzp       sp
14
15 pushaFF:
16         ldx     #$FF
17         bne     pushax
18
19 push7:  lda     #7
20         bne     pusha0
21 push6:  lda     #6
22         bne     pusha0
23 push5:  lda     #5
24         bne     pusha0
25 push4:  lda     #4
26         bne     pusha0
27 push3:  lda     #3
28         bne     pusha0
29 push2:  lda     #2
30         bne     pusha0
31 push1:  lda     #1
32         bne     pusha0
33 push0:  lda     #0
34 ;       beq     pusha0
35 pusha0: ldx     #0
36
37 ; This function is used *a lot*, so don't call any subroutines here.
38 ; Beware: The value in ax must not be changed by this function!
39 ; Beware^2: The optimizer knows about the value of Y after the function
40 ;           returns!
41
42 pushax: ldy     sp
43         beq     @L1
44         dey
45         beq     @L2
46         dey
47 @L0:    sty     sp
48         ldy     #0              ; get index
49         sta     (sp),y          ; store lo byte
50         pha                     ; save it
51         txa                     ; get hi byte
52         iny                     ; bump idx
53         sta     (sp),y          ; store hi byte
54         pla                     ; get A back
55         rts                     ; done
56
57 @L1:    dey
58 @L2:    dey
59         dec     sp+1
60         bne     @L0             ; Branch always
61
62 ; Push for chars, same warning as above: The optimizer expects the value
63 ; 0 in the Y register after this function.
64
65 pushc2: lda     #2
66         bne     pusha
67 pushc1: lda     #1
68         bne     pusha
69 pushc0: lda     #0
70         beq     pusha
71 pushaysp:            
72         lda     (sp),y
73 pusha:  ldy     sp
74         beq     @L1
75         dec     sp
76         ldy     #0
77         sta     (sp),y
78         rts
79
80 @L1:    dec     sp+1
81         dec     sp
82         sta     (sp),y
83         rts