]> git.sur5r.net Git - cc65/blob - libsrc/pet/crt0.s
This commit was generated by cvs2svn to compensate for changes in r2,
[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         __hinit, initconio, zerobss, push0, doatexit
9         .import         _main
10
11         .include        "pet.inc"
12         .include        "../cbm/cbm.inc"
13
14 ; ------------------------------------------------------------------------
15 ; Define and export the ZP variables for the C64 runtime
16
17         .exportzp       sp, sreg, regsave
18         .exportzp       ptr1, ptr2, ptr3, ptr4
19         .exportzp       tmp1, tmp2, tmp3, tmp4
20         .exportzp       regbank, zpspace
21
22 sp      =       $02             ; stack pointer
23 sreg    =       $04             ; secondary register/high 16 bit for longs
24 regsave =       $06             ; slot to save/restore (E)AX into
25 ptr1    =       $0A             ;
26 ptr2    =       $0C
27 ptr3    =       $0E
28 ptr4    =       $10
29 tmp1    =       $12
30 tmp2    =       $13
31 tmp3    =       $14
32 tmp4    =       $15
33 regbank =       $16             ; 6 byte register bank
34 zpspace =       $1A             ; Zero page space allocated
35
36 ; ------------------------------------------------------------------------
37 ; BASIC header with a SYS call
38
39         .org    $3FF
40         .word   Head            ; Load address
41 Head:   .word   @Next
42         .word   1000            ; Line number
43         .byte   $9E,"1037"      ; SYS 1037
44         .byte   $00             ; End of BASIC line
45 @Next:  .word   0               ; BASIC end marker
46         .reloc
47
48 ; ------------------------------------------------------------------------
49 ; Actual code
50
51         ldy     #zpspace-1
52 L1:     lda     sp,y
53         sta     zpsave,y        ; Save the zero page locations we need
54         dey
55         bpl     L1
56
57 ; Close open files
58
59         jsr     CLRCH
60
61 ; Switch to second charset
62
63         lda     #14
64 ;       sta     $E84C           ; See PET FAQ
65         jsr     BSOUT
66
67 ; Clear the BSS data
68
69         jsr     zerobss
70
71 ; Save system stuff and setup the stack
72
73         tsx
74         stx     spsave          ; Save the system stack ptr
75
76         lda     MEMSIZE
77         sta     sp
78         lda     MEMSIZE+1
79         sta     sp+1            ; Set argument stack ptr
80
81 ; Initialize the heap
82
83         jsr     __hinit
84
85 ; Initialize conio stuff
86
87         jsr     initconio
88
89 ; Pass an empty command line
90
91         jsr     push0           ; argc
92         jsr     push0           ; argv
93
94         ldy     #4              ; Argument size
95         jsr     _main           ; call the users code
96
97 ; fall thru to exit...
98
99 _exit:  jsr     doatexit        ; call exit functions
100
101         ldx     spsave
102         txs                     ; Restore stack pointer
103
104 ; Copy back the zero page stuff
105
106         ldy     #zpspace-1
107 L2:     lda     zpsave,y
108         sta     sp,y
109         dey
110         bpl     L2
111
112 ; Back to basic
113
114         rts
115
116
117 .data
118
119 zpsave: .res    zpspace
120
121 .bss
122
123 spsave: .res    1
124 mmusave:.res    1
125