2 * Simulator of microcontrollers (xacl.h)
4 * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
6 * Written by Karl Bongers karl@turbobit.com
8 * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
12 /* This file is part of microcontroller simulator: ucsim.
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.
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.
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
38 * Base type of XA microcontrollers
41 class cl_xa: public cl_uc
48 class cl_mem *sfr, *iram;
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 */
57 cl_xa(class cl_sim *asim);
58 virtual int init(void);
59 virtual char *id_string(void);
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);
65 virtual struct dis_entry *dis_tbl(void);
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);
72 virtual int inst_length(t_addr addr);
73 virtual int inst_branch(t_addr addr);
74 virtual int longest_inst(void);
76 virtual int get_disasm_info(t_addr addr,
83 virtual char *disass(t_addr addr, char *sep);
84 virtual void print_regs(class cl_console *con);
86 virtual int exec_inst(void);
87 virtual int get_reg(int word_flag, unsigned int index);
89 virtual void store1(t_addr addr, unsigned char val);
90 virtual void store2(t_addr addr, unsigned char val);
91 virtual unsigned char get1(t_addr addr);
92 virtual unsigned short get2(t_addr addr);
94 virtual bool get_bit(int bit);
95 virtual void set_bit(int bit, int value);
101 /* following are macros which get substituted for FUNC1() and FUNC2()
102 in the inst.cc to form the body of ADD,ADDC,SUB,XOR,... */
103 /* can I put these in the .cc file and still have them do the inline thing? */
104 /*-------------------------------------
105 add - flags changed:C,AC,V,N,Z.
106 |---------------------------------------*/
107 inline unsigned char add1(unsigned char dst, unsigned char src)
112 flags &= ~BIT_ALL; /* clear these bits */
114 if (result == 0) flags |= BIT_Z;
115 if (result > 0xff) flags |= BIT_C;
116 if (result & 0x80) flags |= BIT_N;
117 /* fixme: do AC, V */
119 return (unsigned char) result;
122 inline unsigned short add2(unsigned short dst, unsigned short src)
127 flags &= ~BIT_ALL; /* clear these bits */
129 if (result == 0) flags |= BIT_Z;
130 if (result > 0xff) flags |= BIT_C;
131 if (result & 0x80) flags |= BIT_N;
132 /* fixme: do AC, V */
134 return (unsigned short) result;
137 /*-------------------------------------
138 addc - flags changed:C,AC,V,N,Z.
139 |---------------------------------------*/
140 inline unsigned char addc1(unsigned char dst, unsigned char src)
146 flags &= ~BIT_ALL; /* clear these bits */
147 result = dst + src + 1;
149 flags &= ~BIT_ALL; /* clear these bits */
152 if (result == 0) flags |= BIT_Z;
153 if (result > 0xff) flags |= BIT_C;
154 if (result & 0x80) flags |= BIT_N;
155 /* fixme: do AC, V */
157 return (unsigned char) result;
160 inline unsigned short addc2(unsigned short dst, unsigned short src)
165 flags &= ~BIT_ALL; /* clear these bits */
167 flags &= ~BIT_ALL; /* clear these bits */
168 result = dst + src + 1;
170 flags &= ~BIT_ALL; /* clear these bits */
173 if (result == 0) flags |= BIT_Z;
174 if (result > 0xff) flags |= BIT_C;
175 if (result & 0x80) flags |= BIT_N;
176 /* fixme: do AC, V */
178 return (unsigned short) result;
181 /*-------------------------------------
182 sub - flags changed:C,AC,V,N,Z.
183 |---------------------------------------*/
184 inline unsigned char sub1(unsigned char dst, unsigned char src)
189 flags &= ~BIT_ALL; /* clear these bits */
191 if (result == 0) flags |= BIT_Z;
192 if (result > 0xff) flags |= BIT_C;
193 if (dst < src) flags |= BIT_N;
194 /* fixme: do AC, V */
196 return (unsigned char) result;
199 inline unsigned short sub2(unsigned short dst, unsigned short src)
204 flags &= ~BIT_ALL; /* clear these bits */
206 if (result == 0) flags |= BIT_Z;
207 if (result > 0xff) flags |= BIT_C;
208 if (dst < src) flags |= BIT_N;
209 /* fixme: do AC, V */
211 return (unsigned short) result;
214 /*-------------------------------------
215 subb - flags changed:C,AC,V,N,Z.
216 |---------------------------------------*/
217 inline unsigned char subb1(unsigned char dst, unsigned char src)
223 flags &= ~BIT_ALL; /* clear these bits */
224 result = dst - src - 1;
226 flags &= ~BIT_ALL; /* clear these bits */
229 if (result == 0) flags |= BIT_Z;
230 if (result > 0xff) flags |= BIT_C;
231 if (dst < src) flags |= BIT_N;
232 /* fixme: do AC, V */
234 return (unsigned char) result;
237 inline unsigned short subb2(unsigned short dst, unsigned short src)
242 flags &= ~BIT_ALL; /* clear these bits */
244 flags &= ~BIT_ALL; /* clear these bits */
245 result = dst - src - 1;
247 flags &= ~BIT_ALL; /* clear these bits */
250 if (result == 0) flags |= BIT_Z;
251 if (result > 0xff) flags |= BIT_C;
252 if (dst < src) flags |= BIT_N;
253 /* fixme: do AC, V */
255 return (unsigned short) result;
258 /*-------------------------------------
259 cmp - flags changed:C,AC,V,N,Z.
260 |---------------------------------------*/
261 inline unsigned char cmp1(unsigned char dst, unsigned char src)
266 flags &= ~BIT_ALL; /* clear these bits */
268 if (result == 0) flags |= BIT_Z;
269 if (result > 0xff) flags |= BIT_C;
270 if (dst < src) flags |= BIT_N;
271 /* fixme: do AC, V */
273 return (unsigned char) dst;
276 inline unsigned short cmp2(unsigned short dst, unsigned short src)
281 flags &= ~BIT_ALL; /* clear these bits */
283 if (result == 0) flags |= BIT_Z;
284 if (result > 0xff) flags |= BIT_C;
285 if (dst < src) flags |= BIT_N;
286 /* fixme: do AC, V */
288 return (unsigned short) dst;
291 /*-------------------------------------
292 and - flags changed:N,Z.
293 |---------------------------------------*/
294 inline unsigned char and1(unsigned char dst, unsigned char src)
298 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
300 if (result == 0) flags |= BIT_Z;
301 if (result & 0x80) flags |= BIT_N;
303 return (unsigned char) result;
306 inline unsigned short and2(unsigned short dst, unsigned short src)
310 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
312 if (result == 0) flags |= BIT_Z;
313 if (result & 0x80) flags |= BIT_N;
315 return (unsigned short) result;
318 /*-------------------------------------
319 or - flags changed:N,Z.
320 |---------------------------------------*/
321 inline unsigned char or1(unsigned char dst, unsigned char src)
325 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
327 if (result == 0) flags |= BIT_Z;
328 if (result & 0x80) flags |= BIT_N;
330 return (unsigned char) result;
333 inline unsigned short or2(unsigned short dst, unsigned short src)
337 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
339 if (result == 0) flags |= BIT_Z;
340 if (result & 0x80) flags |= BIT_N;
342 return (unsigned short) result;
345 /*-------------------------------------
346 xor - flags changed:N,Z.
347 |---------------------------------------*/
348 inline unsigned char xor1(unsigned char dst, unsigned char src)
351 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
353 if (dst == 0) flags |= BIT_Z;
354 if (dst & 0x80) flags |= BIT_N;
356 return (unsigned char) dst;
359 inline unsigned short xor2(unsigned short dst, unsigned short src)
362 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
364 if (dst == 0) flags |= BIT_Z;
365 if (dst & 0x8000) flags |= BIT_N;
367 return (unsigned short) dst;
370 /*-------------------------------------
371 mov - flags changed:N,Z.
372 |---------------------------------------*/
373 inline unsigned char mov1(unsigned char dst, unsigned char src)
376 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
378 if (dst == 0) flags |= BIT_Z;
379 if (dst & 0x80) flags |= BIT_N;
381 return (unsigned char) dst;
384 inline unsigned short mov2(unsigned short dst, unsigned short src)
387 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
389 if (dst == 0) flags |= BIT_Z;
390 if (dst & 0x8000) flags |= BIT_N;
392 return (unsigned short) dst;
398 /* End of xa.src/xacl.h */