-
Notifications
You must be signed in to change notification settings - Fork 0
/
crt0.s
64 lines (40 loc) · 1.55 KB
/
crt0.s
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
; ---------------------------------------------------------------------------
; crt0.s for CC65->Neo6502
; ---------------------------------------------------------------------------
.export _init , _exit
.import _main
.export __STARTUP__ : absolute = 1 ; Mark as startup
.import __RAM_START__ , __RAM_SIZE__ ; Linker generated
.import __STACKSIZE__
.import copydata , zerobss , initlib , donelib
.include "zeropage.inc"
; ---------------------------------------------------------------------------
; Place the startup code in a special segment
.segment "STARTUP"
; ---------------------------------------------------------------------------
; A little light 6502 housekeeping
_init:
ldx #$FF ; Initialize stack pointer to $01FF
txs
cld ; Clear decimal mode
; ---------------------------------------------------------------------------
; Set cc65 argument stack pointer
lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
ldx #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
sta sp
stx sp+1
; ---------------------------------------------------------------------------
; Initialize memory storage
jsr zerobss ; Clear BSS segment
jsr copydata ; initialise data segment
jsr initlib ; Run constructors
; ---------------------------------------------------------------------------
; Call main()
jsr _main
; ---------------------------------------------------------------------------
; Back from main (this is also the _exit entry):
_exit:
jsr donelib ; Run destructors
_endx:
jmp _endx
jmp ($FFFC) ; Reboot