ad2b2a1b9efc95ba712f4c602435a5b49a9b6de7
[fw/sdcc] / sim / ucsim / xa.src / xacl.h
1 /*
2  * Simulator of microcontrollers (xacl.h)
3  *
4  * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
5  *
6  * Written by Karl Bongers karl@turbobit.com
7  * 
8  * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
9  *
10  */
11
12 /* This file is part of microcontroller simulator: ucsim.
13
14 UCSIM is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 UCSIM is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with UCSIM; see the file COPYING.  If not, write to the Free
26 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 02111-1307, USA. */
28 /*@1@*/
29
30 #ifndef XACL_HEADER
31 #define XACL_HEADER
32
33 #include "uccl.h"
34
35 #include "regsxa.h"
36
37 /*
38  * Base type of XA microcontrollers
39  */
40
41 class cl_xa: public cl_uc
42 {
43 public:
44   cl_mem *ram;
45   cl_mem *rom;
46   struct t_regs regs;
47
48   // for now make it as simple as possible
49   TYPE_UBYTE mem_direct[1024*2];
50 #ifndef WORDS_BIGENDIAN
51   TYPE_UWORD *wmem_direct;  /* word pointer at mem_direct */
52 #endif
53
54 public:
55   cl_xa(class cl_sim *asim);
56   virtual int init(void);
57   virtual char *id_string(void);
58
59   virtual t_addr get_mem_size(enum mem_class type);
60   virtual void mk_hw_elements(void);
61
62   virtual struct dis_entry *dis_tbl(void);
63
64   virtual struct name_entry *sfr_tbl(void);
65   virtual struct name_entry *bit_tbl(void);
66   virtual char *get_dir_name(short);
67   virtual char *get_bit_name(short);
68
69   virtual int inst_length(t_addr addr);
70   virtual int inst_branch(t_addr addr);
71   virtual int longest_inst(void);
72
73   virtual int get_disasm_info(t_addr addr,
74                        int *ret_len,
75                        int *ret_branch,
76                        int *immed_offset,
77                        int *parms,
78                        int *mnemonic);
79
80   virtual char *disass(t_addr addr, char *sep);
81   virtual void print_regs(class cl_console *con);
82
83   virtual int exec_inst(void);
84   virtual int get_reg(int word_flag, unsigned int index);
85   virtual bool get_bit(int bit);
86   virtual void set_bit(int bit, int value);
87
88 #include "instcl.h"
89
90   private :
91
92    /* following are macros which get substituted for FUNC1() and FUNC2()
93       in the inst.cc to form the body of ADD,ADDC,SUB,XOR,... */
94   /* can I put these in the .cc file and still have them do the inline thing? */
95   /*-------------------------------------
96     add - flags changed:C,AC,V,N,Z.
97   |---------------------------------------*/
98   inline unsigned char add1(unsigned char dst, unsigned char src)
99   {
100     unsigned int result;
101     unsigned char flags;
102     flags = get_psw();
103     flags &= ~BIT_ALL; /* clear these bits */
104     result = dst + src;
105     if (result == 0) flags |= BIT_Z;
106     if (result > 0xff) flags |= BIT_C;
107     if (result & 0x80) flags |= BIT_N;
108     /* fixme: do AC, V */
109     set_psw(flags);
110     return (unsigned char) result;
111   }
112
113   inline unsigned short add2(unsigned short dst, unsigned short src)
114   {
115     unsigned int result;
116     unsigned char flags;
117     flags = get_psw();
118     flags &= ~BIT_ALL; /* clear these bits */
119     result = dst + src;
120     if (result == 0) flags |= BIT_Z;
121     if (result > 0xff) flags |= BIT_C;
122     if (result & 0x80) flags |= BIT_N;
123     /* fixme: do AC, V */
124     set_psw(flags);
125     return (unsigned short) result;
126   }
127
128   /*-------------------------------------
129     addc - flags changed:C,AC,V,N,Z.
130   |---------------------------------------*/
131   inline unsigned char addc1(unsigned char dst, unsigned char src)
132   {
133     unsigned int result;
134     unsigned char flags;
135     flags = get_psw();
136     if (flags & BIT_C) {
137       flags &= ~BIT_ALL; /* clear these bits */
138       result = dst + src + 1;
139     } else {
140       flags &= ~BIT_ALL; /* clear these bits */
141       result = dst + src;
142     }
143     if (result == 0) flags |= BIT_Z;
144     if (result > 0xff) flags |= BIT_C;
145     if (result & 0x80) flags |= BIT_N;
146     /* fixme: do AC, V */
147     set_psw(flags);
148     return (unsigned char) result;
149   }
150
151   inline unsigned short addc2(unsigned short dst, unsigned short src)
152   {
153     unsigned int result;
154     unsigned char flags;
155     flags = get_psw();
156     flags &= ~BIT_ALL; /* clear these bits */
157     if (flags & BIT_C) {
158       flags &= ~BIT_ALL; /* clear these bits */
159       result = dst + src + 1;
160     } else {
161       flags &= ~BIT_ALL; /* clear these bits */
162       result = dst + src;
163     }
164     if (result == 0) flags |= BIT_Z;
165     if (result > 0xff) flags |= BIT_C;
166     if (result & 0x80) flags |= BIT_N;
167     /* fixme: do AC, V */
168     set_psw(flags);
169     return (unsigned short) result;
170   }
171
172   /*-------------------------------------
173     sub - flags changed:C,AC,V,N,Z.
174   |---------------------------------------*/
175   inline unsigned char sub1(unsigned char dst, unsigned char src)
176   {
177     unsigned int result;
178     unsigned char flags;
179     flags = get_psw();
180     flags &= ~BIT_ALL; /* clear these bits */
181     result = dst - src;
182     if (result == 0) flags |= BIT_Z;
183     if (result > 0xff) flags |= BIT_C;
184     if (dst < src) flags |= BIT_N;
185     /* fixme: do AC, V */
186     set_psw(flags);
187     return (unsigned char) result;
188   }
189
190   inline unsigned short sub2(unsigned short dst, unsigned short src)
191   {
192     unsigned int result;
193     unsigned char flags;
194     flags = get_psw();
195     flags &= ~BIT_ALL; /* clear these bits */
196     result = dst - src;
197     if (result == 0) flags |= BIT_Z;
198     if (result > 0xff) flags |= BIT_C;
199     if (dst < src) flags |= BIT_N;
200     /* fixme: do AC, V */
201     set_psw(flags);
202     return (unsigned short) result;
203   }
204
205   /*-------------------------------------
206     subb - flags changed:C,AC,V,N,Z.
207   |---------------------------------------*/
208   inline unsigned char subb1(unsigned char dst, unsigned char src)
209   {
210     unsigned int result;
211     unsigned char flags;
212     flags = get_psw();
213     if (flags & BIT_C) {
214       flags &= ~BIT_ALL; /* clear these bits */
215       result = dst - src - 1;
216     } else {
217       flags &= ~BIT_ALL; /* clear these bits */
218       result = dst - src;
219     }
220     if (result == 0) flags |= BIT_Z;
221     if (result > 0xff) flags |= BIT_C;
222     if (dst < src) flags |= BIT_N;
223     /* fixme: do AC, V */
224     set_psw(flags);
225     return (unsigned char) result;
226   }
227
228   inline unsigned short subb2(unsigned short dst, unsigned short src)
229   {
230     unsigned int result;
231     unsigned char flags;
232     flags = get_psw();
233     flags &= ~BIT_ALL; /* clear these bits */
234     if (flags & BIT_C) {
235       flags &= ~BIT_ALL; /* clear these bits */
236       result = dst - src - 1;
237     } else {
238       flags &= ~BIT_ALL; /* clear these bits */
239       result = dst - src;
240     }
241     if (result == 0) flags |= BIT_Z;
242     if (result > 0xff) flags |= BIT_C;
243     if (dst < src) flags |= BIT_N;
244     /* fixme: do AC, V */
245     set_psw(flags);
246     return (unsigned short) result;
247   }
248
249   /*-------------------------------------
250     cmp - flags changed:C,AC,V,N,Z.
251   |---------------------------------------*/
252   inline unsigned char cmp1(unsigned char dst, unsigned char src)
253   {
254     unsigned int result;
255     unsigned char flags;
256     flags = get_psw();
257     flags &= ~BIT_ALL; /* clear these bits */
258     result = dst - src;
259     if (result == 0) flags |= BIT_Z;
260     if (result > 0xff) flags |= BIT_C;
261     if (dst < src) flags |= BIT_N;
262     /* fixme: do AC, V */
263     set_psw(flags);
264     return (unsigned char) dst;
265   }
266
267   inline unsigned short cmp2(unsigned short dst, unsigned short src)
268   {
269     unsigned int result;
270     unsigned char flags;
271     flags = get_psw();
272     flags &= ~BIT_ALL; /* clear these bits */
273     result = dst - src;
274     if (result == 0) flags |= BIT_Z;
275     if (result > 0xff) flags |= BIT_C;
276     if (dst < src) flags |= BIT_N;
277     /* fixme: do AC, V */
278     set_psw(flags);
279     return (unsigned short) dst;
280   }
281
282   /*-------------------------------------
283     and - flags changed:N,Z.
284   |---------------------------------------*/
285   inline unsigned char and1(unsigned char dst, unsigned char src)
286   {
287     unsigned int result;
288     unsigned char flags;
289     flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
290     result = dst & src;
291     if (result == 0) flags |= BIT_Z;
292     if (result & 0x80) flags |= BIT_N;
293     set_psw(flags);
294     return (unsigned char) result;
295   }
296
297   inline unsigned short and2(unsigned short dst, unsigned short src)
298   {
299     unsigned int result;
300     unsigned char flags;
301     flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
302     result = dst & src;
303     if (result == 0) flags |= BIT_Z;
304     if (result & 0x80) flags |= BIT_N;
305     set_psw(flags);
306     return (unsigned short) result;
307   }
308
309   /*-------------------------------------
310     or - flags changed:N,Z.
311   |---------------------------------------*/
312   inline unsigned char or1(unsigned char dst, unsigned char src)
313   {
314     unsigned int result;
315     unsigned char flags;
316     flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
317     result = dst | src;
318     if (result == 0) flags |= BIT_Z;
319     if (result & 0x80) flags |= BIT_N;
320     set_psw(flags);
321     return (unsigned char) result;
322   }
323
324   inline unsigned short or2(unsigned short dst, unsigned short src)
325   {
326     unsigned int result;
327     unsigned char flags;
328     flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
329     result = dst | src;
330     if (result == 0) flags |= BIT_Z;
331     if (result & 0x80) flags |= BIT_N;
332     set_psw(flags);
333     return (unsigned short) result;
334   }
335
336   /*-------------------------------------
337     xor - flags changed:N,Z.
338   |---------------------------------------*/
339   inline unsigned char xor1(unsigned char dst, unsigned char src)
340   {
341     unsigned char flags;
342     flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
343     dst ^= src;
344     if (dst == 0) flags |= BIT_Z;
345     if (dst & 0x80) flags |= BIT_N;
346     set_psw(flags);
347     return (unsigned char) dst;
348   }
349
350   inline unsigned short xor2(unsigned short dst, unsigned short src)
351   {
352     unsigned char flags;
353     flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
354     dst ^= src;
355     if (dst == 0) flags |= BIT_Z;
356     if (dst & 0x8000) flags |= BIT_N;
357     set_psw(flags);
358     return (unsigned short) dst;
359   }
360
361   /*-------------------------------------
362     mov - flags changed:N,Z.
363   |---------------------------------------*/
364   inline unsigned char mov1(unsigned char dst, unsigned char src)
365   {
366     unsigned char flags;
367     flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
368     dst = src;
369     if (dst == 0) flags |= BIT_Z;
370     if (dst & 0x80) flags |= BIT_N;
371     set_psw(flags);
372     return (unsigned char) dst;
373   }
374
375   inline unsigned short mov2(unsigned short dst, unsigned short src)
376   {
377     unsigned char flags;
378     flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
379     dst = src;
380     if (dst == 0) flags |= BIT_Z;
381     if (dst & 0x8000) flags |= BIT_N;
382     set_psw(flags);
383     return (unsigned short) dst;
384   }
385 };
386
387 #endif
388
389 /* End of xa.src/xacl.h */