2 ; Startup code for cc65 (PET version)
4 ; This must be the *first* file on the linker command line
8 .import initlib, donelib, callirq
12 .import __INTERRUPTOR_COUNT__
14 .include "zeropage.inc"
16 .include "../cbm/cbm.inc"
18 ; ------------------------------------------------------------------------
19 ; Place the startup code in a special segment.
23 ; BASIC header with a SYS call
25 .word Head ; Load address
27 .word .version ; Line number
28 .byte $9E,"1037" ; SYS 1037
29 .byte $00 ; End of BASIC line
30 @Next: .word 0 ; BASIC end marker
32 ; ------------------------------------------------------------------------
37 sta zpsave,x ; Save the zero page locations we need
45 ; Switch to second charset
48 ; sta $E84C ; See PET FAQ
55 ; Save system stuff and setup the stack
58 stx spsave ; Save the system stack ptr
63 sta sp+1 ; Set argument stack ptr
65 ; Call module constructors
69 ; If we have IRQ functions, chain our stub into the IRQ vector
71 lda #<__INTERRUPTOR_COUNT__
84 ; Push arguments and call main()
88 ; Call module destructors. This is also the _exit entry.
90 _exit: pha ; Save the return code on stack
91 lda #<__INTERRUPTOR_COUNT__
100 ; Run module destructors
102 NoIRQ2: jsr donelib ; Run module destructors
104 ; Copy back the zero page stuff
112 ; Store the program return code into ST
117 ; Restore the stack pointer
120 txs ; Restore stack pointer
126 ; ------------------------------------------------------------------------
127 ; The IRQ vector jumps here, if condes routines are defined with type 2.
130 cld ; Just to be sure
131 jsr callirq ; Call the functions
132 jmp IRQInd ; Jump to the saved IRQ vector
134 ; ------------------------------------------------------------------------