ab0f5cfb39df2054bbf760fdc9f92af16047bb2e
[fw/sdcc] / sim / ucsim / sim.src / hw.cc
1 /*
2  * Simulator of microcontrollers (hw.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 <stdlib.h>
31 #include "i_string.h"
32
33 #include "stypes.h"
34 #include "hwcl.h"
35
36
37 cl_hw::cl_hw(class cl_uc *auc, enum hw_cath cath, int aid, char *aid_string):
38   cl_guiobj()
39 {
40   flags= HWF_INSIDE;
41   uc= auc;
42   cathegory= cath;
43   id= aid;
44   if (aid_string &&
45       *aid_string)
46     id_string= strdup(aid_string);
47   else
48     id_string= strdup("unknown hw element");
49 }
50
51 cl_hw::~cl_hw(void)
52 {
53   free(id_string);
54 }
55
56
57 /*
58  * Callback functions for changing memory locations
59  */
60
61 t_mem
62 cl_hw::read(class cl_mem *mem, t_addr addr)
63 {
64   // Simply return the value
65   return(mem->get(addr));
66 }
67
68 void
69 cl_hw::write(class cl_mem *mem, t_addr addr, t_mem *val)
70 {
71   // Do not change *val by default
72 }
73
74
75 /*
76  * Simulating `cycles' number of machine cycle
77  */
78
79 int
80 cl_hw::tick(int cycles)
81 {
82   return(0);
83 }
84
85 void
86 cl_hw::print_info(class cl_console *con)
87 {
88   con->printf("%s[%d]\n", id_string, id);
89 }
90
91
92 t_index
93 cl_hws::add(void *item)
94 {
95   int i;
96   t_index res;
97
98   // pre-add
99   for (i= 0; i < count; i++)
100     {
101       class cl_hw *hw= (class cl_hw *)(at(i));
102       hw->adding((class cl_hw *)item);
103     }
104   // add
105   res= cl_list::add(item);
106   // post-add
107   for (i= 0; i < count; i++)
108     {
109       class cl_hw *hw= (class cl_hw *)(at(i));
110       hw->added((class cl_hw *)item);
111     }
112   return(res);
113 }
114
115
116 /* End of hw.cc */