Imported Upstream version 2.9.0
[debian/cc1111] / sim / ucsim / s51.src / bit.cc
1 /*
2  * Simulator of microcontrollers (bit.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 // local
31 #include "uc51cl.h"
32 #include "regs51.h"
33 #include "types51.h"
34
35
36 /*
37  * 0x72 2 24 ORL C,bit
38  *____________________________________________________________________________
39  *
40  */
41
42 int
43 cl_51core::inst_orl_c_bit(uchar code)
44 {
45   uchar bitaddr;
46
47   t_addr a;
48   t_mem m;
49   class cl_address_space *mem;
50   mem= bit2mem(bitaddr= fetch(), &a, &m);
51   SFR_SET_C(SFR_GET_C ||
52             (mem->read(a) & m));
53   tick(1);
54   return(resGO);
55 }
56
57
58 /*
59  * 0x82 2 24 ANL C,bit
60  *____________________________________________________________________________
61  *
62  */
63
64 int
65 cl_51core::inst_anl_c_bit(uchar code)
66 {
67   t_mem m;
68   t_addr a;
69   class cl_address_space *mem;
70
71   mem= bit2mem(fetch(), &a, &m);
72   SFR_SET_C(SFR_GET_C &&
73             (mem->read(a) & m));
74   tick(1);
75   return(resGO);
76 }
77
78
79 /*
80  * 0x92 2 24 MOV bit,C
81  *____________________________________________________________________________
82  *
83  */
84
85 int
86 cl_51core::inst_mov_bit_c(uchar code)
87 {
88   t_addr a;
89   t_mem m, d;
90   class cl_address_space *mem;
91
92   mem= bit2mem(fetch(), &a, &m);
93   d= mem->read(a, HW_PORT);
94   if (SFR_GET_C)
95     mem->write(a, d|m);
96   else
97     mem->write(a, d&~m);
98   tick(1);
99   return(resGO);
100 }
101
102
103 /*
104  * 0xa2 2 12 MOV C,bit
105  *____________________________________________________________________________
106  *
107  */
108
109 int
110 cl_51core::inst_mov_c_bit(uchar code)
111 {
112   t_addr a;
113   t_mem m;
114   class cl_address_space *mem;
115
116   mem= bit2mem(fetch(), &a, &m);
117   SFR_SET_C(mem->read(a) & m);
118   return(resGO);
119 }
120
121
122 /*
123  * 0xa0 2 24 ORL C,/bit
124  *____________________________________________________________________________
125  *
126  */
127
128 int
129 cl_51core::inst_orl_c_Sbit(uchar code)
130 {
131   t_mem m;
132   t_addr a;
133   class cl_address_space *mem;
134
135   mem= bit2mem(fetch(), &a, &m);
136   SFR_SET_C(SFR_GET_C ||
137             !(mem->read(a) & m));
138   tick(1);
139   return(resGO);
140 }
141
142
143 /*
144  * 0xb0 2 24 ANL C,/bit
145  *____________________________________________________________________________
146  *
147  */
148
149 int
150 cl_51core::inst_anl_c_Sbit(uchar code)
151 {
152   t_mem m;
153   t_addr a;
154   class cl_address_space *mem;
155
156   mem= bit2mem(fetch(), &a, &m);
157   SFR_SET_C(SFR_GET_C &&
158             !(mem->read(a) & m));
159   tick(1);
160   return(resGO);
161 }
162
163
164 /*
165  * 0xb2 2 12 CPL bit
166  *____________________________________________________________________________
167  *
168  */
169
170 int
171 cl_51core::inst_cpl_bit(uchar code)
172 {
173   t_addr a;
174   t_mem m, d;
175   class cl_address_space *mem;
176
177   mem= bit2mem(fetch(), &a, &m);
178   d= mem->read(a, HW_PORT);
179   mem->write(a, d^m);
180   return(resGO);
181 }
182
183
184 /*
185  * 0xb3 1 12 CPL C
186  *____________________________________________________________________________
187  *
188  */
189
190 int
191 cl_51core::inst_cpl_c(uchar code)
192 {
193   psw->write(psw->read() ^ bmCY);
194   return(resGO);
195 }
196
197
198 /*
199  * 0xc2 2 12 CLR bit
200  *____________________________________________________________________________
201  *
202  */
203
204 int
205 cl_51core::inst_clr_bit(uchar code)
206 {
207   t_addr a;
208   t_mem m;
209   class cl_address_space *mem;
210
211   mem= bit2mem(fetch(), &a, &m);
212   t_mem d= mem->read(a, HW_PORT);
213   mem->write(a, d&~m);
214   return(resGO);
215 }
216
217
218 /*
219  * 0xc3 1 12 CLR C
220  *____________________________________________________________________________
221  *
222  */
223
224 int
225 cl_51core::inst_clr_c(uchar code)
226 {
227   psw->write(psw->read() & ~bmCY);
228   return(resGO);
229 }
230
231
232 /*
233  * 0xd2 2 12 SETB bit
234  *____________________________________________________________________________
235  *
236  */
237
238 int
239 cl_51core::inst_setb_bit(uchar code)
240 {
241   t_addr a;
242   t_mem m, d;
243   class cl_address_space *mem;
244
245   mem= bit2mem(fetch(), &a, &m);
246   d= mem->read(a, HW_PORT);
247   mem->write(a, d|m);
248   return(resGO);
249 }
250
251
252 /*
253  * 0xd3 1 12 SETB C
254  *____________________________________________________________________________
255  *
256  */
257
258 int
259 cl_51core::inst_setb_c(uchar code)
260 {
261   psw->write(psw->read() | bmCY);
262   return(resGO);
263 }
264
265
266 /* End of s51.src/bit.cc */