]> git.sur5r.net Git - cc65/blob - libsrc/apple2/crt0.s
Remove the ",r" spec
[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         initlib, donelib
9         .import         zerobss, push0
10         .import         __CODE_LOAD__, __BSS_LOAD__     ; Linker generated
11         .import         _main
12
13         .include        "zeropage.inc"
14         .include        "apple2.inc"
15
16 ; ------------------------------------------------------------------------
17 ; The executable header
18
19 .segment        "EXEHDR"
20
21         .word   __CODE_LOAD__                   ; Start address
22         .word   __BSS_LOAD__ - __CODE_LOAD__    ; Size
23
24 ; ------------------------------------------------------------------------
25 ; Actual code
26
27 .code
28
29         ldx     #zpspace-1
30 L1:     lda     sp,x
31         sta     zpsave,x        ; Save the zero page locations we need
32         dex
33         bpl     L1
34
35 ; Clear the BSS data
36
37         jsr     zerobss
38
39 ; Save system stuff and setup the stack
40
41         tsx
42         stx     spsave          ; Save the system stack ptr
43
44         lda     MEMSIZE
45         sta     sp
46         lda     MEMSIZE+1
47         sta     sp+1            ; Set argument stack ptr
48
49 ; Call module constructors
50
51         jsr     initlib
52
53 ; Initialize conio stuff
54
55         lda     #$ff
56         sta     TEXTTYP
57
58 ; Set up to use Apple ROM $C000-$CFFF
59
60         ;;      sta     USEROM
61
62 ; Pass an empty command line
63
64         jsr     push0           ; argc
65         jsr     push0           ; argv
66
67         ldy     #4              ; Argument size
68         jsr     _main           ; call the users code
69
70 ; Call module destructors. This is also the _exit entry.
71
72 _exit:  jsr     donelib
73
74 ; Restore system stuff
75
76         lda     #$ff            ; Reset text mode
77         sta     TEXTTYP
78
79         ldx     spsave
80         txs                     ; Restore stack pointer
81
82 ; Copy back the zero page stuff
83
84         ldx     #zpspace-1
85 L2:     lda     zpsave,x
86         sta     sp,x
87         dex
88         bpl     L2
89
90 ; Reset changed vectors, back to basic
91
92         jmp     RESTOR
93
94
95 .data
96
97 zpsave: .res    zpspace
98
99 .bss
100
101 spsave: .res    1