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 int inst_length(t_addr addr);
65 virtual int inst_branch(t_addr addr);
66 virtual int longest_inst(void);
68 virtual int get_disasm_info(t_addr addr,
75 virtual char *disass(t_addr addr, char *sep);
76 virtual void print_regs(class cl_console *con);
78 virtual int exec_inst(void);
79 virtual int get_reg(int word_flag, unsigned int index);
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)
96 flags &= ~BIT_ALL; /* clear these bits */
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 */
103 return (unsigned char) result;
106 inline unsigned short add2(unsigned short dst, unsigned short src)
111 flags &= ~BIT_ALL; /* clear these bits */
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 */
118 return (unsigned short) result;
121 /*-------------------------------------
122 addc - flags changed:C,AC,V,N,Z.
123 |---------------------------------------*/
124 inline unsigned char addc1(unsigned char dst, unsigned char src)
130 flags &= ~BIT_ALL; /* clear these bits */
131 result = dst + src + 1;
133 flags &= ~BIT_ALL; /* clear these bits */
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 */
141 return (unsigned char) result;
144 inline unsigned short addc2(unsigned short dst, unsigned short src)
149 flags &= ~BIT_ALL; /* clear these bits */
151 flags &= ~BIT_ALL; /* clear these bits */
152 result = dst + src + 1;
154 flags &= ~BIT_ALL; /* clear these bits */
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 */
162 return (unsigned short) result;
165 /*-------------------------------------
166 sub - flags changed:C,AC,V,N,Z.
167 |---------------------------------------*/
168 inline unsigned char sub1(unsigned char dst, unsigned char src)
173 flags &= ~BIT_ALL; /* clear these bits */
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 */
180 return (unsigned char) result;
183 inline unsigned short sub2(unsigned short dst, unsigned short src)
188 flags &= ~BIT_ALL; /* clear these bits */
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 */
195 return (unsigned short) result;
198 /*-------------------------------------
199 subb - flags changed:C,AC,V,N,Z.
200 |---------------------------------------*/
201 inline unsigned char subb1(unsigned char dst, unsigned char src)
207 flags &= ~BIT_ALL; /* clear these bits */
208 result = dst - src - 1;
210 flags &= ~BIT_ALL; /* clear these bits */
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 */
218 return (unsigned char) result;
221 inline unsigned short subb2(unsigned short dst, unsigned short src)
226 flags &= ~BIT_ALL; /* clear these bits */
228 flags &= ~BIT_ALL; /* clear these bits */
229 result = dst - src - 1;
231 flags &= ~BIT_ALL; /* clear these bits */
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 */
239 return (unsigned short) result;
242 /*-------------------------------------
243 cmp - flags changed:C,AC,V,N,Z.
244 |---------------------------------------*/
245 inline unsigned char cmp1(unsigned char dst, unsigned char src)
250 flags &= ~BIT_ALL; /* clear these bits */
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 */
257 return (unsigned char) dst;
260 inline unsigned short cmp2(unsigned short dst, unsigned short src)
265 flags &= ~BIT_ALL; /* clear these bits */
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 */
272 return (unsigned short) dst;
275 /*-------------------------------------
276 and - flags changed:N,Z.
277 |---------------------------------------*/
278 inline unsigned char and1(unsigned char dst, unsigned char src)
282 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
284 if (result == 0) flags |= BIT_Z;
285 if (result & 0x80) flags |= BIT_N;
287 return (unsigned char) result;
290 inline unsigned short and2(unsigned short dst, unsigned short src)
294 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
296 if (result == 0) flags |= BIT_Z;
297 if (result & 0x80) flags |= BIT_N;
299 return (unsigned short) result;
302 /*-------------------------------------
303 or - flags changed:N,Z.
304 |---------------------------------------*/
305 inline unsigned char or1(unsigned char dst, unsigned char src)
309 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
311 if (result == 0) flags |= BIT_Z;
312 if (result & 0x80) flags |= BIT_N;
314 return (unsigned char) result;
317 inline unsigned short or2(unsigned short dst, unsigned short src)
321 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
323 if (result == 0) flags |= BIT_Z;
324 if (result & 0x80) flags |= BIT_N;
326 return (unsigned short) result;
329 /*-------------------------------------
330 xor - flags changed:N,Z.
331 |---------------------------------------*/
332 inline unsigned char xor1(unsigned char dst, unsigned char src)
335 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
337 if (dst == 0) flags |= BIT_Z;
338 if (dst & 0x80) flags |= BIT_N;
340 return (unsigned char) dst;
343 inline unsigned short xor2(unsigned short dst, unsigned short src)
346 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
348 if (dst == 0) flags |= BIT_Z;
349 if (dst & 0x8000) flags |= BIT_N;
351 return (unsigned short) dst;
354 /*-------------------------------------
355 mov - flags changed:N,Z.
356 |---------------------------------------*/
357 inline unsigned char mov1(unsigned char dst, unsigned char src)
360 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
362 if (dst == 0) flags |= BIT_Z;
363 if (dst & 0x80) flags |= BIT_N;
365 return (unsigned char) dst;
368 inline unsigned short mov2(unsigned short dst, unsigned short src)
371 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
373 if (dst == 0) flags |= BIT_Z;
374 if (dst & 0x8000) flags |= BIT_N;
376 return (unsigned short) dst;
382 /* End of xa.src/xacl.h */