2 ; Startup code for cc65 (C16 version)
4 ; Note: The C16 is actually the Plus/4 with just 16KB of memory. So many
5 ; things are similar here, and we even use the plus4.inc include file.
9 .export __STARTUP__ : absolute = 1 ; Mark as startup
10 .import initlib, donelib, callirq
11 .import callmain, zerobss
12 .import MEMTOP, RESTOR, BSOUT, CLRCH
13 .import __INTERRUPTOR_COUNT__
15 .include "zeropage.inc"
19 ; ------------------------------------------------------------------------
26 ; Save the zero page locations we need
34 ; Switch to second charset
43 ; Save system stuff and setup the stack
46 stx spsave ; save system stk ptr
49 jsr MEMTOP ; Get top memory
50 cpy #$80 ; We can only use the low 32K :-(
55 sty sp+1 ; set argument stack ptr
57 ; If we have IRQ functions, chain our stub into the IRQ vector
59 lda #<__INTERRUPTOR_COUNT__
72 ; Call module constructors
76 ; Push arguments and call main()
80 ; Call module destructors. This is also the _exit entry.
82 _exit: pha ; Save the return code on stack
83 jsr donelib ; Run module destructors
85 ; Reset the IRQ vector if we chained it.
87 pha ; Save the return code on stack
88 lda #<__INTERRUPTOR_COUNT__
97 ; Copy back the zero page stuff
99 NoIRQ2: ldx #zpspace-1
105 ; Store the return code into ST
110 ; Restore the stack pointer
119 ; ------------------------------------------------------------------------
120 ; The IRQ vector jumps here, if condes routines are defined with type 2.
123 cld ; Just to be sure
124 jsr callirq ; Call the functions
125 jmp IRQInd ; Jump to the saved IRQ vector
127 ; ------------------------------------------------------------------------