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:48 2009
19 ****************************************************************************/
20 #include "tkgate.h"
21 
22 #define ARSHIFT_IN 0
23 #define ARSHIFT_OUT 1
24 #define ARSHIFT_SHIFT 2
25 
26 void Shift_WriteCellDef(FILE *f,GCellSpec *gcs);
27 
28 static iconDimensions arshift_iconDims[] = {
29   {0, 21, 75, 20, 36, 9},
30   {76, 0, 20, 75, 10, 37},
31   {0,  0, 75, 20, 36, 9},
32   {97, 0, 20, 75, 10, 37},
33 };
34 static int arshift_iconBoldOffset = 76;
35 
36 
37 GPadLoc arshifter_in_loc[] = {
38 	{0,-10,0,-10,D_UP},
39 	{-11,0,-11,0,D_LEFT},
40 	{0,11,0,11,D_DOWN},
41 	{10,0,10,0,D_RIGHT}};
42 
43 GPadLoc arshifter_out_loc[] = {
44 	{0,11,0,11,D_DOWN},
45 	{10,0,10,0,D_RIGHT},
46 	{0,-10,0,-10,D_UP},
47 	{-11,0,-11,0,D_LEFT}};
48 
49 GPadLoc arshifter_shift_loc[] = {
50 	{-37,0,-37,0,D_LEFT},
51 	{0,38,0,38,D_DOWN},
52 	{39,0,39,0,D_RIGHT},
53 	{0,-38,0,-38,D_UP}};
54 
55 static char *psArshifter[] = {
56   "%",
57   "% A Arshifter",
58   "%",
59   "/psarshift {",
60   "  [[0 .5][-.5 .5][2 0.5][0 -.5]] adjstartgate",
61   "  -31 -10.5 moveto",
62   "  -37.5 -5 lineto",
63   "  -37.5 4 lineto",
64   "  -31 10.5 lineto",
65   "  31 10.5 lineto",
66   "  37.5 4 lineto",
67   "  37.5 -5 lineto",
68   "  31 -10.5 lineto",
69   "  closepath stroke",
70   "  -7 2 moveto",
71   "  3 2 lineto",
72   "  3 5 lineto",
73   "  9 0 lineto",
74   "  3 -5 lineto",
75   "  3 -2 lineto",
76   "  -7 -2 lineto",
77   "  closepath fill",
78   "  -9 2 moveto -11 2 lineto",
79   "  -11 -2 lineto -9 -2 lineto",
80   "  closepath fill",
81   "  -9 3 moveto",
82   "  -9 6 lineto",
83   "  -7 6 lineto",
84   "",
85   "  -7 4 lineto",
86   "  -8 4 lineto",
87   "  -6 3 lineto",
88   "  -4 4 lineto",
89   "  -5 4 lineto",
90   "",
91   "  -5 8 lineto",
92   "  -11 8 lineto",
93   "  -11 3 lineto",
94   "  closepath fill",
95   "  grestore",
96   "} def",
97   0
98 };
99 
100 GGateInfo gate_arshifter_info = {
101   0,
102   "ARSHIFT",
103   "arshift",0x0,
104   "psarshift",psArshifter,
105   -1,1,
106 
107   {{"S A",	{"gm.alu",0},		{"gm.alu.arshift",0,"shift",300},	"gat_make ARSHIFT"},
108    {0}},
109 
110   arshift_iconDims,
111 
112   3,{{"I",IN,8,1,arshifter_in_loc},
113        {"Z",OUT,8,1,arshifter_out_loc},
114        {"S",IN,3,1,arshifter_shift_loc}},
115   {{12,-12,LJ},{12,-12,LJ},{12,-12,LJ},{12,-12,LJ}},
116   {1},
117 
118   {"Dsz","Diz",0},
119 
120   Generic_Make,
121   Shift_WriteCellDef,
122   Generic_Init,
123   Generic_Delete,
124   Generic_GetExtents,
125   Generic_HitDistance,
126   Generic_Draw,
127   Generic_Move,
128   Generic_Copy,
129   Err_AddInput,
130   Err_AddOutput,
131   Err_AddInOut,
132   Generic_Rotate,
133   Err_RemovePort,
134   Err_ChangePin,
135   Nop_SimInitFunc,
136   Nop_SimHitFunc,
137   Generic_PSWrite,
138   Generic_EditProps,
139   Generic_VerSave
140 };
141 
Shift_WriteCellDef(FILE * f,GCellSpec * gcs)142 void Shift_WriteCellDef(FILE *f,GCellSpec *gcs)
143 {
144   GGateInfo *gi = gcs->gc_info;
145   int numBits = gcs->gc_numBits;
146   const char *invSpec = gcs->gc_invSpec;
147   int shiftSelBits = required_bits(numBits);
148   const char *op = "arshift";
149   PrimParm primParm;
150 
151   if (strcmp(gi->name,"RSHIFT") == 0)
152     op = "rshift";
153   else if (strcmp(gi->name,"LSHIFT") == 0)
154     op = "lshift";
155 
156   PrimParm_init(&primParm);
157   PrimParm_rangeSet(&primParm,"IZ_RANGE",numBits);
158   PrimParm_rangeSet(&primParm,"S_RANGE",shiftSelBits);
159   PrimParm_invSet(&primParm,"invZ",(*invSpec == 'N'));
160   Primitive_write(f,op,gcs,&primParm);
161 }
162 
init_arshift()163 void init_arshift()
164 {
165   Pixmap P;
166 
167   P = Pixmap_registerFromFile("arshift","arshift.b");
168   gateinfo_iconInit(&gate_arshifter_info,P,arshift_iconDims,arshift_iconBoldOffset);
169   RegisterGate(&gate_arshifter_info);
170 }
171