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 ; 2018-02-11, Greg King
11 .export __STARTUP__ : absolute = 1 ; Mark as startup
13 .import initlib, donelib
19 .import __DATA_LOAD__, __DATA_RUN__, __DATA_SIZE__
20 .import __BSS_RUN__, __BSS_SIZE__
21 .import __MAIN_START__, __MAIN_SIZE__, __STACKSIZE__
28 ; ------------------------------------------------------------------------
29 ; Place the startup code in a special segment.
35 ; Set up the CPU and System-IRQ
40 csh ; Set high speed CPU mode
45 ; Set up stack and memory mapping
46 ldx #$FF ; Stack top ($21FF)
49 ; At power-on, most MPRs have random values; so, initiate them.
51 tam #%00000001 ; $0000-$1FFF = Hardware bank
53 tam #%00000010 ; $2000-$3FFF = Work RAM
55 ;tam #%00000100 ; $4000-$47FF = 2K Battery-backed RAM
57 ;tam #%00001000 ; $6000-$7FFF
63 tam #%00010000 ; $8000-$9FFF = ROM bank 1 (32K block of ROM)
65 tam #%00100000 ; $A000-$BFFF = ROM bank 2
67 @L1: tam #%01000000 ; $C000-$DFFF = ROM bank 3 (32K) or 1 (16K)
68 ;lda #$00 ; (The reset default)
69 ;tam #%10000000 ; $E000-$FFFF hucard/syscard bank 0
72 stz TIMER_CTRL ; Timer off
74 sta IRQ_MASK ; Interrupts off
75 stz IRQ_STATUS ; Acknowledge timer
77 ; FIXME; i dont know why the heck this one doesnt work when called from a constructor :/
81 ; Turn on background and VD interrupt/IRQ1
83 sta IRQ_MASK ; IRQ1=on
85 ; Copy the .data segment to RAM
86 tii __DATA_LOAD__, __DATA_RUN__, __DATA_SIZE__
88 ; Clear the .bss segment
90 tii __BSS_RUN__, __BSS_RUN__ + 1, __BSS_SIZE__ - 1
93 lda #<(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
94 ldx #>(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
98 ; Call module constructors
101 cli ; allow IRQ only after constructors have run
103 ; Pass an empty command line
107 ldy #4 ; Argument size
108 jsr _main ; Call the users code
110 ; Call module destructors. This is also the _exit entry.
112 jsr donelib ; Run module destructors
114 ; reset the PCEngine (start over)
124 ; ------------------------------------------------------------------------
126 ; ------------------------------------------------------------------------
129 .word IRQStub ; $fff6 IRQ2 (External IRQ, BRK)
130 .word IRQStub ; $fff8 IRQ1 (VDC)
131 .word IRQStub ; $fffa Timer
132 .word _nmi ; $fffc NMI
133 .word start ; $fffe reset