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 ; Place the startup code in a special segment.
22 ; BASIC header with a SYS call
24 .word Head ; Load address
26 .word .version ; Line number
28 .byte <(((@Start / 1000) .mod 10) + $30)
29 .byte <(((@Start / 100) .mod 10) + $30)
30 .byte <(((@Start / 10) .mod 10) + $30)
31 .byte <(((@Start / 1) .mod 10) + $30)
32 .byte $00 ; End of BASIC line
33 @Next: .word 0 ; BASIC end marker
36 ; ------------------------------------------------------------------------
41 sta zpsave,x ; Save the zero page locations we need
49 ; Switch to second charset
58 ; Save system stuff and setup the stack
61 stx spsave ; Save the system stack ptr
63 lda #<(__RAM_START__ + __RAM_SIZE__)
65 lda #>(__RAM_START__ + __RAM_SIZE__)
66 sta sp+1 ; Set argument stack ptr
68 ; If we have IRQ functions, chain our stub into the IRQ vector
70 lda #<__INTERRUPTOR_COUNT__
83 ; Call module constructors
87 ; Push arguments and call main()
91 ; Back from main (This is also the _exit entry). Run module destructors
95 ; Reset the IRQ vector if we chained it.
97 pha ; Save the return code on stack
98 lda #<__INTERRUPTOR_COUNT__
107 ; Copy back the zero page stuff
109 NoIRQ2: ldx #zpspace-1
115 ; Place the program return code into ST
120 ; Restore the stack pointer
125 ; Reset changed vectors, back to basic
130 ; ------------------------------------------------------------------------
131 ; The IRQ vector jumps here, if condes routines are defined with type 2.
134 cld ; Just to be sure
135 jsr callirq ; Call the functions
136 jmp IRQInd ; Jump to the saved IRQ vector
138 ; ------------------------------------------------------------------------