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 __RAM_START__, __RAM_SIZE__ ; Linker generated
13 .include "zeropage.inc"
15 .include "../cbm/cbm.inc"
19 ; ------------------------------------------------------------------------
20 ; BASIC header with a SYS call
23 .word Head ; Load address
25 .word 1000 ; Line number
26 .byte $9E,"2061" ; SYS 2061
27 .byte $00 ; End of BASIC line
28 @Next: .word 0 ; BASIC end marker
31 ; ------------------------------------------------------------------------
36 sta zpsave,x ; Save the zero page locations we need
44 ; Switch to second charset
53 ; Save system stuff and setup the stack
56 stx spsave ; Save the system stack ptr
59 sta mmusave ; Save the memory configuration
61 ora #$06 ; Enable kernal+I/O, disable basic
64 lda #<(__RAM_START__ + __RAM_SIZE__)
66 lda #>(__RAM_START__ + __RAM_SIZE__)
67 sta sp+1 ; Set argument stack ptr
69 ; Call module constructors
73 ; Pass an empty command line
78 ldy #4 ; Argument size
79 jsr _main ; call the users code
81 ; Call module destructors. This is also the _exit entry.
83 _exit: jsr donelib ; Run module destructors
85 ; Restore system stuff
88 txs ; Restore stack pointer
90 sta $01 ; Restore memory configuration
92 ; Copy back the zero page stuff
100 ; Reset changed vectors, back to basic