2 * Simulator of microcontrollers (uc51r.cc)
4 * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
6 * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
10 /* This file is part of microcontroller simulator: ucsim.
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.
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.
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
40 * Making an 8051r CPU object
43 cl_uc51r::cl_uc51r(int Itype, int Itech, class cl_sim *asim):
44 cl_uc52(Itype, Itech, asim)
47 for (i= 0; i < ERAM_SIZE; i++)
54 cl_uc51r::mk_hw_elements(void)
58 cl_uc52::mk_hw_elements();
59 hws->add(h= new cl_wdt(this, 0x3fff));
61 hws->add(h= new cl_uc51r_dummy_hw(this));
67 cl_uc51r::make_memories(void)
69 class cl_address_space *as;
71 rom= as= new cl_address_space("rom", 0, 0x10000, 8);
73 address_spaces->add(as);
74 iram= as= new cl_address_space("iram", 0, 0x100, 8);
76 address_spaces->add(as);
77 sfr= as= new cl_address_space("sfr", 0x80, 0x80, 8);
79 address_spaces->add(as);
80 xram= as= new cl_address_space("xram", 0, 0x10000, 8);
82 address_spaces->add(as);
84 class cl_address_decoder *ad;
85 class cl_memory_chip *chip;
87 chip= new cl_memory_chip("rom_chip", 0x10000, 8);
90 ad= new cl_address_decoder(as= address_space("rom"), chip, 0, 0xffff, 0);
92 as->decoders->add(ad);
95 chip= new cl_memory_chip("iram_chip", 0x100, 8);
98 ad= new cl_address_decoder(as= address_space("iram"), chip, 0, 0xff, 0);
100 as->decoders->add(ad);
103 chip= new cl_memory_chip("xram_chip", 0x10000, 8);
106 ad= new cl_address_decoder(as= address_space("xram"), chip, 0, 0xffff, 0);
108 as->decoders->add(ad);
110 chip= new cl_memory_chip("eram_chip", 0x100, 8);
114 chip= new cl_memory_chip("sfr_chip", 0x80, 8);
117 ad= new cl_address_decoder(as= address_space("sfr"), chip, 0x80, 0xff, 0);
119 as->decoders->add(ad);
122 acc= sfr->get_cell(ACC);
123 psw= sfr->get_cell(PSW);
128 * Resetting of the microcontroller
130 * Original method is extended with handling of WDT.
134 cl_uc51r::reset(void)
137 sfr->write(SADDR, 0);
138 sfr->write(SADEN, 0);
143 cl_uc51r::clear_sfr(void)
145 cl_uc52::clear_sfr();
146 sfr->write(SADDR, 0);
147 sfr->write(SADEN, 0);
154 cl_uc51r::received(int c)
156 t_mem br= sfr->get(SADDR) | sfr->get(SADEN);
157 int scon= sfr->get(SCON);
159 if ((0 < scon >> 6) &&
162 if (/* Check for individual address */
163 ((sfr->get(SADDR) & sfr->get(SADEN)) == (c & sfr->get(SADEN)))
165 /* Check for broadcast address */
167 sfr->set_bit1(SCON, bmRI);
170 sfr->set_bit1(SCON, bmRI);
177 cl_uc51r_dummy_hw::cl_uc51r_dummy_hw(class cl_uc *auc):
178 cl_hw(auc, HW_DUMMY, 0, "_51r_dummy")
182 cl_uc51r_dummy_hw::init(void)
184 class cl_address_space *sfr= uc->address_space(MEM_SFR_ID);
187 fprintf(stderr, "No SFR to register %s[%d] into\n", id_string, id);
189 //use_cell(sfr, PSW, &cell_psw, wtd_restore);
190 register_cell(sfr, AUXR, &cell_auxr, wtd_restore);
195 cl_uc51r_dummy_hw::write(class cl_memory_cell *cell, t_mem *val)
197 if (cell == cell_auxr)
199 class cl_address_space *xram= uc->address_space(MEM_XRAM_ID);
200 class cl_memory_chip *eram=
201 dynamic_cast<class cl_memory_chip *>(uc->memory("eram_chip"));
202 class cl_address_decoder *d;
207 d= new cl_address_decoder(xram, uc->memory("xram_chip"), 0,0xff,0);
209 d= new cl_address_decoder(xram, eram, 0, 0xff, 0);
211 xram->decoders->add(d);
215 /*else if (cell == cell_pcon)
217 printf("PCON write 0x%x (PC=0x%x)\n", *val, uc->PC);
223 cl_uc51r_dummy_hw::happen(class cl_hw *where, enum hw_event he, void *params)
225 struct ev_port_changed *ep= (struct ev_port_changed *)params;
227 if (where->cathegory == HW_PORT &&
228 he == EV_PORT_CHANGED &&
231 t_mem p3o= ep->pins & ep->prev_value;
232 t_mem p3n= ep->new_pins & ep->new_value;
233 if ((p3o & bm_INT0) &&
235 uc51->p3_int0_edge++;
236 if ((p3o & bm_INT1) &&
238 uc51->p3_int1_edge++;
243 /* End of s51.src/uc51r.cc */