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 ; BASIC header with a SYS call
22 .word Head ; Load address
24 .word .version ; Line number
26 .byte <(((Start / 1000) .mod 10) + $30)
27 .byte <(((Start / 100) .mod 10) + $30)
28 .byte <(((Start / 10) .mod 10) + $30)
29 .byte <(((Start / 1) .mod 10) + $30)
30 .byte $00 ; End of BASIC line
31 @Next: .word 0 ; BASIC end marker
33 ; ------------------------------------------------------------------------
44 ; Save the zero page locations we need
52 ; Switch to second charset. The routine that is called by BSOUT to switch the
53 ; character set will use FNLEN as temporary storage - YUCK! Since the
54 ; initmainargs routine, which parses the command line for arguments needs this
55 ; information, we need to save and restore it here.
56 ; Thanks to Stefan Haubenthal for this information!
61 ; sta $E84C ; See PET FAQ
64 sta FNLEN ; Restore FNLEN
70 ; Save system stuff and setup the stack
73 stx spsave ; Save the system stack ptr
78 sta sp+1 ; Set argument stack ptr
80 ; If we have IRQ functions, chain our stub into the IRQ vector
82 lda #<__INTERRUPTOR_COUNT__
95 ; Call module constructors
99 ; Push arguments and call main()
103 ; Call module destructors. This is also the _exit entry.
105 _exit: pha ; Save the return code on stack
108 ; Reset the IRQ vector if we chained it.
110 lda #<__INTERRUPTOR_COUNT__
119 ; Copy back the zero page stuff
121 NoIRQ2: ldx #zpspace-1
127 ; Store the program return code into ST
132 ; Restore the stack pointer
135 txs ; Restore stack pointer
141 ; ------------------------------------------------------------------------
142 ; The IRQ vector jumps here, if condes routines are defined with type 2.
145 cld ; Just to be sure
146 jsr callirq ; Call the functions
147 jmp IRQInd ; Jump to the saved IRQ vector
149 ; ------------------------------------------------------------------------