2 ; Startup code for cc65 (Vic20 version)
6 .export __STARTUP__ : absolute = 1 ; Mark as startup
7 .import initlib, donelib, callirq
10 .import RESTOR, BSOUT, CLRCH
11 .import __INTERRUPTOR_COUNT__
12 .import __RAM_START__, __RAM_SIZE__ ; Linker generated
13 .import __STACKSIZE__ ; Linker generated
16 .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 the system stack ptr
48 lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
50 lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
51 sta sp+1 ; Set argument stack ptr
53 ; If we have IRQ functions, chain our stub into the IRQ vector
55 lda #<__INTERRUPTOR_COUNT__
68 ; Call module constructors
72 ; Push arguments and call main()
76 ; Back from main (This is also the _exit entry). Run module destructors
80 ; Reset the IRQ vector if we chained it.
82 pha ; Save the return code on stack
83 lda #<__INTERRUPTOR_COUNT__
92 ; Copy back the zero page stuff
94 NoIRQ2: ldx #zpspace-1
100 ; Place the program return code into ST
105 ; Restore the stack pointer
115 ; ------------------------------------------------------------------------
116 ; The IRQ vector jumps here, if condes routines are defined with type 2.
119 cld ; Just to be sure
120 jsr callirq ; Call the functions
121 jmp IRQInd ; Jump to the saved IRQ vector
123 ; ------------------------------------------------------------------------