]> git.sur5r.net Git - cc65/blob - libsrc/atari2600/crt0.s
Add C support for Atari 2600 (VCS)
[cc65] / libsrc / atari2600 / crt0.s
1 ; Atari VCS 2600 startup code for cc65
2 ;
3 ; Florent Flament (contact@florentflament.com), 2017
4
5         .export         _exit
6         .export         __STARTUP__ : absolute = 1
7
8         .import         __RAM_START__, __RAM_SIZE__
9         .import         copydata
10         .import         _main
11
12         .include        "zeropage.inc"
13
14
15 .segment "STARTUP"
16 start:
17 ; Clear decimal mode
18         cld
19
20 ; Initialization Loop:
21 ; * Clears Atari 2600 whole memory (128 bytes) including BSS segment
22 ; * Clears TIA registers
23 ; * Sets system stack pointer to $ff (i.e top of zero-page)
24         ldx     #0
25         txa
26 clearLoop:
27         dex
28         txs
29         pha
30         bne     clearLoop
31
32 ; Initialize data
33         jsr     copydata
34
35 ; Initialize C stack pointer
36         lda     #<(__RAM_START__ + __RAM_SIZE__)
37         ldx     #>(__RAM_START__ + __RAM_SIZE__)
38         sta     sp
39         stx     sp+1
40
41 ; Call main
42         jsr     _main
43 _exit:  jmp     _exit
44
45
46 .segment "VECTORS"
47 .word   start                   ; NMI
48 .word   start                   ; Reset
49 .word   start                   ; IRQ