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:17:34 2009
19 ****************************************************************************/
20 #include "tkgate.h"
21 
22 #define ROLL_IN 0
23 #define ROLL_OUT 1
24 #define ROLL_SHIFT 2
25 
26 static void Roll_WriteCellDef(FILE *f,GCellSpec *gcs);
27 
28 static iconDimensions roll_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 roll_iconBoldOffset = 76;
35 
36 
37 GPadLoc roller_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 roller_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 roller_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 *psRoller[] = {
56   "%",
57   "% A Roller",
58   "/psroll {",
59   "  [[0 .5][-.5 .5][2 0.5][0 -.5]] adjstartgate",
60   "  -31 -10.5 moveto",
61   "  -37.5 -5 lineto",
62   "  -37.5 4 lineto",
63   "  -31 10.5 lineto",
64   "  31 10.5 lineto",
65   "  37.5 4 lineto",
66   "  37.5 -5 lineto",
67   "  31 -10.5 lineto",
68   "  closepath stroke",
69   "  2 setlinewidth",
70   "  newpath",
71   "  0 0 6 20 340 arc stroke",
72   "  30 rotate",
73   "  4 0 translate",
74   "  -70 rotate",
75   "  -1.5 0 moveto 1.5 0 lineto",
76   "  0 3 lineto closepath stroke",
77   "  grestore",
78   "} def",
79   0
80 };
81 
82 GGateInfo gate_roller_info = {
83   0,
84   "ROLL",
85   "roll",0x0,
86   "psroll",psRoller,
87   -1,1,
88 
89   {{"S O",	{"gm.alu",0},		{"gm.alu.roll",0,"shift",400},	"gat_make ROLL"},
90    {0}},
91 
92 
93   roll_iconDims,
94 
95   3,{{"I",IN,8,1,roller_in_loc},
96        {"Z",OUT,8,1,roller_out_loc},
97        {"S",IN,3,1,roller_shift_loc}},
98   {{12,-12,LJ},{12,-12,LJ},{12,-12,LJ},{12,-12,LJ}},
99   {1},
100 
101   {"Dsz","Diz",0},
102 
103   Generic_Make,
104   Roll_WriteCellDef,
105   Generic_Init,
106   Generic_Delete,
107   Generic_GetExtents,
108   Generic_HitDistance,
109   Generic_Draw,
110   Generic_Move,
111   Generic_Copy,
112   Err_AddInput,
113   Err_AddOutput,
114   Err_AddInOut,
115   Generic_Rotate,
116   Err_RemovePort,
117   Err_ChangePin,
118   Nop_SimInitFunc,
119   Nop_SimHitFunc,
120   Generic_PSWrite,
121   Generic_EditProps,
122   Generic_VerSave
123 };
124 
125 
Roll_WriteCellDef(FILE * f,GCellSpec * gcs)126 static void Roll_WriteCellDef(FILE *f,GCellSpec *gcs)
127 {
128   /** @TODO to check for necessity */
129   /* GGateInfo *gi = gcs->gc_info; */
130   int numBits = gcs->gc_numBits;
131   const char *invSpec = gcs->gc_invSpec;
132   int shiftSelBits = required_bits(numBits);
133   PrimParm primParm;
134 
135 
136   PrimParm_init(&primParm);
137   PrimParm_rangeSet(&primParm,"IZ_RANGE",numBits);
138   PrimParm_intSet(&primParm,"IZ_BITS",numBits);
139   PrimParm_rangeSet(&primParm,"S_RANGE",shiftSelBits);
140   PrimParm_invSet(&primParm,"invZ",(*invSpec == 'N'));
141   Primitive_write(f,"roll",gcs,&primParm);
142 }
143 
init_roll()144 void init_roll()
145 {
146   Pixmap P;
147 
148   P = Pixmap_registerFromFile("roll","roll.b");
149   gateinfo_iconInit(&gate_roller_info,P,roll_iconDims,roll_iconBoldOffset);
150   RegisterGate(&gate_roller_info);
151 }
152