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
15 .include "zeropage.inc"
19 ; ------------------------------------------------------------------------
26 ; Save the zero page locations we need
34 ; Switch to second charset
39 ; Switch off the BASIC ROM
42 pha ; Remember the value
44 ora #$06 ; Enable kernal+I/O, disable basic
51 ; Save system settings and setup the stack
54 sta mmusave ; Save the memory configuration
57 stx spsave ; Save the system stack ptr
59 lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
61 lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
62 sta sp+1 ; Set argument stack ptr
64 ; If we have IRQ functions, chain our stub into the IRQ vector
66 lda #<__INTERRUPTOR_COUNT__
79 ; Call module constructors
83 ; Push arguments and call main
87 ; Back from main (This is also the _exit entry). Run module destructors
92 ; Reset the IRQ vector if we chained it.
94 pha ; Save the return code on stack
95 lda #<__INTERRUPTOR_COUNT__
104 ; Copy back the zero page stuff
106 NoIRQ2: ldx #zpspace-1
112 ; Place the program return code into ST
117 ; Restore system stuff
120 txs ; Restore stack pointer
122 stx $01 ; Restore memory configuration
124 ; Reset changed vectors, back to basic
128 ; ------------------------------------------------------------------------
129 ; The IRQ vector jumps here, if condes routines are defined with type 2.
132 cld ; Just to be sure
133 jsr callirq ; Call the functions
134 jmp IRQInd ; Jump to the saved IRQ vector
136 ; ------------------------------------------------------------------------