⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hw.cc

📁 Small Device C Compiler 面向Inter8051
💻 CC
字号:
/* * Simulator of microcontrollers (hw.cc) * * Copyright (C) 1999,99 Drotos Daniel, Talker Bt. *  * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu * *//* This file is part of microcontroller simulator: ucsim.UCSIM is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.UCSIM is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with UCSIM; see the file COPYING.  If not, write to the FreeSoftware Foundation, 59 Temple Place - Suite 330, Boston, MA02111-1307, USA. *//*@1@*/#include "ddconfig.h"#include <stdlib.h>#include "i_string.h"#include "stypes.h"#include "hwcl.h"/* *____________________________________________________________________________ */cl_watched_cell::cl_watched_cell(class cl_mem *amem, t_addr aaddr,				 class cl_cell **astore,				 enum what_to_do_on_cell_change awtd){  mem= amem;  addr= aaddr;  store= astore;  wtd= awtd;  if (mem)    {      cell= mem->get_cell(addr);      if (store)	*store= cell;    }}voidcl_watched_cell::mem_cell_changed(class cl_mem *amem, t_addr aaddr,				  class cl_hw *hw){  if (mem &&      mem == amem &&      addr == aaddr)    {      cell= mem->get_cell(addr);      if (store &&	  (wtd & WTD_RESTORE))	*store= cell;      if (wtd & WTD_WRITE)	{	  t_mem d= cell->get();	  hw->write(cell, &d);	}    }}/*voidcl_used_cell::mem_cell_changed(class cl_mem *amem, t_addr aaddr, class cl_hw *hw){  if (mem &&      mem == amem &&      addr == aaddr)    {      cell= mem->get_cell(addr);      if (store &&	  (wtd & WTD_RESTORE))	*store= cell;      if (wtd & WTD_WRITE)	{	  t_mem d= cell->get();	  hw->write(cell, &d);	}    }}*//* *____________________________________________________________________________ */cl_hw::cl_hw(class cl_uc *auc, enum hw_cath cath, int aid, char *aid_string):  cl_guiobj(){  flags= HWF_INSIDE;  uc= auc;  cathegory= cath;  id= aid;  if (aid_string &&      *aid_string)    id_string= strdup(aid_string);  else    id_string= strdup("unknown hw element");  partners= new cl_list(2, 2);  watched_cells= new cl_list(2, 2);}cl_hw::~cl_hw(void){  free(id_string);  //hws_to_inform->disconn_all();  delete partners;  delete watched_cells;}voidcl_hw::new_hw_adding(class cl_hw *new_hw){}voidcl_hw::new_hw_added(class cl_hw *new_hw){  int i;  for (i= 0; i < partners->count; i++)    {      class cl_partner_hw *ph= (class cl_partner_hw *)(partners->at(i));      ph->refresh(new_hw);    }}class cl_hw *cl_hw::make_partner(enum hw_cath cath, int id){  class cl_partner_hw *ph;  class cl_hw *hw;  ph= new cl_partner_hw(uc, cath, id);  partners->add(ph);  hw= ph->get_partner();  return(hw);}/* * Callback functions for changing memory locations *//*t_memcl_hw::read(class cl_mem *mem, t_addr addr){  // Simply return the value  return(mem->get(addr));}*//*voidcl_hw::write(class cl_mem *mem, t_addr addr, t_mem *val){  // Do not change *val by default}*/class cl_cell *cl_hw::register_cell(class cl_mem *mem, t_addr addr, class cl_cell **store,		     enum what_to_do_on_cell_change awtd){  class cl_watched_cell *wc;  class cl_cell *cell;  if (mem)    mem->register_hw(addr, this, (int*)0, DD_FALSE);  wc= new cl_watched_cell(mem, addr, &cell, awtd);  if (store)    *store= cell;  watched_cells->add(wc);  // announce  uc->sim->mem_cell_changed(mem, addr);  return(cell);}class cl_cell *cl_hw::use_cell(class cl_mem *mem, t_addr addr, class cl_cell **store,		enum what_to_do_on_cell_change awtd){  class cl_watched_cell *wc;  class cl_cell *cell;  wc= new cl_used_cell(mem, addr, &cell, awtd);  if (store)    *store= cell;  watched_cells->add(wc);  return(cell);}voidcl_hw::mem_cell_changed(class cl_mem *mem, t_addr addr){  int i;  for (i= 0; i < watched_cells->count; i++)    {      class cl_watched_cell *wc=	(class cl_watched_cell *)(watched_cells->at(i));      wc->mem_cell_changed(mem, addr, this);    }}/* * Simulating `cycles' number of machine cycle */intcl_hw::tick(int cycles){  return(0);}voidcl_hw::inform_partners(enum hw_event he, void *params){  int i;  for (i= 0; i < partners->count; i++)    {      class cl_partner_hw *ph= (class cl_partner_hw *)(partners->at(i));      ph->happen(this, he, params);    }}voidcl_hw::print_info(class cl_console *con){  con->dd_printf("%s[%d]\n", id_string, id);}t_indexcl_hws::add(void *item){  int i;  t_index res;  // pre-add  for (i= 0; i < count; i++)    {      class cl_hw *hw= (class cl_hw *)(at(i));      hw->new_hw_adding((class cl_hw *)item);    }  // add  res= cl_list::add(item);  // post-add  for (i= 0; i < count; i++)    {      class cl_hw *hw= (class cl_hw *)(at(i));      hw->new_hw_added((class cl_hw *)item);    }  ((class cl_hw *)item)->added_to_uc();  return(res);}voidcl_hws::mem_cell_changed(class cl_mem *mem, t_addr addr){  int i;    for (i= 0; i < count; i++)    {      class cl_hw *hw= (class cl_hw *)(at(i));      hw->mem_cell_changed(mem, addr);    }}/* *____________________________________________________________________________ */cl_partner_hw::cl_partner_hw(class cl_uc *auc, enum hw_cath cath, int aid):  cl_base(){  uc= auc;  cathegory= cath;  id= aid;  partner= uc->get_hw(cathegory, id, 0);}class cl_hw *cl_partner_hw::get_partner(void){  return(partner);}voidcl_partner_hw::refresh(void){  class cl_hw *hw= uc->get_hw(cathegory, id, 0);  if (!hw)    return;  if (partner)    {      // partner is already set      if (partner != hw)	{	  // partner changed?	  partner= hw;	}      else	partner= hw;    }  partner= hw;}voidcl_partner_hw::refresh(class cl_hw *new_hw){  if (!new_hw)    return;  if (cathegory == new_hw->cathegory &&      id == new_hw->id)    {      if (partner)	{	  // partner changed?	  partner= new_hw;	}      else	partner= new_hw;    }}voidcl_partner_hw::happen(class cl_hw *where, enum hw_event he, void *params){  if (partner)    partner->happen(where, he, params);}/* End of hw.cc */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -