[ucsim] Update email and file info, fix stm8 flash controller
[sdcc.git] / sdcc / sim / ucsim / src / sims / xa.src / xacl.h
blob94ad8c5b626f706c1e1ccf338173be4be6dfa725
1 /*
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
28 02111-1307, USA. */
29 /*@1@*/
31 #ifndef XACL_HEADER
32 #define XACL_HEADER
34 #include "uccl.h"
36 #include "regsxa.h"
39 * Base type of XA microcontrollers
42 class cl_xa: public cl_uc
44 public:
45 class cl_address_space *ram;
46 class cl_address_space *rom;
47 struct t_regs regs;
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 */
55 //#endif
57 public:
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,
79 int *ret_len,
80 int *ret_branch,
81 int *immed_offset,
82 int *parms,
83 int *mnemonic);
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);
99 #include "instcl.h"
101 private :
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)
111 unsigned int result;
112 unsigned char flags;
113 flags = get_psw();
114 flags &= ~BIT_ALL; /* clear these bits */
115 result = dst + src;
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 */
120 set_psw(flags);
121 return (unsigned char) result;
124 inline unsigned short add2(unsigned short dst, unsigned short src)
126 unsigned int result;
127 unsigned char flags;
128 flags = get_psw();
129 flags &= ~BIT_ALL; /* clear these bits */
130 result = dst + src;
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 */
135 set_psw(flags);
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)
144 unsigned int result;
145 unsigned char flags;
146 flags = get_psw();
147 if (flags & BIT_C) {
148 flags &= ~BIT_ALL; /* clear these bits */
149 result = dst + src + 1;
150 } else {
151 flags &= ~BIT_ALL; /* clear these bits */
152 result = dst + src;
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 */
158 set_psw(flags);
159 return (unsigned char) result;
162 inline unsigned short addc2(unsigned short dst, unsigned short src)
164 unsigned int result;
165 unsigned char flags;
166 flags = get_psw();
167 flags &= ~BIT_ALL; /* clear these bits */
168 if (flags & BIT_C) {
169 flags &= ~BIT_ALL; /* clear these bits */
170 result = dst + src + 1;
171 } else {
172 flags &= ~BIT_ALL; /* clear these bits */
173 result = dst + src;
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 */
179 set_psw(flags);
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)
188 unsigned int result;
189 unsigned char flags;
190 flags = get_psw();
191 flags &= ~BIT_ALL; /* clear these bits */
192 result = dst - src;
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 */
197 set_psw(flags);
198 return (unsigned char) result;
201 inline unsigned short sub2(unsigned short dst, unsigned short src)
203 unsigned int result;
204 unsigned char flags;
205 flags = get_psw();
206 flags &= ~BIT_ALL; /* clear these bits */
207 result = dst - src;
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 */
212 set_psw(flags);
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)
221 unsigned int result;
222 unsigned char flags;
223 flags = get_psw();
224 if (flags & BIT_C) {
225 flags &= ~BIT_ALL; /* clear these bits */
226 result = dst - src - 1;
227 } else {
228 flags &= ~BIT_ALL; /* clear these bits */
229 result = dst - src;
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 */
235 set_psw(flags);
236 return (unsigned char) result;
239 inline unsigned short subb2(unsigned short dst, unsigned short src)
241 unsigned int result;
242 unsigned char flags;
243 flags = get_psw();
244 flags &= ~BIT_ALL; /* clear these bits */
245 if (flags & BIT_C) {
246 flags &= ~BIT_ALL; /* clear these bits */
247 result = dst - src - 1;
248 } else {
249 flags &= ~BIT_ALL; /* clear these bits */
250 result = dst - src;
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 */
256 set_psw(flags);
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)
265 unsigned int result;
266 unsigned char flags;
267 flags = get_psw();
268 flags &= ~BIT_ALL; /* clear these bits */
269 result = dst - src;
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 */
274 set_psw(flags);
275 return (unsigned char) dst;
278 inline unsigned short cmp2(unsigned short dst, unsigned short src)
280 unsigned int result;
281 unsigned char flags;
282 flags = get_psw();
283 flags &= ~BIT_ALL; /* clear these bits */
284 result = dst - src;
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 */
289 set_psw(flags);
290 return (unsigned short) dst;
293 /*-------------------------------------
294 and - flags changed:N,Z.
295 |---------------------------------------*/
296 inline unsigned char and1(unsigned char dst, unsigned char src)
298 unsigned int result;
299 unsigned char flags;
300 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
301 result = dst & src;
302 if (result == 0) flags |= BIT_Z;
303 if (result & 0x80) flags |= BIT_N;
304 set_psw(flags);
305 return (unsigned char) result;
308 inline unsigned short and2(unsigned short dst, unsigned short src)
310 unsigned int result;
311 unsigned char flags;
312 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
313 result = dst & src;
314 if (result == 0) flags |= BIT_Z;
315 if (result & 0x80) flags |= BIT_N;
316 set_psw(flags);
317 return (unsigned short) result;
320 /*-------------------------------------
321 or - flags changed:N,Z.
322 |---------------------------------------*/
323 inline unsigned char or1(unsigned char dst, unsigned char src)
325 unsigned int result;
326 unsigned char flags;
327 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
328 result = dst | src;
329 if (result == 0) flags |= BIT_Z;
330 if (result & 0x80) flags |= BIT_N;
331 set_psw(flags);
332 return (unsigned char) result;
335 inline unsigned short or2(unsigned short dst, unsigned short src)
337 unsigned int result;
338 unsigned char flags;
339 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
340 result = dst | src;
341 if (result == 0) flags |= BIT_Z;
342 if (result & 0x80) flags |= BIT_N;
343 set_psw(flags);
344 return (unsigned short) result;
347 /*-------------------------------------
348 xor - flags changed:N,Z.
349 |---------------------------------------*/
350 inline unsigned char xor1(unsigned char dst, unsigned char src)
352 unsigned char flags;
353 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
354 dst ^= src;
355 if (dst == 0) flags |= BIT_Z;
356 if (dst & 0x80) flags |= BIT_N;
357 set_psw(flags);
358 return (unsigned char) dst;
361 inline unsigned short xor2(unsigned short dst, unsigned short src)
363 unsigned char flags;
364 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
365 dst ^= src;
366 if (dst == 0) flags |= BIT_Z;
367 if (dst & 0x8000) flags |= BIT_N;
368 set_psw(flags);
369 return (unsigned short) dst;
372 /*-------------------------------------
373 mov - flags changed:N,Z.
374 |---------------------------------------*/
375 inline unsigned char mov1(unsigned char dst, unsigned char src)
377 unsigned char flags;
378 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
379 dst = src;
380 if (dst == 0) flags |= BIT_Z;
381 if (dst & 0x80) flags |= BIT_N;
382 set_psw(flags);
383 return (unsigned char) dst;
386 inline unsigned short mov2(unsigned short dst, unsigned short src)
388 unsigned char flags;
389 flags = get_psw() & ~(BIT_N | BIT_Z); /* clear these bits */
390 dst = src;
391 if (dst == 0) flags |= BIT_Z;
392 if (dst & 0x8000) flags |= BIT_N;
393 set_psw(flags);
394 return (unsigned short) dst;
398 #endif
400 /* End of xa.src/xacl.h */