]> git.sur5r.net Git - cc65/blob - libsrc/gamate/crt0.s
ead45b7ea1b90bff858e8384fe87db6978e4867d
[cc65] / libsrc / gamate / crt0.s
1
2         .export         Start, _exit
3
4         .import         initlib, donelib, callmain
5         .import         push0, _main, zerobss, copydata
6
7         ; Linker generated symbols
8         .import         __RAM_START__, __RAM_SIZE__
9
10         .include        "zeropage.inc"
11         .include        "gamate.inc"
12
13 Start:
14         ; setup the CPU and System-IRQ
15
16         ; Initialize CPU
17         sei
18         cld
19
20         ldx     #0
21         stx     ZP_IRQ_CTRL     ; disable calling cartridge IRQ/NMI handler
22
23         ; Setup stack and memory mapping
24         ;ldx     #$FF            ; Stack top ($01FF)
25         dex
26         txs
27
28         ; Clear the BSS data
29         jsr     zerobss
30
31         ; Copy the .data segment to RAM
32         jsr     copydata
33
34         ; setup the stack
35         lda     #<(__RAM_START__+__RAM_SIZE__)
36         sta     sp
37         lda     #>(__RAM_START__+__RAM_SIZE__)
38         sta     sp + 1
39
40         ; Call module constructors
41         jsr     initlib
42
43         lda     #1
44         sta     ZP_IRQ_CTRL     ; enable calling cartridge IRQ/NMI handler
45         cli     ; allow IRQ only after constructors have run
46
47         ; Pass an empty command line
48         jsr     push0           ; argc
49         jsr     push0           ; argv
50
51         ldy     #4              ; Argument size
52         jsr     _main           ; call the users code
53
54         ; Call module destructors. This is also the _exit entry.
55 _exit:
56         jsr     donelib         ; Run module destructors
57
58         ; reset (start over)
59         jmp     Start
60
61         .export initmainargs
62 initmainargs:
63         rts