]> git.sur5r.net Git - cc65/blob - libsrc/lynx/crt0.s
6653b6d3b7d630662fd76795f51fe965dda9b5e5
[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 ; This must be the *first* file on the linker command line
18 ;
19
20         .include        "lynx.inc"
21         .export         _exit
22         .exportzp       __iodat,__iodir,__viddma,__sprsys
23
24         .import         initlib, donelib
25         .import         zerobss
26         .import         callmain
27         .import         _main
28         .import         __BSS_LOAD__
29         .import         __RAM_START__, __RAM_SIZE__
30
31         .include        "zeropage.inc"
32
33
34 ; ------------------------------------------------------------------------
35 ; EXE header (BLL header)
36
37         .segment "EXEHDR"
38         .word   $0880
39         .dbyt   __RAM_START__
40         .dbyt   __BSS_LOAD__ - 1
41         .byte   $42,$53
42         .byte   $39,$33
43
44
45 ; ------------------------------------------------------------------------
46 ; Mikey and Suzy init data, reg offsets and data
47
48         .rodata
49
50 SuzyInitReg:    .byte $28,$2a,$04,$06,$92,$83,$90
51 SuzyInitData:   .byte $7f,$7f,$00,$00,$24,$f3,$01
52
53 MikeyInitReg:   .byte $00,$01,$08,$09,$20,$28,$30,$38,$44,$50,$8a,$8b,$8c,$92,$93
54 MikeyInitData:  .byte $9e,$18,$68,$1f,$00,$00,$00,$00,$00,$ff,$1a,$1b,$04,$0d,$29
55
56
57 ; ------------------------------------------------------------------------
58 ; mikey and suzy shadow registers
59
60        .segment "EXTZP" : zeropage
61
62 __iodat:    .res    1
63 __iodir:    .res    1
64 __viddma:   .res    1
65 __sprsys:   .res    1
66
67
68 ; ------------------------------------------------------------------------
69 ; Actual code
70
71         .segment "STARTUP"
72
73 ; set up system
74
75         sei
76         cld
77         ldx     #$FF
78         txs
79
80 ; init bank switching
81
82         lda     #$C
83         sta     MAPCTL                  ; $FFF9
84
85 ; disable all timer interrupts
86
87         lda     #$80
88         trb     TIM0CTLA
89         trb     TIM1CTLA
90         trb     TIM2CTLA
91         trb     TIM3CTLA
92         trb     TIM5CTLA
93         trb     TIM6CTLA
94         trb     TIM7CTLA
95
96 ; disable TX/RX IRQ, set to 8E1
97
98         lda     #%11101
99         sta     SERCTL
100
101 ; clear all pending interrupts
102
103         lda     INTSET
104         sta     INTRST
105
106 ; setup the stack
107
108         lda     #<(__RAM_START__ + __RAM_SIZE__)
109         sta     sp
110         lda     #>(__RAM_START__ + __RAM_SIZE__)
111         sta     sp+1
112
113 ; Init Mickey
114
115         ldx     #.sizeof(MikeyInitReg)-1
116 mloop:  ldy     MikeyInitReg,x
117         lda     MikeyInitData,x
118         sta     $fd00,y
119         dex
120         bpl     mloop
121
122 ; these are RAM-shadows of read only regs
123
124         ldx     #$1b
125         stx     __iodat
126         dex                             ; $1A
127         stx     __iodir
128         ldx     #$d
129         stx     __viddma
130
131 ; Init Suzy
132
133         ldx     #.sizeof(SuzyInitReg)-1
134 sloop:  ldy     SuzyInitReg,x
135         lda     SuzyInitData,x
136         sta     $fc00,y
137         dex
138         bpl     sloop
139
140         lda     #$24
141         sta     __sprsys
142
143 ; Clear the BSS data
144
145         jsr     zerobss
146
147 ; Call module constructors
148
149         jsr     initlib
150
151 ; Push arguments and call main
152
153         jsr     callmain
154
155 ; Call module destructors. This is also the _exit entry.
156
157 _exit:  jsr     donelib         ; Run module destructors
158
159 ; Endless loop
160
161 noret:  bra     noret
162
163