]> git.sur5r.net Git - cc65/blob - libsrc/gamate/crt0.s
b54d8ade1137fcb6fa2a76d178b00ad24f678223
[cc65] / libsrc / gamate / crt0.s
1
2         .export         __STARTUP__ : absolute = 1      ; Mark as startup
3
4         .import         initlib, donelib, callmain
5         .import         push0, _main, zerobss, copydata
6
7         .import         IRQStub
8
9         ; Linker generated symbols
10         .import         __RAM_START__, __RAM_SIZE__
11         .import         __ROM_START__, __ROM_SIZE__
12         .import         __STARTUP_LOAD__,__STARTUP_RUN__, __STARTUP_SIZE__
13         .import         __CODE_LOAD__,__CODE_RUN__, __CODE_SIZE__
14         .import         __RODATA_LOAD__,__RODATA_RUN__, __RODATA_SIZE__
15
16         .include        "zeropage.inc"
17         .include        "gamate.inc"
18
19         .segment "STARTUP"
20
21         .word 0                                         ; +00 checksum from 7000-7fff (simple 8bit adds)
22         .byte 1, 0, 1                                   ; +02 flags
23         .byte "COPYRIGHT BIT CORPORATION", 0, $ff       ; +05 copyright
24         ; system vectors
25         jmp     reset                                   ; +20 reset entry
26         jmp     nmi                                     ; +23 nmi entry
27         jmp     IRQStub                                 ; +26 irq entry (135 hz)
28
29 ;-------------------------------------------------------------------------------
30 reset:
31         ; setup the CPU and System-IRQ
32
33         ; Initialize CPU
34         sei
35         cld
36
37         ; Setup stack and memory mapping
38         ldx     #$FF            ; Stack top ($01FF)
39         txs
40
41         ; Clear the BSS data
42         jsr     zerobss
43
44         ; Copy the .data segment to RAM
45         jsr     copydata
46
47         ; setup the stack
48         lda     #<(__RAM_START__+__RAM_SIZE__)
49         sta     sp
50         lda     #>(__RAM_START__+__RAM_SIZE__)
51         sta     sp + 1
52
53         ; Call module constructors
54         jsr     initlib
55
56         cli     ; allow IRQ only after constructors have run
57
58         ; Pass an empty command line
59         jsr     push0           ; argc
60         jsr     push0           ; argv
61
62         ldy     #4              ; Argument size
63         jsr     _main           ; call the users code
64
65         ; Call module destructors. This is also the _exit entry.
66 _exit:
67         jsr     donelib         ; Run module destructors
68
69         ; reset (start over)
70         jmp     reset
71
72         .export initmainargs
73 initmainargs:
74         rts
75
76 ;-------------------------------------------------------------------------------
77 nmi:
78         rts