Rev 151 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
151 | dimkam | 1 | ; |
2 | ; $Id: Cstartup.s01 1.24 2001/01/04 12:19:06 IPEO Exp $ |
||
3 | ; |
||
4 | |||
5 | ;----------------------------------------------------------; |
||
6 | ; ; |
||
7 | ; CSTARTUP.S01 ; |
||
8 | ; ; |
||
9 | ; This file contains the Z80/HD64180 C startup routine ; |
||
10 | ; and must usually be tailored to suit customer's hardware.; |
||
11 | ; ; |
||
12 | ; Version: 4.00 [ 28/Apr/94 IJAR] ; |
||
13 | ;----------------------------------------------------------; |
||
14 | |||
15 | #define proc64180 ((__TID__&0x010)==0x010) |
||
16 | |||
17 | NAME CSTARTUP |
||
18 | |||
19 | EXTERN main ; where to begin execution |
||
20 | EXTERN ?C_EXIT ; where to go when program is done |
||
21 | |||
22 | #ifdef banking |
||
23 | #if proc64180 |
||
24 | |||
25 | CBAR_addr EQU 3AH ; define I/O ports to MMU registers |
||
26 | CBR_addr EQU 38H ; (See also defines in debug.s01 and l08.s01) |
||
27 | |||
28 | EXTERN CBAR_value |
||
29 | EXTERN CBR_value |
||
30 | #endif |
||
31 | |||
32 | EXTERN ?BANK_CALL_DIRECT_L08 |
||
33 | #endif |
||
34 | |||
35 | ;---------------------------------------------------------------; |
||
36 | ; CSTACK - The C stack segment ; |
||
37 | ; ; |
||
38 | ; Please, see in the link file lnk*.xcl how to increment ; |
||
39 | ; the stack size without having to reassemble cstartup.s01 ! ; |
||
40 | ;---------------------------------------------------------------; |
||
41 | |||
42 | RSEG CSTACK |
||
43 | DEFS 0 ; a bare minimum ! |
||
44 | |||
45 | ;---------------------------------------------------------------; |
||
46 | ; Forward declarations of segment used during initialization ; |
||
47 | ;---------------------------------------------------------------; |
||
48 | RSEG UDATA0 |
||
49 | RSEG IDATA0 |
||
50 | RSEG ECSTR |
||
51 | RSEG TEMP |
||
52 | RSEG DATA0 |
||
53 | RSEG WCSTR |
||
54 | |||
55 | RSEG CDATA0 |
||
56 | RSEG CCSTR |
||
57 | RSEG CONST |
||
58 | RSEG CSTR |
||
59 | |||
60 | ASEG |
||
61 | ORG 0x6000 |
||
62 | init_A |
||
63 | DI |
||
64 | JP init_C |
||
65 | |||
66 | ;---------------------------------------------------------------; |
||
67 | ; RCODE - where the execution actually begins ; |
||
68 | ;---------------------------------------------------------------; |
||
69 | RSEG RCODE |
||
70 | init_C |
||
71 | LD SP,.SFE.(CSTACK-1) ; from high to low address |
||
72 | |||
73 | ;---------------------------------------------------------------; |
||
74 | ; If hardware must be initiated from assembly or if interrupts ; |
||
75 | ; should be on when reaching main, this is the place to insert ; |
||
76 | ; such code. ; |
||
77 | ;---------------------------------------------------------------; |
||
78 | |||
79 | #ifdef banking |
||
80 | #if proc64180 |
||
81 | |||
82 | ;---------------------------------------------------------------; |
||
83 | ; Setting of MMU registers - see chapter "Linking" of manual. ; |
||
84 | ;---------------------------------------------------------------; |
||
85 | |||
86 | LD A,CBAR_value ; set CBAR value |
||
87 | OUT0 (CBAR_addr),A |
||
88 | |||
89 | LD A,CBR_value ; set CBR value |
||
90 | OUT0 (CBR_addr),A |
||
91 | |||
92 | #endif |
||
93 | #endif |
||
94 | |||
95 | ;---------------------------------------------------------------; |
||
96 | ; If it is not a requirement that static/global data is set ; |
||
97 | ; to zero or to some explicit value at startup, the following ; |
||
98 | ; line refering to seg_init can be deleted, or commented. ; |
||
99 | ;---------------------------------------------------------------; |
||
100 | |||
101 | CALL seg_init |
||
102 | |||
103 | #ifdef banking |
||
104 | |||
105 | LD HL,LWRD(main) ; banked call to main() |
||
106 | LD A,BYTE3(main) |
||
107 | CALL ?BANK_CALL_DIRECT_L08 |
||
108 | #else |
||
109 | CALL main ; non-banked call to main() |
||
110 | #endif |
||
111 | |||
112 | ;---------------------------------------------------------------; |
||
113 | ; Now when we are ready with our C program we must perform a ; |
||
114 | ; system-dependent action. In this case we just stop. ; |
||
115 | ;---------------------------------------------------------------; |
||
116 | ; DO NOT CHANGE THE NEXT LINE OF CSTARTUP IF YOU WANT TO RUN ; |
||
117 | ; YOUR SOFTWARE WITH THE HELP OF THE C-SPY HLL DEBUGGER. ; |
||
118 | ;---------------------------------------------------------------; |
||
119 | |||
120 | JP ?C_EXIT |
||
121 | |||
122 | ;---------------------------------------------------------------; |
||
123 | ; Copy initialized PROMmed code to shadow RAM and clear ; |
||
124 | ; uninitialized variables. ; |
||
125 | ;---------------------------------------------------------------; |
||
126 | |||
127 | seg_init |
||
128 | |||
129 | ;---------------------------------------; |
||
130 | ; Zero out UDATA0 ; |
||
131 | ;---------------------------------------; |
||
132 | LD HL,.SFE.(UDATA0) |
||
133 | LD DE,.SFB.(UDATA0) |
||
134 | CALL zero_mem |
||
135 | |||
136 | ;---------------------------------------; |
||
137 | ; Copy CDATA0 into IDATA0 ; |
||
138 | ;---------------------------------------; |
||
139 | LD DE,.SFB.(IDATA0) ;destination address |
||
140 | LD HL,.SFE.(CDATA0) |
||
141 | LD BC,.SFB.(CDATA0) |
||
142 | CALL copy_mem |
||
143 | |||
144 | ;---------------------------------------; |
||
145 | ; Copy CCSTR into ECSTR ; |
||
146 | ;---------------------------------------; |
||
147 | LD DE,.SFB.(ECSTR) ;destination address |
||
148 | LD HL,.SFE.(CCSTR) |
||
149 | LD BC,.SFB.(CCSTR) |
||
150 | |||
151 | ; Just fall in to the copy_mem function |
||
152 | |||
153 | ;---------------------------------------; |
||
154 | ; Copy memory ; |
||
155 | ;---------------------------------------; |
||
156 | copy_mem |
||
157 | XOR A |
||
158 | SBC HL,BC |
||
159 | PUSH BC |
||
160 | LD C,L |
||
161 | LD B,H ; BC - that many bytes |
||
162 | POP HL ; source address |
||
163 | RET Z ; If block size = 0 return now |
||
164 | LDIR |
||
165 | RET |
||
166 | |||
167 | ;---------------------------------------; |
||
168 | ; Clear memory ; |
||
169 | ;---------------------------------------; |
||
170 | zero_mem |
||
171 | XOR A |
||
172 | again PUSH HL |
||
173 | SBC HL,DE |
||
174 | POP HL |
||
175 | RET Z |
||
176 | LD (DE),A |
||
177 | INC DE |
||
178 | JR again |
||
179 | |||
180 | ;---------------------------------------------------------------; |
||
181 | ; Interrupt vectors must be inserted here by the user. ; |
||
182 | ;---------------------------------------------------------------; |
||
183 | |||
184 | COMMON INTVEC |
||
185 | |||
186 | ENDMOD init_A |
||
187 | |||
188 | ;---------------------------------------------------------------; |
||
189 | ; Function/module: exit (int code) ; |
||
190 | ; ; |
||
191 | ; When C-SPY is used this code will automatically be replaced ; |
||
192 | ; by a 'debug' version of exit(). ; |
||
193 | ;---------------------------------------------------------------; |
||
194 | MODULE exit |
||
195 | |||
196 | PUBLIC exit |
||
197 | PUBLIC ?C_EXIT |
||
198 | |||
199 | RSEG RCODE |
||
200 | |||
201 | ?C_EXIT |
||
202 | exit EQU ?C_EXIT |
||
203 | |||
204 | ;--------------------------------------------------------------; |
||
205 | ; The next line can be replaced by user defined code. ; |
||
206 | ;--------------------------------------------------------------; |
||
207 | NOP |
||
208 | JR $ ; loop forever |
||
209 | |||
210 | END |