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"
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
33 .byte $9E,"2061" ; SYS 2061
34 .byte $00 ; End of BASIC line
35 @Next: .word 0 ; BASIC end marker
37 ; ------------------------------------------------------------------------
42 sta zpsave,x ; Save the zero page locations we need
50 ; Switch to second charset
55 ; Switch off the BASIC ROM
58 pha ; Remember the value
60 ora #$06 ; Enable kernal+I/O, disable basic
67 ; Save system settings and setup the stack
70 sta mmusave ; Save the memory configuration
73 stx spsave ; Save the system stack ptr
75 lda #<(__RAM_START__ + __RAM_SIZE__)
77 lda #>(__RAM_START__ + __RAM_SIZE__)
78 sta sp+1 ; Set argument stack ptr
80 ; Call module constructors
84 ; Pass an empty command line
89 ldy #4 ; Argument size
90 jsr _main ; call the users code
92 ; Call module destructors. This is also the _exit entry.
94 _exit: jsr donelib ; Run module destructors
96 ; Restore system stuff
99 txs ; Restore stack pointer
101 sta $01 ; Restore memory configuration
103 ; Copy back the zero page stuff
111 ; Reset changed vectors, back to basic
116 ; ------------------------------------------------------------------------