2 ; Startup code for cc65 (PET version)
4 ; This must be the *first* file on the linker command line
8 .import initlib, donelib
13 .include "zeropage.inc"
15 .include "../cbm/cbm.inc"
17 ; ------------------------------------------------------------------------
18 ; Create an empty LOWCODE segment to avoid linker warnings
22 ; ------------------------------------------------------------------------
23 ; Place the startup code in a special segment.
27 ; BASIC header with a SYS call
29 .word Head ; Load address
31 .word 1000 ; Line number
32 .byte $9E,"1037" ; SYS 1037
33 .byte $00 ; End of BASIC line
34 @Next: .word 0 ; BASIC end marker
36 ; ------------------------------------------------------------------------
41 sta zpsave,x ; Save the zero page locations we need
49 ; Switch to second charset
52 ; sta $E84C ; See PET FAQ
59 ; Save system stuff and setup the stack
62 stx spsave ; Save the system stack ptr
67 sta sp+1 ; Set argument stack ptr
69 ; Call module constructors
73 ; Push arguments and call main()
77 ; Call module destructors. This is also the _exit entry.
79 _exit: jsr donelib ; Run module destructors
81 ; Restore system stuff
84 txs ; Restore stack pointer
86 ; Copy back the zero page stuff
99 ; ------------------------------------------------------------------------