1 // license:BSD-3-Clause
2 // copyright-holders:K.Wilkins,Couriersud,Derrick Renaud,Frank Palazzolo
3 #ifndef MAME_SOUND_DISCRETE_H
4 #define MAME_SOUND_DISCRETE_H
5 
6 #pragma once
7 
8 #include "machine/rescap.h"
9 
10 #include <vector>
11 
12 
13 /***********************************************************************
14  *
15  *  MAME - Discrete sound system emulation library
16  *
17  *  Written by K.Wilkins (mame@esplexo.co.uk)
18  *
19  *  (c) K.Wilkins 2000
20  *
21  *  Coding started in November 2000
22  *
23  *  Additions/bugfix February 2003 - Derrick Renaud, F.Palazzolo, K.Wilkins
24  *  Discrete parallel tasks 2009 - Couriersud
25  *
26  ***********************************************************************
27  *
28  * For free text books on electronic theory check out:
29  * http://www.ibiblio.org/obp/electricCircuits/
30  * For a free circuit simulator:
31  * http://qucs.sourceforge.net/index.html
32  * For a free waveform editor to view DISCRETE_WAVLOG dumps:
33  * http://audacity.sourceforge.net/
34  * http://www.sonicvisualiser.org/
35  *
36  ***********************************************************************
37  *
38  * Currently only one instance of a discrete sound system is supported.
39  * If more then one instance is required in the future, then a chip #
40  * will have to be added to the read/writes and the discrete inputs
41  * modified to match.  This functionality should never be needed.
42  * There is no real need to run more then 1 discrete system.
43  *
44  * If a clock is specified in the machine driver setup, then this is
45  * used for the simulation sample rate.  Otherwise it will default to
46  * run at the audio sample rate.
47  *
48  * Unused/Unconnected input nodes should be set to NODE_NC (No Connect)
49  *
50  * Each node can have many inputs from either constants or other
51  * nodes within the system.
52  *
53  * It should be remembered that the discrete sound system emulation
54  * does not do individual device emulation, but instead does a function
55  * emulation. So you will need to convert the schematic design into
56  * a logic block representation.
57  *
58  * There is the possibility to support multiple outputs per module.
59  * In this case, NODE_XXX is the default output. Alternative outputs may
60  * be accessed by using NODE_XXX_YY where 00<=Y<08.
61  *
62  * You may also access nodes with a macros:
63  *
64  *     NODE_XXX = NODE_SUB(NODE_XXX, 0)
65  *     NODE_XXX = NODE_XXX_00
66  *     NODE_XXX = NODE(XXX)
67  *     NODE_XXX_YY = NODE_SUB(NODE_XXX, YY)
68  *
69  * One node point may feed a number of inputs, for example you could
70  * connect the output of a DISCRETE_SINEWAVE to the AMPLITUDE input
71  * of another DISCRETE_SINEWAVE to amplitude modulate its output and
72  * also connect it to the frequency input of another to frequency
73  * modulate its output, the combinations are endless....
74  *
75  * Consider the circuit below:
76  *
77  *  .--------.             .----------.                 .-------.
78  *  |        |             |          |                 |       |
79  *  | SQUARE |       Enable| SINEWAVE |                 |       |
80  *  | WAVE   |-+---------->|  2000Hz  |---------------->|       |
81  *  |        | |           |          |                 | ADDER |-->OUT
82  *  | NODE11 | |           |  NODE12  |                 |       |
83  *  '--------' |           '----------'              .->|       |
84  *             |                                     |  |NODE20 |
85  *             |  .------.              .---------.  |  '-------'
86  *             |  |Logic |              |         |  |       ^
87  *             |  | INV  |       Enable | SINEWVE |  |       |
88  *             '->| ERT  |------------->| 4000Hz  |--'  .-------.
89  *                |      |              |         |     |       |
90  *                |NODE13|              | NODE14  |     | INPUT |
91  *                '------'              '---------'     |       |
92  *                                                      |NODE01 |
93  *                                                      '-------'
94  *
95  * This should give you an alternating two tone sound switching
96  * between the 2000Hz and 4000Hz sine waves at the frequency of the
97  * square wave, with the memory mapped enable signal mapped onto NODE07
98  * so discrete_sound_w(NODE_01,1) will enable the sound, and
99  * discrete_sound_w(NODE_01,0) will disable the sound.
100  *
101  *  DISCRETE_SOUND_START(test_interface)
102  *      DISCRETE_INPUT_LOGIC(NODE_01)
103  *      DISCRETE_SQUAREWFIX(NODE_11, 1, 0.5, 1, 50, 1.0/2, 0)   // Output 0:1
104  *      DISCRETE_SINEWAVE(NODE_12, NODE_11, 2000, 10000, 0, 0)
105  *      DISCRETE_LOGIC_INVERT(NODE_13, NODE_11)
106  *      DISCRETE_SINEWAVE(NODE_14, NODE_13, 4000, 10000, 0, 0)
107  *      DISCRETE_ADDER2(NODE_20, NODE_01, NODE_12, NODE_14)
108  *      DISCRETE_OUTPUT(NODE_20, 1)
109  *  DISCRETE_SOUND_END
110  *
111  * To aid simulation speed it is preferable to use the enable/disable
112  * inputs to a block rather than setting the output amplitude to zero
113  *
114  * Feedback loops are allowed BUT they will always feedback one time
115  * step later, the loop over the netlist is only performed once per
116  * deltaT so feedback occurs in the next deltaT step. This is not
117  * the perfect solution but saves repeatedly traversing the netlist
118  * until all nodes have settled.
119  *
120  * The best way to work out your system is generally to use a pen and
121  * paper to draw a logical block diagram like the one above, it helps
122  * to understand the system ,map the inputs and outputs and to work
123  * out your node numbering scheme.
124  *
125  * Node numbers NODE_01 to NODE_299 are defined at present.
126  *
127  * It is recommended to put all Inputs at the start of the interface.
128  * That way they are updated first.
129  *
130  * Each sound effects final node should come after all nodes that
131  * create it.  The final mixing of all sound effects should come
132  * at the end of the interface.
133  *
134  ***********************************************************************
135  *
136  * x_time - ANTI-ALIASING features.
137  *
138  * Certain modules make use of x_time.  This is a feature that passes
139  * information between modules about how long in the current sample, the
140  * switch in state happened.  This is a decimal value of the % of the
141  * full sample period that it has been in the new state.
142  * 0 means it has been at the same state the whole sample.
143  *
144  * Example: Here is the output of a clock source with x_time on the
145  *          output.  The square wave is the real world waveform we
146  *          want.  The ^'s are the sample point.  The numbers under
147  *          the ^'s are the node output with the logic state left of
148  *          the decimal and the x_time to the right.  Under that is
149  *          what the node's anti-aliased output energy would be.
150  *          Note: the example is not 4x sampling so the energy
151  *                does not provide an accurate representation of the
152  *                original waveform.  This is intentional so it fits
153  *                in this header file.
154  *  1      ____    ____    ____    ____    ____    ____    ____    ____
155  *  0   ___    ____    ____    ____    ____    ____    ____    ____    __
156  *        ^....^....^....^....^....^....^....^....^....^....^....^....^
157  *   x_time   0.2  1.4  0.6  1.8  1.2  0.4  1.6  0.8  0.2  1.4  0.6
158  *   energy   0.8  0.4  0.4  0.8  0.2  0.6  0.6  0.2  0.8  0.4  0.4
159  *
160  * Some modules will just pass the x_time onto another module.
161  *
162  * Modules that process x_time will keep track of the node's previous
163  * state so they can calculate the actual energy at the sample time.
164  *
165  * Example: Say we have a 555 module that outputs a clock with x_time
166  *          that is connected to a counter.  The output of the counter
167  *          is connected to DAC_R1.
168  *          In this case the counter module continues counting dependant
169  *          on the integer portion of the 555 output.  But it also
170  *          passes the decimal portion as the x_time.
171  *          The DAC_R1 then uses this info to anti-alias its output.
172  *          Consider the following counter outputs vs DAC_R1
173  *          calculations.  The count changes from 9 to 10.  It has
174  *          been at the new state for 75% of the sample.
175  *
176  *          counter    binary   x_time    -- DAC_R1 bit energy --
177  *            out       count              D3    D2    D1    D0
178  *            9.0       1001     0.0      1.0   0.0   0.0   1.0
179  *           10.75      1010     0.75     1.0   0.0   0.75  0.25
180  *           10.0       1010     0.0      1.0   0.0   1.0   0.0
181  *
182  *           The DAC_R1 uses these energy calculations to scale the
183  *           voltages created on each of its resistors.  This
184  *           anti-aliases the waveform no mater what the resistor
185  *           weighting is.
186  *
187  ***********************************************************************
188  *
189  * LIST OF CURRENTLY IMPLEMENTED DISCRETE BLOCKS
190  * ---------------------------------------------
191  *
192  * DISCRETE_SOUND_START(STRUCTURENAME)
193  * DISCRETE_SOUND_END
194  *
195  * DISCRETE_ADJUSTMENT(NODE,MIN,MAX,LOGLIN,TAG)
196  * DISCRETE_ADJUSTMENTX(NODE,MIN,MAX,LOGLIN,TAG,PMIN,PMAX)
197  * DISCRETE_CONSTANT(NODE,CONST0)
198  * DISCRETE_INPUT_DATA(NODE)
199  * DISCRETE_INPUTX_DATA(NODE,GAIN,OFFSET,INIT)
200  * DISCRETE_INPUT_LOGIC(NODE)
201  * DISCRETE_INPUTX_LOGIC(NODE,GAIN,OFFSET,INIT)
202  * DISCRETE_INPUT_NOT(NODE)
203  * DISCRETE_INPUTX_NOT(NODE,GAIN,OFFSET,INIT)
204  * DISCRETE_INPUT_PULSE(NODE,INIT)
205  * DISCRETE_INPUT_STREAM(NODE, NUM)
206  * DISCRETE_INPUTX_STREAM(NODE,NUM, GAIN,OFFSET)
207  *
208  * DISCRETE_COUNTER(NODE,ENAB,RESET,CLK,MIN,MAX,DIR,INIT0,CLKTYPE)
209  * DISCRETE_COUNTER_7492(NODE,ENAB,RESET,CLK,CLKTYPE)
210  * DISCRETE_LFSR_NOISE(NODE,ENAB,RESET,CLK,AMPL,FEED,BIAS,LFSRTB)
211  * DISCRETE_NOISE(NODE,ENAB,FREQ,AMP,BIAS)
212  * DISCRETE_NOTE(NODE,ENAB,CLK,DATA,MAX1,MAX2,CLKTYPE)
213  * DISCRETE_SAWTOOTHWAVE(NODE,ENAB,FREQ,AMP,BIAS,GRADIENT,PHASE)
214  * DISCRETE_SINEWAVE(NODE,ENAB,FREQ,AMP,BIAS,PHASE)
215  * DISCRETE_SQUAREWAVE(NODE,ENAB,FREQ,AMP,DUTY,BIAS,PHASE)
216  * DISCRETE_SQUAREWFIX(NODE,ENAB,FREQ,AMP,DUTY,BIAS,PHASE)
217  * DISCRETE_SQUAREWAVE2(NODE,ENAB,AMPL,T_OFF,T_ON,BIAS,TSHIFT)
218  * DISCRETE_TRIANGLEWAVE(NODE,ENAB,FREQ,AMP,BIAS,PHASE)
219  *
220  * DISCRETE_INVERTER_OSC(NODE,ENAB,MOD,RCHARGE,RP,C,R2,INFO)
221  * DISCRETE_OP_AMP_OSCILLATOR(NODE,ENAB,INFO)
222  * DISCRETE_OP_AMP_VCO1(NODE,ENAB,VMOD1,INFO)
223  * DISCRETE_OP_AMP_VCO2(NODE,ENAB,VMOD1,VMOD2,INFO)
224  * DISCRETE_SCHMITT_OSCILLATOR(NODE,ENAB,INP0,AMPL,TABLE)
225  *
226  * DISCRETE_ADDER2(NODE,ENAB,IN0,IN1)
227  * DISCRETE_ADDER3(NODE,ENAB,IN0,IN1,IN2)
228  * DISCRETE_ADDER4(NODE,ENAB,IN0,IN1,IN2,IN3)
229  * DISCRETE_CLAMP(NODE,IN0,MIN,MAX)
230  * DISCRETE_DIVIDE(NODE,ENAB,IN0,IN1)
231  * DISCRETE_GAIN(NODE,IN0,GAIN)
232  * DISCRETE_INVERT(NODE,IN0)
233  * DISCRETE_LOOKUP_TABLE(NODE,ADDR,SIZE,TABLE)
234  * DISCRETE_MULTIPLY(NODE,ENAB,IN0,IN1)
235  * DISCRETE_MULTADD(NODE,INP0,INP1,INP2)
236  * DISCRETE_ONESHOT(NODE,TRIG,AMPL,WIDTH,TYPE)
237  * DISCRETE_ONESHOTR(NODE,RESET,TRIG,AMPL,WIDTH,TYPE)
238  * DISCRETE_ONOFF(NODE,ENAB,INP0)
239  * DISCRETE_RAMP(NODE,ENAB,RAMP,GRAD,MIN,MAX,CLAMP)
240  * DISCRETE_SAMPLHOLD(NODE,INP0,CLOCK,CLKTYPE)
241  * DISCRETE_SWITCH(NODE,ENAB,SWITCH,INP0,INP1)
242  * DISCRETE_ASWITCH(NODE,CTRL,INP,THRESHOLD)
243  * DISCRETE_TRANSFORM2(NODE,INP0,INP1,FUNCT)
244  * DISCRETE_TRANSFORM3(NODE,INP0,INP1,INP2,FUNCT)
245  * DISCRETE_TRANSFORM4(NODE,INP0,INP1,INP2,INP3,FUNCT)
246  * DISCRETE_TRANSFORM5(NODE,INP0,INP1,INP2,INP3,INP4,FUNCT)
247  *
248  * DISCRETE_COMP_ADDER(NODE,DATA,TABLE)
249  * DISCRETE_DAC_R1(NODE,DATA,VDATA,LADDER)
250  * DISCRETE_DIODE_MIXER2(NODE,IN0,IN1,TABLE)
251  * DISCRETE_DIODE_MIXER3(NODE,IN0,IN1,IN2,TABLE)
252  * DISCRETE_DIODE_MIXER4(NODE,IN0,IN1,IN2,IN3,TABLE)
253  * DISCRETE_INTEGRATE(NODE,TRG0,TRG1,INFO)
254  * DISCRETE_MIXER2(NODE,ENAB,IN0,IN1,INFO)
255  * DISCRETE_MIXER3(NODE,ENAB,IN0,IN1,IN2,INFO)
256  * DISCRETE_MIXER4(NODE,ENAB,IN0,IN1,IN2,IN3,INFO)
257  * DISCRETE_MIXER5(NODE,ENAB,IN0,IN1,IN2,IN3,IN4,INFO)
258  * DISCRETE_MIXER6(NODE,ENAB,IN0,IN1,IN2,IN3,IN4,IN5,INFO)
259  * DISCRETE_MIXER7(NODE,ENAB,IN0,IN1,IN2,IN3,IN4,IN5,IN6,INFO)
260  * DISCRETE_MIXER8(NODE,ENAB,IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7,INFO)
261  * DISCRETE_OP_AMP(NODE,ENAB,IN0,IN1,INFO)
262  * DISCRETE_OP_AMP_ONESHOT(NODE,TRIG,INFO)
263  * DISCRETE_OP_AMP_TRIG_VCA(NODE,TRG0,TRG1,TRG2,IN0,IN1,INFO)
264  *
265  * DISCRETE_BIT_DECODE(NODE,INP,BIT_N,VOUT)
266  * DISCRETE_BITS_DECODE(NODE,INP,BIT_FROM,BIT_TO,VOUT)
267  *
268  * DISCRETE_LOGIC_INVERT(NODE,INP0)
269  * DISCRETE_LOGIC_AND(NODE,INP0,INP1)
270  * DISCRETE_LOGIC_AND3(NODE,INP0,INP1,INP2)
271  * DISCRETE_LOGIC_AND4(NODE,INP0,INP1,INP2,INP3)
272  * DISCRETE_LOGIC_NAND(NODE,INP0,INP1)
273  * DISCRETE_LOGIC_NAND3(NODE,INP0,INP1,INP2)
274  * DISCRETE_LOGIC_NAND4(NODE,INP0,INP1,INP2,INP3)
275  * DISCRETE_LOGIC_OR(NODE,INP0,INP1)
276  * DISCRETE_LOGIC_OR3(NODE,INP0,INP1,INP2)
277  * DISCRETE_LOGIC_OR4(NODE,INP0,INP1,INP2,INP3)
278  * DISCRETE_LOGIC_NOR(NODE,INP0,INP1)
279  * DISCRETE_LOGIC_NOR3(NODE,INP0,INP1,INP2)
280  * DISCRETE_LOGIC_NOR4(NODE,INP0,INP1,INP2,INP3)
281  * DISCRETE_LOGIC_XOR(NODE,INP0,INP1)
282  * DISCRETE_LOGIC_XNOR(NODE,INP0,INP1)
283  * DISCRETE_LOGIC_DFLIPFLOP(NODE,RESET,SET,CLK,INP)
284  * DISCRETE_LOGIC_JKFLIPFLOP(NODE,RESET,SET,CLK,J,K)
285  * DISCRETE_LOGIC_SHIFT(NODE,INP0,RESET,CLK,SIZE,OPTIONS)
286  * DISCRETE_MULTIPLEX2(NODE,ADDR,INP0,INP1)
287  * DISCRETE_MULTIPLEX4(NODE,ADDR,INP0,INP1,INP2,INP3)
288  * DISCRETE_MULTIPLEX8(NODE,ADDR,INP0,INP1,INP2,INP3,INP4,INP5,INP6,INP7)
289  * DISCRETE_XTIME_BUFFER(NODE,IN0,LOW,HIGH)
290  * DISCRETE_XTIME_INVERTER(NODE,IN0,LOW,HIGH)
291  * DISCRETE_XTIME_AND(NODE,IN0,IN1,LOW,HIGH)
292  * DISCRETE_XTIME_NAND(NODE,IN0,IN1,LOW,HIGH)
293  * DISCRETE_XTIME_OR(NODE,IN0,IN1,LOW,HIGH)
294  * DISCRETE_XTIME_NOR(NODE,IN0,IN1,LOW,HIGH)
295  * DISCRETE_XTIME_XOR(NODE,IN0,IN1,LOW,HIGH)
296  * DISCRETE_XTIME_XNOR(NODE,IN0,IN1,LOW,HIGH)
297  *
298  * DISCRETE_FILTER1(NODE,ENAB,INP0,FREQ,TYPE)
299  * DISCRETE_FILTER2(NODE,ENAB,INP0,FREQ,DAMP,TYPE)
300  *
301  * DISCRETE_CRFILTER(NODE,IN0,RVAL,CVAL)
302  * DISCRETE_CRFILTER_VREF(NODE,IN0,RVAL,CVAL,VREF)
303  * DISCRETE_OP_AMP_FILTER(NODE,ENAB,INP0,INP1,TYPE,INFO)
304  * DISCRETE_RC_CIRCUIT_1(NODE,INP0,INP1,RVAL,CVAL)
305  * DISCRETE_RCDISC(NODE,ENAB,IN0,RVAL,CVAL)
306  * DISCRETE_RCDISC2(NODE,SWITCH,INP0,RVAL0,INP1,RVAL1,CVAL)
307  * DISCRETE_RCDISC3(NODE,ENAB,INP0,RVAL0,RVAL1,CVAL, DJV)
308  * DISCRETE_RCDISC4(NODE,ENAB,INP0,RVAL0,RVAL1,RVAL2,CVAL,VP,TYPE)
309  * DISCRETE_RCDISC5(NODE,ENAB,IN0,RVAL,CVAL)
310  * DISCRETE_RCINTEGRATE(NODE,INP0,RVAL0,RVAL1,RVAL2,CVAL,vP,TYPE)
311  * DISCRETE_RCDISC_MODULATED(NODE,INP0,INP1,RVAL0,RVAL1,RVAL2,RVAL3,CVAL,VP)
312  * DISCRETE_RCFILTER(NODE,IN0,RVAL,CVAL)
313  * DISCRETE_RCFILTER_VREF(NODE,IN0,RVAL,CVAL,VREF)
314  *
315  * DISCRETE_555_ASTABLE(NODE,RESET,R1,R2,C,OPTIONS)
316  * DISCRETE_555_ASTABLE_CV(NODE,RESET,R1,R2,C,CTRLV,OPTIONS)
317  * DISCRETE_555_MSTABLE(NODE,RESET,TRIG,R,C,OPTIONS)
318  * DISCRETE_555_CC(NODE,RESET,VIN,R,C,RBIAS,RGND,RDIS,OPTIONS)
319  * DISCRETE_555_VCO1(NODE,RESET,VIN,OPTIONS)
320  * DISCRETE_555_VCO1_CV(NODE,RESET,VIN,CTRLV,OPTIONS)
321  * DISCRETE_566(NODE,VMOD,R,C,VPOS,VNEG,VCHARGE,OPTIONS)
322  * DISCRETE_74LS624(NODE,ENAB,VMOD,VRNG,C,R_FREQ_IN,C_FREQ_IN,R_RNG_IN,OUTTYPE)
323  *
324  * DISCRETE_CUSTOM1(NODE,IN0,INFO)
325  * DISCRETE_CUSTOM2(NODE,IN0,IN1,INFO)
326  * DISCRETE_CUSTOM3(NODE,IN0,IN1,IN2,INFO)
327  * DISCRETE_CUSTOM4(NODE,IN0,IN1,IN2,IN3,INFO)
328  * DISCRETE_CUSTOM5(NODE,IN0,IN1,IN2,IN3,IN4,INFO)
329  * DISCRETE_CUSTOM6(NODE,IN0,IN1,IN2,IN3,IN4,IN5,INFO)
330  * DISCRETE_CUSTOM7(NODE,IN0,IN1,IN2,IN3,IN4,IN5,IN6,INFO)
331  * DISCRETE_CUSTOM8(NODE,IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7,INFO)
332  * DISCRETE_CUSTOM9(NODE,IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7,IN8,INFO)
333  *
334  * DISCRETE_CSVLOG1(NODE1)
335  * DISCRETE_CSVLOG2(NODE1,NODE2)
336  * DISCRETE_CSVLOG3(NODE1,NODE2,NODE3)
337  * DISCRETE_CSVLOG4(NODE1,NODE2,NODE3,NODE4)
338  * DISCRETE_CSVLOG5(NODE1,NODE2,NODE3,NODE4,NODE5)
339  * DISCRETE_WAVLOG1(NODE1,GAIN1)
340  * DISCRETE_WAVLOG2(NODE1,GAIN1,NODE2,GAIN2)
341  * DISCRETE_OUTPUT(OPNODE,GAIN)
342  *
343  ***********************************************************************
344  =======================================================================
345  * from from disc_inp.inc
346  =======================================================================
347  ***********************************************************************
348  *
349  * DISCRETE_ADJUSTMENT     - Adjustable constant set by the UI [~] menu.
350  *
351  *                        .----------.
352  *                        |          |
353  *                        | ADJUST.. |-------->   Netlist node
354  *                        |          |
355  *                        '----------'
356  *  Declaration syntax
357  *
358  *     DISCRETE_ADJUSTMENT(name of node,
359  *                         static minimum value the node can take,
360  *                         static maximum value the node can take,
361  *                         log/linear scale 0=Linear !0=Logarithmic,
362  *                         port tag name of the adjuster)
363  *
364  *  Note: When using DISC_LOGADJ, the min/max values must be > 0.
365  *        If they are <=0, they will be forced to 1.
366  *        Min can be a higher value then max.
367  *        Min/max is just how the slider is displayed.
368  *
369  *  Example config line
370  *
371  *     DISCRETE_ADJUSTMENT(NODE_01,0.0,5.0,DISC_LINADJ,0,"pot")
372  *
373  *  Define an adjustment slider that takes a 0-100 input from input
374  *  port "pot", scaling between 0.0 and 5.0. Adjustment scaling is Linear.
375  *
376  *      DISC_LOGADJ 1.0
377  *      DISC_LINADJ 0.0
378  *
379  * EXAMPLES: see Hit Me, Fire Truck
380  *
381  ***********************************************************************
382  *
383  * DISCRETE_CONSTANT - Single output, fixed at compile time.
384  *                     This is useful as a placeholder for
385  *                     incomplete circuits.
386  *
387  *                        .----------.
388  *                        |          |
389  *                        | CONSTANT |-------->   Netlist node
390  *                        |          |
391  *                        '----------'
392  *  Declaration syntax
393  *
394  *     DISCRETE_CONSTANT(name of node, constant value)
395  *
396  *  Example config line
397  *
398  *     DISCRETE_CONSTANT(NODE_01, 100)
399  *
400  *  Define a node that has a constant value of 100
401  *
402  ***********************************************************************
403  *
404  * DISCRETE_INPUT_DATA  - accepts 8-bit data.  Value at reset is 0.
405  * DISCRETE_INPUT_LOGIC - 0 if data=0; 1 if data=1.  Value at reset is 0.
406  * DISCRETE_INPUT_NOT   - 0 if data=1; 1 if data=0.  Value at reset is 1.
407  *
408  * DISCRETE_INPUTX_xx   - same as above, but will modify the value by the
409  *                        given GAIN and OFFSET.  At reset the value will
410  *                        be INIT modified by GAIN and OFFSET.
411  *
412  * DISCRETE_INPUT_PULSE - Same as normal input node but the netlist
413  *                        node output returns to INIT after a single
414  *                        cycle of sound output. To allow for scenarios
415  *                        whereby the register write pulse is used as
416  *                        a reset to a system.
417  *
418  *                            .----------.
419  *                      -----\|          |
420  *     discrete_sound_w  data | INPUT(A) |---->   Netlist node
421  *            Write     -----/|          |
422  *                            '----------'
423  *
424  *  Declaration syntax
425  *
426  *     DISCRETE_INPUT_DATA  (name of node)
427  *     DISCRETE_INPUT_LOGIC (name of node)
428  *     DISCRETE_INPUT_NOT   (name of node)
429  *     DISCRETE_INPUTX_DATA (name of node, gain, offset, initial value)
430  *     DISCRETE_INPUTX_LOGIC(name of node, gain, offset, initial value)
431  *     DISCRETE_INPUTX_NOT  (name of node, gain, offset, initial value)
432  *     DISCRETE_INPUT_PULSE (name of node, default value)
433  *
434  *  Can be written to with:    discrete_sound_w(NODE_xx, data);
435  *
436  ***********************************************************************
437  *
438  * DISCRETE_INPUT_STREAM(NODE,NUM)              - Accepts stream input NUM
439  * DISCRETE_INPUTX_STREAM(NODE,NUM,GAIN,OFFSET) - Accepts a stream input and
440  *                                                applies a gain and offset.
441  *
442  *  Declaration syntax
443  *
444  *     DISCRETE_INPUT_STREAM (name of node, stream number, )
445  *     DISCRETE_INPUTX_STREAM(name of node, stream nubmer, gain, offset)
446  *
447  * Note: The discrete system is floating point based.  So when routing a stream
448  *       set it's gain to 100% and then use DISCRETE_INPUTX_STREAM to adjust
449  *       it if needed.
450  *       If you need to access a stream from a discrete task, the stream node
451  *       must be part of that task. If a given stream is used in two tasks or
452  *       a task and the main task, you must declare two stream nodes accessing the
453  *       same stream input NUM.
454  *
455  * EXAMPLES: see scramble, frogger
456  *
457  ***********************************************************************
458  =======================================================================
459  * from from disc_wav.inc
460  * Generic modules
461  =======================================================================
462  ***********************************************************************
463  *
464  * DISCRETE_COUNTER     - up/down counter.
465  *
466  *  This counter counts up/down from MIN to MAX.  When the enable is low, the output
467  *  is held at it's last value.  When reset is high, the reset value is loaded
468  *  into the output.  The counter can be clocked internally or externally.  It also
469  *  supports x_time used by the clock modules to pass on anti-aliasing info.
470  *
471  *  Declaration syntax
472  *
473  *       where:  direction: DISC_COUNT_DOWN = 0 = down
474  *                          DISC_COUNT_UP   = 1 = up
475  *
476  *               clock type: DISC_CLK_ON_F_EDGE - toggle on falling edge.
477  *                           DISC_CLK_ON_R_EDGE - toggle on rising edge.
478  *                           DISC_CLK_BY_COUNT  - toggle specified number of times.
479  *                           DISC_CLK_IS_FREQ   - internally clock at this frequency.
480  *
481  *               x_time options: you can also | these x_time features to the basic
482  *                               types above if needed, or use separately with 7492.
483  *                           DISC_OUT_IS_ENERGY - This will uses the x_time to
484  *                                                anti-alias the count.  Might be
485  *                                                useful if not connected to other
486  *                                                modules.
487  *                           DISC_OUT_HAS_XTIME - This will generate x_time if
488  *                                                being used with DISC_CLK_IS_FREQ.
489  *                                                It will pass x_time for the
490  *                                                other clock types.
491  *
492  *     DISCRETE_COUNTER(name of node,
493  *                      enable node or static value,
494  *                      reset node or static value, (reset when true)
495  *                      clock node or static value,
496  *                      min count static value,
497  *                      max count static value,
498  *                      direction node or static value,
499  *                      reset value node or static value,
500  *                      clock type static value)
501  *
502  *     DISCRETE_COUNTER_7492(name of node,
503  *                           enable node or static value,
504  *                           reset node or static value,
505  *                           clock node or static value,
506  *                           clock type static value)
507  *
508  *  Note: A 7492 counter outputs a special bit pattern on its /6 stage.
509  *        A 7492 clocks on the falling edge,
510  *        so it is not recommended to use DISC_CLK_ON_R_EDGE for a 7492.
511  *        This module emulates the /6 stage only.
512  *        Use another DISCRETE_COUNTER for the /2 stage.
513  *
514  * EXAMPLES: see Fire Truck, Monte Carlo, Super Bug, Polaris
515  *
516  ***********************************************************************
517  *
518  * DISCRETE_LFSR_NOISE - Noise waveform generator node, generates
519  *                       pseudo random digital stream at the requested
520  *                       clock frequency.
521  *
522  *  Declaration syntax
523  *
524  *     DISCRETE_LFSR_NOISE(name of node,
525  *                         enable node or static value,
526  *                         reset node or static value,
527  *                         clock node or static value,
528  *                         amplitude node or static value,
529  *                         forced infeed bit to shift reg,
530  *                         bias node or static value,
531  *                         LFSR noise descriptor structure)
532  *
533  *     discrete_lfsr_desc = {clock type,  (see DISCRETE_COUNTER),
534  *                           bitlength, reset_value,
535  *                           feedback_bitsel0, feedback_bitsel1,
536  *                           feedback_function0, feedback_function1, feedback_function2,
537  *                           feedback_function2_mask, flags, output_bit}
538  *
539  *     flags: DISC_LFSR_FLAG_OUT_INVERT     - invert output
540  *            DISC_LFSR_FLAG_RESET_TYPE_L   - reset when LOW (Defalut)
541  *            DISC_LFSR_FLAG_RESET_TYPE_H   - reset when HIGH
542  *            DISC_LFSR_FLAG_OUTPUT_F0      - output is result of F0
543  *            DISC_LFSR_FLAG_OUTPUT_SR_SN1  - output shift register to sub-node output #1
544  *
545  *  The diagram below outlines the structure of the LFSR model.
546  *
547  *         .-------.
548  *   FEED  |       |
549  *   ----->|  F1   |<--------------------------------------------.
550  *         |       |                                             |
551  *         '-------'               BS - Bit Select               |
552  *             |                   Fx - Programmable Function    |
553  *             |        .-------.  PI - Programmable Inversion   |
554  *             |        |       |                                |
555  *             |  .---- | SR>>1 |<--------.                      |
556  *             |  |     |       |         |                      |
557  *             V  V     '-------'         |  .----               |
558  *           .------.                     +->| BS |--. .------.  |
559  *   BITMASK |      |    .-------------.  |  '----'  '-|      |  |
560  *   ------->|  F2  |-+->| Shift Reg   |--+            |  F0  |--'
561  *           |      | |  '-------------'  |  .----.  .-|      |
562  *           '------' |         ^         '->| BS |--' '------'
563  *                    |         |            '----'
564  *   CLOCK            |     RESET VAL
565  *   ---->            |                      .----.  .----.
566  *                    '----------------------| BS |--| PI |--->OUTPUT
567  *                                           '----'  '----'
568  *
569  * EXAMPLES: see Fire Truck, Monte Carlo, Super Bug, Polaris
570  *
571  ***********************************************************************
572  *
573  * DISCRETE_NOISE      - Noise waveform generator node, generates
574  *                       random noise of the chosen frequency.
575  *
576  *                        .------------.
577  *                        |            |
578  *    ENABLE     -0------>|            |
579  *                        |            |
580  *    FREQUENCY  -1------>|   NOISE    |---->   Netlist node
581  *                        |            |
582  *    AMPLITUDE  -2------>|            |
583  *                        |            |
584  *    BIAS       -3------>|            |
585  *                        |            |
586  *                        '------------'
587  *
588  *  Declaration syntax
589  *
590  *     DISCRETE_NOISE(name of node,
591  *                    enable node or static value,
592  *                    frequency node or static value,
593  *                    amplitude node or static value)
594  *
595  *  Example config line
596  *
597  *     DISCRETE_NOISE(NODE_03,1,5000,NODE_01,0)
598  *
599  ***********************************************************************
600  *
601  * DISCRETE_NOTE - Note generator.  This takes a chosen clock, and
602  *                 clocks an up counter that is preloaded with the data
603  *                 value at every max 1 count.  Every time max 1 count
604  *                 is reached, the output counts up one and rolls over
605  *                 to 0 at max 2 count.
606  *                 When the data value is the same as max count 1, the
607  *                 counter no longer counts.
608  *
609  *  Declaration syntax
610  *
611  *     DISCRETE_NOTE(name of node,
612  *                   enable node or static value,
613  *                   clock node or static value,
614  *                   data node or static value,
615  *                   max 1 count static value,
616  *                   max 2 count static value,
617  *                   clock type  (see DISCRETE_COUNTER))
618  *
619  * EXAMPLES: see Polaris, Blockade
620  *
621  ***********************************************************************
622  *
623  * DISCRETE_SAWTOOTHWAVE - Saw tooth shape waveform generator, rapid
624  *                         rise and then graduated fall
625  *
626  *                        .------------.
627  *                        |            |
628  *    ENABLE     -0------>|            |
629  *                        |            |
630  *    FREQUENCY  -1------>|            |
631  *                        |            |
632  *    AMPLITUDE  -2------>|  SAWTOOTH  |----> Netlist Node
633  *                        |    WAVE    |
634  *    BIAS       -3------>|            |
635  *                        |            |
636  *    GRADIENT   -4------>|            |
637  *                        |            |
638  *    PHASE      -5------>|            |
639  *                        |            |
640  *                        '------------'
641  *
642  *  Declaration syntax
643  *
644  *     DISCRETE_SAWTOOTHWAVE(name of node,
645  *                         enable node or static value,
646  *                         frequency node or static value,
647  *                         amplitude node or static value,
648  *                         dc bias value for waveform,
649  *                         gradient of wave ==0 //// !=0 \\\\,
650  *                         starting phase value in degrees)
651  *
652  *  Example config line
653  *
654  *     DISCRETE_SAWTOOTHWAVE(NODE_03,1,5000,NODE_01,0,0,90)
655  *
656  ***********************************************************************
657  *
658  * DISCRETE_SINEWAVE   - Sinewave waveform generator node, has four
659  *                       input nodes FREQUENCY, AMPLITUDE, ENABLE and
660  *                       PHASE, if a node is not connected it will
661  *                       default to the initialised value in the macro
662  *
663  *                        .------------.
664  *                        |            |
665  *    ENABLE     -0------>|            |
666  *                        |            |
667  *    FREQUENCY  -1------>|            |
668  *                        | SINEWAVE   |---->   Netlist node
669  *    AMPLITUDE  -2------>|            |
670  *                        |            |
671  *    BIAS       -3------>|            |
672  *                        |            |
673  *    PHASE      -4------>|            |
674  *                        |            |
675  *                        '------------'
676  *
677  *  Declaration syntax
678  *
679  *     DISCRETE_SINEWAVE  (name of node,
680  *                         enable node or static value,
681  *                         frequency node or static value,
682  *                         amplitude node or static value,
683  *                         dc bias value for waveform,
684  *                         starting phase value in degrees)
685  *
686  *  Example config line
687  *
688  *     DISCRETE_SINEWAVE(NODE_03,NODE_01,NODE_02,10000,5000.0,90)
689  *
690  ***********************************************************************
691  *
692  * DISCRETE_SQUAREWAVE - Squarewave waveform generator node.
693  * DISCRETE_SQUAREWFIX   Waveform is defined by frequency and duty
694  *                       cycle.
695  *
696  *                        .------------.
697  *                        |            |
698  *    ENABLE     -0------>|            |
699  *                        |            |
700  *    FREQUENCY  -1------>|            |
701  *                        |            |
702  *    AMPLITUDE  -2------>| SQUAREWAVE |---->   Netlist node
703  *                        |            |
704  *    DUTY CYCLE -3------>|            |
705  *                        |            |
706  *    BIAS       -4------>|            |
707  *                        |            |
708  *    PHASE      -5------>|            |
709  *                        |            |
710  *                        '------------'
711  *
712  *  Declaration syntax
713  *
714  *     DISCRETE_SQUAREWAVE(name of node,
715  *                         enable node or static value,
716  *                         frequency node or static value,
717  *                         amplitude node or static value,
718  *                         duty cycle node or static value,
719  *                         dc bias value for waveform,
720  *                         starting phase value in degrees)
721  *
722  *  Example config line
723  *
724  *     DISCRETE_SQUAREWAVE(NODE_03,NODE_01,NODE_02,100,50,0,90)
725  *
726  * NOTE: DISCRETE_SQUAREWFIX is used the same as DISCRETE_SQUAREWAVE.
727  *       BUT... It does not stay in sync when you change the freq or
728  *              duty values while enabled.  This should be used only
729  *              when these values are stable while the wave is enabled.
730  *              It takes up less CPU time then DISCRETE_SQUAREWAVE and
731  *              should be used whenever possible.
732  *
733  * EXAMPLES: see Polaris
734  *
735  ***********************************************************************
736  *
737  * DISCRETE_SQUAREWAVE2 - Squarewave waveform generator node.
738  *                        Waveform is defined by it's off/on time
739  *                        periods.
740  *
741  *                        .------------.
742  *                        |            |
743  *    ENABLE     -0------>|            |
744  *                        |            |
745  *    AMPLITUDE  -1------>|            |
746  *                        |            |
747  *    OFF TIME   -2------>| SQUAREWAVE |---->   Netlist node
748  *                        |            |
749  *    ON TIME    -3------>|            |
750  *                        |            |
751  *    BIAS       -4------>|            |
752  *                        |            |
753  *    TIME SHIFT -5------>|            |
754  *                        |            |
755  *                        '------------'
756  *
757  *  Declaration syntax
758  *
759  *     DISCRETE_SQUAREWAVE2(name of node,
760  *                          enable node or static value,
761  *                          amplitude node or static value,
762  *                          off time node or static value in seconds,
763  *                          on time node or static value in seconds,
764  *                          dc bias value for waveform,
765  *                          starting phase value in seconds)
766  *
767  *  Example config line
768  *
769  *   DISCRETE_SQUAREWAVE2(NODE_03,NODE_01,NODE_02,0.01,0.001,0.0,0.001)
770  *
771  ***********************************************************************
772  *
773  * DISCRETE_TRIANGLEW  - Triangular waveform generator, generates
774  *                       equal ramp up/down at chosen frequency
775  *
776  *                        .------------.
777  *                        |            |
778  *    ENABLE     -0------>|            |
779  *                        |            |
780  *    FREQUENCY  -1------>|  TRIANGLE  |---->   Netlist node
781  *                        |    WAVE    |
782  *    AMPLITUDE  -2------>|            |
783  *                        |            |
784  *    BIAS       -3------>|            |
785  *                        |            |
786  *    PHASE      -4------>|            |
787  *                        |            |
788  *                        '------------'
789  *
790  *  Declaration syntax
791  *
792  *     DISCRETE_TRIANGLEWAVE(name of node,
793  *                         enable node or static value,
794  *                         frequency node or static value,
795  *                         amplitude node or static value,
796  *                         dc bias value for waveform,
797  *                         starting phase value in degrees)
798  *
799  *  Example config line
800  *
801  *     DISCRETE_TRIANGLEWAVE(NODE_03,1,5000,NODE_01,0.0,0.0)
802  *
803  ***********************************************************************
804  =======================================================================
805  * from from disc_wav.inc
806  * Component specific modules
807  =======================================================================
808  ***********************************************************************
809  *
810  * DISCRETE_OP_AMP_OSCILLATOR - Various single power supply op-amp oscillator circuits
811  *
812  *  Declaration syntax
813  *
814  *     DISCRETE_OP_AMP_OSCILLATOR(name of node,
815  *                                enable node or static value,
816  *                                address of dss_op_amp_osc_context structure)
817  *
818  *     discrete_op_amp_osc_info = {type, r1, r2, r3, r4, r5, r6, r7, r8, c, vP}
819  *
820  * Note: Set all unused components to 0.
821  *       _OUT_SQW can also be replaced with
822  *                _OUT_ENERGY, _OUT_LOGIC_X, _OUT_COUNT_F_X, _OUT_COUNT_R_X
823  *
824  *  Types:
825  *
826  *     DISC_OP_AMP_OSCILLATOR_1 | DISC_OP_AMP_IS_NORTON
827  *          Basic Norton Op Amp Oscillator circuit.
828  *
829  *              vP >-.
830  *                   |         c
831  *                   Z     .---||----+-------------------------> DISC_OP_AMP_OSCILLATOR_OUT_CAP
832  *                   Z r1  |         |
833  *                   Z     |   |\    |
834  *                   |     |   | \   |            |\
835  *                   '-----+---|- \  |     r3     | \
836  *                             |   >-+----ZZZZ----|- \
837  *                             |+ /               |   >--+-----> DISC_OP_AMP_OSCILLATOR_OUT_SQW
838  *                         .---| /             .--|+ /   |
839  *                         |   |/        r5    |  | /    |
840  *           vP >-.        |      vP >--ZZZZ---+  |/     |
841  *                |        Z                   |         |
842  *                Z        Z r2                |   r4    |
843  *                Z 1k     Z                   '--ZZZZ---+
844  *                Z        |                             |
845  *            |\  |  r6    |                             |
846  * Enable >---| >-+-ZZZZ---+-----------------------------'
847  *            |/ O.C.
848  *
849  * Note: R1 - R5 can be nodes.
850  *
851  * EXAMPLES: see Polaris, Amazing Maze
852  *
853  *          --------------------------------------------------
854  *
855  *     DISC_OP_AMP_OSCILLATOR_2 | DISC_OP_AMP_IS_NORTON
856  *          Basic Norton Op Amp Oscillator circuit.
857  *
858  *       .-------------------------------------------> DISC_OP_AMP_OSCILLATOR_OUT_CAP
859  *       |
860  *       |       r1
861  *       +------ZZZZ-----.
862  *       |               |
863  *       |   r5          |
864  *       +--ZZZZ---|>|---.
865  *       |               |
866  *       |   r6          |
867  *       +--ZZZZ---|<|---.
868  *       |               |
869  *       |         |\    |
870  *       |    r2   | \   |
871  *       +---ZZZZ--|- \  |
872  *       |         |   >-+-------> DISC_OP_AMP_OSCILLATOR_OUT_SQW
873  *      --- c      |+ /  |
874  *      ---    .---| /   |
875  *       |     |   |/    |
876  *      gnd    |         |
877  *             |   r3    |
878  *             +--ZZZZ---'
879  *             |
880  *             Z
881  *             Z r4
882  *             Z
883  *             |
884  *             ^
885  *             vP
886  *
887  * Note: All values are static.
888  *
889  * EXAMPLES: see Space Walk, Blue Shark
890  *
891  ***********************************************************************
892  *
893  * DISCRETE_OP_AMP_VCOn - Various single power supply op-amp VCO circuits
894  *                   (n = 1 or 2)
895  *
896  *  Declaration syntax
897  *
898  *     DISCRETE_OP_AMP_VCOn(name of node,
899  *                          enable node or static value,
900  *                          modulation voltage 1 node or static value,
901  *                          modulation voltage 2 node or static value,  [optional]
902  *                          address of dss_op_amp_osc_context structure)
903  *
904  *     discrete_op_amp_osc_info = {type, r1, r2, r3, r4, r5, r6, r7, r8, c, vP}
905  *
906  * Note: Set all unused components to 0.
907  *       _OUT_SQW can also be replaced with
908  *                _OUT_ENERGY, _OUT_LOGIC_X, _OUT_COUNT_F_X, _OUT_COUNT_R_X
909  *
910  *  Types:
911  *
912  *     DISC_OP_AMP_OSCILLATOR_VCO_1
913  *          Basic Op Amp Voltage Controlled Oscillator circuit.
914  *          Note that this circuit has only 1 modulation voltage.
915  *          So it is used only with DISCRETE_OP_AMP_VCO1.
916  *
917  *                               c
918  *  .------------------------+---||----+---------------------------> DISC_OP_AMP_OSCILLATOR_OUT_CAP
919  *  |                        |         |
920  *  |                        |   |\    |
921  *  |              r1        |   | \   |            |\
922  *  | vMod1 >--+--ZZZZ-------+---|- \  |            | \
923  *  |          |                 |   >-+------------|- \
924  *  |          |   r2            |+ /               |   >--+-------> DISC_OP_AMP_OSCILLATOR_OUT_SQW
925  *  Z          '--ZZZZ--+--------| /             .--|+ /   |
926  *  Z r6                |        |/        r4    |  | /    |
927  *  Z                   Z         vP/2 >--ZZZZ---+  |/     |
928  *  |                   Z r5                     |         |
929  * .----.               Z                        |   r3    |
930  * | sw |<--------.     |                        '--ZZZZ---+
931  * '----'         |    gnd                                 |
932  *    |           |                                        |
933  *   gnd          '----------------------------------------'
934  *
935  * Notes: The 'sw' block can be a transistor or 4066 switch.  It connects
936  *        r6 to ground when 'sw' is high.
937  *
938  *          --------------------------------------------------
939  *
940  *     DISC_OP_AMP_OSCILLATOR_VCO_1 | DISC_OP_AMP_IS_NORTON
941  *          Basic Norton Op Amp Voltage Controlled Oscillator circuit.
942  *          When disabled, c discharges and sqw out goes high.
943  *
944  *                                             .---------------------------> DISC_OP_AMP_OSCILLATOR_OUT_CAP
945  *                                       c     |
946  *               r6                  .---||----+
947  *        vP >--ZZZZ---.             |         |         r5    |\
948  *                     |             |   |\    |  vP >--ZZZZ-. | \
949  *               r7    |   r1        |   | \   |             '-|- \
950  *     vMod1 >--ZZZZ---+--ZZZZ-------+---|- \  |     r3        |   >--+-------> DISC_OP_AMP_OSCILLATOR_OUT_SQW
951  *                     |                 |   >-+----ZZZZ----+--|+ /   |
952  *               r8    |   r2    .----.  |+ /               |  | /    |
953  *     vMod2 >--ZZZZ---+--ZZZZ---| sw |--| /                |  |/     |
954  *                               '----'  |/                 |         |
955  *                                 ^ ^                      |   r4    |
956  *                                 | |                      '--ZZZZ---+
957  *                                 | |                                |
958  *                Enable >---------' |                                |
959  *                                   '--------------------------------'
960  *
961  * EXAMPLES: see Polaris
962  *
963  *          --------------------------------------------------
964  *
965  *     DISC_OP_AMP_OSCILLATOR_VCO_2 | DISC_OP_AMP_IS_NORTON
966  *          Basic Norton Op Amp Voltage Controlled Oscillator circuit.
967  *          Note that this circuit has only 1 modulation voltage.
968  *          So it is used only with DISCRETE_OP_AMP_VCO1.
969  *          When vMod1 goes to 0V, the oscillator is disabled.
970  *          c fully charges and the sqw out goes low.
971  *
972  *                                             .---------------------------> DISC_OP_AMP_OSCILLATOR_OUT_CAP
973  *                                             |
974  *                                             |                 r4
975  *                                       c     |             .--ZZZZ--.
976  *                                   .---||----+             |        |
977  *                                   |         |         r5  | |\     |
978  *                                   |   |\    |  vP >--ZZZZ-+ | \    |
979  *               r1                  |   | \   |             '-|+ \   |
980  *     vMod1 >--ZZZZ-----------------+---|- \  |     r3        |   >--+-------> DISC_OP_AMP_OSCILLATOR_OUT_SQW
981  *                                       |   >-+----ZZZZ-------|- /   |
982  *               r2                      |+ /                  | /    |
983  *        vP >--ZZZZ-----------------+---| /                   |/     |
984  *                                   |   |/                           |
985  *               r6      .----.      |                                |
986  *        vP >--ZZZZ-----|-sw-|------'                                |
987  *                       '----'                                       |
988  *                          ^                                         |
989  *                          |                                         |
990  *                          '-----------------------------------------'
991  *
992  * EXAMPLES: see Double Play
993  *
994  *          --------------------------------------------------
995  *
996  *     DISC_OP_AMP_OSCILLATOR_VCO_3 | DISC_OP_AMP_IS_NORTON
997  *          Basic Norton Op Amp Voltage Controlled Oscillator circuit.
998  *
999  *
1000  *                                  c
1001  *              r7              .---||----+---------------------------> DISC_OP_AMP_OSCILLATOR_OUT_CAP
1002  *       vP >--ZZZZ---.         |         |
1003  *                    |         |   |\    |
1004  *              r1    |         |   | \   |            |\
1005  *    vMod1 >--ZZZZ---+---------+---|- \  |     r3     | \
1006  *                    |             |   >-+----ZZZZ----|- \
1007  *              r6    |             |+ /               |   >--+-------> DISC_OP_AMP_OSCILLATOR_OUT_SQW
1008  *    vMod2 >--ZZZZ---'         .---| /             .--|+ /   |
1009  *                              |   |/        r5    |  | /    |
1010  *                vP >-.        |      vP >--ZZZZ---+  |/     |
1011  *                     |        Z                   |         |
1012  *                     Z        Z r2                |   r4    |
1013  *                     Z 1k     Z                   '--ZZZZ---+
1014  *                     Z        |                             |
1015  *                 |\  |  r8    |                             |
1016  *      Enable >---| >-+-ZZZZ---+-----------------------------'
1017  *                 |/ O.C.
1018  *
1019  * EXAMPLES: see Space Encounter, Blue Shark
1020  *
1021  ***********************************************************************
1022  *
1023  * DISCRETE_SCHMITT_OSCILLATOR - Schmitt Inverter gate oscillator
1024  *
1025  *                  rFeedback
1026  *                .---ZZZ----.                   .--< Amplitude
1027  *                |          |                   |
1028  *                |  |\      |      .------.     |
1029  *           rIn  |  | \     | 0/1  | AND/ |    .-.
1030  *  INP0 >---ZZZ--+--|S >o---+----->|NAND/ |--->|*|-----> Netlist Node
1031  *                |  | /            |  OR/ |    '-'
1032  *                |  |/          .->| NOR  |
1033  *               ---             |  '------'
1034  *               --- C           |
1035  *                |              ^
1036  *               gnd          Enable
1037  *
1038  *  Declaration syntax
1039  *
1040  *     DISCRETE_SCHMITT_OSCILLATOR(name of node,
1041  *                                 enable node or static value,
1042  *                                 Input 0 node or static value,
1043  *                                 Amplitude node or static value,
1044  *                                 address of discrete_schmitt_osc_desc structure)
1045  *
1046  *     discrete_schmitt_osc_desc = {rIn, rFeedback, c, trshRise, trshFall, vGate, options}
1047  *
1048  *  Note: trshRise, trshFall, vGate can be replaced with one of these common types:
1049  *        DEFAULT_7414_VALUES or DEFAULT_74LS14_VALUES  (the LS makes a difference)
1050  *    eg: {rIn, rFeedback, c, DEFAULT_7414_VALUES, options}
1051  *
1052  *  Where:
1053  *     trshRise is the voltage level that triggers the gate input to go high (vGate) on rise.
1054  *     trshFall is the voltage level that triggers the gate input to go low (0V) on fall.
1055  *     vGate    is the output high voltage of the gate that gets fedback through rFeedback.
1056  *
1057  *  Input Options:
1058  *     DISC_SCHMITT_OSC_IN_IS_LOGIC (DEFAULT)
1059  *     DISC_SCHMITT_OSC_IN_IS_VOLTAGE
1060  *
1061  *  Enable Options: (ORed with input options)
1062  *     DISC_SCHMITT_OSC_ENAB_IS_AND (DEFAULT)
1063  *     DISC_SCHMITT_OSC_ENAB_IS_NAND
1064  *     DISC_SCHMITT_OSC_ENAB_IS_OR
1065  *     DISC_SCHMITT_OSC_ENAB_IS_NOR
1066  *
1067  * EXAMPLES: see Fire Truck, Monte Carlo, Super Bug
1068  *
1069  ***********************************************************************
1070  *
1071  * DISCRETE_INVERTER_OSC - Inverter gate oscillator circuits
1072  *
1073  * TYPE 1/3
1074  *               .----------------------------> Netlist Node (Type 3)
1075  *               |
1076  *        |\     |  |\        |\
1077  *        | \    |  | \       | \
1078  *     +--|  >o--+--|-->o--+--|  >o--+--------> Netlist Node (Type 1)
1079  *     |  | /       | /    |  | /    |
1080  *     |  |/        |/     |  |/     |
1081  *     Z                   |         |
1082  *     Z RP               ---        |
1083  *     Z                  --- C      |
1084  *     |                   |     R1  |
1085  *     '-------------------+----ZZZ--'
1086  *
1087  * TYPE 2
1088  *
1089  *        |\        |\
1090  *        | \       | \
1091  *     +--|  >o--+--|-->o--+-------> Netlist Node
1092  *     |  | /    |  | /    |
1093  *     |  |/     |  |/     |
1094  *     Z         Z         |
1095  *     Z RP      Z R1     ---
1096  *     Z         Z        --- C
1097  *     |         |         |
1098  *     '---------+---------'
1099  *
1100  *
1101  * TYPE 4 / see vicdual
1102  *
1103  *                |\        |\
1104  *                | \       | \
1105  * Enable >-+-----+--|>o-+--|-->o--+-------> Netlist Node
1106  *          |     | /    |  | /    |
1107  *          |     |/     |  |/     |
1108  *          Z            Z         |
1109  *          Z RP         Z R1     ---
1110  *          Z            Z        --- C
1111  *          |       D    |         |
1112  *          '------|>|---+---------'
1113  *                       |
1114  * Mod    >-----ZZZ------'
1115  *               R2
1116  *
1117  * TYPE 5 / see vicdual
1118  *    Diode will cause inverted input behaviour and inverted output
1119  *
1120  *                |\        |\
1121  *                | \       | \
1122  * Enable >-+-----+--|>o-+--|-->o--+-------> Netlist Node
1123  *          |     | /    |  | /    |
1124  *          |     |/     |  |/     |
1125  *          Z            Z         |
1126  *          Z RP         Z R1     ---
1127  *          Z            Z        --- C
1128  *          |       D    |         |
1129  *          '------|<|---+---------'
1130  *                       |
1131  * Mod    >-----ZZZ------'
1132  *               R2
1133  *
1134  *  Declaration syntax
1135  *
1136  *     DISCRETE_INVERTER_OSC( name of node,
1137  *                            enable node or static value,
1138  *                            modulation node or static value (0 when not used),
1139  *                            R1 static value,
1140  *                            RP static value
1141  *                            C  static value,
1142  *                            R2 static value (0 when not used),
1143  *                            address of discrete_inverter_osc_desc structure)
1144  *
1145  *     discrete_inverter_osc_desc = {vB, vOutLow, vOutHigh, vInRise, vInFall, clamp, options}
1146  *
1147  *     Where
1148  *        vB       Supply Voltage
1149  *        vOutLow  Low Output voltage
1150  *        vOutHigh High Output voltage
1151  *        vInRise  voltage that triggers the gate input to go high (vGate) on rise
1152  *        vInFall  voltage that triggers the gate input to go low (0V) on fall
1153  *        clamp    internal diode clamp:  [-clamp ... vb+clamp] if clamp>= 0
1154  *        options  bitmapped options
1155  *
1156  *     There is a macro DEFAULT_CD40XX_VALUES(_vB) which may be used to initialize the
1157  *     structure with .... = { 5, DEFAULT_CD40XX_VALUES(5), DISC_OSC_INVERTER_IS_TYPE1}
1158  *
1159  *     The parameters are used to construct a input/output transfer function.
1160  *
1161  *     Option Values
1162  *
1163  *         DISC_OSC_INVERTER_IS_TYPE1
1164  *         DISC_OSC_INVERTER_IS_TYPE2
1165  *         DISC_OSC_INVERTER_IS_TYPE3
1166  *         DISC_OSC_INVERTER_IS_TYPE4
1167  *         DISC_OSC_INVERTER_OUT_IS_LOGIC
1168  *
1169  * EXAMPLES: see dkong
1170  *
1171  ***********************************************************************
1172  =======================================================================
1173  * from from disc_wav.inc
1174  * Not yet implemented
1175  =======================================================================
1176  ***********************************************************************
1177  *
1178  * DISCRETE_ADSR_ENV  - Attack Decay Sustain Release envelope generator
1179  *
1180  * Note: Not yet implemented.
1181  *
1182  *                        .------------.
1183  *                        |            |
1184  *    ENABLE     -0------>|            |
1185  *                        |    /\__    |
1186  *    TRIGGER    -1------>|   /    \   |---->   Netlist node
1187  *                        |    ADSR    |
1188  *    GAIN       -2------>|    Env     |
1189  *                        |            |
1190  *                        '------------'
1191  *
1192  *  Declaration syntax
1193  *
1194  *     DISCRETE_ADSR_ENV  (name of node,
1195  *                         enable node or static value,
1196  *                         envelope gain node or static value,
1197  *                         envelope descriptor struct)
1198  *
1199  *  Example config line
1200  *
1201  *     DISCRETE_ADSR_ENV(NODE_3,1,NODE_21,1.0,&adsrdesc)
1202  *
1203  ***********************************************************************
1204  =======================================================================
1205  * from from disc_mth.inc
1206  * Generic modules
1207  =======================================================================
1208  ***********************************************************************
1209  *
1210  * DISCRETE_ADDER      - Node addition function, available in three
1211  *                       lovely flavours, ADDER2,ADDER3,ADDER4
1212  *                       that perform a summation of incoming nodes
1213  *
1214  *                        .------------.
1215  *                        |            |
1216  *    INPUT0     -0------>|            |
1217  *                        |            |
1218  *    INPUT1     -1------>|     |      |
1219  *                        |    -+-     |---->   Netlist node
1220  *    INPUT2     -2------>|     |      |
1221  *                        |            |
1222  *    INPUT3     -3------>|            |
1223  *                        |            |
1224  *                        '------------'
1225  *
1226  *  Declaration syntax
1227  *
1228  *     DISCRETE_ADDERx    (name of node,
1229  *        (x=2/3/4)        enable node or static value,
1230  *                         input0 node or static value,
1231  *                         input1 node or static value,
1232  *                         input2 node or static value,  [optional]
1233  *                         input3 node or static value)  [optional]
1234  *
1235  *  Example config line
1236  *
1237  *     DISCRETE_ADDER2(NODE_03,1,NODE_12,-2000)
1238  *
1239  *  Always enabled, subtracts 2000 from the output of NODE_12
1240  *
1241  ***********************************************************************
1242  *
1243  * DISCRETE_CLAMP - Force a signal to stay within bounds MIN/MAX
1244  *
1245  *                        .------------.
1246  *                        |            |
1247  *    INP0       -0------>|            |
1248  *                        |            |
1249  *    MIN        -1------>|   CLAMP    |---->   Netlist node
1250  *                        |            |
1251  *    MAX        -2------>|            |
1252  *                        |            |
1253  *                        '------------'
1254  *
1255  *  Declaration syntax
1256  *
1257  *        DISCRETE_CLAMP(name of node,
1258  *                       input node,
1259  *                       minimum node or static value,
1260  *                       maximum node or static value),
1261  *
1262  *  Example config line
1263  *
1264  *     DISCRETE_CLAMP(NODE_9,NODE_10,2.0,10.0)
1265  *
1266  *  Force the value on the node output, to be within the MIN/MAX
1267  *  boundary.  In this example the output is clamped to the range
1268  *  of 2.0 to 10.0 inclusive.
1269  *
1270  * EXAMPLES: Sprint 8
1271  *
1272  ***********************************************************************
1273  *
1274  * DISCRETE_DIVIDE     - Node division function
1275  *
1276  *                        .------------.
1277  *                        |            |
1278  *    ENAB       -0------>|            |
1279  *                        |     o      |
1280  *    INPUT1     -1------>|    ---     |---->   Netlist node
1281  *                        |     o      |
1282  *    INPUT2     -2------>|            |
1283  *                        |            |
1284  *                        '------------'
1285  *
1286  *  Declaration syntax
1287  *
1288  *     DISCRETE_DIVIDE    (name of node,
1289  *                         enable node or static value,
1290  *                         input0 node or static value,
1291  *                         input1 node or static value)
1292  *
1293  *  Example config line
1294  *
1295  *     DISCRETE_DIVIDE(NODE_03,1.0,NODE_12,50.0)
1296  *
1297  *  Always enabled, divides the input NODE_12 by 50.0. Note that a
1298  *  divide by zero condition will give a LARGE number output, it
1299  *  will not stall the machine or simulation. It will also attempt
1300  *  to write a divide by zero error to the Mame log if enabled.
1301  *
1302  ***********************************************************************
1303  *
1304  * DISCRETE_BIT_DECODE - Decode a bit from value
1305  * DISCRETE_BITS_DECODE - Decode a range of bits from value
1306  *
1307  *  Declaration syntax
1308  *
1309  *     DISCRETE_BIT_DECODE(name of node,
1310  *                         input0 node or static value,
1311  *                         bit number static value,
1312  *                         output voltage (logic high) static value)
1313  *
1314  * Note: This module can decode x_time from counters, etc.
1315  *       If you set the output voltage to 0, then 0/1 with x_time will be output.
1316  *       Otherwise it will be used as energy based on the output voltage.
1317  *
1318  *  Example config lines
1319  *
1320  *     DISCRETE_BIT_DECODE(NODE_03,7,0,5)
1321  *
1322  *  Node output is 5
1323  *
1324  *     DISCRETE_BIT_DECODE(NODE_03,7,3,5)
1325  *
1326  *  Node output is 0
1327  *
1328  *  if the range variant is used, you may access the bits (up to 8)
1329  *  by using NODE_SUB, i.e.
1330  *
1331  *     DISCRETE_BITS_DECODE(NODE_03,5,0,4,5)
1332  *
1333  * NODE_SUB(NODE_03, 0) = 5
1334  * NODE_SUB(NODE_03, 1) = 0
1335  * NODE_SUB(NODE_03, 2) = 5
1336  * NODE_SUB(NODE_03, 3) = 0
1337  * NODE_SUB(NODE_03, 4) = 0
1338  *
1339  * EXAMPLES: galaxian, dkong, mario
1340  *
1341  ***********************************************************************
1342  *
1343  * DISCRETE_LOGIC_INVERT - Logic invertor
1344  * DISCRETE_LOGIC_AND  - Logic AND gate (3 & 4 input also available)
1345  * DISCRETE_LOGIC_NAND - Logic NAND gate (3 & 4 input also available)
1346  * DISCRETE_LOGIC_OR   - Logic OR gate (3 & 4 input also available)
1347  * DISCRETE_LOGIC_NOR  - Logic NOR gate (3 & 4 input also available)
1348  * DISCRETE_LOGIC_XOR  - Logic XOR gate
1349  * DISCRETE_LOGIC_XNOR - Logic NXOR gate
1350  *
1351  *                        .------------.
1352  *                        |            |
1353  *    INPUT0     -0------>|            |
1354  *                        |   LOGIC    |
1355  *    [INPUT1]   -1------>|  FUNCTION  |---->   Netlist node
1356  *                        |    !&|^    |
1357  *    [INPUT2]   -2------>|            |
1358  *                        |            |
1359  *    [INPUT3]   -3------>|            |
1360  *                        |            |
1361  *    [] - Optional       '------------'
1362  *
1363  *  Declaration syntax
1364  *
1365  *     DISCRETE_LOGIC_XXXn(name of node,
1366  *      (X=INV/AND/etc)
1367  *      (n=Blank/2/3)      input0 node or static value,
1368  *                         [input1 node or static value],
1369  *                         [input2 node or static value],
1370  *                         [input3 node or static value])
1371  *
1372  *  Example config lines
1373  *
1374  *     DISCRETE_LOGIC_INVERT(NODE_03,NODE_12)
1375  *     DISCRETE_LOGIC_AND(NODE_03,NODE_12,NODE_13)
1376  *     DISCRETE_LOGIC_NOR4(NODE_03,NODE_12,NODE_13,NODE_14,NODE_15)
1377  *
1378  *  Node output is always either 0.0 or 1.0 any input value !=0.0 is
1379  *  taken as a logic 1.
1380  *
1381  ***********************************************************************
1382  *
1383  * DISCRETE_XTIME_BUFFER
1384  * DISCRETE_XTIME_INVERTER
1385  * DISCRETE_XTIME_AND
1386  * DISCRETE_XTIME_NAND
1387  * DISCRETE_XTIME_OR
1388  * DISCRETE_XTIME_NOR
1389  * DISCRETE_XTIME_XOR
1390  * DISCRETE_XTIME_XNOR
1391  *
1392  *  Declaration syntax
1393  *
1394  *     DISCRETE_XTIME_xxx(name of node,
1395  *      (xxx=INV/AND/etc)
1396  *                        input0 node or static value,
1397  *                        [input1 node or static value],
1398  *                        logic Low voltage (static value),
1399  *                        logic High voltage (static value))
1400  *
1401  * These modules all take 0/1 with x_time data and perform the logic
1402  * while keeping and using the x_time anti-alaising data.
1403  * If both logic Low and High are set to 0, the 0/1 + x_time data
1404  * will be output.  Otherwise the Low/High voltages will be used
1405  * to convert the x_time to energy.
1406  *
1407  * EXAMPLES: see Mario Bros.; Donkey Kong Jr
1408  *
1409  ***********************************************************************
1410  *
1411  * DISCRETE_LOGIC_DFLIPFLOP - Standard D-type flip-flop.
1412  *                            Changes on rising edge of clock.
1413  *
1414  *    /SET       -2 ------------.
1415  *                              v
1416  *                        .-----o------.
1417  *                        |            |
1418  *    DATA       -4 ----->|            |
1419  *                        |  FLIPFLOP  |
1420  *                        |           Q|---->    Netlist node
1421  *                        |            |
1422  *    CLOCK      -3 ----->|            |
1423  *                        |            |
1424  *                        '-----o------'
1425  *                              ^
1426  *    /RESET     -1 ------------'
1427  *
1428  *  Declaration syntax
1429  *
1430  *       DISCRETE_LOGIC_DFLIPFLOP(name of node,
1431  *                                reset node or static value,
1432  *                                set node or static value,
1433  *                                clock node,
1434  *                                data node or static value)
1435  *
1436  *  Example config line
1437  *
1438  *     DISCRETE_LOGIC_DFLIPFLOP(NODE_7,NODE_17,0,NODE_13,1)
1439  *
1440  *  A flip-flop that clocks a logic 1 through on the rising edge of
1441  *  NODE_13. A logic 1 on NODE_17 resets the output to 0.
1442  *
1443  * EXAMPLES: see Hit Me, Polaris
1444  *
1445  ***********************************************************************
1446  *
1447  * DISCRETE_LOGIC_JKFLIPFLOP - Standard JK-type flip-flop.
1448  *                             Changes on falling edge of clock.
1449  *
1450  *    /SET       -2 ------------.
1451  *                              v
1452  *                        .-----o------.
1453  *                        |            |
1454  *    J          -4 ----->|            |
1455  *                        |  FLIPFLOP  |
1456  *    CLOCK      -3 ----->|           Q|---->    Netlist node
1457  *                        |            |
1458  *    K          -5 ----->|            |
1459  *                        |            |
1460  *                        '-----o------'
1461  *                              ^
1462  *    /RESET     -1 ------------'
1463  *
1464  *  Declaration syntax
1465  *
1466  *       DISCRETE_LOGIC_JKFLIPFLOP(name of node,
1467  *                                 reset node or static value,
1468  *                                 set node or static value,
1469  *                                 clock node,
1470  *                                 J node or static value,
1471  *                                 K node or static value)
1472  *
1473  * EXAMPLES: see Amazing Maze
1474  *
1475  ***********************************************************************
1476  *
1477  * DISCRETE_LOOKUP_TABLE - returns the value in a table
1478  *
1479  *  Declaration syntax
1480  *
1481  *       DISCRETE_LOOKUP_TABLE(name of node,
1482  *                             address node,
1483  *                             size of table static value,
1484  *                             address of table of double values)
1485  *
1486  ***********************************************************************
1487  *
1488  * DISCRETE_MULTIPLEX - 1 of 2/4/8 multiplexer
1489  *
1490  *                 .-------------.
1491  *   Input 0 >-----|>-<.         |
1492  *                 |    \        |
1493  *   Input 1 >-----|>-   \       |
1494  *                 |      \      |
1495  *   Input 2 >-----|>-    |\     |
1496  *                 |      | \    |
1497  *   Input 3 >-----|>-    |  o-->|------> Netlist Node
1498  *                 |      |      |
1499  *   Input 4 >-----|>-    |      |
1500  *                 |      |      |
1501  *   Input 5 >-----|>-    '------|----< Address
1502  *                 |             |     (0 shown)
1503  *   Input 6 >-----|>-           |
1504  *                 |             |
1505  *   Input 7 >-----|>-           |
1506  *                 '-------------'
1507  *
1508  *  Declaration syntax
1509  *
1510  *       DISCRETE_MULTIPLEXx(name of node,
1511  *           (x=2/4/8)       address node,
1512  *                           input 0 node or static value,
1513  *                           input 1 node or static value, ...)
1514  *
1515  ***********************************************************************
1516  *
1517  * DISCRETE_LOGIC_SHIFT - shift register
1518  *
1519  *  Declaration syntax
1520  *
1521  *     DISCRETE_LOGIC_SHIFT(name of node,
1522  *                          input node,
1523  *                          reset node or static value,
1524  *                          clock node or static value,
1525  *                          size static value,
1526  *                          options static value)
1527  *
1528  * Options:
1529  *          reset type: DISC_LOGIC_SHIFT__RESET_L
1530  *                      DISC_LOGIC_SHIFT__RESET_H
1531  *          shift type: DISC_LOGIC_SHIFT__LEFT
1532  *                      DISC_LOGIC_SHIFT__RIGHT
1533  *          clock type: DISC_CLK_ON_F_EDGE - toggle on falling edge.
1534  *                      DISC_CLK_ON_R_EDGE - toggle on rising edge.
1535  *                      DISC_CLK_BY_COUNT  - toggle specified number of times.
1536  *                      DISC_CLK_IS_FREQ   - internally clock at this frequency.
1537  *
1538  * EXAMPLES: see Sky Raider
1539  *
1540  ***********************************************************************
1541  *
1542  * DISCRETE_GAIN       - Node multiplication function output is equal
1543  * DISCRETE_MULTIPLY     to INPUT0 * INPUT1
1544  * DISCRETE_MULTADD      to (INPUT0 * INPUT1) + INPUT 2
1545  *
1546  *                        .------------.
1547  *                        |            |
1548  *    INPUT0     -1------>|     \|/    |
1549  *                        |     -+-    |---->   Netlist node
1550  *    INPUT1     -2------>|     /|\    |
1551  *                        |            |
1552  *    INPUT2     -3------>|            |
1553  *                        |            |
1554  *                        '------------'
1555  *
1556  *  Declaration syntax
1557  *
1558  *     DISCRETE_MULTIPLY  (name of node,
1559  *                         input0 node or static value,
1560  *                         input1 node or static value)
1561  *
1562  *     DISCRETE_MULTADD   (name of node,
1563  *                         input0 node or static value,
1564  *                         input1 node or static value,
1565  *                         input2 node or static value)
1566  *
1567  *     DISCRETE_GAIN      (name of node,
1568  *                         input0 node or static value,
1569  *                         static value for gain)
1570  *  Example config line
1571  *
1572  *     DISCRETE_GAIN(NODE_03,NODE_12,112.0)
1573  *
1574  *  Always enabled, multiplies the input NODE_12 by 112.0
1575  *
1576  ***********************************************************************
1577  *
1578  * DISCRETE_ONESHOT    - Monostable multivibrator, no reset
1579  * DISCRETE_ONESHOTR   - Monostable multivibrator, with reset
1580  *
1581  *  Declaration syntax
1582  *
1583  *     DISCRETE_ONESHOT   (name of node,
1584  *                         trigger node,
1585  *                         amplitude node or static value,
1586  *                         width (in seconds) node or static value,
1587  *                         type of oneshot static value)
1588  *
1589  *     DISCRETE_ONESHOTR  (name of node,
1590  *                         reset node or static value,
1591  *                         trigger node,
1592  *                         amplitude node or static value,
1593  *                         width (in seconds) node or static value,
1594  *                         type of oneshot static value)
1595  *
1596  *  Types:
1597  *
1598  *     DISC_ONESHOT_FEDGE    0x00 - trigger on falling edge (DEFAULT)
1599  *     DISC_ONESHOT_REDGE    0x01 - trigger on rising edge
1600  *
1601  *     DISC_ONESHOT_NORETRIG 0x00 - non-retriggerable (DEFAULT)
1602  *     DISC_ONESHOT_RETRIG   0x02 - retriggerable
1603  *
1604  *     DISC_OUT_ACTIVE_LOW   0x04 - output active low
1605  *     DISC_OUT_ACTIVE_HIGH  0x00 - output active high (DEFAULT)
1606  *
1607  *  NOTE: A width of 0 seconds will output a pulse of 1 sample.
1608  *        This is useful for a guaranteed minimum pulse, regardless
1609  *        of the sample rate.
1610  *
1611  * EXAMPLES: see Polaris
1612  *
1613  ***********************************************************************
1614  *
1615  * DISCRETE_RAMP - Ramp up/down circuit with clamps & reset
1616  *
1617  *                        .------------.
1618  *                        |            |
1619  *    ENAB       -0------>| FREE/CLAMP |
1620  *                        |            |
1621  *    RAMP       -1------>| FW/REV     |
1622  *                        |            |
1623  *    GRAD       -2------>| Grad/sec   |
1624  *                        |            |---->   Netlist node
1625  *    START      -3------>| Start clamp|
1626  *                        |            |
1627  *    END        -4------>| End clamp  |
1628  *                        |            |
1629  *    CLAMP      -5------>| off clamp  |
1630  *                        |            |
1631  *                        '------------'
1632  *
1633  *  Declaration syntax
1634  *
1635  *         DISCRETE_RAMP(name of node,
1636  *                       enable,
1637  *                       ramp forward/reverse node (or value),
1638  *                       gradient node (or static value),
1639  *                       start node or static value,
1640  *                       end node or static value,
1641  *                       clamp node or static value when disabled)
1642  *
1643  *  Example config line
1644  *
1645  *     DISCRETE_RAMP(NODE_9,NODE_10,NODE_11,10.0,-10.0,10.0,0)
1646  *
1647  *  Node10 when not zero will allow ramp to operate, when 0 then output
1648  *  is clamped to clamp value specified. Node11 ramp when 0 change
1649  *  gradient from start to end. 1 is reverse. Output is clamped to max-
1650  *  min values. Gradient is specified in change/second.
1651  *
1652  ***********************************************************************
1653  *
1654  * DISCRETE_SAMPHOLD - Sample & Hold circuit
1655  *
1656  *                        .------------.
1657  *                        |            |
1658  *    ENAB       -0------>|            |
1659  *                        |            |
1660  *    INP0       -1------>|   SAMPLE   |
1661  *                        |     &      |----> Netlist node
1662  *    CLOCK      -2------>|    HOLD    |
1663  *                        |            |
1664  *    CLKTYPE    -3------>|            |
1665  *                        |            |
1666  *                        '------------'
1667  *
1668  *  Declaration syntax
1669  *
1670  *     DISCRETE_SAMPHOLD(name of node,
1671  *                       enable,
1672  *                       input node,
1673  *                       clock node or static value,
1674  *                       input clock type)
1675  *
1676  *  Example config line
1677  *
1678  *     DISCRETE_SAMPHOLD(NODE_9,1,NODE_11,NODE_12,DISC_SAMPHOLD_REDGE)
1679  *
1680  *  Node9 will sample the input node 11 on the rising edge (REDGE) of
1681  *  the input clock signal of node 12.
1682  *
1683  *   DISC_SAMPHOLD_REDGE  - Rising edge clock
1684  *   DISC_SAMPHOLD_FEDGE  - Falling edge clock
1685  *   DISC_SAMPHOLD_HLATCH - Output is latched whilst clock is high
1686  *   DISC_SAMPHOLD_LLATCH - Output is latched whilst clock is low
1687  *
1688  ***********************************************************************
1689  *
1690  * DISCRETE_SWITCH     - Node switch function, output node is switched
1691  *                       by switch input to take one node/contst or
1692  *                       other. Can be nodes or constants.
1693  *
1694  *    SWITCH     -0--------------.
1695  *                               V
1696  *                        .------------.
1697  *                        |      |     |
1698  *    INPUT0     -1------}|----o       |
1699  *                        |       .--- |---->   Netlist node
1700  *    INPUT1     -2------>|----o /     |
1701  *                        |            |
1702  *                        '------------'
1703  *
1704  *  Declaration syntax
1705  *
1706  *     DISCRETE_SWITCH    (name of node,
1707  *                         enable node or static value,
1708  *                         switch node or static value,
1709  *                         input0 node or static value,
1710  *                         input1 node or static value)
1711  *
1712  *  Example config line
1713  *
1714  *     DISCRETE_SWITCH(NODE_03,1,NODE_10,NODE_90,5.0)
1715  *
1716  *  Always enabled, NODE_10 switches output to be either NODE_90 or
1717  *  constant value 5.0. Switch==0 inp0=output else inp1=output
1718  *
1719  ***********************************************************************
1720  *
1721  * DISCRETE_ASWITCH     - Node switch function, output node is same
1722  *                        as input when CTRL is above threshold.
1723  *
1724  *    CTRL       -0--------------.
1725  *                               V
1726  *                        .------------.
1727  *                        |      |     |
1728  *    INPUT0     -1------ |----- . --- |---->   Netlist node
1729  *                        |            |
1730  *                        |            |
1731  *                        '------------'
1732  *
1733  *  Declaration syntax
1734  *
1735  *     DISCRETE_ASWITCH   (name of node,
1736  *                         ctrl node or static value,
1737  *                         input node or static value,
1738  *                         threshold satic value )
1739  *
1740  *  Example config line
1741  *
1742  *     DISCRETE_ASWITCH(NODE_03,NODE_10,NODE_90, 2.73)
1743  *
1744  *  Always enabled, NODE_10 switches output to be either NODE_90 or
1745  *  constant value 0.0. Ctrl>2.73 output=NODE_90 else output=0
1746  *
1747  ***********************************************************************
1748  *
1749  * DISCRETE_TRANSFORMn - Node arithmatic logic (postfix arithmatic)
1750  *     (n=2,3,4,5)
1751  *                        .------------.
1752  *                        |            |
1753  *    INPUT0     -0------>|            |
1754  *                        |            |
1755  *    INPUT1     -1------>|  Postfix   |
1756  *                        |   stack    |----> Netlist node
1757  *    INPUT2     -2------>|   maths    |
1758  *                        |            |
1759  *    INPUT3     -3------>|            |
1760  *                        |            |
1761  *    INPUT4     -4------>|            |
1762  *                        |            |
1763  *                        '------------'
1764  *
1765  *  Declaration syntax
1766  *
1767  *     DISCRETE_TRANSFORMn(name of node,
1768  *                         input0 node or static value,
1769  *                         input1 node or static value,
1770  *                         input2 node or static value,  [optional]
1771  *                         input3 node or static value,  [optional]
1772  *                         input4 node or static value,  [optional]
1773  *                         maths string)
1774  *
1775  *  Example config line
1776  *
1777  *  DISCRETE_TRANSFORM4(NODE_12,NODE_22,50.0,120.0,33.33,"01*2+3/")
1778  *
1779  *  Arithmetic uses stack based arithmetic similar to Forth, the maths
1780  *  has 5 registers 0-4 and various arithmetic operations. The math
1781  *  string is processed from left to right in the following manner:
1782  *   0 - Push input 0 to stack
1783  *   1 - Push input 1 to stack
1784  *   2 - Push input 2 to stack
1785  *   3 - Push input 3 to stack
1786  *   4 - Push input 4 to stack
1787  *   - - Pop two values from stack, subtract and push result to stack
1788  *   + - Pop two values from stack, add and push result to stack
1789  *   / - Pop two values from stack, divide and push result to stack
1790  *   * - Pop two values from stack, multiply and push result to stack
1791  *   a - Pop one value from stack, multiply -1 if less than 0 and push result to stack
1792  *   i - Pop one value from stack, multiply -1 and push result to stack
1793  *   ! - Pop one value from stack, logical invert, push result to stack
1794  *   = - Pop two values from stack, logical = and push result to stack
1795  *   > - Pop two values from stack, logical > and push result to stack
1796  *   < - Pop two values from stack, logical < and push result to stack
1797  *   & - Pop two values from stack, binary AND and push result to stack
1798  *   | - Pop two values from stack, binary OR and push result to stack
1799  *   ^ - Pop two values from stack, binary XOR and push result to stack
1800  *   P - Push a duplicate of the last stack value back on the stack
1801  *
1802  * EXAMPLES: see Polaris
1803  *
1804  ***********************************************************************
1805  =======================================================================
1806  * from from disc_mth.inc
1807  * Component specific modules
1808  =======================================================================
1809  ***********************************************************************
1810  *
1811  * DISCRETE_COMP_ADDER - Selectable parallel component adder.
1812  *                       The total netlist out will be the parallel sum of all
1813  *                       components with their corresponding data bit = 1.
1814  *                       Set cDefault to 0 if not used.
1815  *
1816  *         common >---cDefault---.
1817  *      data&0x01 >-----c[0]-----+
1818  *      data&0x02 >-----c[1]-----+
1819  *      data&0x04 >-----c[2]-----+
1820  *      data&0x08 >-----c[3]-----+-----> netlist node
1821  *      data&0x10 >-----c[4]-----+
1822  *      data&0x20 >-----c[5]-----+
1823  *      data&0x40 >-----c[6]-----+
1824  *      data&0x80 >-----c[7]-----'
1825  *
1826  *  Declaration syntax
1827  *
1828  *     DISCRETE_COMP_ADDER(name of node,
1829  *                         data node (static value is useless),
1830  *                         address of discrete_comp_adder_table structure)
1831  *
1832  *     discrete_comp_adder_table = {type, cDefault, length, c{}}
1833  *          note: length can be a maximum of 8
1834  *
1835  *  Circuit Types:
1836  *     DISC_COMP_P_CAPACITOR - parallel capacitors
1837  *     DISC_COMP_P_RESISTOR  - parallel resistors
1838  *
1839  * EXAMPLES: see Hit Me
1840  *
1841  ***********************************************************************
1842  *
1843  * DISCRETE_DAC_R1 - R1 ladder DAC with cap smoothing and external bias
1844  *
1845  *                             rBias
1846  * data&0x01 >--/\R[0]/\--+-----/\/\----< vBias
1847  * data&0x02 >--/\R[1]/\--|
1848  * data&0x04 >--/\R[2]/\--|
1849  * data&0x08 >--/\R[3]/\--|
1850  * data&0x10 >--/\R[4]/\--|
1851  * data&0x20 >--/\R[5]/\--|
1852  * data&0x40 >--/\R[6]/\--|
1853  * data&0x80 >--/\R[7]/\--+-------------+-----> Netlist node
1854  *                        |             |
1855  *                        Z            ---
1856  *                        Z rGnd       --- cFilter
1857  *                        |             |
1858  *                       gnd           gnd
1859  *
1860  * NOTES: rBias and vBias are used together.  If not needed they should
1861  *        be set to 0.  If used, they should both have valid values.
1862  *        rGnd and cFilter should be 0 if not needed.
1863  *        A resistor value should be properly set for each resistor
1864  *        up to the ladder length.  Remember 0 is a short circuit.
1865  *        The data node is bit mapped to the ladder. valid int 0-255.
1866  *        TTL logic 0 is actually 0.2V but 0V is used.  The other parts
1867  *        have a tolerance that more then makes up for this.
1868  *
1869  *  Declaration syntax
1870  *
1871  *     DISCRETE_DAC_R1(name of node,
1872  *                     data node (static value is useless),
1873  *                     vData static value (voltage when a bit is on ),
1874  *                     address of discrete_dac_r1_ladder structure)
1875  *
1876  *     discrete_dac_r1_ladder = {ladderLength, r{}, vBias, rBias, rGnd, cFilter}
1877  *
1878  *  Note: Resistors in the ladder that are set to 0, will be handled like they
1879  *        are out of circuit.  So the bit selecting them will have no effect
1880  *        on the DAC output voltage.
1881  *
1882  * x_time - this modules automatically handles any non-integer value
1883  *          on the data input as x_time.
1884  *
1885  * EXAMPLES: see Fire Truck, Monte Carlo, Super Bug, Polaris
1886  *
1887  ***********************************************************************
1888  *
1889  * DISCRETE_DIODE_MIXER - mixes inputs through diodes
1890  *
1891  *
1892  *    input 0 >----|>|---.
1893  *                       |
1894  *    input 1 >----|>|---+----------> Netlist Node
1895  *                       |
1896  *    input 2 >----|>|---+
1897  *                       |
1898  *    input 3 >----|>|---+--/\/\/\--.
1899  *                                  |
1900  *                                 gnd
1901  *
1902  *  Declaration syntax
1903  *
1904  *     DISCRETE_DIODE_MIXERx(name of node,
1905  *         (x = 2/3/4)       input 0 node,
1906  *                           input 1 node,
1907  *                           ...,
1908  *                           address of v_junction table)
1909  *
1910  *    v_junction table can be set to nullptr if you want all diodes to
1911  *                     default to a 0.5V drop.  Otherwise use a
1912  *                     table of doubles to specify junction voltages.
1913  *
1914  * EXAMPLES: see dkong
1915  *
1916  ***********************************************************************
1917  *
1918  * DISCRETE_INTEGRATE - Various Integration circuits
1919  *
1920  *  Declaration syntax
1921  *
1922  *     DISCRETE_INTEGRATE(name of node,
1923  *                        trigger 0 node or static value,
1924  *                        trigger 1 node or static value,
1925  *                        address of discrete_integrate_info)
1926  *
1927  *     discrete_integrate_info = {type, r1, r2, r3, c, v1, vP, f0, f1, f2}
1928  *
1929  * Note: Set all unused components to 0.
1930  *       These are all single supply circuits going from gnd(0V) to vP(B+),
1931  *       so be sure to specify the vP power source.
1932  *
1933  *  Types:
1934  *
1935  *     DISC_INTEGRATE_OP_AMP_1
1936  *
1937  *       v1 >----+-------.
1938  *               |       |           c
1939  *               Z       Z      .---||----.
1940  *               Z r1    Z r2   |         |
1941  *               Z       Z      |  |\     |
1942  *               |       |      |  | \    |
1943  *               +--------------+--|- \   |
1944  *               |       |         |   >--+----> Netlist Node
1945  *              /        +---------|+ /
1946  *            |/         |         | /
1947  *   Trig0 >--| NPN      Z         |/
1948  *            |\         Z r3
1949  *              >        Z
1950  *               |       |
1951  *              gnd     gnd
1952  *
1953  *
1954  * EXAMPLES: see Tank8
1955  *
1956  *          --------------------------------------------------
1957  *
1958  *     DISC_INTEGRATE_OP_AMP_1 | DISC_OP_AMP_IS_NORTON
1959  *
1960  *                               c
1961  *                          .---||----.
1962  *                          |         |
1963  *                          |  |\     |
1964  *               r1         |  | \    |
1965  *      v1 >----ZZZZ--------+--|- \   |
1966  *                             |   >--+----> Netlist Node
1967  *               r2         .--|+ /
1968  *   Trig0 >----ZZZZ--------'  | /
1969  *                             |/
1970  *
1971  * Note: Trig0 is voltage level, not logic.
1972  *       No functions are used so set them to 0, or DISC_OP_AMP_TRIGGER_FUNCTION_NONE.
1973  *       You can also use DISCRETE_OP_AMP with type DISC_OP_AMP_IS_NORTON to emulate this.
1974  *
1975  * EXAMPLES: see Double Play
1976  *
1977  *          --------------------------------------------------
1978  *
1979  *     DISC_INTEGRATE_OP_AMP_2 | DISC_OP_AMP_IS_NORTON
1980  *
1981  *                                       c
1982  *                                  .---||----.
1983  *            r1a                   |         |
1984  *   v1 >----ZZZZ---.               |  |\     |
1985  *          .----.  |   r1b   Diode |  | \    |
1986  *          | F0 |--+--ZZZZ----|>|--+--|- \   |
1987  *          '----'                     |   >--+----> Netlist Node
1988  *            r2a       r2b         .--|+ /
1989  *   v1 >----ZZZZ---+--ZZZZ---------+  | /
1990  *          .----.  |               |  |/
1991  *          | F1 |--'               |
1992  *          '----'                  |
1993  *            r3a       r3b   Diode |
1994  *   v1 >----ZZZZ---+--ZZZZ----|>|--'
1995  *          .----.  |
1996  *          | F2 |--'
1997  *          '----'
1998  *
1999  * Note: For an explanation of the functions and trigger inputs,
2000  *       see DISCRETE_OP_AMP_TRIG_VCA below.
2001  *
2002  * EXAMPLES: see Polaris
2003  *
2004  ***********************************************************************
2005  *
2006  * DISCRETE_MIXER - Mixes multiple input signals.
2007  *
2008  *  Declaration syntax
2009  *
2010  *     DISCRETE_MIXERx(name of node,
2011  *      (x = 2 to 8)   enable node or static value,
2012  *                     input 0 node,
2013  *                     input 1 node,
2014  *                     input 2 node,  (if used)
2015  *                     input 3 node,  (if used)
2016  *                     input 4 node,  (if used)
2017  *                     input 5 node,  (if used)
2018  *                     input 6 node,  (if used)
2019  *                     input 7 node,  (if used)
2020  *                     address of discrete_mixer_info structure)
2021  *
2022  *     discrete_mixer_desc = {type, r{}, r_node{}, c{}, rI, rF, cF, cAmp, vRef, gain}
2023  *
2024  * Note: Set all unused components to 0.
2025  *       If an rNode is not used it should also be set to 0.
2026  *
2027  *  Types:
2028  *
2029  *     DISC_MIXER_IS_RESISTOR
2030  *
2031  *       rNode[0]   r[0]   c[0]
2032  *  IN0 >--zzzz-----zzzz----||---.
2033  *                               |
2034  *       rNode[1]   r[1]   c[1]  |
2035  *  IN1 >--zzzz-----zzzz----||---+--------.
2036  *   .      .        .      .    |        |      cAmp
2037  *   .      .        .      .    |        Z<------||---------> Netlist Node
2038  *   .      .        .      .    |        Z
2039  *   .   rNode[7]   r[7]   c[7]  |        Z rF
2040  *  IN7 >--zzzz-----zzzz----||---+        |
2041  *                               |        |
2042  *                              ---       |
2043  *                           cF ---       |
2044  *                               |        |
2045  *                              gnd      gnd
2046  *
2047  *  Note: The variable resistor is used in it's full volume position.
2048  *        MAME's built in volume is used for adjustment.
2049  *
2050  * EXAMPLES: see Polaris, Super Bug
2051  *
2052  *          --------------------------------------------------
2053  *
2054  *     DISC_MIXER_IS_OP_AMP
2055  *
2056  *                                               cF
2057  *                                          .----||---.
2058  *                                          |         |
2059  *        rNode[0]    r[0]   c[0]           |    rF   |
2060  *   IN0 >--zzzz------zzzz----||---.        +---ZZZZ--+
2061  *                                 |        |         |
2062  *        rNode[1]    r[1]   c[1]  |   rI   |  |\     |
2063  *   IN1 >--zzzz------zzzz----||---+--zzzz--+  | \    |
2064  *    .      .         .      .    |        '--|- \   |  cAmp
2065  *    .      .         .      .    |           |   >--+---||-----> Netlist Node
2066  *    .      .         .      .    |        .--|+ /
2067  *    .   rNode[7]    r[7]   c[7]  |        |  | /
2068  *   IN7 >--zzzz------zzzz----||---'        |  |/
2069  *                                          |
2070  *  vRef >----------------------------------'
2071  *
2072  * Note: rI is not always used and should then be 0.
2073  *
2074  * EXAMPLES: see Fire Truck, Monte Carlo
2075  *
2076  ***********************************************************************
2077  *
2078  * DISCRETE_OP_AMP - Various op-amp circuits
2079  *
2080  *  Declaration syntax
2081  *
2082  *     DISCRETE_OP_AMP(name of node,
2083  *                     enable node or static value,
2084  *                     input 0 node or static value,
2085  *                     input 1 node or static value,
2086  *                     address of discrete_op_amp_info structure)
2087  *
2088  *     discrete_op_amp_info = {type, r1, r2, r3, r4, c, vN, vP}
2089  *
2090  * Note: Set all unused components to 0.
2091  *
2092  *  Types:
2093  *
2094  *     DISC_OP_AMP_IS_NORTON
2095  *
2096  *                            c
2097  *                      .----||---.
2098  *                      |         |
2099  *             r3       |    r4   |       vP = B+
2100  *     vP >---ZZZZ------+---ZZZZ--+       vN = B-
2101  *                      |         |
2102  *             r1       |  |\     |       Note: r2 must always be used
2103  *    IN0 >---ZZZZ------+  | \    |
2104  *                      '--|- \   |
2105  *             r2          |   >--+-----> Netlist Node
2106  *    IN1 >---ZZZZ---------|+ /
2107  *                         | /
2108  *                         |/
2109  *
2110  * EXAMPLES: see Space Encounter
2111  *
2112  ***********************************************************************
2113  *
2114  * DISCRETE_OP_AMP_ONESHOT - Various op-amp one shot circuits
2115  *
2116  *  Declaration syntax
2117  *
2118  *     DISCRETE_OP_AMP_ONESHOT(name of node,
2119  *                             trigger node (voltage level),
2120  *                             address of discrete_op_amp_1sht_info structure)
2121  *
2122  *     discrete_op_amp_1sht_info = {type, r1, r2, r3, r4, r5, c1, c2, vN, vP}
2123  *
2124  *  Types:
2125  *
2126  *     DISC_OP_AMP_1SHT_1 | DISC_OP_AMP_IS_NORTON
2127  *
2128  *             c1       .---|>|---.
2129  *    gnd >----||---+---+         |
2130  *                  |   |    r4   |       vP = B+
2131  *                  Z   '---ZZZZ--+       vN = B-
2132  *                  Z r3          |
2133  *                  Z      |\     |       Note: all components must be used
2134  *             r1   |      | \    |             The oneshot is cancelled when TRIG goes low
2135  *     vP >---ZZZZ--+------|- \   |
2136  *                         |   >--+-----> Netlist Node
2137  *           c2    r2   .--|+ /   |
2138  *   TRIG >--||---ZZZZ--+  | /    |
2139  *                      |  |/     |
2140  *                      |    r5   |
2141  *                      '---ZZZZ--'
2142  *
2143  *
2144  * EXAMPLES: see Space Encounter
2145  *
2146  ***********************************************************************
2147  *
2148  * DISCRETE_OP_AMP_TRIG_VCA - Triggered Norton op amp voltage controlled amplifier.
2149  *                            This means the cap is rapidly charged through r5 when F2=1.
2150  *                            Then it discharges through r6+r7 when F2=0.
2151  *                            This voltage controls the amplitude.
2152  *                            While the diagram looks complex, usually only parts of it are used.
2153  *
2154  *  Declaration syntax
2155  *
2156  *     DISCRETE_OP_AMP_TRIG_VCA(name of node,
2157  *                              trigger 0 node or static value,
2158  *                              trigger 1 node or static value,
2159  *                              trigger 2 node or static value,
2160  *                              input 0 node or static value,
2161  *                              input 1 node or static value,
2162  *                              address of discrete_op_amp_tvca_info structure)
2163  *
2164  *     discrete_op_amp_tvca_info = { r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, c1, c2, c3, c4, v1, v2, v3, vP, f0, f1, f2, f3, f4, f5}
2165  *
2166  * Note: Set all unused components to 0.
2167  *       Set all unused functions to DISC_OP_AMP_TRIGGER_FUNCTION_NONE
2168  *       Set all unused nodes to NODE_NC.
2169  *       If function F3 is not used then set r6=0 and use only r7.
2170  *       r2 = r2a + r2b.  r3 = r3a + r3b.
2171  *       vP is the op-amp B+.
2172  *
2173  *             r2a
2174  *   IN0 >----ZZZZ-----.               r1         c4
2175  *           .----.    |     vP >------ZZZZ---+---||----.
2176  *           | F0 |----+                      |         |
2177  *           '----'    |                r2b   |    r4   |
2178  *             r3a     '---------------ZZZZ---+---ZZZZ--+
2179  *   IN1 >----ZZZZ---.                        |         |
2180  *           .----.  |                  r3b   |  |\     |
2181  *           | F1 |--+-----------------ZZZZ---+  | \    |
2182  *           '----'                           '--|- \   |
2183  *           .----.    diode     r6        r7    |   >--+----> Netlist Node
2184  *           | F2 |--+--|>|--+--ZZZZ---+--ZZZZ-+-|+ /
2185  *           '----'  |       |         |       | | /
2186  *                   |      ---      .----.    | |/
2187  *             r5    |      --- c1   | F3 |    |
2188  *    v1 >----ZZZZ---'       |       '----'    |
2189  *                          gnd                |
2190  *                                             |
2191  *           .----.    diode               r9  |
2192  *           | F4 |--+--|>|-----------+---ZZZZ-+
2193  *           '----'  |           c2   |        |
2194  *             r8    |   gnd >---||---'        |
2195  *    v2 >----ZZZZ---'                         |
2196  *           .----.    diode               r11 |
2197  *           | F5 |--+--|>|-----------+---ZZZZ-'
2198  *           '----'  |           c3   |
2199  *             r10   |   gnd >---||---'
2200  *    v3 >----ZZZZ---'
2201  *
2202  *  Function types:
2203  *
2204  *   Trigger 0, 1 and 2 are used for the functions F0 - F5.
2205  *   When the output of the function is 0, then the connection is held at 0V or gnd.
2206  *   When the output of the function is 1, then the function is an open circuit.
2207  *
2208  *   DISC_OP_AMP_TRIGGER_FUNCTION_NONE       - Not used, circuit open.
2209  *   DISC_OP_AMP_TRIGGER_FUNCTION_TRG0       - Gnd when trigger 0 is 0.
2210  *   DISC_OP_AMP_TRIGGER_FUNCTION_TRG0_INV   - Gnd when trigger 0 is 1.
2211  *   DISC_OP_AMP_TRIGGER_FUNCTION_TRG1       - Gnd when trigger 1 is 0.
2212  *   DISC_OP_AMP_TRIGGER_FUNCTION_TRG1_INV   - Gnd when trigger 1 is 1.
2213  *   DISC_OP_AMP_TRIGGER_FUNCTION_TRG2       - Gnd when trigger 2 is 0.
2214  *   DISC_OP_AMP_TRIGGER_FUNCTION_TRG2_INV   - Gnd when trigger 2 is 1.
2215  *   DISC_OP_AMP_TRIGGER_FUNCTION_TRG01_AND  - Gnd when trigger 0 or 1 are 0.
2216  *   DISC_OP_AMP_TRIGGER_FUNCTION_TRG01_NAND - Gnd when trigger 0 and 1 are 1.
2217  *
2218  * EXAMPLES: see Polaris
2219  *
2220  ***********************************************************************
2221  =======================================================================
2222  * from from disc_flt.inc
2223  * Generic modules
2224  =======================================================================
2225  ***********************************************************************
2226  *
2227  * DISCRETE_FILTER1
2228  *
2229  *  Declaration syntax
2230  *
2231  *     DISCRETE_FILTER1(name of node,
2232  *                      enable node or static value,
2233  *                      input node,
2234  *                      filter center frequency static value,
2235  *                      filter type static value)
2236  *
2237  *  Filter types: DISC_FILTER_LOWPASS,
2238  *                DISC_FILTER_HIGHPASS
2239  *                DISC_FILTER_BANDPASS
2240  *
2241  ***********************************************************************
2242  *
2243  * DISCRETE_FILTER2
2244  *
2245  *  Declaration syntax
2246  *
2247  *     DISCRETE_FILTER2(name of node,
2248  *                      enable node or static value,
2249  *                      input node,
2250  *                      filter center frequency static value,
2251  *                      damp static value,
2252  *                      filter type static value)
2253  *
2254  *  Filter types: DISC_FILTER_LOWPASS,
2255  *                DISC_FILTER_HIGHPASS
2256  *                DISC_FILTER_BANDPASS
2257  *
2258  * Note: Damp = 1/Q
2259  *
2260  ***********************************************************************
2261  =======================================================================
2262  * from from disc_flt.inc
2263  * Component specific modules
2264  =======================================================================
2265  ***********************************************************************
2266  *
2267  * DISCRETE_CRFILTER - Simple single pole CR filter network (vRef = 0)
2268  * DISCRETE_CRFILTER_VREF - Same but referenced to vRef not 0V
2269  *
2270  *                        .------------.
2271  *                        |            |
2272  *                        | CR FILTER  |
2273  *                        |            |
2274  *    INPUT1     -0------}| --| |-+--  |
2275  *                        |   C   |    |----}   Netlist node
2276  *    RVAL       -1------}|       Z    |
2277  *                        |       Z R  |
2278  *    CVAL       -2------}|       |    |
2279  *                        |      vRef  |
2280  *                        '------------'
2281  *
2282  *  Declaration syntax
2283  *
2284  *     DISCRETE_CRFILTER(name of node,
2285  *                       input node (or value)
2286  *                       resistor node or static value in OHMS
2287  *                       capacitor node or static value in FARADS)
2288  *
2289  *     DISCRETE_CRFILTER_VREF(name of node,
2290  *                            input node (or value)
2291  *                            resistor value in OHMS
2292  *                            capacitor value in FARADS,
2293  *                            vRef node or static value)
2294  *
2295  *  Example config line
2296  *
2297  *     DISCRETE_CRFILTER(NODE_11,NODE_10,100,CAP_U(1))
2298  *
2299  *  Defines a CR filter with a 100R & 1uF network
2300  *  the input is fed from NODE_10.
2301  *
2302  *  This can be also thought of as a high pass filter with a 3dB cutoff
2303  *  at:
2304  *                                  1
2305  *            Fcuttoff =      --------------
2306  *                            2*Pi*RVAL*CVAL
2307  *
2308  *  (3dB cutoff is where the output power has dropped by 3dB ie Half)
2309  *
2310  ***********************************************************************
2311  *
2312  *  DISCRETE_OP_AMP_FILTER - Various Op Amp Filters.
2313  *
2314  *  Declaration syntax
2315  *
2316  *      DISCRETE_OP_AMP_FILTER(name of node,
2317  *                             enable node or static value,
2318  *                             input 1 node or static value,
2319  *                             input 2 node or static value,
2320  *                             type static value,
2321  *                             address of discrete_op_amp_filt_info)
2322  *
2323  *      discrete_op_amp_filt_info = {r1, r2, r3, r4, rF, c1, c2, c3, vRef, vP, vN}
2324  *
2325  * Note: Set all unused components to 0.
2326  *       vP and vN are the +/- op-amp power supplies.
2327  *       vRef is 0 if Gnd.
2328  *
2329  *  Types:
2330  *
2331  *     DISC_OP_AMP_FILTER_IS_LOW_PASS_1
2332  *          First Order Low Pass Filter
2333  *
2334  *                              c1
2335  *                      .-------||---------.
2336  *                      |                  |
2337  *          r1          |       rF         |
2338  *  IN0 >--ZZZZ--.      +------ZZZZ--------+
2339  *               |      |                  |
2340  *          r2   |      |           |\     |
2341  *  IN1 >--ZZZZ--+------+--------+  | \    |
2342  *               |               '--|- \   |
2343  *          r3   |                  |   >--+----------> Netlist Node
2344  * vRef >--ZZZZ--'               .--|+ /
2345  *                               |  | /
2346  *  vRef >-----------------------'  |/
2347  *
2348  *          --------------------------------------------------
2349  *
2350  *     DISC_OP_AMP_FILTER_IS_LOW_PASS_1_A
2351  *          First Order Low Pass Filter
2352  *
2353  *                              c1
2354  *                      .-------||---------.
2355  *                      |                  |
2356  *          r1          |       rF         |
2357  *  IN0 >--ZZZZ--.      +------ZZZZ--------+
2358  *               |      |                  |
2359  *          r2   |      |           |\     |
2360  *  VP  >--ZZZZ--+------+--------+  | \    |
2361  *               |               '--|- \   |
2362  *          r3   |                  |   >--+----------> Netlist Node
2363  *  VN  >--ZZZZ--'               .--|+ /
2364  *                               |  | /
2365  *  IN1 >------------------------'  |/
2366  *
2367  *          --------------------------------------------------
2368  *
2369  *     DISC_OP_AMP_FILTER_IS_HIGH_PASS_1
2370  *          First Order High Pass Filter
2371  *
2372  *          r1                  rF
2373  *  IN0 >--ZZZZ--.      .------ZZZZ--------.
2374  *               |      |                  |
2375  *          r2   |  c1  |           |\     |
2376  *  IN1 >--ZZZZ--+--||--+--------+  | \    |
2377  *               |               '--|- \   |
2378  *          r3   |                  |   >--+----------> Netlist Node
2379  * vRef >--ZZZZ--'               .--|+ /
2380  *                               |  | /
2381  *  vRef >-----------------------'  |/
2382  *
2383  *          --------------------------------------------------
2384  *
2385  *     DISC_OP_AMP_FILTER_IS_BAND_PASS_1
2386  *          First Order Band Pass Filter
2387  *
2388  *                              c1
2389  *                      .-------||---------.
2390  *                      |                  |
2391  *          r1          |       rF         |
2392  *  IN0 >--ZZZZ--.      +------ZZZZ--------+
2393  *               |      |                  |
2394  *          r2   |  c2  |           |\     |
2395  *  IN1 >--ZZZZ--+--||--+--------+  | \    |
2396  *               |               '--|- \   |
2397  *          r3   |                  |   >--+----------> Netlist Node
2398  * vRef >--ZZZZ--'               .--|+ /
2399  *                               |  | /
2400  *  vRef >-----------------------'  |/
2401  *
2402  *          --------------------------------------------------
2403  *
2404  *     DISC_OP_AMP_FILTER_IS_BAND_PASS_1M
2405  *          Single Pole Multiple Feedback Band Pass Filter
2406  *
2407  *                         c1
2408  *                      .--||----+---------.
2409  *                      |        |         |
2410  *          r1          |        Z         |
2411  *  IN0 >--ZZZZ--.      |        Z rF      |
2412  *               |      |        Z         |
2413  *          r2   |      |  c2    |  |\     |
2414  *  IN1 >--ZZZZ--+------+--||----+  | \    |
2415  *               |               '--|- \   |
2416  *          r3   |                  |   >--+----------> Netlist Node
2417  * vRef >--ZZZZ--'               .--|+ /
2418  *                               |  | /
2419  *  vRef >-----------------------'  |/
2420  *
2421  * EXAMPLES: see Tank 8, Atari Baseball, Monte Carlo
2422  *
2423  *          --------------------------------------------------
2424  *
2425  *     DISC_OP_AMP_FILTER_IS_BAND_PASS_1M | DISC_OP_AMP_IS_NORTON
2426  *          Single Pole Multiple Feedback Band Pass Filter
2427  *
2428  *                         c1
2429  *                      .--||----+---------.
2430  *                      |        |         |
2431  *                      |        Z         |
2432  *                      |        Z rF      |
2433  *                      |        Z         |
2434  *          r1          |  c2    |  |\     |
2435  *  IN0 >--ZZZZ--+------+--||----+  | \    |
2436  *               |               '--|- \   |
2437  *          r2   |                  |   >--+----------> Netlist Node
2438  * vRef >--ZZZZ--'               .--|+ /
2439  *                    r3         |  | /
2440  *    vP >-----------ZZZZ--------'  |/
2441  *
2442  * EXAMPLES: see Space Encounter
2443  *
2444  *          --------------------------------------------------
2445  *
2446  *     DISC_OP_AMP_FILTER_IS_HIGH_PASS_0 | DISC_OP_AMP_IS_NORTON
2447  *          Basic Norton High Pass Filter
2448  *
2449  *                                   rF
2450  *          r1 = r1a + r1b       .--ZZZZ---.
2451  *                               |         |
2452  *          r1a   c1    r1b      |  |\     |
2453  *  IN1 >--ZZZZ---||---ZZZZ------+  | \    |
2454  *                               '--|- \   |
2455  *                                  |   >--+----------> Netlist Node
2456  *                               .--|+ /
2457  *                     r4        |  | /
2458  *  vRef >------------ZZZZ-------'  |/
2459  *
2460  * EXAMPLES: see Polaris
2461  *
2462  *          --------------------------------------------------
2463  *
2464  *     DISC_OP_AMP_FILTER_IS_BAND_PASS_0 | DISC_OP_AMP_IS_NORTON
2465  *          Basic Norton Band Pass Filter
2466  *
2467  *                                                    rF
2468  *                             r3 = r3a + r3b     .--ZZZZ---.
2469  *                                                |         |
2470  *           r1       r2       r3a   c3     r3b   |  |\     |
2471  *  IN1 >---ZZZZ--+--ZZZZ--+--ZZZZ---||----ZZZZ---+  | \    |
2472  *                |        |                      '--|- \   |
2473  *               ---      ---                        |   >--+---> Netlist Node
2474  *               --- c1   --- c2                  .--|+ /
2475  *                |        |                      |  | /
2476  *               gnd      gnd                     |  |/
2477  *                                         r4     |
2478  *  vRef >--------------------------------ZZZZ----'
2479  *
2480  * EXAMPLES: see Polaris
2481  *
2482  ***********************************************************************
2483  *
2484  * DISCRETE_SALLEN_KEY_FILTER - Sallen key low pass filter
2485  *
2486  *  Declaration syntax
2487  *
2488  *      DISCRETE_SALLEN_KEY_FILTER(name of node,
2489  *                                 enable node or static value,
2490  *                                 input node or static value,
2491  *                                 type static value,
2492  *                                 address of discrete_op_amp_filt_info)
2493  *
2494  *      discrete_op_amp_filt_info = {r1, r2, r3, r4, rF, c1, c2, c3, vRef, vP, vN}
2495  *
2496  * Note: Set all unused components to 0.
2497  *
2498  *  Types:
2499  *
2500  *     DISC_SALLEN_KEY_LOWPASS
2501  *
2502  *                              .---------.
2503  *                              |         |
2504  *                              |  |\     |
2505  *                              |  | \    |
2506  *                              `--|- \   |
2507  *            R1       R2          |   >--+----> Netlist Node
2508  *    IN >---ZZZZ--+--ZZZZ--+------|+ /   |
2509  *                 |        |      | /    |
2510  *                ---      ---     |/     |
2511  *                --- C1   --- C2         |
2512  *                 |        |             |
2513  *                 |       gnd            |
2514  *                 |                      |
2515  *                 `----------------------'
2516  *
2517  * EXAMPLES: see moon patrol, dkong
2518  *
2519  * References:
2520  *      http://www.t-linespeakers.org/tech/filters/Sallen-Key.html
2521  *      http://en.wikipedia.org/wiki/Sallen_Key_filter
2522  ***********************************************************************
2523  *
2524  * DISCRETE_RC_CIRCUIT_1 - RC charge/discharge circuit
2525  *
2526  *  Declaration syntax
2527  *
2528  *     DISCRETE_RC_CIRCUIT_1(name of node,
2529  *                           In0 (Logic) node,
2530  *                           In1 (Logic) node,
2531  *                           R static value,
2532  *                           C static value)
2533  *
2534  *              5V
2535  *               v
2536  *               |
2537  *           .-------.
2538  *           |  4066 |
2539  *   In0 >---|c      |
2540  *           '-------'
2541  *               |
2542  *               +------------.
2543  *               |            |
2544  *           .-------.       --- C
2545  *           |  4066 |       ---
2546  *   In1 >---|c      |        |
2547  *           '-------'       gnd
2548  *               |
2549  *               +----> Node Output
2550  *               |
2551  *               Z
2552  *               Z R
2553  *               Z
2554  *               |
2555  *              gnd
2556  *
2557  * EXAMPLES: see Sky Raider, Battlezone
2558  *
2559  ************************************************************************
2560  *
2561  * DISCRETE_RCDISC - Simple single pole RC discharge network
2562  *
2563  *                        .------------.
2564  *                        |            |
2565  *                        | RC         |
2566  *                        |            |
2567  *    INPUT1     -0------>| -ZZZZ-+--  |
2568  *                        |   R   |    |---->   Netlist node
2569  *    RVAL       -1------>|      ---   |
2570  *                        |      ---C  |
2571  *    CVAL       -2------>|       |    |
2572  *                        |      vref  |
2573  *                        '------------'
2574  *
2575  *  Declaration syntax
2576  *
2577  *     DISCRETE_RCFILTER(name of node,
2578  *                       input node (or value),
2579  *                       resistor value in OHMS,
2580  *                       capacitor value in FARADS)
2581  *
2582  *  Example config line
2583  *
2584  *     DISCRETE_RCDISC(NODE_11,10,100,CAP_U(1))
2585  *
2586  *  C discharges from 10v as indicated by RC of 100R & 1uF.
2587  *
2588  ***********************************************************************
2589  *
2590  * DISCRETE_RCDISC2  - Switched input RC discharge network
2591  *
2592  *                        .------------.
2593  *                        |            |
2594  *    SWITCH     -0------>| IP0 | IP1  |
2595  *                        |            |
2596  *    INPUT0     -1------>| -ZZZZ-.    |
2597  *                        |   R0  |    |
2598  *    RVAL0      -2------>|       |    |
2599  *                        |       |    |
2600  *    INPUT1     -3------>| -ZZZZ-+--  |
2601  *                        |   R1  |    |---->   Netlist node
2602  *    RVAL1      -4------>|      ---   |
2603  *                        |      ---C  |
2604  *    CVAL       -5------>|       |    |
2605  *                        |            |
2606  *                        '------------'
2607  *
2608  *  Declaration syntax
2609  *
2610  *      DISCRETE_RCDISC2(name of node,
2611  *                       switch,
2612  *                       input0 node (or value),
2613  *                       resistor0 value in OHMS,
2614  *                       input1 node (or value),
2615  *                       resistor1 value in OHMS,
2616  *                       capacitor value in FARADS)
2617  *
2618  *  Example config line
2619  *
2620  *     DISCRETE_RCDISC2(NODE_9,NODE_10,10.0,100,0.0,100,CAP_U(1))
2621  *
2622  *  When switched by NODE_10, C charges/discharges from 10v/0v
2623  *  as dictated by R0/C & R1/C combos respectively
2624  *  of 100R & 1uF.
2625  *
2626  ***********************************************************************
2627  *
2628  * DISCRETE_RCDISC3 - RC discharge network
2629  *
2630  * FIXME: Diode direction (for bzone)
2631  *
2632  *                        .-----------------.
2633  *                        |                 |
2634  *    ENAB       -0------>|                 |
2635  *                        |    diode  R2    |
2636  *    JV         -5------>| -+-|>|--ZZZZ-+- |---->   Netlist node (JV < 0)
2637  *                        |                 |
2638  *                        |    diode  R2    |
2639  *    INPUT1     -1------>| -+-|<|--ZZZZ-+- |---->   Netlist node (JV > 0)
2640  *                        |  |           |  |
2641  *    RVAL1      -2------>|  '-ZZZZ-+----'  |
2642  *                        |     R1  |       |
2643  *    RVAL2      -3------>|        ---      |
2644  *                        |        ---C     |
2645  *    CVAL       -4------>|         |       |
2646  *                        |        gnd      |
2647  *                        '-----------------'
2648  *
2649  *  Declaration syntax
2650  *
2651  *     DISCRETE_RCDISC3(name of node,
2652  *                      enable,
2653  *                      input node (or value),
2654  *                      R1 resistor value in OHMS,
2655  *                      R2 resistor value in OHMS,
2656  *                      capacitor value in FARADS,
2657  *                      diode junction voltage)
2658  *
2659  * The polarity of the diode junction voltage determines the polarity of the diode.
2660  *
2661  *  Example config line
2662  *
2663  *     DISCRETE_RCDISC3(NODE_11,NODE_10,10,100,220,CAP_U(1), 0.5)
2664  *
2665  *  When enabled by NODE_10, C charges from 10v as indicated by RC
2666  *  of 100R & 1uF.
2667  *
2668  * EXAMPLES: see Tank8, bzone
2669  *
2670  ***********************************************************************
2671  *
2672  * DISCRETE_RCDISC4 - RC discharge networks triggered by logic levels
2673  *
2674  *  Declaration syntax
2675  *
2676  *     DISCRETE_RCDISC4(name of node,
2677  *                      enable,
2678  *                      logic input node,
2679  *                      R1 resistor static value in OHMS,
2680  *                      R2 resistor static value in OHMS,
2681  *                      R3 resistor static value in OHMS,
2682  *                      C1 capacitor static value in FARADS,
2683  *                      vP static value in VOLTS,
2684  *                      circuit type static value)
2685  *
2686  *  Type: 1
2687  *
2688  *                             vP >---.
2689  *                                    |              .------.
2690  *                                    Z              |      |
2691  *                                    Z R2           | |\   |
2692  *             O.C.                   Z              '-|-\  |
2693  *             |\    Diode      R1    |                |  >-+---> node
2694  *   Input >---| o----|<|------ZZZZ---+--------+-------|+/
2695  *             |/                     |        |       |/
2696  *                                   ---     -----
2697  *                                C1 ---      \ / Diode
2698  *                                    |        V
2699  *                                   gnd      ---
2700  *                                             |
2701  *                                             Z
2702  *                                             Z R3
2703  *                                             Z
2704  *                                             |
2705  *                                            gnd
2706  *
2707  * EXAMPLES: see Phoenix
2708  *
2709  *          --------------------------------------------------
2710  *
2711  *  Type: 2
2712  *
2713  *      5V >---.                                    .------.
2714  *             Z                                    |      |
2715  *             Z 1k                                 | |\   |
2716  *             Z                                    '-|-\  |
2717  *             |   R1     C1         Diode            |  >-+---> node
2718  *   Input >---+--ZZZZ----||----+-----|>|----+--------|+/
2719  *                              |            |        |/
2720  *                            -----          Z
2721  *                              ^            Z R2
2722  *                             / \ Diode     Z
2723  *                            -----          |
2724  *                              |           gnd
2725  *                             gnd
2726  *
2727  * EXAMPLES: see
2728  *
2729  *          --------------------------------------------------
2730  *
2731  *  Type: 3
2732  *
2733  *      5V >---.                                     .------.
2734  *             Z                                     |      |
2735  *             Z 1k                                  | |\   |
2736  *             Z                                     '-|-\  |
2737  *             |   R1     Diode                        |  >-+---> node
2738  *   Input >---+--ZZZZ-----|>|------+---------+--------|+/
2739  *                                  |         |        |/
2740  *                                 --- C1     Z
2741  *                                 ---        Z R2
2742  *                                  |         Z
2743  *                                 gnd        |
2744  *                                           gnd
2745  *
2746  *
2747  * EXAMPLES: see
2748  *
2749  ***********************************************************************
2750  *
2751  * DISCRETE_RCDISC5 - Diode in series with R//C
2752  *
2753  *                        .---------------------.
2754  *                        |                     |
2755  *    ENAB       -0------>| -----------.        |
2756  *                        |           --        |
2757  *    INPUT1     -1------>| -|>|--+--|SW|---+-  |---->   Netlist node
2758  *                        |       |   --    |   |
2759  *    RVAL       -2------>|      ---        Z   |
2760  *                        |     C---        Z R |
2761  *    CVAL       -3------>|       |         Z   |
2762  *                        |       -----+-----   |
2763  *                        |            |gnd     |
2764  *                        '---------------------'
2765  *
2766  *  Declaration syntax
2767  *
2768  *     DISCRETE_RCDISC5(name of node,
2769  *                      enable,
2770  *                      input node (or value),
2771  *                      resistor value in OHMS,
2772  *                      capacitor value in FARADS)
2773  *
2774  *  Example config line
2775  *
2776  *     DISCRETE_RCDISC5(NODE_11,NODE_10,10,100,CAP_U(1))
2777  *
2778  *  When enabled by NODE_10, C discharges from 10v as indicated by RC
2779  *  of 100R & 1uF. If not enabled, the capacitors keeps it load and may
2780  *  still be charged through input1. The switch is assumed to be a CD4066,
2781  *  thus if not enabled the output will be drawn by R to GND since
2782  *  the switch is in high impedance mode.
2783  *
2784  *  EXAMPLES: see Spiders, Galaxian
2785  *
2786  ***********************************************************************
2787  *
2788  * DISCRETE_RCDISC_MODULATED - RC triggered by logic and modulated
2789  *
2790  *           vP  >---.
2791  *                   |
2792  *                   Z
2793  *                   Z  R1
2794  *             O.C.  Z
2795  *             |\    |   R2   C1                R3
2796  *  INPUT1 >---| o---+--ZZZ---||------+----+---ZZZ------+---> node
2797  *             |/                     |    |           /
2798  *                                   / \   Z         |/
2799  *                            Diode -----  Z R4  .---| NPN
2800  *                                    |    Z     |   |\
2801  *                                    |    |     |     >
2802  *                                   gnd  gnd    |      |
2803  *                                               |     gnd
2804  *  INPUT2 >----------ZZZ------------------------.
2805  *
2806  *  Declaration syntax
2807  *
2808  *     DISCRETE_RCDISC_MODULATED(name of node,
2809  *                      INPUT1 node (or value),
2810  *                      INPUT2 node (or value),
2811  *                      R1 value in OHMS (static value),
2812  *                      R2 value in OHMS (static value),
2813  *                      R3 value in OHMS (static value),
2814  *                      R4 value in OHMS (static value),
2815  *                      C1 value in FARADS (static value),
2816  *                      vP value in VOLTS)
2817  *
2818  * EXAMPLES: dkong
2819  *
2820  ***********************************************************************
2821  *
2822  * DISCRETE_RCFILTER - Simple single pole RC filter network (vRef = 0)
2823  * DISCRETE_RCFILTER_VREF - Same but referenced to vRef not 0V
2824  *
2825  *                        .------------.
2826  *                        |            |
2827  *    ENAB       -0------}| RC FILTER  |
2828  *                        |            |
2829  *    INPUT1     -1------}| -ZZZZ-+--  |
2830  *                        |   R   |    |----}   Netlist node
2831  *    RVAL       -2------}|      ---   |
2832  *                        |      ---C  |
2833  *    CVAL       -3------}|       |    |
2834  *                        |      vRef  |
2835  *                        '------------'
2836  *
2837  *  Declaration syntax
2838  *
2839  *     DISCRETE_RCFILTER(name of node,
2840  *                       enable
2841  *                       input node (or value)
2842  *                       resistor value in OHMS
2843  *                       capacitor value in FARADS)
2844  *
2845  *     DISCRETE_RCFILTER_VREF(name of node,
2846  *                            enable
2847  *                            input node (or value)
2848  *                            resistor value in OHMS
2849  *                            capacitor value in FARADS,
2850  *                            vRef static value)
2851  *
2852  *  Example config line
2853  *
2854  *     DISCRETE_RCFILTER(NODE_11,1,NODE_10,100,CAP_U(1))
2855  *
2856  *  Defines an always enabled RC filter with a 100R & 1uF network
2857  *  the input is fed from NODE_10.
2858  *
2859  *  This can be also thought of as a low pass filter with a 3dB cutoff
2860  *  at:
2861  *                                  1
2862  *            Fcuttoff =      --------------
2863  *                            2*Pi*RVAL*CVAL
2864  *
2865  *  (3dB cutoff is where the output power has dropped by 3dB ie Half)
2866  *
2867  * EXAMPLES: see Polaris
2868  *
2869  ***********************************************************************
2870  *
2871  * DISCRETE_RCFILTER_SW - Multiple switchable RC filters
2872  *
2873  *                             R
2874  *    INPUT      >-----------ZZZZ-+-------+----......-----> Output
2875  *                                |       |
2876  *                               +-+     +-+
2877  *    SWITCH     > Bit 0 ---->F1 | |  F2 | |
2878  *                               '-'   ^ '-'
2879  *                 Bit 1 ---------|----'  |
2880  *                                |       |
2881  *                 Bit ...       ---     ---
2882  *                               --- C1  --- C2
2883  *                                |       |
2884  *                               GND     GND
2885  *
2886  *
2887  *  Declaration syntax
2888  *
2889  *     DISCRETE_RCFILTER_SW(name of node,
2890  *                          enable,
2891  *                          input node (or value),
2892  *                          switch node (or value),
2893  *                          R in Ohms (static value),
2894  *                          C1 in Farads (static value),
2895  *                          C2 in Farads (static value),
2896  *                          C3 in Farads (static value),
2897  *                          C4 in Farads (static value))
2898  *
2899  *     This is a typical filter circuit in circusc or scramble.
2900  *     Switches are usually CD4066 with a "open" resistance of
2901  *     typical 470 Ohms at 5V.
2902  *     This circuit supports up to 4 filters.
2903  *
2904  * EXAMPLES: see circusc
2905  *
2906  ***********************************************************************
2907  *
2908  * DISCRETE_RCINTEGRATE - RC integration circuit/amplifier
2909  *
2910  *
2911  *  vP    >-------------------+
2912  *                            |
2913  *                            Z
2914  *                            Z R3
2915  *                            Z
2916  *                            |
2917  *                            +-----------------> node (Type 3)
2918  *                           /
2919  *                         |/
2920  *  INPUT  >---------------| NPN
2921  *                          \    .--------------> node (Type 2)
2922  *                           >   |  R1
2923  *                            +--+--ZZZ-+-------> node (Type 1)
2924  *                            |         |
2925  *                            Z        ---
2926  *                            Z R2    C---
2927  *                            Z         |
2928  *                            |         |
2929  *                           gnd       gnd
2930  *
2931  *  Declaration syntax
2932  *
2933  *     DISCRETE_RCINTEGRATE(name of node,
2934  *                          INPUT node (or value),
2935  *                          R1 value in OHMS,
2936  *                          R2 value in OHMS,
2937  *                          R3 value in OHMS,
2938  *                          C  value in FARADS,
2939  *                          vP node (or value in VOLTS)
2940  *                          TYPE)
2941  *
2942  * TYPE: RC_INTEGRATE_TYPE1, RC_INTEGRATE_TYPE2, RC_INTEGRATE_TYPE3
2943  *
2944  * Actually an amplifier as well. Primary reason for implementation was integration.
2945  * The integration configuration (TYPE3, R3=0) works quite well, the amplifying
2946  * configuration is missing a good, yet simple ( :-) ) transistor model. Around the
2947  * defined working point the amplifier delivers results.
2948  *
2949  * EXAMPLES: dkong
2950  *
2951  *
2952  ***********************************************************************
2953  =======================================================================
2954  * from from disc_dev.inc
2955  * Component specific modules
2956  =======================================================================
2957  ***********************************************************************
2958  *
2959  * DISCRETE_555_ASTABLE    - NE555 Chip simulation (astable mode).
2960  * DISCRETE_555_ASTABLE_CV - NE555 Chip simulation (astable mode) with CV control.
2961  *
2962  *                            v_charge     v_pos
2963  *                                 V         V
2964  *                                 |         |
2965  *                                 |         |
2966  *                                 |         |
2967  *                                 Z         |8
2968  *    _FAST_CHARGE_DIODE        R1 Z     .---------.
2969  *       (optional)                |    7|  Vcc    |
2970  *                    +--------->  +-----|Discharge|
2971  *                    |            |     |         |
2972  *                   ---           Z     |   555   |3
2973  *                   \ /        R2 Z     |      Out|---> Netlist Node
2974  *                    V            |    6|         |
2975  *                   ---           +-----|Threshold|
2976  *                    |            |     |         |
2977  *                    +--------->  +-----|Trigger  |
2978  *                                 |    2|         |---< Control Voltage
2979  *                                 |     |  Reset  |5
2980  *                                 |     '---------'
2981  *                                ---        4|
2982  *                              C ---         |
2983  *                                 |          ^
2984  *                                gnd       Reset
2985  *
2986  *  Declaration syntax
2987  *
2988  *     DISCRETE_555_ASTABLE(name of node,
2989  *                          reset node (or value),
2990  *                          R1 node (or value) in ohms,
2991  *                          R2 node (or value) in ohms,
2992  *                          C node (or value) in farads,
2993  *                          address of discrete_555_desc structure)
2994  *
2995  *     DISCRETE_555_ASTABLE_CV(name of node,
2996  *                            reset node (or value),
2997  *                            R1 node (or value) in ohms,
2998  *                            R2 node (or value) in ohms,
2999  *                            C node (or value) in farads,
3000  *                            Control Voltage node (or value),
3001  *                            address of discrete_555_desc structure)
3002  *
3003  *    discrete_555_desc =
3004  *    {
3005  *        options,        - bit mapped options
3006  *        v_pos,          - B+ voltage of 555
3007  *        v_charge,       - voltage (or node) to charge circuit  (Defaults to v_pos)
3008  *        v_out_high     - High output voltage of 555 (Defaults to v_pos - 1.2V)
3009  *    }
3010  *
3011  * The last 2 options of discrete_555_desc can use the following defaults:
3012  *     DEFAULT_555_CHARGE -  to connect v_charge to v_pos
3013  *     DEFAULT_555_HIGH   - to use the normal output voltage based on v_pos
3014  * or combine both as:
3015  *     DEFAULT_555_VALUES
3016  *
3017  * eg. {DISC_555_OUT_SQW | DISC_555_OUT_DC, 12, DEFAULT_555_VALUES}
3018  *
3019  *  Output Types: (only needed with DISC_555_OUT_SQW, DISC_555_OUT_CAP
3020  *                 and DISC_555_OUT_ENERGY)
3021  *     DISC_555_OUT_DC - Output is actual DC. (DEFAULT)
3022  *     DISC_555_OUT_AC - A cheat to make the waveform AC.
3023  *
3024  *  Waveform Types: (ORed with output types)
3025  *     DISC_555_OUT_SQW     - Output is Squarewave.  0 or v_out_high. (DEFAULT)
3026  *                            When the state changes from low to high (or high to low)
3027  *                            during a sample, the output will high (or low) for that
3028  *                            sample.  This can cause alaising effects.
3029  *     DISC_555_OUT_CAP     - Output is Timing Capacitor 'C' voltage.
3030  *     DISC_555_OUT_COUNT_F - If the 555 frequency is greater then half the sample
3031  *                            rate, then the output may change state more then once
3032  *                            during the sample.  Using this flag will cause
3033  *                            the output to be the number of falling edges that
3034  *                            happened during the sample.  This is useful to feed
3035  *                            to counter circuits.  The Output Type flag is ignored
3036  *                            when this flag is used.
3037  *     DISC_555_OUT_COUNT_R - Same as DISC_555_OUT_COUNT_F but with rising edges.
3038  *     DISC_555_OUT_ENERGY  - Same SQW, but will help reduce aliasing effects.
3039  *                            This should be used when the 555 squarewave output is used
3040  *                            as a final output and not as a clock source.
3041  *                            If the state changes from low to high 1/4 of the way
3042  *                            through the sample, then the output will be 75% of the
3043  *                            normal high value.
3044  *     DISC_555_OUT_LOGIC_X - This will output the 0/1 level of the flip-flop with
3045  *                            some eXtra info.  This x_time is in decimal remainder.
3046  *                            It lets you know the percent of sample time where the
3047  *                            flip-flop changed state.  If 0, the change did not happen
3048  *                            during the sample.  1.75 means the flip-flop is 1 and
3049  *                            switched over 1/4 of the way through the sample.
3050  *                            0.2 means the flip-flop is 0 and switched over 4/5 of
3051  *                            the way through the sample.
3052  *                            X modules can be used with counters to reduce alaising.
3053  *   DISC_555_OUT_COUNT_F_X - Same as DISC_555_OUT_COUNT_F but with x_time.
3054  *   DISC_555_OUT_COUNT_R_X - Same as DISC_555_OUT_COUNT_R but with x_time.
3055  *
3056  *  other options - DISCRETE_555_ASTABLE only:
3057  *     DISC_555_ASTABLE_HAS_FAST_CHARGE_DIODE - diode used to bypass rDischarge
3058  *                                              when charging for quicker charge.
3059  *
3060  * EXAMPLES: see Hit Me, Canyon Bomber, Sky Diver
3061  *
3062  ***********************************************************************
3063  *
3064  * DISCRETE_555_MSTABLE - NE555 Chip simulation (monostable mode)
3065  *                      - Triggered on falling edge.
3066  *
3067  *            v_charge     v_pos
3068  *                 V         V
3069  *                 |         |
3070  *                 |         |
3071  *                 |         |
3072  *                 Z         |
3073  *               R Z     .---------.
3074  *                 |     |  Vcc    |
3075  *                 +-----|Discharge|
3076  *                 |     |         |
3077  *                 |     |   555   |
3078  *                 |     |      Out|---> Netlist Node
3079  *                 |     |         |
3080  *                 +-----|Threshold|
3081  *                 |     |         |
3082  *                 |     |  Trigger|--------< Trigger
3083  *                 |     |       CV|---.
3084  *                 |     |  Reset  |   |
3085  *                 |     '---------'  --- not
3086  *                ---         |       --- needed
3087  *              C ---         |        |
3088  *                 |          ^       gnd
3089  *                gnd       Reset
3090  *
3091  *  Declaration syntax
3092  *
3093  *     DISCRETE_555_MSTABLE(name of node,
3094  *                          reset node (or value),
3095  *                          Trigger node,
3096  *                          R node (or value) in ohms,
3097  *                          C node (or value) in farads,
3098  *                          address of discrete_555_desc structure)
3099  *
3100  *    discrete_555_desc = See DISCRETE_555_ASTABLE for description.
3101  *      Note: v_charge can not be a node for this circuit.
3102  *
3103  *  Trigger Types
3104  *     DISC_555_TRIGGER_IS_LOGIC   - Input is (0 or !0) logic (DEFAULT)
3105  *     DISC_555_TRIGGER_IS_VOLTAGE - Input is actual voltage.
3106  *                                   Voltage must drop below
3107  *                                   trigger to activate.
3108  *     DISC_555_TRIGGER_IS_COUNT   - 1 when trigger, allows passing of x_time.
3109  *                                   Mainly connected with other module using
3110  *                                   a xxx_COUNT_F_X type.
3111  *     DISC_555_TRIGGER_DISCHARGES_CAP - some circuits connect an external
3112  *                                       device (transistor) to the cap to
3113  *                                       discharge it when the trigger is
3114  *                                       enabled.  Thereby allowing the one-shot
3115  *                                       to retrigger.
3116  *
3117  *  Output Types: (ORed with trigger types)
3118  *     DISC_555_OUT_DC - Output is actual DC. (DEFAULT)
3119  *     DISC_555_OUT_AC - A cheat to make the waveform AC.
3120  *
3121  *  Waveform Types: (ORed with trigger types)
3122  *     DISC_555_OUT_SQW     - Output is Squarewave.  0 or v_out_high. (DEFAULT)
3123  *     DISC_555_OUT_CAP     - Output is Timing Capacitor 'C' voltage.
3124  *     DISC_555_OUT_ENERGY  - see DISCRETE_555_MSTABLE.
3125  *
3126  * EXAMPLES: see Frogs, Sprint 8
3127  *
3128  ***********************************************************************
3129  *
3130  * DISCRETE_555_CC - Constant Current Controlled 555 Oscillator
3131  *                   Which works out to a VCO when R is fixed.
3132  *
3133  *       v_cc_source                     v_pos
3134  *           V                            V
3135  *           |     .----------------------+
3136  *           |     |                      |
3137  *           |     |                  .---------.
3138  *           |     |       rDischarge |  Vcc    |
3139  *           Z     Z        .---+-----|Discharge|
3140  *           Z R   Z rBias  |   |     |         |
3141  *           |     |        |   Z     |   555   |
3142  *           |     |        |   Z     |      Out|---> Netlist Node
3143  *         .----.  |      >-'   |     |         |
3144  *  Vin >--| CC |--+--> option  +-----|Threshold|
3145  *         '----'         >-----+     |         |
3146  *                              +-----|Trigger  |
3147  *                              |     |         |
3148  *                 .------+-----'     |  Reset  |
3149  *                 |      |           '---------'
3150  *                ---     Z                |
3151  *                --- C   Z rGnd           |
3152  *                 |      |                ^
3153  *                gnd    gnd             Reset
3154  *
3155  * Notes: R sets the current and should NEVER be 0 (short).
3156  *        The current follows the voltage I=Vin/R and charges C.
3157  *        rBias, rDischarge and rGnd should be 0 if not used.
3158  *        Reset is active low for the module.
3159  *
3160  *        Note that the CC source can be connected two different ways.
3161  *        See the option flags below for more info.
3162  *
3163  *        DISC_555_OUT_SQW mode only:
3164  *        When there is no rDischarge there is a very short discharge
3165  *        cycle (almost 0s), so the module triggers the output for 1
3166  *        sample. This does not effect the timing, just the duty cycle.
3167  *        But frequencies more the half the sample frequency will be
3168  *        limited to a max of half the sample frequency.
3169  *        This mode should be used to drive a counter for any real use.
3170  *        Just like the real thing.
3171  *
3172  *  Declaration syntax
3173  *
3174  *     DISCRETE_555_CC(name of node,
3175  *                     reset node or static value,
3176  *                     Vin node or static value,
3177  *                     R node or static value,
3178  *                     C node or static value,
3179  *                     rBias node or static value,
3180  *                     rGnd node or static value,
3181  *                     rDischarge node or static value,
3182  *                     address of discrete_555_cc_desc structure)
3183  *
3184  *     discrete_555_cc_desc =
3185  * {
3186  *         options;         - bit mapped options
3187  *         v_pos;           - B+ voltage of 555
3188  *         v_cc_source;     - Voltage of the Constant Current source
3189  *         v_out_high;      - High output voltage of 555 (Defaults to v_pos - 1.2V)
3190  *         v_cc_junction;   - The voltage drop of the Constant Current source transistor
3191  *                            (0 if Op Amp)
3192  *  }
3193  *
3194  * The last 2 options of discrete_555_desc can use the following defaults:
3195  *     DEFAULT_555_CC_SOURCE - to connect v_cc_source to v_pos
3196  *     DEFAULT_555_HIGH      - to use the normal output voltage based on v_pos
3197  * or combine both as:
3198  *     DEFAULT_555_VALUES
3199  *
3200  *  Output Types:
3201  *     See DISCRETE_555_ASTABLE for description.
3202  *
3203  *  Waveform Types: (ORed with output types)
3204  *     See DISCRETE_555_ASTABLE for description.
3205  *
3206  *  Other Flags:
3207  *     DISCRETE_555_CC_TO_DISCHARGE_PIN - The CC source connects to the
3208  *                                        discharge pin. (Default)
3209  *     DISCRETE_555_CC_TO_CAP           - The CC source connects to the
3210  *                                        threshold pin.  This is not fully
3211  *                                        implemented yet.  It only works properly
3212  *                                        when only rDischarge is defined.
3213  *
3214  * EXAMPLES: see Fire Truck, Monte Carlo, Super Bug
3215  *
3216  ***********************************************************************
3217  *
3218  * DISCRETE_555_VCO1    - Op-Amp based 555 VCO circuit.
3219  * DISCRETE_555_VCO1_CV - Op-Amp based 555 VCO circuit with CV control.
3220  *
3221  *                               c
3222  *  .------------------------+---||----+---------------------------> DISC_555_OUT_CAP
3223  *  |                        |         |
3224  *  |                        |   |\    |
3225  *  |              r1        |   | \   |      .------------.
3226  *  |  vIn1 >--+--ZZZZ-------+---|- \  |      |            |
3227  *  |          |                 |   >-+---+--|Threshold   |
3228  *  |          |   r2            |+ /      |  |         Out|------> DISC_555_OUT_xx
3229  *  Z          '--ZZZZ--+--------| /       '--|Trigger     |
3230  *  Z r4                |        |/           |            |
3231  *  Z                   Z                     |       Reset|------< Reset
3232  *  |                   Z r3          vIn2 >--|CV          |
3233  * .----.               Z                     |            |
3234  * |  En|<--------.     |                 .---|Discharge   |
3235  * '----'         |    gnd                |   '------------'
3236  *   |            |                       |
3237  *  gnd           '-----------------------+---ZZZZ------> v_charge (ignored)
3238  *                                             rX
3239  *
3240  *  Declaration syntax
3241  *
3242  *     DISCRETE_555_VCO1(name of node,
3243  *                       reset node or static value,
3244  *                       Vin1 node or static value,
3245  *                       address of discrete_555_vco1_desc structure)
3246  *
3247  *     DISCRETE_555_VCO1_CV(name of node,
3248  *                          reset node or static value,
3249  *                          Vin1 node or static value,
3250  *                          Vin2 (CV) node or static value,
3251  *                          address of discrete_555_vco1_desc structure)
3252  *
3253  *  discrete_555_vco1_desc =
3254  *  {
3255  *      options,            - bit mapped options
3256  *      r1, r2, r3, r4, c,
3257  *      v_pos,              - B+ voltage of 555
3258  *      v_out_high,         - High output voltage of 555 (Defaults to v_pos - 1.2V)
3259  *  }
3260  *
3261  * The last option of discrete_555_vco1_desc can use the following default:
3262  *     DEFAULT_555_HIGH      - to use the normal output voltage based on v_pos
3263  *
3264  * Notes: The value of resistor rX is not needed.  It is just a pull-up
3265  *        for the discharge output.
3266  *        The 'En' block can be a transistor or 4066 switch.  It connects
3267  *        r4 to ground when En is high.
3268  *
3269  ***********************************************************************
3270  *
3271  * DISCRETE_566 - NE566 VCO simulation.
3272  *
3273  *       v_charge        v_pos
3274  *           V             V
3275  *           |             |
3276  *           |             |
3277  *           |    R    .-------.
3278  *           '---/\/\--|6  8   |
3279  *                     |       |
3280  *   vMod >------------|5   3/4|---------> Netlist Node
3281  *                     |       |
3282  *                 .---|7  1   |
3283  *                 |   '-------'
3284  *                ---      |
3285  *                --- C    |
3286  *                 |       |
3287  *               v_neg   v_neg
3288  *
3289  * Note: There is usually a 0.001uF cap between pins 5 & 6.
3290  *       This is for circuit stability and can be ignored for simulation purposes.
3291  *
3292  *  Declaration syntax
3293  *
3294  *     DISCRETE_566(name of node,
3295  *                  vMod node or static value,
3296  *                  R node or static value in ohms,
3297  *                  C node or static value in Farads,
3298  *                  v_pos static value
3299  *                  v_neg static value
3300  *                  v_charge node or static value
3301  *                  options)
3302  *
3303  *  Output Types:
3304  *     DISC_566_OUT_DC - Output is actual DC. (DEFAULT)
3305  *     DISC_566_OUT_AC - A cheat to make the waveform AC.
3306  *
3307  *  Waveform Types:
3308  *     DISC_566_OUT_SQUARE   - Pin 3 Square Wave Output (DEFAULT)
3309  *     DISC_566_OUT_ENERGY   - Pin 3 anti-aliased Square Wave Output
3310  *     DISC_566_OUT_TRIANGLE - Pin 4 Triangle Wave Output
3311  *     DISC_566_OUT_LOGIC    - Internal Flip/Flop Output
3312  *     DISC_566_COUNT_F      - # of falling edges
3313  *     DISC_566_COUNT_R      - # of rising edges
3314  *     DISC_566_COUNT_F_X    - # of falling edges with x-time
3315  *     DISC_566_COUNT_R_X    - # of rising edges with x-time
3316  *
3317  * EXAMPLES: see Starship 1
3318  *
3319  ***********************************************************************
3320  *
3321  * DISCRETE_74LS624 - VCO.  1/2 of 74LS629.
3322  *
3323  * The datasheet gives no formulae. The implementation is based on
3324  * testing a 74LS629.
3325  *
3326  * For a LS628, use VRng = 3.2
3327  *
3328  *                                    V+
3329  *                                     |
3330  *                  R_rng_in     .---------.
3331  *   vRng >-----------ZZZZ-------|Rng  V+  |
3332  *           R_freq_in           |         |
3333  *   vMod >---ZZZZ-+-------------|Freq   Z |---------> Netlist Node
3334  *                 |             |         |
3335  *      C_freq_in ---        .---|CX1      |
3336  *                ---        |   |         |
3337  *                 |        ---  |         |
3338  *                 |      C ---  |         |
3339  *                Gnd        |   |         |
3340  *                           '---|CX2      |
3341  *                               '---------'
3342  *                                   |
3343  *                                  GND
3344  *
3345  *  Declaration syntax
3346  *
3347  *     DISCRETE_74LS624(name of node,(NODE,ENAB,VMOD,VRNG,C,R_FREQ_IN,C_FREQ_IN,R_RNG_IN,OUTTYPE)
3348  *                      enable node or static value,
3349  *                      vMod node or static value,
3350  *                      vRng static value,
3351  *                      C static value in Farads,
3352  *                      R_freq_in static value in Ohms,
3353  *                      C_freq_in static value in Farads,
3354  *                      R_rng_in static value in Ohms,
3355  *                     Type of output static value)
3356  *
3357  * Type of Output
3358  *      DISC_LS624_OUT_SQUARE      - 4.4V square wave
3359  *      DISC_LS624_OUT_ENERGY      - 4.4V anti-aliased square wave
3360  *      DISC_LS624_OUT_LOGIC       - Logic ( 0 or 1)
3361  *      DISC_LS624_OUT_LOGIC_X     - Logic ( 0 or 1) with x_time
3362  *      DISC_LS624_OUT_COUNT_F     - Number of Falling edges
3363  *      DISC_LS624_OUT_COUNT_F_X   - Number of Falling edges with x_time
3364  *      DISC_LS624_OUT_COUNT_R     - Number of Rising  edges
3365  *      DISC_LS624_OUT_COUNT_R_X   - Number of Rising  edges with x_time
3366  *
3367  *
3368  * EXAMPLES: see Donkey Kong Jr.; Mario Bros.
3369  *
3370  ***********************************************************************
3371  *
3372  * DISCRETE_CUSTOMx - Link to custom code
3373  *     where x = 1 to 9
3374  *
3375  *  Declaration syntax
3376  *
3377  *     DISCRETE_CUSTOMx(name of node,
3378  *                      input 0 node or static value, ...)
3379  *
3380  *     discrete_custom_info = {discrete_module, custom}
3381  *                             discrete_module  = discrete module definition
3382  *                             custom = address of specific initialization data
3383  *
3384  * In most case, you should be able to use
3385  *
3386  *     discrete_custom_info = {DISCRETE_CUSTOM_MODULE(basename, context type), custom}
3387  *
3388  * if you have used DISCRETE_STEP(basename) and DISCRETE_RESET(basename) to define
3389  * the step/reset procedures.
3390  *
3391  * EXAMPLES: see Sky Raider, Donkey Kong
3392  *
3393  ***********************************************************************
3394  =======================================================================
3395  * Debugging modules.
3396  =======================================================================
3397  ***********************************************************************
3398  *
3399  * DISCRETE_CSVLOGx - Dump n nodes into a csv (comma separated value) file
3400  *
3401  *  Declaration syntax
3402  *
3403  *     DISCRETE_CSVLOGx(node 1, ...)
3404  *         where x = 1 to 5
3405  *
3406  *  WARNING: This can rapidally use up a lot of hard drive space.
3407  *           48kHz sampling of 5 nodes used 217M after 80 seconds.
3408  *
3409  *  Use this to monitor nodes while debugging the driver.  You should
3410  *  remove these nodes from the final driver.  You can use up to a maximum
3411  *  DISCRETE_MAX_CSVLOGS.  Each file will be called discreteX_Y.csv,
3412  *  where X is the sound tag.  Y is 0-9, in the order the file is
3413  *  created in the driver.
3414  *
3415  *  This can be used to monitor how multiple nodes relate to each other.
3416  *  The resulting file can be imported to a spreadsheet.
3417  *
3418  ************************************************************************
3419  *
3420  * DISCRETE_WAVLOG - Dump nodes into a wav file
3421  *
3422  *  Declaration syntax
3423  *
3424  *     DISCRETE_WAVLOG1(node,
3425  *                       static gain for node)
3426  *
3427  *     DISCRETE_WAVLOG2(left node,
3428  *                       static gain for left node,
3429  *                       right node,
3430  *                       static gain for right node)
3431  *
3432  *  Use this to monitor nodes while debugging the driver.  You should
3433  *  remove these nodes from the final driver.  You can use up to a maximum
3434  *  of DISCRETE_MAX_WAVLOGS.  Each file will be called discreteX_Y.wav,
3435  *  where X is the sound tag.  Y is 0-9, in the order the file is
3436  *  created in the driver.
3437  *
3438  *  This can be used to monitor how a node's input affects it's output.
3439  *  Monitor the input trigger against the final effect, etc.  The resulting
3440  *  file can be played/viewed etc. by music player/editor software.
3441  *
3442  *  When logging nodes that are voltage levels, you may want to use a
3443  *  gain of 1000.  This will make the wav sample level reflect milli-volts.
3444  *
3445  ************************************************************************
3446  =======================================================================
3447  * Must be last module.
3448  =======================================================================
3449  ***********************************************************************
3450  *
3451  * DISCRETE_OUTPUT - Single output node to Mame mixer and output
3452  *
3453  *                            .----------.       .
3454  *                            |          |    .-/|
3455  *      Netlist node -------->| OUTPUT   |----|  | Sound Output
3456  *                            |          |    '-\|
3457  *                            '----------'       '
3458  *
3459  *  Declaration syntax
3460  *
3461  *     DISCRETE_OUTPUT(name of output node, gain)
3462  *
3463  *  Example config line
3464  *
3465  *     DISCRETE_OUTPUT(NODE_02, 1000)
3466  *
3467  *  Output stream will be generated from the NODE_02 output stream * 1000.
3468  *
3469  *  Multiple outputs can be used up to DISCRETE_MAX_OUTPUTS.
3470  *
3471  ************************************************************************/
3472 
3473 /*************************************
3474  *
3475  *  macros
3476  *  see also: emu\machine\rescap.h
3477  *
3478  *************************************/
3479 
3480 /* calculate charge exponent using discrete sample time */
3481 #define RC_CHARGE_EXP(rc)                       (1.0 - exp(-this->sample_time() / (rc)))
3482 /* calculate charge exponent using given sample time */
3483 #define RC_CHARGE_EXP_DT(rc, dt)                (1.0 - exp(-(dt) / (rc)))
3484 #define RC_CHARGE_NEG_EXP_DT(rc, dt)            (1.0 - exp((dt) / (rc)))
3485 
3486 /* calculate discharge exponent using discrete sample time */
3487 #define RC_DISCHARGE_EXP(rc)                    (exp(-this->sample_time() / (rc)))
3488 /* calculate discharge exponent using given sample time */
3489 #define RC_DISCHARGE_EXP_DT(rc, dt)             (exp(-(dt) / (rc)))
3490 #define RC_DISCHARGE_NEG_EXP_DT(rc, dt)         (exp((dt) / (rc)))
3491 
3492 #define FREQ_OF_555(_r1, _r2, _c)   (1.49 / ((_r1 + 2 * _r2) * _c))
3493 
3494 /*************************************
3495  *
3496  *  Interface & Naming
3497  *
3498  *************************************/
3499 
3500 #define DISCRETE_CLASS_FUNC(_class, _func)      DISCRETE_CLASS_NAME(_class) :: _func
3501 
3502 #define DISCRETE_STEP(_class)                   void DISCRETE_CLASS_FUNC(_class, step)(void)
3503 #define DISCRETE_RESET(_class)                  void DISCRETE_CLASS_FUNC(_class, reset)(void)
3504 #define DISCRETE_START(_class)                  void DISCRETE_CLASS_FUNC(_class, start)(void)
3505 #define DISCRETE_STOP(_class)                   void DISCRETE_CLASS_FUNC(_class, stop)(void)
3506 #define DISCRETE_DECLARE_INFO(_name)            const _name *info = (const  _name *)this->custom_data();
3507 
3508 //#define DISCRETE_INPUT(_num)                  (*(this->m_input[_num]))
3509 #define DISCRETE_INPUT(_num)                    (input(_num))
3510 
3511 /*************************************
3512  *
3513  *  Core constants
3514  *
3515  *************************************/
3516 
3517 #define DISCRETE_MAX_NODES                  300
3518 #define DISCRETE_MAX_INPUTS                 10
3519 #define DISCRETE_MAX_OUTPUTS                8
3520 
3521 #define DISCRETE_MAX_TASK_GROUPS            10
3522 
3523 
3524 /*************************************
3525  *
3526  *  Node-specific constants
3527  *
3528  *************************************/
3529 
3530 #define DEFAULT_TTL_V_LOGIC_1               3.4
3531 
3532 #define DISC_LOGADJ                         1.0
3533 #define DISC_LINADJ                         0.0
3534 
3535 /* DISCRETE_COMP_ADDER types */
3536 #define DISC_COMP_P_CAPACITOR               0x00
3537 #define DISC_COMP_P_RESISTOR                0x01
3538 
3539 /* clk types */
3540 #define DISC_CLK_MASK                       0x03
3541 #define DISC_CLK_ON_F_EDGE                  0x00
3542 #define DISC_CLK_ON_R_EDGE                  0x01
3543 #define DISC_CLK_BY_COUNT                   0x02
3544 #define DISC_CLK_IS_FREQ                    0x03
3545 
3546 #define DISC_COUNT_DOWN                     0
3547 #define DISC_COUNT_UP                       1
3548 
3549 #define DISC_COUNTER_IS_7492                0x08
3550 
3551 #define DISC_OUT_MASK                       0x30
3552 #define DISC_OUT_DEFAULT                    0x00
3553 #define DISC_OUT_IS_ENERGY                  0x10
3554 #define DISC_OUT_HAS_XTIME                  0x20
3555 
3556 /* Function possibilities for the LFSR feedback nodes */
3557 /* 2 inputs, one output                               */
3558 #define DISC_LFSR_XOR                       0
3559 #define DISC_LFSR_OR                        1
3560 #define DISC_LFSR_AND                       2
3561 #define DISC_LFSR_XNOR                      3
3562 #define DISC_LFSR_NOR                       4
3563 #define DISC_LFSR_NAND                      5
3564 #define DISC_LFSR_IN0                       6
3565 #define DISC_LFSR_IN1                       7
3566 #define DISC_LFSR_NOT_IN0                   8
3567 #define DISC_LFSR_NOT_IN1                   9
3568 #define DISC_LFSR_REPLACE                   10
3569 #define DISC_LFSR_XOR_INV_IN0               11
3570 #define DISC_LFSR_XOR_INV_IN1               12
3571 
3572 /* LFSR Flag Bits */
3573 #define DISC_LFSR_FLAG_OUT_INVERT           0x01
3574 #define DISC_LFSR_FLAG_RESET_TYPE_L         0x00
3575 #define DISC_LFSR_FLAG_RESET_TYPE_H         0x02
3576 #define DISC_LFSR_FLAG_OUTPUT_F0            0x04
3577 #define DISC_LFSR_FLAG_OUTPUT_SR_SN1        0x08
3578 
3579 /* Sample & Hold supported clock types */
3580 #define DISC_SAMPHOLD_REDGE                 0
3581 #define DISC_SAMPHOLD_FEDGE                 1
3582 #define DISC_SAMPHOLD_HLATCH                2
3583 #define DISC_SAMPHOLD_LLATCH                3
3584 
3585 /* Shift options */
3586 #define DISC_LOGIC_SHIFT__RESET_L           0x00
3587 #define DISC_LOGIC_SHIFT__RESET_H           0x10
3588 #define DISC_LOGIC_SHIFT__LEFT              0x00
3589 #define DISC_LOGIC_SHIFT__RIGHT             0x20
3590 
3591 /* Maximum number of resistors in ladder chain */
3592 #define DISC_LADDER_MAXRES                  8
3593 
3594 /* Filter types */
3595 #define DISC_FILTER_LOWPASS                 0
3596 #define DISC_FILTER_HIGHPASS                1
3597 #define DISC_FILTER_BANDPASS                2
3598 
3599 /* Mixer types */
3600 #define DISC_MIXER_IS_RESISTOR              0
3601 #define DISC_MIXER_IS_OP_AMP                1
3602 #define DISC_MIXER_IS_OP_AMP_WITH_RI        2   /* Used only internally.  Use DISC_MIXER_IS_OP_AMP */
3603 
3604 /* Triggered Op Amp Functions */
3605 enum
3606 {
3607 	DISC_OP_AMP_TRIGGER_FUNCTION_NONE,
3608 	DISC_OP_AMP_TRIGGER_FUNCTION_TRG0,
3609 	DISC_OP_AMP_TRIGGER_FUNCTION_TRG0_INV,
3610 	DISC_OP_AMP_TRIGGER_FUNCTION_TRG1,
3611 	DISC_OP_AMP_TRIGGER_FUNCTION_TRG1_INV,
3612 	DISC_OP_AMP_TRIGGER_FUNCTION_TRG2,
3613 	DISC_OP_AMP_TRIGGER_FUNCTION_TRG2_INV,
3614 	DISC_OP_AMP_TRIGGER_FUNCTION_TRG01_AND,
3615 	DISC_OP_AMP_TRIGGER_FUNCTION_TRG01_NAND
3616 };
3617 
3618 
3619 /* Common Op Amp Flags and values */
3620 #define DISC_OP_AMP_IS_NORTON               0x100
3621 #define OP_AMP_NORTON_VBE                   0.5     // This is the norton junction voltage. Used only internally.
3622 #define OP_AMP_VP_RAIL_OFFSET               1.5     // This is how close an op-amp can get to the vP rail. Used only internally.
3623 
3624 /* Integrate options */
3625 #define DISC_INTEGRATE_OP_AMP_1             0x00
3626 #define DISC_INTEGRATE_OP_AMP_2             0x10
3627 
3628 /* op amp 1 shot types */
3629 #define DISC_OP_AMP_1SHT_1                  0x00
3630 
3631 /* Op Amp Filter Options */
3632 #define DISC_OP_AMP_FILTER_IS_LOW_PASS_1    0x00
3633 #define DISC_OP_AMP_FILTER_IS_HIGH_PASS_1   0x10
3634 #define DISC_OP_AMP_FILTER_IS_BAND_PASS_1   0x20
3635 #define DISC_OP_AMP_FILTER_IS_BAND_PASS_1M  0x30
3636 #define DISC_OP_AMP_FILTER_IS_HIGH_PASS_0   0x40
3637 #define DISC_OP_AMP_FILTER_IS_BAND_PASS_0   0x50
3638 #define DISC_OP_AMP_FILTER_IS_LOW_PASS_1_A  0x60
3639 
3640 #define DISC_OP_AMP_FILTER_TYPE_MASK        (0xf0 | DISC_OP_AMP_IS_NORTON)  // Used only internally.
3641 
3642 /* Sallen-Key filter Options */
3643 #define DISC_SALLEN_KEY_LOW_PASS            0x01
3644 #define DISC_SALLEN_KEY_HIGH_PASS           0x02
3645 
3646 
3647 /* Op Amp Oscillator Flags */
3648 #define DISC_OP_AMP_OSCILLATOR_TYPE_MASK    (0xf0 | DISC_OP_AMP_IS_NORTON)  // Used only internally.
3649 #define DISC_OP_AMP_OSCILLATOR_1            0x00
3650 #define DISC_OP_AMP_OSCILLATOR_2            0x10
3651 #define DISC_OP_AMP_OSCILLATOR_VCO_1        0x20
3652 #define DISC_OP_AMP_OSCILLATOR_VCO_2        0x30
3653 #define DISC_OP_AMP_OSCILLATOR_VCO_3        0x40
3654 
3655 #define DISC_OP_AMP_OSCILLATOR_OUT_MASK         0x07
3656 #define DISC_OP_AMP_OSCILLATOR_OUT_CAP          0x00
3657 #define DISC_OP_AMP_OSCILLATOR_OUT_SQW          0x01
3658 #define DISC_OP_AMP_OSCILLATOR_OUT_ENERGY       0x02
3659 #define DISC_OP_AMP_OSCILLATOR_OUT_LOGIC_X      0x03
3660 #define DISC_OP_AMP_OSCILLATOR_OUT_COUNT_F_X    0x04
3661 #define DISC_OP_AMP_OSCILLATOR_OUT_COUNT_R_X    0x05
3662 
3663 /* Schmitt Oscillator Options */
3664 #define DISC_SCHMITT_OSC_IN_IS_LOGIC        0x00
3665 #define DISC_SCHMITT_OSC_IN_IS_VOLTAGE      0x01
3666 
3667 #define DISC_SCHMITT_OSC_ENAB_IS_AND        0x00
3668 #define DISC_SCHMITT_OSC_ENAB_IS_NAND       0x02
3669 #define DISC_SCHMITT_OSC_ENAB_IS_OR         0x04
3670 #define DISC_SCHMITT_OSC_ENAB_IS_NOR        0x06
3671 
3672 #define DISC_SCHMITT_OSC_ENAB_MASK          0x06    /* Bits that define output enable type.
3673                                                      * Used only internally in module. */
3674 
3675 /* 555 Common output flags */
3676 #define DISC_555_OUT_DC                     0x00
3677 #define DISC_555_OUT_AC                     0x10
3678 
3679 #define DISC_555_TRIGGER_IS_LOGIC           0x00
3680 #define DISC_555_TRIGGER_IS_VOLTAGE         0x20
3681 #define DISC_555_TRIGGER_IS_COUNT           0x40
3682 #define DSD_555_TRIGGER_TYPE_MASK           0x60
3683 #define DISC_555_TRIGGER_DISCHARGES_CAP     0x80
3684 
3685 #define DISC_555_OUT_SQW                    0x00    /* Squarewave */
3686 #define DISC_555_OUT_CAP                    0x01    /* Cap charge waveform */
3687 #define DISC_555_OUT_COUNT_F                0x02    /* Falling count */
3688 #define DISC_555_OUT_COUNT_R                0x03    /* Rising count */
3689 #define DISC_555_OUT_ENERGY                 0x04
3690 #define DISC_555_OUT_LOGIC_X                0x05
3691 #define DISC_555_OUT_COUNT_F_X              0x06
3692 #define DISC_555_OUT_COUNT_R_X              0x07
3693 
3694 #define DISC_555_OUT_MASK                   0x07    /* Bits that define output type.
3695                                                  * Used only internally in module. */
3696 
3697 #define DISC_555_ASTABLE_HAS_FAST_CHARGE_DIODE      0x80
3698 #define DISCRETE_555_CC_TO_DISCHARGE_PIN            0x00
3699 #define DISCRETE_555_CC_TO_CAP                      0x80
3700 
3701 /* 566 output flags */
3702 #define DISC_566_OUT_DC                     0x00
3703 #define DISC_566_OUT_AC                     0x10
3704 
3705 #define DISC_566_OUT_SQUARE                 0x00    /* Squarewave */
3706 #define DISC_566_OUT_ENERGY                 0x01    /* anti-aliased Squarewave */
3707 #define DISC_566_OUT_TRIANGLE               0x02    /* Triangle waveform */
3708 #define DISC_566_OUT_LOGIC                  0x03    /* 0/1 logic output */
3709 #define DISC_566_OUT_COUNT_F                0x04
3710 #define DISC_566_OUT_COUNT_R                0x05
3711 #define DISC_566_OUT_COUNT_F_X              0x06
3712 #define DISC_566_OUT_COUNT_R_X              0x07
3713 #define DISC_566_OUT_MASK                   0x07    /* Bits that define output type.
3714                                                      * Used only internally in module. */
3715 
3716 /* LS624 output flags */
3717 #define DISC_LS624_OUT_SQUARE               0x01
3718 #define DISC_LS624_OUT_ENERGY               0x02
3719 #define DISC_LS624_OUT_LOGIC                0x03
3720 #define DISC_LS624_OUT_LOGIC_X              0x04
3721 #define DISC_LS624_OUT_COUNT_F              0x05
3722 #define DISC_LS624_OUT_COUNT_R              0x06
3723 #define DISC_LS624_OUT_COUNT_F_X            0x07
3724 #define DISC_LS624_OUT_COUNT_R_X            0x08
3725 
3726 /* Oneshot types */
3727 #define DISC_ONESHOT_FEDGE                  0x00
3728 #define DISC_ONESHOT_REDGE                  0x01
3729 
3730 #define DISC_ONESHOT_NORETRIG               0x00
3731 #define DISC_ONESHOT_RETRIG                 0x02
3732 
3733 #define DISC_OUT_ACTIVE_LOW                 0x04
3734 #define DISC_OUT_ACTIVE_HIGH                0x00
3735 
3736 #define DISC_CD4066_THRESHOLD               2.75
3737 
3738 /* Integrate */
3739 
3740 #define DISC_RC_INTEGRATE_TYPE1             0x00
3741 #define DISC_RC_INTEGRATE_TYPE2             0x01
3742 #define DISC_RC_INTEGRATE_TYPE3             0x02
3743 
3744 /*************************************
3745  *
3746  *  Classes and structs to handle
3747  *  linked lists.
3748  *
3749  *************************************/
3750 
3751 /*************************************
3752  *
3753  *  Node-specific struct types
3754  *
3755  *************************************/
3756 
3757 struct discrete_lfsr_desc
3758 {
3759 	int clock_type;
3760 	int bitlength;
3761 	int reset_value;
3762 
3763 	int feedback_bitsel0;
3764 	int feedback_bitsel1;
3765 	int feedback_function0;         /* Combines bitsel0 & bitsel1 */
3766 
3767 	int feedback_function1;         /* Combines funct0 & infeed bit */
3768 
3769 	int feedback_function2;         /* Combines funct1 & shifted register */
3770 	int feedback_function2_mask;    /* Which bits are affected by function 2 */
3771 
3772 	int flags;
3773 
3774 	int output_bit;
3775 };
3776 
3777 
3778 struct discrete_op_amp_osc_info
3779 {
3780 	uint32_t  type;
3781 	double  r1;
3782 	double  r2;
3783 	double  r3;
3784 	double  r4;
3785 	double  r5;
3786 	double  r6;
3787 	double  r7;
3788 	double  r8;
3789 	double  c;
3790 	double  vP;     // Op amp B+
3791 };
3792 
3793 
3794 #define DEFAULT_7414_VALUES     1.7, 0.9, 3.4
3795 
3796 #define DEFAULT_74LS14_VALUES   1.6, 0.8, 3.4
3797 
3798 struct discrete_schmitt_osc_desc
3799 {
3800 	double  rIn;
3801 	double  rFeedback;
3802 	double  c;
3803 	double  trshRise;   // voltage that triggers the gate input to go high (vGate) on rise
3804 	double  trshFall;   // voltage that triggers the gate input to go low (0V) on fall
3805 	double  vGate;      // the output high voltage of the gate that gets fedback through rFeedback
3806 	int     options;    // bitmapped options
3807 };
3808 
3809 
3810 struct discrete_comp_adder_table
3811 {
3812 	int     type;
3813 	double  cDefault;               // Default component.  0 if not used.
3814 	int     length;
3815 	double  c[DISC_LADDER_MAXRES];  // Component table
3816 };
3817 
3818 
3819 struct discrete_dac_r1_ladder
3820 {
3821 	int     ladderLength;       // 2 to DISC_LADDER_MAXRES.  1 would be useless.
3822 	double  r[DISC_LADDER_MAXRES];  // Don't use 0 for valid resistors.  That is a short.
3823 	double  vBias;          // Voltage Bias resistor is tied to (0 = not used)
3824 	double  rBias;          // Additional resistor tied to vBias (0 = not used)
3825 	double  rGnd;           // Resistor tied to ground (0 = not used)
3826 	double  cFilter;        // Filtering cap (0 = not used)
3827 };
3828 
3829 
3830 struct discrete_integrate_info
3831 {
3832 	uint32_t  type;
3833 	double  r1;     // r1a + r1b
3834 	double  r2;     // r2a + r2b
3835 	double  r3;     // r3a + r3b
3836 	double  c;
3837 	double  v1;
3838 	double  vP;
3839 	double  f0;
3840 	double  f1;
3841 	double  f2;
3842 };
3843 
3844 
3845 #define DISC_MAX_MIXER_INPUTS   8
3846 struct discrete_mixer_desc
3847 {
3848 	int     type;
3849 	double  r[DISC_MAX_MIXER_INPUTS];       /* static input resistance values.  These are in series with rNode, if used. */
3850 	int     r_node[DISC_MAX_MIXER_INPUTS];  /* variable resistance nodes, if needed.  0 if not used. */
3851 	double  c[DISC_MAX_MIXER_INPUTS];
3852 	double  rI;
3853 	double  rF;
3854 	double  cF;
3855 	double  cAmp;
3856 	double  vRef;
3857 	double  gain;               /* Scale value to get output close to +/- 32767 */
3858 };
3859 
3860 
3861 struct discrete_op_amp_info
3862 {
3863 	uint32_t  type;
3864 	double  r1;
3865 	double  r2;
3866 	double  r3;
3867 	double  r4;
3868 	double  c;
3869 	double  vN;     // Op amp B-
3870 	double  vP;     // Op amp B+
3871 };
3872 
3873 
3874 struct discrete_op_amp_1sht_info
3875 {
3876 	uint32_t  type;
3877 	double  r1;
3878 	double  r2;
3879 	double  r3;
3880 	double  r4;
3881 	double  r5;
3882 	double  c1;
3883 	double  c2;
3884 	double  vN;     // Op amp B-
3885 	double  vP;     // Op amp B+
3886 };
3887 
3888 
3889 struct discrete_op_amp_tvca_info
3890 {
3891 	double  r1;
3892 	double  r2;     // r2a + r2b
3893 	double  r3;     // r3a + r3b
3894 	double  r4;
3895 	double  r5;
3896 	double  r6;
3897 	double  r7;
3898 	double  r8;
3899 	double  r9;
3900 	double  r10;
3901 	double  r11;
3902 	double  c1;
3903 	double  c2;
3904 	double  c3;
3905 	double  c4;
3906 	double  v1;
3907 	double  v2;
3908 	double  v3;
3909 	double  vP;
3910 	int     f0;
3911 	int     f1;
3912 	int     f2;
3913 	int     f3;
3914 	int     f4;
3915 	int     f5;
3916 };
3917 
3918 
3919 struct discrete_op_amp_filt_info
3920 {
3921 	double  r1;
3922 	double  r2;
3923 	double  r3;
3924 	double  r4;
3925 	double  rF;
3926 	double  c1;
3927 	double  c2;
3928 	double  c3;
3929 	double  vRef;
3930 	double  vP;
3931 	double  vN;
3932 };
3933 
3934 
3935 #define DEFAULT_555_CHARGE      -1
3936 #define DEFAULT_555_HIGH        -1
3937 #define DEFAULT_555_VALUES      DEFAULT_555_CHARGE, DEFAULT_555_HIGH
3938 
3939 struct discrete_555_desc
3940 {
3941 	int     options;    /* bit mapped options */
3942 	double  v_pos;      /* B+ voltage of 555 */
3943 	double  v_charge;   /* voltage to charge circuit  (Defaults to v_pos) */
3944 	double  v_out_high; /* High output voltage of 555 (Defaults to v_pos - 1.2V) */
3945 };
3946 
3947 #define DEFAULT_555_CC_SOURCE   DEFAULT_555_CHARGE
3948 
3949 struct discrete_555_cc_desc
3950 {
3951 	int     options;        /* bit mapped options */
3952 	double  v_pos;          /* B+ voltage of 555 */
3953 	double  v_cc_source;    /* Voltage of the Constant Current source */
3954 	double  v_out_high;     /* High output voltage of 555 (Defaults to v_pos - 1.2V) */
3955 	double  v_cc_junction;  /* The voltage drop of the Constant Current source transistor (0 if Op Amp) */
3956 };
3957 
3958 
3959 struct discrete_555_vco1_desc
3960 {
3961 	int    options;             /* bit mapped options */
3962 	double r1, r2, r3, r4, c;
3963 	double v_pos;               /* B+ voltage of 555 */
3964 	double v_charge;            /* (ignored) */
3965 	double v_out_high;          /* High output voltage of 555 (Defaults to v_pos - 1.2V) */
3966 };
3967 
3968 
3969 struct discrete_adsr
3970 {
3971 	double attack_time;  /* All times are in seconds */
3972 	double attack_value;
3973 	double decay_time;
3974 	double decay_value;
3975 	double sustain_time;
3976 	double sustain_value;
3977 	double release_time;
3978 	double release_value;
3979 };
3980 
3981 
3982 /*************************************
3983  *
3984  *  The node numbers themselves
3985  *
3986  *************************************/
3987 
3988 #define NODE0_DEF(_x) NODE_ ## 0 ## _x = (0x40000000 + (_x) * DISCRETE_MAX_OUTPUTS), \
3989 	NODE_ ## 0 ## _x ## _00 = NODE_ ## 0 ## _x, NODE_ ## 0 ## _x ## _01, NODE_ ## 0 ## _x ## _02, NODE_ ## 0 ## _x ## _03, \
3990 	NODE_ ## 0 ## _x ## _04, NODE_ ## 0 ## _x ## _05, NODE_ ## 0 ## _x ## _06, NODE_ ## 0 ## _x ## _07
3991 #define NODE_DEF(_x) NODE_ ## _x = (0x40000000 + (_x) * DISCRETE_MAX_OUTPUTS), \
3992 	NODE_ ## _x ## _00 = NODE_ ## _x, NODE_ ## _x ## _01, NODE_ ## _x ## _02, NODE_ ## _x ## _03, \
3993 	NODE_ ## _x ## _04, NODE_ ## _x ## _05, NODE_ ## _x ## _06, NODE_ ## _x ## _07
3994 
3995 enum {
3996 	NODE0_DEF(0), NODE0_DEF(1), NODE0_DEF(2), NODE0_DEF(3), NODE0_DEF(4), NODE0_DEF(5), NODE0_DEF(6), NODE0_DEF(7), NODE0_DEF(8), NODE0_DEF(9),
3997 	NODE_DEF(10), NODE_DEF(11), NODE_DEF(12), NODE_DEF(13), NODE_DEF(14), NODE_DEF(15), NODE_DEF(16), NODE_DEF(17), NODE_DEF(18), NODE_DEF(19),
3998 	NODE_DEF(20), NODE_DEF(21), NODE_DEF(22), NODE_DEF(23), NODE_DEF(24), NODE_DEF(25), NODE_DEF(26), NODE_DEF(27), NODE_DEF(28), NODE_DEF(29),
3999 	NODE_DEF(30), NODE_DEF(31), NODE_DEF(32), NODE_DEF(33), NODE_DEF(34), NODE_DEF(35), NODE_DEF(36), NODE_DEF(37), NODE_DEF(38), NODE_DEF(39),
4000 	NODE_DEF(40), NODE_DEF(41), NODE_DEF(42), NODE_DEF(43), NODE_DEF(44), NODE_DEF(45), NODE_DEF(46), NODE_DEF(47), NODE_DEF(48), NODE_DEF(49),
4001 	NODE_DEF(50), NODE_DEF(51), NODE_DEF(52), NODE_DEF(53), NODE_DEF(54), NODE_DEF(55), NODE_DEF(56), NODE_DEF(57), NODE_DEF(58), NODE_DEF(59),
4002 	NODE_DEF(60), NODE_DEF(61), NODE_DEF(62), NODE_DEF(63), NODE_DEF(64), NODE_DEF(65), NODE_DEF(66), NODE_DEF(67), NODE_DEF(68), NODE_DEF(69),
4003 	NODE_DEF(70), NODE_DEF(71), NODE_DEF(72), NODE_DEF(73), NODE_DEF(74), NODE_DEF(75), NODE_DEF(76), NODE_DEF(77), NODE_DEF(78), NODE_DEF(79),
4004 	NODE_DEF(80), NODE_DEF(81), NODE_DEF(82), NODE_DEF(83), NODE_DEF(84), NODE_DEF(85), NODE_DEF(86), NODE_DEF(87), NODE_DEF(88), NODE_DEF(89),
4005 	NODE_DEF(90), NODE_DEF(91), NODE_DEF(92), NODE_DEF(93), NODE_DEF(94), NODE_DEF(95), NODE_DEF(96), NODE_DEF(97), NODE_DEF(98), NODE_DEF(99),
4006 	NODE_DEF(100),NODE_DEF(101),NODE_DEF(102),NODE_DEF(103),NODE_DEF(104),NODE_DEF(105),NODE_DEF(106),NODE_DEF(107),NODE_DEF(108),NODE_DEF(109),
4007 	NODE_DEF(110),NODE_DEF(111),NODE_DEF(112),NODE_DEF(113),NODE_DEF(114),NODE_DEF(115),NODE_DEF(116),NODE_DEF(117),NODE_DEF(118),NODE_DEF(119),
4008 	NODE_DEF(120),NODE_DEF(121),NODE_DEF(122),NODE_DEF(123),NODE_DEF(124),NODE_DEF(125),NODE_DEF(126),NODE_DEF(127),NODE_DEF(128),NODE_DEF(129),
4009 	NODE_DEF(130),NODE_DEF(131),NODE_DEF(132),NODE_DEF(133),NODE_DEF(134),NODE_DEF(135),NODE_DEF(136),NODE_DEF(137),NODE_DEF(138),NODE_DEF(139),
4010 	NODE_DEF(140),NODE_DEF(141),NODE_DEF(142),NODE_DEF(143),NODE_DEF(144),NODE_DEF(145),NODE_DEF(146),NODE_DEF(147),NODE_DEF(148),NODE_DEF(149),
4011 	NODE_DEF(150),NODE_DEF(151),NODE_DEF(152),NODE_DEF(153),NODE_DEF(154),NODE_DEF(155),NODE_DEF(156),NODE_DEF(157),NODE_DEF(158),NODE_DEF(159),
4012 	NODE_DEF(160),NODE_DEF(161),NODE_DEF(162),NODE_DEF(163),NODE_DEF(164),NODE_DEF(165),NODE_DEF(166),NODE_DEF(167),NODE_DEF(168),NODE_DEF(169),
4013 	NODE_DEF(170),NODE_DEF(171),NODE_DEF(172),NODE_DEF(173),NODE_DEF(174),NODE_DEF(175),NODE_DEF(176),NODE_DEF(177),NODE_DEF(178),NODE_DEF(179),
4014 	NODE_DEF(180),NODE_DEF(181),NODE_DEF(182),NODE_DEF(183),NODE_DEF(184),NODE_DEF(185),NODE_DEF(186),NODE_DEF(187),NODE_DEF(188),NODE_DEF(189),
4015 	NODE_DEF(190),NODE_DEF(191),NODE_DEF(192),NODE_DEF(193),NODE_DEF(194),NODE_DEF(195),NODE_DEF(196),NODE_DEF(197),NODE_DEF(198),NODE_DEF(199),
4016 	NODE_DEF(200),NODE_DEF(201),NODE_DEF(202),NODE_DEF(203),NODE_DEF(204),NODE_DEF(205),NODE_DEF(206),NODE_DEF(207),NODE_DEF(208),NODE_DEF(209),
4017 	NODE_DEF(210),NODE_DEF(211),NODE_DEF(212),NODE_DEF(213),NODE_DEF(214),NODE_DEF(215),NODE_DEF(216),NODE_DEF(217),NODE_DEF(218),NODE_DEF(219),
4018 	NODE_DEF(220),NODE_DEF(221),NODE_DEF(222),NODE_DEF(223),NODE_DEF(224),NODE_DEF(225),NODE_DEF(226),NODE_DEF(227),NODE_DEF(228),NODE_DEF(229),
4019 	NODE_DEF(230),NODE_DEF(231),NODE_DEF(232),NODE_DEF(233),NODE_DEF(234),NODE_DEF(235),NODE_DEF(236),NODE_DEF(237),NODE_DEF(238),NODE_DEF(239),
4020 	NODE_DEF(240),NODE_DEF(241),NODE_DEF(242),NODE_DEF(243),NODE_DEF(244),NODE_DEF(245),NODE_DEF(246),NODE_DEF(247),NODE_DEF(248),NODE_DEF(249),
4021 	NODE_DEF(250),NODE_DEF(251),NODE_DEF(252),NODE_DEF(253),NODE_DEF(254),NODE_DEF(255),NODE_DEF(256),NODE_DEF(257),NODE_DEF(258),NODE_DEF(259),
4022 	NODE_DEF(260),NODE_DEF(261),NODE_DEF(262),NODE_DEF(263),NODE_DEF(264),NODE_DEF(265),NODE_DEF(266),NODE_DEF(267),NODE_DEF(268),NODE_DEF(269),
4023 	NODE_DEF(270),NODE_DEF(271),NODE_DEF(272),NODE_DEF(273),NODE_DEF(274),NODE_DEF(275),NODE_DEF(276),NODE_DEF(277),NODE_DEF(278),NODE_DEF(279),
4024 	NODE_DEF(280),NODE_DEF(281),NODE_DEF(282),NODE_DEF(283),NODE_DEF(284),NODE_DEF(285),NODE_DEF(286),NODE_DEF(287),NODE_DEF(288),NODE_DEF(289),
4025 	NODE_DEF(290),NODE_DEF(291),NODE_DEF(292),NODE_DEF(293),NODE_DEF(294),NODE_DEF(295),NODE_DEF(296),NODE_DEF(297),NODE_DEF(298),NODE_DEF(299)
4026 };
4027 
4028 /* Some Pre-defined nodes for convenience */
4029 
4030 #define NODE(_x)    (NODE_00 + (_x) * DISCRETE_MAX_OUTPUTS)
4031 #define NODE_SUB(_x, _y) ((_x) + (_y))
4032 
4033 #if DISCRETE_MAX_OUTPUTS == 8
4034 #define NODE_CHILD_NODE_NUM(_x)     ((int)(_x) & 7)
4035 #define NODE_DEFAULT_NODE(_x)       ((int)(_x) & ~7)
4036 #define NODE_INDEX(_x)              (((int)(_x) - NODE_START)>>3)
4037 #else
4038 #error "DISCRETE_MAX_OUTPUTS != 8"
4039 #endif
4040 
4041 #define NODE_RELATIVE(_x, _y) (NODE(NODE_INDEX(_x) + (_y)))
4042 
4043 #define NODE_NC  NODE_00
4044 #define NODE_SPECIAL  NODE(DISCRETE_MAX_NODES)
4045 
4046 #define NODE_START  NODE_00
4047 #define NODE_END    NODE_SPECIAL
4048 
4049 #define IS_VALUE_A_NODE(val)    (((val) > NODE_START) && ((val) <= NODE_END))
4050 
4051 // Optional node such as used in CR_FILTER
4052 #define OPT_NODE(val)   (int) val
4053 /*************************************
4054  *
4055  *  Enumerated values for Node types
4056  *  in the simulation
4057  *
4058  *      DSS - Discrete Sound Source
4059  *      DST - Discrete Sound Transform
4060  *      DSD - Discrete Sound Device
4061  *      DSO - Discrete Sound Output
4062  *
4063  *************************************/
4064 
4065 enum discrete_node_type
4066 {
4067 	DSS_NULL,           /* Nothing, nill, zippo, only to be used as terminating node */
4068 	DSS_NOP,            /* just do nothing, placeholder for potential DISCRETE_REPLACE in parent block */
4069 
4070 	/* standard node */
4071 
4072 	DSS_NODE,           /* a standard node */
4073 
4074 	/* Custom */
4075 	DST_CUSTOM,         /* whatever you want */
4076 
4077 	/* Debugging */
4078 	DSO_CSVLOG,         /* Dump nodes as csv file */
4079 	DSO_WAVLOG,     /* Dump nodes as wav file */
4080 
4081 	/* Parallel execution */
4082 	DSO_TASK_START, /* start of parallel task */
4083 	DSO_TASK_END,   /* end of parallel task */
4084 
4085 	/* Output Node -- this must be the last entry in this enum! */
4086 	DSO_OUTPUT,         /* The final output node */
4087 
4088 	/* Import another blocklist */
4089 	DSO_IMPORT,         /* import from another discrete block */
4090 	DSO_REPLACE,        /* replace next node */
4091 	DSO_DELETE,         /* delete nodes */
4092 
4093 	/* Marks end of this enum -- must be last entry ! */
4094 	DSO_LAST
4095 };
4096 
4097 /*************************************
4098  *
4099  *  Forward declarations
4100  *
4101  *************************************/
4102 
4103 struct discrete_block;
4104 class discrete_task;
4105 class discrete_base_node;
4106 class discrete_dss_input_stream_node;
4107 class discrete_device;
4108 
4109 
4110 /*************************************
4111  *
4112  *  Discrete module definition
4113  *
4114  *************************************/
4115 
4116 
4117 /*************************************
4118  *
4119  *  The discrete sound blocks as
4120  *  defined in the drivers
4121  *
4122  *************************************/
4123 
4124 struct discrete_block
4125 {
4126 	int             node;                           /* Output node number */
4127 	std::unique_ptr<discrete_base_node> (*factory)(discrete_device &pdev, const discrete_block &block);
4128 	int             type;                           /* see defines below */
4129 	int             active_inputs;                  /* Number of active inputs on this node type */
4130 	int             input_node[DISCRETE_MAX_INPUTS];/* input/control nodes */
4131 	double          initial[DISCRETE_MAX_INPUTS];   /* Initial values */
4132 	const void *    custom;                         /* Custom function specific initialisation data */
4133 	const char *    name;                           /* Node Name */
4134 	const char *    mod_name;                       /* Module / class name */
4135 };
4136 
4137 /*************************************
4138  *
4139  *  Node interfaces
4140  *
4141  *************************************/
4142 
4143 class discrete_step_interface
4144 {
4145 public:
~discrete_step_interface()4146 	virtual ~discrete_step_interface() { }
4147 
4148 	virtual void step() = 0;
4149 	osd_ticks_t         run_time;
4150 	discrete_base_node *    self;
4151 };
4152 
4153 class discrete_input_interface
4154 {
4155 public:
~discrete_input_interface()4156 	virtual ~discrete_input_interface() { }
4157 
4158 	virtual void input_write(int sub_node, uint8_t data ) = 0;
4159 };
4160 
4161 class discrete_sound_output_interface
4162 {
4163 public:
~discrete_sound_output_interface()4164 	virtual ~discrete_sound_output_interface() { }
4165 
4166 	virtual void set_output_ptr(write_stream_view &view) = 0;
4167 };
4168 
4169 //**************************************************************************
4170 //  TYPE DEFINITIONS
4171 //**************************************************************************
4172 
4173 class discrete_sound_output_interface;
4174 
4175 
4176 // ======================> discrete_device
4177 
4178 class discrete_device : public device_t
4179 {
4180 	//friend class discrete_base_node;
4181 
4182 protected:
4183 	// construction/destruction
4184 	discrete_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);
4185 
4186 public:
4187 	typedef std::vector<std::unique_ptr<discrete_task> > task_list_t;
4188 	typedef std::vector<std::unique_ptr<discrete_base_node> > node_list_t;
4189 	typedef std::vector<discrete_step_interface *> node_step_list_t;
4190 
4191 	// inline configuration helpers
set_intf(const discrete_block * intf)4192 	void set_intf(const discrete_block *intf) { m_intf = intf; }
4193 
4194 	uint8_t read(offs_t offset);
4195 	void write(offs_t offset, uint8_t data);
4196 	virtual ~discrete_device();
4197 
4198 	template<int DiscreteInput>
DECLARE_WRITE_LINE_MEMBER(write_line)4199 	DECLARE_WRITE_LINE_MEMBER(write_line)
4200 	{
4201 		write(DiscreteInput, state ? 1 : 0);
4202 	}
4203 
4204 	/* --------------------------------- */
4205 
update_to_current_time()4206 	virtual void update_to_current_time() const {  }
4207 
4208 	/* process a number of samples */
4209 	void process(int samples);
4210 
4211 	/* access to the discrete_logging facility */
4212 	void CLIB_DECL discrete_log(const char *text, ...) const ATTR_PRINTF(2,3);
4213 
4214 	/* get pointer to a info struct node ref */
4215 	const double *node_output_ptr(int onode);
4216 
4217 	/* FIXME: this is used by csv and wav logs - going forward, identifiers should be explicitly passed */
4218 	int same_module_index(const discrete_base_node &node);
4219 
4220 	/* get node */
4221 	discrete_base_node *discrete_find_node(int node);
4222 
4223 	/* are we profiling */
profiling()4224 	inline int profiling() { return m_profiling; }
4225 
sample_rate()4226 	inline int sample_rate() { return m_sample_rate; }
sample_time()4227 	inline double sample_time() { return m_sample_time; }
4228 
4229 
4230 protected:
4231 	// device-level overrides
4232 	virtual void device_start() override;
4233 	virtual void device_reset() override;
4234 	virtual void device_stop() override;
4235 
4236 	// configuration state
4237 	const discrete_block *m_intf;
4238 
4239 	// internal state
4240 
4241 	/* --------------------------------- */
4242 
4243 	/* emulation info */
4244 	int                 m_sample_rate;
4245 	double              m_sample_time;
4246 	double              m_neg_sample_time;
4247 
4248 	/* list of all nodes */
4249 	node_list_t             m_node_list;        /* node_description * */
4250 
4251 private:
4252 	typedef std::vector<const discrete_block *> sound_block_list_t;
4253 
4254 	void discrete_build_list(const discrete_block *intf, sound_block_list_t &block_list);
4255 	void discrete_sanity_check(const sound_block_list_t &block_list);
4256 	void display_profiling();
4257 	void init_nodes(const sound_block_list_t &block_list);
4258 
4259 	/* internal node tracking */
4260 	std::unique_ptr<discrete_base_node * []>   m_indexed_node;
4261 
4262 	/* tasks */
4263 	task_list_t             task_list;      /* discrete_task_context * */
4264 
4265 	/* debugging statistics */
4266 	FILE *                  m_disclogfile;
4267 
4268 	/* parallel tasks */
4269 	osd_work_queue *        m_queue;
4270 
4271 	/* profiling */
4272 	int                     m_profiling;
4273 	uint64_t                  m_total_samples;
4274 	uint64_t                  m_total_stream_updates;
4275 };
4276 
4277 // ======================> discrete_sound_device
4278 
4279 class discrete_sound_device :   public discrete_device,
4280 								public device_sound_interface
4281 {
4282 public:
4283 	// construction/destruction
discrete_sound_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock,const discrete_block * intf)4284 	discrete_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock, const discrete_block *intf)
4285 		: discrete_sound_device(mconfig, tag, owner, clock)
4286 	{
4287 		set_intf(intf);
4288 	}
discrete_sound_device(const machine_config & mconfig,const char * tag,device_t * owner,const discrete_block * intf)4289 	discrete_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, const discrete_block *intf)
4290 		: discrete_sound_device(mconfig, tag, owner, uint32_t(0))
4291 	{
4292 		set_intf(intf);
4293 	}
4294 	discrete_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock = 0);
~discrete_sound_device()4295 	virtual ~discrete_sound_device() { };
4296 
4297 	/* --------------------------------- */
4298 
update_to_current_time()4299 	virtual void update_to_current_time() const override { m_stream->update(); }
4300 
get_stream()4301 	sound_stream *get_stream() { return m_stream; }
4302 protected:
4303 
4304 	// device-level overrides
4305 	virtual void device_start() override;
4306 	virtual void device_reset() override;
4307 
4308 	// device_sound_interface overrides
4309 	virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override;
4310 
4311 private:
4312 	typedef std::vector<discrete_dss_input_stream_node *> istream_node_list_t;
4313 	typedef std::vector<discrete_sound_output_interface *> node_output_list_t;
4314 
4315 	/* the output stream */
4316 	sound_stream        *m_stream;
4317 
4318 	/* the input streams */
4319 	istream_node_list_t     m_input_stream_list;
4320 	/* output node tracking */
4321 	node_output_list_t      m_output_list;
4322 };
4323 
4324 // device type definition
DECLARE_DEVICE_TYPE(DISCRETE,discrete_sound_device)4325 DECLARE_DEVICE_TYPE(DISCRETE, discrete_sound_device)
4326 
4327 /*************************************
4328  *
4329  *  Node class
4330  *
4331  *************************************/
4332 
4333 class discrete_base_node
4334 {
4335 	friend class discrete_device;
4336 	template <class C> friend class discrete_node_factory;
4337 	friend class discrete_task;
4338 
4339 public:
4340 	virtual ~discrete_base_node();
4341 
4342 	virtual void reset() { }
4343 	virtual void start() { }
4344 	virtual void stop() { }
4345 	virtual void save_state();
4346 
4347 	virtual int max_output() { return 1; };
4348 
4349 	inline bool interface(discrete_step_interface *&intf) const { intf = m_step_intf; return (intf != nullptr); }
4350 	inline bool interface(discrete_input_interface *&intf) const { intf = m_input_intf; return (intf != nullptr); }
4351 	inline bool interface(discrete_sound_output_interface *&intf) const { intf = m_output_intf; return (intf != nullptr); }
4352 
4353 	/* get the input value from node #n */
4354 	inline double input(int n) { return *(m_input[n]); }
4355 
4356 	/* set an output */
4357 	inline void set_output(int n, double val) { m_output[n] = val; }
4358 
4359 	/* Return the node index, i.e. X from NODE(X) */
4360 	inline int index() { return NODE_INDEX(m_block->node); }
4361 
4362 	/* Return the node number, i.e. NODE(X) */
4363 	inline int block_node() const { return m_block->node;  }
4364 
4365 	/* Custom function specific initialisation data */
4366 	inline const void *custom_data() { return m_custom; }
4367 
4368 	inline int input_node(int inputnum) { return m_block->input_node[inputnum]; }
4369 
4370 	/* Number of active inputs on this node type */
4371 	inline int          active_inputs() { return m_active_inputs; }
4372 	/* Bit Flags.  1 in bit location means input_is_node */
4373 	inline int          input_is_node() { return m_input_is_node; }
4374 
4375 	inline double       sample_time() { return m_device->sample_time(); }
4376 	inline int          sample_rate() { return m_device->sample_rate(); }
4377 
4378 	const char *        module_name() { return m_block->mod_name; }
4379 	inline int          module_type() const { return m_block->type; }
4380 
4381 protected:
4382 
4383 	discrete_base_node();
4384 
4385 	/* finish node setup after allocation is complete */
4386 	void init(discrete_device * pdev, const discrete_block *block);
4387 
4388 	void resolve_input_nodes();
4389 
4390 	double                          m_output[DISCRETE_MAX_OUTPUTS];     /* The node's last output value */
4391 	const double *                  m_input[DISCRETE_MAX_INPUTS];       /* Addresses of Input values */
4392 	discrete_device *               m_device;                           /* Points to the parent */
4393 
4394 private:
4395 
4396 	const discrete_block *  m_block;                            /* Points to the node's setup block. */
4397 	int                             m_active_inputs;                    /* Number of active inputs on this node type */
4398 
4399 	const void *                    m_custom;                           /* Custom function specific initialisation data */
4400 	int                             m_input_is_node;
4401 
4402 	discrete_step_interface *       m_step_intf;
4403 	discrete_input_interface *      m_input_intf;
4404 	discrete_sound_output_interface *       m_output_intf;
4405 };
4406 
4407 template <class C>
4408 class discrete_node_factory
4409 {
4410 public:
create(discrete_device & pdev,const discrete_block & block)4411 	static std::unique_ptr<discrete_base_node> create(discrete_device &pdev, const discrete_block &block)
4412 	{
4413 		std::unique_ptr<discrete_base_node> r = make_unique_clear<C>();
4414 
4415 		r->init(&pdev, &block);
4416 		return r;
4417 	}
4418 };
4419 
4420 /*************************************
4421  *
4422  *  Class definitions for nodes
4423  *
4424  *************************************/
4425 
4426 #include "disc_cls.h"
4427 
4428 /*************************************
4429  *
4430  *  Encapsulation macros for defining
4431  *  your simulation
4432  *
4433  *************************************/
4434 
4435 #define DISCRETE_SOUND_EXTERN(name) extern const discrete_block name[]
4436 #define DISCRETE_SOUND_START(name) const discrete_block name[] = {
4437 //#define DSC_SND_ENTRY(_nod, _class, _dss, _num, _iact, _iinit, _custom, _name) { _nod,  new discrete_node_factory< DISCRETE_CLASS_NAME(_class) >, _dss, _num, _iact, _iinit, _custom, _name, # _class }
4438 #define DSC_SND_ENTRY(_nod, _class, _dss, _num, _iact, _iinit, _custom, _name) { _nod,  &discrete_node_factory< DISCRETE_CLASS_NAME(_class) >::create, _dss, _num, _iact, _iinit, _custom, _name, # _class }
4439 
4440 
4441 #define DISCRETE_SOUND_END                                              DSC_SND_ENTRY( NODE_00, special, DSS_NULL     , 0, DSE( NODE_NC ), DSE( 0 ) ,nullptr  ,"DISCRETE_SOUND_END" )  };
4442 #define DSE( ... ) { __VA_ARGS__ }
4443 
4444 /*      Module Name                                                       out,  enum value,      #in,   {variable inputs},              {static inputs},    data pointer,   "name" */
4445 
4446 /* from disc_inp.inc */
4447 #define DISCRETE_ADJUSTMENT(NODE,MIN,MAX,LOGLIN,TAG)                    DSC_SND_ENTRY( NODE, dss_adjustment  , DSS_NODE        , 6, DSE( NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( MIN,MAX,LOGLIN,0   ,0   ,100  ), TAG   , "DISCRETE_ADJUSTMENT" ),
4448 #define DISCRETE_ADJUSTMENTX(NODE,MIN,MAX,LOGLIN,TAG,PMIN,PMAX)         DSC_SND_ENTRY( NODE, dss_adjustment  , DSS_NODE        , 6, DSE( NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( MIN,MAX,LOGLIN,0   ,PMIN,PMAX ), TAG   , "DISCRETE_ADJUSTMENTX"  ),
4449 #define DISCRETE_CONSTANT(NODE,CONST)                                   DSC_SND_ENTRY( NODE, dss_constant    , DSS_NODE        , 1, DSE( NODE_NC ), DSE( CONST ) ,nullptr  ,"DISCRETE_CONSTANT" ),
4450 #define DISCRETE_INPUT_DATA(NODE)                                       DSC_SND_ENTRY( NODE, dss_input_data  , DSS_NODE        , 3, DSE( NODE_NC,NODE_NC,NODE_NC ), DSE( 1,0,0 ), nullptr, "DISCRETE_INPUT_DATA" ),
4451 #define DISCRETE_INPUTX_DATA(NODE,GAIN,OFFSET,INIT)                     DSC_SND_ENTRY( NODE, dss_input_data  , DSS_NODE        , 3, DSE( NODE_NC,NODE_NC,NODE_NC ), DSE( GAIN,OFFSET,INIT ), nullptr, "DISCRETE_INPUTX_DATA" ),
4452 #define DISCRETE_INPUT_LOGIC(NODE)                                      DSC_SND_ENTRY( NODE, dss_input_logic , DSS_NODE        , 3, DSE( NODE_NC,NODE_NC,NODE_NC ), DSE( 1,0,0 ), nullptr, "DISCRETE_INPUT_LOGIC" ),
4453 #define DISCRETE_INPUTX_LOGIC(NODE,GAIN,OFFSET,INIT)                    DSC_SND_ENTRY( NODE, dss_input_logic , DSS_NODE        , 3, DSE( NODE_NC,NODE_NC,NODE_NC ), DSE( GAIN,OFFSET,INIT ), nullptr, "DISCRETE_INPUTX_LOGIC" ),
4454 #define DISCRETE_INPUT_NOT(NODE)                                        DSC_SND_ENTRY( NODE, dss_input_not   , DSS_NODE        , 3, DSE( NODE_NC,NODE_NC,NODE_NC ), DSE( 1,0,0 ), nullptr, "DISCRETE_INPUT_NOT" ),
4455 #define DISCRETE_INPUTX_NOT(NODE,GAIN,OFFSET,INIT)                      DSC_SND_ENTRY( NODE, dss_input_not   , DSS_NODE        , 3, DSE( NODE_NC,NODE_NC,NODE_NC ), DSE( GAIN,OFFSET,INIT ), nullptr, "DISCRETE_INPUTX_NOT" ),
4456 #define DISCRETE_INPUT_PULSE(NODE,INIT)                                 DSC_SND_ENTRY( NODE, dss_input_pulse , DSS_NODE        , 3, DSE( NODE_NC,NODE_NC,NODE_NC ), DSE( 1,0,INIT ), nullptr, "DISCRETE_INPUT_PULSE" ),
4457 
4458 #define DISCRETE_INPUT_STREAM(NODE, NUM)                                DSC_SND_ENTRY( NODE, dss_input_stream, DSS_NODE        , 3, DSE( static_cast<int>(NUM),NODE_NC,NODE_NC ), DSE( NUM,1,0 ), nullptr, "DISCRETE_INPUT_STREAM" ),
4459 #define DISCRETE_INPUTX_STREAM(NODE, NUM, GAIN,OFFSET)                  DSC_SND_ENTRY( NODE, dss_input_stream, DSS_NODE        , 3, DSE( static_cast<int>(NUM),NODE_NC,NODE_NC ), DSE( NUM,GAIN,OFFSET ), nullptr, "DISCRETE_INPUTX_STREAM" ),
4460 
4461 #define DISCRETE_INPUT_BUFFER(NODE, NUM)                                DSC_SND_ENTRY( NODE, dss_input_buffer, DSS_NODE        , 3, DSE( static_cast<int>(NUM),NODE_NC,NODE_NC ), DSE( NUM,1,0 ), nullptr, "DISCRETE_INPUT_BUFFER" ),
4462 
4463 /* from disc_wav.inc */
4464 /* generic modules */
4465 #define DISCRETE_COUNTER(NODE,ENAB,RESET,CLK,MIN,MAX,DIR,INIT0,CLKTYPE) DSC_SND_ENTRY( NODE, dss_counter     , DSS_NODE        , 8, DSE( static_cast<int>(ENAB),static_cast<int>(RESET),static_cast<int>(CLK),NODE_NC,NODE_NC,static_cast<int>(DIR),static_cast<int>(INIT0),NODE_NC ), DSE( ENAB,RESET,CLK,MIN,MAX,DIR,INIT0,CLKTYPE ), nullptr, "DISCRETE_COUNTER" ),
4466 #define DISCRETE_COUNTER_7492(NODE,ENAB,RESET,CLK,CLKTYPE)              DSC_SND_ENTRY( NODE, dss_counter     , DSS_NODE        , 8, DSE( static_cast<int>(ENAB),static_cast<int>(RESET),static_cast<int>(CLK),NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( ENAB,RESET,CLK,CLKTYPE,0,1,0,DISC_COUNTER_IS_7492 ), nullptr, "DISCRETE_COUNTER_7492" ),
4467 #define DISCRETE_LFSR_NOISE(NODE,ENAB,RESET,CLK,AMPL,FEED,BIAS,LFSRTB)  DSC_SND_ENTRY( NODE, dss_lfsr_noise  , DSS_NODE        , 6, DSE( static_cast<int>(ENAB),static_cast<int>(RESET),static_cast<int>(CLK),static_cast<int>(AMPL),static_cast<int>(FEED),static_cast<int>(BIAS) ), DSE( ENAB,RESET,CLK,AMPL,FEED,BIAS ), LFSRTB, "DISCRETE_LFSR_NOISE" ),
4468 #define DISCRETE_NOISE(NODE,ENAB,FREQ,AMPL,BIAS)                        DSC_SND_ENTRY( NODE, dss_noise       , DSS_NODE        , 4, DSE( static_cast<int>(ENAB),static_cast<int>(FREQ),static_cast<int>(AMPL),static_cast<int>(BIAS) ), DSE( ENAB,FREQ,AMPL,BIAS ), nullptr, "DISCRETE_NOISE" ),
4469 #define DISCRETE_NOTE(NODE,ENAB,CLK,DATA,MAX1,MAX2,CLKTYPE)             DSC_SND_ENTRY( NODE, dss_note        , DSS_NODE        , 6, DSE( static_cast<int>(ENAB),static_cast<int>(CLK),static_cast<int>(DATA),NODE_NC,NODE_NC,NODE_NC ), DSE( ENAB,CLK,DATA,MAX1,MAX2,CLKTYPE ), nullptr, "DISCRETE_NOTE" ),
4470 #define DISCRETE_SAWTOOTHWAVE(NODE,ENAB,FREQ,AMPL,BIAS,GRAD,PHASE)      DSC_SND_ENTRY( NODE, dss_sawtoothwave, DSS_NODE        , 6, DSE( static_cast<int>(ENAB),static_cast<int>(FREQ),static_cast<int>(AMPL),static_cast<int>(BIAS),NODE_NC,NODE_NC ), DSE( ENAB,FREQ,AMPL,BIAS,GRAD,PHASE ), nullptr, "DISCRETE_SAWTOOTHWAVE" ),
4471 #define DISCRETE_SINEWAVE(NODE,ENAB,FREQ,AMPL,BIAS,PHASE)               DSC_SND_ENTRY( NODE, dss_sinewave    , DSS_NODE        , 5, DSE( static_cast<int>(ENAB),static_cast<int>(FREQ),static_cast<int>(AMPL),static_cast<int>(BIAS),NODE_NC ), DSE( ENAB,FREQ,AMPL,BIAS,PHASE ), nullptr, "DISCRETE_SINEWAVE" ),
4472 #define DISCRETE_SQUAREWAVE(NODE,ENAB,FREQ,AMPL,DUTY,BIAS,PHASE)        DSC_SND_ENTRY( NODE, dss_squarewave  , DSS_NODE        , 6, DSE( static_cast<int>(ENAB),static_cast<int>(FREQ),static_cast<int>(AMPL),static_cast<int>(DUTY),static_cast<int>(BIAS),NODE_NC ), DSE( ENAB,FREQ,AMPL,DUTY,BIAS,PHASE ), nullptr, "DISCRETE_SQUAREWAVE" ),
4473 #define DISCRETE_SQUAREWFIX(NODE,ENAB,FREQ,AMPL,DUTY,BIAS,PHASE)        DSC_SND_ENTRY( NODE, dss_squarewfix  , DSS_NODE        , 6, DSE( static_cast<int>(ENAB),static_cast<int>(FREQ),static_cast<int>(AMPL),static_cast<int>(DUTY),static_cast<int>(BIAS),NODE_NC ), DSE( ENAB,FREQ,AMPL,DUTY,BIAS,PHASE ), nullptr, "DISCRETE_SQUAREWFIX" ),
4474 #define DISCRETE_SQUAREWAVE2(NODE,ENAB,AMPL,T_OFF,T_ON,BIAS,TSHIFT)     DSC_SND_ENTRY( NODE, dss_squarewave2 , DSS_NODE        , 6, DSE( static_cast<int>(ENAB),static_cast<int>(AMPL),static_cast<int>(T_OFF),static_cast<int>(T_ON),static_cast<int>(BIAS),NODE_NC ), DSE( ENAB,AMPL,T_OFF,T_ON,BIAS,TSHIFT ), nullptr, "DISCRETE_SQUAREWAVE2" ),
4475 #define DISCRETE_TRIANGLEWAVE(NODE,ENAB,FREQ,AMPL,BIAS,PHASE)           DSC_SND_ENTRY( NODE, dss_trianglewave, DSS_NODE        , 5, DSE( static_cast<int>(ENAB),static_cast<int>(FREQ),static_cast<int>(AMPL),static_cast<int>(BIAS),NODE_NC ), DSE( ENAB,FREQ,AMPL,BIAS,PHASE ), nullptr, "DISCRETE_TRIANGLEWAVE" ),
4476 /* Component specific */
4477 #define DISCRETE_INVERTER_OSC(NODE,ENAB,MOD,RCHARGE,RP,C,R2,INFO)       DSC_SND_ENTRY( NODE, dss_inverter_osc, DSS_NODE        , 6, DSE( static_cast<int>(ENAB),static_cast<int>(MOD),NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( ENAB,MOD,RCHARGE,RP,C,R2 ), INFO, "DISCRETE_INVERTER_OSC" ),
4478 #define DISCRETE_OP_AMP_OSCILLATOR(NODE,ENAB,INFO)                      DSC_SND_ENTRY( NODE, dss_op_amp_osc  , DSS_NODE        , 1, DSE( static_cast<int>(ENAB) ), DSE( ENAB ), INFO, "DISCRETE_OP_AMP_OSCILLATOR" ),
4479 #define DISCRETE_OP_AMP_VCO1(NODE,ENAB,VMOD1,INFO)                      DSC_SND_ENTRY( NODE, dss_op_amp_osc  , DSS_NODE        , 2, DSE( static_cast<int>(ENAB),static_cast<int>(VMOD1) ), DSE( ENAB,VMOD1 ), INFO, "DISCRETE_OP_AMP_VCO1" ),
4480 #define DISCRETE_OP_AMP_VCO2(NODE,ENAB,VMOD1,VMOD2,INFO)                DSC_SND_ENTRY( NODE, dss_op_amp_osc  , DSS_NODE        , 3, DSE( static_cast<int>(ENAB),static_cast<int>(VMOD1),static_cast<int>(VMOD2) ), DSE( ENAB,VMOD1,VMOD2 ), INFO, "DISCRETE_OP_AMP_VCO2" ),
4481 #define DISCRETE_SCHMITT_OSCILLATOR(NODE,ENAB,INP0,AMPL,TABLE)          DSC_SND_ENTRY( NODE, dss_schmitt_osc , DSS_NODE        , 3, DSE( static_cast<int>(ENAB),static_cast<int>(INP0),static_cast<int>(AMPL) ), DSE( ENAB,INP0,AMPL ), TABLE, "DISCRETE_SCHMITT_OSCILLATOR" ),
4482 /* Not yet implemented */
4483 #define DISCRETE_ADSR_ENV(NODE,ENAB,TRIGGER,GAIN,ADSRTB)                DSC_SND_ENTRY( NODE, dss_adsr        , DSS_NODE        , 3, DSE( static_cast<int>(ENAB),static_cast<int>(TRIGGER),static_cast<int>(GAIN) ), DSE( ENAB,TRIGGER,GAIN ), ADSRTB, "DISCRETE_ADSR_ENV" ),
4484 
4485 /* from disc_mth.inc */
4486 /* generic modules */
4487 #define DISCRETE_ADDER2(NODE,ENAB,INP0,INP1)                            DSC_SND_ENTRY( NODE, dst_adder       , DSS_NODE        , 3, DSE( static_cast<int>(ENAB),static_cast<int>(INP0),static_cast<int>(INP1) ), DSE( ENAB,INP0,INP1 ), nullptr, "DISCRETE_ADDER2" ),
4488 #define DISCRETE_ADDER3(NODE,ENAB,INP0,INP1,INP2)                       DSC_SND_ENTRY( NODE, dst_adder       , DSS_NODE        , 4, DSE( static_cast<int>(ENAB),static_cast<int>(INP0),static_cast<int>(INP1),static_cast<int>(INP2) ), DSE( ENAB,INP0,INP1,INP2 ), nullptr, "DISCRETE_ADDER3" ),
4489 #define DISCRETE_ADDER4(NODE,ENAB,INP0,INP1,INP2,INP3)                  DSC_SND_ENTRY( NODE, dst_adder       , DSS_NODE        , 5, DSE( static_cast<int>(ENAB),static_cast<int>(INP0),static_cast<int>(INP1),static_cast<int>(INP2),static_cast<int>(INP3) ), DSE( ENAB,INP0,INP1,INP2,INP3 ), nullptr, "DISCRETE_ADDER4" ),
4490 #define DISCRETE_CLAMP(NODE,INP0,MIN,MAX)                               DSC_SND_ENTRY( NODE, dst_clamp       , DSS_NODE        , 3, DSE( static_cast<int>(INP0),static_cast<int>(MIN),static_cast<int>(MAX) ), DSE( INP0,MIN,MAX ), nullptr, "DISCRETE_CLAMP" ),
4491 #define DISCRETE_DIVIDE(NODE,ENAB,INP0,INP1)                            DSC_SND_ENTRY( NODE, dst_divide      , DSS_NODE        , 3, DSE( static_cast<int>(ENAB),static_cast<int>(INP0),static_cast<int>(INP1) ), DSE( ENAB,INP0,INP1 ), nullptr, "DISCRETE_DIVIDE" ),
4492 #define DISCRETE_GAIN(NODE,INP0,GAIN)                                   DSC_SND_ENTRY( NODE, dst_gain        , DSS_NODE        , 3, DSE( static_cast<int>(INP0),NODE_NC,NODE_NC ), DSE( INP0,GAIN,0 ), nullptr, "DISCRETE_GAIN" ),
4493 #define DISCRETE_INVERT(NODE,INP0)                                      DSC_SND_ENTRY( NODE, dst_gain        , DSS_NODE        , 3, DSE( static_cast<int>(INP0),NODE_NC,NODE_NC ), DSE( INP0,-1,0 ), nullptr, "DISCRETE_INVERT" ),
4494 #define DISCRETE_LOGIC_INVERT(NODE,INP0)                                DSC_SND_ENTRY( NODE, dst_logic_inv   , DSS_NODE        , 1, DSE( static_cast<int>(INP0) ), DSE( INP0 ), nullptr, "DISCRETE_LOGIC_INVERT" ),
4495 
4496 #define DISCRETE_BIT_DECODE(NODE, INP, BIT_N, VOUT)                     DSC_SND_ENTRY( NODE, dst_bits_decode , DSS_NODE        , 4, DSE( static_cast<int>(INP),NODE_NC,NODE_NC,NODE_NC ), DSE( INP,BIT_N,BIT_N,VOUT ), nullptr, "DISCRETE_BIT_DECODE" ),
4497 #define DISCRETE_BITS_DECODE(NODE, INP, BIT_FROM, BIT_TO, VOUT)         DSC_SND_ENTRY( NODE, dst_bits_decode , DSS_NODE        , 4, DSE( static_cast<int>(INP),NODE_NC,NODE_NC,NODE_NC ), DSE( INP,BIT_FROM,BIT_TO,VOUT ), nullptr, "DISCRETE_BITS_DECODE" ),
4498 
4499 #define DISCRETE_LOGIC_AND(NODE,INP0,INP1)                              DSC_SND_ENTRY( NODE, dst_logic_and   , DSS_NODE        , 4, DSE( static_cast<int>(INP0),static_cast<int>(INP1),NODE_NC,NODE_NC ), DSE( INP0,INP1,1.0,1.0 ), nullptr, "DISCRETE_LOGIC_AND" ),
4500 #define DISCRETE_LOGIC_AND3(NODE,INP0,INP1,INP2)                        DSC_SND_ENTRY( NODE, dst_logic_and   , DSS_NODE        , 4, DSE( static_cast<int>(INP0),static_cast<int>(INP1),static_cast<int>(INP2),NODE_NC ), DSE( INP0,INP1,INP2,1.0 ), nullptr, "DISCRETE_LOGIC_AND3" ),
4501 #define DISCRETE_LOGIC_AND4(NODE,INP0,INP1,INP2,INP3)                   DSC_SND_ENTRY( NODE, dst_logic_and   , DSS_NODE        , 4, DSE( static_cast<int>(INP0),static_cast<int>(INP1),static_cast<int>(INP2),static_cast<int>(INP3) ), DSE( INP0,INP1,INP2,INP3 ) ,nullptr, "DISCRETE_LOGIC_AND4" ),
4502 #define DISCRETE_LOGIC_NAND(NODE,INP0,INP1)                             DSC_SND_ENTRY( NODE, dst_logic_nand  , DSS_NODE        , 4, DSE( static_cast<int>(INP0),static_cast<int>(INP1),NODE_NC,NODE_NC ), DSE( INP0,INP1,1.0,1.0 ), nullptr, "DISCRETE_LOGIC_NAND" ),
4503 #define DISCRETE_LOGIC_NAND3(NODE,INP0,INP1,INP2)                       DSC_SND_ENTRY( NODE, dst_logic_nand  , DSS_NODE        , 4, DSE( static_cast<int>(INP0),static_cast<int>(INP1),static_cast<int>(INP2),NODE_NC ), DSE( INP0,INP1,INP2,1.0 ), nullptr, "DISCRETE_LOGIC_NAND3" ),
4504 #define DISCRETE_LOGIC_NAND4(NODE,INP0,INP1,INP2,INP3)                  DSC_SND_ENTRY( NODE, dst_logic_nand  , DSS_NODE        , 4, DSE( static_cast<int>(INP0),static_cast<int>(INP1),static_cast<int>(INP2),static_cast<int>(INP3) ), DSE( INP0,INP1,INP2,INP3 ), nullptr, ")DISCRETE_LOGIC_NAND4" ),
4505 #define DISCRETE_LOGIC_OR(NODE,INP0,INP1)                               DSC_SND_ENTRY( NODE, dst_logic_or    , DSS_NODE        , 4, DSE( static_cast<int>(INP0),static_cast<int>(INP1),NODE_NC,NODE_NC ), DSE( INP0,INP1,0.0,0.0 ), nullptr, "DISCRETE_LOGIC_OR" ),
4506 #define DISCRETE_LOGIC_OR3(NODE,INP0,INP1,INP2)                         DSC_SND_ENTRY( NODE, dst_logic_or    , DSS_NODE        , 4, DSE( static_cast<int>(INP0),static_cast<int>(INP1),static_cast<int>(INP2),NODE_NC ), DSE( INP0,INP1,INP2,0.0 ), nullptr, "DISCRETE_LOGIC_OR3" ),
4507 #define DISCRETE_LOGIC_OR4(NODE,INP0,INP1,INP2,INP3)                    DSC_SND_ENTRY( NODE, dst_logic_or    , DSS_NODE        , 4, DSE( static_cast<int>(INP0),static_cast<int>(INP1),static_cast<int>(INP2),static_cast<int>(INP3) ), DSE( INP0,INP1,INP2,INP3 ), nullptr, "DISCRETE_LOGIC_OR4" ),
4508 #define DISCRETE_LOGIC_NOR(NODE,INP0,INP1)                              DSC_SND_ENTRY( NODE, dst_logic_nor   , DSS_NODE        , 4, DSE( static_cast<int>(INP0),static_cast<int>(INP1),NODE_NC,NODE_NC ), DSE( INP0,INP1,0.0,0.0 ), nullptr, "DISCRETE_LOGIC_NOR" ),
4509 #define DISCRETE_LOGIC_NOR3(NODE,INP0,INP1,INP2)                        DSC_SND_ENTRY( NODE, dst_logic_nor   , DSS_NODE        , 4, DSE( static_cast<int>(INP0),static_cast<int>(INP1),static_cast<int>(INP2),NODE_NC ), DSE( INP0,INP1,INP2,0.0 ), nullptr, "DISCRETE_LOGIC_NOR3" ),
4510 #define DISCRETE_LOGIC_NOR4(NODE,INP0,INP1,INP2,INP3)                   DSC_SND_ENTRY( NODE, dst_logic_nor   , DSS_NODE        , 4, DSE( static_cast<int>(INP0),static_cast<int>(INP1),static_cast<int>(INP2),static_cast<int>(INP3) ), DSE( INP0,INP1,INP2,INP3 ), nullptr, "DISCRETE_LOGIC_NOR4" ),
4511 #define DISCRETE_LOGIC_XOR(NODE,INP0,INP1)                              DSC_SND_ENTRY( NODE, dst_logic_xor   , DSS_NODE        , 2, DSE( static_cast<int>(INP0),static_cast<int>(INP1) ), DSE( INP0,INP1 ), nullptr, "DISCRETE_LOGIC_XOR" ),
4512 #define DISCRETE_LOGIC_XNOR(NODE,INP0,INP1)                             DSC_SND_ENTRY( NODE, dst_logic_nxor  , DSS_NODE        , 2, DSE( static_cast<int>(INP0),static_cast<int>(INP1) ), DSE( INP0,INP1 ), nullptr, "DISCRETE_LOGIC_XNOR" ),
4513 #define DISCRETE_LOGIC_DFLIPFLOP(NODE,RESET,SET,CLK,INP)                DSC_SND_ENTRY( NODE, dst_logic_dff   , DSS_NODE        , 4, DSE( static_cast<int>(RESET),static_cast<int>(SET),static_cast<int>(CLK),static_cast<int>(INP) ), DSE( RESET,SET,CLK,INP ), nullptr, "DISCRETE_LOGIC_DFLIPFLOP" ),
4514 #define DISCRETE_LOGIC_JKFLIPFLOP(NODE,RESET,SET,CLK,J,K)               DSC_SND_ENTRY( NODE, dst_logic_jkff  , DSS_NODE        , 5, DSE( static_cast<int>(RESET),static_cast<int>(SET),static_cast<int>(CLK),static_cast<int>(J),static_cast<int>(K) ), DSE( RESET,SET,CLK,J,K ), nullptr, "DISCRETE_LOGIC_JKFLIPFLOP" ),
4515 #define DISCRETE_LOGIC_SHIFT(NODE,INP0,RESET,CLK,SIZE,OPTIONS)          DSC_SND_ENTRY( NODE, dst_logic_shift , DSS_NODE        , 5, DSE( static_cast<int>(INP0),static_cast<int>(RESET),static_cast<int>(CLK),NODE_NC,NODE_NC ), DSE( INP0,RESET,CLK,SIZE,OPTIONS ), nullptr, "DISCRETE_LOGIC_SHIFT" ),
4516 #define DISCRETE_LOOKUP_TABLE(NODE,ADDR,SIZE,TABLE)                     DSC_SND_ENTRY( NODE, dst_lookup_table, DSS_NODE        , 2, DSE( static_cast<int>(ADDR),NODE_NC ), DSE( ADDR,SIZE ), TABLE, "DISCRETE_LOOKUP_TABLE" ),
4517 #define DISCRETE_MULTIPLEX2(NODE,ADDR,INP0,INP1)                        DSC_SND_ENTRY( NODE, dst_multiplex   , DSS_NODE        , 3, DSE( static_cast<int>(ADDR),static_cast<int>(INP0),static_cast<int>(INP1) ), DSE( ADDR,INP0,INP1 ), nullptr, "DISCRETE_MULTIPLEX2" ),
4518 #define DISCRETE_MULTIPLEX4(NODE,ADDR,INP0,INP1,INP2,INP3)              DSC_SND_ENTRY( NODE, dst_multiplex   , DSS_NODE        , 5, DSE( static_cast<int>(ADDR),static_cast<int>(INP0),static_cast<int>(INP1),static_cast<int>(INP2),static_cast<int>(INP3) ), DSE( ADDR,INP0,INP1,INP2,INP3 ), nullptr, "DISCRETE_MULTIPLEX4" ),
4519 #define DISCRETE_MULTIPLEX8(NODE,ADDR,INP0,INP1,INP2,INP3,INP4,INP5,INP6,INP7) DSC_SND_ENTRY( NODE, dst_multiplex, DSS_NODE    , 9, DSE( static_cast<int>(ADDR),static_cast<int>(INP0),static_cast<int>(INP1),static_cast<int>(INP2),static_cast<int>(INP3),static_cast<int>(INP4),static_cast<int>(INP5),static_cast<int>(INP6),static_cast<int>(INP7) ), DSE( ADDR,INP0,INP1,INP2,INP3,INP4,INP5,INP6,INP7 ), nullptr, "DISCRETE_MULTIPLEX8" ),
4520 #define DISCRETE_MULTIPLY(NODE,INP0,INP1)                               DSC_SND_ENTRY( NODE, dst_gain        , DSS_NODE        , 3, DSE( static_cast<int>(INP0),static_cast<int>(INP1),NODE_NC ), DSE( INP0,INP1,0 ), nullptr, "DISCRETE_MULTIPLY" ),
4521 #define DISCRETE_MULTADD(NODE,INP0,INP1,INP2)                           DSC_SND_ENTRY( NODE, dst_gain        , DSS_NODE        , 3, DSE( static_cast<int>(INP0),static_cast<int>(INP1),static_cast<int>(INP2) ), DSE( INP0,INP1,INP2 ), nullptr, "DISCRETE_MULTADD" ),
4522 #define DISCRETE_ONESHOT(NODE,TRIG,AMPL,WIDTH,TYPE)                     DSC_SND_ENTRY( NODE, dst_oneshot     , DSS_NODE        , 5, DSE( 0,static_cast<int>(TRIG),static_cast<int>(AMPL),static_cast<int>(WIDTH),NODE_NC ), DSE( 0,TRIG,AMPL,WIDTH,TYPE ), nullptr, "DISCRETE_ONESHOT" ),
4523 #define DISCRETE_ONESHOTR(NODE,RESET,TRIG,AMPL,WIDTH,TYPE)              DSC_SND_ENTRY( NODE, dst_oneshot     , DSS_NODE        , 5, DSE( static_cast<int>(RESET),static_cast<int>(TRIG),static_cast<int>(AMPL),static_cast<int>(WIDTH),NODE_NC ), DSE( RESET,TRIG,AMPL,WIDTH,TYPE ), nullptr, "One Shot Resetable" ),
4524 #define DISCRETE_ONOFF(NODE,ENAB,INP0)                                  DSC_SND_ENTRY( NODE, dst_gain        , DSS_NODE        , 3, DSE( static_cast<int>(ENAB),static_cast<int>(INP0),NODE_NC ), DSE( 0,1,0 ), nullptr, "DISCRETE_ONOFF" ),
4525 #define DISCRETE_RAMP(NODE,ENAB,RAMP,GRAD,START,END,CLAMP)              DSC_SND_ENTRY( NODE, dst_ramp        , DSS_NODE        , 6, DSE( static_cast<int>(ENAB),static_cast<int>(RAMP),static_cast<int>(GRAD),static_cast<int>(START),static_cast<int>(END),static_cast<int>(CLAMP) ), DSE( ENAB,RAMP,GRAD,START,END,CLAMP ), nullptr, "DISCRETE_RAMP" ),
4526 #define DISCRETE_SAMPLHOLD(NODE,INP0,CLOCK,CLKTYPE)                     DSC_SND_ENTRY( NODE, dst_samphold    , DSS_NODE        , 3, DSE( static_cast<int>(INP0),static_cast<int>(CLOCK),NODE_NC ), DSE( INP0,CLOCK,CLKTYPE ), nullptr, "DISCRETE_SAMPLHOLD" ),
4527 #define DISCRETE_SWITCH(NODE,ENAB,SWITCH,INP0,INP1)                     DSC_SND_ENTRY( NODE, dst_switch      , DSS_NODE        , 4, DSE( static_cast<int>(ENAB),static_cast<int>(SWITCH),static_cast<int>(INP0),static_cast<int>(INP1) ), DSE( ENAB,SWITCH,INP0,INP1 ), nullptr, "DISCRETE_SWITCH" ),
4528 #define DISCRETE_ASWITCH(NODE,CTRL,INP,THRESHOLD)                       DSC_SND_ENTRY( NODE, dst_aswitch     , DSS_NODE        , 3, DSE( static_cast<int>(CTRL),static_cast<int>(INP),static_cast<int>(THRESHOLD) ), DSE( CTRL,INP, THRESHOLD), nullptr, "Analog Switch" ),
4529 #define DISCRETE_TRANSFORM2(NODE,INP0,INP1,FUNCT)                       DSC_SND_ENTRY( NODE, dst_transform   , DSS_NODE        , 2, DSE( static_cast<int>(INP0),static_cast<int>(INP1) ), DSE( INP0,INP1 ), FUNCT, "DISCRETE_TRANSFORM2" ),
4530 #define DISCRETE_TRANSFORM3(NODE,INP0,INP1,INP2,FUNCT)                  DSC_SND_ENTRY( NODE, dst_transform   , DSS_NODE        , 3, DSE( static_cast<int>(INP0),static_cast<int>(INP1),static_cast<int>(INP2) ), DSE( INP0,INP1,INP2 ), FUNCT, "DISCRETE_TRANSFORM3" ),
4531 #define DISCRETE_TRANSFORM4(NODE,INP0,INP1,INP2,INP3,FUNCT)             DSC_SND_ENTRY( NODE, dst_transform   , DSS_NODE        , 4, DSE( static_cast<int>(INP0),static_cast<int>(INP1),static_cast<int>(INP2),static_cast<int>(INP3) ), DSE( INP0,INP1,INP2,INP3 ), FUNCT, "DISCRETE_TRANSFORM4" ),
4532 #define DISCRETE_TRANSFORM5(NODE,INP0,INP1,INP2,INP3,INP4,FUNCT)        DSC_SND_ENTRY( NODE, dst_transform   , DSS_NODE        , 5, DSE( static_cast<int>(INP0),static_cast<int>(INP1),static_cast<int>(INP2),static_cast<int>(INP3),static_cast<int>(INP4) ), DSE( INP0,INP1,INP2,INP3,INP4 ), FUNCT, "DISCRETE_TRANSFORM5" ),
4533 /* Component specific */
4534 #define DISCRETE_COMP_ADDER(NODE,DATA,TABLE)                            DSC_SND_ENTRY( NODE, dst_comp_adder  , DSS_NODE        , 1, DSE( static_cast<int>(DATA) ), DSE( DATA ), TABLE, "DISCRETE_COMP_ADDER" ),
4535 #define DISCRETE_DAC_R1(NODE,DATA,VDATA,LADDER)                         DSC_SND_ENTRY( NODE, dst_dac_r1      , DSS_NODE        , 2, DSE( static_cast<int>(DATA),NODE_NC ), DSE( DATA,VDATA ), LADDER, "DISCRETE_DAC_R1" ),
4536 #define DISCRETE_DIODE_MIXER2(NODE,IN0,IN1,TABLE)                       DSC_SND_ENTRY( NODE, dst_diode_mix   , DSS_NODE        , 2, DSE( static_cast<int>(IN0),static_cast<int>(IN1) ), DSE( IN0,IN1 ), TABLE, "DISCRETE_DIODE_MIXER2" ),
4537 #define DISCRETE_DIODE_MIXER3(NODE,IN0,IN1,IN2,TABLE)                   DSC_SND_ENTRY( NODE, dst_diode_mix   , DSS_NODE        , 3, DSE( static_cast<int>(IN0),static_cast<int>(IN1),static_cast<int>(IN2) ), DSE( IN0,IN1,IN2 ), TABLE, "DISCRETE_DIODE_MIXER3" ),
4538 #define DISCRETE_DIODE_MIXER4(NODE,IN0,IN1,IN2,IN3,TABLE)               DSC_SND_ENTRY( NODE, dst_diode_mix   , DSS_NODE        , 4, DSE( static_cast<int>(IN0),static_cast<int>(IN1),static_cast<int>(IN2),static_cast<int>(IN3) ), DSE( IN0,IN1,IN2,IN3 ), TABLE, "DISCRETE_DIODE_MIXER4" ),
4539 #define DISCRETE_INTEGRATE(NODE,TRG0,TRG1,INFO)                         DSC_SND_ENTRY( NODE, dst_integrate   , DSS_NODE        , 2, DSE( static_cast<int>(TRG0),static_cast<int>(TRG1) ), DSE( TRG0,TRG1 ), INFO, "DISCRETE_INTEGRATE" ),
4540 #define DISCRETE_MIXER2(NODE,ENAB,IN0,IN1,INFO)                         DSC_SND_ENTRY( NODE, dst_mixer       , DSS_NODE        , 3, DSE( static_cast<int>(ENAB),static_cast<int>(IN0),static_cast<int>(IN1) ), DSE( ENAB,IN0,IN1 ), INFO, "DISCRETE_MIXER2" ),
4541 #define DISCRETE_MIXER3(NODE,ENAB,IN0,IN1,IN2,INFO)                     DSC_SND_ENTRY( NODE, dst_mixer       , DSS_NODE        , 4, DSE( static_cast<int>(ENAB),static_cast<int>(IN0),static_cast<int>(IN1),static_cast<int>(IN2) ), DSE( ENAB,IN0,IN1,IN2 ), INFO, "DISCRETE_MIXER3" ),
4542 #define DISCRETE_MIXER4(NODE,ENAB,IN0,IN1,IN2,IN3,INFO)                 DSC_SND_ENTRY( NODE, dst_mixer       , DSS_NODE        , 5, DSE( static_cast<int>(ENAB),static_cast<int>(IN0),static_cast<int>(IN1),static_cast<int>(IN2),static_cast<int>(IN3) ), DSE( ENAB,IN0,IN1,IN2,IN3 ), INFO, "DISCRETE_MIXER4" ),
4543 #define DISCRETE_MIXER5(NODE,ENAB,IN0,IN1,IN2,IN3,IN4,INFO)             DSC_SND_ENTRY( NODE, dst_mixer       , DSS_NODE        , 6, DSE( static_cast<int>(ENAB),static_cast<int>(IN0),static_cast<int>(IN1),static_cast<int>(IN2),static_cast<int>(IN3),static_cast<int>(IN4) ), DSE( ENAB,IN0,IN1,IN2,IN3,IN4 ), INFO, "DISCRETE_MIXER5" ),
4544 #define DISCRETE_MIXER6(NODE,ENAB,IN0,IN1,IN2,IN3,IN4,IN5,INFO)         DSC_SND_ENTRY( NODE, dst_mixer       , DSS_NODE        , 7, DSE( static_cast<int>(ENAB),static_cast<int>(IN0),static_cast<int>(IN1),static_cast<int>(IN2),static_cast<int>(IN3),static_cast<int>(IN4),static_cast<int>(IN5) ), DSE( ENAB,IN0,IN1,IN2,IN3,IN4,IN5 ), INFO, "DISCRETE_MIXER6" ),
4545 #define DISCRETE_MIXER7(NODE,ENAB,IN0,IN1,IN2,IN3,IN4,IN5,IN6,INFO)     DSC_SND_ENTRY( NODE, dst_mixer       , DSS_NODE        , 8, DSE( static_cast<int>(ENAB),static_cast<int>(IN0),static_cast<int>(IN1),static_cast<int>(IN2),static_cast<int>(IN3),static_cast<int>(IN4),static_cast<int>(IN5),static_cast<int>(IN6) ), DSE( ENAB,IN0,IN1,IN2,IN3,IN4,IN5,IN6 ), INFO, "DISCRETE_MIXER7" ),
4546 #define DISCRETE_MIXER8(NODE,ENAB,IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7,INFO) DSC_SND_ENTRY( NODE, dst_mixer       , DSS_NODE        , 9, DSE( static_cast<int>(ENAB),static_cast<int>(IN0),static_cast<int>(IN1),static_cast<int>(IN2),static_cast<int>(IN3),static_cast<int>(IN4),static_cast<int>(IN5),static_cast<int>(IN6),static_cast<int>(IN7) ), DSE( ENAB,IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7 ), INFO, "DISCRETE_MIXER8" ),
4547 #define DISCRETE_OP_AMP(NODE,ENAB,IN0,IN1,INFO)                         DSC_SND_ENTRY( NODE, dst_op_amp      , DSS_NODE        , 3, DSE( static_cast<int>(ENAB),static_cast<int>(IN0),static_cast<int>(IN1) ), DSE( ENAB,IN0,IN1 ), INFO, "DISCRETE_OP_AMP" ),
4548 #define DISCRETE_OP_AMP_ONESHOT(NODE,TRIG,INFO)                         DSC_SND_ENTRY( NODE, dst_op_amp_1sht , DSS_NODE        , 1, DSE( static_cast<int>(TRIG) ), DSE( TRIG ), INFO, "DISCRETE_OP_AMP_ONESHOT" ),
4549 #define DISCRETE_OP_AMP_TRIG_VCA(NODE,TRG0,TRG1,TRG2,IN0,IN1,INFO)      DSC_SND_ENTRY( NODE, dst_tvca_op_amp , DSS_NODE        , 5, DSE( static_cast<int>(TRG0),static_cast<int>(TRG1),static_cast<int>(TRG2),static_cast<int>(IN0),static_cast<int>(IN1) ), DSE( TRG0,TRG1,TRG2,IN0,IN1 ), INFO, "DISCRETE_OP_AMP_TRIG_VCA" ),
4550 #define DISCRETE_VCA(NODE,ENAB,IN0,CTRL,TYPE)                           DSC_SND_ENTRY( NODE, dst_vca         , DSS_NODE        , 4, DSE( static_cast<int>(ENAB),static_cast<int>(IN0),static_cast<int>(CTRL),NODE_NC ), DSE( ENAB,IN0,CTRL,TYPE ), nullptr, "DISCRETE_VCA" ),
4551 #define DISCRETE_XTIME_BUFFER(NODE,IN0,LOW,HIGH)                        DSC_SND_ENTRY( NODE, dst_xtime_buffer, DSS_NODE        , 4, DSE( static_cast<int>(IN0),static_cast<int>(LOW),static_cast<int>(HIGH),NODE_NC ), DSE( IN0,LOW,HIGH,0 ), nullptr, "DISCRETE_XTIME_BUFFER" ),
4552 #define DISCRETE_XTIME_INVERTER(NODE,IN0,LOW,HIGH)                      DSC_SND_ENTRY( NODE, dst_xtime_buffer, DSS_NODE        , 4, DSE( static_cast<int>(IN0),static_cast<int>(LOW),static_cast<int>(HIGH),NODE_NC ), DSE( IN0,LOW,HIGH,1 ), nullptr, "DISCRETE_XTIME_INVERTER" ),
4553 #define DISCRETE_XTIME_AND(NODE,IN0,IN1,LOW,HIGH)                       DSC_SND_ENTRY( NODE, dst_xtime_and   , DSS_NODE        , 5, DSE( static_cast<int>(IN0),static_cast<int>(IN1),static_cast<int>(LOW),static_cast<int>(HIGH),NODE_NC ), DSE( IN0,IN1,LOW,HIGH,0 ), nullptr, "DISCRETE_XTIME_AND" ),
4554 #define DISCRETE_XTIME_NAND(NODE,IN0,IN1,LOW,HIGH)                      DSC_SND_ENTRY( NODE, dst_xtime_and   , DSS_NODE        , 5, DSE( static_cast<int>(IN0),static_cast<int>(IN1),static_cast<int>(LOW),static_cast<int>(HIGH),NODE_NC ), DSE( IN0,IN1,LOW,HIGH,1 ), nullptr, "DISCRETE_XTIME_NAND" ),
4555 #define DISCRETE_XTIME_OR(NODE,IN0,IN1,LOW,HIGH)                        DSC_SND_ENTRY( NODE, dst_xtime_or    , DSS_NODE        , 5, DSE( static_cast<int>(IN0),static_cast<int>(IN1),static_cast<int>(LOW),static_cast<int>(HIGH),NODE_NC ), DSE( IN0,IN1,LOW,HIGH,0 ), nullptr, "DISCRETE_XTIME_OR" ),
4556 #define DISCRETE_XTIME_NOR(NODE,IN0,IN1,LOW,HIGH)                       DSC_SND_ENTRY( NODE, dst_xtime_or    , DSS_NODE        , 5, DSE( static_cast<int>(IN0),static_cast<int>(IN1),static_cast<int>(LOW),static_cast<int>(HIGH),NODE_NC ), DSE( IN0,IN1,LOW,HIGH,1 ), nullptr, "DISCRETE_XTIME_NOR" ),
4557 #define DISCRETE_XTIME_XOR(NODE,IN0,IN1,LOW,HIGH)                       DSC_SND_ENTRY( NODE, dst_xtime_xor   , DSS_NODE        , 5, DSE( static_cast<int>(IN0),static_cast<int>(IN1),static_cast<int>(LOW),static_cast<int>(HIGH),NODE_NC ), DSE( IN0,IN1,LOW,HIGH,0 ), nullptr, "DISCRETE_XTIME_XOR" ),
4558 #define DISCRETE_XTIME_XNOR(NODE,IN0,IN1,LOW,HIGH)                      DSC_SND_ENTRY( NODE, dst_xtime_xnor  , DSS_NODE        , 5, DSE( static_cast<int>(IN0),static_cast<int>(IN1),static_cast<int>(LOW),static_cast<int>(HIGH),NODE_NC ), DSE( IN0,IN1,LOW,HIGH,1 ), nullptr, "DISCRETE_XTIME_XNOR" ),
4559 
4560 /* from disc_flt.inc */
4561 /* generic modules */
4562 #define DISCRETE_FILTER1(NODE,ENAB,INP0,FREQ,TYPE)                      DSC_SND_ENTRY( NODE, dst_filter1     , DSS_NODE        , 4, DSE( static_cast<int>(ENAB),static_cast<int>(INP0),NODE_NC,NODE_NC ), DSE( ENAB,INP0,FREQ,TYPE ), nullptr, "DISCRETE_FILTER1" ),
4563 #define DISCRETE_FILTER2(NODE,ENAB,INP0,FREQ,DAMP,TYPE)                 DSC_SND_ENTRY( NODE, dst_filter2     , DSS_NODE        , 5, DSE( static_cast<int>(ENAB),static_cast<int>(INP0),NODE_NC,NODE_NC,NODE_NC ), DSE( ENAB,INP0,FREQ,DAMP,TYPE ), nullptr, "DISCRETE_FILTER2" ),
4564 /* Component specific */
4565 #define DISCRETE_SALLEN_KEY_FILTER(NODE,ENAB,INP0,TYPE,INFO)            DSC_SND_ENTRY( NODE, dst_sallen_key  , DSS_NODE        , 3, DSE( static_cast<int>(ENAB),static_cast<int>(INP0),NODE_NC ), DSE( ENAB,INP0,TYPE ), INFO, "DISCRETE_SALLEN_KEY_FILTER" ),
4566 #define DISCRETE_CRFILTER(NODE,INP0,RVAL,CVAL)                          DSC_SND_ENTRY( NODE, dst_crfilter    , DSS_NODE        , 3, DSE( static_cast<int>(INP0),static_cast<int>(OPT_NODE(RVAL)),static_cast<int>(OPT_NODE(CVAL)) ), DSE( INP0,RVAL,CVAL ), nullptr, "DISCRETE_CRFILTER" ),
4567 #define DISCRETE_CRFILTER_VREF(NODE,INP0,RVAL,CVAL,VREF)                DSC_SND_ENTRY( NODE, dst_crfilter    , DSS_NODE        , 4, DSE( static_cast<int>(INP0),static_cast<int>(OPT_NODE(RVAL)),static_cast<int>(OPT_NODE(CVAL)),static_cast<int>(VREF) ), DSE( INP0,RVAL,CVAL,VREF ), nullptr, "DISCRETE_CRFILTER_VREF" ),
4568 #define DISCRETE_OP_AMP_FILTER(NODE,ENAB,INP0,INP1,TYPE,INFO)           DSC_SND_ENTRY( NODE, dst_op_amp_filt , DSS_NODE        , 4, DSE( static_cast<int>(ENAB),static_cast<int>(INP0),static_cast<int>(INP1),NODE_NC ), DSE( ENAB,INP0,INP1,TYPE ), INFO, "DISCRETE_OP_AMP_FILTER" ),
4569 #define DISCRETE_RC_CIRCUIT_1(NODE,INP0,INP1,RVAL,CVAL)                 DSC_SND_ENTRY( NODE, dst_rc_circuit_1, DSS_NODE        , 4, DSE( static_cast<int>(INP0),static_cast<int>(INP1),NODE_NC,NODE_NC ), DSE( INP0,INP1,RVAL,CVAL ), nullptr, "DISCRETE_RC_CIRCUIT_1" ),
4570 #define DISCRETE_RCDISC(NODE,ENAB,INP0,RVAL,CVAL)                       DSC_SND_ENTRY( NODE, dst_rcdisc      , DSS_NODE        , 4, DSE( static_cast<int>(ENAB),static_cast<int>(INP0),NODE_NC,NODE_NC ), DSE( ENAB,INP0,RVAL,CVAL ), nullptr, "DISCRETE_RCDISC" ),
4571 #define DISCRETE_RCDISC2(NODE,SWITCH,INP0,RVAL0,INP1,RVAL1,CVAL)        DSC_SND_ENTRY( NODE, dst_rcdisc2     , DSS_NODE        , 6, DSE( static_cast<int>(SWITCH),static_cast<int>(INP0),NODE_NC,static_cast<int>(INP1),NODE_NC,NODE_NC ), DSE( SWITCH,INP0,RVAL0,INP1,RVAL1,CVAL ), nullptr, "DISCRETE_RCDISC2" ),
4572 #define DISCRETE_RCDISC3(NODE,ENAB,INP0,RVAL0,RVAL1,CVAL,DJV)           DSC_SND_ENTRY( NODE, dst_rcdisc3     , DSS_NODE        , 6, DSE( static_cast<int>(ENAB),static_cast<int>(INP0),NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( ENAB,INP0,RVAL0,RVAL1,CVAL,DJV ), nullptr, "DISCRETE_RCDISC3" ),
4573 #define DISCRETE_RCDISC4(NODE,ENAB,INP0,RVAL0,RVAL1,RVAL2,CVAL,VP,TYPE) DSC_SND_ENTRY( NODE, dst_rcdisc4     , DSS_NODE        , 8, DSE( static_cast<int>(ENAB),static_cast<int>(INP0),NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( ENAB,INP0,RVAL0,RVAL1,RVAL2,CVAL,VP,TYPE ), nullptr, "DISCRETE_RCDISC4" ),
4574 #define DISCRETE_RCDISC5(NODE,ENAB,INP0,RVAL,CVAL)                      DSC_SND_ENTRY( NODE, dst_rcdisc5     , DSS_NODE        , 4, DSE( static_cast<int>(ENAB),static_cast<int>(INP0),NODE_NC,NODE_NC ), DSE( ENAB,INP0,RVAL,CVAL ), nullptr, "DISCRETE_RCDISC5" ),
4575 #define DISCRETE_RCDISC_MODULATED(NODE,INP0,INP1,RVAL0,RVAL1,RVAL2,RVAL3,CVAL,VP)   DSC_SND_ENTRY( NODE, dst_rcdisc_mod, DSS_NODE        , 8, DSE( static_cast<int>(INP0),static_cast<int>(INP1),NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( INP0,INP1,RVAL0,RVAL1,RVAL2,RVAL3,CVAL,VP ), nullptr, "DISCRETE_RCDISC_MODULATED" ),
4576 #define DISCRETE_RCFILTER(NODE,INP0,RVAL,CVAL)                          DSC_SND_ENTRY( NODE, dst_rcfilter    , DSS_NODE        , 3, DSE( static_cast<int>(INP0),static_cast<int>(OPT_NODE(RVAL)),static_cast<int>(OPT_NODE(CVAL)) ), DSE( INP0,RVAL,CVAL ), nullptr, "DISCRETE_RCFILTER" ),
4577 #define DISCRETE_RCFILTER_VREF(NODE,INP0,RVAL,CVAL,VREF)                DSC_SND_ENTRY( NODE, dst_rcfilter    , DSS_NODE        , 4, DSE( static_cast<int>(INP0),static_cast<int>(OPT_NODE(RVAL)),static_cast<int>(OPT_NODE(CVAL)),static_cast<int>(VREF) ), DSE( INP0,RVAL,CVAL,VREF ), nullptr, "DISCRETE_RCFILTER_VREF" ),
4578 #define DISCRETE_RCFILTER_SW(NODE,ENAB,INP0,SW,RVAL,CVAL1,CVAL2,CVAL3,CVAL4) DSC_SND_ENTRY( NODE, dst_rcfilter_sw, DSS_NODE    , 8, DSE( static_cast<int>(ENAB),static_cast<int>(INP0),static_cast<int>(SW),NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( ENAB,INP0,SW,RVAL,CVAL1,CVAL2,CVAL3,CVAL4 ), nullptr, "DISCRETE_RCFILTER_SW" ),
4579 #define DISCRETE_RCINTEGRATE(NODE,INP0,RVAL0,RVAL1,RVAL2,CVAL,vP,TYPE)  DSC_SND_ENTRY( NODE, dst_rcintegrate , DSS_NODE        , 7, DSE( static_cast<int>(INP0),NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( INP0,RVAL0,RVAL1,RVAL2,CVAL,vP,TYPE ), nullptr, "DISCRETE_RCINTEGRATE" ),
4580 /* For testing - seem to be buggered.  Use versions not ending in N. */
4581 #define DISCRETE_RCDISCN(NODE,ENAB,INP0,RVAL,CVAL)                      DSC_SND_ENTRY( NODE, dst_rcdiscn     , DSS_NODE        , 4, DSE( static_cast<int>(ENAB),static_cast<int>(INP0),NODE_NC,NODE_NC ), DSE( ENAB,INP0,RVAL,CVAL ), nullptr, "DISCRETE_RCDISCN" ),
4582 #define DISCRETE_RCDISC2N(NODE,SWITCH,INP0,RVAL0,INP1,RVAL1,CVAL)       DSC_SND_ENTRY( NODE, dst_rcdisc2n    , DSS_NODE        , 6, DSE( static_cast<int>(SWITCH),static_cast<int>(INP0),NODE_NC,static_cast<int>(INP1),NODE_NC,NODE_NC ), DSE( SWITCH,INP0,RVAL0,INP1,RVAL1,CVAL ), nullptr, "DISCRETE_RCDISC2N" ),
4583 #define DISCRETE_RCFILTERN(NODE,ENAB,INP0,RVAL,CVAL)                    DSC_SND_ENTRY( NODE, dst_rcfiltern   , DSS_NODE        , 4, DSE( static_cast<int>(ENAB),static_cast<int>(INP0),NODE_NC,NODE_NC ), DSE( ENAB,INP0,RVAL,CVAL ), nullptr, "DISCRETE_RCFILTERN" ),
4584 
4585 /* from disc_dev.inc */
4586 /* generic modules */
4587 #define DISCRETE_CUSTOM1(NODE,CLASS,IN0,INFO)                                 DSC_SND_ENTRY( NODE, CLASS, DST_CUSTOM      , 1, DSE( static_cast<int>(IN0) ), DSE( IN0 ), INFO, "DISCRETE_CUSTOM1" ),
4588 #define DISCRETE_CUSTOM2(NODE,CLASS,IN0,IN1,INFO)                             DSC_SND_ENTRY( NODE, CLASS, DST_CUSTOM      , 2, DSE( static_cast<int>(IN0),static_cast<int>(IN1) ), DSE( IN0,IN1 ), INFO, "DISCRETE_CUSTOM2" ),
4589 #define DISCRETE_CUSTOM3(NODE,CLASS,IN0,IN1,IN2,INFO)                         DSC_SND_ENTRY( NODE, CLASS, DST_CUSTOM      , 3, DSE( static_cast<int>(IN0),static_cast<int>(IN1),static_cast<int>(IN2) ), DSE( IN0,IN1,IN2 ), INFO, "DISCRETE_CUSTOM3" ),
4590 #define DISCRETE_CUSTOM4(NODE,CLASS,IN0,IN1,IN2,IN3,INFO)                     DSC_SND_ENTRY( NODE, CLASS, DST_CUSTOM      , 4, DSE( static_cast<int>(IN0),static_cast<int>(IN1),static_cast<int>(IN2),static_cast<int>(IN3) ), DSE( IN0,IN1,IN2,IN3 ), INFO, "DISCRETE_CUSTOM4" ),
4591 #define DISCRETE_CUSTOM5(NODE,CLASS,IN0,IN1,IN2,IN3,IN4,INFO)                 DSC_SND_ENTRY( NODE, CLASS, DST_CUSTOM      , 5, DSE( static_cast<int>(IN0),static_cast<int>(IN1),static_cast<int>(IN2),static_cast<int>(IN3),static_cast<int>(IN4) ), DSE( IN0,IN1,IN2,IN3,IN4 ), INFO, "DISCRETE_CUSTOM5" ),
4592 #define DISCRETE_CUSTOM6(NODE,CLASS,IN0,IN1,IN2,IN3,IN4,IN5,INFO)             DSC_SND_ENTRY( NODE, CLASS, DST_CUSTOM      , 6, DSE( static_cast<int>(IN0),static_cast<int>(IN1),static_cast<int>(IN2),static_cast<int>(IN3),static_cast<int>(IN4),static_cast<int>(IN5) ), DSE( IN0,IN1,IN2,IN3,IN4,IN5 ), INFO, "DISCRETE_CUSTOM6" ),
4593 #define DISCRETE_CUSTOM7(NODE,CLASS,IN0,IN1,IN2,IN3,IN4,IN5,IN6,INFO)         DSC_SND_ENTRY( NODE, CLASS, DST_CUSTOM      , 7, DSE( static_cast<int>(IN0),static_cast<int>(IN1),static_cast<int>(IN2),static_cast<int>(IN3),static_cast<int>(IN4),static_cast<int>(IN5),static_cast<int>(IN6) ), DSE( IN0,IN1,IN2,IN3,IN4,IN5,IN6 ), INFO, "DISCRETE_CUSTOM7" ),
4594 #define DISCRETE_CUSTOM8(NODE,CLASS,IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7,INFO)     DSC_SND_ENTRY( NODE, CLASS, DST_CUSTOM      , 8, DSE( static_cast<int>(IN0),static_cast<int>(IN1),static_cast<int>(IN2),static_cast<int>(IN3),static_cast<int>(IN4),static_cast<int>(IN5),static_cast<int>(IN6),static_cast<int>(IN7) ), DSE( IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7 ), INFO, "DISCRETE_CUSTOM8" ),
4595 #define DISCRETE_CUSTOM9(NODE,CLASS,IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7,IN8,INFO) DSC_SND_ENTRY( NODE, CLASS, DST_CUSTOM      , 9, DSE( static_cast<int>(IN0),static_cast<int>(IN1),static_cast<int>(IN2),static_cast<int>(IN3),static_cast<int>(IN4),static_cast<int>(IN5),static_cast<int>(IN6),static_cast<int>(IN7),static_cast<int>(IN8) ), DSE( IN0,IN1,IN2,IN3,IN4,IN5,IN6,IN7,IN8 ), INFO, "DISCRETE_CUSTOM9" ),
4596 
4597 /* Component specific */
4598 #define DISCRETE_555_ASTABLE(NODE,RESET,R1,R2,C,OPTIONS)                DSC_SND_ENTRY( NODE, dsd_555_astbl   , DSS_NODE        , 5, DSE( static_cast<int>(RESET),static_cast<int>(R1),static_cast<int>(R2),static_cast<int>(C),NODE_NC ), DSE( RESET,R1,R2,C,-1 ), OPTIONS, "DISCRETE_555_ASTABLE" ),
4599 #define DISCRETE_555_ASTABLE_CV(NODE,RESET,R1,R2,C,CTRLV,OPTIONS)       DSC_SND_ENTRY( NODE, dsd_555_astbl   , DSS_NODE        , 5, DSE( static_cast<int>(RESET),static_cast<int>(R1),static_cast<int>(R2),static_cast<int>(C),static_cast<int>(CTRLV) ), DSE( RESET,R1,R2,C,CTRLV ), OPTIONS, "DISCRETE_555_ASTABLE_CV" ),
4600 #define DISCRETE_555_MSTABLE(NODE,RESET,TRIG,R,C,OPTIONS)               DSC_SND_ENTRY( NODE, dsd_555_mstbl   , DSS_NODE        , 4, DSE( static_cast<int>(RESET),static_cast<int>(TRIG),static_cast<int>(R),static_cast<int>(C) ), DSE( RESET,TRIG,R,C ), OPTIONS, "DISCRETE_555_MSTABLE" ),
4601 #define DISCRETE_555_CC(NODE,RESET,VIN,R,C,RBIAS,RGND,RDIS,OPTIONS)     DSC_SND_ENTRY( NODE, dsd_555_cc      , DSS_NODE        , 7, DSE( static_cast<int>(RESET),static_cast<int>(VIN),static_cast<int>(R),static_cast<int>(C),static_cast<int>(RBIAS),static_cast<int>(RGND),static_cast<int>(RDIS) ), DSE( RESET,VIN,R,C,RBIAS,RGND,RDIS ), OPTIONS, "DISCRETE_555_CC" ),
4602 #define DISCRETE_555_VCO1(NODE,RESET,VIN,OPTIONS)                       DSC_SND_ENTRY( NODE, dsd_555_vco1    , DSS_NODE        , 3, DSE( static_cast<int>(RESET),static_cast<int>(VIN),NODE_NC ), DSE( RESET,VIN,-1 ), OPTIONS, "DISCRETE_555_VCO1" ),
4603 #define DISCRETE_555_VCO1_CV(NODE,RESET,VIN,CTRLV,OPTIONS)              DSC_SND_ENTRY( NODE, dsd_555_vco1    , DSS_NODE        , 3, DSE( static_cast<int>(RESET),static_cast<int>(VIN),static_cast<int>(CTRLV) ), DSE( RESET,VIN,CTRLV ), OPTIONS, "DISCRETE_555_VCO1_CV" ),
4604 #define DISCRETE_566(NODE,VMOD,R,C,VPOS,VNEG,VCHARGE,OPTIONS)           DSC_SND_ENTRY( NODE, dsd_566         , DSS_NODE        , 7, DSE( static_cast<int>(VMOD),static_cast<int>(R),static_cast<int>(C),NODE_NC,NODE_NC,static_cast<int>(VCHARGE),NODE_NC ), DSE( VMOD,R,C,VPOS,VNEG,VCHARGE,OPTIONS ), nullptr, "DISCRETE_566" ),
4605 #define DISCRETE_74LS624(NODE,ENAB,VMOD,VRNG,C,R_FREQ_IN,C_FREQ_IN,R_RNG_IN,OUTTYPE) DSC_SND_ENTRY( NODE, dsd_ls624   , DSS_NODE        , 8, DSE( static_cast<int>(ENAB),static_cast<int>(VMOD),NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC ), DSE( ENAB,VMOD,VRNG,C,R_FREQ_IN,C_FREQ_IN,R_RNG_IN,OUTTYPE ), nullptr, "DISCRETE_74LS624" ),
4606 
4607 /* NOP */
4608 #define DISCRETE_NOP(NODE)                                              DSC_SND_ENTRY( NODE, dss_nop         , DSS_NOP         , 0, DSE( 0 ), DSE( 0 ), nullptr, "DISCRETE_NOP" ),
4609 
4610 /* logging */
4611 #define DISCRETE_CSVLOG1(NODE1)                                         DSC_SND_ENTRY( NODE_SPECIAL, dso_csvlog  , DSO_CSVLOG  , 1, DSE( static_cast<int>(NODE1) ), DSE( NODE1 ), nullptr, "DISCRETE_CSVLOG1" ),
4612 #define DISCRETE_CSVLOG2(NODE1,NODE2)                                   DSC_SND_ENTRY( NODE_SPECIAL, dso_csvlog  , DSO_CSVLOG  , 2, DSE( static_cast<int>(NODE1),static_cast<int>(NODE2) ), DSE( NODE1,NODE2 ), nullptr, "DISCRETE_CSVLOG2" ),
4613 #define DISCRETE_CSVLOG3(NODE1,NODE2,NODE3)                             DSC_SND_ENTRY( NODE_SPECIAL, dso_csvlog  , DSO_CSVLOG  , 3, DSE( static_cast<int>(NODE1),static_cast<int>(NODE2),static_cast<int>(NODE3) ), DSE( NODE1,NODE2,NODE3 ), nullptr, "DISCRETE_CSVLOG3" ),
4614 #define DISCRETE_CSVLOG4(NODE1,NODE2,NODE3,NODE4)                       DSC_SND_ENTRY( NODE_SPECIAL, dso_csvlog  , DSO_CSVLOG  , 4, DSE( static_cast<int>(NODE1),static_cast<int>(NODE2),static_cast<int>(NODE3),static_cast<int>(NODE4) ), DSE( NODE1,NODE2,NODE3,NODE4 ), nullptr, "DISCRETE_CSVLOG4" ),
4615 #define DISCRETE_CSVLOG5(NODE1,NODE2,NODE3,NODE4,NODE5)                 DSC_SND_ENTRY( NODE_SPECIAL, dso_csvlog  , DSO_CSVLOG  , 5, DSE( static_cast<int>(NODE1),static_cast<int>(NODE2),static_cast<int>(NODE3),static_cast<int>(NODE4),static_cast<int>(NODE5) ), DSE( NODE1,NODE2,NODE3,NODE4,NODE5 ), nullptr, "DISCRETE_CSVLOG5" ),
4616 #define DISCRETE_WAVLOG1(NODE1,GAIN1)                                   DSC_SND_ENTRY( NODE_SPECIAL, dso_wavlog  , DSO_WAVLOG  , 2, DSE( static_cast<int>(NODE1),NODE_NC ), DSE( NODE1,GAIN1 ), nullptr, "DISCRETE_WAVLOG1" ),
4617 #define DISCRETE_WAVLOG2(NODE1,GAIN1,NODE2,GAIN2)                       DSC_SND_ENTRY( NODE_SPECIAL, dso_wavlog  , DSO_WAVLOG  , 4, DSE( static_cast<int>(NODE1),NODE_NC,static_cast<int>(NODE2),NODE_NC ), DSE( NODE1,GAIN1,NODE2,GAIN2 ), nullptr, "DISCRETE_WAVLOG2" ),
4618 
4619 /* import */
4620 #define DISCRETE_IMPORT(INFO)                                           DSC_SND_ENTRY( NODE_SPECIAL, special     , DSO_IMPORT  , 0, DSE( 0 ), DSE( 0 ), &(INFO), "DISCRETE_IMPORT" ),
4621 #define DISCRETE_DELETE(NODE_FROM, NODE_TO)                             DSC_SND_ENTRY( NODE_SPECIAL, special     , DSO_DELETE  , 2, DSE( static_cast<int>(NODE_FROM), static_cast<int>(NODE_TO) ), DSE( NODE_FROM, NODE_TO ), nullptr, "DISCRETE_DELETE" ),
4622 #define DISCRETE_REPLACE                                                DSC_SND_ENTRY( NODE_SPECIAL, special     , DSO_REPLACE , 0, DSE( 0 ), DSE( 0 ), nullptr, "DISCRETE_REPLACE" ),
4623 
4624 /* parallel tasks */
4625 
4626 #define DISCRETE_TASK_START(TASK_GROUP)                                 DSC_SND_ENTRY( NODE_SPECIAL, special     , DSO_TASK_START, 2, DSE( NODE_NC, NODE_NC ), DSE( TASK_GROUP, 0 ), nullptr, "DISCRETE_TASK_START" ),
4627 #define DISCRETE_TASK_END()                                             DSC_SND_ENTRY( NODE_SPECIAL, special     , DSO_TASK_END  , 0, DSE( 0 ), DSE( 0 ), nullptr, "DISCRETE_TASK_END" ),
4628 //#define DISCRETE_TASK_SYNC()                                          DSC_SND_ENTRY( NODE_SPECIAL, special     , DSO_TASK_SYNC , 0, DSE( 0 ), DSE( 0 ), nullptr, "DISCRETE_TASK_SYNC" ),
4629 
4630 /* output */
4631 #define DISCRETE_OUTPUT(OPNODE,GAIN)                                   DSC_SND_ENTRY( NODE_SPECIAL, dso_output   , DSO_OUTPUT   ,2, DSE( static_cast<int>(OPNODE),NODE_NC ), DSE( 0,GAIN ), nullptr, "DISCRETE_OUTPUT" ),
4632 
4633 
4634 
4635 #endif // MAME_SOUND_DISCRETE_H
4636