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);
88 virtual bool get_bit(int bit);
89 virtual void set_bit(int bit, int value);
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)
106 flags &= ~BIT_ALL; /* clear these bits */
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 */
113 return (unsigned char) result;
116 inline unsigned short add2(unsigned short dst, unsigned short src)
121 flags &= ~BIT_ALL; /* clear these bits */
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 */
128 return (unsigned short) result;
131 /*-------------------------------------
132 addc - flags changed:C,AC,V,N,Z.
133 |---------------------------------------*/
134 inline unsigned char addc1(unsigned char dst, unsigned char src)
140 flags &= ~BIT_ALL; /* clear these bits */
141 result = dst + src + 1;
143 flags &= ~BIT_ALL; /* clear these bits */
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 */
151 return (unsigned char) result;
154 inline unsigned short addc2(unsigned short dst, unsigned short src)
159 flags &= ~BIT_ALL; /* clear these bits */
161 flags &= ~BIT_ALL; /* clear these bits */
162 result = dst + src + 1;
164 flags &= ~BIT_ALL; /* clear these bits */
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 */
172 return (unsigned short) result;
175 /*-------------------------------------
176 sub - flags changed:C,AC,V,N,Z.
177 |---------------------------------------*/
178 inline unsigned char sub1(unsigned char dst, unsigned char src)
183 flags &= ~BIT_ALL; /* clear these bits */
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 */
190 return (unsigned char) result;
193 inline unsigned short sub2(unsigned short dst, unsigned short src)
198 flags &= ~BIT_ALL; /* clear these bits */
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 */
205 return (unsigned short) result;
208 /*-------------------------------------
209 subb - flags changed:C,AC,V,N,Z.
210 |---------------------------------------*/
211 inline unsigned char subb1(unsigned char dst, unsigned char src)
217 flags &= ~BIT_ALL; /* clear these bits */
218 result = dst - src - 1;
220 flags &= ~BIT_ALL; /* clear these bits */
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 */
228 return (unsigned char) result;
231 inline unsigned short subb2(unsigned short dst, unsigned short src)
236 flags &= ~BIT_ALL; /* clear these bits */
238 flags &= ~BIT_ALL; /* clear these bits */
239 result = dst - src - 1;
241 flags &= ~BIT_ALL; /* clear these bits */
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 */
249 return (unsigned short) result;
252 /*-------------------------------------
253 cmp - flags changed:C,AC,V,N,Z.
254 |---------------------------------------*/
255 inline unsigned char cmp1(unsigned char dst, unsigned char src)
260 flags &= ~BIT_ALL; /* clear these bits */
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 */
267 return (unsigned char) dst;
270 inline unsigned short cmp2(unsigned short dst, unsigned short src)
275 flags &= ~BIT_ALL; /* clear these bits */
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 */
282 return (unsigned short) dst;
285 /*-------------------------------------
286 and - flags changed:N,Z.
287 |---------------------------------------*/
288 inline unsigned char and1(unsigned char dst, unsigned char src)
292 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
294 if (result == 0) flags |= BIT_Z;
295 if (result & 0x80) flags |= BIT_N;
297 return (unsigned char) result;
300 inline unsigned short and2(unsigned short dst, unsigned short src)
304 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
306 if (result == 0) flags |= BIT_Z;
307 if (result & 0x80) flags |= BIT_N;
309 return (unsigned short) result;
312 /*-------------------------------------
313 or - flags changed:N,Z.
314 |---------------------------------------*/
315 inline unsigned char or1(unsigned char dst, unsigned char src)
319 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
321 if (result == 0) flags |= BIT_Z;
322 if (result & 0x80) flags |= BIT_N;
324 return (unsigned char) result;
327 inline unsigned short or2(unsigned short dst, unsigned short src)
331 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
333 if (result == 0) flags |= BIT_Z;
334 if (result & 0x80) flags |= BIT_N;
336 return (unsigned short) result;
339 /*-------------------------------------
340 xor - flags changed:N,Z.
341 |---------------------------------------*/
342 inline unsigned char xor1(unsigned char dst, unsigned char src)
345 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
347 if (dst == 0) flags |= BIT_Z;
348 if (dst & 0x80) flags |= BIT_N;
350 return (unsigned char) dst;
353 inline unsigned short xor2(unsigned short dst, unsigned short src)
356 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
358 if (dst == 0) flags |= BIT_Z;
359 if (dst & 0x8000) flags |= BIT_N;
361 return (unsigned short) dst;
364 /*-------------------------------------
365 mov - flags changed:N,Z.
366 |---------------------------------------*/
367 inline unsigned char mov1(unsigned char dst, unsigned char src)
370 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
372 if (dst == 0) flags |= BIT_Z;
373 if (dst & 0x80) flags |= BIT_N;
375 return (unsigned char) dst;
378 inline unsigned short mov2(unsigned short dst, unsigned short src)
381 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
383 if (dst == 0) flags |= BIT_Z;
384 if (dst & 0x8000) flags |= BIT_N;
386 return (unsigned short) dst;
392 /* End of xa.src/xacl.h */