2 ; Startup code for cc65 (PCEngine version)
4 ; by Groepaz/Hitmen <groepaz@gmx.net>
5 ; based on code by Ullrich von Bassewitz <uz@cc65.org>
7 ; This must be the *first* file on the linker command line
11 .export __STARTUP__ : absolute = 1 ; Mark as startup
13 .import initlib, donelib
14 .import push0, _main, zerobss
16 .import tmp1,tmp2,tmp3
19 .import __RAM_START__, __RAM_SIZE__
20 .import __ROM0_START__, __ROM0_SIZE__
21 .import __ROM_START__, __ROM_SIZE__
22 .import __STARTUP_LOAD__,__STARTUP_RUN__, __STARTUP_SIZE__
23 .import __CODE_LOAD__,__CODE_RUN__, __CODE_SIZE__
24 .import __RODATA_LOAD__,__RODATA_RUN__, __RODATA_SIZE__
25 .import __DATA_LOAD__,__DATA_RUN__, __DATA_SIZE__
33 ; ------------------------------------------------------------------------
34 ; Create an empty LOWCODE segment to avoid linker warnings
38 ; ------------------------------------------------------------------------
39 ; Place the startup code in a special segment.
45 ; setup the CPU and System-IRQ
51 csh ; set high speed CPU mode
56 ; Setup stack and memory mapping
57 ldx #$FF ; Stack top ($21FF)
60 ; at startup all MPRs are set to 0, so init them
62 tam #%00000001 ; 0000-1FFF = Hardware page
64 tam #%00000010 ; 2000-3FFF = Work RAM
66 ;tam #%00000100 ; 4000-5FFF = Save RAM
68 ;tam #%00001000 ; 6000-7FFF Page 2
70 ;tam #%00010000 ; 8000-9FFF Page 3
72 ;tam #%00100000 ; A000-BFFF Page 4
74 ;tam #%01000000 ; C000-DFFF Page 5
76 ;tam #%10000000 ; e000-fFFF hucard/syscard bank 0
78 ; Clear work RAM (2000-3FFF)
80 tii $2000, $2001, $1FFF
83 stz TIMER_COUNT ; Timer off
85 sta IRQ_MASK ; Interrupts off
86 stz IRQ_STATUS ; Acknowledge timer
88 ;; FIXME; i dont know why the heck this one doesnt work when called from a constructor :/
92 ; Turn on background and VD interrupt/IRQ1
94 sta IRQ_MASK ; IRQ1=on
101 ; Copy the .data segment to RAM
102 lda #<(__DATA_LOAD__)
104 lda #>(__DATA_LOAD__)
111 ldx #>(__DATA_SIZE__)
113 beq @s1 ; no more full pages
129 ; copy remaining bytes
137 cpy #<(__DATA_SIZE__)
141 lda #<(__RAM_START__+__RAM_SIZE__)
143 lda #>(__RAM_START__+__RAM_SIZE__)
149 ; Call module constructors
152 ; Pass an empty command line
156 ldy #4 ; Argument size
157 jsr _main ; call the users code
159 ; Call module destructors. This is also the _exit entry.
161 jsr donelib ; Run module destructors
163 ; reset the PCEngine (start over)
166 ; ------------------------------------------------------------------------
167 ; System V-Blank Interupt
168 ; FIXME: hooks should be provided so the user can abuse the IRQ
169 ; ------------------------------------------------------------------------
185 ; Acknowlege interrupt
204 ; ------------------------------------------------------------------------
206 ; ------------------------------------------------------------------------
209 .word _irq2 ; $fff6 IRQ2 (External IRQ, BRK)
210 .word _irq1 ; $fff8 IRQ1 (VDC)
211 .word _timer ; $fffa Timer
212 .word _nmi ; $fffc NMI
213 .word start ; $fffe reset