2 * Simulator of microcontrollers (xacl.h)
4 * Copyright (C) 2002 Drotos Daniel
6 * To contact author send email to dr.dkdb@gmail.com
7 * Other contributors include:
8 * Karl Bongers karl@turbobit.com,
9 * Johan Knol johan.knol@iduna.nl
13 /* This file is part of microcontroller simulator: ucsim.
15 UCSIM is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
20 UCSIM is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with UCSIM; see the file COPYING. If not, write to the Free
27 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
39 * Base type of XA microcontrollers
42 class cl_xa
: public cl_uc
45 class cl_address_space
*ram
;
46 class cl_address_space
*rom
;
49 class cl_address_space
*sfr
, *iram
;
51 // for now make it as simple as possible
52 // TYPE_UBYTE mem_direct[1024*2];
53 //#ifndef WORDS_BIGENDIAN
54 // TYPE_UWORD *wmem_direct; /* word pointer at mem_direct */
58 cl_xa(class cl_sim
*asim
);
59 virtual int init(void);
60 virtual const char *id_string(void);
62 //virtual class cl_m *mk_mem(enum mem_class type, char *class_name);
63 //virtual t_addr get_mem_size(enum mem_class type);
64 virtual void mk_hw_elements(void);
65 virtual void make_memories(void);
67 virtual struct dis_entry
*dis_tbl(void);
69 virtual struct name_entry
*sfr_tbl(void);
70 virtual struct name_entry
*bit_tbl(void);
71 virtual chars
get_dir_name(short);
72 virtual chars
get_bit_name(short);
74 virtual int inst_length(t_addr addr
);
75 virtual int inst_branch(t_addr addr
);
76 virtual int longest_inst(void);
78 virtual int get_disasm_info(t_addr addr
,
85 virtual char *disass(t_addr addr
);
86 virtual void print_regs(class cl_console_base
*con
);
88 virtual int exec_inst(void);
89 virtual int get_reg(int word_flag
, unsigned int index
);
91 virtual void store1(t_addr addr
, unsigned char val
);
92 virtual void store2(t_addr addr
, unsigned short val
);
93 virtual unsigned char get1(t_addr addr
);
94 virtual unsigned short get2(t_addr addr
);
96 virtual bool get_bit(int bit
);
97 virtual void set_bit(int bit
, int value
);
103 /* following are macros which get substituted for FUNC1() and FUNC2()
104 in the inst.cc to form the body of ADD,ADDC,SUB,XOR,... */
105 /* can I put these in the .cc file and still have them do the inline thing? */
106 /*-------------------------------------
107 add - flags changed:C,AC,V,N,Z.
108 |---------------------------------------*/
109 inline unsigned char add1(unsigned char dst
, unsigned char src
)
114 flags
&= ~BIT_ALL
; /* clear these bits */
116 if (result
== 0) flags
|= BIT_Z
;
117 if (result
> 0xff) flags
|= BIT_C
;
118 if (result
& 0x80) flags
|= BIT_N
;
119 /* fixme: do AC, V */
121 return (unsigned char) result
;
124 inline unsigned short add2(unsigned short dst
, unsigned short src
)
129 flags
&= ~BIT_ALL
; /* clear these bits */
131 if (result
== 0) flags
|= BIT_Z
;
132 if (result
> 0xff) flags
|= BIT_C
;
133 if (result
& 0x80) flags
|= BIT_N
;
134 /* fixme: do AC, V */
136 return (unsigned short) result
;
139 /*-------------------------------------
140 addc - flags changed:C,AC,V,N,Z.
141 |---------------------------------------*/
142 inline unsigned char addc1(unsigned char dst
, unsigned char src
)
148 flags
&= ~BIT_ALL
; /* clear these bits */
149 result
= dst
+ src
+ 1;
151 flags
&= ~BIT_ALL
; /* clear these bits */
154 if (result
== 0) flags
|= BIT_Z
;
155 if (result
> 0xff) flags
|= BIT_C
;
156 if (result
& 0x80) flags
|= BIT_N
;
157 /* fixme: do AC, V */
159 return (unsigned char) result
;
162 inline unsigned short addc2(unsigned short dst
, unsigned short src
)
167 flags
&= ~BIT_ALL
; /* clear these bits */
169 flags
&= ~BIT_ALL
; /* clear these bits */
170 result
= dst
+ src
+ 1;
172 flags
&= ~BIT_ALL
; /* clear these bits */
175 if (result
== 0) flags
|= BIT_Z
;
176 if (result
> 0xff) flags
|= BIT_C
;
177 if (result
& 0x80) flags
|= BIT_N
;
178 /* fixme: do AC, V */
180 return (unsigned short) result
;
183 /*-------------------------------------
184 sub - flags changed:C,AC,V,N,Z.
185 |---------------------------------------*/
186 inline unsigned char sub1(unsigned char dst
, unsigned char src
)
191 flags
&= ~BIT_ALL
; /* clear these bits */
193 if (result
== 0) flags
|= BIT_Z
;
194 if (result
> 0xff) flags
|= BIT_C
;
195 if (dst
< src
) flags
|= BIT_N
;
196 /* fixme: do AC, V */
198 return (unsigned char) result
;
201 inline unsigned short sub2(unsigned short dst
, unsigned short src
)
206 flags
&= ~BIT_ALL
; /* clear these bits */
208 if (result
== 0) flags
|= BIT_Z
;
209 if (result
> 0xff) flags
|= BIT_C
;
210 if (dst
< src
) flags
|= BIT_N
;
211 /* fixme: do AC, V */
213 return (unsigned short) result
;
216 /*-------------------------------------
217 subb - flags changed:C,AC,V,N,Z.
218 |---------------------------------------*/
219 inline unsigned char subb1(unsigned char dst
, unsigned char src
)
225 flags
&= ~BIT_ALL
; /* clear these bits */
226 result
= dst
- src
- 1;
228 flags
&= ~BIT_ALL
; /* clear these bits */
231 if (result
== 0) flags
|= BIT_Z
;
232 if (result
> 0xff) flags
|= BIT_C
;
233 if (dst
< src
) flags
|= BIT_N
;
234 /* fixme: do AC, V */
236 return (unsigned char) result
;
239 inline unsigned short subb2(unsigned short dst
, unsigned short src
)
244 flags
&= ~BIT_ALL
; /* clear these bits */
246 flags
&= ~BIT_ALL
; /* clear these bits */
247 result
= dst
- src
- 1;
249 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 short) result
;
260 /*-------------------------------------
261 cmp - flags changed:C,AC,V,N,Z.
262 |---------------------------------------*/
263 inline unsigned char cmp1(unsigned char dst
, unsigned char src
)
268 flags
&= ~BIT_ALL
; /* clear these bits */
270 if (result
== 0) flags
|= BIT_Z
;
271 if (result
> 0xff) flags
|= BIT_C
;
272 if (dst
< src
) flags
|= BIT_N
;
273 /* fixme: do AC, V */
275 return (unsigned char) dst
;
278 inline unsigned short cmp2(unsigned short dst
, unsigned short src
)
283 flags
&= ~BIT_ALL
; /* clear these bits */
285 if (result
== 0) flags
|= BIT_Z
;
286 if (result
> 0xff) flags
|= BIT_C
;
287 if (dst
< src
) flags
|= BIT_N
;
288 /* fixme: do AC, V */
290 return (unsigned short) dst
;
293 /*-------------------------------------
294 and - flags changed:N,Z.
295 |---------------------------------------*/
296 inline unsigned char and1(unsigned char dst
, unsigned char src
)
300 flags
= get_psw() & ~(BIT_N
| BIT_Z
); /* clear these bits */
302 if (result
== 0) flags
|= BIT_Z
;
303 if (result
& 0x80) flags
|= BIT_N
;
305 return (unsigned char) result
;
308 inline unsigned short and2(unsigned short dst
, unsigned short src
)
312 flags
= get_psw() & ~(BIT_N
| BIT_Z
); /* clear these bits */
314 if (result
== 0) flags
|= BIT_Z
;
315 if (result
& 0x80) flags
|= BIT_N
;
317 return (unsigned short) result
;
320 /*-------------------------------------
321 or - flags changed:N,Z.
322 |---------------------------------------*/
323 inline unsigned char or1(unsigned char dst
, unsigned char src
)
327 flags
= get_psw() & ~(BIT_N
| BIT_Z
); /* clear these bits */
329 if (result
== 0) flags
|= BIT_Z
;
330 if (result
& 0x80) flags
|= BIT_N
;
332 return (unsigned char) result
;
335 inline unsigned short or2(unsigned short dst
, unsigned short src
)
339 flags
= get_psw() & ~(BIT_N
| BIT_Z
); /* clear these bits */
341 if (result
== 0) flags
|= BIT_Z
;
342 if (result
& 0x80) flags
|= BIT_N
;
344 return (unsigned short) result
;
347 /*-------------------------------------
348 xor - flags changed:N,Z.
349 |---------------------------------------*/
350 inline unsigned char xor1(unsigned char dst
, unsigned char src
)
353 flags
= get_psw() & ~(BIT_N
| BIT_Z
); /* clear these bits */
355 if (dst
== 0) flags
|= BIT_Z
;
356 if (dst
& 0x80) flags
|= BIT_N
;
358 return (unsigned char) dst
;
361 inline unsigned short xor2(unsigned short dst
, unsigned short src
)
364 flags
= get_psw() & ~(BIT_N
| BIT_Z
); /* clear these bits */
366 if (dst
== 0) flags
|= BIT_Z
;
367 if (dst
& 0x8000) flags
|= BIT_N
;
369 return (unsigned short) dst
;
372 /*-------------------------------------
373 mov - flags changed:N,Z.
374 |---------------------------------------*/
375 inline unsigned char mov1(unsigned char dst
, unsigned char src
)
378 flags
= get_psw() & ~(BIT_N
| BIT_Z
); /* clear these bits */
380 if (dst
== 0) flags
|= BIT_Z
;
381 if (dst
& 0x80) flags
|= BIT_N
;
383 return (unsigned char) dst
;
386 inline unsigned short mov2(unsigned short dst
, unsigned short src
)
389 flags
= get_psw() & ~(BIT_N
| BIT_Z
); /* clear these bits */
391 if (dst
== 0) flags
|= BIT_Z
;
392 if (dst
& 0x8000) flags
|= BIT_N
;
394 return (unsigned short) dst
;
400 /* End of xa.src/xacl.h */