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 ; ------------------------------------------------------------------------
24 ; Save the zero page locations we need
32 ; Switch to 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 this
35 ; information, we need to save and restore it here.
36 ; Thanks to Stefan Haubenthal for this information!
41 ; sta $E84C ; See PET FAQ
44 sta FNLEN ; Restore FNLEN
50 ; Save system stuff and setup the stack
53 stx spsave ; Save the system stack ptr
58 sta sp+1 ; Set argument stack ptr
60 ; If we have IRQ functions, chain our stub into the IRQ vector
62 lda #<__INTERRUPTOR_COUNT__
75 ; Call module constructors
79 ; Push arguments and call main()
83 ; Call module destructors. This is also the _exit entry.
85 _exit: pha ; Save the return code on stack
88 ; Reset the IRQ vector if we chained it.
90 lda #<__INTERRUPTOR_COUNT__
99 ; Copy back the zero page stuff
101 NoIRQ2: ldx #zpspace-1
107 ; Store the program return code into ST
112 ; Restore the stack pointer
115 txs ; Restore stack pointer
121 ; ------------------------------------------------------------------------
122 ; The IRQ vector jumps here, if condes routines are defined with type 2.
125 cld ; Just to be sure
126 jsr callirq ; Call the functions
127 jmp IRQInd ; Jump to the saved IRQ vector
129 ; ------------------------------------------------------------------------