]> git.sur5r.net Git - cc65/blob - libsrc/atmos/crt0.s
e789b28c279f533b4863ff801689eab1b1a7e5d0
[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 ; 2015-01-09, Greg King
6 ;
7
8         .export         _exit
9         .export         __STARTUP__ : absolute = 1      ; Mark as startup
10         .import         initlib, donelib
11         .import         callmain, zerobss
12         .import         __RAM_START__, __RAM_SIZE__, __STACKSIZE__
13
14         .include        "zeropage.inc"
15         .include        "atmos.inc"
16
17 ; ------------------------------------------------------------------------
18 ; Place the startup code in a special segment.
19
20 .segment        "STARTUP"
21
22 ; Save the zero-page area that we're about to use.
23
24         ldx     #zpspace-1
25 L1:     lda     sp,x
26         sta     zpsave,x
27         dex
28         bpl     L1
29
30 ; Clear the BSS data.
31
32         jsr     zerobss
33
34 ; Currently, color isn't supported on the text screen.
35 ; Unprotect screen columns 0 and 1 (where each line's color codes would sit).
36
37         lda     STATUS
38         sta     stsave
39         and     #%11011111
40         sta     STATUS
41
42 ; Save some system stuff; and, set up the stack.
43
44         tsx
45         stx     spsave          ; Save system stk ptr
46
47         lda     #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
48         sta     sp
49         lda     #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
50         sta     sp+1            ; Set argument stack ptr
51
52 ; Call the module constructors.
53
54         jsr     initlib
55
56 ; Push the command-line arguments; and, call main().
57
58         jsr     callmain
59
60 ; Call the module destructors. This is also the exit() entry.
61
62 _exit:  jsr     donelib
63
64 ; Restore the system stuff.
65
66         ldx     spsave
67         txs
68         lda     stsave
69         sta     STATUS
70
71 ; Copy back the zero-page stuff.
72
73         ldx     #zpspace-1
74 L2:     lda     zpsave,x
75         sta     sp,x
76         dex
77         bpl     L2
78
79 ; Back to BASIC.
80
81         rts
82
83 ; ------------------------------------------------------------------------
84
85 .segment        "ZPSAVE1"
86
87 zpsave:
88
89 ; This padding is needed by a bug in the ROM.
90 ; (The CLOAD command starts BASIC's variables table on top of the last byte
91 ; that was loaded [instead of at the next address].)
92 ; This is overlaid on a buffer, so that it doesn't use extra space in RAM.
93
94         .byte   0
95
96 ; The segments "ZPSAVE1" and "ZPSAVE2" always must be together.
97 ; They create a single object (the zpsave buffer).
98
99 .segment        "ZPSAVE2"
100
101         .res    zpspace - 1
102
103 ; ------------------------------------------------------------------------
104
105 .bss
106
107 spsave: .res    1
108 stsave: .res    1