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) + $30)
28 .byte <(((Start / 100) .mod 10) + $30)
29 .byte <(((Start / 10) .mod 10) + $30)
30 .byte <(((Start / 1) .mod 10) + $30)
31 .byte $00 ; End of BASIC line
32 @Next: .word 0 ; BASIC end marker
34 ; ------------------------------------------------------------------------
45 ; Save the zero page locations we need
53 ; Switch to second charset
58 ; Switch off the BASIC ROM
61 pha ; Remember the value
63 ora #$06 ; Enable kernal+I/O, disable basic
70 ; Save system settings and setup the stack
73 sta mmusave ; Save the memory configuration
76 stx spsave ; Save the system stack ptr
78 lda #<(__RAM_START__ + __RAM_SIZE__)
80 lda #>(__RAM_START__ + __RAM_SIZE__)
81 sta sp+1 ; Set argument stack ptr
83 ; If we have IRQ functions, chain our stub into the IRQ vector
85 lda #<__INTERRUPTOR_COUNT__
98 ; Call module constructors
102 ; Push arguments and call main
106 ; Back from main (This is also the _exit entry). Run module destructors
111 ; Reset the IRQ vector if we chained it.
113 pha ; Save the return code on stack
114 lda #<__INTERRUPTOR_COUNT__
123 ; Copy back the zero page stuff
125 NoIRQ2: ldx #zpspace-1
131 ; Place the program return code into ST
136 ; Restore system stuff
139 txs ; Restore stack pointer
141 stx $01 ; Restore memory configuration
143 ; Reset changed vectors, back to basic
147 ; ------------------------------------------------------------------------
148 ; The IRQ vector jumps here, if condes routines are defined with type 2.
151 cld ; Just to be sure
152 jsr callirq ; Call the functions
153 jmp IRQInd ; Jump to the saved IRQ vector
155 ; ------------------------------------------------------------------------