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 ; ------------------------------------------------------------------------
40 ; Save the zero page locations we need
48 ; Switch to second charset. The routine that is called by BSOUT to switch the
49 ; character set will use FNLEN as temporary storage - YUCK! Since the
50 ; initmainargs routine, which parses the command line for arguments needs this
51 ; information, we need to save and restore it here.
52 ; Thanks to Stefan Haubenthal for this information!
57 ; sta $E84C ; See PET FAQ
60 sta FNLEN ; Restore FNLEN
66 ; Save system stuff and setup the stack
69 stx spsave ; Save the system stack ptr
74 sta sp+1 ; Set argument stack ptr
76 ; If we have IRQ functions, chain our stub into the IRQ vector
78 lda #<__INTERRUPTOR_COUNT__
91 ; Call module constructors
95 ; Push arguments and call main()
99 ; Call module destructors. This is also the _exit entry.
101 _exit: pha ; Save the return code on stack
104 ; Reset the IRQ vector if we chained it.
106 lda #<__INTERRUPTOR_COUNT__
115 ; Copy back the zero page stuff
117 NoIRQ2: ldx #zpspace-1
123 ; Store the program return code into ST
128 ; Restore the stack pointer
131 txs ; Restore stack pointer
137 ; ------------------------------------------------------------------------
138 ; The IRQ vector jumps here, if condes routines are defined with type 2.
141 cld ; Just to be sure
142 jsr callirq ; Call the functions
143 jmp IRQInd ; Jump to the saved IRQ vector
145 ; ------------------------------------------------------------------------