aboutsummaryrefslogtreecommitdiff
path: root/src/crt0.s
blob: 564ca3db40230a65c2ed02784b1efc47bd76ec54 (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
;
; Startup code for cc65 (ATARI version)
;
; Contributing authors:
;       Mark Keates
;       Freddy Offenga
;       Christian Groessler
;       Stefan Haubenthal
;

; Hacked up, trimmed down version for fnchat.

        .export         __STARTUP__ : absolute = 1      ; Mark as startup
        .export         _exit, start

        .import         _main;  not any more: , zerobss
        .import         __RESERVED_MEMORY__
        .import         __MAIN_START__, __MAIN_SIZE__
        .import         __LOWCODE_RUN__, __LOWCODE_SIZE__
        .import         __BSS_RUN__, __BSS_SIZE__
        .import         _scr_init, _init_channels
        .importzp       ptr1
        .include        "zeropage.inc"
        .include        "atari.inc"

; ------------------------------------------------------------------------

.segment        "STARTUP"
 _exit = WARMSV ; nothing should be calling exit() anyway.

        rts     ; fix for SpartaDOS / OS/A+
                ; They first call the entry point from AUTOSTRT; and
                ; then, the load address (this rts here).
                ; We point AUTOSTRT directly after the rts.

; Real entry point:

start:

; Clear the BSS data.
; This routine was copied from libsrc/common/zerobss.s.
;zerobss:
        lda     #<__BSS_RUN__
        sta     ptr1
        lda     #>__BSS_RUN__
        sta     ptr1+1
        lda     #0
        tay

; Clear full pages

L1:     ldx     #>__BSS_SIZE__
        beq     L3
L2:     sta     (ptr1),y
        iny
        bne     L2
        inc     ptr1+1
        dex
        bne     L2

; Clear remaining page (y is zero on entry)

L3:     cpy     #<__BSS_SIZE__
        beq     L4
        sta     (ptr1),y
        iny
        bne     L3

L4:
; Done clearing BSS.

; Set up the stack
        lda MEMTOP
        sta sp
        lda MEMTOP+1
        sta sp+1

; Set various OS variables.
        ldy     #$ff
        sty     CH              ; remove keypress which might be in the input buffer
        iny                     ; Set Y to 0
        sty     SHFLOK          ; Turn off Caps Lock
        sty     SOUNDR          ; Turn off SIO beep/click

; These 2 used to be called from main(). Moving the calls here saves 6 bytes.
; Do not call _edbox_clear from here (we're *running* in the edbox area).
       jsr _scr_init
       jsr _init_channels

; Go directly to main(). No support for CLI arguments, no saving
; any machine state for a clean exit, because we don't exit.
       jmp _main

; ------------------------------------------------------------------------

.segment "LOWCODE"       ; have at least one (empty) segment of LOWCODE, so that the next line works even if the program doesn't make use of this segment
.assert (__LOWCODE_RUN__ + __LOWCODE_SIZE__ <= $4000 || __LOWCODE_RUN__ > $7FFF || __LOWCODE_SIZE__ = 0), warning, "'lowcode area' reaches into $4000..$7FFF bank memory window"
; check for LOWBSS_SIZE = 0 not needed since the only file which uses LOWBSS (irq.s) also uses LOWCODE
; check for LOWCODE_RUN > $7FFF is mostly for cartridges, where this segment is loaded high (into cart ROM)
; there is a small chance that if the user loads the program really high, LOWCODE is above $7FFF, but LOWBSS is below -- no warning emitted in this case