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 Sat Jan 24 09:02:39 2009
19 ****************************************************************************/
20 #include "tkgate.h"
21 
22 #define MULT_A 0
23 #define MULT_B 1
24 #define MULT_P 2
25 
26 static void Mult_WriteCellDef(FILE *f,GCellSpec *gcs);
27 
28 static iconDimensions mult_iconDims[] = {
29   {0,  0,  59, 28, 29, 15},
30   {60, 0,  28, 59, 15, 29},
31   {29, 60, 59, 28, 28, 12},
32   {0,  29, 28, 59, 12, 29},
33 };
34 static int mult_iconBoldOffset = 89;
35 
36 GPadLoc mult_A_loc[] = {
37 	{-16,-16,-16,-16,D_UP},
38 	{-16,16,-16,16,D_LEFT},
39 	{16,16,16,16,D_DOWN},
40 	{16,-16,16,-16,D_RIGHT}};
41 
42 GPadLoc mult_B_loc[] = {
43 	{16,-16,16,-16,D_UP},
44 	{-16,-16,-16,-16,D_LEFT},
45 	{-16,16,-16,16,D_DOWN},
46 	{16,16,16,16,D_RIGHT}};
47 
48 GPadLoc mult_P_loc[] = {
49 	{0,13,0,13,D_DOWN},
50 	{13,0,13,0,D_RIGHT},
51 	{0,-13,0,-13,D_UP},
52 	{-13,0,-13,0,D_LEFT}};
53 
54 static char *psMult[] = {
55   "%",
56   "% x y r psmult",
57   "%",
58   "/psmult {",
59   "  startgate",
60   "  -30 15.5 moveto",
61   "  -5 15.5 lineto",
62   "  0 10 lineto",
63   "  5 15.5 lineto",
64   "  30 15.5 lineto",
65   "  16 -12.5 lineto",
66   "  -16 -12.5 lineto",
67   "  closepath stroke",
68   "  -3 -3 moveto 3 3 lineto stroke",
69   "  -3 3 moveto 3 -3 lineto stroke",
70   "  grestore",
71   "} def",
72   0
73 };
74 
75 GGateInfo gate_mult_info = {
76   0,
77   "MUL",
78   "mult",0x0,
79   "psmult",psMult,
80   -1,2,
81 
82   {{"*",	{"gm.alu",0},		{"gm.alu.mult",0,0,200},	"gat_make MUL"},
83    {0}},
84 
85 
86   mult_iconDims,
87 
88   3,{{"A",IN,8,1,mult_A_loc},
89        {"B",IN,8,1,mult_B_loc},
90        {"P",OUT,8,1,mult_P_loc}},
91   {{24,10,LJ},{8,-24,LJ},{-24,-8,RJ},{-12,24,RJ}},
92   {1},
93 
94   {"Dab_p",0},
95 
96   Generic_Make,
97   Mult_WriteCellDef,
98   Generic_Init,
99   Generic_Delete,
100   Generic_GetExtents,
101   Generic_HitDistance,
102   Generic_Draw,
103   Generic_Move,
104   Generic_Copy,
105   Err_AddInput,
106   Err_AddOutput,
107   Err_AddInOut,
108   Generic_Rotate,
109   Err_RemovePort,
110   Err_ChangePin,
111   Nop_SimInitFunc,
112   Nop_SimHitFunc,
113   Generic_PSWrite,
114   Generic_EditProps,
115   Generic_VerSave
116 };
117 
118 
119 /*****************************************************************************
120  *
121  * Generate primitive cell definition for multipliers.
122  *
123  * Parameters:
124  *    f			File to write cell to.
125  *    name		Name of cell to write.
126  *
127  *****************************************************************************/
Mult_WriteCellDef(FILE * f,GCellSpec * gcs)128 static void Mult_WriteCellDef(FILE *f,GCellSpec *gcs)
129 {
130   /** @TODO to remove */
131   /* GGateInfo *gi = gcs->gc_info; */
132   int numBit = gcs->gc_numBits;
133   const char *invSpec = gcs->gc_invSpec;
134   PrimParm primParm;
135   int invP = 0;
136 
137   if (*invSpec == 'N')
138     invP = 1;
139 
140   PrimParm_init(&primParm);
141   PrimParm_rangeSet(&primParm,"AB_RANGE",(numBit+1)/2);
142   PrimParm_rangeSet(&primParm,"P_RANGE",numBit);
143   PrimParm_invSet(&primParm,"invP",invP);
144   Primitive_write(f,"mult",gcs,&primParm);
145 }
146 
init_mult()147 void init_mult()
148 {
149   Pixmap P;
150 
151   P = Pixmap_registerFromFile("mult","mult.b");
152   gateinfo_iconInit(&gate_mult_info,P,mult_iconDims,mult_iconBoldOffset);
153   RegisterGate(&gate_mult_info);
154 }
155