2 ; Startup code for cc65 (C64 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"
20 ; ------------------------------------------------------------------------
21 ; BASIC header with a SYS call
24 .word Head ; Load address
26 .word 1000 ; Line number
27 .byte $9E,"2061" ; SYS 2061
28 .byte $00 ; End of BASIC line
29 @Next: .word 0 ; BASIC end marker
32 ; ------------------------------------------------------------------------
37 sta zpsave,x ; Save the zero page locations we need
45 ; Switch to second charset
54 ; Save system stuff and setup the stack
57 stx spsave ; Save the system stack ptr
60 sta mmusave ; Save the memory configuration
62 ora #$06 ; Enable kernal+I/O, disable basic
65 lda #<(__RAM_START__ + __RAM_SIZE__)
67 lda #>(__RAM_START__ + __RAM_SIZE__)
68 sta sp+1 ; Set argument stack ptr
70 ; Call module constructors
74 ; Pass an empty command line
79 ldy #4 ; Argument size
80 jsr _main ; call the users code
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 sta $01 ; Restore memory configuration
93 ; Copy back the zero page stuff
101 ; Reset changed vectors, back to basic