]> git.sur5r.net Git - cc65/blob - libsrc/pet/crt0.s
Fixed gcc compiler warning (#867)
[cc65] / libsrc / pet / crt0.s
1 ;
2 ; Startup code for cc65 (PET version)
3 ;
4
5         .export         _exit
6         .export         __STARTUP__ : absolute = 1      ; Mark as startup
7         .import         initlib, donelib
8         .import         zerobss, push0
9         .import         callmain
10         .import         CLRCH, BSOUT
11         .importzp       ST
12
13         .include        "zeropage.inc"
14         .include        "pet.inc"
15         .include        "../cbm/cbm.inc"
16
17 ; ------------------------------------------------------------------------
18 ; Startup code
19
20 .segment        "STARTUP"
21
22 Start:
23
24 ; Save the zero-page locations that we need.
25
26         ldx     #zpspace-1
27 L1:     lda     sp,x
28         sta     zpsave,x
29         dex
30         bpl     L1
31
32 ; Switch to the second charset. The routine that is called by BSOUT to switch the
33 ; character set will use FNLEN as temporary storage -- YUCK! Since the
34 ; initmainargs routine, which parses the command line for arguments, needs that
35 ; information, we need to save and restore it here.
36 ; Thanks to Stefan Haubenthal for this information!
37
38         lda     FNLEN
39         pha                     ; Save FNLEN
40         lda     #14
41 ;       sta     $E84C           ; See PET FAQ
42         jsr     BSOUT
43         pla
44         sta     FNLEN           ; Restore FNLEN
45
46 ; Clear the BSS data.
47
48         jsr     zerobss
49
50 ; Save some system stuff; and, set up the stack.
51
52         tsx
53         stx     spsave          ; Save the system stack ptr
54
55         lda     MEMSIZE
56         sta     sp
57         lda     MEMSIZE+1
58         sta     sp+1            ; Set argument stack ptr
59
60 ; Call the module constructors.
61
62         jsr     initlib
63
64 ; Push the command-line arguments; and, call main().
65
66         jsr     callmain
67
68 ; Call the module destructors. This is also the exit() entry.
69
70 _exit:  pha                     ; Save the return code on stack
71         jsr     donelib
72
73 ; Copy back the zero-page stuff.
74
75         ldx     #zpspace-1
76 L2:     lda     zpsave,x
77         sta     sp,x
78         dex
79         bpl     L2
80
81 ; Store the program return code into BASIC's status variable.
82
83         pla
84         sta     ST
85
86 ; Restore the stack pointer.
87
88         ldx     spsave
89         txs                     ; Restore stack pointer
90
91 ; Back to BASIC.
92
93         rts
94
95 ; ------------------------------------------------------------------------
96
97 .segment        "INIT"
98
99 zpsave: .res    zpspace
100
101 ; ------------------------------------------------------------------------
102
103 .bss
104
105 spsave: .res    1
106 mmusave:.res    1