aboutsummaryrefslogtreecommitdiff
path: root/src/crt0.s
blob: 44a1c93583101394ccda421b564db4a4438ddcfb (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
;
; 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, zerobss
        .import         __RESERVED_MEMORY__
        .import         __MAIN_START__, __MAIN_SIZE__
        .import         __LOWCODE_RUN__, __LOWCODE_SIZE__
        .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.
        jsr     zerobss

; 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

; 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