a67921e02a4e752317b67628b158df5aa4f827f5
[fw/sdcc] / 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_mem *mem;
61   t_addr addr;
62   class cl_cell *cell;
63   class cl_cell **store;
64 public:
65   enum what_to_do_on_cell_change wtd;
66 public:
67   cl_watched_cell(class cl_mem *amem, t_addr aaddr, class cl_cell **astore,
68                   enum what_to_do_on_cell_change awtd);
69
70   virtual void mem_cell_changed(class cl_mem *amem, t_addr aaddr,
71                                 class cl_hw *hw);
72 };
73
74 class cl_used_cell: public cl_watched_cell
75 {
76 public:
77   cl_used_cell(class cl_mem *amem, t_addr aaddr, class cl_cell **astore,
78                enum what_to_do_on_cell_change awtd):
79     cl_watched_cell(amem, aaddr, astore, awtd) {}
80
81   /*virtual void mem_cell_changed(class cl_mem *amem, t_addr aaddr,
82     class cl_hw *hw);*/
83 };
84
85 class cl_hw: public cl_guiobj
86 {
87 public:
88   int flags;
89   class cl_uc *uc;
90   enum hw_cath cathegory;
91   int id;
92   char *id_string;
93 protected:
94   class cl_list *partners;
95   class cl_list *watched_cells;
96 public:
97   cl_hw(class cl_uc *auc, enum hw_cath cath, int aid, char *aid_string);
98   virtual ~cl_hw(void);
99
100   virtual void new_hw_adding(class cl_hw *new_hw);
101   virtual void new_hw_added(class cl_hw *new_hw);
102   virtual void added_to_uc(void) {}
103   virtual class cl_hw *make_partner(enum hw_cath cath, int id);
104
105   virtual t_mem read(class cl_cell *cell) { return(cell->get()); }
106   virtual void write(class cl_cell */*cell*/, t_mem */*val*/) {}
107
108   virtual void set_cmd(class cl_cmdline *cmdline, class cl_console *con) {}
109   virtual class cl_cell *register_cell(class cl_mem *mem, t_addr addr,
110                                        class cl_cell **store,
111                                        enum what_to_do_on_cell_change awtd);
112   virtual class cl_cell *use_cell(class cl_mem *mem, t_addr addr,
113                                   class cl_cell **store,
114                                   enum what_to_do_on_cell_change awtd);
115   virtual void mem_cell_changed(class cl_mem *mem, t_addr addr);
116
117   virtual int tick(int cycles);
118   virtual void reset(void) {}
119   virtual void happen(class cl_hw */*where*/, enum hw_event /*he*/,
120                       void */*params*/) {}
121   virtual void inform_partners(enum hw_event he, void *params);
122
123   virtual void print_info(class cl_console *con);
124 };
125
126 class cl_hws: public cl_list
127 {
128 public:
129   cl_hws(void): cl_list(2, 2) {}
130   virtual t_index add(void *item);
131   virtual void mem_cell_changed(class cl_mem *mem, t_addr addr);
132 };
133
134
135 class cl_partner_hw: public cl_base
136 {
137 protected:
138   class cl_uc *uc;
139   enum hw_cath cathegory;
140   int id;
141   class cl_hw *partner;
142 public:
143   cl_partner_hw(class cl_uc *auc, enum hw_cath cath, int aid);
144
145   virtual class cl_hw *get_partner(void);
146   virtual void refresh(void);
147   virtual void refresh(class cl_hw *new_hw);
148
149   virtual void happen(class cl_hw *where, enum hw_event he, void *params);
150 };
151
152
153 #endif
154
155 /* End of hwcl.h */