32e936b909e4d8a653edddd84c92903a6ba6f4e4
[fw/sdcc] / 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 t_uc51::inst_orl_addr_a(uchar code)
46 {
47   uchar *addr;
48
49   addr= get_direct(fetch(), &event_at.wi, &event_at.ws);
50   (*addr)|= sfr->get(event_at.rs= ACC);
51   proc_write(addr);
52   return(resGO);
53 }
54
55
56 /*
57  * 0x43 3 24 ORL addr,#data
58  *____________________________________________________________________________
59  *
60  */
61
62 int
63 t_uc51::inst_orl_addr_$data(uchar code)
64 {
65   uchar *addr;
66
67   addr= get_direct(fetch(), &event_at.wi, &event_at.ws);
68   (*addr)|= fetch();
69   proc_write(addr);
70   tick(1);
71   return(resGO);
72 }
73
74
75 /*
76  * 0x44 2 12 ORL A,#data
77  *____________________________________________________________________________
78  *
79  */
80
81 int
82 t_uc51::inst_orl_a_$data(uchar code)
83 {
84   uchar d;
85
86   d= sfr->get(event_at.ws= ACC);
87   sfr->set(ACC, d|= fetch());
88   return(resGO);
89 }
90
91
92 /*
93  * 0x45 2 12 ORL A,addr
94  *____________________________________________________________________________
95  *
96  */
97
98 int
99 t_uc51::inst_orl_a_addr(uchar code)
100 {
101   uchar *addr, d;
102
103   addr= get_direct(fetch(), &event_at.ri, &event_at.rs);
104   d= sfr->get(event_at.ws= ACC);
105   sfr->set(ACC, d|= read(addr));
106   return(resGO);
107 }
108
109
110 /*
111  * 0x46-0x47 1 12 ORL A,@Ri
112  *____________________________________________________________________________
113  *
114  */
115
116 int
117 t_uc51::inst_orl_a_$ri(uchar code)
118 {
119   uchar *addr, d;
120   int res;
121
122   addr= get_indirect(event_at.ri= *(get_reg(code & 0x01)), &res);
123   d= sfr->get(event_at.ws= ACC);
124   sfr->set(ACC, d|= *addr);
125   return(res);
126 }
127
128
129 /*
130  * 0x48-0x4f 1 12 ORL A,Rn
131  *____________________________________________________________________________
132  *
133  */
134
135 int
136 t_uc51::inst_orl_a_rn(uchar code)
137 {
138   uchar d;
139
140   d= sfr->get(event_at.ws= ACC);
141   sfr->set(ACC, d|= *(get_reg(code & 0x07, &event_at.ri)));
142   return(resGO);
143 }
144
145
146 /*
147  * 0x52 2 12 ANL addr,A
148  *____________________________________________________________________________
149  *
150  */
151
152 int
153 t_uc51::inst_anl_addr_a(uchar code)
154 {
155   uchar *addr;
156
157   addr= get_direct(fetch(), &event_at.wi, &event_at.ws);
158   (*addr)&= sfr->get(event_at.rs= ACC);
159   proc_write(addr);
160   return(resGO);
161 }
162
163
164 /*
165  * 0x53 3 24 ANL addr,#data
166  *____________________________________________________________________________
167  *
168  */
169
170 int
171 t_uc51::inst_anl_addr_$data(uchar code)
172 {
173   uchar *addr;
174
175   addr= get_direct(fetch(), &event_at.wi, &event_at.ws);
176   (*addr)&= fetch();
177   proc_write(addr);
178   tick(1);
179   return(resGO);
180 }
181
182
183 /*
184  * 0x54 2 12 ANL A,#data
185  *____________________________________________________________________________
186  *
187  */
188
189 int
190 t_uc51::inst_anl_a_$data(uchar code)
191 {
192   uchar d;
193
194   d= sfr->get(event_at.ws= ACC);
195   sfr->set(ACC, d&= fetch());
196   return(resGO);
197 }
198
199
200 /*
201  * 0x55 2 12 ANL A,addr
202  *____________________________________________________________________________
203  *
204  */
205
206 int
207 t_uc51::inst_anl_a_addr(uchar code)
208 {
209   uchar *addr, d;
210
211   addr= get_direct(fetch(), &event_at.ri, &event_at.rs);
212   d= sfr->get(event_at.ws= ACC);
213   sfr->set(ACC, d&= read(addr));
214   return(resGO);
215 }
216
217
218 /*
219  * 0x56-0x57 1 12 ANL A,@Ri
220  *____________________________________________________________________________
221  *
222  */
223
224 int
225 t_uc51::inst_anl_a_$ri(uchar code)
226 {
227   uchar *addr, d;
228   int res;
229
230   addr= get_indirect(event_at.ri= *(get_reg(code & 0x01)), &res);
231   d= sfr->get(event_at.ws= ACC);
232   sfr->set(ACC, d&= *addr);
233   return(res);
234 }
235
236
237 /*
238  * 0x58-0x5f 1 12 ANL A,Rn
239  *____________________________________________________________________________
240  *
241  */
242
243 int
244 t_uc51::inst_anl_a_rn(uchar code)
245 {
246   uchar d;
247
248   d= sfr->get(event_at.ws= ACC);
249   sfr->set(ACC, d&= *(get_reg(code & 0x07, &event_at.ri)));
250   return(resGO);
251 }
252
253
254 /*
255  * 0x62 2 12 XRL addr,A
256  *____________________________________________________________________________
257  *
258  */
259
260 int
261 t_uc51::inst_xrl_addr_a(uchar code)
262 {
263   uchar *addr;
264
265   addr= get_direct(fetch(), &event_at.wi, &event_at.ws);
266   (*addr)^= sfr->get(event_at.rs= ACC);
267   proc_write(addr);
268   return(resGO);
269 }
270
271
272 /*
273  * 0x63 3 24 XRL addr,#data
274  *____________________________________________________________________________
275  *
276  */
277
278 int
279 t_uc51::inst_xrl_addr_$data(uchar code)
280 {
281   uchar *addr;
282
283   addr= get_direct(fetch(), &event_at.wi, &event_at.ws);
284   (*addr)^= fetch();
285   proc_write(addr);
286   tick(1);
287   return(resGO);
288 }
289
290
291 /*
292  * 0x64 2 12 XRL A,#data
293  *____________________________________________________________________________
294  *
295  */
296
297 int
298 t_uc51::inst_xrl_a_$data(uchar code)
299 {
300   uchar d;
301
302   d= sfr->get(event_at.ws= ACC);
303   sfr->set(ACC, d^= fetch());
304   return(resGO);
305 }
306
307
308 /*
309  * 0x65 2 12 XRL A,addr
310  *____________________________________________________________________________
311  *
312  */
313
314 int
315 t_uc51::inst_xrl_a_addr(uchar code)
316 {
317   uchar d;
318
319   d= sfr->get(event_at.ws= ACC);
320   sfr->set(ACC, d^= read(get_direct(fetch(),
321                                     &event_at.ri,
322                                     &event_at.ri)));
323   return(resGO);
324 }
325
326
327 /*
328  * 0x66-0x67 1 12 XRL A,@Ri
329  *____________________________________________________________________________
330  *
331  */
332
333 int
334 t_uc51::inst_xrl_a_$ri(uchar code)
335 {
336   uchar *addr, d;
337   int res;
338
339   addr= get_indirect(event_at.ri= *(get_reg(code & 0x01)), &res);
340   d= sfr->get(event_at.ws= ACC);
341   sfr->set(ACC, d^= *addr);
342   return(res);
343 }
344
345
346 /*
347  * 0x68-0x6f 1 12 XRL A,Rn
348  *____________________________________________________________________________
349  *
350  */
351
352 int
353 t_uc51::inst_xrl_a_rn(uchar code)
354 {
355   uchar d;
356
357   d= sfr->get(event_at.ws= ACC);
358   sfr->set(ACC, d^= *(get_reg(code & 0x07, &event_at.ri)));
359   return(resGO);
360 }
361
362
363 /*
364  * 0xf4 1 12 CPL A
365  *____________________________________________________________________________
366  *
367  */
368
369 int
370 t_uc51::inst_cpl_a(uchar code)
371 {
372   sfr->set(event_at.ws= ACC, ~(sfr->get(ACC)));
373   return(resGO);
374 }
375
376
377 /* End of s51.src/logic.cc */