Imported Upstream version 2.9.0
[debian/cc1111] / sim / ucsim / s51.src / uc89c51r.cc
1 /*
2  * Simulator of microcontrollers (uc89c51r.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 #include <stdio.h>
31 #include <ctype.h>
32
33 // local
34 #include "uc89c51rcl.h"
35 #include "regs51.h"
36 #include "pcacl.h"
37 #include "wdtcl.h"
38
39
40 cl_uc89c51r::cl_uc89c51r(int Itype, int Itech, class cl_sim *asim):
41   cl_uc51r(Itype, Itech, asim)
42 {
43 }
44
45
46 void
47 cl_uc89c51r::mk_hw_elements(void)
48 {
49   class cl_hw *h;
50
51   cl_uc52::mk_hw_elements();
52   hws->add(h= new cl_wdt(this, 0x3fff));
53   h->init();
54   hws->add(h= new cl_pca(this, 0));
55   h->init();
56   hws->add(h= new cl_89c51r_dummy_hw(this));
57   h->init();
58 }
59
60 void
61 cl_uc89c51r::make_memories(void)
62 {
63   cl_uc52::make_memories();
64 }
65
66
67 void
68 cl_uc89c51r::reset(void)
69 {
70   cl_uc51r::reset();
71   sfr->set_bit1(CCAPM0, bmECOM);
72   sfr->set_bit1(CCAPM1, bmECOM);
73   sfr->set_bit1(CCAPM2, bmECOM);
74   sfr->set_bit1(CCAPM3, bmECOM);
75   sfr->set_bit1(CCAPM4, bmECOM);
76   //t0_overflows= 0;
77   dpl0= dph0= dpl1= dph1= 0;
78   sfr->write(IPH, 0);
79 }
80
81 int
82 cl_uc89c51r::it_priority(uchar ie_mask)
83 {
84   uchar l, h;
85
86   l= sfr->get(IP) & ie_mask;
87   h= sfr->get(IPH) & ie_mask;
88   if (!h && !l)
89     return(0);
90   if (!h && l)
91     return(1);
92   if (h && !l)
93     return(2);
94   if (h && l)
95     return(3);
96   return(0);
97 }
98
99 void
100 cl_uc89c51r::pre_inst(void)
101 {
102   //printf("pre dptr0:%02X%02X dptr1:%02X%02X\n", dph0, dpl0, dph1, dpl1);
103   dps = (sfr->get(AUXR1) & bmDPS);
104   if (dps)
105     {
106       sfr->set(DPL, dpl1);
107       sfr->set(DPH, dph1);
108     }
109   else
110     {
111       sfr->set(DPL, dpl0);
112       sfr->set(DPH, dph0);
113     }
114   cl_uc51r::pre_inst();
115 }
116
117 void
118 cl_uc89c51r::post_inst(void)
119 {
120   if (dps)
121     {
122       dpl1= sfr->get(DPL);
123       dph1= sfr->get(DPH);
124     }
125   else
126     {
127       dpl0= sfr->get(DPL);
128       dph0= sfr->get(DPH);
129     }
130   dps = (sfr->get(AUXR1) & bmDPS);
131   if (dps)
132     {
133       sfr->set(DPL, dpl1);
134       sfr->set(DPH, dph1);
135     }
136   else
137     {
138       sfr->set(DPL, dpl0);
139       sfr->set(DPH, dph0);
140     }
141   //printf("post dptr0:%02X%02X dptr1:%02X%02X\n", dph0, dpl0, dph1, dpl1);
142   cl_uc51r::post_inst();
143 }
144
145
146 void
147 cl_uc89c51r::print_regs(class cl_console_base *con)
148 {
149   t_addr start;
150   uchar data, acc, dps;
151
152   start= psw->get() & 0x18;
153   //dump_memory(iram, &start, start+7, 8, /*sim->cmd_out()*/con, sim);
154   iram->dump(start, start+7, 8, con);
155   start= psw->get() & 0x18;
156   data= iram->get(iram->get(start));
157   con->dd_printf("%06x %02x %c",
158               iram->get(start), data, isprint(data)?data:'.');
159
160   acc= sfr->get(ACC);
161   con->dd_printf("  ACC= 0x%02x %3d %c  B= 0x%02x", acc, acc,
162               isprint(acc)?(acc):'.', sfr->get(B)); 
163   //eram2xram();
164   dps = sfr->get(AUXR1) & bmDPS;
165   data= xram->get(dph0*256+dpl0);
166   con->dd_printf("  %cDPTR0= 0x%02x%02x @DPTR0= 0x%02x %3d %c",
167               dps?' ':'*', dph0, dpl0,
168               data, data, isprint(data)?data:'.');
169   data= xram->get(dph1*256+dpl1);
170   con->dd_printf("  %cDPTR1= 0x%02x%02x @DPTR1= 0x%02x %3d %c\n",
171               dps?'*':' ', dph1, dpl1,
172               data, data, isprint(data)?data:'.');
173
174   data= iram->get(iram->get(start+1));
175   con->dd_printf("%06x %02x %c", iram->get(start+1), data,
176               isprint(data)?data:'.');
177   data= psw->get();
178   con->dd_printf("  PSW= 0x%02x CY=%c AC=%c OV=%c P=%c\n", data,
179               (data&bmCY)?'1':'0', (data&bmAC)?'1':'0',
180               (data&bmOV)?'1':'0', (data&bmP)?'1':'0');
181
182   print_disass(PC, con);
183 }
184
185
186 /*
187  */
188
189 cl_89c51r_dummy_hw::cl_89c51r_dummy_hw(class cl_uc *auc):
190   cl_hw(auc, HW_DUMMY, 0, "_89c51r_dummy")
191 {}
192
193 int
194 cl_89c51r_dummy_hw::init(void)
195 {
196   class cl_address_space *sfr= uc->address_space(MEM_SFR_ID);
197   if (!sfr)
198     {
199       fprintf(stderr, "No SFR to register %s[%d] into\n", id_string, id);
200     }
201   //auxr= sfr->register_hw(AUXR, this, 0);
202   register_cell(sfr, AUXR1, &auxr1, wtd_restore);
203   return(0);
204 }
205
206 void
207 cl_89c51r_dummy_hw::write(class cl_memory_cell *cell, t_mem *val)
208 {
209   if (cell == auxr1)
210     auxr1->set_bit0(0x04);
211 }
212
213
214 /* End of s51.src/uc89c51r.cc */