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