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 __RAM_START__, __RAM_SIZE__ ; Linker generated
13 .include "zeropage.inc"
15 .include "../cbm/cbm.inc"
17 ; ------------------------------------------------------------------------
18 ; BASIC header with a SYS call
21 .word Head ; Load address
23 .word 1000 ; Line number
25 .byte <(((@Start / 1000) .mod 10) + $30)
26 .byte <(((@Start / 100) .mod 10) + $30)
27 .byte <(((@Start / 10) .mod 10) + $30)
28 .byte <(((@Start / 1) .mod 10) + $30)
29 .byte $00 ; End of BASIC line
30 @Next: .word 0 ; BASIC end marker
33 ; ------------------------------------------------------------------------
40 sta zpsave,x ; 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 ; Call module constructors
71 ; Pass an empty command line
76 ldy #4 ; Argument size
77 jsr _main ; call the users code
79 ; Call module destructors. This is also the _exit entry.
81 _exit: jsr donelib ; Run module destructors
83 ; Restore system stuff
86 txs ; Restore stack pointer
88 ; Copy back the zero page stuff
96 ; Reset changed vectors, back to basic