2 ; Startup code for cc65 (PET version)
6 .export __STARTUP__ : absolute = 1 ; Mark as startup
7 .import initlib, donelib, callirq
11 .import __INTERRUPTOR_COUNT__
13 .include "zeropage.inc"
15 .include "../cbm/cbm.inc"
17 ; ------------------------------------------------------------------------
18 ; Place the startup code in a special segment.
22 ; BASIC header with a SYS call
24 .word Head ; Load address
26 .word .version ; Line number
27 .byte $9E,"1037" ; SYS 1037
28 .byte $00 ; End of BASIC line
29 @Next: .word 0 ; BASIC end marker
31 ; ------------------------------------------------------------------------
36 sta zpsave,x ; Save the zero page locations we need
44 ; Switch to second charset. The routine that is called by BSOUT to switch the
45 ; character set will use FNLEN as temporary storage - YUCK! Since the
46 ; initmainargs routine, which parses the command line for arguments needs this
47 ; information, we need to save and restore it here.
48 ; Thanks to Stefan Haubenthal for this information!
53 ; sta $E84C ; See PET FAQ
56 sta FNLEN ; Restore FNLEN
62 ; Save system stuff and setup the stack
65 stx spsave ; Save the system stack ptr
70 sta sp+1 ; Set argument stack ptr
72 ; If we have IRQ functions, chain our stub into the IRQ vector
74 lda #<__INTERRUPTOR_COUNT__
87 ; Call module constructors
91 ; Push arguments and call main()
95 ; Call module destructors. This is also the _exit entry.
97 _exit: pha ; Save the return code on stack
100 ; Reset the IRQ vector if we chained it.
102 lda #<__INTERRUPTOR_COUNT__
111 ; Copy back the zero page stuff
113 NoIRQ2: ldx #zpspace-1
119 ; Store the program return code into ST
124 ; Restore the stack pointer
127 txs ; Restore stack pointer
133 ; ------------------------------------------------------------------------
134 ; The IRQ vector jumps here, if condes routines are defined with type 2.
137 cld ; Just to be sure
138 jsr callirq ; Call the functions
139 jmp IRQInd ; Jump to the saved IRQ vector
141 ; ------------------------------------------------------------------------