summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/video/resnet.h
blob: acc62bece79b0d5204b63c63c82d46fb802395ee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// license:BSD-3-Clause
// copyright-holders:Couriersud
/*****************************************************************************

    resnet.h

    Compute weights for resistors networks.

*****************************************************************************/

#ifndef MAME_EMU_VIDEO_RESNET_H
#define MAME_EMU_VIDEO_RESNET_H

#pragma once

/**********************************************************************
 *      Rbias
 * Vbias >-ZZZ-.    .-----------------------------------------> Out0
 *             |    |                           Vcc
 *          R0 |    |                            |
 *   In0 >-ZZZ-+----+               Vcc          Z
 *             |    |                |           Z
 *          R1 |    |               /            Z
 *   In1 >-ZZZ-+    +----+----ZZZ--|   NPN       +------------> Out1
 *             :         |          >           <
 *             :         |           +----+----|  PNP
 *          R8 |         |           Z    |     \
 *   In8 >-ZZZ-+         |           Z    |      |
 *             |         |           Z    |     Gnd
 *             Z         |           |    '-------------------> Out2
 *             Z Rgnd    |          Gnd
 *             Z         |   |-----------------------|
 *             |         `---| max(vmin,min(sig-vcut)|--------> Out3
 *            Gnd            |-----------------------|
 *
 *********************************************************************/

/* Amplifier stage per channel but may be specified globally as default */

#define RES_NET_AMP_USE_GLOBAL      0x0000
#define RES_NET_AMP_NONE            0x0001      //Out0
#define RES_NET_AMP_DARLINGTON      0x0002      //Out1
#define RES_NET_AMP_EMITTER         0x0003      //Out2
#define RES_NET_AMP_CUSTOM          0x0004      //Out3
#define RES_NET_AMP_MASK            0x0007

/* VCC prebuilds - Global */

#define RES_NET_VCC_5V              0x0000
#define RES_NET_VCC_CUSTOM          0x0008
#define RES_NET_VCC_MASK            0x0008

/* VBias prebuilds - per channel but may be specified globally as default */

#define RES_NET_VBIAS_USE_GLOBAL    0x0000
#define RES_NET_VBIAS_5V            0x0010
#define RES_NET_VBIAS_TTL           0x0020
#define RES_NET_VBIAS_CUSTOM        0x0030
#define RES_NET_VBIAS_MASK          0x0030

/* Input Voltage levels - Global */

#define RES_NET_VIN_OPEN_COL        0x0000
#define RES_NET_VIN_VCC             0x0100
#define RES_NET_VIN_TTL_OUT         0x0200
#define RES_NET_VIN_CUSTOM          0x0300
#define RES_NET_VIN_MASK            0x0300

/* Monitor options */

// Just invert the signal
#define RES_NET_MONITOR_INVERT      0x1000
// SANYO_EZV20 / Nintendo with inverter circuit
#define RES_NET_MONITOR_SANYO_EZV20 0x2000
// Electrohome G07 Series
// 5.6k input impedance
#define RES_NET_MONITOR_ELECTROHOME_G07 0x3000

#define RES_NET_MONITOR_MASK        0x3000

/* General defines */

#define RES_NET_CHAN_RED            0x00
#define RES_NET_CHAN_GREEN          0x01
#define RES_NET_CHAN_BLUE           0x02

/* Some aliases */

#define RES_NET_VIN_MB7051          RES_NET_VIN_TTL_OUT
#define RES_NET_VIN_MB7052          RES_NET_VIN_TTL_OUT
#define RES_NET_VIN_MB7053          RES_NET_VIN_TTL_OUT
#define RES_NET_VIN_28S42           RES_NET_VIN_TTL_OUT

/* Structures */

struct res_net_channel_info {
	// per channel options
	u32     options;
	// Pullup resistor value in Ohms
	double  rBias;
	// Pulldown resistor value in Ohms
	double  rGnd;
	// Number of inputs connected to resistors
	int     num;
	// Resistor values
	// - Least significant bit first
	double  R[8];
	// Minimum output voltage
	// - Applicable if output is routed through a complimentary
	// - darlington circuit
	// - typical value ~ 0.9V
	double  minout;
	// Cutoff output voltage
	// - Applicable if output is routed through 1:1 transistor amplifier
	// - Typical value ~ 0.7V
	double  cut;
	// Voltage at the pullup resistor
	// - Typical voltage ~5V
	double  vBias;
};

struct res_net_info {
	// global options
	u32     options;
	// The three color channels
	res_net_channel_info rgb[3];
	// Supply Voltage
	// - Typical value 5V
	double  vcc;
	// High Level output voltage
	// - TTL : 3.40V
	// - CMOS: 4.95V (@5v vcc)
	double  vOL;
	// Low Level output voltage
	// - TTL : 0.35V
	// - CMOS: 0.05V (@5v vcc)
	double  vOH;
	// Open Collector flag
	u8      OpenCol;
};

#define RES_NET_MAX_COMP    3

struct res_net_decode_info {
	int numcomp;
	int start;
	int end;
	u16 offset[3 * RES_NET_MAX_COMP];
	s16 shift[3 * RES_NET_MAX_COMP];
	u16 mask[3 * RES_NET_MAX_COMP];
};

/* return a single value for one channel */

int compute_res_net(int inputs, int channel, const res_net_info &di);

/* compute all values */

void compute_res_net_all(std::vector<rgb_t> &rgb, const u8 *prom, const res_net_decode_info &rdi, const res_net_info &di);


/* legacy interface */

namespace emu { namespace detail {

template <std::size_t I, typename T, std::size_t N, typename U>
constexpr auto combine_weights(T const (&tab)[N], U w) { return tab[I] * w; }

template <std::size_t I, typename T, std::size_t N, typename U, typename... V>
constexpr auto combine_weights(T const (&tab)[N], U w0, V... w) { return (tab[I] * w0) + combine_weights<I + 1>(tab, w...); }

} } // namespace emu::detail

double compute_resistor_weights(
		int minval, int maxval, double scaler,
		int count_1, const int * resistances_1, double * weights_1, int pulldown_1, int pullup_1,
		int count_2, const int * resistances_2, double * weights_2, int pulldown_2, int pullup_2,
		int count_3, const int * resistances_3, double * weights_3, int pulldown_3, int pullup_3);

template <typename T = int, typename U, std::size_t N, typename... V>
constexpr T combine_weights(U const (&tab)[N], V... w)
{
	return T(emu::detail::combine_weights<0U>(tab, w...) + 0.5);
}



/* this should be moved to one of the core files */

#define MAX_NETS 3
#define MAX_RES_PER_NET 18




/* for the open collector outputs PROMs */

double compute_resistor_net_outputs(
		int minval, int maxval, double scaler,
		int count_1, const int * resistances_1, double * outputs_1, int pulldown_1, int pullup_1,
		int count_2, const int * resistances_2, double * outputs_2, int pulldown_2, int pullup_2,
		int count_3, const int * resistances_3, double * outputs_3, int pulldown_3, int pullup_3 );



#endif /* MAME_EMU_VIDEO_RESNET_H */