2 ; Startup code for cc65 (Oric version)
4 ; By Debrune Jérôme <jede@oric.org> and Ullrich von Bassewitz <uz@cc65.org>
8 .export __STARTUP__ : absolute = 1 ; Mark as startup
9 .import initlib, donelib
10 .import callmain, zerobss, callirq
11 .import __INTERRUPTOR_COUNT__
12 .import __RAM_START__, __RAM_SIZE__
13 .import __ZPSAVE_LOAD__, __STACKSIZE__
15 .include "zeropage.inc"
19 ; ------------------------------------------------------------------------
24 .byte $16, $16, $16 ; Sync bytes
25 .byte $24 ; End of header marker
29 .byte $80 ; $2AE Machine code flag
30 .byte $C7 ; $2AD Autoload flag
31 .dbyt __ZPSAVE_LOAD__ - 1 ; $2AB
32 .dbyt __RAM_START__ ; $2A9
34 .byte ((.VERSION >> 8) & $0F) + '0'
35 .byte ((.VERSION >> 4) & $0F) + '0'
36 .byte (.VERSION & $0F) + '0'
37 .byte $00 ; Zero terminated compiler version
39 ; ------------------------------------------------------------------------
40 ; Place the startup code in a special segment.
44 ; Save the zero page area we're about to use
48 sta zpsave,x ; Save the zero page locations we need
56 ; Unprotect columns 0 and 1
63 ; Save system stuff and setup the stack
66 stx spsave ; Save system stk ptr
68 lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
70 lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
71 sta sp+1 ; Set argument stack ptr
73 ; If we have IRQ functions, chain our stub into the IRQ vector
75 lda #<__INTERRUPTOR_COUNT__
88 ; Call module constructors
92 ; Push arguments and call main()
96 ; Call module destructors. This is also the _exit entry.
98 _exit: jsr donelib ; Run module destructors
100 ; Reset the IRQ vector if we chained it.
102 pha ; Save the return code on stack
103 lda #<__INTERRUPTOR_COUNT__
112 ; Restore system stuff
119 ; Copy back the zero page stuff
131 ; ------------------------------------------------------------------------
132 ; The IRQ vector jumps here, if condes routines are defined with type 2.
135 cld ; Just to be sure
141 jsr callirq ; Call the functions
147 jmp IRQInd ; Jump to the saved IRQ vector
149 ; ------------------------------------------------------------------------