]> git.sur5r.net Git - cc65/blob - libsrc/atmos/crt0.s
Moved the data that keeps a copy of the used zero page locations in its own
[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         callmain, zerobss
12         .import         __RAM_START__, __RAM_SIZE__, __BSS_LOAD__
13
14         .include        "zeropage.inc"
15         .include        "atmos.inc"
16
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   __BSS_LOAD__                    ; $2AB
31         .dbyt   __RAM_START__                   ; $2A9
32         .byte   $00                             ; $2A8
33         .byte   $00                             ; Zero terminated name
34
35 ; ------------------------------------------------------------------------
36 ; Place the startup code in a special segment.
37
38 .segment        "STARTUP"
39
40 ; Save the zero page area we're about to use
41
42         ldx     #zpspace-1
43 L1:     lda     sp,x
44         sta     zpsave,x        ; Save the zero page locations we need
45         dex
46         bpl     L1
47
48 ; Clear the BSS data
49
50         jsr     zerobss
51
52 ; Unprotect columns 0 and 1
53
54         lda     STATUS
55         sta     stsave
56         and     #%11011111
57         sta     STATUS
58
59 ; Save system stuff and setup the stack
60
61         tsx
62         stx     spsave          ; save system stk ptr
63
64         lda     #<(__RAM_START__ + __RAM_SIZE__)
65         sta     sp
66         lda     #>(__RAM_START__ + __RAM_SIZE__)
67         sta     sp+1            ; Set argument stack ptr
68
69 ; Call module constructors
70
71         jsr     initlib
72
73 ; Push arguments and call main()
74
75         jsr     callmain
76
77 ; Call module destructors. This is also the _exit entry.
78
79 _exit:  jsr     donelib         ; Run module destructors
80
81 ; Restore system stuff
82
83         ldx     spsave
84         txs
85         lda     stsave
86         sta     STATUS
87
88 ; Copy back the zero page stuff
89
90         ldx     #zpspace-1
91 L2:     lda     zpsave,x
92         sta     sp,x
93         dex
94         bpl     L2
95
96 ; Back to BASIC
97
98         rts
99
100 ; ------------------------------------------------------------------------
101 ; Data
102
103 .segment        "ZPSAVE"
104
105 zpsave: .res    zpspace
106
107 .bss
108 spsave: .res    1
109 stsave: .res    1
110
111