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
15 .include "zeropage.inc"
18 ; ------------------------------------------------------------------------
25 ; Save the zero page locations we need
33 ; Switch to second charset
42 ; Save system stuff and setup the stack
45 stx spsave ; Save the system stack ptr
47 lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
49 lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
50 sta sp+1 ; Set argument stack ptr
52 ; If we have IRQ functions, chain our stub into the IRQ vector
54 lda #<__INTERRUPTOR_COUNT__
67 ; Call module constructors
71 ; Push arguments and call main()
75 ; Back from main (This is also the _exit entry). Run module destructors
79 ; Reset the IRQ vector if we chained it.
81 pha ; Save the return code on stack
82 lda #<__INTERRUPTOR_COUNT__
91 ; Copy back the zero page stuff
93 NoIRQ2: ldx #zpspace-1
99 ; Place the program return code into ST
104 ; Restore the stack pointer
114 ; ------------------------------------------------------------------------
115 ; The IRQ vector jumps here, if condes routines are defined with type 2.
118 cld ; Just to be sure
119 jsr callirq ; Call the functions
120 jmp IRQInd ; Jump to the saved IRQ vector
122 ; ------------------------------------------------------------------------