2 * Simulator of microcontrollers (hw.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
38 *____________________________________________________________________________
41 cl_watched_cell::cl_watched_cell(class cl_mem *amem, t_addr aaddr,
42 class cl_cell **astore,
43 enum what_to_do_on_cell_change awtd)
51 cell= mem->get_cell(addr);
58 cl_watched_cell::mem_cell_changed(class cl_mem *amem, t_addr aaddr,
65 cell= mem->get_cell(addr);
78 cl_used_cell::mem_cell_changed(class cl_mem *amem, t_addr aaddr,
85 cell= mem->get_cell(addr);
99 *____________________________________________________________________________
102 cl_hw::cl_hw(class cl_uc *auc, enum hw_cath cath, int aid, char *aid_string):
111 id_string= strdup(aid_string);
113 id_string= strdup("unknown hw element");
114 partners= new cl_list(2, 2);
115 watched_cells= new cl_list(2, 2);
121 //hws_to_inform->disconn_all();
123 delete watched_cells;
128 cl_hw::new_hw_adding(class cl_hw *new_hw)
133 cl_hw::new_hw_added(class cl_hw *new_hw)
137 for (i= 0; i < partners->count; i++)
139 class cl_partner_hw *ph= (class cl_partner_hw *)(partners->at(i));
145 cl_hw::make_partner(enum hw_cath cath, int id)
147 class cl_partner_hw *ph;
150 ph= new cl_partner_hw(uc, cath, id);
152 hw= ph->get_partner();
158 * Callback functions for changing memory locations
162 cl_hw::read(class cl_mem *mem, t_addr addr)
164 // Simply return the value
165 return(mem->get(addr));
169 cl_hw::write(class cl_mem *mem, t_addr addr, t_mem *val)
171 // Do not change *val by default
176 cl_hw::register_cell(class cl_mem *mem, t_addr addr, class cl_cell **store,
177 enum what_to_do_on_cell_change awtd)
179 class cl_watched_cell *wc;
183 mem->register_hw(addr, this, (int*)0, DD_FALSE);
184 wc= new cl_watched_cell(mem, addr, &cell, awtd);
187 watched_cells->add(wc);
189 uc->sim->mem_cell_changed(mem, addr);
194 cl_hw::use_cell(class cl_mem *mem, t_addr addr, class cl_cell **store,
195 enum what_to_do_on_cell_change awtd)
197 class cl_watched_cell *wc;
200 wc= new cl_used_cell(mem, addr, &cell, awtd);
203 watched_cells->add(wc);
208 cl_hw::mem_cell_changed(class cl_mem *mem, t_addr addr)
212 for (i= 0; i < watched_cells->count; i++)
214 class cl_watched_cell *wc=
215 (class cl_watched_cell *)(watched_cells->at(i));
216 wc->mem_cell_changed(mem, addr, this);
222 * Simulating `cycles' number of machine cycle
226 cl_hw::tick(int cycles)
232 cl_hw::inform_partners(enum hw_event he, void *params)
236 for (i= 0; i < partners->count; i++)
238 class cl_partner_hw *ph= (class cl_partner_hw *)(partners->at(i));
239 ph->happen(this, he, params);
245 cl_hw::print_info(class cl_console *con)
247 con->dd_printf("%s[%d]\n", id_string, id);
252 cl_hws::add(void *item)
258 for (i= 0; i < count; i++)
260 class cl_hw *hw= (class cl_hw *)(at(i));
261 hw->new_hw_adding((class cl_hw *)item);
264 res= cl_list::add(item);
266 for (i= 0; i < count; i++)
268 class cl_hw *hw= (class cl_hw *)(at(i));
269 hw->new_hw_added((class cl_hw *)item);
271 ((class cl_hw *)item)->added_to_uc();
277 cl_hws::mem_cell_changed(class cl_mem *mem, t_addr addr)
281 for (i= 0; i < count; i++)
283 class cl_hw *hw= (class cl_hw *)(at(i));
284 hw->mem_cell_changed(mem, addr);
290 *____________________________________________________________________________
293 cl_partner_hw::cl_partner_hw(class cl_uc *auc, enum hw_cath cath, int aid):
299 partner= uc->get_hw(cathegory, id, 0);
303 cl_partner_hw::get_partner(void)
309 cl_partner_hw::refresh(void)
311 class cl_hw *hw= uc->get_hw(cathegory, id, 0);
317 // partner is already set
330 cl_partner_hw::refresh(class cl_hw *new_hw)
334 if (cathegory == new_hw->cathegory &&
348 cl_partner_hw::happen(class cl_hw *where, enum hw_event he, void *params)
351 partner->happen(where, he, params);