* .version: Updated to 2.3.1
[fw/sdcc] / device / lib / z80 / crt0.s
1         ;; Generic crt0.s for a Z80
2         .module crt0
3         .globl  _main
4
5         .area _HEADER (ABS)
6         ;; Reset vector
7         .org    0
8         jp      init
9
10         .org    0x08
11         reti
12         .org    0x10
13         reti
14         .org    0x18
15         reti
16         .org    0x20
17         reti
18         .org    0x28
19         reti
20         .org    0x30
21         reti
22         .org    0x38
23         reti
24         
25         .org    0x100
26 init:
27         ;; Stack at the top of memory.
28         ld      sp,#0xffff        
29
30         ;; Initialise global variables
31         call    gsinit
32         call    _main
33         jp      _exit
34
35         ;; Ordering of segments for the linker.
36         .area   _CODE
37         .area   _GSINIT
38         .area   _GSFINAL
39         
40         .area   _DATA
41         .area   _BSS
42
43         .area   _CODE
44 __clock::
45         ld      a,#2
46         rst     0x08
47         ret
48         
49 _exit::
50         ;; Exit - special code to the emulator
51         ld      a,#0
52         rst     0x08
53 1$:
54         halt
55         jr      1$
56
57         ;; Special RLE decoder used for initing global data
58 __initrleblock::
59         ;; Pop the return address
60         pop     hl
61         ;; Save registers
62         push    bc
63         push    de
64
65         ;; Pull the destination address out
66         ld      c,(hl)
67         inc     hl
68         ld      b,(hl)
69         inc     hl
70 1$:
71         ;; Fetch the run
72         ld      e,(hl)
73         inc     hl
74         ;; Negative means a run
75         bit     7,e
76         jp      z,2$
77         ;; Code for expanding a run
78         ld      a,(hl)
79         inc     hl
80 3$:
81         ld      (bc),a
82         inc     bc
83         inc     e
84         jp      nz,3$
85         jp      1$
86 2$:
87         ;; Zero means end of a block
88         xor     a
89         or      e
90         jp      z,4$
91         ;; Code for expanding a block
92 5$:     
93         ld      a,(hl)        
94         inc     hl
95         ld      (bc),a
96         inc     bc
97         dec     e
98         jp      nz,5$
99         jp      1$
100 4$:     
101         pop     de
102         pop     bc
103
104         ;; Push the return address back onto the stack
105         push    hl
106         ret
107
108         .area   _GSINIT
109 gsinit::        
110
111         .area   _GSFINAL
112         ret