]> git.sur5r.net Git - cc65/blob - libsrc/lynx/crt0.s
Merge remote-tracking branch 'upstream/master' into creativision
[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 the 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         .export         _exit
19         .export         __STARTUP__ : absolute = 1      ; Mark as startup
20
21         .import         initlib, donelib
22         .import         zerobss
23         .import         callmain
24         .import         _main
25         .import         __MAIN_START__, __MAIN_SIZE__, __STACKSIZE__
26
27         .include        "zeropage.inc"
28         .include        "extzp.inc"
29         .include        "lynx.inc"
30
31 ; ------------------------------------------------------------------------
32 ; Mikey and Suzy init data, reg offsets and data
33
34         .rodata
35
36 SuzyInitReg:    .byte $28,$2a,$04,$06,$92,$83,$90
37 SuzyInitData:   .byte $7f,$7f,$00,$00,$24,$f3,$01
38
39 MikeyInitReg:   .byte $00,$01,$08,$09,$20,$28,$30,$38,$44,$50,$8a,$8b,$8c,$92,$93
40 MikeyInitData:  .byte $9e,$18,$68,$1f,$00,$00,$00,$00,$00,$ff,$1a,$1b,$04,$0d,$29
41
42 ; ------------------------------------------------------------------------
43 ; Actual code
44
45         .segment "STARTUP"
46
47 ; Set up the system.
48
49         sei
50         cld
51         ldx     #$FF
52         txs
53
54 ; Init the bank switching.
55
56         lda     #$C
57         sta     MAPCTL          ; $FFF9
58
59 ; Disable all timer interrupts.
60
61         lda     #$80
62         trb     TIM0CTLA
63         trb     TIM1CTLA
64         trb     TIM2CTLA
65         trb     TIM3CTLA
66         trb     TIM5CTLA
67         trb     TIM6CTLA
68         trb     TIM7CTLA
69
70 ; Disable the TX/RX IRQ; set to 8E1.
71
72         lda     #%11101
73         sta     SERCTL
74
75 ; Clear all pending interrupts.
76
77         lda     INTSET
78         sta     INTRST
79
80 ; Set up the stack.
81
82         lda     #<(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
83         ldx     #>(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
84         sta     sp
85         stx     sp+1
86
87 ; Init Mickey.
88
89         ldx     #.sizeof(MikeyInitReg)-1
90 mloop:  ldy     MikeyInitReg,x
91         lda     MikeyInitData,x
92         sta     $fd00,y
93         dex
94         bpl     mloop
95
96 ; These are RAM-shadows of read-only regs.
97
98         ldx     #$1b
99         stx     __iodat
100         dex                     ; $1A
101         stx     __iodir
102         ldx     #$d
103         stx     __viddma
104
105 ; Init Suzy.
106
107         ldx     #.sizeof(SuzyInitReg)-1
108 sloop:  ldy     SuzyInitReg,x
109         lda     SuzyInitData,x
110         sta     $fc00,y
111         dex
112         bpl     sloop
113
114         lda     #$24
115         sta     __sprsys
116         cli
117
118 ; Clear the BSS data.
119
120         jsr     zerobss
121
122 ; Call the module constructors.
123
124         jsr     initlib
125
126 ; Push the command-line arguments; and, call main().
127
128         jsr     callmain
129
130 ; Call the module destructors. This is also the exit() entry.
131
132 _exit:  jsr     donelib         ; Run module destructors
133
134 ; Endless loop
135
136 noret:  bra     noret