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 ; Create an empty LOWCODE segment to avoid linker warnings
23 ; ------------------------------------------------------------------------
24 ; Place the startup code in a special segment.
28 ; BASIC header with a SYS call
30 .word Head ; Load address
32 .word 1000 ; Line number
34 .byte <(((@Start / 1000) .mod 10) + $30)
35 .byte <(((@Start / 100) .mod 10) + $30)
36 .byte <(((@Start / 10) .mod 10) + $30)
37 .byte <(((@Start / 1) .mod 10) + $30)
38 .byte $00 ; End of BASIC line
39 @Next: .word 0 ; BASIC end marker
42 ; ------------------------------------------------------------------------
47 sta zpsave,x ; Save the zero page locations we need
55 ; Switch to second charset
64 ; Save system stuff and setup the stack
67 stx spsave ; Save the system stack ptr
69 lda #<(__RAM_START__ + __RAM_SIZE__)
71 lda #>(__RAM_START__ + __RAM_SIZE__)
72 sta sp+1 ; Set argument stack ptr
74 ; Call module constructors
78 ; Push arguments and call main()
82 ; Call module destructors. This is also the _exit entry.
84 _exit: jsr donelib ; Run module destructors
86 ; Restore system stuff
89 txs ; Restore stack pointer
91 ; Copy back the zero page stuff
99 ; Reset changed vectors, back to basic
104 ; ------------------------------------------------------------------------