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 #include "tkgate.h"
19 
20 GCElement *AOX_Make(EditState **,GModuleDef *,int,int,int,int,const char *,int,const char**,int);
21 void AOX_Draw(GCElement *g,int md);
22 void AOX_AddInput(EditState *es,GCElement*);
23 void AOX_VerSave(FILE*,GCElement*);
24 void AOX_SetProp(GCElement*,const char*,const void*);
25 int AOX_EditProps(GCElement *g,int isLoadDialog);
26 void AOX_PSWrite(GPrint *P,GModLayout*,GCElement *g);
27 void AOX_RemovePort(EditState *es,GCElement *g,GWire *);
28 GCElement *AOX_Copy(GModuleDef *M,GCElement *g,int x,int y,unsigned flags);
29 void AOX_WriteCellDef(FILE *f,GCellSpec *gcs);
30 
31 static iconDimensions xor_iconDims[] = {
32   {0, 0, 24, 15, 12, 7},
33   {25, 0, 15, 24, 7, 9},
34   {16, 25, 24, 15, 11, 7},
35   {0, 16, 15, 24, 7, 14},
36 };
37 static int xor_iconBoldOffset = 41;
38 
39 extern GPadLoc and_out_loc[];
40 extern GPadLoc and_in_loc[];
41 
42 static char *psXOr[] = {
43   "%",
44   "% 'OR' part of XOR gate",
45   "%",
46   "/base_xor {",
47   "  startgate",
48   "  -10 -7 moveto",
49   "  -5 7 14 -90 -30 arc",
50   "  -5 -7 14 30 90 arc",
51   "  14 theight neg 11 sub 0 14 30 -30 arcn",
52   "  closepath",
53   "  stroke",
54   "  grestore",
55   "} bind def",
56   "%",
57   "% An XOR Gate",
58   "%",
59   "/psxor {",
60   "  startgate",
61   "  3 0 0 base_xor",
62   "  14 theight neg 11 sub 0 14 30 -30 arcn",
63   "  stroke",
64   "  grestore",
65   "} bind def",
66   0
67 };
68 
69 GGateInfo gate_xor_info = {
70   0,
71   "XOR",
72   "xor:xnor",0x2,
73   "psxor",psXOr,
74   0,0,
75 
76   {{"x",	{"gm.gate",0},		{"gm.gate.xor",0,0,300},	"gat_make XOR"},
77    {"X",	{"gm.gate",0},		{"gm.gate.xnor",0,0,301},	"gat_make XOR -invert Z"},
78    {"Ctl-r x",	{"gm.rgate",0},		{"gm.rgate.xor",0,0,300},	"gat_make XOR -pins I=1"},
79    {"Ctl-r X",	{"gm.rgate",0},		{"gm.rgate.xnor",0,0,301},	"gat_make XOR -pins I=1 -invert Z"},
80    {0}},
81 
82   xor_iconDims,
83 
84   2,{{"I",IN,1,2,and_in_loc,1},{"Z",OUT,1,1,and_out_loc,0}},
85   {{0,-12,CT},{12,0,LJ},{0,-12,CT},{12,0,LJ}},
86   {1},
87 
88   {"Diz",0},
89 
90   AOX_Make,
91   AOX_WriteCellDef,
92   Generic_Init,
93   Generic_Delete,
94   Generic_GetExtents,
95   Generic_HitDistance,
96   AOX_Draw,
97   Generic_Move,
98   AOX_Copy,
99   AOX_AddInput,
100   Err_AddOutput,
101   Err_AddInOut,
102   Generic_Rotate,
103   AOX_RemovePort,
104   Err_ChangePin,
105   Nop_SimInitFunc,
106   Nop_SimHitFunc,
107   AOX_PSWrite,
108   AOX_EditProps,
109   AOX_VerSave,
110   AOX_SetProp
111 };
112 
init_xor()113 void init_xor()
114 {
115   Pixmap P;
116   P = Pixmap_registerFromFile("xor","xor.b");
117   gateinfo_iconInit(&gate_xor_info,P,xor_iconDims,xor_iconBoldOffset);
118   RegisterGate(&gate_xor_info);
119 }
120