]> git.sur5r.net Git - cc65/blob - libsrc/plus4/crt0.s
Use external symbols for the CBM kernal jump table functions. This allows
[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, zerobss
10         .import         MEMTOP, RESTOR, BSOUT, CLRCH
11
12         .include        "zeropage.inc"
13         .include        "plus4.inc"
14
15
16 ; ------------------------------------------------------------------------
17 ; BASIC header with a SYS call
18
19 .code
20
21         .org    $0FFF
22         .word   Head            ; Load address
23 Head:   .word   @Next
24         .word   1000            ; Line number
25         .byte   $9E,"4109"      ; SYS 4109
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         jsr     BSOUT
47
48 ; Clear the BSS data
49
50         jsr     zerobss
51
52 ; Save system stuff and setup the stack
53
54         tsx
55         stx     spsave          ; save system stk ptr
56
57         sec
58         jsr     MEMTOP          ; Get top memory
59         cpy     #$80            ; We can only use the low 32K :-(
60         bcc     MemOk
61         ldy     #$80
62         ldx     #$00
63 MemOk:  stx     sp
64         sty     sp+1            ; set argument stack ptr
65
66 ; Call module constructors
67
68         jsr     initlib
69
70 ; Pass an empty command line
71
72         jsr     push0           ; argc
73         jsr     push0           ; argv
74
75         ldy     #4              ; Argument size
76         jsr     _main           ; call the users code
77
78 ; Call module destructors. This is also the _exit entry.
79
80 _exit:  jsr     donelib         ; Run module destructors
81
82 ; Restore system stuff
83
84         ldx     spsave
85         txs
86
87 ; Copy back the zero page stuff
88
89         ldx     #zpspace-1
90 L2:     lda     zpsave,x
91         sta     sp,x
92         dex
93         bpl     L2
94
95 ; Reset changed vectors
96
97         jmp     RESTOR
98
99
100 .data
101 zpsave: .res    zpspace
102
103 .bss
104 spsave: .res    1
105
106