* src/pic16/{device.c,pcode.c}: s/free/Safe_free/g for
[fw/sdcc] / src / pic16 / device.c
1 /*-------------------------------------------------------------------------
2
3   device.c - Accomodates subtle variations in PIC16 devices
4
5    Written By -  Scott Dattalo scott@dattalo.com
6    Ported to PIC16 By -  Martin Dubuc m.dubuc@rogers.com
7
8    This program is free software; you can redistribute it and/or modify it
9    under the terms of the GNU General Public License as published by the
10    Free Software Foundation; either version 2, or (at your option) any
11    later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 -------------------------------------------------------------------------*/
22
23
24 /*
25         VR - Began writing code to make PIC16 C source files independent from
26         the header file (created by the inc2h.pl)
27
28         - adding maximum RAM memory into PIC_Device structure
29
30 */
31
32 #include <stdio.h>
33
34 #include "common.h"   // Include everything in the SDCC src directory
35 #include "newalloc.h"
36
37
38 #include "main.h"
39 #include "pcode.h"
40 #include "ralloc.h"
41 #include "device.h"
42
43
44 static PIC16_device Pics16[] = {
45 //  {
46 //    {"p18f242", "18f242", "pic18f242", "f242"},               // aliases
47 //    0,
48 //    0x300,                                            // RAMsize
49 //    0,
50 //    { 0xf80, 0xfff },       /* PIC18F242 range of SFR's */
51 //      {
52 //              /* PIC18F242 configuration words */
53 //              0x300001,
54 //              0x30000d,
55 //              { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , 
56 //              { -1, 0, 0xff } /* 4 */  , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , 
57 //              { -1, 0, 0xff } /* 7 */  , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
58 //              { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , 
59 //              { 0x40, 0, 0xff } /* d */ } 
60 //      }
61 //  },
62
63   {
64     {"p18f242", "18f242", "pic18f242", "f242"},
65     0,
66     0x300,      /* 768 */
67     0x80,
68     0,
69     { 0xf80, 0xfff },   /* PIC18F242 range of SFR's */
70     {
71     /* PIC18F242 configuration words */
72       0x300001,
73       0x30000d,
74       { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , 
75       { -1, 0, 0xff } /* 4 */  , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , 
76       { -1, 0, 0xff } /* 7 */  , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
77       { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , 
78       { 0x40, 0, 0xff } /* d */  }
79     },
80     { 0x200000, 0x200007, 
81       { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
82         { 0, 0 }, { 0, 0 }, { 0, 0 } }
83     }
84   },
85   {
86     {"p18f248", "18f248", "pic18f248", "f248"},
87     0,
88     0x300,      /* 768 */
89     0x60,
90     0,
91     { 0xf00, 0xfff },   /* PIC18F248 range of SFR's */
92     {
93     /* PIC18F248 configuration words */
94       0x300001,
95       0x30000d,
96       { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , 
97       { -1, 0, 0xff } /* 4 */  , { -1, 0, 0xff } /* 5 */  , { 0x85, 0, 0xff } /* 6 */ , 
98       { -1, 0, 0xff } /* 7 */  , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
99       { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , 
100       { 0x40, 0, 0xff } /* d */  }
101     },
102     { 0x200000, 0x200007, 
103       { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
104         { 0, 0 }, { 0, 0 }, { 0, 0 } }
105     }
106   },
107   {
108     {"p18f252", "18f252", "pic18f252", "f252"},
109     0,
110     0x600,      /* 1536 */
111     0x80,
112     0,
113     { 0xf80, 0xfff },   /* PIC18F252 range of SFR's */
114     {
115     /* PIC18F252 configuration words */
116       0x300001,
117       0x30000d,
118       { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , 
119       { -1, 0, 0xff } /* 4 */  , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , 
120       { -1, 0, 0xff } /* 7 */  , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
121       { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , 
122       { 0x40, 0, 0xff } /* d */  }
123     },
124     { 0x200000, 0x200007, 
125       { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
126         { 0, 0 }, { 0, 0 }, { 0, 0 } }
127     }
128   },
129   {
130     {"p18f258", "18f258", "pic18f258", "f258"},
131     0,
132     0x600,      /* 1536 */
133     0x60,
134     0,
135     { 0xf00, 0xfff },   /* PIC18F258 range of SFR's */
136     {
137     /* PIC18F258 configuration words */
138       0x300001,
139       0x30000d,
140       { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , 
141       { -1, 0, 0xff } /* 4 */  , { -1, 0, 0xff } /* 5 */  , { 0x85, 0, 0xff } /* 6 */ , 
142       { -1, 0, 0xff } /* 7 */  , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
143       { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , 
144       { 0x40, 0, 0xff } /* d */  }
145     },
146     { 0x200000, 0x200007, 
147       { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
148         { 0, 0 }, { 0, 0 }, { 0, 0 } }
149     }
150   },
151   {
152     {"p18f442", "18f442", "pic18f442", "f442"},
153     0,
154     0x300,      /* 768 */
155     0x80,
156     0,
157     { 0xf80, 0xfff },   /* PIC18F442 range of SFR's */
158     {
159     /* PIC18F442 configuration words */
160       0x300001,
161       0x30000d,
162       { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , 
163       { -1, 0, 0xff } /* 4 */  , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , 
164       { -1, 0, 0xff } /* 7 */  , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
165       { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , 
166       { 0x40, 0, 0xff } /* d */  }
167     },
168     { 0x200000, 0x200007, 
169       { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
170         { 0, 0 }, { 0, 0 }, { 0, 0 } }
171     }
172   },
173   {
174     {"p18f448", "18f448", "pic18f448", "f448"},
175     0,
176     0x300,      /* 768 */
177     0x60,
178     0,
179     { 0xf00, 0xfff },   /* PIC18F448 range of SFR's */
180     {
181     /* PIC18F448 configuration words */
182       0x300001,
183       0x30000d,
184       { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , 
185       { -1, 0, 0xff } /* 4 */  , { -1, 0, 0xff } /* 5 */  , { 0x85, 0, 0xff } /* 6 */ , 
186       { -1, 0, 0xff } /* 7 */  , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
187       { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , 
188       { 0x40, 0, 0xff } /* d */  }
189     },
190     { 0x200000, 0x200007, 
191       { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
192         { 0, 0 }, { 0, 0 }, { 0, 0 } }
193     }
194   },
195   {
196     {"p18f452", "18f452", "pic18f452", "f452"},
197     0,
198     0x600,      /* 1536 */
199     0x80,
200     0,
201     { 0xf80, 0xfff },   /* PIC18F452 range of SFR's */
202     {
203     /* PIC18F452 configuration words */
204       0x300001,
205       0x30000d,
206       { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , 
207       { -1, 0, 0xff } /* 4 */  , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , 
208       { -1, 0, 0xff } /* 7 */  , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
209       { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , 
210       { 0x40, 0, 0xff } /* d */  }
211     },
212     { 0x200000, 0x200007, 
213       { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
214         { 0, 0 }, { 0, 0 }, { 0, 0 } }
215     }
216   },
217   {
218     {"p18f458", "18f458", "pic18f458", "f458"},
219     0,
220     0x600,      /* 1536 */
221     0x60,
222     0,
223     { 0xf00, 0xfff },   /* PIC18F458 range of SFR's */
224     {
225     /* PIC18F458 configuration words */
226       0x300001,
227       0x30000d,
228       { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , 
229       { -1, 0, 0xff } /* 4 */  , { -1, 0, 0xff } /* 5 */  , { 0x85, 0, 0xff } /* 6 */ , 
230       { -1, 0, 0xff } /* 7 */  , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
231       { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , 
232       { 0x40, 0, 0xff } /* d */  }
233     },
234     { 0x200000, 0x200007, 
235       { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
236         { 0, 0 }, { 0, 0 }, { 0, 0 } }
237     }
238   },
239   {
240     {"p18f1220", "18f1220", "pic18f1220", "f1220"},
241     0,
242     0x100,      /* 256 */
243     0x80,
244     0,
245     { 0xf80, 0xfff },   /* PIC18F1220 range of SFR's */
246     {
247     /* PIC18F1220 configuration words */
248       0x300001,
249       0x30000d,
250       { { 0xcf, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ , 
251       { -1, 0, 0xff } /* 4 */  , { 0x80, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , 
252       { -1, 0, 0xff } /* 7 */  , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
253       { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , 
254       { 0x40, 0, 0xff } /* d */  }
255     },
256     { 0x200000, 0x200007, 
257       { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
258         { 0, 0 }, { 0, 0 }, { 0, 0 } }
259     }
260   },
261   {
262     {"p18f2220", "18f2220", "pic18f2220", "f2220"},
263     0,
264     0x200,      /* 512 */
265     0x80,
266     0,
267     { 0xf80, 0xfff },   /* PIC18F2220 range of SFR's */
268     {
269     /* PIC18F2220 configuration words */
270       0x300001,
271       0x30000d,
272       { { 0xcf, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ , 
273       { -1, 0, 0xff } /* 4 */  , { 0x83, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , 
274       { -1, 0, 0xff } /* 7 */  , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
275       { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , 
276       { 0x40, 0, 0xff } /* d */  }
277     },
278     { 0x200000, 0x200007, 
279       { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
280         { 0, 0 }, { 0, 0 }, { 0, 0 } }
281     }
282   },
283   {
284     {"p18f6520", "18f6520", "pic18f6520", "f6520"},
285     0,
286     0x800,      /* 2048 */
287     0x60,
288     0,
289     { 0xf6b, 0xfff },   /* PIC18F6520 range of SFR's */
290     {
291     /* PIC18F6520 configuration words */
292       0x300001,
293       0x30000d,
294       { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , 
295       { 0x80, 0, 0xff } /* 4 */ , { 0x88, 0, 0xff } /* 5 */ , { -1, 0, 0xff } /* 6 */  , 
296       { -1, 0, 0xff } /* 7 */  , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
297       { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , 
298       { 0x40, 0, 0xff } /* d */  }
299     },
300     { 0x200000, 0x200007, 
301       { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
302         { 0, 0 }, { 0, 0 }, { 0, 0 } }
303     }
304   },
305   {
306     {"p18f6620", "18f6620", "pic18f6620", "f6620"},
307     0,
308     0xf00,      /* 3840 */
309     0x60,
310     0,
311     { 0xf6b, 0xfff },   /* PIC18F6620 range of SFR's */
312     {
313     /* PIC18F6620 configuration words */
314       0x300001,
315       0x30000d,
316       { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , 
317       { -1, 0, 0xff } /* 4 */  , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , 
318       { -1, 0, 0xff } /* 7 */  , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
319       { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , 
320       { 0x40, 0, 0xff } /* d */  }
321     },
322     { 0x200000, 0x200007, 
323       { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
324         { 0, 0 }, { 0, 0 }, { 0, 0 } }
325     }
326   },
327   {
328     {"p18f6680", "18f6680", "pic18f6680", "f6680"},
329     0,
330     0xf00,      /* 3840 */
331     0x60,
332     0,
333     { 0xf00, 0xfff },   /* PIC18F6680 range of SFR's */
334     {
335     /* PIC18F6680 configuration words */
336       0x300001,
337       0x30000d,
338       { { 0x2f, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ , 
339       { -1, 0, 0xff } /* 4 */  , { 0x83, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , 
340       { -1, 0, 0xff } /* 7 */  , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
341       { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , 
342       { 0x40, 0, 0xff } /* d */  }
343     },
344     { 0x200000, 0x200007, 
345       { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
346         { 0, 0 }, { 0, 0 }, { 0, 0 } }
347     }
348   },
349   {
350     {"p18f6720", "18f6720", "pic18f6720", "f6720"},
351     0,
352     0xf00,      /* 3840 */
353     0x60,
354     0,
355     { 0xf6b, 0xfff },   /* PIC18F6720 range of SFR's */
356     {
357     /* PIC18F6720 configuration words */
358       0x300001,
359       0x30000d,
360       { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , 
361       { -1, 0, 0xff } /* 4 */  , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , 
362       { -1, 0, 0xff } /* 7 */  , { 0xff, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
363       { 0xff, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0xff, 0, 0xff } /* c */ , 
364       { 0x40, 0, 0xff } /* d */  }
365     },
366     { 0x200000, 0x200007, 
367       { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
368         { 0, 0 }, { 0, 0 }, { 0, 0 } }
369     }
370   },
371   {
372     {"p18f8520", "18f8520", "pic18f8520", "f8520"},
373     0,
374     0x800,      /* 2048 */
375     0x60,
376     1,
377     { 0xf6b, 0xfff },   /* PIC18F8520 range of SFR's */
378     {
379     /* PIC18F8520 configuration words */
380       0x300001,
381       0x30000d,
382       { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , 
383       { 0x83, 0, 0xff } /* 4 */ , { 0x88, 0, 0xff } /* 5 */ , { -1, 0, 0xff } /* 6 */  , 
384       { -1, 0, 0xff } /* 7 */  , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
385       { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , 
386       { 0x40, 0, 0xff } /* d */  }
387     },
388     { 0x200000, 0x200007, 
389       { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
390         { 0, 0 }, { 0, 0 }, { 0, 0 } }
391     }
392   },
393   {
394     {"p18f8620", "18f8620", "pic18f8620", "f8620"},
395     0,
396     0xf00,      /* 3840 */
397     0x60,
398     1,
399     { 0xf6b, 0xfff },   /* PIC18F8620 range of SFR's */
400     {
401     /* PIC18F8620 configuration words */
402       0x300001,
403       0x30000d,
404       { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , 
405       { 0x83, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , 
406       { -1, 0, 0xff } /* 7 */  , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
407       { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , 
408       { 0x40, 0, 0xff } /* d */  }
409     },
410     { 0x200000, 0x200007, 
411       { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
412         { 0, 0 }, { 0, 0 }, { 0, 0 } }
413     }
414   },
415   {
416     {"p18f8680", "18f8680", "pic18f8680", "f8680"},
417     0,
418     0xf00,      /* 3840 */
419     0x60,
420     0,
421     { 0xf00, 0xfff },   /* PIC18F8680 range of SFR's */
422     {
423     /* PIC18F8680 configuration words */
424       0x300001,
425       0x30000d,
426       { { 0x2f, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ , 
427       { 0x83, 0, 0xff } /* 4 */ , { 0x83, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , 
428       { -1, 0, 0xff } /* 7 */  , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
429       { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , 
430       { 0x40, 0, 0xff } /* d */  }
431     },
432     { 0x200000, 0x200007, 
433       { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
434         { 0, 0 }, { 0, 0 }, { 0, 0 } }
435     }
436   },
437   {
438     {"p18f8720", "18f8720", "pic18f8720", "f8720"},
439     0,
440     0xf00,      /* 3840 */
441     0x60,
442     1,
443     { 0xf6b, 0xfff },   /* PIC18F8720 range of SFR's */
444     {
445     /* PIC18F8720 configuration words */
446       0x300001,
447       0x30000d,
448       { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , 
449       { 0x83, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , 
450       { -1, 0, 0xff } /* 7 */  , { 0xff, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , 
451       { 0xff, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0xff, 0, 0xff } /* c */ , 
452       { 0x40, 0, 0xff } /* d */  }
453     },
454     { 0x200000, 0x200007, 
455       { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 
456         { 0, 0 }, { 0, 0 }, { 0, 0 } }
457     }
458   }
459
460 };
461
462 static int num_of_supported_PICS = sizeof(Pics16)/sizeof(PIC16_device);
463
464 stats_t statistics = { 0, 0, 0, 0 };
465
466 #define DEFAULT_PIC "452"
467
468 PIC16_device *pic16=NULL;
469 unsigned int stackPos = 0;
470 unsigned int stackLen = 0;
471
472 extern regs* newReg(short type, short pc_type, int rIdx, char *name, int size, int alias, operand *refop);
473
474 void pic16_setMaxRAM(int size)
475 {
476         pic16->maxRAMaddress = size;
477         stackPos = pic16->RAMsize-1;
478
479         if (pic16->maxRAMaddress < 0) {
480                 fprintf(stderr, "invalid \"#pragma maxram 0x%x\" setting\n",
481                         pic16->maxRAMaddress);
482           return;
483         }
484 }
485
486 extern char *iComments2;
487
488 void pic16_dump_equates(FILE *of, set *equs)
489 {
490   regs *r;
491
492         r = setFirstItem(equs);
493         if(!r)return;
494         
495         fprintf(of, "%s", iComments2);
496         fprintf(of, ";\tEquates to used internal registers\n");
497         fprintf(of, "%s", iComments2);
498         
499         for(; r; r = setNextItem(equs)) {
500                 fprintf(of, "%s\tequ\t0x%02x\n", r->name, r->address);
501         }
502 }
503
504
505 void pic16_dump_access(FILE *of, set *section)
506 {
507   regs *r;
508
509         r = setFirstItem(section);
510         if(!r)return;
511         
512         fprintf(of, "%s", iComments2);
513         fprintf(of, ";\tAccess bank symbols\n");
514         fprintf(of, "%s", iComments2);
515         
516         fprintf(of, "\tudata_acs\n");
517         for(; r; r = setNextItem(section)) {
518                 fprintf(of, "%s\tres\t%d\n", r->name, r->size);
519                 statistics.adsize += r->size;
520         }
521 }
522
523
524 int regCompare(const void *a, const void *b)
525 {
526   const regs *const *i = a;
527   const regs *const *j = b;
528
529         /* sort primarily by the address */
530         if( (*i)->address > (*j)->address)return 1;
531         if( (*i)->address < (*j)->address)return -1;
532         
533         /* and secondarily by size */
534         /* register size sorting may have strange results use with care */
535         if( (*i)->size > (*j)->size)return 1;
536         if( (*i)->size < (*j)->size)return -1;
537         
538         /* finally if in same address and same size sort by name */
539         return (strcmp( (*i)->name, (*j)->name));
540
541   return 0;
542 }
543
544 int symCompare(const void *a, const void *b)
545 {
546   const symbol *const *i = a;
547   const symbol *const *j = b;
548
549         /* sort primarily by the address */
550         if( SPEC_ADDR((*i)->etype) > SPEC_ADDR((*j)->etype))return 1;
551         if( SPEC_ADDR((*i)->etype) < SPEC_ADDR((*j)->etype))return -1;
552         
553         /* and secondarily by size */
554         /* register size sorting may have strange results use with care */
555         if( getSize((*i)->etype) > getSize((*j)->etype))return 1;
556         if( getSize((*i)->etype) < getSize((*j)->etype))return -1;
557
558         /* finally if in same address and same size sort by name */
559         return (strcmp( (*i)->rname, (*j)->rname));
560
561   return 0;
562 }
563
564 void pic16_dump_usection(FILE *of, set *section, int fix)
565 {
566   static int abs_usection_no=0;
567   static unsigned int usection_no=0;
568   regs *r, *rprev;
569   unsigned int init_addr, i;
570   regs **rlist;
571   regs *r1;
572
573         /* put all symbols in an array */
574         rlist = Safe_calloc(elementsInSet(section), sizeof(regs *));
575         r = rlist[0]; i = 0;
576         for(rprev = setFirstItem(section); rprev; rprev = setNextItem(section)) {
577                 rlist[i] = rprev; i++;
578         }
579         
580         if(!i) {
581                 if(rlist)Safe_free(rlist);
582           return;
583         }
584
585         /* sort symbols according to their address */
586         qsort(rlist, i  /*elementsInSet(section)*/, sizeof(regs *), regCompare);
587         
588         if(!fix) {
589
590 #define EMIT_SINGLE_UDATA_SECTION       0
591 #if EMIT_SINGLE_UDATA_SECTION
592                 fprintf(of, "\n\n\tudata\n");
593                 for(r = setFirstItem(section); r; r = setNextItem(section)) {
594                         fprintf(of, "%s\tres\t%d\n", r->name, r->size);
595                         statistics.udsize += r->size;
596                 }
597 #else
598                 for(r = setFirstItem(section); r; r = setNextItem(section)) {
599                         //fprintf(of, "\nudata_%s_%s\tudata\n", moduleName, r->name);
600                         fprintf(of, "\nudata_%s_%u\tudata\n", moduleName, usection_no++);
601                         fprintf(of, "%s\tres\t%d\n", r->name, r->size);
602                         statistics.udsize += r->size;
603                 }
604 #endif
605         } else {
606           unsigned int j=0;
607           int deb_addr=0;
608
609                 rprev = NULL;
610                 init_addr = rlist[j]->address;
611                 deb_addr = init_addr;
612                 fprintf(of, "\n\nustat_%s_%02d\tudata\t0X%04X\n", moduleName, abs_usection_no++, init_addr);
613         
614                 for(j=0;j<i;j++) {
615                         r = rlist[j];
616                         if(j < i-1)r1 = rlist[j+1]; else r1 = NULL;
617                         
618                         init_addr = r->address;
619                         deb_addr = init_addr;
620                         
621                         if((rprev && (init_addr > (rprev->address + rprev->size)))) {
622                                 fprintf(of, "\n\nustat_%s_%02d\tudata\t0X%04X\n", moduleName, abs_usection_no++, init_addr);
623                         }
624
625                         if(r1 && (init_addr == r1->address)) {
626                                 fprintf(of, "\n%s\tres\t0\n", r->name);
627                         } else {
628                                 fprintf(of, "%s\tres\t%d\n", r->name, r->size);
629                                 deb_addr += r->size;
630                                 statistics.udsize += r->size;
631                         }
632                         
633                         rprev = r;
634                 }
635         }
636         Safe_free(rlist);
637 }
638
639 void pic16_dump_gsection(FILE *of, set *sections)
640 {
641   regs *r;
642   sectName *sname;
643
644         for(sname = setFirstItem(sections); sname; sname = setNextItem(sections)) {
645                 if(!strcmp(sname->name, "access"))continue;
646                 fprintf(of, "\n\n%s\tudata\n", sname->name);
647
648                 for(r=setFirstItem(sname->regsSet); r; r=setNextItem(sname->regsSet)) {
649 #if 0
650                         fprintf(stderr, "%s:%d emitting variable %s for section %s (%p)\n", __FILE__, __LINE__,
651                                 r->name, sname->name, sname);
652 #endif
653                         fprintf(of, "%s\tres\t%d\n", r->name, r->size);
654                         statistics.udsize += r->size;
655                 }
656         }
657 }
658
659
660 /* forward declaration */
661 void pic16_printIval(symbol * sym, sym_link * type, initList * ilist, char ptype, void *p);
662 extern void pic16_pCodeConstString(char *name, char *value);
663
664 void pic16_dump_isection(FILE *of, set *section, int fix)
665 {
666   static int abs_isection_no=0;
667   symbol *s, *sprev;
668   unsigned int init_addr, i;
669   symbol **slist;
670
671         /* put all symbols in an array */
672         slist = Safe_calloc(elementsInSet(section), sizeof(symbol *));
673         s = slist[0]; i = 0;
674         for(sprev = setFirstItem(section); sprev; sprev = setNextItem(section)) {
675                 slist[i] = sprev; i++;
676         }
677         
678         if(!i) {
679                 if(slist)Safe_free(slist);
680           return;
681         }
682
683         /* sort symbols according to their address */
684         qsort(slist, i, sizeof(symbol *), symCompare);
685         
686         pic16_initDB();
687
688         if(!fix) {
689                 fprintf(of, "\n\n\tidata\n");
690                 for(s = setFirstItem(section); s; s = setNextItem(section)) {
691
692                         if(s->ival) {
693                                 fprintf(of, "%s", s->rname);
694                                 pic16_printIval(s, s->type, s->ival, 'f', (void *)of);
695                                 pic16_flushDB('f', (void *)of);
696                         } else {
697                                 if (IS_ARRAY (s->type) && IS_CHAR (s->type->next)
698                                         && SPEC_CVAL (s->etype).v_char) {
699
700 //                                      fprintf(stderr, "%s:%d printing code string from %s\n", __FILE__, __LINE__, s->rname);
701                                         pic16_pCodeConstString(s->rname , SPEC_CVAL (s->etype).v_char);
702                                 } else {
703                                         assert(0);
704                                 }
705                         }
706                                 
707                 }
708         } else {
709           unsigned int j=0;
710           symbol *s1;
711           
712                 sprev = NULL;
713                 init_addr = SPEC_ADDR(slist[j]->etype);
714                 fprintf(of, "\n\nistat_%s_%02d\tidata\t0X%04X\n", moduleName, abs_isection_no++, init_addr);
715         
716                 for(j=0;j<i;j++) {
717                         s = slist[j];
718                         if(j < i-1)s1 = slist[j+1]; else s1 = NULL;
719                         
720                         init_addr = SPEC_ADDR(s->etype);
721
722                         if(sprev && (init_addr > (SPEC_ADDR(sprev->etype) + getSize(sprev->etype)))) {
723                                 fprintf(of, "\nistat_%s_%02d\tidata\t0X%04X\n", moduleName, abs_isection_no++, init_addr);
724                         }
725
726                         if(s->ival) {
727                                 fprintf(of, "%s", s->rname);
728                                 pic16_printIval(s, s->type, s->ival, 'f', (void *)of);
729                                 pic16_flushDB('f', (void *)of);
730                         } else {
731                                 if (IS_ARRAY (s->type) && IS_CHAR (s->type->next)
732                                         && SPEC_CVAL (s->etype).v_char) {
733
734 //                                      fprintf(stderr, "%s:%d printing code string from %s\n", __FILE__, __LINE__, s->rname);
735                                         pic16_pCodeConstString(s->rname , SPEC_CVAL (s->etype).v_char);
736                                 } else {
737                                         assert(0);
738                                 }
739                         }
740
741
742                         sprev = s;
743                 }
744         }
745         Safe_free(slist);
746 }
747
748
749 void pic16_dump_int_registers(FILE *of, set *section)
750 {
751   regs *r, *rprev;
752   int i;
753   regs **rlist;
754
755         /* put all symbols in an array */
756         rlist = Safe_calloc(elementsInSet(section), sizeof(regs *));
757         r = rlist[0]; i = 0;
758         for(rprev = setFirstItem(section); rprev; rprev = setNextItem(section)) {
759                 rlist[i] = rprev; i++;
760         }
761
762         /* sort symbols according to their address */
763         qsort(rlist, elementsInSet(section), sizeof(regs *), regCompare);
764         
765         if(!i) {
766                 if(rlist)Safe_free(rlist);
767           return;
768         }
769         
770         fprintf(of, "\n\n; Internal registers\n");
771         
772         fprintf(of, "%s\tudata_ovr\t0x0000\n", ".registers");
773         for(r = setFirstItem(section); r; r = setNextItem(section)) {
774                 fprintf(of, "%s\tres\t%d\n", r->name, r->size);
775                 statistics.intsize += r->size;
776         }
777
778         Safe_free(rlist);
779 }
780
781
782 #ifdef WORDS_BIGENDIAN
783   #define _ENDIAN(x)  (3-x)
784 #else
785   #define _ENDIAN(x)  (x)
786 #endif
787
788 #define BYTE_IN_LONG(x,b) ((x>>(8*_ENDIAN(b)))&0xff)
789
790
791 /*-----------------------------------------------------------------*
792  *  void pic16_list_valid_pics(int ncols, int list_alias)
793  *
794  * Print out a formatted list of valid PIC devices
795  *
796  * ncols - number of columns in the list.
797  *
798  * list_alias - if non-zero, print all of the supported aliases
799  *              for a device (e.g. F84, 16F84, etc...)
800  *-----------------------------------------------------------------*/
801 void pic16_list_valid_pics(int ncols, int list_alias)
802 {
803   int col,longest;
804   int i,j,k,l;
805
806   if(list_alias)
807     list_alias = sizeof(Pics16[0].name) / sizeof(Pics16[0].name[0]);
808
809   /* decrement the column number if it's greater than zero */
810   ncols = (ncols > 1) ? ncols-1 : 4;
811
812   /* Find the device with the longest name */
813   for(i=0,longest=0; i<num_of_supported_PICS; i++) {
814     for(j=0; j<=list_alias; j++) {
815       k = strlen(Pics16[i].name[j]);
816       if(k>longest)
817         longest = k;
818     }
819   }
820
821   col = 0;
822
823   for(i=0;  i < num_of_supported_PICS; i++) {
824     j = 0;
825     do {
826
827       fprintf(stderr,"%s", Pics16[i].name[j]);
828       if(col<ncols) {
829         l = longest + 2 - strlen(Pics16[i].name[j]);
830         for(k=0; k<l; k++)
831           fputc(' ',stderr);
832
833         col++;
834
835       } else {
836         fputc('\n',stderr);
837         col = 0;
838       }
839
840     } while(++j<list_alias);
841
842   }
843   if(col != ncols)
844     fputc('\n',stderr);
845
846 }
847
848 /*-----------------------------------------------------------------*
849  *  
850  *-----------------------------------------------------------------*/
851 PIC16_device *pic16_find_device(char *name)
852 {
853
854   int i,j;
855
856   if(!name)
857     return NULL;
858
859   for(i = 0; i<num_of_supported_PICS; i++) {
860
861     for(j=0; j<PROCESSOR_NAMES; j++)
862       if(!STRCASECMP(Pics16[i].name[j], name) )
863         return &Pics16[i];
864   }
865
866   /* not found */
867   return NULL; 
868 }
869
870 /*-----------------------------------------------------------------*
871  *  
872  *-----------------------------------------------------------------*/
873 void pic16_init_pic(char *pic_type)
874 {
875         pic16 = pic16_find_device(pic_type);
876
877         if(!pic16) {
878                 if(pic_type)
879                         fprintf(stderr, "'%s' was not found.\n", pic_type);
880                 else
881                         fprintf(stderr, "No processor has been specified (use -pPROCESSOR_NAME)\n");
882
883                 fprintf(stderr,"Valid devices are:\n");
884
885                 pic16_list_valid_pics(4,0);
886                 exit(1);
887         }
888
889 //      printf("PIC processor found and initialized: %s\n", pic_type);
890         pic16_setMaxRAM( 0xfff  );
891 }
892
893 /*-----------------------------------------------------------------*
894  *  
895  *-----------------------------------------------------------------*/
896 int pic16_picIsInitialized(void)
897 {
898   if(pic16 && pic16->maxRAMaddress > 0)
899     return 1;
900
901   return 0;
902
903 }
904
905 /*-----------------------------------------------------------------*
906  *  char *pic16_processor_base_name(void) - Include file is derived from this.
907  *-----------------------------------------------------------------*/
908 char *pic16_processor_base_name(void)
909 {
910
911   if(!pic16)
912     return NULL;
913
914   return pic16->name[0];
915 }
916
917 #define DEBUG_CHECK     0
918
919 /*
920  * return 1 if register wasn't found and added, 0 otherwise
921  */
922 int checkAddReg(set **set, regs *reg)
923 {
924   regs *tmp;
925
926
927         if(!reg)return 0;
928 #if DEBUG_CHECK
929         fprintf(stderr, "%s: about to insert REGister: %s ... ", __FUNCTION__, reg->name);
930 #endif
931
932         for(tmp = setFirstItem(*set); tmp; tmp = setNextItem(*set)) {
933                 if(!strcmp(tmp->name, reg->name))break;
934         }
935         
936         if(!tmp) {
937                 addSet(set, reg);
938 #if DEBUG_CHECK
939                 fprintf(stderr, "added\n");
940 #endif
941                 return 1;
942         }
943
944 #if DEBUG_CHECK
945         fprintf(stderr, "already added\n");
946 #endif
947   return 0;
948 }
949
950 int checkAddSym(set **set, symbol *sym)
951 {
952   symbol *tmp;
953
954         if(!sym)return 0;
955 #if DEBUG_CHECK
956         fprintf(stderr, "%s: about to add SYMbol: %s ... ", __FUNCTION__, sym->name);
957 #endif
958
959         for(tmp = setFirstItem( *set ); tmp; tmp = setNextItem(*set)) {
960                 if(!strcmp(tmp->name, sym->name))break;
961         }
962         
963         if(!tmp) {
964                 addSet(set, sym);
965 #if DEBUG_CHECK
966                 fprintf(stderr, "added\n");
967 #endif
968                 return 1;
969         }
970
971 #if DEBUG_CHECK
972         fprintf(stderr, "already added\n");
973 #endif
974
975   return 0;
976 }
977
978 int checkSym(set *set, symbol *sym)
979 {
980   symbol *tmp;
981
982         if(!sym)return 0;
983         
984 #if DEUG_CHECK
985         fprintf(stderr, "%s: about to search for SYMbol: %s ... ", __FUNCTION__, sym->name);
986 #endif
987
988         for(tmp = setFirstItem( set ); tmp; tmp = setNextItem( set )) {
989                 if(!strcmp(tmp->name, sym->name))break;
990         }
991         
992         if(!tmp) {
993 #if DEBUG_CHECK
994                 fprintf(stderr, "not found\n");
995 #endif
996                 return 0;
997         }
998
999 #if DEBUG_CHECK
1000         fprintf(stderr, "found\n");
1001 #endif
1002
1003   return 1;
1004 }
1005
1006 /*-----------------------------------------------------------------*
1007  * void pic16_groupRegistersInSection - add each register to its   *
1008  *      corresponding section                                      *
1009  *-----------------------------------------------------------------*/
1010 void pic16_groupRegistersInSection(set *regset)
1011 {
1012   regs *reg;
1013   sectSym *ssym;
1014   int docontinue=0;
1015
1016         for(reg=setFirstItem(regset); reg; reg = setNextItem(regset)) {
1017
1018 #if 0
1019                 fprintf(stderr, "%s:%d group registers in section, reg: %s (used: %d, %p)\n",
1020                         __FILE__, __LINE__, reg->name, reg->wasUsed, reg);
1021 #endif
1022                 if((reg->wasUsed
1023                         && !(reg->regop && SPEC_EXTR(OP_SYM_ETYPE(reg->regop))))
1024                   ) {
1025                         
1026                         /* avoid grouping registers that have an initial value,
1027                          * they will be added later in idataSymSet */
1028                         if(reg->regop && (OP_SYMBOL(reg->regop)->ival && !OP_SYMBOL(reg->regop)->level))
1029                                 continue;
1030
1031 #if 0
1032                         fprintf(stderr, "%s:%d register %s alias:%d fix:%d ival=%i level=%i code=%i\n",
1033                                 __FILE__, __LINE__, reg->name, reg->alias, reg->isFixed,
1034                                         (reg->regop?(OP_SYMBOL(reg->regop)->ival?1:0):-1),
1035                                         (reg->regop?(OP_SYMBOL(reg->regop)->level):-1),
1036                                         (reg->regop?(IS_CODE(OP_SYM_ETYPE(reg->regop))):-1) );
1037 #endif
1038                         
1039                         docontinue=0;
1040                         for(ssym=setFirstItem(sectSyms);ssym;ssym=setNextItem(sectSyms)) {
1041                                 if(!strcmp(ssym->name, reg->name)) {
1042 //                                      fprintf(stderr, "%s:%d section found %s (%p) with var %s\n",
1043 //                                                      __FILE__, __LINE__, ssym->section->name, ssym->section, ssym->name);
1044                                         if(strcmp(ssym->section->name, "access")) {
1045                                                 addSet(&ssym->section->regsSet, reg);
1046                                                 docontinue=1;
1047                                                 break;
1048                                         } else {
1049                                                 docontinue=0;
1050                                                 reg->accessBank = 1;
1051                                                 break;
1052                                         }
1053                                 }
1054                         }
1055
1056                         if(docontinue)continue;
1057
1058 //                      fprintf(stderr, "%s:%d reg: %s\n", __FILE__, __LINE__, reg->name);
1059
1060                         if(reg->alias == 0x80) {
1061                                 checkAddReg(&pic16_equ_data, reg);
1062                         } else
1063                         if(reg->isFixed) {
1064                                 checkAddReg(&pic16_fix_udata, reg);
1065                         } else
1066                         if(!reg->isFixed) {
1067                                 if(reg->pc_type == PO_GPR_TEMP)
1068                                         checkAddReg(&pic16_int_regs, reg);
1069                                 else {
1070                                         if(reg->accessBank) {
1071                                                 if(reg->alias != 0x40)
1072                                                         checkAddReg(&pic16_acs_udata, reg);
1073                                         } else
1074                                                 checkAddReg(&pic16_rel_udata, reg);
1075                                 }
1076                         }
1077                 }
1078         }
1079 }
1080
1081
1082
1083
1084
1085 /*-----------------------------------------------------------------*
1086  *  void pic16_assignConfigWordValue(int address, int value)
1087  *
1088  * All high performance RISC CPU PICs have seven config word starting
1089  * at address 0x300000.
1090  * This routine will assign a value to that address.
1091  *
1092  *-----------------------------------------------------------------*/
1093 void pic16_assignConfigWordValue(int address, unsigned int value)
1094 {
1095   int i;
1096
1097         for(i=0;i<pic16->cwInfo.confAddrEnd-pic16->cwInfo.confAddrStart+1;i++) {
1098                 if((address == pic16->cwInfo.confAddrStart+i)
1099                   && (pic16->cwInfo.crInfo[i].mask != -1)) {
1100
1101 #if 0
1102                         fprintf(stderr, "setting location 0x%X to value 0x%x\tmask: 0x%x\ttest: 0x%x\n",
1103                                 /*address*/ pic16->cwInfo.confAddrStart+i, (~value)&0xff,
1104                                         pic16->cwInfo.crInfo[i].mask,
1105                                         (pic16->cwInfo.crInfo[i].mask) & (~value));
1106 #endif
1107
1108                         if((((pic16->cwInfo.crInfo[i].mask) & (~value))&0xff) != ((~value)&0xff)) {
1109                                 fprintf(stderr, "%s:%d a wrong value has been given for configuration register 0x%x\n",
1110                                         __FILE__, __LINE__, address);
1111                                         return;
1112                         }
1113                         pic16->cwInfo.crInfo[i].value = value;
1114                         pic16->cwInfo.crInfo[i].emit = 1;
1115                         return;
1116                 }
1117         }
1118 }
1119
1120 void pic16_assignIdByteValue(int address, char value)
1121 {
1122   int i;
1123
1124         for(i=0;i<pic16->idInfo.idAddrEnd-pic16->idInfo.idAddrStart+1;i++) {
1125                 if(address == pic16->idInfo.idAddrStart+i) {
1126                         pic16->idInfo.irInfo[i].value = value;
1127                         pic16->idInfo.irInfo[i].emit = 1;
1128                 }
1129         }
1130 }