File: logic.h

package info (click to toggle)
gpsim 0.22.0-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 7,552 kB
  • ctags: 12,443
  • sloc: cpp: 69,959; sh: 8,747; asm: 7,706; ansic: 4,101; lex: 1,125; makefile: 1,102; yacc: 760
file content (210 lines) | stat: -rw-r--r-- 4,299 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
   Copyright (C) 1998,1999,2000 T. Scott Dattalo

This file is part of gpsim.

gpsim is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

gpsim is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with gpsim; see the file COPYING.  If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  */


#ifndef __LOGIC_H__
#define __LOGIC_H__

/* IN_MODULE should be defined for modules */
#define IN_MODULE

#include "../src/stimuli.h"
#include "../src/ioports.h"
#include "../src/symbol.h"
#include "../src/modules.h"

#ifdef HAVE_GUI
#include <gtk/gtk.h>
#endif

class LogicGate;
class ANDGate;
class AND2Gate;


/*********************************************************
 *
 * Create a class derived from the IO_input class that
 * will allow us to intercept when the I/O input is being
 * driven. (This isn't done for PIC I/O pins because the
 * logic for handling I/O pin changes resides in the IOPORT
 * class.)
 */

class Logic_Input : public IOPIN
{
private:
  LogicGate *LGParent;
  unsigned int m_iobit;

public:

  virtual void setDrivenState( bool new_state);

  Logic_Input (LogicGate *parent, unsigned int b, const char *opt_name=0) 
    : IOPIN(opt_name), LGParent(parent), m_iobit(b)
    { 
    }

};

class Logic_Output : public IO_bi_directional
{
private:
  LogicGate *LGParent;
  unsigned int m_iobit;
public:

  Logic_Output (LogicGate *parent, unsigned int b,const char *opt_name=0) 
    : IO_bi_directional(opt_name), LGParent(parent), m_iobit(b)
    { 
    }

};

/*************************************************************
 *
 * LogicGate class.
 *
 * Here's the definition for the LogicGate class and all of its
 * children
 *
 *    Module
 *      |
 *      --------
 *             |
 *             |-LogicGate
 *                 |
 *                 |- ANDGate
 *                 |     |
 *                 |     |- AND2Gate
 *                 |- ORGate
 *                       |
 *                       |- OR2Gate
 */

class LogicGate : public Module
{
public:

  int number_of_pins;
  unsigned int input_bit_mask;
  unsigned int input_state;
  IOPIN  **pInputPins;
  Logic_Output *pOutputPin;
#ifdef HAVE_GUI
  GdkPixmap *pixmap;
#endif
  LogicGate(void);
  ~LogicGate(void);

  // Inheritances from the Package class
  virtual void create_iopin_map(void);


  virtual void update_state(void)=0;
  void update_input_pin(unsigned int pin, bool bValue);
  virtual int get_num_of_pins(void) {return number_of_pins;};
  void set_number_of_pins(int npins){number_of_pins=npins;};
#ifdef HAVE_GUI
  GtkWidget *create_pixmap(char **pixmap_data);
#endif
};

// 2 input and gate

class ANDGate: public LogicGate
{
public:

  virtual void update_state(void);

};

class AND2Gate: public ANDGate
{
public:

  static Module *construct(const char *new_name);
  const virtual char *type(void) { return ("and2"); };
  // virtual void update_state(void);
  AND2Gate(void);
  ~AND2Gate(void);

};

class ORGate: public LogicGate
{
public:

  virtual void update_state(void);

};

// 2 input or gate

class OR2Gate: public ORGate
{
public:

  //virtual void update_state(void);
  static Module *construct(const char *new_name);
  const virtual char *type(void) { return ("or2"); };
  OR2Gate(void);
  ~OR2Gate(void);
  
};

class XORGate: public LogicGate
{
public:

  virtual void update_state(void);

};

// 2 input or gate

class XOR2Gate: public XORGate
{
public:

  //virtual void update_state(void);
  static Module *construct(const char *new_name);
  const virtual char *type(void) { return ("xor2"); };
  XOR2Gate(void);
  ~XOR2Gate(void);
  
};

class NOTGate: public LogicGate
{
public:

  //virtual void update_state(void);
  static Module *construct(const char *new_name);
  const virtual char *type(void) { return ("not"); };
  virtual void update_state(void);
  NOTGate(void);
  ~NOTGate(void);
  
};
#endif //  __LOGIC_H__