]> git.sur5r.net Git - cc65/blob - libsrc/atmos/crt0.s
5955fd94b7a50355a7079092e46ace4f6357981a
[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         push0, _main, zerobss
12         .import         __RAM_START__, __RAM_SIZE__     ; Linker generated
13
14
15 ; ------------------------------------------------------------------------
16 ; Define and export the ZP variables for the Oric runtime
17
18         .exportzp       sp, sreg, regsave
19         .exportzp       ptr1, ptr2, ptr3, ptr4
20         .exportzp       tmp1, tmp2, tmp3, tmp4
21         .exportzp       regbank, zpspace
22
23 .zeropage
24
25 zpstart = *
26 sp:             .res    2       ; Stack pointer
27 sreg:           .res    2       ; Secondary register/high 16 bit for longs
28 regsave:        .res    2       ; slot to save/restore (E)AX into
29 ptr1:           .res    2
30 ptr2:           .res    2
31 ptr3:           .res    2
32 ptr4:           .res    2
33 tmp1:           .res    1
34 tmp2:           .res    1
35 tmp3:           .res    1
36 tmp4:           .res    1
37 regbank:        .res    6       ; 6 byte register bank
38
39 zpspace = * - zpstart           ; Zero page space allocated
40
41 .code
42
43 ; ------------------------------------------------------------------------
44 ; Actual code
45
46 ; Clear the BSS data
47
48         jsr     zerobss
49
50 ; Save system stuff and setup the stack
51
52         tsx
53         stx     spsave          ; save system stk ptr
54
55         lda     #<(__RAM_START__ + __RAM_SIZE__)
56         sta     sp
57         lda     #>(__RAM_START__ + __RAM_SIZE__)
58         sta     sp+1            ; Set argument stack ptr
59
60 ; Call module constructors
61
62         jsr     initlib
63
64 ; Pass an empty command line
65
66         jsr     push0           ; argc
67         jsr     push0           ; argv
68
69         ldy     #4              ; Argument size
70         jsr     _main           ; call the users code
71
72 ; Call module destructors. This is also the _exit entry.
73
74 _exit:  jsr     donelib         ; Run module destructors
75
76 ; Restore system stuff
77
78         ldx     spsave
79         txs
80
81 ; Back to BASIC
82
83         rts
84
85 .bss
86 spsave: .res    1
87
88