File: crt0.s

package info (click to toggle)
cc65 2.19-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,268 kB
  • sloc: ansic: 117,151; asm: 66,339; pascal: 4,248; makefile: 1,009; perl: 607
file content (63 lines) | stat: -rw-r--r-- 1,597 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

        .export         Start, _exit

        .import         initlib, donelib, callmain
        .import         push0, _main, zerobss, copydata

        ; Linker generated symbols
        .import         __RAM_START__, __RAM_SIZE__

        .include        "zeropage.inc"
        .include        "gamate.inc"

Start:
        ; setup the CPU and System-IRQ

        ; Initialize CPU
        sei
        cld

        ldx     #0
        stx     ZP_IRQ_CTRL     ; disable calling cartridge IRQ/NMI handler

        ; Set up stack and memory mapping
        ;ldx     #$FF            ; Stack top ($01FF)
        dex
        txs

        ; Clear the BSS data
        jsr     zerobss

        ; Copy the .data segment to RAM
        jsr     copydata

        ; Set up the stack
        lda     #<(__RAM_START__+__RAM_SIZE__)
        ldx     #>(__RAM_START__+__RAM_SIZE__)
        sta     sp
        stx     sp + 1

        ; Call module constructors
        jsr     initlib

        lda     #1
        sta     ZP_IRQ_CTRL     ; enable calling cartridge IRQ/NMI handler
        cli                     ; allow IRQ only after constructors have run

        ; Pass an empty command line
        jsr     push0           ; argc
        jsr     push0           ; argv

        ldy     #4              ; Argument size
        jsr     _main           ; call the users code

        ; Call module destructors. This is also the _exit entry.
_exit:
        jsr     donelib         ; Run module destructors

        ; reset (start over)
        jmp     Start

        .export initmainargs
initmainargs:
        rts