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 // 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 */
55 cl_xa(class cl_sim *asim);
56 virtual int init(void);
57 virtual char *id_string(void);
59 virtual t_addr get_mem_size(enum mem_class type);
60 virtual void mk_hw_elements(void);
62 virtual struct dis_entry *dis_tbl(void);
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);
69 virtual int inst_length(t_addr addr);
70 virtual int inst_branch(t_addr addr);
71 virtual int longest_inst(void);
73 virtual int get_disasm_info(t_addr addr,
80 virtual char *disass(t_addr addr, char *sep);
81 virtual void print_regs(class cl_console *con);
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);
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)
103 flags &= ~BIT_ALL; /* clear these bits */
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 */
110 return (unsigned char) result;
113 inline unsigned short add2(unsigned short dst, unsigned short src)
118 flags &= ~BIT_ALL; /* clear these bits */
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 */
125 return (unsigned short) result;
128 /*-------------------------------------
129 addc - flags changed:C,AC,V,N,Z.
130 |---------------------------------------*/
131 inline unsigned char addc1(unsigned char dst, unsigned char src)
137 flags &= ~BIT_ALL; /* clear these bits */
138 result = dst + src + 1;
140 flags &= ~BIT_ALL; /* clear these bits */
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 */
148 return (unsigned char) result;
151 inline unsigned short addc2(unsigned short dst, unsigned short src)
156 flags &= ~BIT_ALL; /* clear these bits */
158 flags &= ~BIT_ALL; /* clear these bits */
159 result = dst + src + 1;
161 flags &= ~BIT_ALL; /* clear these bits */
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 */
169 return (unsigned short) result;
172 /*-------------------------------------
173 sub - flags changed:C,AC,V,N,Z.
174 |---------------------------------------*/
175 inline unsigned char sub1(unsigned char dst, unsigned char src)
180 flags &= ~BIT_ALL; /* clear these bits */
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 */
187 return (unsigned char) result;
190 inline unsigned short sub2(unsigned short dst, unsigned short src)
195 flags &= ~BIT_ALL; /* clear these bits */
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 */
202 return (unsigned short) result;
205 /*-------------------------------------
206 subb - flags changed:C,AC,V,N,Z.
207 |---------------------------------------*/
208 inline unsigned char subb1(unsigned char dst, unsigned char src)
214 flags &= ~BIT_ALL; /* clear these bits */
215 result = dst - src - 1;
217 flags &= ~BIT_ALL; /* clear these bits */
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 */
225 return (unsigned char) result;
228 inline unsigned short subb2(unsigned short dst, unsigned short src)
233 flags &= ~BIT_ALL; /* clear these bits */
235 flags &= ~BIT_ALL; /* clear these bits */
236 result = dst - src - 1;
238 flags &= ~BIT_ALL; /* clear these bits */
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 */
246 return (unsigned short) result;
249 /*-------------------------------------
250 cmp - flags changed:C,AC,V,N,Z.
251 |---------------------------------------*/
252 inline unsigned char cmp1(unsigned char dst, unsigned char src)
257 flags &= ~BIT_ALL; /* clear these bits */
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 */
264 return (unsigned char) dst;
267 inline unsigned short cmp2(unsigned short dst, unsigned short src)
272 flags &= ~BIT_ALL; /* clear these bits */
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 */
279 return (unsigned short) dst;
282 /*-------------------------------------
283 and - flags changed:N,Z.
284 |---------------------------------------*/
285 inline unsigned char and1(unsigned char dst, unsigned char src)
289 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
291 if (result == 0) flags |= BIT_Z;
292 if (result & 0x80) flags |= BIT_N;
294 return (unsigned char) result;
297 inline unsigned short and2(unsigned short dst, unsigned short src)
301 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
303 if (result == 0) flags |= BIT_Z;
304 if (result & 0x80) flags |= BIT_N;
306 return (unsigned short) result;
309 /*-------------------------------------
310 or - flags changed:N,Z.
311 |---------------------------------------*/
312 inline unsigned char or1(unsigned char dst, unsigned char src)
316 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
318 if (result == 0) flags |= BIT_Z;
319 if (result & 0x80) flags |= BIT_N;
321 return (unsigned char) result;
324 inline unsigned short or2(unsigned short dst, unsigned short src)
328 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
330 if (result == 0) flags |= BIT_Z;
331 if (result & 0x80) flags |= BIT_N;
333 return (unsigned short) result;
336 /*-------------------------------------
337 xor - flags changed:N,Z.
338 |---------------------------------------*/
339 inline unsigned char xor1(unsigned char dst, unsigned char src)
342 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
344 if (dst == 0) flags |= BIT_Z;
345 if (dst & 0x80) flags |= BIT_N;
347 return (unsigned char) dst;
350 inline unsigned short xor2(unsigned short dst, unsigned short src)
353 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
355 if (dst == 0) flags |= BIT_Z;
356 if (dst & 0x8000) flags |= BIT_N;
358 return (unsigned short) dst;
361 /*-------------------------------------
362 mov - flags changed:N,Z.
363 |---------------------------------------*/
364 inline unsigned char mov1(unsigned char dst, unsigned char src)
367 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
369 if (dst == 0) flags |= BIT_Z;
370 if (dst & 0x80) flags |= BIT_N;
372 return (unsigned char) dst;
375 inline unsigned short mov2(unsigned short dst, unsigned short src)
378 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
380 if (dst == 0) flags |= BIT_Z;
381 if (dst & 0x8000) flags |= BIT_N;
383 return (unsigned short) dst;
389 /* End of xa.src/xacl.h */