]> git.sur5r.net Git - cc65/blob - libsrc/lynx/crt0.s
Fix 32/64-bit int/pointer casts
[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         ldx     #$FF
51         txs
52
53 ; Init the bank switching.
54
55         lda     #$C
56         sta     MAPCTL          ; $FFF9
57
58 ; Disable all timer interrupts.
59
60         lda     #$80
61         trb     TIM0CTLA
62         trb     TIM1CTLA
63         trb     TIM2CTLA
64         trb     TIM3CTLA
65         trb     TIM5CTLA
66         trb     TIM6CTLA
67         trb     TIM7CTLA
68
69 ; Disable the TX/RX IRQ; set to 8E1.
70
71         lda     #%11101
72         sta     SERCTL
73
74 ; Clear all pending interrupts.
75
76         lda     INTSET
77         sta     INTRST
78
79 ; Set up the stack.
80
81         lda     #<(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
82         ldx     #>(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
83         sta     sp
84         stx     sp+1
85
86 ; Init Mickey.
87
88         ldx     #.sizeof(MikeyInitReg)-1
89 mloop:  ldy     MikeyInitReg,x
90         lda     MikeyInitData,x
91         sta     $fd00,y
92         dex
93         bpl     mloop
94
95 ; These are RAM-shadows of read-only regs.
96
97         ldx     #$1b
98         stx     __iodat
99         dex                     ; $1A
100         stx     __iodir
101         ldx     #$d
102         stx     __viddma
103
104 ; Init Suzy.
105
106         ldx     #.sizeof(SuzyInitReg)-1
107 sloop:  ldy     SuzyInitReg,x
108         lda     SuzyInitData,x
109         sta     $fc00,y
110         dex
111         bpl     sloop
112
113         lda     #$24
114         sta     __sprsys
115         cli
116
117 ; Clear the BSS data.
118
119         jsr     zerobss
120
121 ; Call the module constructors.
122
123         jsr     initlib
124
125 ; Push the command-line arguments; and, call main().
126
127         jsr     callmain
128
129 ; Call the module destructors. This is also the exit() entry.
130
131 _exit:  jsr     donelib         ; Run module destructors
132
133 ; Endless loop
134
135 noret:  bra     noret