2 ; Startup code for cc65 (Apple2 version)
4 ; This must be the *first* file on the linker command line
9 .import initlib, donelib
10 .import callmain, callirq
11 .import __STARTUP_LOAD__, __BSS_LOAD__ ; Linker generated
12 .import __INTERRUPTOR_COUNT__ ; Linker generated
14 .include "zeropage.inc"
18 ; ------------------------------------------------------------------------
22 .addr __STARTUP_LOAD__ ; Start address
23 .word __BSS_LOAD__ - __STARTUP_LOAD__ ; Size
25 ; ------------------------------------------------------------------------
29 ; ProDOS TechRefMan, chapter 5.2.1:
30 ; "For maximum interrupt efficiency, a system program should not
31 ; use more than the upper 3/4 of the stack."
33 txs ; Init stack pointer
35 ; Delegate all further processing to keep STARTUP small
38 ; Avoid re-entrance of donelib. This is also the _exit entry
41 jsr reset ; Setup RESET vector
43 ; Check for valid interrrupt vector table entry number
47 ; Deallocate interrupt vector table entry
48 dec params ; Adjust parameter count
50 .byte $41 ; Dealloc interrupt
53 ; Call module destructors
56 ; Restore the original RESET vector. This is also the __Exit entry
63 ; Copy back the zero page stuff
70 ; ProDOS TechRefMan, chapter 5.2.1:
71 ; "System programs should set the stack pointer to $FF at the
72 ; warm-start entry point."
74 txs ; Re-init stack pointer
79 ; ------------------------------------------------------------------------
83 ; Save the zero page locations we need
90 ; Save the original RESET vector
97 ; ProDOS TechRefMan, chapter 5.3.5:
98 ; "Your system program should place in the RESET vector the
99 ; address of a routine that ... closes the files."
102 jsr reset ; Setup RESET vector
111 sta sp+1 ; Set argument stack ptr
113 ; Call module constructors
116 ; Check for interruptors
117 lda #<__INTERRUPTOR_COUNT__
122 cmp #$4C ; Is MLI present? (JMP opcode)
125 ; Allocate interrupt vector table entry
127 .byte $40 ; Alloc interrupt
130 ; Push arguments and call main()
133 ; ------------------------------------------------------------------------
137 ; ProDOS TechRefMan, chapter 6.2:
138 ; "Each installed routine must begin with a CLD instruction"
144 ; ProDOS TechRefMan, chapter 6.2:
145 ; "When the routine that can process the interrupt is called, it
146 ; should ... return (via an RTS) with the carry flag clear."
150 ; ------------------------------------------------------------------------
161 ; ------------------------------------------------------------------------
169 params: .byte $02 ; Parameter count
170 intnum: .byte $00 ; Interrupt number
171 .addr intrpt ; Interrupt handler