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