2 ; Startup code for cc65 (PET version)
6 .export __STARTUP__ : absolute = 1 ; Mark as startup
7 .import initlib, donelib, callirq
11 .import __INTERRUPTOR_COUNT__
14 .include "zeropage.inc"
16 .include "../cbm/cbm.inc"
18 ; ------------------------------------------------------------------------
25 ; Save the zero page locations we need
33 ; Switch to second charset. The routine that is called by BSOUT to switch the
34 ; character set will use FNLEN as temporary storage - YUCK! Since the
35 ; initmainargs routine, which parses the command line for arguments needs this
36 ; information, we need to save and restore it here.
37 ; Thanks to Stefan Haubenthal for this information!
42 ; sta $E84C ; See PET FAQ
45 sta FNLEN ; Restore FNLEN
51 ; Save system stuff and setup the stack
54 stx spsave ; Save the system stack ptr
59 sta sp+1 ; Set argument stack ptr
61 ; If we have IRQ functions, chain our stub into the IRQ vector
63 lda #<__INTERRUPTOR_COUNT__
76 ; Call module constructors
80 ; Push arguments and call main()
84 ; Call module destructors. This is also the _exit entry.
86 _exit: pha ; Save the return code on stack
89 ; Reset the IRQ vector if we chained it.
91 lda #<__INTERRUPTOR_COUNT__
100 ; Copy back the zero page stuff
102 NoIRQ2: ldx #zpspace-1
108 ; Store the program return code into ST
113 ; Restore the stack pointer
116 txs ; Restore stack pointer
122 ; ------------------------------------------------------------------------
123 ; The IRQ vector jumps here, if condes routines are defined with type 2.
126 cld ; Just to be sure
127 jsr callirq ; Call the functions
128 jmp IRQInd ; Jump to the saved IRQ vector
130 ; ------------------------------------------------------------------------