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 Last edit by hansen on Mon Feb 2 23:19:11 2009
19 ****************************************************************************/
20 #include "tkgate.h"
21
22
23 #define REG_Q 0
24 #define REG_D 1
25 #define REG_EN 2
26 #define REG_CLR 3
27 #define REG_CK 4
28
29 static void Register_WriteCellDef(FILE *f,GCellSpec *gcs);
30
31
32 static iconDimensions reg_iconDims[] = {
33 {0, 0, 75, 20, 36, 9},
34 {97, 0, 20, 75, 10, 37},
35 {0, 21, 75, 20, 36, 9},
36 {76, 0, 20, 75, 10, 37},
37 };
38 static int reg_iconBoldOffset = 76;
39
40 GPadLoc register_in_loc[] = {
41 {0,-10,0,-10,D_UP},
42 {-11,0,-11,0,D_LEFT},
43 {0,11,0,11,D_DOWN},
44 {10,0,10,0,D_RIGHT}};
45
46 GPadLoc register_out_loc[] = {
47 {0,11,0,11,D_DOWN},
48 {10,0,10,0,D_RIGHT},
49 {0,-10,0,-10,D_UP},
50 {-11,0,-11,0,D_LEFT}};
51
52 GPadLoc register_ck_loc[] = {
53 {-37,0,-37,0,D_LEFT},
54 {0,38,0,38,D_DOWN},
55 {39,0,39,0,D_RIGHT},
56 {0,-38,0,-38,D_UP}};
57
58 GPadLoc register_en_loc[] = {
59 {39,5,39,5,D_RIGHT},
60 {5,-38,5,-38,D_UP},
61 {-37,-5,-37,-5,D_LEFT},
62 {-5,38,-5,38,D_DOWN}};
63
64 GPadLoc register_clr_loc[] = {
65 {39,-5,39,-5,D_RIGHT},
66 {-5,-38,-5,-38,D_UP},
67 {-37,5,-37,5,D_LEFT},
68 {5,38,5,38,D_DOWN}};
69
70
71 static char *psRegister[] = {
72 "%",
73 "% A Register",
74 "/register {",
75 " [[0 0][-1 1][2 1][0 -1]] adjstartgate",
76 " -36.5 -10.5 moveto",
77 " -36.5 9.5 lineto",
78 " 38.5 9.5 lineto",
79 " 38.5 -10.5 lineto",
80 " closepath stroke",
81 " -36.5 -7 moveto",
82 " -30 0 lineto",
83 " -36.5 7 lineto stroke",
84 " 7 rfont",
85 " (_CLR) dup stringwidth pop neg 36 add 0 prshow",
86 " (_EN) dup stringwidth pop neg 36 add -9 prshow",
87 " grestore",
88 "} def",
89 0
90 };
91
92 GGateInfo gate_register_info = {
93 GC_REGISTER,
94 "REG",
95 "register",0x0,
96 "register",psRegister,
97 -1,0,
98
99 {{"r", {"gm.mem",5}, {"gm.mem.reg",0,0,100}, "gat_make REG"},
100 {0}},
101
102
103 reg_iconDims,
104
105 5,{{"Q",OUT,8,1,register_out_loc},
106 {"D",IN,8,1,register_in_loc},
107 {"EN",IN,1,1,register_en_loc},
108 {"CLR",IN,1,1,register_clr_loc},
109 {"CK",IN,1,1,register_ck_loc}},
110 {{0,3,CT},{13,-5,LJ},{0,3,CT},{13,-5,LJ}},
111 {1},
112
113 {"Dsetup","Dhold","Dck_q",0},
114
115 Generic_Make,
116 Register_WriteCellDef,
117 Generic_Init,
118 Generic_Delete,
119 Generic_GetExtents,
120 Generic_HitDistance,
121 Generic_Draw,
122 Generic_Move,
123 Generic_Copy,
124 Err_AddInput,
125 Err_AddOutput,
126 Err_AddInOut,
127 Generic_Rotate,
128 Err_RemovePort,
129 Err_ChangePin,
130 Nop_SimInitFunc,
131 Nop_SimHitFunc,
132 Generic_PSWrite,
133 Generic_EditProps,
134 Generic_VerSave
135 };
136
137 /*****************************************************************************
138 *
139 * Generate primitive cell definition for registers.
140 *
141 * Parameters:
142 * f File to write cell to.
143 * name Name of cell to write.
144 *
145 *****************************************************************************/
Register_WriteCellDef(FILE * f,GCellSpec * gcs)146 static void Register_WriteCellDef(FILE *f,GCellSpec *gcs)
147 {
148 int numBit = gcs->gc_numBits;
149 const char *invSpec = gcs->gc_invSpec;
150 int invQ = 0;
151 PrimParm primParm;
152
153 if (*invSpec == 'N')
154 invQ = 1;
155
156 PrimParm_init(&primParm);
157 PrimParm_rangeSet(&primParm,"DQ_RANGE",numBit);
158 PrimParm_intSet(&primParm,"DQ_BITS",numBit);
159 PrimParm_invSet(&primParm,"invQ",invQ);
160 Primitive_write(f,"register",gcs,&primParm);
161 }
162
init_register()163 void init_register()
164 {
165 Pixmap P;
166
167 P = Pixmap_registerFromFile("reg","reg.b");
168 gateinfo_iconInit(&gate_register_info,P,reg_iconDims,reg_iconBoldOffset);
169 RegisterGate(&gate_register_info);
170 }
171