]> git.sur5r.net Git - cc65/blob - libsrc/pet/crt0.s
Use external symbols for the CBM kernal jump table functions. This allows
[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         _main
11         .import         CLRCH, BSOUT
12
13         .include        "zeropage.inc"
14         .include        "pet.inc"
15         .include        "../cbm/cbm.inc"
16
17 ; ------------------------------------------------------------------------
18 ; BASIC header with a SYS call
19
20 .code
21
22         .org    $3FF
23         .word   Head            ; Load address
24 Head:   .word   @Next
25         .word   1000            ; Line number
26         .byte   $9E,"1037"      ; SYS 1037
27         .byte   $00             ; End of BASIC line
28 @Next:  .word   0               ; BASIC end marker
29         .reloc
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 ; Pass an empty command line
69
70         jsr     push0           ; argc
71         jsr     push0           ; argv
72
73         ldy     #4              ; Argument size
74         jsr     _main           ; call the users code
75
76 ; Call module destructors. This is also the _exit entry.
77
78 _exit:  jsr     donelib         ; Run module destructors
79
80 ; Restore system stuff
81
82         ldx     spsave
83         txs                     ; Restore stack pointer
84
85 ; Copy back the zero page stuff
86
87         ldx     #zpspace-1
88 L2:     lda     zpsave,x
89         sta     sp,x
90         dex
91         bpl     L2
92
93 ; Back to basic
94
95         rts
96
97
98 .data
99
100 zpsave: .res    zpspace
101
102 .bss
103
104 spsave: .res    1
105 mmusave:.res    1
106