66997b5247493e3db7ee8c0dd6f921afcf704100
[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   class cl_mem *sfr, *iram;
49
50   // for now make it as simple as possible
51 //  TYPE_UBYTE mem_direct[1024*2];
52 //#ifndef WORDS_BIGENDIAN
53 //  TYPE_UWORD *wmem_direct;  /* word pointer at mem_direct */
54 //#endif
55
56 public:
57   cl_xa(class cl_sim *asim);
58   virtual int init(void);
59   virtual char *id_string(void);
60
61   virtual class cl_mem *mk_mem(enum mem_class type, char *class_name);
62   virtual t_addr get_mem_size(enum mem_class type);
63   virtual void mk_hw_elements(void);
64
65   virtual struct dis_entry *dis_tbl(void);
66
67   virtual struct name_entry *sfr_tbl(void);
68   virtual struct name_entry *bit_tbl(void);
69   virtual char *get_dir_name(short);
70   virtual char *get_bit_name(short);
71
72   virtual int inst_length(t_addr addr);
73   virtual int inst_branch(t_addr addr);
74   virtual int longest_inst(void);
75
76   virtual int get_disasm_info(t_addr addr,
77                        int *ret_len,
78                        int *ret_branch,
79                        int *immed_offset,
80                        int *parms,
81                        int *mnemonic);
82
83   virtual char *disass(t_addr addr, char *sep);
84   virtual void print_regs(class cl_console *con);
85
86   virtual int exec_inst(void);
87   virtual int get_reg(int word_flag, unsigned int index);
88   virtual bool get_bit(int bit);
89   virtual void set_bit(int bit, int value);
90
91 #include "instcl.h"
92
93   private :
94
95    /* following are macros which get substituted for FUNC1() and FUNC2()
96       in the inst.cc to form the body of ADD,ADDC,SUB,XOR,... */
97   /* can I put these in the .cc file and still have them do the inline thing? */
98   /*-------------------------------------
99     add - flags changed:C,AC,V,N,Z.
100   |---------------------------------------*/
101   inline unsigned char add1(unsigned char dst, unsigned char src)
102   {
103     unsigned int result;
104     unsigned char flags;
105     flags = get_psw();
106     flags &= ~BIT_ALL; /* clear these bits */
107     result = dst + src;
108     if (result == 0) flags |= BIT_Z;
109     if (result > 0xff) flags |= BIT_C;
110     if (result & 0x80) flags |= BIT_N;
111     /* fixme: do AC, V */
112     set_psw(flags);
113     return (unsigned char) result;
114   }
115
116   inline unsigned short add2(unsigned short dst, unsigned short src)
117   {
118     unsigned int result;
119     unsigned char flags;
120     flags = get_psw();
121     flags &= ~BIT_ALL; /* clear these bits */
122     result = dst + src;
123     if (result == 0) flags |= BIT_Z;
124     if (result > 0xff) flags |= BIT_C;
125     if (result & 0x80) flags |= BIT_N;
126     /* fixme: do AC, V */
127     set_psw(flags);
128     return (unsigned short) result;
129   }
130
131   /*-------------------------------------
132     addc - flags changed:C,AC,V,N,Z.
133   |---------------------------------------*/
134   inline unsigned char addc1(unsigned char dst, unsigned char src)
135   {
136     unsigned int result;
137     unsigned char flags;
138     flags = get_psw();
139     if (flags & BIT_C) {
140       flags &= ~BIT_ALL; /* clear these bits */
141       result = dst + src + 1;
142     } else {
143       flags &= ~BIT_ALL; /* clear these bits */
144       result = dst + src;
145     }
146     if (result == 0) flags |= BIT_Z;
147     if (result > 0xff) flags |= BIT_C;
148     if (result & 0x80) flags |= BIT_N;
149     /* fixme: do AC, V */
150     set_psw(flags);
151     return (unsigned char) result;
152   }
153
154   inline unsigned short addc2(unsigned short dst, unsigned short src)
155   {
156     unsigned int result;
157     unsigned char flags;
158     flags = get_psw();
159     flags &= ~BIT_ALL; /* clear these bits */
160     if (flags & BIT_C) {
161       flags &= ~BIT_ALL; /* clear these bits */
162       result = dst + src + 1;
163     } else {
164       flags &= ~BIT_ALL; /* clear these bits */
165       result = dst + src;
166     }
167     if (result == 0) flags |= BIT_Z;
168     if (result > 0xff) flags |= BIT_C;
169     if (result & 0x80) flags |= BIT_N;
170     /* fixme: do AC, V */
171     set_psw(flags);
172     return (unsigned short) result;
173   }
174
175   /*-------------------------------------
176     sub - flags changed:C,AC,V,N,Z.
177   |---------------------------------------*/
178   inline unsigned char sub1(unsigned char dst, unsigned char src)
179   {
180     unsigned int result;
181     unsigned char flags;
182     flags = get_psw();
183     flags &= ~BIT_ALL; /* clear these bits */
184     result = dst - src;
185     if (result == 0) flags |= BIT_Z;
186     if (result > 0xff) flags |= BIT_C;
187     if (dst < src) flags |= BIT_N;
188     /* fixme: do AC, V */
189     set_psw(flags);
190     return (unsigned char) result;
191   }
192
193   inline unsigned short sub2(unsigned short dst, unsigned short src)
194   {
195     unsigned int result;
196     unsigned char flags;
197     flags = get_psw();
198     flags &= ~BIT_ALL; /* clear these bits */
199     result = dst - src;
200     if (result == 0) flags |= BIT_Z;
201     if (result > 0xff) flags |= BIT_C;
202     if (dst < src) flags |= BIT_N;
203     /* fixme: do AC, V */
204     set_psw(flags);
205     return (unsigned short) result;
206   }
207
208   /*-------------------------------------
209     subb - flags changed:C,AC,V,N,Z.
210   |---------------------------------------*/
211   inline unsigned char subb1(unsigned char dst, unsigned char src)
212   {
213     unsigned int result;
214     unsigned char flags;
215     flags = get_psw();
216     if (flags & BIT_C) {
217       flags &= ~BIT_ALL; /* clear these bits */
218       result = dst - src - 1;
219     } else {
220       flags &= ~BIT_ALL; /* clear these bits */
221       result = dst - src;
222     }
223     if (result == 0) flags |= BIT_Z;
224     if (result > 0xff) flags |= BIT_C;
225     if (dst < src) flags |= BIT_N;
226     /* fixme: do AC, V */
227     set_psw(flags);
228     return (unsigned char) result;
229   }
230
231   inline unsigned short subb2(unsigned short dst, unsigned short src)
232   {
233     unsigned int result;
234     unsigned char flags;
235     flags = get_psw();
236     flags &= ~BIT_ALL; /* clear these bits */
237     if (flags & BIT_C) {
238       flags &= ~BIT_ALL; /* clear these bits */
239       result = dst - src - 1;
240     } else {
241       flags &= ~BIT_ALL; /* clear these bits */
242       result = dst - src;
243     }
244     if (result == 0) flags |= BIT_Z;
245     if (result > 0xff) flags |= BIT_C;
246     if (dst < src) flags |= BIT_N;
247     /* fixme: do AC, V */
248     set_psw(flags);
249     return (unsigned short) result;
250   }
251
252   /*-------------------------------------
253     cmp - flags changed:C,AC,V,N,Z.
254   |---------------------------------------*/
255   inline unsigned char cmp1(unsigned char dst, unsigned char src)
256   {
257     unsigned int result;
258     unsigned char flags;
259     flags = get_psw();
260     flags &= ~BIT_ALL; /* clear these bits */
261     result = dst - src;
262     if (result == 0) flags |= BIT_Z;
263     if (result > 0xff) flags |= BIT_C;
264     if (dst < src) flags |= BIT_N;
265     /* fixme: do AC, V */
266     set_psw(flags);
267     return (unsigned char) dst;
268   }
269
270   inline unsigned short cmp2(unsigned short dst, unsigned short src)
271   {
272     unsigned int result;
273     unsigned char flags;
274     flags = get_psw();
275     flags &= ~BIT_ALL; /* clear these bits */
276     result = dst - src;
277     if (result == 0) flags |= BIT_Z;
278     if (result > 0xff) flags |= BIT_C;
279     if (dst < src) flags |= BIT_N;
280     /* fixme: do AC, V */
281     set_psw(flags);
282     return (unsigned short) dst;
283   }
284
285   /*-------------------------------------
286     and - flags changed:N,Z.
287   |---------------------------------------*/
288   inline unsigned char and1(unsigned char dst, unsigned char src)
289   {
290     unsigned int result;
291     unsigned char flags;
292     flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
293     result = dst & src;
294     if (result == 0) flags |= BIT_Z;
295     if (result & 0x80) flags |= BIT_N;
296     set_psw(flags);
297     return (unsigned char) result;
298   }
299
300   inline unsigned short and2(unsigned short dst, unsigned short src)
301   {
302     unsigned int result;
303     unsigned char flags;
304     flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
305     result = dst & src;
306     if (result == 0) flags |= BIT_Z;
307     if (result & 0x80) flags |= BIT_N;
308     set_psw(flags);
309     return (unsigned short) result;
310   }
311
312   /*-------------------------------------
313     or - flags changed:N,Z.
314   |---------------------------------------*/
315   inline unsigned char or1(unsigned char dst, unsigned char src)
316   {
317     unsigned int result;
318     unsigned char flags;
319     flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
320     result = dst | src;
321     if (result == 0) flags |= BIT_Z;
322     if (result & 0x80) flags |= BIT_N;
323     set_psw(flags);
324     return (unsigned char) result;
325   }
326
327   inline unsigned short or2(unsigned short dst, unsigned short src)
328   {
329     unsigned int result;
330     unsigned char flags;
331     flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
332     result = dst | src;
333     if (result == 0) flags |= BIT_Z;
334     if (result & 0x80) flags |= BIT_N;
335     set_psw(flags);
336     return (unsigned short) result;
337   }
338
339   /*-------------------------------------
340     xor - flags changed:N,Z.
341   |---------------------------------------*/
342   inline unsigned char xor1(unsigned char dst, unsigned char src)
343   {
344     unsigned char flags;
345     flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
346     dst ^= src;
347     if (dst == 0) flags |= BIT_Z;
348     if (dst & 0x80) flags |= BIT_N;
349     set_psw(flags);
350     return (unsigned char) dst;
351   }
352
353   inline unsigned short xor2(unsigned short dst, unsigned short src)
354   {
355     unsigned char flags;
356     flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
357     dst ^= src;
358     if (dst == 0) flags |= BIT_Z;
359     if (dst & 0x8000) flags |= BIT_N;
360     set_psw(flags);
361     return (unsigned short) dst;
362   }
363
364   /*-------------------------------------
365     mov - flags changed:N,Z.
366   |---------------------------------------*/
367   inline unsigned char mov1(unsigned char dst, unsigned char src)
368   {
369     unsigned char flags;
370     flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
371     dst = src;
372     if (dst == 0) flags |= BIT_Z;
373     if (dst & 0x80) flags |= BIT_N;
374     set_psw(flags);
375     return (unsigned char) dst;
376   }
377
378   inline unsigned short mov2(unsigned short dst, unsigned short src)
379   {
380     unsigned char flags;
381     flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
382     dst = src;
383     if (dst == 0) flags |= BIT_Z;
384     if (dst & 0x8000) flags |= BIT_N;
385     set_psw(flags);
386     return (unsigned short) dst;
387   }
388 };
389
390 #endif
391
392 /* End of xa.src/xacl.h */