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