]> git.sur5r.net Git - cc65/blob - libsrc/apple2/crt0.s
info about c1541 in docs, lowered highest available address to $6000 due to
[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         _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 in
23 ; the standard apple2 linker config. They must be changed if sweet-16
24 ; is to be supported
25
26 .zeropage
27
28 zpstart = *
29 sp:             .res    2       ; Stack pointer
30 sreg:           .res    2       ; Secondary register/high 16 bit for longs
31 regsave:        .res    2       ; slot to save/restore (E)AX into
32 ptr1:           .res    2
33 ptr2:           .res    2
34 ptr3:           .res    2
35 ptr4:           .res    2
36 tmp1:           .res    1
37 tmp2:           .res    1
38 tmp3:           .res    1
39 tmp4:           .res    1
40 regbank:        .res    6       ; 6 byte register bank
41
42 zpspace = * - zpstart           ; Zero page space allocated
43
44 .code
45
46 ; ------------------------------------------------------------------------
47 ; Actual code
48
49         ldx     #zpspace-1
50 L1:     lda     sp,x
51         sta     zpsave,x        ; Save the zero page locations we need
52         dex
53         bpl     L1
54
55 ; Clear the BSS data
56
57         jsr     zerobss
58
59 ; Save system stuff and setup the stack
60
61         tsx
62         stx     spsave          ; Save the system stack ptr
63
64         lda     #<TOPMEM
65         sta     sp
66         lda     #>TOPMEM
67         sta     sp+1            ; Set argument stack ptr
68
69 ; Call module constructors
70
71         jsr     initlib
72
73 ; Initialize conio stuff
74
75         lda     #$ff
76         sta     TEXTTYP
77
78 ; Set up to use Apple ROM $C000-$CFFF
79
80         ;;      sta     USEROM
81
82 ; Pass an empty command line
83
84         jsr     push0           ; argc
85         jsr     push0           ; argv
86
87         ldy     #4              ; Argument size
88         jsr     _main           ; call the users code
89
90 ; Call module destructors. This is also the _exit entry.
91
92 _exit:  jsr     donelib
93                        
94 ; Restore system stuff
95
96         lda     #$ff            ; Reset text mode
97         sta     TEXTTYP
98
99         ldx     spsave
100         txs                     ; Restore stack pointer
101
102 ; Copy back the zero page stuff
103
104         ldx     #zpspace-1
105 L2:     lda     zpsave,x
106         sta     sp,x
107         dex
108         bpl     L2
109
110 ; Reset changed vectors, back to basic
111
112         jmp     RESTOR
113
114
115 .data
116
117 zpsave: .res    zpspace
118
119 .bss
120
121 spsave: .res    1