2 ; Startup code for cc65 (PET version)
4 ; This must be the *first* file on the linker command line
8 .import initlib, donelib, callirq
12 .import __INTERRUPTOR_COUNT__
14 .include "zeropage.inc"
16 .include "../cbm/cbm.inc"
18 ; ------------------------------------------------------------------------
19 ; Place the startup code in a special segment.
23 ; BASIC header with a SYS call
25 .word Head ; Load address
27 .word .version ; Line number
28 .byte $9E,"1037" ; SYS 1037
29 .byte $00 ; End of BASIC line
30 @Next: .word 0 ; BASIC end marker
32 ; ------------------------------------------------------------------------
37 sta zpsave,x ; Save the zero page locations we need
45 ; Switch to second charset. The routine that is called by BSOUT to switch the
46 ; character set will use FNLEN as temporary storage - YUCK! Since the
47 ; initmainargs routine, which parses the command line for arguments needs this
48 ; information, we need to save and restore it here.
49 ; Thanks to Stefan Haubenthal for this information!
54 ; sta $E84C ; See PET FAQ
57 sta FNLEN ; Restore FNLEN
63 ; Save system stuff and setup the stack
66 stx spsave ; Save the system stack ptr
71 sta sp+1 ; Set argument stack ptr
73 ; If we have IRQ functions, chain our stub into the IRQ vector
75 lda #<__INTERRUPTOR_COUNT__
88 ; Call module constructors
92 ; Push arguments and call main()
96 ; Call module destructors. This is also the _exit entry.
98 _exit: pha ; Save the return code on stack
101 ; Reset the IRQ vector if we chained it.
103 lda #<__INTERRUPTOR_COUNT__
112 ; Copy back the zero page stuff
114 NoIRQ2: ldx #zpspace-1
120 ; Store the program return code into ST
125 ; Restore the stack pointer
128 txs ; Restore stack pointer
134 ; ------------------------------------------------------------------------
135 ; The IRQ vector jumps here, if condes routines are defined with type 2.
138 cld ; Just to be sure
139 jsr callirq ; Call the functions
140 jmp IRQInd ; Jump to the saved IRQ vector
142 ; ------------------------------------------------------------------------