]> git.sur5r.net Git - cc65/blob - libsrc/vic20/crt0.s
Removed (pretty inconsistently used) tab chars from source code base.
[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
8         .import         zerobss, push0
9         .import         callmain
10         .import         RESTOR, BSOUT, CLRCH
11         .import         __RAM_START__, __RAM_SIZE__     ; Linker generated
12         .import         __STACKSIZE__                   ; Linker generated
13         .importzp       ST
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 ; Call module constructors
53
54         jsr     initlib
55
56 ; Push arguments and call main()
57
58         jsr     callmain
59
60 ; Back from main (This is also the _exit entry). Run module destructors
61
62 _exit:  pha                     ; Save the return code on stack
63         jsr     donelib
64
65 ; Copy back the zero page stuff
66
67         ldx     #zpspace-1
68 L2:     lda     zpsave,x
69         sta     sp,x
70         dex
71         bpl     L2
72
73 ; Place the program return code into ST
74
75         pla
76         sta     ST
77
78 ; Restore the stack pointer
79
80         ldx     spsave
81         txs
82
83 ; Back to basic
84
85         rts
86
87 ; ------------------------------------------------------------------------
88
89 .segment        "ZPSAVE"
90
91 zpsave: .res    zpspace
92
93 ; ------------------------------------------------------------------------
94
95 .bss
96
97 spsave: .res    1