Imported Upstream version 2.9.0
[debian/cc1111] / sim / ucsim / sim.src / hwcl.h
1 /*
2  * Simulator of microcontrollers (sim.src/hwcl.h)
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 /* Abstract hw element. It can be a timer, serial line or whatever */
29
30 #ifndef SIM_HWCL_HEADER
31 #define SIM_HWCL_HEADER
32
33 #include "stypes.h"
34 #include "pobjcl.h"
35 #include "guiobjcl.h"
36
37 // cmd.src
38 #include "newcmdcl.h"
39
40 // local
41 #include "memcl.h"
42 #include "uccl.h"
43
44
45 enum what_to_do_on_cell_change {
46   wtd_none              = 0x01,
47   wtd_write             = 0x02,
48   wtd_restore           = 0x04,
49   wtd_restore_write     = 0x08
50 };
51
52 #define WTD_WRITE       (wtd_write|wtd_restore_write)
53 #define WTD_RESTORE     (wtd_restore|wtd_restore_write)
54
55 class cl_hw; // forward
56
57 class cl_watched_cell: public cl_base
58 {
59 protected:
60   class cl_address_space *mem;
61   t_addr addr;
62   class cl_memory_cell *cell;
63   class cl_memory_cell **store;
64 public:
65   enum what_to_do_on_cell_change wtd;
66 public:
67   cl_watched_cell(class cl_address_space *amem, t_addr aaddr,
68                   class cl_memory_cell **astore,
69                   enum what_to_do_on_cell_change awtd);
70
71   virtual void mem_cell_changed(class cl_address_space *amem, t_addr aaddr,
72                                 class cl_hw *hw);
73   virtual void address_space_added(class cl_address_space *amem,
74                                    class cl_hw *hw);
75 };
76
77 class cl_used_cell: public cl_watched_cell
78 {
79 public:
80   cl_used_cell(class cl_address_space *amem, t_addr aaddr,
81                class cl_memory_cell **astore,
82                enum what_to_do_on_cell_change awtd):
83     cl_watched_cell(amem, aaddr, astore, awtd) {}
84
85   virtual void mem_cell_changed(class cl_address_space *amem, t_addr aaddr,
86                                 class cl_hw *hw);
87   virtual void address_space_added(class cl_address_space *amem,
88                                    class cl_hw *hw);
89 };
90
91 class cl_hw: public cl_guiobj
92 {
93 public:
94   int flags;
95   class cl_uc *uc;
96   enum hw_cath cathegory;
97   int id;
98   char *id_string;
99 protected:
100   class cl_list *partners;
101   class cl_list *watched_cells;
102 public:
103   cl_hw(class cl_uc *auc, enum hw_cath cath, int aid, const char *aid_string);
104   virtual ~cl_hw(void);
105
106   virtual void new_hw_adding(class cl_hw *new_hw);
107   virtual void new_hw_added(class cl_hw *new_hw);
108   virtual void added_to_uc(void) {}
109   virtual class cl_hw *make_partner(enum hw_cath cath, int id);
110
111   virtual t_mem read(class cl_memory_cell *cell) { return(cell->get()); }
112   virtual void write(class cl_memory_cell * /*cell*/, t_mem * /*val*/) {}
113
114   virtual void set_cmd(class cl_cmdline *cmdline, class cl_console_base *con);
115   virtual class cl_memory_cell *register_cell(class cl_address_space *mem,
116                                               t_addr addr,
117                                               class cl_memory_cell **store,
118                                               enum what_to_do_on_cell_change
119                                               awtd);
120   virtual class cl_memory_cell *use_cell(class cl_address_space *mem,
121                                          t_addr addr,
122                                          class cl_memory_cell **store,
123                                          enum what_to_do_on_cell_change awtd);
124   virtual void mem_cell_changed(class cl_address_space *mem, t_addr addr);
125   virtual void address_space_added(class cl_address_space *as);
126
127   virtual int tick(int cycles);
128   virtual void reset(void) {}
129   virtual void happen(class cl_hw * /*where*/, enum hw_event /*he*/,
130                       void * /*params*/) {}
131   virtual void inform_partners(enum hw_event he, void *params);
132
133   virtual void print_info(class cl_console_base *con);
134 };
135
136 class cl_hws: public cl_list
137 {
138 public:
139   cl_hws(void): cl_list(2, 2, "hws") {}
140   virtual t_index add(void *item);
141   virtual void mem_cell_changed(class cl_address_space *mem, t_addr addr);
142   virtual void address_space_added(class cl_address_space *as);
143 };
144
145
146 class cl_partner_hw: public cl_base
147 {
148 protected:
149   class cl_uc *uc;
150   enum hw_cath cathegory;
151   int id;
152   class cl_hw *partner;
153 public:
154   cl_partner_hw(class cl_uc *auc, enum hw_cath cath, int aid);
155
156   virtual class cl_hw *get_partner(void);
157   virtual void refresh(void);
158   virtual void refresh(class cl_hw *new_hw);
159
160   virtual void happen(class cl_hw *where, enum hw_event he, void *params);
161 };
162
163
164 #endif
165
166 /* End of hwcl.h */