]> git.sur5r.net Git - cc65/blob - libsrc/atari/crt0.s
Don't save and restore the zero page locations used.
[cc65] / libsrc / atari / crt0.s
1 ;
2 ; Startup code for cc65 (ATARI version)
3 ;
4 ; Contributing authors:
5 ;       Mark Keates
6 ;       Freddy Offenga
7 ;       Christian Groessler
8 ;       Stefan Haubenthal
9 ;
10
11         .export         _exit
12         .export         __STARTUP__ : absolute = 1      ; Mark as startup
13
14         .import         initlib, donelib
15         .import         callmain, zerobss
16         .import         __STARTUP_LOAD__, __BSS_LOAD__
17         .import         __RESERVED_MEMORY__
18
19         .include        "zeropage.inc"
20         .include        "atari.inc"
21
22 ; ------------------------------------------------------------------------
23 ; EXE header
24
25 .segment        "EXEHDR"
26
27         .word   $FFFF
28         .word   __STARTUP_LOAD__
29         .word   __BSS_LOAD__ - 1
30
31 ; ------------------------------------------------------------------------
32 ; Actual code
33
34 .segment        "STARTUP"
35
36         rts     ; fix for SpartaDOS / OS/A+
37                 ; they first call the entry point from AUTOSTRT and
38                 ; then the load addess (this rts here).
39                 ; We point AUTOSTRT directly after the rts.
40
41 ; Real entry point:
42
43 ; Clear the BSS data
44
45         jsr     zerobss
46
47 ; Setup the stack
48
49         tsx
50         stx     spsave
51
52 ; Report memory usage
53
54         lda     APPMHI
55         sta     appmsav                 ; remember old APPMHI value
56         lda     APPMHI+1
57         sta     appmsav+1
58
59         sec
60         lda     MEMTOP
61         sbc     #<__RESERVED_MEMORY__
62         sta     APPMHI                  ; initialize our APPMHI value
63         sta     sp                      ; setup runtime stack part 1
64         lda     MEMTOP+1
65         sbc     #>__RESERVED_MEMORY__
66         sta     APPMHI+1
67         sta     sp+1                    ; setup runtime stack part 2
68
69 ; Call module constructors
70
71         jsr     initlib
72
73 ; Set left margin to 0
74
75         lda     LMARGN
76         sta     old_lmargin
77         ldy     #0
78         sty     LMARGN
79
80 ; Set keyb to upper/lowercase mode
81
82         ldx     SHFLOK
83         stx     old_shflok
84         sty     SHFLOK
85
86 ; Initialize conio stuff
87
88         dey                             ; Set X to $FF
89         sty     CH
90
91 ; Push arguments and call main
92
93         jsr     callmain
94
95 ; Call module destructors. This is also the _exit entry.
96
97 _exit:  jsr     donelib         ; Run module destructors
98
99 ; Restore system stuff
100
101         ldx     spsave
102         txs                     ; Restore stack pointer
103
104 ; Restore left margin
105
106         lda     old_lmargin
107         sta     LMARGN
108
109 ; Restore kb mode
110
111         lda     old_shflok
112         sta     SHFLOK
113
114 ; Restore APPMHI
115
116         lda     appmsav
117         sta     APPMHI
118         lda     appmsav+1
119         sta     APPMHI+1
120
121 ; Turn on cursor
122
123         ldx     #0
124         stx     CRSINH
125
126 ; Back to DOS
127
128         rts
129
130 ; *** end of main startup code
131
132 ; ------------------------------------------------------------------------
133
134 .bss
135
136 spsave:         .res    1
137 appmsav:        .res    1
138 old_shflok:     .res    1
139 old_lmargin:    .res    1
140
141
142 .segment "AUTOSTRT"
143         .word   RUNAD                   ; defined in atari.inc
144         .word   RUNAD+1
145         .word   __STARTUP_LOAD__ + 1