]> git.sur5r.net Git - cc65/blob - libsrc/plus4/crt0.s
This commit was generated by cvs2svn to compensate for changes in r2,
[cc65] / libsrc / plus4 / crt0.s
1 ;
2 ; Startup code for cc65 (Plus/4 version)
3 ;
4 ; This must be the *first* file on the linker command line
5 ;
6
7         .export         _exit
8         .import         __hinit, push0, doatexit, _main
9         .import         initconio, doneconio, zerobss
10
11         .include        "plus4.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    $0FFF
40         .word   Head            ; Load address
41 Head:   .word   @Next
42         .word   1000            ; Line number
43         .byte   $9E,"4109"      ; SYS 4109
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         jsr     BSOUT
65
66 ; Clear the BSS data
67
68         jsr     zerobss
69
70 ; Save system stuff and setup the stack
71
72         tsx
73         stx     spsave          ; save system stk ptr
74
75         sec
76         jsr     MEMTOP          ; Get top memory
77         cpy     #$80            ; We can only use the low 32K :-(
78         bcc     MemOk
79         ldy     #$80
80         ldx     #$00
81 MemOk:  stx     sp
82         sty     sp+1            ; set argument stack ptr
83
84 ; Initialize the heap
85
86         jsr     __hinit
87
88 ; Initialize conio stuff
89
90         jsr     initconio
91
92 ; Pass an empty command line
93
94         jsr     push0           ; argc
95         jsr     push0           ; argv
96
97         ldy     #4              ; Argument size
98         jsr     _main           ; call the users code
99
100 ; fall thru to exit...
101
102 _exit:  jsr     doatexit        ; call exit functions
103         ldx     spsave
104         txs
105
106 ; Reset the conio stuff
107
108         jsr     doneconio
109
110 ; Copy back the zero page stuff
111
112         ldy     #zpspace-1
113 L2:     lda     zpsave,y
114         sta     sp,y
115         dey
116         bpl     L2
117
118 ; Reset changed vectors
119
120         jmp     RESTOR
121
122
123 .data
124 zpsave: .res    zpspace
125
126 .bss
127 spsave: .res    1
128
129