]> git.sur5r.net Git - cc65/blob - libsrc/pet/crt0.s
New loadable mouse drivers
[cc65] / libsrc / pet / crt0.s
1 ;
2 ; Startup code for cc65 (PET version)
3 ;
4 ; This must be the *first* file on the linker command line
5 ;
6
7         .export         _exit
8         .import         initlib, donelib
9         .import         zerobss, push0
10         .import         callmain
11         .import         CLRCH, BSOUT
12
13         .include        "zeropage.inc"
14         .include        "pet.inc"
15         .include        "../cbm/cbm.inc"
16
17 ; ------------------------------------------------------------------------
18 ; Place the startup code in a special segment.
19
20 .segment        "STARTUP"
21
22 ; BASIC header with a SYS call
23
24         .word   Head            ; Load address
25 Head:   .word   @Next
26         .word   1000            ; Line number
27         .byte   $9E,"1037"      ; SYS 1037
28         .byte   $00             ; End of BASIC line
29 @Next:  .word   0               ; BASIC end marker
30
31 ; ------------------------------------------------------------------------
32 ; Actual code
33
34         ldx     #zpspace-1
35 L1:     lda     sp,x
36         sta     zpsave,x        ; Save the zero page locations we need
37         dex
38         bpl     L1
39
40 ; Close open files
41
42         jsr     CLRCH
43
44 ; Switch to second charset
45
46         lda     #14
47 ;       sta     $E84C           ; See PET FAQ
48         jsr     BSOUT
49
50 ; Clear the BSS data
51
52         jsr     zerobss
53
54 ; Save system stuff and setup the stack
55
56         tsx
57         stx     spsave          ; Save the system stack ptr
58
59         lda     MEMSIZE
60         sta     sp
61         lda     MEMSIZE+1
62         sta     sp+1            ; Set argument stack ptr
63
64 ; Call module constructors
65
66         jsr     initlib
67
68 ; Push arguments and call main()
69
70         jsr     callmain
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                     ; Restore stack pointer
80
81 ; Copy back the zero page stuff
82
83         ldx     #zpspace-1
84 L2:     lda     zpsave,x
85         sta     sp,x
86         dex
87         bpl     L2
88
89 ; Back to basic
90
91         rts
92
93
94 ; ------------------------------------------------------------------------
95 ; Data
96
97 .data
98
99 zpsave: .res    zpspace
100
101 .bss
102
103 spsave: .res    1
104 mmusave:.res    1
105