]> git.sur5r.net Git - cc65/blob - libsrc/atmos/crt0.s
Force an import of the special symbol __STARTUP__ in the C compiler when
[cc65] / libsrc / atmos / crt0.s
1 ;
2 ; Startup code for cc65 (Oric version)
3 ;
4 ; By Debrune Jérôme <jede@oric.org> and Ullrich von Bassewitz <uz@cc65.org>
5 ;
6
7         .export         _exit
8         .export         __STARTUP__ : absolute = 1      ; Mark as startup
9         .import         initlib, donelib
10         .import         callmain, zerobss
11         .import         __RAM_START__, __RAM_SIZE__, __BSS_LOAD__
12
13         .include        "zeropage.inc"
14         .include        "atmos.inc"
15
16
17 ; ------------------------------------------------------------------------
18 ; Oric tape header
19
20 .segment        "TAPEHDR"
21
22         .byte   $16, $16, $16   ; Sync bytes
23         .byte   $24             ; End of header marker
24
25         .byte   $00                             ; $2B0
26         .byte   $00                             ; $2AF
27         .byte   $80                             ; $2AE Machine code flag
28         .byte   $C7                             ; $2AD Autoload flag
29         .dbyt   __BSS_LOAD__                    ; $2AB
30         .dbyt   __RAM_START__                   ; $2A9
31         .byte   $00                             ; $2A8
32         .byte   $00                             ; Zero terminated name
33
34 ; ------------------------------------------------------------------------
35 ; Place the startup code in a special segment.
36
37 .segment        "STARTUP"
38
39 ; Save the zero page area we're about to use
40
41         ldx     #zpspace-1
42 L1:     lda     sp,x
43         sta     zpsave,x        ; Save the zero page locations we need
44         dex
45         bpl     L1
46
47 ; Clear the BSS data
48
49         jsr     zerobss
50
51 ; Unprotect columns 0 and 1
52
53         lda     STATUS
54         sta     stsave
55         and     #%11011111
56         sta     STATUS
57
58 ; Save system stuff and setup the stack
59
60         tsx
61         stx     spsave          ; save system stk ptr
62
63         lda     #<(__RAM_START__ + __RAM_SIZE__)
64         sta     sp
65         lda     #>(__RAM_START__ + __RAM_SIZE__)
66         sta     sp+1            ; Set argument stack ptr
67
68 ; Call module constructors
69
70         jsr     initlib
71
72 ; Push arguments and call main()
73
74         jsr     callmain
75
76 ; Call module destructors. This is also the _exit entry.
77
78 _exit:  jsr     donelib         ; Run module destructors
79
80 ; Restore system stuff
81
82         ldx     spsave
83         txs
84         lda     stsave
85         sta     STATUS
86
87 ; Copy back the zero page stuff
88
89         ldx     #zpspace-1
90 L2:     lda     zpsave,x
91         sta     sp,x
92         dex
93         bpl     L2
94
95 ; Back to BASIC
96
97         rts
98
99 ; ------------------------------------------------------------------------
100 ; Data
101
102 .segment        "ZPSAVE"
103
104 zpsave: .res    zpspace
105
106 .bss
107 spsave: .res    1
108 stsave: .res    1
109
110