]> git.sur5r.net Git - cc65/blob - libsrc/atmos/crt0.s
removed some duplicated GEOS conio stuff
[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 ; This must be the *first* file on the linker command line
7 ;
8
9         .export         _exit
10         .import         initlib, donelib
11         .import         callmain, zerobss
12         .import         __RAM_START__, __RAM_SIZE__, __RAM_LAST__
13
14         .include        "zeropage.inc"
15         .include        "atmos.inc"
16
17
18 ; ------------------------------------------------------------------------
19 ; Create an empty LOWCODE segment to avoid linker warnings
20
21 .segment        "LOWCODE"
22
23 ; ------------------------------------------------------------------------
24 ; Oric tape header
25
26 .segment        "TAPEHDR"
27
28         .byte   $16, $16, $16   ; Sync bytes
29         .byte   $24             ; End of header marker
30
31         .byte   $00                             ; $2B0
32         .byte   $00                             ; $2AF
33         .byte   $80                             ; $2AE Machine code flag
34         .byte   $C7                             ; $2AD Autoload flag
35         .dbyt   __RAM_START__ + __RAM_LAST__    ; $2AB
36         .dbyt   __RAM_START__                   ; $2A9
37         .byte   $00                             ; $2A8
38         .byte   $00                             ; Zero terminated name
39
40 ; ------------------------------------------------------------------------
41 ; Place the startup code in a special segment.
42
43 .segment        "STARTUP"
44
45 ; Save the zero page area we're about to use
46
47         ldx     #zpspace-1
48 L1:     lda     sp,x
49         sta     zpsave,x        ; Save the zero page locations we need
50         dex
51         bpl     L1
52
53 ; Clear the BSS data
54
55         jsr     zerobss
56
57 ; Unprotect columns 0 and 1
58
59         lda     STATUS
60         sta     stsave
61         and     #%11011111
62         sta     STATUS
63
64 ; Save system stuff and setup the stack
65
66         tsx
67         stx     spsave          ; save system stk ptr
68
69         lda     #<(__RAM_START__ + __RAM_SIZE__)
70         sta     sp
71         lda     #>(__RAM_START__ + __RAM_SIZE__)
72         sta     sp+1            ; Set argument stack ptr
73
74 ; Call module constructors
75
76         jsr     initlib
77
78 ; Push arguments and call main()
79
80         jsr     callmain
81
82 ; Call module destructors. This is also the _exit entry.
83
84 _exit:  jsr     donelib         ; Run module destructors
85
86 ; Restore system stuff
87
88         ldx     spsave
89         txs
90         lda     stsave
91         sta     STATUS
92
93 ; Copy back the zero page stuff
94
95         ldx     #zpspace-1
96 L2:     lda     zpsave,x
97         sta     sp,x
98         dex
99         bpl     L2
100
101 ; Back to BASIC
102
103         rts
104
105 ; ------------------------------------------------------------------------
106 ; Data
107
108 .data
109
110 zpsave: .res    zpspace
111
112 .bss
113 spsave: .res    1
114 stsave: .res    1
115
116