]> git.sur5r.net Git - cc65/blob - libsrc/vic20/crt0.s
Moved the 'disk' files from 'geos-cbm' to 'geos-common' which are believed to work...
[cc65] / libsrc / vic20 / crt0.s
1 ;
2 ; Startup code for cc65 (Vic20 version)
3 ;
4
5         .export         _exit
6         .export         __STARTUP__ : absolute = 1      ; Mark as startup
7         .import         initlib, donelib, callirq
8         .import         zerobss, push0
9         .import         callmain
10         .import         RESTOR, BSOUT, CLRCH
11         .import         __INTERRUPTOR_COUNT__
12         .import         __RAM_START__, __RAM_SIZE__     ; Linker generated
13         .import         __STACKSIZE__                   ; Linker generated
14
15         .include        "zeropage.inc"
16         .include        "vic20.inc"
17
18 ; ------------------------------------------------------------------------
19 ; Startup code
20
21 .segment        "STARTUP"
22
23 Start:
24
25 ; Save the zero page locations we need
26
27         ldx     #zpspace-1
28 L1:     lda     sp,x
29         sta     zpsave,x
30         dex
31         bpl     L1
32
33 ; Switch to second charset
34
35         lda     #14
36         jsr     BSOUT
37
38 ; Clear the BSS data
39
40         jsr     zerobss
41
42 ; Save system stuff and setup the stack
43
44         tsx
45         stx     spsave          ; Save the system stack 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 ; If we have IRQ functions, chain our stub into the IRQ vector
53
54         lda     #<__INTERRUPTOR_COUNT__
55         beq     NoIRQ1
56         lda     IRQVec
57         ldx     IRQVec+1
58         sta     IRQInd+1
59         stx     IRQInd+2
60         lda     #<IRQStub
61         ldx     #>IRQStub
62         sei
63         sta     IRQVec
64         stx     IRQVec+1
65         cli
66
67 ; Call module constructors
68
69 NoIRQ1: jsr     initlib
70
71 ; Push arguments and call main()
72
73         jsr     callmain
74
75 ; Back from main (This is also the _exit entry). Run module destructors
76
77 _exit:  jsr     donelib
78
79 ; Reset the IRQ vector if we chained it.
80
81         pha                     ; Save the return code on stack
82         lda     #<__INTERRUPTOR_COUNT__
83         beq     NoIRQ2
84         lda     IRQInd+1
85         ldx     IRQInd+2
86         sei
87         sta     IRQVec
88         stx     IRQVec+1
89         cli
90
91 ; Copy back the zero page stuff
92
93 NoIRQ2: ldx     #zpspace-1
94 L2:     lda     zpsave,x
95         sta     sp,x
96         dex
97         bpl     L2
98
99 ; Place the program return code into ST
100
101         pla
102         sta     ST
103
104 ; Restore the stack pointer
105
106         ldx     spsave
107         txs
108
109 ; Back to basic
110
111         rts
112
113
114 ; ------------------------------------------------------------------------
115 ; The IRQ vector jumps here, if condes routines are defined with type 2.
116
117 IRQStub:
118         cld                             ; Just to be sure
119         jsr     callirq                 ; Call the functions
120         jmp     IRQInd                  ; Jump to the saved IRQ vector
121
122 ; ------------------------------------------------------------------------
123 ; Data
124
125 .data
126
127 IRQInd: jmp     $0000
128
129 .segment        "ZPSAVE"
130
131 zpsave: .res    zpspace
132
133 .bss
134
135 spsave: .res    1