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 ; Place the startup code in a special segment.
23 ; BASIC header with a SYS call
25 .word Head ; Load address
27 .word 1000 ; Line number
28 .byte $9E,"2061" ; SYS 2061
29 .byte $00 ; End of BASIC line
30 @Next: .word 0 ; BASIC end marker
32 ; ------------------------------------------------------------------------
37 sta zpsave,x ; Save the zero page locations we need
45 ; Switch to second charset
50 ; Switch off the BASIC ROM
53 pha ; Remember the value
55 ora #$06 ; Enable kernal+I/O, disable basic
62 ; Save system settings and setup the stack
65 sta mmusave ; Save the memory configuration
68 stx spsave ; Save the system stack ptr
70 lda #<(__RAM_START__ + __RAM_SIZE__)
72 lda #>(__RAM_START__ + __RAM_SIZE__)
73 sta sp+1 ; Set argument stack ptr
75 ; Call module constructors
79 ; Push arguments and call main
83 ; Call module destructors. This is also the _exit entry.
85 _exit: jsr donelib ; Run module destructors
87 ; Restore system stuff
90 txs ; Restore stack pointer
92 sta $01 ; Restore memory configuration
94 ; Copy back the zero page stuff
102 ; Reset changed vectors, back to basic
107 ; ------------------------------------------------------------------------