blob: ce2e55bb77ea1a97b7e4404a58646d5beab36224 [file] [log] [blame]
kthacker62e146c2006-04-17 15:11:35 +00001;; File: crt0.s
2;; Generic crt0.s for a Z80
3;; From SDCC..
4;; Modified to suit execution on the Amstrad CPC!
5;; by H. Hansen 2003
6
7 .module crt0
8 .globl _main
9 .globl _progend
PulkoMandy81050b82023-05-06 22:16:49 +020010
kthacker62e146c2006-04-17 15:11:35 +000011 ;; Ordering of segments for the linker.
PulkoMandy81050b82023-05-06 22:16:49 +020012 ; Things that go in RAM
PulkoMandy32c249b2014-06-29 13:15:09 +020013 .area _INITIALIZED
kthacker62e146c2006-04-17 15:11:35 +000014
PulkoMandy2bb86d92014-06-28 17:09:59 +020015 .area _DATA
PulkoMandy81050b82023-05-06 22:16:49 +020016 .area _BSS
17 .area _HEAP
PulkoMandy2bb86d92014-06-28 17:09:59 +020018_progend::
PulkoMandy32c249b2014-06-29 13:15:09 +020019
PulkoMandy81050b82023-05-06 22:16:49 +020020 ;; Things that go in ROM
21 .area _HOME
22 .area _CODE (REL,CON)
23 .area _INITIALIZER (REL,CON)
24 .area _GSINIT (REL,CON)
25 .area _GSFINAL (REL,CON)
26
27 .area _CODE (REL,CON)
28
29 .db #1 ; Background ROM
30 .db #1 ; Version 1.4
31 .db #4
32 .db #0
33 .dw rsx_table
34
35 jp do_nothing
36 jp init
37
38rsx_table:
39
40 .db 'K' + #0x80
41 .ascii "CONTIK"
42 .db 'I' + #0x80
43 .db #0
44
45init:
46; This is the program entry point. Execution starts here
47;; Initialise global variables, clear BSS areas, initialize AMSDOS and setup heap.
PulkoMandyd4445ca2014-06-28 11:43:26 +020048 ld bc, #l__INITIALIZER
49 ld a, b
50 or a, c
51 jr Z, gsinit_next
52 ld de, #s__INITIALIZED
53 ld hl, #s__INITIALIZER
54 ldir
55gsinit_next:
PulkoMandy2bb86d92014-06-28 17:09:59 +020056; Clear BSS sections
57 ld hl,#s__DATA
58 ld (hl),#0
PulkoMandy9d35dfb2014-06-29 20:26:47 +020059 ld de,#s__DATA + #1
PulkoMandy81050b82023-05-06 22:16:49 +020060 ld bc,#s__DATA + #0x200
PulkoMandy2bb86d92014-06-28 17:09:59 +020061 ldir
62
63; Initialize disk ROM
64 ld hl,#0xabff
65 ld de,#0x40
66 ld c,#7
67 call 0xbcce
kthacker62e146c2006-04-17 15:11:35 +000068
PulkoMandy81050b82023-05-06 22:16:49 +020069 ; Init the heap. Do it after the disk ROM is ready, because that may change HIMEM
70 call __sdcc_heap_init
71; Enter the C main.
72 jp _main
73
74do_nothing:
PulkoMandy81050b82023-05-06 22:16:49 +020075 scf
76 ret
77
78_exit::
79 rst #0
80
81; -----------------------------------------------------------------------------