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 Sep 26 18:24:54 2009
19 ****************************************************************************/
20 #include <string.h>
21 #include "tkgate.h"
22 
23 static void Rom_WriteCellDef(FILE *f,GCellSpec *gcs);
24 
25 
26 static iconDimensions rom_iconDims[] = {
27   {0,  0,   34, 49, 17, 23},
28   {35, 0,   49, 34, 23, 16},
29   {50, 35,  34, 49, 16, 25},
30   {0,  50,  49, 34, 25, 17},
31 };
32 static int rom_iconBoldOffset = 85;
33 
34 GCElement *RamRom_Make(EditState **es,GModuleDef *env,int GType,
35 		    int x,int y,int r,const char *Name,int noWires,const char **options,int nOptions);
36 int RamRom_EditProps(GCElement *g,int isLoadDialog);
37 void RamRom_SetProp(GCElement*,const char*,const void*);
38 int RamRom_SimHitFunc(EditState *es,GCElement *g);
39 void RamRom_VerSave(FILE *f,GCElement *g);
40 
41 #define ROM_A 0
42 #define ROM_D 1
43 #define ROM_OE 2
44 
45 GPadLoc rom_A_loc[] = {
46   {-18, 1, -18, 1, D_LEFT},
47   {1, 18, 1, 18, D_DOWN},
48   {18, -1, 18, -1, D_RIGHT},
49   {-1, -18, -1, -18, D_UP}
50 };
51 
52 GPadLoc rom_D_loc[] = {
53   {17, -1, 17, -1, D_RIGHT},
54   {-1, -17, -1, -17, D_UP},
55   {-17, 1, -17, 1, D_LEFT},
56   {1, 17, 1, 17, D_DOWN}
57 
58 };
59 GPadLoc rom_oe_loc[] = {
60  {0, 26, 0, 26, D_DOWN},
61  {26, 0, 26, 7, D_RIGHT},
62  {0, -26, 0, -26, D_UP},
63  {-26, 0, -26, 0, D_LEFT}
64 };
65 
66 static char *psRom[] = {
67   "%",
68   "% x y r psrom",
69   "%",
70   "/psrom {",
71   "  startgate",
72   "  -17.5 23.5 moveto",
73   "  16.5 23.5 lineto",
74   "  16.5 -25.5 lineto",
75   "  -17.5 -25.5 lineto",
76   "  closepath stroke",
77   "  8 rfont",
78   "  -15 -2 moveto (A) show",
79   "  5 -2 moveto (D) show",
80   "  6 rfont",
81   "  (_oe) -4 -23 prshow",
82   "  grestore",
83   "} def",
84   0
85 };
86 
87 GGateInfo gate_rom_info = {
88   GC_ROM,
89   "ROM",
90   "rom",0x0,
91   "psrom",psRom,
92   -1,-1,
93 
94   {{"u",	{"gm.mem",5},		{"gm.mem.rom",0,"mem",200},	"gat_make ROM"},
95    {0}},
96 
97 
98   rom_iconDims,
99 
100   3,{{"A",IN,8,1,rom_A_loc},
101        {"D",TRI,8,1,rom_D_loc},
102        {"OE",IN,1,1,rom_oe_loc}},
103   {{10,-30,RJ},{10,-30,RJ},{10,-30,RJ},{10,-30,RJ}},
104   {1},
105 
106   {"Dout","Dread",0},
107 
108   RamRom_Make,
109   Rom_WriteCellDef,
110   Generic_Init,
111   Generic_Delete,
112   Generic_GetExtents,
113   Generic_HitDistance,
114   Generic_Draw,
115   Generic_Move,
116   Generic_Copy,
117   Err_AddInput,
118   Err_AddOutput,
119   Err_AddInOut,
120   Generic_Rotate,
121   Err_RemovePort,
122   Err_ChangePin,
123   Nop_SimInitFunc,
124   RamRom_SimHitFunc,
125   Generic_PSWrite,
126   RamRom_EditProps,
127   RamRom_VerSave,
128   RamRom_SetProp
129 };
130 
131 /*****************************************************************************
132  *
133  * Generate primitive cell definition for roms.
134  *
135  * Parameters:
136  *    f			File to write cell to.
137  *    name		Name of cell to write.
138  *
139  *****************************************************************************/
Rom_WriteCellDef(FILE * f,GCellSpec * gcs)140 static void Rom_WriteCellDef(FILE *f,GCellSpec *gcs)
141 {
142   /** @TODO to check for necessity */
143   /* GGateInfo *gi = gcs->gc_info; */
144   int AnumBits = gcs->gc_multiPad;	/* Hack for ROM/RAM gates */
145   int DnumBits = gcs->gc_numBits;
146   const char *invSpec = gcs->gc_invSpec;
147   PrimParm primParm;
148 
149   PrimParm_init(&primParm);
150   PrimParm_rangeSet(&primParm,"A_RANGE",AnumBits);
151   PrimParm_rangeSet(&primParm,"D_RANGE",DnumBits);
152   PrimParm_set(&primParm,"MEM_RANGE","[0:%u]",(1 << AnumBits) - 1);
153   PrimParm_intSet(&primParm,"D_BITS",DnumBits);
154   PrimParm_invSet(&primParm,"invD",(*invSpec == 'N'));
155   Primitive_write(f,"rom",gcs,&primParm);
156 }
157 
init_rom()158 void init_rom()
159 {
160   Pixmap P;
161 
162   P = Pixmap_registerFromFile("rom","rom.b");
163   gateinfo_iconInit(&gate_rom_info,P,rom_iconDims,rom_iconBoldOffset);
164   RegisterGate(&gate_rom_info);
165 }
166