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
13 .import __STACKSIZE__ ; Linker generated
16 .include "zeropage.inc"
20 ; ------------------------------------------------------------------------
27 ; Save the zero page locations we need
35 ; Switch to second charset
40 ; Switch off the BASIC ROM
43 pha ; Remember the value
45 ora #$06 ; Enable kernal+I/O, disable basic
52 ; Save system settings and setup the stack
55 sta mmusave ; Save the memory configuration
58 stx spsave ; Save the system stack ptr
60 lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
62 lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
63 sta sp+1 ; Set argument stack ptr
65 ; If we have IRQ functions, chain our stub into the IRQ vector
67 lda #<__INTERRUPTOR_COUNT__
80 ; Call module constructors
84 ; Push arguments and call main
88 ; Back from main (This is also the _exit entry). Run module destructors
93 ; Reset the IRQ vector if we chained it.
95 pha ; Save the return code on stack
96 lda #<__INTERRUPTOR_COUNT__
105 ; Copy back the zero page stuff
107 NoIRQ2: ldx #zpspace-1
113 ; Place the program return code into ST
118 ; Restore system stuff
121 txs ; Restore stack pointer
123 stx $01 ; Restore memory configuration
129 ; ------------------------------------------------------------------------
130 ; The IRQ vector jumps here, if condes routines are defined with type 2.
133 cld ; Just to be sure
134 jsr callirq ; Call the functions
135 jmp IRQInd ; Jump to the saved IRQ vector
137 ; ------------------------------------------------------------------------