]> git.sur5r.net Git - cc65/blob - libsrc/pet/crt0.s
Move zp space out of crt0.s
[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
12         .include        "zeropage.inc"
13         .include        "pet.inc"
14         .include        "../cbm/cbm.inc"
15
16 ; ------------------------------------------------------------------------
17 ; BASIC header with a SYS call
18
19 .code
20
21         .org    $3FF
22         .word   Head            ; Load address
23 Head:   .word   @Next
24         .word   1000            ; Line number
25         .byte   $9E,"1037"      ; SYS 1037
26         .byte   $00             ; End of BASIC line
27 @Next:  .word   0               ; BASIC end marker
28         .reloc
29
30 ; ------------------------------------------------------------------------
31 ; Actual code
32
33         ldx     #zpspace-1
34 L1:     lda     sp,x
35         sta     zpsave,x        ; Save the zero page locations we need
36         dex
37         bpl     L1
38
39 ; Close open files
40
41         jsr     CLRCH
42
43 ; Switch to second charset
44
45         lda     #14
46 ;       sta     $E84C           ; See PET FAQ
47         jsr     BSOUT
48
49 ; Clear the BSS data
50
51         jsr     zerobss
52
53 ; Save system stuff and setup the stack
54
55         tsx
56         stx     spsave          ; Save the system stack ptr
57
58         lda     MEMSIZE
59         sta     sp
60         lda     MEMSIZE+1
61         sta     sp+1            ; Set argument stack ptr
62
63 ; Call module constructors
64
65         jsr     initlib
66
67 ; Pass an empty command line
68
69         jsr     push0           ; argc
70         jsr     push0           ; argv
71
72         ldy     #4              ; Argument size
73         jsr     _main           ; call the users code
74
75 ; Call module destructors. This is also the _exit entry.
76
77 _exit:  jsr     donelib         ; Run module destructors
78
79 ; Restore system stuff
80
81         ldx     spsave
82         txs                     ; Restore stack pointer
83
84 ; Copy back the zero page stuff
85
86         ldx     #zpspace-1
87 L2:     lda     zpsave,x
88         sta     sp,x
89         dex
90         bpl     L2
91
92 ; Back to basic
93
94         rts
95
96
97 .data
98
99 zpsave: .res    zpspace
100
101 .bss
102
103 spsave: .res    1
104 mmusave:.res    1
105