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