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
14 .include "zeropage.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) + '0')
27 .byte <(((Start / 100) .mod 10) + '0')
28 .byte <(((Start / 10) .mod 10) + '0')
29 .byte <(((Start / 1) .mod 10) + '0')
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
57 ; Save system stuff and setup the stack
60 stx spsave ; Save the system stack ptr
62 lda #<(__RAM_START__ + __RAM_SIZE__)
64 lda #>(__RAM_START__ + __RAM_SIZE__)
65 sta sp+1 ; Set argument stack ptr
67 ; If we have IRQ functions, chain our stub into the IRQ vector
69 lda #<__INTERRUPTOR_COUNT__
82 ; Call module constructors
86 ; Push arguments and call main()
90 ; Back from main (This is also the _exit entry). Run module destructors
94 ; Reset the IRQ vector if we chained it.
96 pha ; Save the return code on stack
97 lda #<__INTERRUPTOR_COUNT__
106 ; Copy back the zero page stuff
108 NoIRQ2: ldx #zpspace-1
114 ; Place the program return code into ST
119 ; Restore the stack pointer
124 ; Reset changed vectors, back to basic
129 ; ------------------------------------------------------------------------
130 ; The IRQ vector jumps here, if condes routines are defined with type 2.
133 cld ; Just to be sure
134 jsr callirq ; Call the functions
135 jmp IRQInd ; Jump to the saved IRQ vector
137 ; ------------------------------------------------------------------------