]> git.sur5r.net Git - cc65/blob - libsrc/lynx/crt0.s
Allow different output formats using additional linker configs. Contributed by
[cc65] / libsrc / lynx / crt0.s
1 ; ***
2 ; CC65 Lynx Library
3 ;
4 ; Originally by Bastian Schick
5 ; http://www.geocities.com/SiliconValley/Byte/4242/lynx/
6 ;
7 ; Ported to cc65 (http://www.cc65.org) by
8 ; Shawn Jefferson, June 2004
9 ;
10 ; ***
11 ;
12 ; Startup code for cc65 (Lynx version).  Based on Atari 8-bit startup
13 ; code structure.  The C stack is located at the end of the RAM memory
14 ; segment and grows downward.  Bastian Schick's executable header is put
15 ; on the front of the fully linked binary (see EXEHDR segment.)
16 ;
17
18         .include        "lynx.inc"
19         .export         _exit
20         .export         __STARTUP__ : absolute = 1      ; Mark as startup
21
22         .import         callirq, initlib, donelib
23         .import         zerobss
24         .import         callmain
25         .import         _main
26         .import         __INTERRUPTOR_COUNT__
27         .import         __RAM_START__, __RAM_SIZE__, __STACKSIZE__
28
29         .include        "zeropage.inc"
30         .include        "extzp.inc"
31
32 ; ------------------------------------------------------------------------
33 ; Mikey and Suzy init data, reg offsets and data
34
35         .rodata
36
37 SuzyInitReg:    .byte $28,$2a,$04,$06,$92,$83,$90
38 SuzyInitData:   .byte $7f,$7f,$00,$00,$24,$f3,$01
39
40 MikeyInitReg:   .byte $00,$01,$08,$09,$20,$28,$30,$38,$44,$50,$8a,$8b,$8c,$92,$93
41 MikeyInitData:  .byte $9e,$18,$68,$1f,$00,$00,$00,$00,$00,$ff,$1a,$1b,$04,$0d,$29
42
43
44 ; ------------------------------------------------------------------------
45 ; Actual code
46
47         .segment "STARTUP"
48
49 ; set up system
50
51         sei
52         cld
53         ldx     #$FF
54         txs
55
56 ; init bank switching
57
58         lda     #$C
59         sta     MAPCTL                  ; $FFF9
60
61 ; disable all timer interrupts
62
63         lda     #$80
64         trb     TIM0CTLA
65         trb     TIM1CTLA
66         trb     TIM2CTLA
67         trb     TIM3CTLA
68         trb     TIM5CTLA
69         trb     TIM6CTLA
70         trb     TIM7CTLA
71
72 ; disable TX/RX IRQ, set to 8E1
73
74         lda     #%11101
75         sta     SERCTL
76
77 ; clear all pending interrupts
78
79         lda     INTSET
80         sta     INTRST
81
82 ; setup the stack
83
84         lda     #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
85         sta     sp
86         lda     #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
87         sta     sp+1
88
89 ; Init Mickey
90
91         ldx     #.sizeof(MikeyInitReg)-1
92 mloop:  ldy     MikeyInitReg,x
93         lda     MikeyInitData,x
94         sta     $fd00,y
95         dex
96         bpl     mloop
97
98 ; these are RAM-shadows of read only regs
99
100         ldx     #$1b
101         stx     __iodat
102         dex                             ; $1A
103         stx     __iodir
104         ldx     #$d
105         stx     __viddma
106
107 ; Init Suzy
108
109         ldx     #.sizeof(SuzyInitReg)-1
110 sloop:  ldy     SuzyInitReg,x
111         lda     SuzyInitData,x
112         sta     $fc00,y
113         dex
114         bpl     sloop
115
116         lda     #$24
117         sta     __sprsys
118
119 ; Clear the BSS data
120
121         jsr     zerobss
122
123 ; If we have IRQ functions, set the IRQ vector
124 ; as Lynx is a console there is not much point in releasing the IRQ
125
126         lda     #<__INTERRUPTOR_COUNT__
127         beq     NoIRQ1
128         lda     #<IRQStub
129         ldx     #>IRQStub
130         sei
131         sta     INTVECTL
132         stx     INTVECTH
133         cli
134
135 ; Call module constructors
136
137 NoIRQ1: jsr     initlib
138
139 ; Push arguments and call main
140
141         jsr     callmain
142
143 ; Call module destructors. This is also the _exit entry.
144
145 _exit:  jsr     donelib         ; Run module destructors
146
147 ; Endless loop
148
149 noret:  bra     noret
150
151
152         .segment "CODE"
153 IRQStub:
154         phy
155         phx
156         pha
157         cld
158         jsr     callirq
159         lda     INTSET
160         sta     INTRST
161         pla
162         plx
163         ply
164         rti
165