]> git.sur5r.net Git - cc65/blob - libsrc/plus4/crt0.s
Removed initialization code to set the screen size and replaced it by a
[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         initlib, donelib
9         .import         push0, _main
10         .import         initconio, doneconio, zerobss
11
12         .include        "plus4.inc"
13         .include        "../cbm/cbm.inc"
14
15 ; ------------------------------------------------------------------------
16 ; Define and export the ZP variables for the C64 runtime
17
18         .exportzp       sp, sreg, regsave
19         .exportzp       ptr1, ptr2, ptr3, ptr4
20         .exportzp       tmp1, tmp2, tmp3, tmp4
21         .exportzp       regbank, zpspace
22
23 .zeropage
24
25 zpstart = *
26 sp:             .res    2       ; Stack pointer
27 sreg:           .res    2       ; Secondary register/high 16 bit for longs
28 regsave:        .res    2       ; slot to save/restore (E)AX into
29 ptr1:           .res    2
30 ptr2:           .res    2
31 ptr3:           .res    2
32 ptr4:           .res    2
33 tmp1:           .res    1
34 tmp2:           .res    1
35 tmp3:           .res    1
36 tmp4:           .res    1
37 regbank:        .res    6       ; 6 byte register bank
38
39 zpspace = * - zpstart           ; Zero page space allocated
40
41 .code
42
43 ; ------------------------------------------------------------------------
44 ; BASIC header with a SYS call
45
46         .org    $0FFF
47         .word   Head            ; Load address
48 Head:   .word   @Next
49         .word   1000            ; Line number
50         .byte   $9E,"4109"      ; SYS 4109
51         .byte   $00             ; End of BASIC line
52 @Next:  .word   0               ; BASIC end marker
53         .reloc
54
55 ; ------------------------------------------------------------------------
56 ; Actual code
57
58         ldx     #zpspace-1
59 L1:     lda     sp,x
60         sta     zpsave,x        ; save the zero page locations we need
61         dex
62         bpl     L1
63
64 ; Close open files
65
66         jsr     CLRCH
67
68 ; Switch to second charset
69
70         lda     #14
71         jsr     BSOUT
72
73 ; Clear the BSS data
74
75         jsr     zerobss
76
77 ; Save system stuff and setup the stack
78
79         tsx
80         stx     spsave          ; save system stk ptr
81
82         sec
83         jsr     MEMTOP          ; Get top memory
84         cpy     #$80            ; We can only use the low 32K :-(
85         bcc     MemOk
86         ldy     #$80
87         ldx     #$00
88 MemOk:  stx     sp
89         sty     sp+1            ; set argument stack ptr
90
91 ; Call module constructors
92
93         jsr     initlib
94
95 ; Initialize conio stuff
96
97         jsr     initconio
98
99 ; Pass an empty command line
100
101         jsr     push0           ; argc
102         jsr     push0           ; argv
103
104         ldy     #4              ; Argument size
105         jsr     _main           ; call the users code
106
107 ; Call module destructors. This is also the _exit entry.
108
109 _exit:  jsr     donelib         ; Run module destructors
110
111 ; Restore system stuff
112
113         ldx     spsave
114         txs
115
116 ; Reset the conio stuff
117
118         jsr     doneconio
119
120 ; Copy back the zero page stuff
121
122         ldx     #zpspace-1
123 L2:     lda     zpsave,x
124         sta     sp,x
125         dex
126         bpl     L2
127
128 ; Reset changed vectors
129
130         jmp     RESTOR
131
132
133 .data
134 zpsave: .res    zpspace
135
136 .bss
137 spsave: .res    1
138
139