2 ; Startup code for cc65 (Vic20 version)
4 ; This must be the *first* file on the linker command line
8 .import initlib, donelib
11 .import RESTOR, BSOUT, CLRCH
12 .import __RAM_START__, __RAM_SIZE__ ; Linker generated
14 .include "zeropage.inc"
16 .include "../cbm/cbm.inc"
18 ; ------------------------------------------------------------------------
19 ; Place the startup code in a special segment.
23 ; BASIC header with a SYS call
25 .word Head ; Load address
27 .word .version ; Line number
29 .byte <(((@Start / 1000) .mod 10) + $30)
30 .byte <(((@Start / 100) .mod 10) + $30)
31 .byte <(((@Start / 10) .mod 10) + $30)
32 .byte <(((@Start / 1) .mod 10) + $30)
33 .byte $00 ; End of BASIC line
34 @Next: .word 0 ; BASIC end marker
37 ; ------------------------------------------------------------------------
42 sta zpsave,x ; Save the zero page locations we need
50 ; Switch to second charset
59 ; Save system stuff and setup the stack
62 stx spsave ; Save the system stack ptr
64 lda #<(__RAM_START__ + __RAM_SIZE__)
66 lda #>(__RAM_START__ + __RAM_SIZE__)
67 sta sp+1 ; Set argument stack ptr
69 ; Call module constructors
73 ; Push arguments and call main()
77 ; Call module destructors. This is also the _exit entry.
79 _exit: jsr donelib ; Run module destructors
81 ; Restore system stuff
84 txs ; Restore stack pointer
86 ; Copy back the zero page stuff
94 ; Reset changed vectors, back to basic
99 ; ------------------------------------------------------------------------