1 #ifndef _discrete_h_
2 #define _discrete_h_
3 
4 /************************************************************************/
5 /*                                                                      */
6 /*  MAME - Discrete sound system emulation library                      */
7 /*                                                                      */
8 /*  Written by Keith Wilkins (mame@esplexo.co.uk)                       */
9 /*                                                                      */
10 /*  (c) K.Wilkins 2000                                                  */
11 /*                                                                      */
12 /*  Coding started in November 2000                                     */
13 /*                                                                      */
14 /*  Additions/bugfix February 2003 - Sawtooth, Switch, Adjusters        */
15 /*                                   LFSR noise source                  */
16 /*                                                                      */
17 /************************************************************************/
18 /*                                                                      */
19 /* Unused/Unconnected input nodes should be set to NODE_NC (No Connect) */
20 /*                                                                      */
21 /* Each node can have upto 6 inputs from either constants or other      */
22 /* nodes within the system.                                             */
23 /*                                                                      */
24 /* It should be remembered that the discrete sound system emulation     */
25 /* does not do individual device emulation, but instead does a function */
26 /* emulation. So you will need to convert the schematic design into     */
27 /* a logic block representation.                                        */
28 /*                                                                      */
29 /* One node point may feed a number of inputs, for example you could    */
30 /* connect the output of a DISCRETE_SINEWAVE to the AMPLITUDE input     */
31 /* of another DISCRETE_SINEWAVE to amplitude modulate its output and    */
32 /* also connect it to the frequecy input of another to frequency        */
33 /* modulate its output, the combinations are endless....                */
34 /*                                                                      */
35 /* Consider the circuit below:                                          */
36 /*                                                                      */
37 /*   --------               ----------                   -------        */
38 /*  |        |             |          |                 |       |       */
39 /*  | SQUARE |       Enable| SINEWAVE |                 |       |       */
40 /*  | WAVE   |------------>|  2000Hz  |---------------->|       |       */
41 /*  |        | |           |          |                 | ADDER |--}OUT */
42 /*  | NODE01 | |           |  NODE02  |                 |       |       */
43 /*   --------  |            ----------                ->|       |       */
44 /*             |                                     |  |NODE06 |       */
45 /*             |   ------     ------     ---------   |   -------        */
46 /*             |  |      |   |      |   |         |  |       ^          */
47 /*             |  | INV  |Ena| ADD  |Ena| SINEWVE |  |       |          */
48 /*              ->| ERT  |-->| ER2  |-->| 4000Hz  |--    -------        */
49 /*                |      |ble|      |ble|         |     |       |       */
50 /*                |NODE03|   |NODE04|   | NODE05  |     | INPUT |       */
51 /*                 ------     ------     ---------      |       |       */
52 /*                                                      |NODE07 |       */
53 /*                                                       -------        */
54 /*                                                                      */
55 /* This should give you an alternating two tone sound switching         */
56 /* between the 2000Hz and 4000Hz sine waves at the frequency of the     */
57 /* square wave, with the memory mapped enable signal mapped onto NODE07 */
58 /* so discrete_sound_w(NODE_06,1) will enable the sound, and            */
59 /* discrete_sound_w(NODE_06,0) will disable the sound.                  */
60 /*                                                                      */
61 /*  DISCRETE_SOUND_START(test_interface)                                */
62 /*      DISCRETE_SQUAREWAVE(NODE_01,1,0.5,1,50,0)                       */
63 /*      DISCRETE_SINEWAVE(NODE_02,NODE_01,2000,10000,0)                 */
64 /*      DISCRETE_INVERT(NODE_03,NODE_01)                                */
65 /*      DISCRETE_ADDER2(NODE_04,1,NODE_03,1)                            */
66 /*      DISCRETE_SINEWAVE(NODE_05,NODE_04,4000,10000,0)                 */
67 /*      DISCRETE_ADDER2(NODE_06,NODE_07,NODE_02,NODE_05)                */
68 /*      DISCRETE_INPUT(NODE_07,1)                                       */
69 /*      DISCRETE_OUTPUT(NODE_06)                                        */
70 /*  DISCRETE_SOUND_END                                                  */
71 /*                                                                      */
72 /* To aid simulation speed it is preferable to use the enable/disable   */
73 /* inputs to a block rather than setting the output amplitude to zero   */
74 /*                                                                      */
75 /* Feedback loops are allowed BUT they will always feeback one time     */
76 /* step later, the loop over the netlist is only performed once per     */
77 /* deltaT so feedback occurs in the next deltaT step. This is not       */
78 /* the perfect solution but saves repeatedly traversing the netlist     */
79 /* until all nodes have settled.                                        */
80 /*                                                                      */
81 /* It will often be necessary to add gain and level shifting blocks to  */
82 /* correct the signal amplitude and offset to the required level        */
83 /* as all sine waves have 0 offset and swing +ve/-ve so if you want     */
84 /* to use this as a frequency modulation you need to offset it so that  */
85 /* it always stays positive, use the DISCRETE_ADDER & DISCRETE_GAIN     */
86 /* modules to do this. You will also need to do this to scale and off-  */
87 /* set your memory mapped device inputs if they are being used to set   */
88 /* amplitude and frequency values.                                      */
89 /*                                                                      */
90 /* The best way to work out your system is generally to use a pen and   */
91 /* paper to draw a logical block diagram like the one above, it helps   */
92 /* to understand the system ,map the inputs and outputs and to work     */
93 /* out your node numbering scheme.                                      */
94 /*                                                                      */
95 /* Node numbers NODE_01 to NODE_99 are defined at present.              */
96 /*                                                                      */
97 /************************************************************************/
98 /*                                                                      */
99 /* LIST OF CURRENTLY IMPLEMENTED DISCRETE BLOCKS                        */
100 /* ---------------------------------------------                        */
101 /*                                                                      */
102 /* DISCRETE_SOUND_START(STRUCTURENAME)                                  */
103 /* DISCRETE_SOUND_END                                                   */
104 /*                                                                      */
105 /* DISCRETE_CONSTANT(NODE,CONST0)                                       */
106 /* DISCRETE_ADJUSTMENT(NODE,ENAB,MIN,MAX,DEFAULT,NAME)                  */
107 /* DISCRETE_INPUT(NODE,INIT0,ADDR,MASK)                                 */
108 /* DISCRETE_SQUAREWAVE(NODE,ENAB,FREQ,AMP,DUTY,PHASE)                   */
109 /* DISCRETE_SINEWAVE(NODE,ENAB,FREQ,AMP,PHASE)                          */
110 /* DISCRETE_TRIANGLEWAVE(NODE,ENAB,FREQ,AMP,PHASE)                      */
111 /* DISCRETE_SAWTOOTHWAVE(NODE,ENAB,FREQ,AMP,GRADIENT,PHASE)             */
112 /* DISCRETE_NOISE(NODE,ENAB,FREQ,AMP)                                   */
113 /* DISCRETE_LFSR_NOISE(NODE,ENAB,FREQ,AMP,LFSRDESC)                     */
114 /*                                                                      */
115 /* DISCRETE_INVERT(NODE,IN0)                                            */
116 /* DISCRETE_MULTIPLY(NODE,ENAB,IN0,IN1)                                 */
117 /* DISCRETE_DIVIDE(NODE,ENAB,IN0,IN1)                                   */
118 /* DISCRETE_GAIN(NODE,IN0,GAIN)                                         */
119 /* DISCRETE_ONOFF(NODE,IN0,IN1)                                         */
120 /* DISCRETE_ADDER2(NODE,IN0,IN1,IN2)                                    */
121 /* DISCRETE_ADDER3(NODE,IN0,IN1,IN2,IN3)                                */
122 /* DISCRETE_SWITCH(NODE,ENAB,SWITCH,INP0,INP1)                          */
123 /* DISCRETE_ONESHOTR(NODE,ENAB,TRIG,AMP,WIDTH) - Retriggerable          */
124 /* DISCRETE_ONESHOT(NODE,ENAB,TRIG,RESET,AMP,WIDTH) - Non retriggerable */
125 /*                                                                      */
126 /* DISCRETE_RCFILTER(NODE,ENAB,IN0,RVAL,CVAL)                           */
127 /* DISCRETE_RCDISC(NODE,ENAB,IN0,RVAL,CVAL)                             */
128 /* DISCRETE_RCDISC2(NODE,IN0,RVAL0,IN1,RVAL1,CVAL)                      */
129 /* DISCRETE_RAMP(NODE,ENAB,RAMP,GRAD,MIN,MAX,CLAMP)                     */
130 /* DISCRETE_CLAMP(NODE,ENAB,IN0,MIN,MAX,CLAMP)                          */
131 /* DISCRETE_LADDER(NODE,ENAB,IN0,GAIN,LADDER)                           */
132 /* DISCRETE_SAMPLHOLD(NODE,ENAB,INP0,CLOCK,CLKTYPE)                     */
133 /*                                                                      */
134 /* DISCRETE_LOGIC_INVERT(NODE,ENAB,INP0)                                */
135 /* DISCRETE_LOGIC_AND(NODE,ENAB,INP0,INP1)                              */
136 /* DISCRETE_LOGIC_AND3(NODE,ENAB,INP0,INP1,INP2)                        */
137 /* DISCRETE_LOGIC_AND4(NODE,ENAB,INP0,INP1,INP2,INP3)                   */
138 /* DISCRETE_LOGIC_NAND(NODE,ENAB,INP0,INP1)                             */
139 /* DISCRETE_LOGIC_NAND3(NODE,ENAB,INP0,INP1,INP2)                       */
140 /* DISCRETE_LOGIC_NAND4(NODE,ENAB,INP0,INP1,INP2,INP3)                  */
141 /* DISCRETE_LOGIC_OR(NODE,ENAB,INP0,INP1)                               */
142 /* DISCRETE_LOGIC_OR3(NODE,ENAB,INP0,INP1,INP2)                         */
143 /* DISCRETE_LOGIC_OR4(NODE,ENAB,INP0,INP1,INP2,INP3)                    */
144 /* DISCRETE_LOGIC_NOR(NODE,ENAB,INP0,INP1)                              */
145 /* DISCRETE_LOGIC_NOR3(NODE,ENAB,INP0,INP1,INP2)                        */
146 /* DISCRETE_LOGIC_NOR4(NODE,ENAB,INP0,INP1,INP2,INP3)                   */
147 /* DISCRETE_LOGIC_XOR(NODE,ENAB,INP0,INP1)                              */
148 /* DISCRETE_LOGIC_NXOR(NODE,ENAB,INP0,INP1)                             */
149 /*                                                                      */
150 /* DISCRETE_NE555(NODE,RESET,TRIGR,THRSH,CTRLV,VCC)                     */
151 /*                                                                      */
152 /* DISCRETE_OUTPUT(OPNODE)                                              */
153 /* DISCRETE_OUTPUT_STEREO(OPNODEL,OPNODER)                              */
154 /*                                                                      */
155 /************************************************************************/
156 /*                                                                      */
157 /* DISCRETE_CONSTANT - Single output, fixed at compile time             */
158 /*                                                                      */
159 /*                         ----------                                   */
160 /*                        |          |                                  */
161 /*                        | CONSTANT |--------}   Netlist node          */
162 /*                        |          |                                  */
163 /*                         ----------                                   */
164 /*  Declaration syntax                                                  */
165 /*                                                                      */
166 /*     DISCRETE_CONSTANT(name of node, constant value)                  */
167 /*                                                                      */
168 /*  Example config line                                                 */
169 /*                                                                      */
170 /*     DISCRETE_CONSTANT(NODE_01, 100)                                  */
171 /*                                                                      */
172 /*  Define a node that has a constant value of 100                      */
173 /*                                                                      */
174 /************************************************************************/
175 /*                                                                      */
176 /* DISCRETE_ADJUSTMENT - Adjustable constant nodempile time             */
177 /*                                                                      */
178 /*                         ----------                                   */
179 /*                        |          |                                  */
180 /*                        | ADJUST.. |--------}   Netlist node          */
181 /*                        |          |                                  */
182 /*                         ----------                                   */
183 /*  Declaration syntax                                                  */
184 /*                                                                      */
185 /*     DISCRETE_ADJUSTMENT(name of node,                                */
186 /*                         enable node or static value                  */
187 /*                         static minimum value the node can take       */
188 /*                         static maximum value the node can take       */
189 /*                         default static value for the node            */
190 /*                         log/linear scale 0=Linear !0=Logarithmic     */
191 /*                         ascii name of the node for UI)               */
192 /*                                                                      */
193 /*  Example config line                                                 */
194 /*                                                                      */
195 /*     DISCRETE_ADJUSTMENT(NODE_01,1.0,0.0,5.0,2.5,0,"VCO Trimmer")     */
196 /*                                                                      */
197 /*  Define an adjustment slider that has a default value of 2.5 and     */
198 /*  can be adjusted between 0.0 and 5.0 via the user interface.         */
199 /*  Adujstment scaling is Linear.                                       */
200 /*                                                                      */
201 /************************************************************************/
202 /*                                                                      */
203 /* DISCRETE INPUT - Single output node, initialised at compile time and */
204 /*                variable via memory based interface                   */
205 /*                                                                      */
206 /*                             ----------                               */
207 /*                      -----\|          |                              */
208 /*        Memory Mapped ===== | INPUT(A) |----}   Netlist node          */
209 /*            Write     -----/|          |                              */
210 /*                             ----------                               */
211 /*                                                                      */
212 /*  Declaration syntax                                                  */
213 /*                                                                      */
214 /*     DISCRETE_INPUT(name of node, initial value, addr, addrmask)      */
215 /*                                                                      */
216 /*  Example config line                                                 */
217 /*                                                                      */
218 /*     DISCRETE_INPUT(NODE_02, 100,0x0000,0x000f)                       */
219 /*                                                                      */
220 /*  Define a memory mapped input node called NODE_02 that has an        */
221 /*  initial value of 100. It is memory mapped into location 0x0000,     */
222 /*  0x0010, 0x0020 etc all the way to 0x0ff0. The exact size of memory  */
223 /*  space is defined by DSS_INPUT_SPACE in file disc_inp.c              */
224 /*                                                                      */
225 /*  The incoming address is first logicalled AND with the the ADDRMASK  */
226 /*  and then compared to the address, if there is a match on the write  */
227 /*  then the node is written to.                                        */
228 /*                                                                      */
229 /*  The memory space for discrete sound is 4096 locations (0x1000)      */
230 /*  the addr/addrmask values are used to setup a lookup table.          */
231 /*                                                                      */
232 /*  Can be written to with:    discrete_sound_w(0x0000, data);          */
233 /*                                                                      */
234 /************************************************************************/
235 /*                                                                      */
236 /* DISCRETE_SQUAREWAVE - Squarewave waveform generator node, has four   */
237 /*                       input nodes FREQUENCY, AMPLITUDE, ENABLE and   */
238 /*                       DUTY if node is not connected it will default  */
239 /*                       to the initialised value.                      */
240 /*                                                                      */
241 /*                         ------------                                 */
242 /*                        |            |                                */
243 /*    ENABLE     -0------}|            |                                */
244 /*                        |            |                                */
245 /*    FREQUENCY  -1------}|            |                                */
246 /*                        |            |                                */
247 /*    AMPLITUDE  -2------}| SQUAREWAVE |----}   Netlist node            */
248 /*                        |            |                                */
249 /*    DUTY CYCLE -3------}|            |                                */
250 /*                        |            |                                */
251 /*    BIAS       -4------}|            |                                */
252 /*                        |            |                                */
253 /*    PHASE      -5------}|            |                                */
254 /*                        |            |                                */
255 /*                         ------------                                 */
256 /*                                                                      */
257 /*  Declaration syntax                                                  */
258 /*                                                                      */
259 /*     DISCRETE_SQUAREWAVE(name of node,                                */
260 /*                         enable node or static value                  */
261 /*                         frequency node or static value               */
262 /*                         amplitude node or static value               */
263 /*                         duty cycle node or static value              */
264 /*                         dc bias value for waveform                   */
265 /*                         starting phase value in degrees)             */
266 /*                                                                      */
267 /*  Example config line                                                 */
268 /*                                                                      */
269 /*     DISCRETE_SQUAREWAVE(NODE_03,NODE_01,NODE_02,0,100,50,90)         */
270 /*                                                                      */
271 /************************************************************************/
272 /*                                                                      */
273 /* DISCRETE_SINEWAVE   - Sinewave waveform generator node, has four     */
274 /*                       input nodes FREQUENCY, AMPLITUDE, ENABLE and   */
275 /*                       PHASE, if a node is not connected it will      */
276 /*                       default to the initialised value in the macro  */
277 /*                                                                      */
278 /*                         ------------                                 */
279 /*                        |            |                                */
280 /*    ENABLE     -0------}|            |                                */
281 /*                        |            |                                */
282 /*    FREQUENCY  -1------}|            |                                */
283 /*                        | SINEWAVE   |----}   Netlist node            */
284 /*    AMPLITUDE  -2------}|            |                                */
285 /*                        |            |                                */
286 /*    BIAS       -3------}|            |                                */
287 /*                        |            |                                */
288 /*    PHASE      -4------}|            |                                */
289 /*                        |            |                                */
290 /*                         ------------                                 */
291 /*                                                                      */
292 /*  Declaration syntax                                                  */
293 /*                                                                      */
294 /*     DISCRETE_SINEWAVE  (name of node,                                */
295 /*                         enable node or static value                  */
296 /*                         frequency node or static value               */
297 /*                         amplitude node or static value               */
298 /*                         dc bias value for waveform                   */
299 /*                         starting phase value in degrees)             */
300 /*                                                                      */
301 /*  Example config line                                                 */
302 /*                                                                      */
303 /*     DISCRETE_SINEWAVE(NODE_03,NODE_01,NODE_02,10000,90)              */
304 /*                                                                      */
305 /************************************************************************/
306 /*                                                                      */
307 /* DISCRETE_TRIANGLEW  - Triagular waveform generator, generates        */
308 /*                       equal ramp up/down at chosen frequency         */
309 /*                                                                      */
310 /*                         ------------                                 */
311 /*                        |            |                                */
312 /*    ENABLE     -0------}|            |                                */
313 /*                        |            |                                */
314 /*    FREQUENCY  -1------}|  TRIANGLE  |----}   Netlist node            */
315 /*                        |    WAVE    |                                */
316 /*    AMPLITUDE  -2------}|            |                                */
317 /*                        |            |                                */
318 /*    BIAS       -3------}|            |                                */
319 /*                        |            |                                */
320 /*    PHASE      -4------}|            |                                */
321 /*                        |            |                                */
322 /*                         ------------                                 */
323 /*                                                                      */
324 /*  Declaration syntax                                                  */
325 /*                                                                      */
326 /*     DISCRETE_TRIANGLEWAVE(name of node,                              */
327 /*                         enable node or static value                  */
328 /*                         frequency node or static value               */
329 /*                         amplitude node or static value               */
330 /*                         dc bias value for waveform                   */
331 /*                         starting phase value in degrees)             */
332 /*                                                                      */
333 /*  Example config line                                                 */
334 /*                                                                      */
335 /*     DISCRETE_TRIANGLEWAVE(NODE_03,1,5000,NODE_01)                    */
336 /*                                                                      */
337 /************************************************************************/
338 /*                                                                      */
339 /* DISCRETE_SAWTOOTHWAVE - Saw tooth shape waveform generator, rapid    */
340 /*                         rise and then graduated fall                 */
341 /*                                                                      */
342 /*                         ------------                                 */
343 /*                        |            |                                */
344 /*    ENABLE     -0------}|            |                                */
345 /*                        |            |                                */
346 /*    FREQUENCY  -1------}|            |                                */
347 /*                        |            |                                */
348 /*    AMPLITUDE  -2------}|  SAWTOOTH  |----} Netlist Node              */
349 /*                        |    WAVE    |                                */
350 /*    BIAS       -3------}|            |                                */
351 /*                        |            |                                */
352 /*    GRADIENT   -4------}|            |                                */
353 /*                        |            |                                */
354 /*    PHASE      -5------}|            |                                */
355 /*                        |            |                                */
356 /*                         ------------                                 */
357 /*                                                                      */
358 /*  Declaration syntax                                                  */
359 /*                                                                      */
360 /*     DISCRETE_SAWTOOTHWAVE(name of node,                              */
361 /*                         enable node or static value                  */
362 /*                         frequency node or static value               */
363 /*                         amplitude node or static value               */
364 /*                         dc bias value for waveform                   */
365 /*                         gradient of wave ==0 //// !=0 \\\\           */
366 /*                         starting phase value in degrees)             */
367 /*                                                                      */
368 /*  Example config line                                                 */
369 /*                                                                      */
370 /*     DISCRETE_SAWTOOTHWAVE(NODE_03,1,5000,NODE_01,0,90)               */
371 /*                                                                      */
372 /************************************************************************/
373 /*                                                                      */
374 /* DISCRETE_NOISE      - Noise waveform generator node, generates       */
375 /*                       random noise at the chosen frequency.          */
376 /*                                                                      */
377 /*                         ------------                                 */
378 /*                        |            |                                */
379 /*    ENABLE     -0------}|            |                                */
380 /*                        |            |                                */
381 /*    FREQUENCY  -1------}|   NOISE    |----}   Netlist node            */
382 /*                        |            |                                */
383 /*    AMPLITUDE  -2------}|            |                                */
384 /*                        |            |                                */
385 /*    BIAS       -3------}|            |                                */
386 /*                        |            |                                */
387 /*                         ------------                                 */
388 /*                                                                      */
389 /*  Declaration syntax                                                  */
390 /*                                                                      */
391 /*     DISCRETE_NOISE     (name of node,                                */
392 /*                         enable node or static value                  */
393 /*                         frequency node or static value               */
394 /*                         amplitude node or static value)              */
395 /*                                                                      */
396 /*  Example config line                                                 */
397 /*                                                                      */
398 /*     DISCRETE_NOISE(NODE_03,1,5000,NODE_01)                           */
399 /*                                                                      */
400 /************************************************************************/
401 /*                                                                      */
402 /* DISCRETE_LFSR_NOISE - Noise waveform generator node, generates       */
403 /*                       psuedo random digital stream at the requested  */
404 /*                       clock frequency. Amplitude is 0/AMPLITUDE.     */
405 /*                                                                      */
406 /*                         ------------                                 */
407 /*                        |            |                                */
408 /*    ENABLE      -0-----}|            |                                */
409 /*                        |            |                                */
410 /*    RESET       -1-----}|            |                                */
411 /*                        |            |                                */
412 /*    FREQUENCY   -2-----}|   LFSR     |                                */
413 /*                        |   CYCLIC   |----}   Netlist Node            */
414 /*    AMPLITUDE   -3-----}|   NOISE    |                                */
415 /*                        |            |                                */
416 /*    FEED BIT    -4-----}|            |                                */
417 /*                        |            |                                */
418 /*    LFSR DESC   -5-----}|            |                                */
419 /*                        |            |                                */
420 /*                         ------------                                 */
421 /*                                                                      */
422 /*  Declaration syntax                                                  */
423 /*                                                                      */
424 /*     DISCRETE_LFSR_NOISE(name of node,                                */
425 /*                         enable node or static value                  */
426 /*                         reset node or static value                   */
427 /*                         frequency node or static value               */
428 /*                         amplitude node or static value               */
429 /*                         forced infeed bit to shift reg               */
430 /*                         LFSR noise descriptor structure)             */
431 /*                                                                      */
432 /*  Example config line                                                 */
433 /*                                                                      */
434 /*     DISCRETE_LFSR_NOISE(NODE_03,1,NODE_04,5000,NODE_01,0,{...})      */
435 /*                                                                      */
436 /*  The diagram below outlines the structure of the LFSR model.         */
437 /*                                                                      */
438 /*         .-------.                                                    */
439 /*   FEED  |       |                                                    */
440 /*   ----->|  F2   |<--------------------------------------------.      */
441 /*         |       |                                             |      */
442 /*         .-------.               BS - Bit Select               |      */
443 /*             |                   Fx - Programmable Function    |      */
444 /*             |        .-------.  PI - Programmable Inversion   |      */
445 /*             |        |       |                                |      */
446 /*             |  .---- | SR>>1 |<--------.                      |      */
447 /*             |  |     |       |         |                      |      */
448 /*             V  V     .-------.         |  .----               |      */
449 /*           .------.                     |->| BS |--. .------.  |      */
450 /*   BITMASK |      |    .-------------.  |  .----.  .-|      |  |      */
451 /*   ------->|  F3  |--->| Shift Reg   |--|            |  F1  |--.      */
452 /*           |      | |  .-------------.  |  .----.  .-|      |         */
453 /*           .------. |         ^         .->| BS |--. .------.         */
454 /*                    |         |            .----.                     */
455 /*   CLOCK            |     RESET VAL                                   */
456 /*   ---->            |                      .----.  .----.             */
457 /*                    .----------------------| BS |--| PI |----OUTPUT   */
458 /*                                           .----.  .----.             */
459 /*                                                                      */
460 /************************************************************************/
461 /*                                                                      */
462 /* DISCRETE_ADDER      - Node addition function, available in three     */
463 /*                       lovelly flavours, ADDER2,ADDER3,ADDER4         */
464 /*                       that perform a summation of incoming nodes     */
465 /*                                                                      */
466 /*                         ------------                                 */
467 /*                        |            |                                */
468 /*    INPUT0     -0------}|            |                                */
469 /*                        |            |                                */
470 /*    INPUT1     -1------}|     |      |                                */
471 /*                        |    -+-     |----}   Netlist node            */
472 /*    INPUT2     -2------}|     |      |                                */
473 /*                        |            |                                */
474 /*    INPUT3     -3------}|            |                                */
475 /*                        |            |                                */
476 /*                         ------------                                 */
477 /*                                                                      */
478 /*  Declaration syntax                                                  */
479 /*                                                                      */
480 /*     DISCRETE_ADDERx    (name of node,                                */
481 /*        (x=2/3/4)        enable node or static value                  */
482 /*                         input0 node or static value                  */
483 /*                         input1 node or static value                  */
484 /*                         input2 node or static value                  */
485 /*                         input3 node or static value)                 */
486 /*                                                                      */
487 /*  Example config line                                                 */
488 /*                                                                      */
489 /*     DISCRETE_ADDER2(NODE_03,1,NODE_12,-2000)                         */
490 /*                                                                      */
491 /*  Always enabled, subtracts 2000 from the output of NODE_12           */
492 /*                                                                      */
493 /************************************************************************/
494 /*                                                                      */
495 /* DISCRETE_GAIN       - Node multiplication function output is equal   */
496 /* DISCRETE_MULTIPLY     to INPUT0 * INPUT1                             */
497 /*                                                                      */
498 /*                         ------------                                 */
499 /*                        |            |                                */
500 /*    ENAB       -0------}|            |                                */
501 /*                        |    \|/     |                                */
502 /*    INPUT1     -1------}|    -+-     |----}   Netlist node            */
503 /*                        |    /|\     |                                */
504 /*    INPUT2     -2------}|            |                                */
505 /*                        |            |                                */
506 /*                         ------------                                 */
507 /*                                                                      */
508 /*  Declaration syntax                                                  */
509 /*                                                                      */
510 /*     DISCRETE_MULTIPLY  (name of node,                                */
511 /*                         enable node or static value                  */
512 /*                         input0 node or static value                  */
513 /*                         input1 node or static value)                 */
514 /*                                                                      */
515 /*     DISCRETE_GAIN      (name of node,                                */
516 /*                         input0 node or static value                  */
517 /*                         static value for gain)                       */
518 /*  Example config line                                                 */
519 /*                                                                      */
520 /*     DISCRETE_GAIN(NODE_03,NODE_12,112.0)                             */
521 /*                                                                      */
522 /*  Always enabled, multiplies the input NODE_12 by 112.0               */
523 /*                                                                      */
524 /************************************************************************/
525 /*                                                                      */
526 /* DISCRETE_DIVIDE     - Node dividion function                         */
527 /*                                                                      */
528 /*                         ------------                                 */
529 /*                        |            |                                */
530 /*    ENAB       -0------}|            |                                */
531 /*                        |     o      |                                */
532 /*    INPUT1     -1------}|    ---     |----}   Netlist node            */
533 /*                        |     o      |                                */
534 /*    INPUT2     -2------}|            |                                */
535 /*                        |            |                                */
536 /*                         ------------                                 */
537 /*                                                                      */
538 /*  Declaration syntax                                                  */
539 /*                                                                      */
540 /*     DISCRETE_DIVIDE    (name of node,                                */
541 /*                         enable node or static value                  */
542 /*                         input0 node or static value                  */
543 /*                         input1 node or static value)                 */
544 /*                                                                      */
545 /*  Example config line                                                 */
546 /*                                                                      */
547 /*     DISCRETE_DIVIDE(NODE_03,1.0,NODE_12,50.0)                        */
548 /*                                                                      */
549 /*  Always enabled, divides the input NODE_12 by 50.0. Note that a      */
550 /*  divide by zero condition will give a LARGE number output, it        */
551 /*  will not stall the machine or simulation. It will also attempt      */
552 /*  to write a divide by zero error to the Mame log if enabled.         */
553 /*                                                                      */
554 /************************************************************************/
555 /*                                                                      */
556 /* DISCRETE_SWITCH     - Node switch function, output node is switched  */
557 /*                       by switch input to take one node/contst or     */
558 /*                       other. Can be nodes or constants.              */
559 /*                                                                      */
560 /*    SWITCH     -0--------------.                                      */
561 /*                               V                                      */
562 /*                         ------------                                 */
563 /*                        |      |     |                                */
564 /*    INPUT0     -1------}|----o       |                                */
565 /*                        |       .--- |----}   Netlist node            */
566 /*    INPUT1     -2------}|----o /     |                                */
567 /*                        |            |                                */
568 /*                         ------------                                 */
569 /*                                                                      */
570 /*  Declaration syntax                                                  */
571 /*                                                                      */
572 /*     DISCRETE_SWITCH    (name of node,                                */
573 /*        (x=2/3/4)        enable node or static value                  */
574 /*                         switch node or static value                  */
575 /*                         input0 node or static value                  */
576 /*                         input1 node or static value)                 */
577 /*                                                                      */
578 /*  Example config line                                                 */
579 /*                                                                      */
580 /*     DISCRETE_SWITCH(NODE_03,1,NODE_10,NODE_90,5.0)                   */
581 /*                                                                      */
582 /*  Always enabled, NODE_10 switches output to be either NODE_90 or     */
583 /*  constant value 5.0. Switch==0 inp0=output else inp1=output          */
584 /*                                                                      */
585 /************************************************************************/
586 /*                                                                      */
587 /* DISCRETE_RCFILTER - Simple single pole RC filter network             */
588 /*                                                                      */
589 /*                         ------------                                 */
590 /*                        |            |                                */
591 /*    ENAB       -0------}| RC FILTER  |                                */
592 /*                        |            |                                */
593 /*    INPUT1     -1------}| -ZZZZ----  |                                */
594 /*                        |   R   |    |----}   Netlist node            */
595 /*    RVAL       -2------}|      ---   |                                */
596 /*                        |      ---C  |                                */
597 /*    CVAL       -3------}|       |    |                                */
598 /*                        |            |                                */
599 /*                         ------------                                 */
600 /*                                                                      */
601 /*  Declaration syntax                                                  */
602 /*                                                                      */
603 /*     DISCRETE_RCFILTER(name of node,                                  */
604 /*                       enable                                         */
605 /*                       input node (or value)                          */
606 /*                       resistor value in OHMS                         */
607 /*                       capacitor value in FARADS)                     */
608 /*                                                                      */
609 /*  Example config line                                                 */
610 /*                                                                      */
611 /*     DISCRETE_RCFILTER(NODE_11,1,NODE_10,100,1e-6)                    */
612 /*                                                                      */
613 /*  Defines an always enabled RC filter with a 100R & 1uF network       */
614 /*  the input is fed from NODE_10.                                      */
615 /*                                                                      */
616 /*  This can be also thought of as a low pass filter with a 3dB cutoff  */
617 /*  at:                                                                 */
618 /*                                  1                                   */
619 /*            Fcuttoff =      --------------                            */
620 /*                            2*Pi*RVAL*CVAL                            */
621 /*                                                                      */
622 /*  (3dB cutoff is where the output power has dropped by 3dB ie Half)   */
623 /*                                                                      */
624 /************************************************************************/
625 /*                                                                      */
626 /* DISCRETE_RCDISC - Simple single pole RC discharge network            */
627 /*                                                                      */
628 /*                         ------------                                 */
629 /*                        |            |                                */
630 /*    ENAB       -0------}| RC         |                                */
631 /*                        |            |                                */
632 /*    INPUT1     -1------}| -ZZZZ----  |                                */
633 /*                        |   R   |    |----}   Netlist node            */
634 /*    RVAL       -2------}|      ---   |                                */
635 /*                        |      ---C  |                                */
636 /*    CVAL       -3------}|       |    |                                */
637 /*                        |            |                                */
638 /*                         ------------                                 */
639 /*                                                                      */
640 /*  Declaration syntax                                                  */
641 /*                                                                      */
642 /*     DISCRETE_RCFILTER(name of node,                                  */
643 /*                       enable                                         */
644 /*                       input node (or value)                          */
645 /*                       resistor value in OHMS                         */
646 /*                       capacitor value in FARADS)                     */
647 /*                                                                      */
648 /*  Example config line                                                 */
649 /*                                                                      */
650 /*     DISCRETE_RCDISC(NODE_11,NODE_10,10,100,1e-6)                     */
651 /*                                                                      */
652 /*  When enabled by NODE_10, C dischanges from 10v as indicated by RC   */
653 /*  of 100R & 1uF.                                                      */
654 /*                                                                      */
655 /************************************************************************/
656 /*                                                                      */
657 /* DISCRETE_RCDIS2C  - Switched input RC discharge network              */
658 /*                                                                      */
659 /*                         ------------                                 */
660 /*                        |            |                                */
661 /*    SWITCH     -0------}| IP0 | IP1  |                                */
662 /*                        |            |                                */
663 /*    INPUT0     -1------}| -ZZZZ-.    |                                */
664 /*                        |   R0  |    |                                */
665 /*    RVAL0      -2------}|       |    |                                */
666 /*                        |       |    |                                */
667 /*    INPUT1     -3------}| -ZZZZ----  |                                */
668 /*                        |   R1  |    |----}   Netlist node            */
669 /*    RVAL1      -4------}|      ---   |                                */
670 /*                        |      ---C  |                                */
671 /*    CVAL       -5------}|       |    |                                */
672 /*                        |            |                                */
673 /*                         ------------                                 */
674 /*                                                                      */
675 /*  Declaration syntax                                                  */
676 /*                                                                      */
677 /*      DISCRETE_RCDISC2(name of node,                                  */
678 /*                       switch                                         */
679 /*                       input0 node (or value)                         */
680 /*                       resistor0 value in OHMS                        */
681 /*                       input1 node (or value)                         */
682 /*                       resistor1 value in OHMS                        */
683 /*                       capacitor value in FARADS)                     */
684 /*                                                                      */
685 /*  Example config line                                                 */
686 /*                                                                      */
687 /*     DISCRETE_RCDISC(NODE_9,NODE_10,10.0,100,0.0,100,1e-6)            */
688 /*                                                                      */
689 /*  When switched by NODE_10, C charges/dischanges from 10v/0v          */
690 /*  as dicated by RC0 & RC1 combos respectively                         */
691 /*  of 100R & 1uF.                                                      */
692 /*                                                                      */
693 /************************************************************************/
694 /*                                                                      */
695 /* DISCRETE_RAMP - Ramp up/down circuit with clamps & reset             */
696 /*                                                                      */
697 /*                         ------------                                 */
698 /*                        |            |                                */
699 /*    ENAB       -0------}| FREE/CLAMP |                                */
700 /*                        |            |                                */
701 /*    RAMP       -1------}| Up/Down    |                                */
702 /*                        |            |                                */
703 /*    GRAD       -2------}| Grad/sec   |                                */
704 /*                        |            |----}   Netlist node            */
705 /*    MIN        -3------}| Start clamp|                                */
706 /*                        |            |                                */
707 /*    MAX        -4------}| End clamp  |                                */
708 /*                        |            |                                */
709 /*    CLAMP      -5------}| off clamp  |                                */
710 /*                        |            |                                */
711 /*                         ------------                                 */
712 /*                                                                      */
713 /*  Declaration syntax                                                  */
714 /*                                                                      */
715 /*         DISCRETE_RAMP(name of node,                                  */
716 /*                       enable                                         */
717 /*                       ramp forward/reverse node (or value)           */
718 /*                       gradient node (or static value)                */
719 /*                       minimum node or static value                   */
720 /*                       maximum node or static value                   */
721 /*                       clamp node or static value when disabled)      */
722 /*                                                                      */
723 /*  Example config line                                                 */
724 /*                                                                      */
725 /*     DISCRETE_RAMP(NODE_9,NODE_10,NODE_11,10.0,-10.0,10.0,0)          */
726 /*                                                                      */
727 /*  Node10 when not zero will allow ramp to operate, when 0 then output */
728 /*  is clamped to clamp value specified. Node11 ramp when 0 then +ve    */
729 /*  gradient, not zero equals -ve gradient. Output is clamped to max-   */
730 /*  min values. Gradient is specified in change/second.                 */
731 /*                                                                      */
732 /************************************************************************/
733 /*                                                                      */
734 /* DISCRETE_CLAMP - Force a signal to stay within bounds MIN/MAX        */
735 /*                                                                      */
736 /*                         ------------                                 */
737 /*                        |            |                                */
738 /*    ENAB       -0------}|            |                                */
739 /*                        |            |                                */
740 /*    INP0       -1------}|            |                                */
741 /*                        |            |                                */
742 /*    MIN        -2------}|   CLAMP    |----}   Netlist node            */
743 /*                        |            |                                */
744 /*    MAX        -3------}|            |                                */
745 /*                        |            |                                */
746 /*    CLAMP      -4------}|            |                                */
747 /*                        |            |                                */
748 /*                         ------------                                 */
749 /*                                                                      */
750 /*  Declaration syntax                                                  */
751 /*                                                                      */
752 /*        DISCRETE_CLAMP(name of node,                                  */
753 /*                       enable                                         */
754 /*                       input node                                     */
755 /*                       minimum node or static value                   */
756 /*                       maximum node or static value                   */
757 /*                       clamp node or static value when disabled)      */
758 /*                                                                      */
759 /*  Example config line                                                 */
760 /*                                                                      */
761 /*     DISCRETE_CLAMP(NODE_9,NODE_10,NODE_11,2.0,10.0,5.0)              */
762 /*                                                                      */
763 /*  Node10 when not zero will allow clamp to operate forcing the value  */
764 /*  on the node output, to be within the MIN/MAX boundard. When enable  */
765 /*  is set to zero the node will output the clamp value                 */
766 /*                                                                      */
767 /************************************************************************/
768 /*                                                                      */
769 /* DISCRETE_SAMPHOLD - Sample & Hold circuit                            */
770 /*                                                                      */
771 /*                         ------------                                 */
772 /*                        |            |                                */
773 /*    ENAB       -0------}|            |                                */
774 /*                        |            |                                */
775 /*    INP0       -1------}|   SAMPLE   |                                */
776 /*                        |     &      |----} Netlist node              */
777 /*    CLOCK      -2------}|    HOLD    |                                */
778 /*                        |            |                                */
779 /*    CLKTYPE    -3------}|            |                                */
780 /*                        |            |                                */
781 /*                         ------------                                 */
782 /*                                                                      */
783 /*  Declaration syntax                                                  */
784 /*                                                                      */
785 /*     DISCRETE_SAMPHOLD(name of node,                                  */
786 /*                       enable                                         */
787 /*                       input node                                     */
788 /*                       clock node or static value                     */
789 /*                       input clock type)                              */
790 /*                                                                      */
791 /*  Example config line                                                 */
792 /*                                                                      */
793 /*     DISCRETE_SAMPHOLD(NODE_9,1,NODE_11,NODE_12,DISC_SAMPHOLD_REDGE)  */
794 /*                                                                      */
795 /*  Node9 will sample the input node 11 on the rising edge (REDGE) of   */
796 /*  the input clock signal of node 12.                                  */
797 /*                                                                      */
798 /*   DISC_SAMPHOLD_REDGE  - Rising edge clock                           */
799 /*   DISC_SAMPHOLD_FEDGE  - Falling edge clock                          */
800 /*   DISC_SAMPHOLD_HLATCH - Output is latched whilst clock is high      */
801 /*   DISC_SAMPHOLD_LLATCH - Output is latched whilst clock is low       */
802 /*                                                                      */
803 /************************************************************************/
804 /*                                                                      */
805 /* DISCRETE_LOGIC_INV  - Logic invertor                                 */
806 /* DISCRETE_LOGIC_AND  - Logic AND gate (3 & 4 input also available)    */
807 /* DISCRETE_LOGIC_NAND - Logic NAND gate (3 & 4 input also available)   */
808 /* DISCRETE_LOGIC_OR   - Logic OR gate (3 & 4 input also available)     */
809 /* DISCRETE_LOGIC_NOR  - Logic NOR gate (3 & 4 input also available)    */
810 /* DISCRETE_LOGIC_XOR  - Logic XOR gate                                 */
811 /* DISCRETE_LOGIC_NXOR - Logic NXOR gate                                */
812 /*                                                                      */
813 /*                         ------------                                 */
814 /*                        |            |                                */
815 /*    ENAB       -0------}|            |                                */
816 /*                        |            |                                */
817 /*    INPUT0     -0------}|            |                                */
818 /*                        |   LOGIC    |                                */
819 /*    [INPUT1]   -1------}|  FUNCTION  |----}   Netlist node            */
820 /*                        |    !&|^    |                                */
821 /*    [INPUT2]   -2------}|            |                                */
822 /*                        |            |                                */
823 /*    [INPUT3]   -3------}|            |                                */
824 /*                        |            |                                */
825 /*    [] - Optional        ------------                                 */
826 /*                                                                      */
827 /*  Declaration syntax                                                  */
828 /*                                                                      */
829 /*     DISCRETE_LOGIC_XXXn(name of node,                                */
830 /*      (X=INV/AND/etc)    enable node or static value                  */
831 /*      (n=Blank/2/3)      input0 node or static value                  */
832 /*                         [input1 node or static value]                */
833 /*                         [input2 node or static value]                */
834 /*                         [input3 node or static value])               */
835 /*                                                                      */
836 /*  Example config lines                                                */
837 /*                                                                      */
838 /*     DISCRETE_LOGIC_INV(NODE_03,1,NODE_12)                            */
839 /*     DISCRETE_LOGIC_AND(NODE_03,1,NODE_12,NODE_13)                    */
840 /*     DISCRETE_LOGIC_NOR4(NODE_03,1,NODE_12,NODE_13,NODE_14,NODE_15)   */
841 /*                                                                      */
842 /*  Node output is always either 0.0 or 1.0 any input value !=0.0 is    */
843 /*  taken as a logic 1.                                                 */
844 /*                                                                      */
845 /************************************************************************/
846 /*                                                                      */
847 /* DISCRETE_NE555 - NE555 Chip simulation                               */
848 /*                                                                      */
849 /*                         ------------                                 */
850 /*                        |            |                                */
851 /*    RESET      -0------}|            |                                */
852 /*                        |            |                                */
853 /*    TRIGGER    -1------}|            |                                */
854 /*                        |            |                                */
855 /*    THRESHOLD  -2------}|   NE555    |----}   Netlist node            */
856 /*                        |            |                                */
857 /*    CONTROL V  -3------}|            |                                */
858 /*                        |            |                                */
859 /*    VCC        -4------}|            |                                */
860 /*                        |            |                                */
861 /*                         ------------                                 */
862 /*                                                                      */
863 /*  Declaration syntax                                                  */
864 /*                                                                      */
865 /*     DISCRETE_NE555(reset node (or value) - <0.7 causes a reset       */
866 /*                    trigger node (or value)                           */
867 /*                    threshold node (or value)                         */
868 /*                    ctrl volt node (or value) - Use NODE_NC for N/C   */
869 /*                    vcc node (or value) - Needed for comparators)     */
870 /*                                                                      */
871 /*  Example config line                                                 */
872 /*                                                                      */
873 /*     DISCRETE_NE555(NODE32,1,NODE_31,NODE_31,NODE_NC,5.0)             */
874 /*                                                                      */
875 /************************************************************************/
876 /*                                                                      */
877 /* DISCRETE_OUTPUT - Single output node to Mame mixer and output        */
878 /*                                                                      */
879 /*                             ----------                               */
880 /*                            |          |     -/|                      */
881 /*      Netlist node --------}| OUTPUT   |----|  | Sound Output         */
882 /*                            |          |     -\|                      */
883 /*                             ----------                               */
884 /*                                                                      */
885 /*  Declaration syntax                                                  */
886 /*                                                                      */
887 /*     DISCRETE_OUTPUT(name of output node,volume)                      */
888 /*                                                                      */
889 /*  Example config line                                                 */
890 /*                                                                      */
891 /*     DISCRETE_OUTPUT(NODE_02,100)                                     */
892 /*                                                                      */
893 /*  Output stream will be generated from the NODE_02 output stream.     */
894 /*                                                                      */
895 /************************************************************************/
896 /*                                                                      */
897 /* DISCRETE_OUTPUT_STEREO - Single output node to Mame mixer and output */
898 /*                                                                      */
899 /*                                ----------                            */
900 /*                               |          |                           */
901 /*    Left  Netlist node -------}|          |     -/|                   */
902 /*                               | OUTPUT   |----|  | Sound Output      */
903 /*    Right Netlist node -------}|          |     -\|     L/R           */
904 /*                               |          |                           */
905 /*                                ----------                            */
906 /*  Declaration syntax                                                  */
907 /*                                                                      */
908 /*     DISCRETE_OUTPUT_STEREO(left output node,                         */
909 /*                            right output node,                        */
910 /*                            volume level)                             */
911 /*                                                                      */
912 /*  Example config line                                                 */
913 /*                                                                      */
914 /*   DISCRETE_OUTPUT_STEREO(NODE_02,NODE12,100)                         */
915 /*                                                                      */
916 /*  Output stream will be generated from the NODE_02 and NODE_12        */
917 /*  streams.                                                            */
918 /*                                                                      */
919 /************************************************************************/
920 
921 #define DISCRETE_MAX_NODES		300
922 #define DISCRETE_MAX_ADJUSTERS	20
923 
924 #define DISC_LOGADJ 1.0
925 #define DISC_LINADJ 0.0
926 
927 /* Function possibilities for the LFSR feedback nodes */
928 /* 2 inputs, one output                               */
929 #define DISC_LFSR_XOR		0
930 #define DISC_LFSR_OR		1
931 #define DISC_LFSR_AND		2
932 #define DISC_LFSR_XNOR		3
933 #define DISC_LFSR_NOR		4
934 #define DISC_LFSR_NAND		5
935 #define DISC_LFSR_IN0		6
936 #define DISC_LFSR_IN1		7
937 #define DISC_LFSR_NOT_IN0	8
938 #define DISC_LFSR_NOT_IN1	9
939 #define DISC_LFSR_REPLACE	10
940 
941 /* Sample & Hold supported clock types */
942 #define DISC_SAMPHOLD_REDGE		0
943 #define DISC_SAMPHOLD_FEDGE		1
944 #define DISC_SAMPHOLD_HLATCH	2
945 #define DISC_SAMPHOLD_LLATCH	3
946 
947 
948 struct discrete_sound_block
949 {
950 	int node;                                   /* Output node number */
951 	int type;                                   /* see defines below */
952 	int input_node0;                            /* input/control nodes */
953 	int input_node1;                            /* input/control nodes */
954 	int input_node2;                            /* input/control nodes */
955 	int input_node3;                            /* input/control nodes */
956 	int input_node4;                            /* input/control nodes */
957 	int input_node5;                            /* input/control nodes */
958 	float initial0;                            /* Initial values */
959 	float initial1;                            /* Initial values */
960 	float initial2;                            /* Initial values */
961 	float initial3;                            /* Initial values */
962 	float initial4;                            /* Initial values */
963 	float initial5;                            /* Initial values */
964 	const void *custom;                         /* Custom function specific initialisation data */
965 	const char *name;                           /* Node Name */
966 };
967 
968 struct node_description
969 {
970 	int 	node;								/* The nodes index number in the node list      */
971 	int		module;								/* The nodes module number from the module list */
972 	float	output;								/* The nodes last output value                  */
973 	struct node_description *input_node0;		/* Either pointer to input node OR NULL in which case use the input value */
974 	struct node_description *input_node1;
975 	struct node_description *input_node2;
976 	struct node_description *input_node3;
977 	struct node_description *input_node4;
978 	struct node_description *input_node5;
979 	float	input0;
980 	float	input1;
981 	float	input2;
982 	float	input3;
983 	float	input4;
984 	float	input5;
985 	void	*context;                           /* Contextual information specific to this node type */
986 	const char	*name;
987 	const void *custom;                         /* Custom function specific initialisation data */
988 };
989 
990 struct discrete_module
991 {
992 	int type;
993 	const char *name;
994 	int (*init) (struct node_description *node);	/* Create the context resource for a node */
995 	int (*kill) (struct node_description *node);	/* Destroy the context of a node and release all resources */
996 	int (*reset)(struct node_description *node);	/* Called to reset a node after creation or system reset */
997 	int (*step) (struct node_description *node);	/* Called to execute one time delta of output update */
998 };
999 
1000 struct discrete_sh_adjuster
1001 {
1002 	float value;
1003 	float min;
1004 	float max;
1005 	float initial;
1006 	const char *name;
1007 	int islogscale;
1008 };
1009 
1010 struct discrete_lfsr_desc
1011 {
1012 	int bitlength;
1013 	int reset_value;
1014 
1015 	int feedback_bitsel0;
1016 	int feedback_bitsel1;
1017 	int feedback_function0;         /* Combines bitsel0 & bitsel1 */
1018 
1019 	int feedback_function1;         /* Combines funct0 & infeed bit */
1020 
1021 	int feedback_function2;         /* Combines funct1 & shifted register */
1022 	int feedback_function2_mask;    /* Which bits are affected by function 2 */
1023 
1024 	int output_invert;              /* Invert the output */
1025 
1026 	int output_bit;
1027 };
1028 
1029 
1030 struct discrete_ladder
1031 {
1032 	int ladderlength;
1033 	float resistors[8];	/* Limit of 8 bit resistor ladder */
1034 	float capacitor;
1035 };
1036 
1037 
1038 enum { NODE_00=0x40000000
1039               , NODE_01, NODE_02, NODE_03, NODE_04, NODE_05, NODE_06, NODE_07, NODE_08, NODE_09,
1040        NODE_10, NODE_11, NODE_12, NODE_13, NODE_14, NODE_15, NODE_16, NODE_17, NODE_18, NODE_19,
1041        NODE_20, NODE_21, NODE_22, NODE_23, NODE_24, NODE_25, NODE_26, NODE_27, NODE_28, NODE_29,
1042        NODE_30, NODE_31, NODE_32, NODE_33, NODE_34, NODE_35, NODE_36, NODE_37, NODE_38, NODE_39,
1043        NODE_40, NODE_41, NODE_42, NODE_43, NODE_44, NODE_45, NODE_46, NODE_47, NODE_48, NODE_49,
1044        NODE_50, NODE_51, NODE_52, NODE_53, NODE_54, NODE_55, NODE_56, NODE_57, NODE_58, NODE_59,
1045        NODE_60, NODE_61, NODE_62, NODE_63, NODE_64, NODE_65, NODE_66, NODE_67, NODE_68, NODE_69,
1046        NODE_70, NODE_71, NODE_72, NODE_73, NODE_74, NODE_75, NODE_76, NODE_77, NODE_78, NODE_79,
1047        NODE_80, NODE_81, NODE_82, NODE_83, NODE_84, NODE_85, NODE_86, NODE_87, NODE_88, NODE_89,
1048        NODE_90, NODE_91, NODE_92, NODE_93, NODE_94, NODE_95, NODE_96, NODE_97, NODE_98, NODE_99,
1049        NODE_100,NODE_101,NODE_102,NODE_103,NODE_104,NODE_105,NODE_106,NODE_107,NODE_108,NODE_109,
1050        NODE_110,NODE_111,NODE_112,NODE_113,NODE_114,NODE_115,NODE_116,NODE_117,NODE_118,NODE_119,
1051        NODE_120,NODE_121,NODE_122,NODE_123,NODE_124,NODE_125,NODE_126,NODE_127,NODE_128,NODE_129,
1052        NODE_130,NODE_131,NODE_132,NODE_133,NODE_134,NODE_135,NODE_136,NODE_137,NODE_138,NODE_139,
1053        NODE_140,NODE_141,NODE_142,NODE_143,NODE_144,NODE_145,NODE_146,NODE_147,NODE_148,NODE_149,
1054        NODE_150,NODE_151,NODE_152,NODE_153,NODE_154,NODE_155,NODE_156,NODE_157,NODE_158,NODE_159,
1055        NODE_160,NODE_161,NODE_162,NODE_163,NODE_164,NODE_165,NODE_166,NODE_167,NODE_168,NODE_169,
1056        NODE_170,NODE_171,NODE_172,NODE_173,NODE_174,NODE_175,NODE_176,NODE_177,NODE_178,NODE_179,
1057        NODE_180,NODE_181,NODE_182,NODE_183,NODE_184,NODE_185,NODE_186,NODE_187,NODE_188,NODE_189,
1058        NODE_190,NODE_191,NODE_192,NODE_193,NODE_194,NODE_195,NODE_196,NODE_197,NODE_198,NODE_199,
1059        NODE_200,NODE_201,NODE_202,NODE_203,NODE_204,NODE_205,NODE_206,NODE_207,NODE_208,NODE_209,
1060        NODE_210,NODE_211,NODE_212,NODE_213,NODE_214,NODE_215,NODE_216,NODE_217,NODE_218,NODE_219,
1061        NODE_220,NODE_221,NODE_222,NODE_223,NODE_224,NODE_225,NODE_226,NODE_227,NODE_228,NODE_229,
1062        NODE_230,NODE_231,NODE_232,NODE_233,NODE_234,NODE_235,NODE_236,NODE_237,NODE_238,NODE_239,
1063        NODE_240,NODE_241,NODE_242,NODE_243,NODE_244,NODE_245,NODE_246,NODE_247,NODE_248,NODE_249,
1064        NODE_250,NODE_251,NODE_252,NODE_253,NODE_254,NODE_255,NODE_256,NODE_257,NODE_258,NODE_259,
1065        NODE_260,NODE_261,NODE_262,NODE_263,NODE_264,NODE_265,NODE_266,NODE_267,NODE_268,NODE_269,
1066        NODE_270,NODE_271,NODE_272,NODE_273,NODE_274,NODE_275,NODE_276,NODE_277,NODE_278,NODE_279,
1067        NODE_280,NODE_281,NODE_282,NODE_283,NODE_284,NODE_285,NODE_286,NODE_287,NODE_288,NODE_289,
1068        NODE_290,NODE_291,NODE_292,NODE_293,NODE_294,NODE_295,NODE_296,NODE_297,NODE_298,NODE_299 };
1069 
1070 /* Some Pre-defined nodes for convenience */
1071 
1072 #define NODE_NC  NODE_00
1073 #define NODE_OP  (NODE_00+(DISCRETE_MAX_NODES))
1074 
1075 #define NODE_START	NODE_00
1076 #define NODE_END	NODE_OP
1077 
1078 /************************************************************************/
1079 /*                                                                      */
1080 /*        Enumerated values for Node types in the simulation            */
1081 /*                                                                      */
1082 /*  DSS - Discrete Sound Source                                         */
1083 /*  DST - Discrete Sound Transform                                      */
1084 /*  DSD - Discrete Sound Device                                         */
1085 /*  DSO - Discrete Sound Output                                         */
1086 /*                                                                      */
1087 /************************************************************************/
1088 enum {
1089 	/* Sources */
1090 		DSS_NULL,                                /* Nothing, nill, zippo, only to be used as terminating node */
1091 		DSS_CONSTANT,                            /* Constant node */
1092 		DSS_ADJUSTMENT,                          /* Adjustment node */
1093 		DSS_INPUT,                               /* Memory mapped input node */
1094 		DSS_NOISE,                               /* Random Noise generator */
1095 		DSS_LFSR_NOISE,                          /* Cyclic/Resetable LFSR based Noise generator */
1096 		DSS_SQUAREWAVE,                          /* Square Wave generator */
1097 		DSS_SINEWAVE,                            /* Sine Wave generator */
1098 		DSS_TRIANGLEWAVE,                        /* Triangle wave generator */
1099 		DSS_SAWTOOTHWAVE,                        /* Sawtooth wave generator */
1100 	/* Transforms */
1101 		DST_RCFILTER,							 /* Simple RC Filter network */
1102 		DST_RCDISC,                              /* Simple RC discharge */
1103 		DST_RCDISC2,                             /* Switched 2 Input RC discharge */
1104 		DST_RAMP,                                /* Ramp up/down simulation */
1105 		DST_CLAMP,                               /* Signal Clamp */
1106 //		DST_LPF,                                 /* Low Pass Filter */
1107 //		DST_HPF,                                 /* High Pass Filter */
1108 		DST_GAIN,                                /* Gain Block, C = A*B */
1109 		DST_DIVIDE,                              /* Gain Block, C = A/B */
1110 		DST_ADDER,                               /* C = A+B */
1111 		DST_SWITCH,                              /* C = A or B */
1112 		DST_ONESHOT,                             /* One-shot pulse generator */
1113 		DST_SAMPHOLD,                            /* Sample & hold transform */
1114 		DST_LADDER,                              /* Resistor ladder emulation */
1115 //		DST_DELAY,                               /* Phase shift/Delay line */
1116 	/* Logic */
1117 		DST_LOGIC_INV,
1118 		DST_LOGIC_AND,
1119 		DST_LOGIC_NAND,
1120 		DST_LOGIC_OR,
1121 		DST_LOGIC_NOR,
1122 		DST_LOGIC_XOR,
1123 		DST_LOGIC_NXOR,
1124 	/* Devices */
1125 		DSD_NE555,                               /* NE555 Emulation */
1126 	/* Custom */
1127 //		DST_CUSTOM,                              /* whatever you want someday */
1128     /* Output Node */
1129 		DSO_OUTPUT                              /* The final output node */
1130 };
1131 
1132 
1133 /************************************************************************/
1134 /*                                                                      */
1135 /*        Encapsulation macros for defining your simulation             */
1136 /*                                                                      */
1137 /************************************************************************/
1138 #define DISCRETE_SOUND_START(STRUCTURENAME) struct discrete_sound_block STRUCTURENAME[] = {
1139 #define DISCRETE_SOUND_END                                             { NODE_00, DSS_NULL       ,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,0     ,0     ,0     ,0     ,0     ,0     ,NULL  ,"End Marker" }  };
1140 
1141 #define DISCRETE_CONSTANT(NODE,CONST)                                  { NODE   , DSS_CONSTANT   ,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,CONST ,0     ,0     ,0     ,0     ,0     ,NULL  ,"Constant"           },
1142 #define DISCRETE_ADJUSTMENT(NODE,ENAB,MIN,MAX,DEFAULT,LOGLIN,NAME)     { NODE   , DSS_ADJUSTMENT ,ENAB   ,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,ENAB  ,MIN   ,MAX   ,DEFAULT,LOGLIN,0    ,NULL  ,NAME                 },
1143 #define DISCRETE_INPUT(NODE,ADDR,MASK,INIT0)                           { NODE   , DSS_INPUT      ,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,INIT0 ,ADDR  ,MASK  ,1     ,0     ,INIT0 ,NULL  ,"Input"              },
1144 #define DISCRETE_INPUTX(NODE,ADDR,MASK,GAIN,OFFSET,INIT0)              { NODE   , DSS_INPUT      ,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,NODE_NC,INIT0 ,ADDR  ,MASK  ,GAIN  ,OFFSET,INIT0 ,NULL  ,"InputX"             },
1145 
1146 #define DISCRETE_SQUAREWAVE(NODE,ENAB,FREQ,AMPL,DUTY,BIAS,PHASE)       { NODE   , DSS_SQUAREWAVE ,ENAB   ,FREQ   ,AMPL   ,DUTY   ,BIAS   ,NODE_NC,ENAB  ,FREQ  ,AMPL  ,DUTY  ,BIAS  ,PHASE ,NULL  ,"Square Wave"        },
1147 #define DISCRETE_SINEWAVE(NODE,ENAB,FREQ,AMPL,BIAS,PHASE)              { NODE   , DSS_SINEWAVE   ,ENAB   ,FREQ   ,AMPL   ,BIAS   ,NODE_NC,NODE_NC,ENAB  ,FREQ  ,AMPL  ,BIAS  ,PHASE ,0     ,NULL  ,"Sine Wave"          },
1148 #define DISCRETE_NOISE(NODE,ENAB,FREQ,AMPL,BIAS)                       { NODE   , DSS_NOISE      ,ENAB   ,FREQ   ,AMPL   ,BIAS   ,NODE_NC,NODE_NC,ENAB  ,FREQ  ,AMPL  ,BIAS  ,0     ,0     ,NULL  ,"Noise Source"       },
1149 #define DISCRETE_TRIANGLEWAVE(NODE,ENAB,FREQ,AMPL,BIAS,PHASE)          { NODE   , DSS_TRIANGLEWAVE,ENAB  ,FREQ   ,AMPL   ,BIAS   ,NODE_NC,NODE_NC,ENAB  ,FREQ  ,AMPL  ,BIAS  ,PHASE ,0     ,NULL  ,"Triangle Wave"      },
1150 #define DISCRETE_SAWTOOTHWAVE(NODE,ENAB,FREQ,AMPL,BIAS,GRAD,PHASE)     { NODE   , DSS_SAWTOOTHWAVE,ENAB  ,FREQ   ,AMPL   ,BIAS   ,NODE_NC,NODE_NC,ENAB  ,FREQ  ,AMPL  ,BIAS  ,GRAD  ,PHASE ,NULL  ,"Saw Tooth Wave"     },
1151 #define DISCRETE_LFSR_NOISE(NODE,ENAB,RESET,FREQ,AMPL,FEED,BIAS,LFSRTB){ NODE   , DSS_LFSR_NOISE ,ENAB   ,RESET  ,FREQ   ,AMPL   ,FEED   ,BIAS   ,ENAB  ,RESET ,FREQ  ,AMPL  ,FEED  ,BIAS  ,LFSRTB,"LFSR Noise Source"  },
1152 
1153 #define DISCRETE_RCFILTER(NODE,ENAB,INP0,RVAL,CVAL)                    { NODE   , DST_RCFILTER   ,ENAB   ,INP0   ,NODE_NC,NODE_NC,NODE_NC,NODE_NC,ENAB  ,INP0  ,RVAL  ,CVAL  ,0     ,0     ,NULL  ,"RC Filter"          },
1154 #define DISCRETE_RCDISC(NODE,ENAB,INP0,RVAL,CVAL)                      { NODE   , DST_RCDISC     ,ENAB   ,INP0   ,NODE_NC,NODE_NC,NODE_NC,NODE_NC,ENAB  ,INP0  ,RVAL  ,CVAL  ,0     ,0     ,NULL  ,"RC Discharge"       },
1155 #define DISCRETE_RCDISC2(NODE,SWITCH,INP0,RVAL0,INP1,RVAL1,CVAL)       { NODE   , DST_RCDISC2    ,SWITCH ,INP0   ,NODE_NC,INP1   ,NODE_NC,NODE_NC,SWITCH,INP0  ,RVAL0 ,INP1  ,RVAL1 ,CVAL  ,NULL  ,"RC Discharge 2"     },
1156 #define DISCRETE_RAMP(NODE,ENAB,RAMP,GRAD,START,END,CLAMP)             { NODE   , DST_RAMP       ,ENAB   ,RAMP   ,GRAD   ,START  ,END    ,CLAMP  ,ENAB  ,RAMP  ,GRAD  ,START ,END   ,CLAMP ,NULL  ,"Ramp Up/Down"       },
1157 #define DISCRETE_ONOFF(NODE,ENAB,INP0)                                 { NODE   , DST_GAIN       ,ENAB   ,INP0   ,NODE_NC,NODE_NC,NODE_NC,NODE_NC,ENAB  ,0     ,1     ,0     ,0     ,0     ,NULL  ,"OnOff Switch"       },
1158 #define DISCRETE_INVERT(NODE,INP0)                                     { NODE   , DST_GAIN       ,NODE_NC,INP0   ,NODE_NC,NODE_NC,NODE_NC,NODE_NC,1     ,0     ,-1    ,0     ,0     ,0     ,NULL  ,"Inverter"           },
1159 #define DISCRETE_GAIN(NODE,INP0,GAIN)                                  { NODE   , DST_GAIN       ,NODE_NC,INP0   ,NODE_NC,NODE_NC,NODE_NC,NODE_NC,1     ,INP0  ,GAIN  ,0     ,0     ,0     ,NULL  ,"Gain"               },
1160 #define DISCRETE_MULTIPLY(NODE,ENAB,INP0,INP1)                         { NODE   , DST_GAIN       ,ENAB   ,INP0   ,INP1   ,NODE_NC,NODE_NC,NODE_NC,ENAB  ,INP0  ,INP1  ,0     ,0     ,0     ,NULL  ,"Multiplier"         },
1161 #define DISCRETE_DIVIDE(NODE,ENAB,INP0,INP1)                           { NODE   , DST_DIVIDE     ,ENAB   ,INP0   ,INP1   ,NODE_NC,NODE_NC,NODE_NC,ENAB  ,INP0  ,INP1  ,0     ,0     ,0     ,NULL  ,"Divider"            },
1162 #define DISCRETE_CLAMP(NODE,ENAB,INP0,MIN,MAX,CLAMP)                   { NODE   , DST_CLAMP      ,ENAB   ,INP0   ,MIN    ,MAX    ,CLAMP  ,NODE_NC,ENAB  ,INP0  ,MIN   ,MAX   ,CLAMP ,0     ,NULL  ,"Signal Clamp"       },
1163 #define DISCRETE_SWITCH(NODE,ENAB,SWITCH,INP0,INP1)                    { NODE   , DST_SWITCH     ,ENAB   ,SWITCH ,INP0   ,INP1   ,NODE_NC,NODE_NC,ENAB  ,SWITCH,INP0  ,INP1  ,0     ,0     ,NULL  ,"2 Pole Switch"      },
1164 #define DISCRETE_ADDER2(NODE,ENAB,INP0,INP1)                           { NODE   , DST_ADDER      ,ENAB   ,INP0   ,INP1   ,NODE_NC,NODE_NC,NODE_NC,ENAB  ,INP0  ,INP1  ,0     ,0     ,0     ,NULL  ,"Adder 2 Node"       },
1165 #define DISCRETE_ADDER3(NODE,ENAB,INP0,INP1,INP2)                      { NODE   , DST_ADDER      ,ENAB   ,INP0   ,INP1   ,INP2   ,NODE_NC,NODE_NC,ENAB  ,INP0  ,INP1  ,INP2  ,0     ,0     ,NULL  ,"Adder 3 Node"       },
1166 #define DISCRETE_ADDER4(NODE,ENAB,INP0,INP1,INP2,INP3)                 { NODE   , DST_ADDER      ,ENAB   ,INP0   ,INP1   ,INP2   ,INP3   ,NODE_NC,ENAB  ,INP0  ,INP1  ,INP2  ,INP3  ,0     ,NULL  ,"Adder 4 Node"       },
1167 #define DISCRETE_ONESHOTR(NODE,ENAB,TRIG,AMPL,WIDTH)                   { NODE   , DST_ONESHOT    ,ENAB   ,TRIG   ,NODE_NC,AMPL   ,WIDTH  ,NODE_NC,ENAB  ,TRIG  ,1     ,AMPL  ,WIDTH ,0     ,NULL  ,"One Shot Resetable" },
1168 #define DISCRETE_ONESHOT(NODE,ENAB,TRIG,RESET,AMPL,WIDTH)              { NODE   , DST_ONESHOT    ,ENAB   ,TRIG   ,RESET  ,AMPL   ,WIDTH  ,NODE_NC,ENAB  ,TRIG  ,RESET ,AMPL  ,WIDTH ,0     ,NULL  ,"One Shot"           },
1169 #define DISCRETE_LADDER(NODE,ENAB,INP0,GAIN,LADDER)                    { NODE   , DST_LADDER     ,ENAB   ,INP0   ,GAIN   ,NODE_NC,NODE_NC,NODE_NC,ENAB  ,INP0  ,GAIN  ,0     ,0     ,0     ,LADDER,"Resistor Ladder"    },
1170 #define DISCRETE_SAMPLHOLD(NODE,ENAB,INP0,CLOCK,CLKTYPE)               { NODE   , DST_SAMPHOLD   ,ENAB   ,INP0   ,CLOCK  ,NODE_NC,NODE_NC,NODE_NC,ENAB  ,INP0  ,CLOCK ,CLKTYPE,0    ,0     ,NULL  ,"Sample & Hold"      },
1171 
1172 #define	DISCRETE_LOGIC_INVERT(NODE,ENAB,INP0)                          { NODE   , DST_LOGIC_INV  ,ENAB   ,INP0   ,NODE_NC,NODE_NC,NODE_NC,NODE_NC,ENAB  ,INP0  ,0     ,0     ,0     ,0     ,NULL  ,"Logic Invertor"     },
1173 #define	DISCRETE_LOGIC_AND(NODE,ENAB,INP0,INP1)                        { NODE   , DST_LOGIC_AND  ,ENAB   ,INP0   ,INP1   ,NODE_NC,NODE_NC,NODE_NC,ENAB  ,INP0  ,INP1  ,1     ,1     ,0     ,NULL  ,"Logic AND (2inp)"   },
1174 #define	DISCRETE_LOGIC_AND3(NODE,ENAB,INP0,INP1,INP2)                  { NODE   , DST_LOGIC_AND  ,ENAB   ,INP0   ,INP1   ,INP2   ,NODE_NC,NODE_NC,ENAB  ,INP0  ,INP1  ,INP2  ,1     ,0     ,NULL  ,"Logic AND (3inp)"   },
1175 #define	DISCRETE_LOGIC_AND4(NODE,ENAB,INP0,INP1,INP2,INP3)             { NODE   , DST_LOGIC_AND  ,ENAB   ,INP0   ,INP1   ,INP2   ,INP3   ,NODE_NC,ENAB  ,INP0  ,INP1  ,INP2  ,INP3  ,0     ,NULL  ,"Logic AND (4inp)"   },
1176 #define	DISCRETE_LOGIC_NAND(NODE,ENAB,INP0,INP1)                       { NODE   , DST_LOGIC_NAND ,ENAB   ,INP0   ,INP1   ,NODE_NC,NODE_NC,NODE_NC,ENAB  ,INP0  ,INP1  ,1     ,1     ,0     ,NULL  ,"Logic NAND (2inp)"  },
1177 #define	DISCRETE_LOGIC_NAND3(NODE,ENAB,INP0,INP1,INP2)                 { NODE   , DST_LOGIC_NAND ,ENAB   ,INP0   ,INP1   ,INP2   ,NODE_NC,NODE_NC,ENAB  ,INP0  ,INP1  ,INP2  ,1     ,0     ,NULL  ,"Logic NAND (3inp)"  },
1178 #define	DISCRETE_LOGIC_NAND4(NODE,ENAB,INP0,INP1,INP2,INP3)            { NODE   , DST_LOGIC_NAND ,ENAB   ,INP0   ,INP1   ,INP2   ,INP3   ,NODE_NC,ENAB  ,INP0  ,INP1  ,INP2  ,INP3  ,0     ,NULL  ,"Logic NAND (4inp)"  },
1179 #define	DISCRETE_LOGIC_OR(NODE,ENAB,INP0,INP1)                         { NODE   , DST_LOGIC_OR   ,ENAB   ,INP0   ,INP1   ,NODE_NC,NODE_NC,NODE_NC,ENAB  ,INP0  ,INP1  ,0     ,0     ,0     ,NULL  ,"Logic OR (2inp)"    },
1180 #define	DISCRETE_LOGIC_OR3(NODE,ENAB,INP0,INP1,INP2)                   { NODE   , DST_LOGIC_OR   ,ENAB   ,INP0   ,INP1   ,INP2   ,NODE_NC,NODE_NC,ENAB  ,INP0  ,INP1  ,INP2  ,0     ,0     ,NULL  ,"Logic OR (3inp)"    },
1181 #define	DISCRETE_LOGIC_OR4(NODE,ENAB,INP0,INP1,INP2,INP3)              { NODE   , DST_LOGIC_OR   ,ENAB   ,INP0   ,INP1   ,INP2   ,INP3   ,NODE_NC,ENAB  ,INP0  ,INP1  ,INP2  ,INP3  ,0     ,NULL  ,"Logic OR (4inp)"    },
1182 #define	DISCRETE_LOGIC_NOR(NODE,ENAB,INP0,INP1)                        { NODE   , DST_LOGIC_NOR  ,ENAB   ,INP0   ,INP1   ,NODE_NC,NODE_NC,NODE_NC,ENAB  ,INP0  ,INP1  ,0     ,0     ,0     ,NULL  ,"Logic NOR (2inp)"   },
1183 #define	DISCRETE_LOGIC_NOR3(NODE,ENAB,INP0,INP1,INP2)                  { NODE   , DST_LOGIC_NOR  ,ENAB   ,INP0   ,INP1   ,INP2   ,NODE_NC,NODE_NC,ENAB  ,INP0  ,INP1  ,INP2  ,0     ,0     ,NULL  ,"Logic NOR (3inp)"   },
1184 #define	DISCRETE_LOGIC_NOR4(NODE,ENAB,INP0,INP1,INP2,INP3)             { NODE   , DST_LOGIC_NOR  ,ENAB   ,INP0   ,INP1   ,INP2   ,INP3   ,NODE_NC,ENAB  ,INP0  ,INP1  ,INP2  ,INP3  ,0     ,NULL  ,"Logic NOR (4inp)"   },
1185 #define	DISCRETE_LOGIC_XOR(NODE,ENAB,INP0,INP1)                        { NODE   , DST_LOGIC_XOR  ,ENAB   ,INP0   ,INP1   ,NODE_NC,NODE_NC,NODE_NC,ENAB  ,INP0  ,INP1  ,0     ,0     ,0     ,NULL  ,"Logic XOR (2inp)"   },
1186 #define	DISCRETE_LOGIC_NXOR(NODE,ENAB,INP0,INP1)                       { NODE   , DST_LOGIC_NXOR ,ENAB   ,INP0   ,INP1   ,NODE_NC,NODE_NC,NODE_NC,ENAB  ,INP0  ,INP1  ,0     ,0     ,0     ,NULL  ,"Logic NXOR (2inp)"  },
1187 
1188 #define DISCRETE_NE555(NODE,RESET,TRIGR,THRSH,CTRLV,VCC)               { NODE   , DSD_NE555      ,RESET  ,TRIGR  ,THRSH  ,CTRLV  ,VCC    ,NODE_NC,RESET ,TRIGR ,THRSH ,CTRLV ,VCC   ,0     ,NULL  ,"NE555 (Broken"      },
1189 
1190 #define DISCRETE_OUTPUT(OPNODE,VOL)                                    { NODE_OP, DSO_OUTPUT     ,OPNODE ,OPNODE ,NODE_NC,NODE_NC,NODE_NC,NODE_NC,0     ,0     ,VOL   ,0     ,0     ,0     ,NULL  ,"Output Node"        },
1191 #define DISCRETE_OUTPUT_STEREO(OPNODEL,OPNODER,VOL)                    { NODE_OP, DSO_OUTPUT     ,OPNODEL,OPNODER,NODE_NC,NODE_NC,NODE_NC,NODE_NC,0     ,0     ,VOL   ,0     ,0     ,0     ,NULL  ,"Stereo Output Node" },
1192 
1193 
1194 /************************************************************************/
1195 /*                                                                      */
1196 /*        Software interface to the external world i.e Into Mame        */
1197 /*                                                                      */
1198 /************************************************************************/
1199 
1200 int  discrete_sh_start (const struct MachineSound *msound);
1201 void discrete_sh_stop (void);
1202 void discrete_sh_reset (void);
1203 void discrete_sh_update (void);
1204 
1205 int  discrete_sh_adjuster_count(struct discrete_sound_block *dsintf);
1206 int  discrete_sh_adjuster_get(int arg,struct discrete_sh_adjuster *adjuster);
1207 int discrete_sh_adjuster_set(int arg,struct discrete_sh_adjuster *adjuster);
1208 
1209 WRITE_HANDLER(discrete_sound_w);
1210 READ_HANDLER(discrete_sound_r);
1211 
1212 
1213 #endif
1214