2b6cf83e4620a5d22651a8490197ee2306b83c6b
[fw/sdcc] / 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 t_uc51::inst_orl_c_bit(uchar code)
44 {
45   uchar bitaddr;
46
47   t_addr a;
48   t_mem m;
49   class cl_mem *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 t_uc51::inst_anl_c_bit(uchar code)
66 {
67   t_mem m;
68   t_addr a;
69   class cl_mem *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 t_uc51::inst_mov_bit_c(uchar code)
87 {
88   t_addr a;
89   t_mem m, d;
90   class cl_mem *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 t_uc51::inst_mov_c_bit(uchar code)
111 {
112   t_addr a;
113   t_mem m;
114   class cl_mem *mem;
115
116   mem= bit2mem(fetch(), &a, &m);
117   SFR_SET_C(mem->read(a) & m);
118   return(resGO);
119 }
120
121
122 /*
123  * 0xb0 2 24 ANL C,/bit
124  *____________________________________________________________________________
125  *
126  */
127
128 int
129 t_uc51::inst_anl_c_Sbit(uchar code)
130 {
131   t_mem m;
132   t_addr a;
133   class cl_mem *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  * 0xb2 2 12 CPL bit
145  *____________________________________________________________________________
146  *
147  */
148
149 int
150 t_uc51::inst_cpl_bit(uchar code)
151 {
152   t_addr a;
153   t_mem m, d;
154   class cl_mem *mem;
155
156   mem= bit2mem(fetch(), &a, &m);
157   d= mem->read(a, HW_PORT);
158   mem->write(a, d^m);
159   return(resGO);
160 }
161
162
163 /*
164  * 0xb3 1 12 CPL C
165  *____________________________________________________________________________
166  *
167  */
168
169 int
170 t_uc51::inst_cpl_c(uchar code)
171 {
172   psw->write(psw->read() ^ bmCY);
173   return(resGO);
174 }
175
176
177 /*
178  * 0xc2 2 12 CLR bit
179  *____________________________________________________________________________
180  *
181  */
182
183 int
184 t_uc51::inst_clr_bit(uchar code)
185 {
186   t_addr a;
187   t_mem m;
188   class cl_mem *mem;
189
190   mem= bit2mem(fetch(), &a, &m);
191   t_mem d= mem->read(a, HW_PORT);
192   mem->write(a, d&~m);
193   return(resGO);
194 }
195
196
197 /*
198  * 0xc3 1 12 CLR C
199  *____________________________________________________________________________
200  *
201  */
202
203 int
204 t_uc51::inst_clr_c(uchar code)
205 {
206   psw->write(psw->read() & ~bmCY);
207   return(resGO);
208 }
209
210
211 /*
212  * 0xd2 2 12 SETB bit
213  *____________________________________________________________________________
214  *
215  */
216
217 int
218 t_uc51::inst_setb_bit(uchar code)
219 {
220   t_addr a;
221   t_mem m, d;
222   class cl_mem *mem;
223
224   mem= bit2mem(fetch(), &a, &m);
225   d= mem->read(a, HW_PORT);
226   mem->write(a, d|m);
227   return(resGO);
228 }
229
230
231 /*
232  * 0xd3 1 12 SETB C
233  *____________________________________________________________________________
234  *
235  */
236
237 int
238 t_uc51::inst_setb_c(uchar code)
239 {
240   psw->write(psw->read() | bmCY);
241   return(resGO);
242 }
243
244
245 /* End of s51.src/bit.cc */