1 /****************************************************************************
2     Copyright (C) 1987-2015 by Jeffery P. Hansen
3 
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License along
15     with this program; if not, write to the Free Software Foundation, Inc.,
16     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 ****************************************************************************/
18 #ifndef __circuit_h
19 #define __circuit_h
20 
21 /*
22  * Time unit codes
23  */
24 #define UC_SEC		0
25 #define UC_MILLISEC	1
26 #define UC_MICROSEC	2
27 #define UC_NANOSEC	3
28 #define UC_PICOSEC	4
29 #define UC_FEMTOSEC	5
30 
31 /*****************************************************************************
32  *
33  * Timing violation mode
34  *
35  *****************************************************************************/
36 typedef enum {
37     TV_NONE = 0,
38 #define TV_NONE		TV_NONE
39     TV_AFTER = 1,
40 #define TV_AFTER	TV_AFTER
41     TV_ALL = 2
42 #define TV_ALL		TV_ALL
43 } tviolation_t;
44 
45 /*****************************************************************************
46  *
47  * Representation of the current file.
48  *
49  *****************************************************************************/
50 struct CurrentFile_str {
51   char	*baseName;		/* Base name of current circuit file */
52   char	*dirName;		/* Name of directory for current file */
53   char	*fullPathName;		/* Full path name of the current file */
54 };
55 
56 struct GrabbedLabel_str {
57   GNet		*net;		/* Net whose label has been grabbed */
58   char		*label;		/* Text of label */
59   int		ox,oy;		/* Offset from mouse poninter for text label */
60   int		position;	/* Label positioning */
61 };
62 
63 /*****************************************************************************
64  *
65  * Used to record probes that were used in simulation mode so they can be
66  * reused when starting the simualtion again.  We keep track of the net so
67  * that if we delete a net then we can remove probes associated with it.
68  *
69  *****************************************************************************/
70 typedef struct SavedProbe_str {
71   char		*sp_name;	/* Full path name of probe */
72   GNet		*sp_net;	/* Circuit net probe is based on */
73 } SavedProbe;
74 
75 /*****************************************************************************
76  *
77  * Top-level circuit data
78  *
79  *****************************************************************************/
80 struct Circuit_str {
81   CurrentFile	*currentFile;	/* Name of current file */
82   char		*fileVersion;	/* Version of current file */
83   char		*title;		/* Title of current circuit */
84 
85   Locale	*c_locale;	/* Locale of the file */
86   char		*c_encoding;	/* Character encoding for save file. */
87   Encoder	*c_saveEncoder;		/* Encoder used to save verilog data */
88   Encoder	*c_loadEncoder;		/* Encoder used to load verilog data */
89   Encoder	*c_displayEncoder;	/* Encoder used to used to display strings */
90   Encoder	*c_psEncoder;		/* Encoder used to used to generate postscript */
91 
92   Timescale	c_timescale;	/* Circuit timescale */
93 
94   tviolation_t		c_tvMode;	/* Timing violation mode (0=none, 1=after startup, 2=all) */
95   double	c_startup;	/* Time required for initialization (suppress timing violations) */
96   int		c_startupUnits;	/* Unit code for startup time */
97 
98   SimInterface	simulator;	/* top-level state for the simulator */
99   NHash		*c_breakpoints;	/* Circuit breakpoints */
100   NHash		*c_scripts;	/* Scripts active in simulator */
101   List		*c_probes;	/* Saved list of nets with probes on them */
102 
103   GSearchContext *search;	/* The current search context */
104 
105   GModuleDef	*mid_mod;	/* Module interface descriptors */
106   GModuleDef	*mid_altMod;	/* Module for alternate interface descriptions */
107   GModuleDef	*mid_display;	/* Module for displaying a single interface */
108   GModuleDef	*root_mod;	/* Top-level module */
109   GSimModule	*root_ss;	/* Root simulation state */
110 
111   SHash		*moduleTable;	/* Table of modules */
112 
113   int		numInitScripts;	/* Number of simulation initialization scripts */
114   char		**initScripts;	/* Simulation initialization scripts */
115 
116   char		*c_gatePrefix;	/* Prefix for tkgate primitives */
117 
118   int		discardChanges;	/* Are we discarding changes? */
119   int		useExtBars;	/* Are we using extender bars? */
120   int		showSwitchNets;	/* Show net names on switches and dips? */
121   int		simAutoStart;	/* Auto-start of simulator */
122   int		simClockMode;	/* 0=stop on all clocks, 1=stop on named clock */
123 
124   char		*simClockName;	/* Name of clock to stop on */
125 
126   int		no_set_modify;	/* Do not set 'modified' flag */
127   unsigned	modified_flags;	/* Flags indicating what has changed and needs to be saved */
128 
129   int		c_isNewFile;	/* Is this a brand new never saved file? */
130 
131   /*****************************************************************************/
132   /* These are fields that probably should be moved someplace else             */
133   /*****************************************************************************/
134 
135   int		org_x,org_y;	/* Origin point for viewable */
136   int		zoom_factor;	/* Zoom factor */
137   EditState	*es;		/* Current editing context */
138   GCutBuffer	*cut_buffer;	/* Buffer for cut/paste operations */
139   GSelection	*mg_selection;	/* The current multi-gate selection */
140   GCElement	*select;	/* Current single-gate selection */
141   GCElement	*last;		/* Last selected gate */
142   GWire		*wsel;		/* Selected wire */
143   GWireNode	*wnsel;		/* Selected wire node */
144   GNet		*nsel;		/* Selected net */
145   GrabbedLabel	*labelsel;	/* Selected wire label */
146   int rot;			/* Current rotation */
147   int mode;			/* Current mode */
148 };
149 
150 Circuit *new_Circuit();
151 void Circuit_setTitle(const char*);
152 void Circuit_setLocale(Circuit *c,Locale *);
153 void Circuit_setFileEncoding(Circuit *c,const char*);
154 void Circuit_setClockName(const char*);
155 void Circuit_setCurrentFile(const char*);
156 void Circuit_setCurrentFileVersion(const char*);
157 void Circuit_setScripts(int nScripts,const char **scripts);
158 void Circuit_setLibraries(int nLibraries,const char **libraries);
159 void Circuit_changeRoot(GModuleDef *M);
160 void Circuit_clear();
161 int Circuit_isSelection(Circuit *c);
162 
163 void Circuit_loadLibrary(Circuit *c, const char *name);
164 void Circuit_unloadLibrary(Circuit *c, const char *name);
165 void Circuit_unloadAllLibraries(Circuit *c);
166 
167 void Circuit_clearSavedProbes(Circuit *c);
168 void Circuit_addProbeName(Circuit *c,const char *name,GNet *net);
169 void Circuit_removeProbesOnNet(Circuit *c,GNet *net);
170 #define Circuit_getLoadFileEncoder(c) (c)->c_loadEncoder
171 #define Circuit_getSaveFileEncoder(c) (c)->c_saveEncoder
172 #define Circuit_getDisplayEncoder(c) (c)->c_displayEncoder
173 #define Circuit_getPSEncoder(c) (c)->c_psEncoder
174 void Circuit_invalidateHtml(Circuit *c);
175 void Circuit_initOptions(Circuit *c);
176 
177 CurrentFile *new_CurrentFile();
178 int CurrentFile_set(CurrentFile *cf,const char *name);
179 #define CurrentFile_getBase(cf) (cf)->baseName
180 #define CurrentFile_getDir(cf) (cf)->dirName
181 #define CurrentFile_path(cf) (cf)->fullPathName
182 
183 GrabbedLabel *new_GrabbedLabel();
184 void GrabbedLabel_draw(int x,int y);
185 void GrabbedLabel_unset();
186 void GrabbedLabel_set(GNet *net,int x,int y,int p);
187 
188 void EditState_setMode(int mode);
189 void EditState_setRotation(int rot);
190 #define EditState_getMode() TkGate.circuit->mode
191 #define EditState_getRotation() TkGate.circuit->rot
192 
193 void Timescale_save(Timescale *ts, FILE *f);
194 simtime_t Timescale_parse(int num,const char *units);
195 void Timescale_decode(unsigned long long n, int *num,char *units);
196 int Timescale_unitsToCode(const char *units);
197 const char *Timescale_codeToUnits(int code);
198 
199 #endif
200