Imported Upstream version 2.9.0
[debian/cc1111] / sim / ucsim / s51.src / logic.cc
1 /*
2  * Simulator of microcontrollers (logic.cc)
3  *
4  * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
5  * 
6  * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
7  *
8  */
9
10 /* This file is part of microcontroller simulator: ucsim.
11
12 UCSIM is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 UCSIM is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with UCSIM; see the file COPYING.  If not, write to the Free
24 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 02111-1307, USA. */
26 /*@1@*/
27
28 #include "ddconfig.h"
29
30 // prj
31 #include "stypes.h"
32
33 // local
34 #include "uc51cl.h"
35 #include "regs51.h"
36
37
38 /*
39  * 0x42 2 12 ORL addr,A
40  *____________________________________________________________________________
41  *
42  */
43
44 int
45 cl_51core::inst_orl_addr_a(uchar code)
46 {
47   class cl_memory_cell *cell;
48
49   cell= get_direct(fetch());
50   cell->write(cell->read(HW_PORT) | acc->read());
51   return(resGO);
52 }
53
54
55 /*
56  * 0x43 3 24 ORL addr,#data
57  *____________________________________________________________________________
58  *
59  */
60
61 int
62 cl_51core::inst_orl_addr_Sdata(uchar code)
63 {
64   class cl_memory_cell *cell;
65   int res= resGO;
66
67   cell= get_direct(fetch());
68   t_mem d= fetch();
69   cell->write(cell->read(HW_PORT) | d);
70   tick(1);
71   return(res);
72 }
73
74
75 /*
76  * 0x44 2 12 ORL A,#data
77  *____________________________________________________________________________
78  *
79  */
80
81 int
82 cl_51core::inst_orl_a_Sdata(uchar code)
83 {
84   uchar d;
85
86   d= acc->read();
87   acc->write(d|= fetch());
88   return(resGO);
89 }
90
91
92 /*
93  * 0x45 2 12 ORL A,addr
94  *____________________________________________________________________________
95  *
96  */
97
98 int
99 cl_51core::inst_orl_a_addr(uchar code)
100 {
101   t_mem d;
102   class cl_memory_cell *cell;
103
104   cell= get_direct(fetch());
105   d= acc->read();
106   acc->write(d|= cell->read());
107   return(resGO);
108 }
109
110
111 /*
112  * 0x46-0x47 1 12 ORL A,@Ri
113  *____________________________________________________________________________
114  *
115  */
116
117 int
118 cl_51core::inst_orl_a_Sri(uchar code)
119 {
120   t_mem d;
121   class cl_memory_cell *cell;
122
123   cell= iram->get_cell(get_reg(code & 0x01)->read());
124   d= acc->read();
125   acc->write(d|= cell->read());
126   return(resGO);
127 }
128
129
130 /*
131  * 0x48-0x4f 1 12 ORL A,Rn
132  *____________________________________________________________________________
133  *
134  */
135
136 int
137 cl_51core::inst_orl_a_rn(uchar code)
138 {
139   t_mem d;
140
141   d= acc->read();
142   acc->write(d|= get_reg(code & 0x07)->read());
143   return(resGO);
144 }
145
146
147 /*
148  * 0x52 2 12 ANL addr,A
149  *____________________________________________________________________________
150  *
151  */
152
153 int
154 cl_51core::inst_anl_addr_a(uchar code)
155 {
156   class cl_memory_cell *cell;
157   
158   cell= get_direct(fetch());
159   cell->write(cell->read(HW_PORT) & acc->read());
160   return(resGO);
161 }
162
163
164 /*
165  * 0x53 3 24 ANL addr,#data
166  *____________________________________________________________________________
167  *
168  */
169
170 int
171 cl_51core::inst_anl_addr_Sdata(uchar code)
172 {
173   class cl_memory_cell *cell;
174   t_mem d;
175
176   cell= get_direct(fetch());
177   d= fetch();
178   cell->write(cell->read(HW_PORT) & d);
179   tick(1);
180   return(resGO);
181 }
182
183
184 /*
185  * 0x54 2 12 ANL A,#data
186  *____________________________________________________________________________
187  *
188  */
189
190 int
191 cl_51core::inst_anl_a_Sdata(uchar code)
192 {
193   uchar d;
194
195   d= acc->read();
196   acc->write(d & fetch());
197   return(resGO);
198 }
199
200
201 /*
202  * 0x55 2 12 ANL A,addr
203  *____________________________________________________________________________
204  *
205  */
206
207 int
208 cl_51core::inst_anl_a_addr(uchar code)
209 {
210   t_mem d;
211   class cl_memory_cell *cell;
212
213   cell= get_direct(fetch());
214   d= acc->read();
215   acc->write(d & cell->read());
216   return(resGO);
217 }
218
219
220 /*
221  * 0x56-0x57 1 12 ANL A,@Ri
222  *____________________________________________________________________________
223  *
224  */
225
226 int
227 cl_51core::inst_anl_a_Sri(uchar code)
228 {
229   t_mem d;
230   class cl_memory_cell *cell;
231
232   cell= iram->get_cell(get_reg(code & 0x01)->read());
233   d= acc->read();
234   acc->write(d & cell->read());
235   return(resGO);
236 }
237
238
239 /*
240  * 0x58-0x5f 1 12 ANL A,Rn
241  *____________________________________________________________________________
242  *
243  */
244
245 int
246 cl_51core::inst_anl_a_rn(uchar code)
247 {
248   uchar d;
249
250   d= acc->read();
251   acc->write(d & get_reg(code & 0x07)->read());
252   return(resGO);
253 }
254
255
256 /*
257  * 0x62 2 12 XRL addr,A
258  *____________________________________________________________________________
259  *
260  */
261
262 int
263 cl_51core::inst_xrl_addr_a(uchar code)
264 {
265   class cl_memory_cell *cell;
266
267   cell= get_direct(fetch());
268   cell->write(cell->read(HW_PORT) ^ acc->read());
269   return(resGO);
270 }
271
272
273 /*
274  * 0x63 3 24 XRL addr,#data
275  *____________________________________________________________________________
276  *
277  */
278
279 int
280 cl_51core::inst_xrl_addr_Sdata(uchar code)
281 {
282   class cl_memory_cell *cell;
283
284   cell= get_direct(fetch());
285   cell->write(cell->read(HW_PORT) ^ fetch());
286   tick(1);
287   return(resGO);
288 }
289
290
291 /*
292  * 0x64 2 12 XRL A,#data
293  *____________________________________________________________________________
294  *
295  */
296
297 int
298 cl_51core::inst_xrl_a_Sdata(uchar code)
299 {
300   uchar d;
301
302   d= acc->read();
303   acc->write(d ^ fetch());
304   return(resGO);
305 }
306
307
308 /*
309  * 0x65 2 12 XRL A,addr
310  *____________________________________________________________________________
311  *
312  */
313
314 int
315 cl_51core::inst_xrl_a_addr(uchar code)
316 {
317   t_mem d;
318   class cl_memory_cell *cell;
319
320   cell= get_direct(fetch());
321   d= acc->read();
322   acc->write(d ^ cell->read());
323   return(resGO);
324 }
325
326
327 /*
328  * 0x66-0x67 1 12 XRL A,@Ri
329  *____________________________________________________________________________
330  *
331  */
332
333 int
334 cl_51core::inst_xrl_a_Sri(uchar code)
335 {
336   t_mem d;
337   class cl_memory_cell *cell;
338
339   cell= iram->get_cell(get_reg(code & 0x01)->read());
340   d= acc->read();
341   acc->write(d ^ cell->read());
342   return(resGO);
343 }
344
345
346 /*
347  * 0x68-0x6f 1 12 XRL A,Rn
348  *____________________________________________________________________________
349  *
350  */
351
352 int
353 cl_51core::inst_xrl_a_rn(uchar code)
354 {
355   t_mem d;
356
357   d= acc->read();
358   acc->write(d ^ get_reg(code & 0x07)->read());
359   return(resGO);
360 }
361
362
363 /*
364  * 0xf4 1 12 CPL A
365  *____________________________________________________________________________
366  *
367  */
368
369 int
370 cl_51core::inst_cpl_a(uchar code)
371 {
372   acc->write(~(acc->read()));
373   return(resGO);
374 }
375
376
377 /* End of s51.src/logic.cc */