1 // license:BSD-3-Clause
2 // copyright-holders:Couriersud
3 /*****************************************************************************
4 
5     resnet.h
6 
7     Compute weights for resistors networks.
8 
9 *****************************************************************************/
10 
11 /**********************************************************************
12  *      Rbias
13  * Vbias >-ZZZ-.    .-----------------------------------------> Out0
14  *             |    |                           Vcc
15  *          R0 |    |                            |
16  *   In0 >-ZZZ-+----+               Vcc          Z
17  *             |    |                |           Z
18  *          R1 |    |               /            Z
19  *   In1 >-ZZZ-+    +----+----ZZZ--|   NPN       +------------> Out1
20  *             :         |          >           <
21  *             :         |           +----+----|  PNP
22  *          R8 |         |           Z    |     \
23  *   In8 >-ZZZ-+         |           Z    |      |
24  *             |         |           Z    |     Gnd
25  *             Z         |           |    '-------------------> Out2
26  *             Z Rgnd    |          Gnd
27  *             Z         |   |-----------------------|
28  *             |         `---| max(vmin,min(sig-vcut)|--------> Out3
29  *            Gnd            |-----------------------|
30  *
31  *********************************************************************/
32 
33 /* Amplifier stage per channel but may be specified globally as default */
34 
35 #define RES_NET_AMP_USE_GLOBAL      0x0000
36 #define RES_NET_AMP_NONE            0x0001      //Out0
37 #define RES_NET_AMP_DARLINGTON      0x0002      //Out1
38 #define RES_NET_AMP_EMITTER         0x0003      //Out2
39 #define RES_NET_AMP_CUSTOM          0x0004      //Out3
40 #define RES_NET_AMP_MASK            0x0007
41 
42 /* VCC prebuilds - Global */
43 
44 #define RES_NET_VCC_5V              0x0000
45 #define RES_NET_VCC_CUSTOM          0x0008
46 #define RES_NET_VCC_MASK            0x0008
47 
48 /* VBias prebuils - per channel but may be specified globally as default */
49 
50 #define RES_NET_VBIAS_USE_GLOBAL    0x0000
51 #define RES_NET_VBIAS_5V            0x0010
52 #define RES_NET_VBIAS_TTL           0x0020
53 #define RES_NET_VBIAS_CUSTOM        0x0030
54 #define RES_NET_VBIAS_MASK          0x0030
55 
56 /* Input Voltage levels - Global */
57 
58 #define RES_NET_VIN_OPEN_COL        0x0000
59 #define RES_NET_VIN_VCC             0x0100
60 #define RES_NET_VIN_TTL_OUT         0x0200
61 #define RES_NET_VIN_CUSTOM          0x0300
62 #define RES_NET_VIN_MASK            0x0300
63 
64 /* Monitor options */
65 
66 // Just invert the signal
67 #define RES_NET_MONITOR_INVERT      0x1000
68 // SANYO_EZV20 / Nintendo with inverter circuit
69 #define RES_NET_MONITOR_SANYO_EZV20 0x2000
70 // Electrohome G07 Series
71 // 5.6k input impedance
72 #define RES_NET_MONITOR_ELECTROHOME_G07 0x3000
73 
74 #define RES_NET_MONITOR_MASK        0x3000
75 
76 /* General defines */
77 
78 #define RES_NET_CHAN_RED            0x00
79 #define RES_NET_CHAN_GREEN          0x01
80 #define RES_NET_CHAN_BLUE           0x02
81 
82 /* Some aliases */
83 
84 #define RES_NET_VIN_MB7051          RES_NET_VIN_TTL_OUT
85 #define RES_NET_VIN_MB7052          RES_NET_VIN_TTL_OUT
86 #define RES_NET_VIN_MB7053          RES_NET_VIN_TTL_OUT
87 #define RES_NET_VIN_28S42           RES_NET_VIN_TTL_OUT
88 
89 /* Structures */
90 
91 struct res_net_channel_info {
92 	// per channel options
93 	UINT32  options;
94 	// Pullup resistor value in Ohms
95 	double  rBias;
96 	// Pulldown resistor value in Ohms
97 	double  rGnd;
98 	// Number of inputs connected to resistors
99 	INT32     num;
100 	// Resistor values
101 	// - Least significant bit first
102 	double R[8];
103 	// Minimum output voltage
104 	// - Applicable if output is routed through a complimentary
105 	// - darlington circuit
106 	// - typical value ~ 0.9V
107 	double  minout;
108 	// Cutoff output voltage
109 	// - Applicable if output is routed through 1:1 transistor amplifier
110 	// - Typical value ~ 0.7V
111 	double  cut;
112 	// Voltage at the pullup resistor
113 	// - Typical voltage ~5V
114 	double  vBias;
115 };
116 
117 struct res_net_info {
118 	// global options
119 	UINT32  options;
120 	// The three color channels
121 	res_net_channel_info rgb[3];
122 	// Supply Voltage
123 	// - Typical value 5V
124 	double  vcc;
125 	// High Level output voltage
126 	// - TTL : 3.40V
127 	// - CMOS: 4.95V (@5v vcc)
128 	double  vOL;
129 	// Low Level output voltage
130 	// - TTL : 0.35V
131 	// - CMOS: 0.05V (@5v vcc)
132 	double  vOH;
133 	// Open Collector flag
134 	UINT8   OpenCol;
135 };
136 
137 #define RES_NET_MAX_COMP    3
138 
139 struct res_net_decode_info {
140 	INT32 numcomp;
141 	INT32 start;
142 	INT32 end;
143 	UINT16  offset[3 * RES_NET_MAX_COMP];
144 	INT16   shift[3 * RES_NET_MAX_COMP];
145 	UINT16  mask[3 * RES_NET_MAX_COMP];
146 };
147 
148 /* return a single value for one channel */
149 
150 INT32 compute_res_net(INT32 inputs, INT32 channel, const res_net_info &di);
151 
152 /* compute all values */
153 
154 void compute_res_net_all(UINT32 *DrvPal, const UINT8 *prom, const res_net_decode_info &rdi, const res_net_info &di);
155 
156 /* legacy interface */
157 #define MAX_NETS 3
158 #define MAX_RES_PER_NET 18
159 
160 #define combine_8_weights(tab,w0,w1,w2,w3,w4,w5,w6,w7)  ((int)(((tab)[0]*(w0) + (tab)[1]*(w1) + (tab)[2]*(w2) + (tab)[3]*(w3) + (tab)[4]*(w4) + (tab)[5]*(w5) + (tab)[6]*(w6) + (tab)[7]*(w7)) + 0.5))
161 #define combine_7_weights(tab,w0,w1,w2,w3,w4,w5,w6)     ((int)(((tab)[0]*(w0) + (tab)[1]*(w1) + (tab)[2]*(w2) + (tab)[3]*(w3) + (tab)[4]*(w4) + (tab)[5]*(w5) + (tab)[6]*(w6)) + 0.5))
162 #define combine_6_weights(tab,w0,w1,w2,w3,w4,w5)        ((int)(((tab)[0]*(w0) + (tab)[1]*(w1) + (tab)[2]*(w2) + (tab)[3]*(w3) + (tab)[4]*(w4) + (tab)[5]*(w5)) + 0.5))
163 #define combine_5_weights(tab,w0,w1,w2,w3,w4)           ((int)(((tab)[0]*(w0) + (tab)[1]*(w1) + (tab)[2]*(w2) + (tab)[3]*(w3) + (tab)[4]*(w4)) + 0.5))
164 #define combine_4_weights(tab,w0,w1,w2,w3)              ((int)(((tab)[0]*(w0) + (tab)[1]*(w1) + (tab)[2]*(w2) + (tab)[3]*(w3)) + 0.5))
165 #define combine_3_weights(tab,w0,w1,w2)                 ((int)(((tab)[0]*(w0) + (tab)[1]*(w1) + (tab)[2]*(w2)) + 0.5))
166 #define combine_2_weights(tab,w0,w1)                    ((int)(((tab)[0]*(w0) + (tab)[1]*(w1)) + 0.5))
167 
168 double compute_resistor_weights(INT32 minval, INT32 maxval, double scaler, INT32 count_1, const INT32 * resistances_1, double * weights_1, INT32 pulldown_1, INT32 pullup_1, INT32 count_2, const INT32 * resistances_2, double * weights_2, INT32 pulldown_2, INT32 pullup_2, INT32 count_3, const INT32 * resistances_3, double * weights_3, INT32 pulldown_3, INT32 pullup_3);
169 
170 /* for the open collector outputs PROMs */
171 
172 double compute_resistor_net_outputs(
173 	INT32 minval, INT32 maxval, double scaler,
174 	INT32 count_1, const INT32 * resistances_1, double * outputs_1, INT32 pulldown_1, INT32 pullup_1,
175 	INT32 count_2, const INT32 * resistances_2, double * outputs_2, INT32 pulldown_2, INT32 pullup_2,
176 	INT32 count_3, const INT32 * resistances_3, double * outputs_3, INT32 pulldown_3, INT32 pullup_3 );
177 
178