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 Jan 19 18:13:37 2009
19 ****************************************************************************/
20 #include "tkgate.h"
21 
22 #define ADDER_A 0
23 #define ADDER_B 1
24 #define ADDER_S 2
25 #define ADDER_CI 3
26 #define ADDER_CO 4
27 
28 static void Adder_WriteCellDef(FILE *f,GCellSpec *gcs);
29 
30 static iconDimensions add_iconDims[] = {
31   {0,  0,  59, 28, 29, 15},
32   {60, 0,  28, 59, 15, 29},
33   {29, 60, 59, 28, 28, 12},
34   {0,  29, 28, 59, 12, 29},
35 };
36 static int add_iconBoldOffset = 89;
37 
38 GPadLoc adder_A_loc[] = {
39 	{-16,-16,-16,-16,D_UP},
40 	{-16,16,-16,16,D_LEFT},
41 	{16,16,16,16,D_DOWN},
42 	{16,-16,16,-16,D_RIGHT}};
43 
44 GPadLoc adder_B_loc[] = {
45 	{16,-16,16,-16,D_UP},
46 	{-16,-16,-16,-16,D_LEFT},
47 	{-16,16,-16,16,D_DOWN},
48 	{16,16,16,16,D_RIGHT}};
49 
50 GPadLoc adder_Ci_loc[] = {
51 	{24,-2,24,-2,D_RIGHT},
52 	{-2,-24,-2,-24,D_UP},
53 	{-24,2,-24,2,D_LEFT},
54 	{2,24,2,24,D_DOWN}};
55 
56 GPadLoc adder_Co_loc[] = {
57 	{-24,-2,-24,-2,D_LEFT},
58 	{-2,24,-2,24,D_DOWN},
59 	{24,2,24,2,D_RIGHT},
60 	{2,-24,2,-24,D_UP}};
61 
62 
63 GPadLoc adder_S_loc[] = {
64 	{0,13,0,13,D_DOWN},
65 	{13,0,13,0,D_RIGHT},
66 	{0,-13,0,-13,D_UP},
67 	{-13,0,-13,0,D_LEFT}};
68 
69 static const char *psAdder[] = {
70   "%",
71   "% x y r adder",
72   "%",
73   "/psadder {",
74   "  startgate",
75   "  -30 15.5 moveto",
76   "  -5 15.5 lineto",
77   "  0 10 lineto",
78   "  5 15.5 lineto",
79   "  30 15.5 lineto",
80   "  16 -12.5 lineto",
81   "  -16 -12.5 lineto",
82   "  closepath stroke",
83   "  -3 0 moveto 3 0 lineto stroke",
84   "  0 3 moveto 0 -3 lineto stroke",
85   "  19 2 2 0 360 arc closepath fill",
86   "  grestore",
87   "} def",
88   0
89 };
90 
91 GGateInfo gate_add_info = {
92   0,
93   "ADD",
94   "add",0x0,
95   "psadder",(char**)psAdder,
96   -1,2,
97 
98   {{"+",	{"gm.alu",0},		{"gm.alu.add",0,0,100},	"gat_make ADD"},
99    {0}},
100 
101 
102   add_iconDims,
103 
104   5,{{"A",IN,8,1,adder_A_loc},
105        {"B",IN,8,1,adder_B_loc},
106        {"S",OUT,8,1,adder_S_loc},
107        {"CI",IN,1,1,adder_Ci_loc},
108        {"CO",OUT,1,1,adder_Co_loc}},
109   {{24,10,LJ},{8,-24,LJ},{-24,-8,RJ},{-12,24,RJ}},
110   {1},
111 
112   {"Dab_s","Dab_co","Dci_s","Dci_co",0},
113 
114   Generic_Make,
115   Adder_WriteCellDef,
116   Generic_Init,
117   Generic_Delete,
118   Generic_GetExtents,
119   Generic_HitDistance,
120   Generic_Draw,
121   Generic_Move,
122   Generic_Copy,
123   Err_AddInput,
124   Err_AddOutput,
125   Err_AddInOut,
126   Generic_Rotate,
127   Err_RemovePort,
128   Err_ChangePin,
129   Nop_SimInitFunc,
130   Nop_SimHitFunc,
131   Generic_PSWrite,
132   Generic_EditProps,
133   Generic_VerSave
134 };
135 
136 /*****************************************************************************
137  *
138  * Generate primitive cell definition for adders.
139  *
140  * Parameters:
141  *    f			File to write cell to.
142  *    name		Name of cell to write.
143  *
144  *****************************************************************************/
Adder_WriteCellDef(FILE * f,GCellSpec * gcs)145 static void Adder_WriteCellDef(FILE *f,GCellSpec *gcs)
146 {
147   /** @TODO to remove */
148   /*
149   GGateInfo *gi = gcs->gc_info;
150   */
151   int numBit = gcs->gc_numBits;
152   const char *invSpec = gcs->gc_invSpec;
153   PrimParm primParm;
154   int invS = 0,invCO = 0;
155 
156 
157   if (*invSpec) {
158     if (*invSpec == 'N')
159       invS = 1;
160     if (!invSpec[1] || invSpec[1] == 'N')
161       invCO = 0;
162   }
163 
164   PrimParm_init(&primParm);
165   PrimParm_rangeSet(&primParm,"ABS_RANGE",numBit);
166   PrimParm_invSet(&primParm,"invS",invS);
167   PrimParm_invSet(&primParm,"invCO",invCO);
168   Primitive_write(f,"adder",gcs,&primParm);
169 }
170 
init_adder()171 void init_adder()
172 {
173   Pixmap P;
174 
175   P = Pixmap_registerFromFile("add","add.b");
176   gateinfo_iconInit(&gate_add_info,P,add_iconDims,add_iconBoldOffset);
177   RegisterGate(&gate_add_info);
178 }
179