7a137da499c7b8519fcce8a33ee85f565e7c5ca1
[fw/sdcc] / 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
32 // local
33 #include "uc89c51rcl.h"
34 #include "regs51.h"
35 #include "pcacl.h"
36
37
38 t_uc89c51r::t_uc89c51r(int Itype, int Itech, class cl_sim *asim):
39   t_uc51r(Itype, Itech, asim)
40 {
41   /*it_sources->add_at(4, new cl_it_src(bmEC, CCON, bmCCF4, 0x0033, false,
42                                       "PCA module #4"));
43   it_sources->add_at(4, new cl_it_src(bmEC, CCON, bmCCF3, 0x0033, false,
44                                       "PCA module #3"));
45   it_sources->add_at(4, new cl_it_src(bmEC, CCON, bmCCF2, 0x0033, false,
46                                       "PCA module #2"));
47   it_sources->add_at(4, new cl_it_src(bmEC, CCON, bmCCF1, 0x0033, false,
48                                       "PCA module #1"));
49   it_sources->add_at(4, new cl_it_src(bmEC, CCON, bmCCF0, 0x0033, false,
50                                       "PCA module #0"));
51   it_sources->add_at(4, new cl_it_src(bmEC, CCON, bmCF, 0x0033, false,
52   "PCA counter"));*/
53 }
54
55
56 void
57 t_uc89c51r::mk_hw_elements(void)
58 {
59   class cl_hw *h;
60
61   t_uc51r::mk_hw_elements();
62   hws->add(h= new cl_pca(this, 0));
63   h->init();
64   /*hws->add(h= new cl_pca(this, 1));
65   h->init();
66   hws->add(h= new cl_pca(this, 2));
67   h->init();
68   hws->add(h= new cl_pca(this, 3));
69   h->init();
70   hws->add(h= new cl_pca(this, 4));
71   h->init();*/
72   hws->add(h= new cl_89c51r_dummy_hw(this));
73   h->init();
74 }
75
76
77 void
78 t_uc89c51r::reset(void)
79 {
80   t_uc51r::reset();
81   sfr->set_bit1(CCAPM0, bmECOM);
82   sfr->set_bit1(CCAPM1, bmECOM);
83   sfr->set_bit1(CCAPM2, bmECOM);
84   sfr->set_bit1(CCAPM3, bmECOM);
85   sfr->set_bit1(CCAPM4, bmECOM);
86   //t0_overflows= 0;
87   dpl0= dph0= dpl1= dph1= 0;
88   sfr->set(IPH, 0);
89 }
90
91 int
92 t_uc89c51r::it_priority(uchar ie_mask)
93 {
94   uchar l, h;
95
96   l= sfr->get(IP) & ie_mask;
97   h= sfr->get(IPH) & ie_mask;
98   if (!h && !l)
99     return(0);
100   if (!h && l)
101     return(1);
102   if (h && !l)
103     return(2);
104   if (h && l)
105     return(3);
106   return(0);
107 }
108
109 void
110 t_uc89c51r::pre_inst(void)
111 {
112   if (sfr->get(AUXR1) & bmDPS)
113     {
114       sfr->set(DPL, dpl1);
115       sfr->set(DPH, dph1);
116     }
117   else
118     {
119       sfr->set(DPL, dpl0);
120       sfr->set(DPH, dph0);
121     }
122   t_uc51r::pre_inst();
123 }
124
125 void
126 t_uc89c51r::post_inst(void)
127 {
128   if (sfr->get(AUXR1) & bmDPS)
129     {
130       dpl1= sfr->get(DPL);
131       dph1= sfr->get(DPH);
132     }
133   else
134     {
135       dpl0= sfr->get(DPL);
136       dph0= sfr->get(DPH);
137     }
138   t_uc51r::post_inst();
139 }
140
141
142 /*
143  */
144
145 cl_89c51r_dummy_hw::cl_89c51r_dummy_hw(class cl_uc *auc):
146   cl_hw(auc, HW_DUMMY, 0, "_89c51r_dummy")
147 {}
148
149 int
150 cl_89c51r_dummy_hw::init(void)
151 {
152   class cl_mem *sfr= uc->mem(MEM_SFR);
153   if (!sfr)
154     {
155       fprintf(stderr, "No SFR to register %s[%d] into\n", id_string, id);
156     }
157   //auxr= sfr->register_hw(AUXR, this, 0);
158   register_cell(sfr, AUXR, &auxr, wtd_restore);
159   return(0);
160 }
161
162 void
163 cl_89c51r_dummy_hw::write(class cl_cell *cell, t_mem *val)
164 {
165   if (cell == auxr)
166     auxr->set_bit0(0x04);
167 }
168
169
170 /* End of s51.src/uc89c51r.cc */