2 ; Startup code for cc65 (C64 version)
6 .export __STARTUP__ : absolute = 1 ; Mark as startup
7 .import initlib, donelib, callirq
10 .import RESTOR, BSOUT, CLRCH
11 .import __INTERRUPTOR_COUNT__
12 .import __RAM_START__, __RAM_SIZE__ ; Linker generated
14 .include "zeropage.inc"
18 ; ------------------------------------------------------------------------
19 ; BASIC header with a SYS call
23 .word Head ; Load address
25 .word .version ; Line number
27 .byte <(((Start / 1000) .mod 10) + '0')
28 .byte <(((Start / 100) .mod 10) + '0')
29 .byte <(((Start / 10) .mod 10) + '0')
30 .byte <(((Start / 1) .mod 10) + '0')
31 .byte $00 ; End of BASIC line
32 @Next: .word 0 ; BASIC end marker
34 ; ------------------------------------------------------------------------
41 ; Save the zero page locations we need
49 ; Switch to second charset
54 ; Switch off the BASIC ROM
57 pha ; Remember the value
59 ora #$06 ; Enable kernal+I/O, disable basic
66 ; Save system settings and setup the stack
69 sta mmusave ; Save the memory configuration
72 stx spsave ; Save the system stack ptr
74 lda #<(__RAM_START__ + __RAM_SIZE__)
76 lda #>(__RAM_START__ + __RAM_SIZE__)
77 sta sp+1 ; Set argument stack ptr
79 ; If we have IRQ functions, chain our stub into the IRQ vector
81 lda #<__INTERRUPTOR_COUNT__
94 ; Call module constructors
98 ; Push arguments and call main
102 ; Back from main (This is also the _exit entry). Run module destructors
107 ; Reset the IRQ vector if we chained it.
109 pha ; Save the return code on stack
110 lda #<__INTERRUPTOR_COUNT__
119 ; Copy back the zero page stuff
121 NoIRQ2: ldx #zpspace-1
127 ; Place the program return code into ST
132 ; Restore system stuff
135 txs ; Restore stack pointer
137 stx $01 ; Restore memory configuration
139 ; Reset changed vectors, back to basic
143 ; ------------------------------------------------------------------------
144 ; The IRQ vector jumps here, if condes routines are defined with type 2.
147 cld ; Just to be sure
148 jsr callirq ; Call the functions
149 jmp IRQInd ; Jump to the saved IRQ vector
151 ; ------------------------------------------------------------------------