kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 1 | ;; 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 |
PulkoMandy | 81050b8 | 2023-05-06 22:16:49 +0200 | [diff] [blame] | 10 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 11 | ;; Ordering of segments for the linker. |
PulkoMandy | 81050b8 | 2023-05-06 22:16:49 +0200 | [diff] [blame] | 12 | ; Things that go in RAM |
PulkoMandy | 32c249b | 2014-06-29 13:15:09 +0200 | [diff] [blame] | 13 | .area _INITIALIZED |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 14 | |
PulkoMandy | 2bb86d9 | 2014-06-28 17:09:59 +0200 | [diff] [blame] | 15 | .area _DATA |
PulkoMandy | 81050b8 | 2023-05-06 22:16:49 +0200 | [diff] [blame] | 16 | .area _BSS |
| 17 | .area _HEAP |
PulkoMandy | 2bb86d9 | 2014-06-28 17:09:59 +0200 | [diff] [blame] | 18 | _progend:: |
PulkoMandy | 32c249b | 2014-06-29 13:15:09 +0200 | [diff] [blame] | 19 | |
PulkoMandy | 81050b8 | 2023-05-06 22:16:49 +0200 | [diff] [blame] | 20 | ;; 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 | |
| 38 | rsx_table: |
| 39 | |
| 40 | .db 'K' + #0x80 |
| 41 | .ascii "CONTIK" |
| 42 | .db 'I' + #0x80 |
| 43 | .db #0 |
| 44 | |
| 45 | init: |
| 46 | ; This is the program entry point. Execution starts here |
| 47 | ;; Initialise global variables, clear BSS areas, initialize AMSDOS and setup heap. |
PulkoMandy | d4445ca | 2014-06-28 11:43:26 +0200 | [diff] [blame] | 48 | 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 |
| 55 | gsinit_next: |
PulkoMandy | 2bb86d9 | 2014-06-28 17:09:59 +0200 | [diff] [blame] | 56 | ; Clear BSS sections |
| 57 | ld hl,#s__DATA |
| 58 | ld (hl),#0 |
PulkoMandy | 9d35dfb | 2014-06-29 20:26:47 +0200 | [diff] [blame] | 59 | ld de,#s__DATA + #1 |
PulkoMandy | 81050b8 | 2023-05-06 22:16:49 +0200 | [diff] [blame] | 60 | ld bc,#s__DATA + #0x200 |
PulkoMandy | 2bb86d9 | 2014-06-28 17:09:59 +0200 | [diff] [blame] | 61 | ldir |
| 62 | |
| 63 | ; Initialize disk ROM |
| 64 | ld hl,#0xabff |
| 65 | ld de,#0x40 |
| 66 | ld c,#7 |
| 67 | call 0xbcce |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 68 | |
PulkoMandy | 81050b8 | 2023-05-06 22:16:49 +0200 | [diff] [blame] | 69 | ; 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 | |
| 74 | do_nothing: |
PulkoMandy | 81050b8 | 2023-05-06 22:16:49 +0200 | [diff] [blame] | 75 | scf |
| 76 | ret |
| 77 | |
| 78 | _exit:: |
| 79 | rst #0 |
| 80 | |
| 81 | ; ----------------------------------------------------------------------------- |