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