]> git.sur5r.net Git - cc65/blob - libsrc/telestrat/crt0.s
atari5200: name conio constructor 'initconio'
[cc65] / libsrc / telestrat / 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
10         .import         initlib, donelib
11         .import         callmain, zerobss
12         .import         __MAIN_START__, __MAIN_SIZE__
13
14         .include        "zeropage.inc"
15         .include        "telestrat.inc"
16
17 ; ------------------------------------------------------------------------
18 ; Place the startup code in a special segment.
19
20 .segment        "STARTUP"
21
22         tsx
23         stx     spsave          ; Save system stk ptr
24
25 ; Save space by putting some of the start-up code in a segment
26 ; that will be re-used.
27
28         jsr     init
29
30 ; Clear the BSS variables (after the constructors have been run).
31
32         jsr     zerobss
33
34 ; Push the command-line arguments; and, call main().
35
36         jsr     callmain
37
38 ; Call the module destructors. This is also the exit() entry.
39
40 _exit:  jsr     donelib
41
42 ; Restore the system stuff.
43
44         ldx     spsave
45         txs
46
47 ; Copy back the zero-page stuff.
48
49         ldx     #zpspace - 1
50 L2:     lda     zpsave,x
51         sta     sp,x
52         dex
53         bpl     L2
54
55 ; Back to BASIC.
56
57         rts
58
59 ; ------------------------------------------------------------------------
60 ; Put this code in a place that will be re-used by BSS, the heap,
61 ; and the C stack.
62
63 .segment        "ONCE"
64
65 ; Save the zero-page area that we're about to use.
66
67 init:   ldx     #zpspace - 1
68 L1:     lda     sp,x
69         sta     zpsave,x
70         dex
71         bpl     L1
72
73
74 ; Set up the C stack.
75
76         lda     #<(__MAIN_START__ + __MAIN_SIZE__)
77         ldx     #>(__MAIN_START__ + __MAIN_SIZE__)
78         sta     sp
79         stx     sp+1            ; Set argument stack ptr
80
81 ; Call the module constructors.
82
83         jmp     initlib
84
85 ; ------------------------------------------------------------------------
86
87 .segment        "INIT"
88
89 spsave: .res    1
90 stsave: .res    1
91 zpsave: .res    zpspace