]> git.sur5r.net Git - cc65/blob - libsrc/apple2/crt0.s
This commit was generated by cvs2svn to compensate for changes in r2,
[cc65] / libsrc / apple2 / crt0.s
1 ;
2 ; Startup code for cc65 (Apple2 version)
3 ;
4 ; This must be the *first* file on the linker command line
5 ;
6
7         .export         _exit
8         .import         __hinit
9         .import         zerobss, push0, doatexit
10         .import         _main
11
12         .include         "apple2.inc"
13
14 ; ------------------------------------------------------------------------
15 ; Define and export the ZP variables for the C64 runtime
16
17         .exportzp       sp, sreg, regsave
18         .exportzp       ptr1, ptr2, ptr3, ptr4
19         .exportzp       tmp1, tmp2, tmp3, tmp4
20         .exportzp       regbank, zpspace
21
22 ; These zero page entries overlap with the sweet-16 registers.
23 ; must be changed if sweet-16 is to be supported
24 sp      =       $00             ; stack pointer
25 sreg    =       $02             ; secondary register/high 16 bit for longs
26 regsave =       $04             ; slot to save/restore (E)AX into
27 ptr1    =       $08             ;
28 ptr2    =       $0A
29 ptr3    =       $0C
30 ptr4    =       $0E
31 tmp1    =       $10
32 tmp2    =       $11
33 tmp3    =       $12
34 tmp4    =       $13
35 regbank =       $14             ; 6 byte register bank
36 zpspace =       $1A             ; Zero page space allocated
37
38 ; ------------------------------------------------------------------------
39 ; Actual code
40
41         ldy     #zpspace-1
42 L1:     lda     sp,y
43         sta     zpsave,y        ; Save the zero page locations we need
44         dey
45         bpl     L1
46
47 ; Clear the BSS data
48
49         jsr     zerobss
50
51 ; Save system stuff and setup the stack
52
53         tsx
54         stx     spsave          ; Save the system stack ptr
55
56         lda     #<TOPMEM
57         sta     sp
58         lda     #>TOPMEM
59         sta     sp+1            ; Set argument stack ptr
60
61 ; Initialize the heap
62
63         jsr     __hinit
64
65 ; Initialize conio stuff
66
67         lda     #$ff
68         sta     TEXTTYP
69
70 ; Set up to use Apple ROM $C000-$CFFF
71
72         ;;      sta     USEROM
73
74 ; Pass an empty command line
75
76         jsr     push0           ; argc
77         jsr     push0           ; argv
78
79         ldy     #4              ; Argument size
80         jsr     _main           ; call the users code
81
82 ; fall thru to exit...
83
84 _exit:
85         lda     #$ff
86         sta     TEXTTYP
87
88         jsr     doatexit        ; call exit functions
89
90         ldx     spsave
91         txs                     ; Restore stack pointer
92
93 ; Copy back the zero page stuff
94
95         ldy     #zpspace-1
96 L2:     lda     zpsave,y
97         sta     sp,y
98         dey
99         bpl     L2
100
101 ; Reset changed vectors, back to basic
102
103         jmp     RESTOR
104
105
106 .data
107
108 zpsave: .res    zpspace
109
110 .bss
111
112 spsave: .res    1