]> git.sur5r.net Git - cc65/blob - libsrc/atmos/crt0.s
cb1b5a14eabd6a45ddf9638f4583fad8e0f9de33
[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         push0, callmain, zerobss
12         .import         __RAM_START__, __RAM_SIZE__     ; Linker generated
13
14         .importzp       sp
15
16 ; ------------------------------------------------------------------------
17 ; Create an empty LOWCODE segment to avoid linker warnings
18
19 .segment        "LOWCODE"
20
21 ; ------------------------------------------------------------------------
22 ; Place the startup code in a special segment.
23
24 .segment        "STARTUP"
25
26 ; Clear the BSS data
27
28         jsr     zerobss
29
30 ; Save system stuff and setup the stack
31
32         tsx
33         stx     spsave          ; save system stk ptr
34
35         lda     #<(__RAM_START__ + __RAM_SIZE__)
36         sta     sp
37         lda     #>(__RAM_START__ + __RAM_SIZE__)
38         sta     sp+1            ; Set argument stack ptr
39
40 ; Call module constructors
41
42         jsr     initlib
43
44 ; Push arguments and call main()
45
46         jsr     callmain
47
48 ; Call module destructors. This is also the _exit entry.
49
50 _exit:  jsr     donelib         ; Run module destructors
51
52 ; Restore system stuff
53
54         ldx     spsave
55         txs
56
57 ; Back to BASIC
58
59         rts
60
61 ; ------------------------------------------------------------------------
62 ; Data
63
64 .bss
65 spsave: .res    1
66
67