1 // license:CC0
2 // copyright-holders:Colin Douglas Howell
3 
4 #include "netlist/devices/net_lib.h"
5 
6 
7 #define USE_FRONTIERS   1
8 #define FAST_SWITCHES   1
9 
10 // This is a netlist description for the sound circuits of Midway's Gun Fight,
11 // based on Midway's schematic "Gun Fight Sound Generator Detail P.C.
12 // 597-907E".
13 //
14 // (This sound circuitry seems to have evolved from that for an older Midway
15 // game, an electromechanical rifle game from 1974 called Twin Pirate Gun. The
16 // schematics for Twin Pirate Gun's sound circuitry (P.C. 569-907-88),
17 // although not completely identical to Gun Fight's, are similar both in
18 // general structure and in many details.)
19 //
20 // Gun Fight's sound effects are simple "bang" sounds, both for the shooting
21 // of bullets and for bullets hitting targets. The effects are directed to the
22 // left or right speaker, depending on whether the left or right player is
23 // shooting or being hit. (Hits to obstacles get the same sound as hits to the
24 // right player and thus play from the right speaker.) Each sound effect gets
25 // a different pitch, with shots being higher pitched than hits. Shot sounds
26 // also decay faster than hit sounds and have slightly separated initial and
27 // secondary attacks, resulting in a "ka-pow" effect.
28 //
29 // The sounds are generated in stages by different sections of the circuitry.
30 // A noise generator, based on a zener diode, continuously produces white
31 // noise that forms the basis for all the sounds, and this noise is fed to
32 // four separate sound generators. Each generator filters the noise to produce
33 // the distinct pitch of its sound. Each generator's sound is triggered by a
34 // switch, activated digitally by the CPU. When this switch is turned on
35 // momentarily, a storage capacitor is charged up, and that sends power to the
36 // sound generator's transistor amplifier. This amplifies the filtered noise
37 // with a sharp attack as the switch is turned on and gradual decay as the
38 // capacitor drains. The generated sound is filtered further and then
39 // attenuated by a potentiometer which controls that sound's relative volume.
40 // Each side's two sound effect signals, after being generated and then
41 // attenuated by their respective volume pots, are mixed together and then
42 // further amplified by a second-stage transistor amplifier for that side.
43 // This mixed and amplified signal is itself filtered and then attenuated by
44 // the side's master volume potentiometer. Finally it gets sent to the power
45 // amplifier IC for that side's speaker. (This emulation does not handle the
46 // final power amplification.)
47 //
48 // The different sound effect generators have a common structure which is
49 // repeated four times. The mixers and second-stage amplifiers likewise have a
50 // common structure which is repeated twice, and their amplifiers are also
51 // rather similar to the effect amplifiers.
52 //
53 // To make the netlist easier to follow and verify, I've grouped its
54 // components and connections by function, with the groups ordered roughly
55 // according to the flow of signals:
56 //
57 // * the activating switches,
58 // * the shared noise generator,
59 // * the sound-effect noise filters,
60 // * the sound-effect initial amplifiers, output coupling capacitors and
61 //   filters, and effect-volume potentiometers,
62 // * the mixing circuits,
63 // * the second-stage amplifiers, output coupling capacitors and filters, and
64 //   master-volume potentiometers.
65 //
66 // Within each group, I've placed the sets of four similar components or
67 // connections together and listed them in the order: left-shot, right-shot,
68 // left-hit, right-hit. (For mixing and second-stage amplification components,
69 // the order is simply left, right.) Individual components are labeled the
70 // same as on the schematic.
71 
72 
73 // There are some uncertainties in this emulation about sound levels. The
74 // average level of the initially generated noise is uncertain, which poses a
75 // problem because all of the sound effects are based on amplifying that
76 // noise. The noise is generated by passing a small amount of current through
77 // a zener diode on the verge of its breakdown voltage, which results in very
78 // noisy current flow. Even though both the type of zener and the average
79 // current are known, the average strength of the noise is still uncertain,
80 // both because zener manufacturers do not specify performance under these
81 // conditions (they recommended zeners for voltage control under more stable,
82 // relatively noise-free operating conditions) and because the amount of noise
83 // may vary greatly from one zener to the next, even within the same
84 // production batch--let alone from one manufacturer to another. This is an
85 // inherent problem with zener diodes when used for noise generation.
86 //
87 // I have chosen a round figure of 2 mV RMS for the zener's average (RMS)
88 // noise level. Although this is only a guess, it seems to be in the ballpark
89 // for similar zeners operated with similar amounts of average current. It
90 // also keeps the noise component of the sound effects strong enough so as not
91 // to be overwhelmed by the pulse of the sound effects' initial attacks; this
92 // pulse is created by switching on their generating amplifiers and is
93 // independent of noise level. Meanwhile, this noise level is still low enough
94 // that, with all the volume potentiometers set to their midpoints, the noise
95 // won't be clipped by any subsequent amplification stage in the netlist, up
96 // to the power amp inputs. (Some such clipping may occur if a sound effect's
97 // volume is turned up well beyond its midpoint. That may also be true on real
98 // hardware.)
99 //
100 // The other big uncertainty is the audible effect of the power amp ICs. These
101 // amplifiers add both power and voltage gain, which may be enough to distort
102 // or clip the output. They may also have an audible filtering effect. In the
103 // Gun Fight schematic, and apparently in real machines, they are configured
104 // for a voltage gain of 15. Furthermore, any input voltages beyond a few
105 // hundred mV (positive or negative) should produce at least some clipping
106 // distortion, with the distortion getting worse for stronger signals. With
107 // all potentiometers set to the midpoint, the power amp signal inputs should
108 // see extreme pulses of +/- 3 V from the initial attack for sound effects,
109 // and even past those initial attack pulses, the sound effect noise should
110 // kick in at levels above +/- 1 V on the power amp inputs. If these levels
111 // are correct and the power amp ICs work as described, the noise of the sound
112 // effects should initially be heavily distorted, but since the original
113 // signal is already random noise, it's not clear whether that distortion
114 // would be apparent. Anyhow, the power amp ICs are completely unemulated
115 // here, and any distortion effects they might produce would be quite
116 // different from the hard clipping produced when limiting output levels
117 // digitally.
118 //
119 // I have compromized by setting the volume multipliers for the netlist stream
120 // outputs so that output levels of +/- 3 volts will produce the maximum
121 // allowed stream output magnitudes of +/- 32767. Voltages beyond that will be
122 // clipped. This at least produces some distortion if the volume
123 // potentiometers are adjusted above their midpoints.
124 //
125 // Further improving accuracy would require testing signal levels on actual
126 // hardware, with allowances made for variations in components, as well as a
127 // better understanding of the electrical and sonic behavior of the power
128 // amplifiers, speakers, and cabinet. It's questionable whether doing so is
129 // worth the effort.
130 
131 
132 // As I've said, this netlist does not include the final stage of sound
133 // generation, the twin audio power amplifier ICs. Although it is the norm for
134 // MAME analog sound emulation to omit this stage, some discussion of the
135 // power amplifiers is worthwhile in this case. Each is an SGS-ATES
136 // TAA-621-A11 single-channel amplifier, driving one 8-ohm speaker of about 4
137 // or 5 inches.
138 //
139 // (On the Gun Fight schematic, the TAA-621-A11 is also labeled "LM354". The
140 // TAA-621-A11 was introduced in 1970 by the Italian firm SGS. The very
141 // similar LM354 was introduced in 1972 by European Electronic Products.
142 // However, this company seems to have been a mere U.S. importer and
143 // distributor of European components, making the LM354 just a rebadged
144 // TAA-621-A11. The LM354 occasionally comes up in discussions of Gun Fight
145 // audio but seems to have been otherwise short-lived. One problem with its
146 // name is that it can easily be mistaken for a National Semiconductor LMxxx
147 // linear IC, even though it's unrelated to that company. To further confuse
148 // matters, National Semiconductor had already introduced an LM354 of their
149 // own in 1970 which wasn't an audio amplifier at all, but a second-source
150 // version of Texas Instruments' SN7525 sense amplifier for minicomputer
151 // magnetic-core memory systems.)
152 //
153 // As is normal for TAA-621-A11 amps, those in Gun Fight are configured with
154 // some negative feedback to control their voltage gain. The gain is
155 // determined by the ratio of the chip's internal 15-kohm feedback resistor to
156 // the external resistor connected to the feedback terminal, pin 10. In Gun
157 // Fight this external resistor is 1 kohm, so the ratio, and thus the voltage
158 // gain, is 15.
159 //
160 // The TAA-621-A11 is rated at 4 watts at 10% total harmonic distortion (THD)
161 // when supplied with 24-volt power and driving a 16-ohm load. (Although not
162 // explicitly stated, this appears to be an RMS rating rather than a peak
163 // rating.) In Gun Fight's case, the speaker load is only 8 ohms, and the
164 // power supply voltage is a bit lower, about 22 volts (it comes from
165 // rectified 16.5-volt-RMS AC, buffered by a large smoothing capacitor). Both
166 // of these factors lower the power rating somewhat. Also, a power rating at
167 // 10% THD implies clipping is already heavy. The unclipped, clean power
168 // rating in Gun Fight would be lower, probably no more than 2 watts RMS,
169 // giving output around 4 volts RMS or about 5.5 volts in extreme amplitude.
170 // With a power amp voltage gain of 15, this would mean that any input signals
171 // with extreme amplitudes greater than about a third of a volt would be
172 // subject to power amp clipping.
173 //
174 // The power amps also have a few other connections, including ripple bypass
175 // capacitors to suppress ripple from the unregulated power supply, frequency
176 // compensation capacitors to prevent inducing unstable amplifier oscillations
177 // at high frequencies, and some filtering on the output to the speakers.
178 
179 
180 // All of the amplifying transistors in this circuit are NPN transistors of a
181 // particular type, marked as "A-138" on the Gun Fight schematics. This seems
182 // to be the Amperex A-138, a low-power silicon NPN transistor made by Amperex
183 // Electronic Corporation, which was a U.S. division of Philips. This
184 // transistor, being a vendor-specific type long out of production, seems to
185 // have fallen into obscurity. The only source I could find with any data on
186 // it (given in greatly abbreviated form) is _Transistor Discontinued Devices
187 // D.A.T.A.Book, Edition 16_ (1980), by Derivation and Tabulation Associates,
188 // which lists the A-138 on p. 76, line 86.
189 //
190 // This source shows the A-138 to be an ordinary amplifier transistor of
191 // fairly high gain, with a maximum small-signal forward current transfer
192 // ratio (h_fe, AC current gain) of 650. The minimum h_fe is not given, but it
193 // can be estimated using the fact that such transistors are often graded and
194 // designated by gain. The A-137, another Amperex transistor listed on line 85
195 // of the same D.A.T.A.Book page, has the same limits on power, collector
196 // current, and junction voltages, and thus appears to be in the same series,
197 // but it has a maximum h_fe of 415. If the A-137 was the next lower grade of
198 // gain from the A-138, the latter should have a minimum h_fe around 400.
199 // Values for h_FE, the DC forward current transfer ratio (DC current gain),
200 // aren't given for the A-138, but the range would be about the same or a bit
201 // lower, perhaps 350-600, with an average around 450-500.
202 //
203 // The high gain of Gun Fight's A-138 transistors causes a "ka-pow" effect in
204 // its shot sounds; I explain how later. (Andy Wellburn, in a Discord chat on
205 // 2020-06-05, confirmed this effect can be heard in some actual machines. He
206 // measured an h_FE of 238 for one A-138 from a Gun Fight sound board, but he
207 // warned that for old transistors like this, h_FE measurements can vary a
208 // lot, and I'm not surprised that the transistors' gain might be reduced more
209 // than 40 years later. But even a gain of 238 turns out to be high enough to
210 // give the "ka-pow" shot effect.)
211 //
212 // Considering the A-138's high gain and other limits, a decent match for it
213 // here seems to be the BC548C, which is modeled in the netlist library. The
214 // BC548C is the high-gain version of the BC548, a widely used Pro Electron
215 // standard type of general-purpose small-signal transistor in a through-hole
216 // TO-92 package. All A-138 transistors in this netlist are modeled as
217 // BC548Cs.
218 
219 
220 static NETLIST_START(gunfight_schematics)
221 
222 	// **** Sound effect activation switches.
223 
224 	// These switches are triggered by digital logic signals activated by
225 	// the CPU. A high TTL logic level turns the switch on, allowing
226 	// 16-volt power to flow through the switch into the sound effect
227 	// generator's amplifier and storage capacitor, and a low logic level
228 	// turns the switch off, cutting off the power flow. In practice, each
229 	// sound effect is triggered by turning its switch on for about 50 ms
230 	// and then switching it off again.
231 	//
232 	// Each switch is built from two transistors: a "low-side" NPN
233 	// transistor which is switched on when a high TTL output level drives
234 	// the NPN's base high, and a "high-side" PNP transistor which is
235 	// switched on when the now conducting NPN pulls the PNP's base low.
236 	// It is the high-side PNP transistor that actually switches the
237 	// 16-volt power, hence the term "high-side".
238 
239 #if FAST_SWITCHES
240 
241 	// Use abstracted activation switches instead of a detailed circuit
242 	// model of the dual-transistor switches. This gives faster emulation
243 	// while not making any audible difference in the sound produced.
244 
245 	SYS_DSW(SW_LEFT_SHOT,  IN_LS, I_V16.Q, R130.1)
246 	SYS_DSW(SW_RIGHT_SHOT, IN_RS, I_V16.Q, R230.1)
247 	SYS_DSW(SW_LEFT_HIT,   IN_LH, I_V16.Q, R117.1)
248 	SYS_DSW(SW_RIGHT_HIT,  IN_RH, I_V16.Q, R217.1)
249 
250 	// Lower the on-resistance to a more accurate value. The charging
251 	// resistor which follows is only 15 ohms, so the default
252 	// on-resistance of 1 ohm might noticeably affect the result.
253 	PARAM(SW_LEFT_SHOT.RON, 0.1)
254 	PARAM(SW_RIGHT_SHOT.RON, 0.1)
255 	PARAM(SW_LEFT_HIT.RON, 0.1)
256 	PARAM(SW_RIGHT_HIT.RON, 0.1)
257 
258 #else
259 
260 	// Detailed circuit model of the dual-transistor switches.
261 
262 	// "Low-side" NPN transistor switches, driven by TTL logic inputs.
263 
264 	RES(R134, RES_R(470))
265 	RES(R234, RES_R(470))
266 	RES(R121, RES_R(470))
267 	RES(R221, RES_R(470))
268 
269 	NET_C(IN_LS, R134.1)
270 	NET_C(IN_RS, R234.1)
271 	NET_C(IN_LH, R121.1)
272 	NET_C(IN_RH, R221.1)
273 
274 	RES(R133, RES_K(5.1))
275 	RES(R233, RES_K(5.1))
276 	RES(R120, RES_K(5.1))
277 	RES(R220, RES_K(5.1))
278 
279 	QBJT_SW(Q108, "BC548C")
280 	QBJT_SW(Q208, "BC548C")
281 	QBJT_SW(Q105, "BC548C")
282 	QBJT_SW(Q205, "BC548C")
283 
284 	// These all go to TTL ground at pin 7 of 7404 IC H6, rather than the
285 	// ground used for the other sound circuits.
286 	NET_C(GND,
287 		  R133.2, R233.2, R120.2, R220.2,
288 		  Q108.E, Q208.E, Q105.E, Q205.E)
289 
290 	NET_C(R134.2, R133.1, Q108.B)
291 	NET_C(R234.2, R233.1, Q208.B)
292 	NET_C(R121.2, R120.1, Q105.B)
293 	NET_C(R221.2, R220.1, Q205.B)
294 
295 	RES(R131, RES_K(1))
296 	RES(R231, RES_K(1))
297 	RES(R118, RES_K(1))
298 	RES(R218, RES_K(1))
299 
300 	NET_C(Q108.C, R131.1)
301 	NET_C(Q208.C, R231.1)
302 	NET_C(Q105.C, R118.1)
303 	NET_C(Q205.C, R218.1)
304 
305 	// "High-side" PNP transistor switches, driven by "low-side" NPN
306 	// switch outputs. The PNP switch outputs charge the storage
307 	// capacitors that supply power to the sound-effect amplifiers; in
308 	// addition, while they are on they power the amplifiers directly.
309 
310 	RES(R132, RES_K(5.1))
311 	RES(R232, RES_K(5.1))
312 	RES(R119, RES_K(5.1))
313 	RES(R219, RES_K(5.1))
314 
315 	// The actual transistors used here are 2N4125s:
316 	QBJT_SW(Q107, "PNP")
317 	QBJT_SW(Q207, "PNP")
318 	QBJT_SW(Q104, "PNP")
319 	QBJT_SW(Q204, "PNP")
320 
321 	// All connected to 16-volt power.
322 	NET_C(I_V16.Q,
323 		  R132.1, R232.1, R119.1, R219.1,
324 		  Q107.E, Q207.E, Q104.E, Q204.E)
325 
326 	NET_C(R131.2, R132.2, Q107.B)
327 	NET_C(R231.2, R232.2, Q207.B)
328 	NET_C(R118.2, R119.2, Q104.B)
329 	NET_C(R218.2, R219.2, Q204.B)
330 
331 	NET_C(Q107.C, R130.1)
332 	NET_C(Q207.C, R230.1)
333 	NET_C(Q104.C, R117.1)
334 	NET_C(Q204.C, R217.1)
335 
336 	// End of switch description.
337 
338 #endif
339 
340 
341 	// **** Current supply and storage capacitors for sound-effect
342 	// **** amplifiers.
343 
344 	RES(R130, RES_R(15))
345 	RES(R230, RES_R(15))
346 	RES(R117, RES_R(15))
347 	RES(R217, RES_R(15))
348 
349 	CAP(C122, CAP_U(10))
350 	CAP(C222, CAP_U(10))
351 	CAP(C116, CAP_U(20))
352 	CAP(C216, CAP_U(20))
353 	NET_C(GND, C122.2, C222.2, C116.2, C216.2)
354 
355 	NET_C(R130.2, C122.1, R126.1, R124.1)
356 	NET_C(R230.2, C222.1, R226.1, R224.1)
357 	NET_C(R117.2, C116.1, R113.1, R111.1)
358 	NET_C(R217.2, C216.1, R213.1, R211.1)
359 
360 
361 	// **** Shared white-noise generator circuit. This is the basic noise
362 	// **** source which is filtered and amplified by the sound-effect
363 	// **** circuits.
364 
365 	// Gun Fight's noise generator circuit is based on a reverse-biased
366 	// 9.1-volt zener diode (D304, a 1N5239) whose noise current is then
367 	// amplified by an A-138 NPN transistor, producing white noise at
368 	// audio frequencies.
369 	//
370 	// (Strictly speaking, this is not a *pure* white noise generator,
371 	// because the generator's bypass capacitor and biasing resistor, in
372 	// combination with negative feedback from the amplified signal, act
373 	// as a high-pass RC filter, filtering out the lowest noise
374 	// frequencies.)
375 	//
376 	// Figuring out how strong the noise signal should be for this circuit
377 	// is difficult. The noise generator's biasing resistors and
378 	// transistor gain limit the average current through its zener to
379 	// around 2 microamps, but the 1N5239 is normally expected to be used
380 	// with much larger currents, in the range of 250 microamps to 50
381 	// milliamps.
382 	//
383 	// Zeners are most often used for smoothly controlling and limiting
384 	// voltage with minimal fluctuation, like in a power regulator. But a
385 	// zener can only do this smoothly if it passes a large enough
386 	// current. This is especially true for "zeners" of voltages of 9.1
387 	// volts or more, which properly speaking are "avalanche diodes" that
388 	// don't user the actual Zener effect but rather a different effect,
389 	// avalanche breakdown, which is capable of generating far more noise.
390 	// Standard zener specifications include "knee" figures which in
391 	// effect give the minimum expected current, along with the maximum
392 	// "dynamic impedance" at that current: how much the voltage may vary
393 	// if the current changes, or vice versa. For the 1N5239, the knee is
394 	// at 250 microamps, and the maximum dynamic impedance at the knee is
395 	// 600 ohms, so a 1 microamp increase in current at that point would
396 	// raise the voltage drop by up to 0.6 millivolts. Noise values for
397 	// zeners are often not given at all, or if they are (as with
398 	// Motorola's zeners), they are given at the knee current. In short,
399 	// the manufacturer expects the current to be kept above the knee
400 	// value, and if your current is lower, you're on your own.
401 	//
402 	// At very low currents, still within the breakdown region but well
403 	// below the knee current, the zener's dynamic impedance is much
404 	// greater, and more importantly, so is its noise. The conduction of
405 	// current is no longer smooth and regular, but pulsing and episodic,
406 	// as small conducting "microplasmas" within the diode's junction are
407 	// repeatedly triggered and extinguished, like microscopic versions of
408 	// lightning bolts in a thunderstorm.
409 	//
410 	// The netlist library includes a Zener diode model, but this model
411 	// does not simulate the Zener's noise behavior. Instead I generate
412 	// the noise from a noise voltage source in series with the Zener.
413 
414 	// Simple model of a 1N5239 9.1-volt Zener diode. The 1N5239 is
415 	// specified to conduct 20 mA of current at its nominal breakdown
416 	// voltage of 9.1 V. The model produces an exponential I-V curve,
417 	// passing through this point, which has the same general shape as
418 	// that of a normal forward-biased diode. NBV is an exponent scale
419 	// factor; its value here of 1 gives the curve a steep rise and a
420 	// relatively sharp knee. Actual breakdown I-V curves have an even
421 	// steeper rise and sharper knee, too steep and sharp to be
422 	// represented by an exponential, but this model is good enough for
423 	// this emulation, since the diode operates very close to a single
424 	// point on the curve.
425 	ZDIODE(D304, "D(BV=9.1 IBV=0.020 NBV=1)")
426 
427 	// 24 kHz noise clock for the noise source, chosen to retain noise
428 	// frequencies as high as possible for 48 kHz sample rate.
429 	CLOCK(NCLK, 24000)
430 	NET_C(I_V5.Q, NCLK.VCC)
431 	NET_C(GND, NCLK.GND)
432 
433 	// Normally-distributed noise of 2 millivolts RMS voltage.
434 	// This level was chosen to have a strong amplified noise signal that
435 	// won't be clipped by any subsequent stages of amplification before
436 	// the power amps, if the volume potentiometers are not raised beyond
437 	// their approximate midpoints.
438 	SYS_NOISE_MT_N(NOISE, 0.002)
439 
440 	NET_C(NCLK.Q, NOISE.I)
441 
442 	RES(R302, RES_K(6.8))
443 	RES(R303, RES_K(6.8))
444 	CAP(C307, CAP_U(10))
445 	NET_C(C307.2, GND)
446 	QBJT_EB(Q302, "BC548C")
447 	NET_C(Q302.E, GND)
448 
449 	NET_C(I_V16.Q, R302.1)
450 	NET_C(Q302.B, NOISE.1)
451 	NET_C(D304.A, NOISE.2)
452 	NET_C(R303.2, C307.1, D304.K)
453 
454 	// Coupling capacitors from noise generator to sound effect frequency
455 	// filters. (These coupling capacitors, together with the resistances
456 	// beyond them, act as high-pass filters with very low cutoff
457 	// frequencies.)
458 
459 	CAP(C303, CAP_U(0.1))
460 	CAP(C306, CAP_U(0.1))
461 	CAP(C304, CAP_U(0.1))
462 	CAP(C305, CAP_U(0.1))
463 
464 	NET_C(R302.2, Q302.C, R303.1, C303.1, C306.1, C304.1, C305.1)
465 
466 
467 	// **** Sound effect frequency filters.
468 
469 	// Each sound effect has a pair of passive low-pass RC filters with
470 	// cutoff frequencies determined by their component values. The
471 	// different capacitor values produce each sound effect's distinct
472 	// pitch.
473 
474 	RES(R129, RES_K(20))
475 	RES(R229, RES_K(20))
476 	RES(R116, RES_K(20))
477 	RES(R216, RES_K(20))
478 
479 	NET_C(C303.2, R129.1)
480 	NET_C(C306.2, R229.1)
481 	NET_C(C304.2, R116.1)
482 	NET_C(C305.2, R216.1)
483 
484 	CAP(C121, CAP_U(0.015))
485 	CAP(C221, CAP_U(0.015))
486 	CAP(C115, CAP_U(0.033))
487 	CAP(C215, CAP_U(0.033))
488 	NET_C(C121.2, C221.2, C115.2, C215.2, GND)
489 
490 	RES(R128, RES_K(30))
491 	RES(R228, RES_K(30))
492 	RES(R115, RES_K(30))
493 	RES(R215, RES_K(30))
494 
495 	NET_C(R129.2, C121.1, R128.1)
496 	NET_C(R229.2, C221.1, R228.1)
497 	NET_C(R116.2, C115.1, R115.1)
498 	NET_C(R216.2, C215.1, R215.1)
499 
500 	CAP(C120, CAP_U(0.01))
501 	CAP(C220, CAP_U(0.015))
502 	CAP(C114, CAP_U(0.1))
503 	CAP(C214, CAP_U(0.047))
504 	NET_C(C120.2, C220.2, C114.2, C214.2, GND)
505 
506 
507 	// **** Sound effect amplifier circuits.
508 
509 	// Each sound-effect amplifier is a single NPN transistor wired as a
510 	// common-emitter amplifier. The amplifiers for "hit" sounds also have
511 	// a bypass capacitor at the emitter, while those for "shot" sounds
512 	// have no bypass capacitor and a much lower emitter resistance. The
513 	// attack and decay of the sound effects is handled by controlling the
514 	// current supply to each amplifier, which is done by the switching
515 	// circuits and supply capacitors described above.
516 
517 	// More explanation is needed for the "shot" sounds. Apart from their
518 	// higher frequency and faster decay, the "ka-pow" effect in their
519 	// initial attack further distinguishes them from the "hit" sounds.
520 	// This effect comes from the high current gain (around 450-500) of
521 	// the amplifier's A-138 transistor together with the low emitter
522 	// resistance. When the current supply for the sound is switched on,
523 	// the collector voltage at first spikes upward as the supply
524 	// capacitor is charged. But the transistor's base voltage and base
525 	// current also rise, which "turns on" the transistor, and as its
526 	// collector current increases through its biasing resistor, the
527 	// collector voltage plummets. For the "shot" sound transistors,
528 	// because of their high current gain and low emitter resistance, the
529 	// collector current grows so much that the collector voltage is
530 	// pulled below the base voltage, pushing the transistor into
531 	// saturation. This persists for as long as the current supply switch
532 	// remains on; the collector voltage stays low with little variation.
533 	// In this state the amplifier's input noise signal is being clipped
534 	// rather than amplified.
535 
536 	// The result is that the sound effect's initial voltage spike is
537 	// followed by a relatively prolonged low with almost no noise. As
538 	// this signal passes through the output coupling capacitor, the
539 	// intervening filter and potentiometer, and then the second
540 	// amplification stage, it becomes a series of strong oscillations,
541 	// followed by a momentary silence which lasts as long as the sound's
542 	// switch is held on: around 50 milliseconds.
543 
544 	// Finally the sound switch is turned off, and the amplifier's supply
545 	// voltage and current begin to drop as the supply capacitor
546 	// discharges. The base current and collector current drop also, and
547 	// the collector voltage begins to rise, eventually rising above the
548 	// base voltage again. The transistor leaves saturation and returns to
549 	// forward active mode. Now the noise signal is not being clipped but
550 	// gets properly amplified on the collector output. So the momentary
551 	// silence is followed by a sudden burst of noise, which then dies
552 	// away as the supply capacitor is drained.
553 
554 	// The result is the shot's distinct "ka-pow" sound: an initial
555 	// punctuating crack, a very brief silence, and a sudden noise burst
556 	// that quickly fades.
557 
558 	// The "hit" sounds don't have this effect, despite using the same
559 	// high-gain transistors, because their transistor amplifiers have a
560 	// bypass capacitor and a much larger emitter resistance, 1 Kohm
561 	// versus 100 ohms. That higher resistance keeps the collector current
562 	// low enough that the collector voltage never drops below the base
563 	// voltage, so the transistor never saturates, while the bypass
564 	// capacitor allows the amplifier's AC gain to remain very high.
565 
566 	RES(R126, RES_K(330))
567 	RES(R226, RES_K(330))
568 	RES(R113, RES_K(330))
569 	RES(R213, RES_K(330))
570 
571 	RES(R127, RES_K(30))
572 	RES(R227, RES_K(30))
573 	RES(R114, RES_K(30))
574 	RES(R214, RES_K(30))
575 	NET_C(R127.2, R227.2, R114.2, R214.2, GND)
576 
577 	RES(R124, RES_K(5.1))
578 	RES(R224, RES_K(5.1))
579 	RES(R111, RES_K(5.1))
580 	RES(R211, RES_K(5.1))
581 
582 	RES(R125, RES_R(100))
583 	RES(R225, RES_R(100))
584 	RES(R112, RES_K(1))
585 	RES(R212, RES_K(1))
586 	NET_C(R125.2, R225.2, R112.2, R212.2, GND)
587 
588 	CAP(C113, CAP_U(50))
589 	CAP(C213, CAP_U(50))
590 	NET_C(C113.2, C213.2, GND)
591 
592 	QBJT_EB(Q106, "BC548C")
593 	QBJT_EB(Q206, "BC548C")
594 	QBJT_EB(Q103, "BC548C")
595 	QBJT_EB(Q203, "BC548C")
596 
597 	NET_C(R128.2, C120.1, R126.2, R127.1, Q106.B)
598 	NET_C(R228.2, C220.1, R226.2, R227.1, Q206.B)
599 	NET_C(R115.2, C114.1, R113.2, R114.1, Q103.B)
600 	NET_C(R215.2, C214.1, R213.2, R214.1, Q203.B)
601 
602 	NET_C(R125.1, Q106.E)
603 	NET_C(R225.1, Q206.E)
604 	NET_C(R112.1, C113.1, Q103.E)
605 	NET_C(R212.1, C213.1, Q203.E)
606 
607 
608 	// **** Coupling capacitors, high-pass (pulse-differentiator) filters,
609 	// **** and volume potentiometers for sound effect amplifier outputs.
610 
611 	// These circuits act as high-pass filters on the sound effect
612 	// generator outputs, with very low cutoff frequencies. Because the
613 	// cutoff frequency is so low, one of the main effects of the filter
614 	// is to remove any flat areas from the initial turn-on pulse of the
615 	// sound effect generator amplifier. The filter effectively
616 	// differentiates the pulse, producing output voltage proportional to
617 	// the steepness of its slope. This replaces the single wide pulse of
618 	// the initial attack with a sequence of sharp spike pulses.
619 
620 	CAP(C119, CAP_U(0.047))
621 	CAP(C219, CAP_U(0.047))
622 	CAP(C112, CAP_U(0.1))
623 	CAP(C212, CAP_U(0.1))
624 
625 	NET_C(R124.2, Q106.C, C119.1)
626 	NET_C(R224.2, Q206.C, C219.1)
627 	NET_C(R111.2, Q103.C, C112.1)
628 	NET_C(R211.2, Q203.C, C212.1)
629 
630 	CAP(C118, CAP_U(0.022))
631 	CAP(C218, CAP_U(0.022))
632 	CAP(C111, CAP_U(0.033))
633 	CAP(C211, CAP_U(0.033))
634 	NET_C(C118.2, C218.2, C111.2, C211.2, GND)
635 
636 	// There are four sound-effect volume pots, for shot and hit sounds on
637 	// left and right.
638 
639 	POT(R123, RES_K(50))
640 	POT(R223, RES_K(50))
641 	POT(R110, RES_K(50))
642 	POT(R210, RES_K(50))
643 	NET_C(R123.3, R223.3, R110.3, R210.3, GND)
644 
645 	// Reverse the sense of pot adjustments so that larger values result
646 	// in greater volume.
647 	PARAM(R123.REVERSE, 1)
648 	PARAM(R223.REVERSE, 1)
649 	PARAM(R110.REVERSE, 1)
650 	PARAM(R210.REVERSE, 1)
651 
652 	NET_C(C119.2, C118.1, R123.1)
653 	NET_C(C219.2, C218.1, R223.1)
654 	NET_C(C112.2, C111.1, R110.1)
655 	NET_C(C212.2, C211.1, R210.1)
656 
657 
658 	// **** Mixing of shot and hit sounds for each side.
659 
660 	RES(R122, RES_K(30))
661 	RES(R222, RES_K(30))
662 	RES(R109, RES_K(30))
663 	RES(R209, RES_K(30))
664 
665 	NET_C(R123.2, R122.2)
666 	NET_C(R223.2, R222.2)
667 	NET_C(R110.2, R109.2)
668 	NET_C(R210.2, R209.2)
669 
670 	CAP(C117, CAP_U(0.047))
671 	CAP(C217, CAP_U(0.047))
672 	CAP(C110, CAP_U(0.1))
673 	CAP(C210, CAP_U(0.1))
674 
675 	NET_C(R122.1, C117.2)
676 	NET_C(R222.1, C217.2)
677 	NET_C(R109.1, C110.2)
678 	NET_C(R209.1, C210.2)
679 
680 
681 	// **** Second-stage amplifier circuits, which amplify each side's
682 	// **** mixed shot and hit sounds.
683 
684 	// These amplifiers are similar to those for the "hit" sound effects,
685 	// each being a single A-138 NPN transistor wired in common-emitter
686 	// configuration, with a 1-Kohm resistance and a bypass capacitor at
687 	// the emitter. They have no need for an attack-decay envelope,
688 	// however, and so get their current directly from the 16-volt power
689 	// supply.
690 
691 	RES(R107, RES_K(150))
692 	RES(R207, RES_K(150))
693 
694 	RES(R105, RES_K(30))
695 	RES(R205, RES_K(30))
696 	NET_C(R105.2, R205.2, GND)
697 
698 	RES(R108, RES_K(5.1))
699 	RES(R208, RES_K(5.1))
700 
701 	RES(R106, RES_K(1))
702 	RES(R206, RES_K(1))
703 	NET_C(R106.2, R206.2, GND)
704 
705 	CAP(C109, CAP_U(50))
706 	CAP(C209, CAP_U(50))
707 	NET_C(C109.2, C209.2, GND)
708 
709 	NET_C(R107.1, R207.1, R108.1, R208.1, I_V16.Q)
710 
711 	QBJT_EB(Q102, "BC548C")
712 	QBJT_EB(Q202, "BC548C")
713 
714 	NET_C(C110.1, C117.1, R107.2, R105.1, Q102.B)
715 	NET_C(C210.1, C217.1, R207.2, R205.1, Q202.B)
716 
717 	NET_C(R106.1, C109.1, Q102.E)
718 	NET_C(R206.1, C209.1, Q202.E)
719 
720 
721 	// **** Coupling capacitors, bandpass filters, and volume
722 	// **** potentiometers for second-stage amplifier outputs.
723 
724 	CAP(C108, CAP_U(0.047))
725 	CAP(C208, CAP_U(0.047))
726 
727 	NET_C(R108.2, Q102.C, C108.1)
728 	NET_C(R208.2, Q202.C, C208.1)
729 
730 	RES(R104, RES_K(30))
731 	RES(R204, RES_K(30))
732 
733 	NET_C(C108.2, R104.1)
734 	NET_C(C208.2, R204.1)
735 
736 	CAP(C107, CAP_U(0.001))
737 	CAP(C207, CAP_U(0.001))
738 	NET_C(C107.2, C207.2, GND)
739 
740 	// There are two master volume pots, for left and right.
741 
742 	POT(R103, RES_K(47))
743 	POT(R203, RES_K(47))
744 	NET_C(R103.3, R203.3, GND)
745 
746 	// Reverse the sense of pot adjustments so that larger values result
747 	// in greater volume.
748 	PARAM(R103.REVERSE, 1)
749 	PARAM(R203.REVERSE, 1)
750 
751 	NET_C(R104.2, C107.1, R103.1)
752 	NET_C(R204.2, C207.1, R203.1)
753 
754 	// The potentiometer outputs are used here as the left and right audio
755 	// outputs. In the real circuit they drive the signal inputs of the
756 	// audio power amplifier ICs for the left and right speakers.
757 
758 	ALIAS(OUT_L, R103.2)
759 	ALIAS(OUT_R, R203.2)
760 
761 	// The real outputs are somewhat constrained in that they drive the
762 	// bases of the input transistors within the power amplifiers. If they
763 	// go too low in voltage, there seems to be a peculiar effect on the
764 	// speaker output waveforms, although I'm not sure whether this is a
765 	// real effect or an artifact of the LTspice simulation I constructed.
766 	// Nor am I sure whether it matters in practice. In any case, it's not
767 	// modeled here.
768 
769 NETLIST_END()
770 
771 
772 NETLIST_START(gunfight)
773 
774 	SOLVER(Solver, 48000)
775 	PARAM(Solver.SORT_TYPE, "ASCENDING")
776 	// For this netlist, ASCENDING turns out to be slightly faster than
777 	// the default sort type of PREFER_IDENTITY_TOP_LEFT, but the
778 	// difference when using static solvers is very small.
779 
780 	LOCAL_SOURCE(gunfight_schematics)
781 
782 	INCLUDE(gunfight_schematics)
783 
784 	// The amplifying transistors all get 16-volt power. The raw AC power
785 	// input from the main power supply to the game logic board is 16.5
786 	// volts, but this is rectified and regulated to about 16 volts via
787 	// TIP-31 power transistor Q301 and BZX61-C16 16-volt Zener diode
788 	// D304.
789 	ANALOG_INPUT(I_V16, 16)  // 16-volt power for sound amplifiers
790 	ANALOG_INPUT(I_V5, 5)  // 5-volt power for logic input devices
791 
792 	LOGIC_INPUT(I_LEFT_SHOT,  0, "74XX")
793 	LOGIC_INPUT(I_RIGHT_SHOT, 0, "74XX")
794 	LOGIC_INPUT(I_LEFT_HIT,   0, "74XX")
795 	LOGIC_INPUT(I_RIGHT_HIT,  0, "74XX")
796 
797 	// Power and ground connections for logic input devices:
798 	NET_C(I_V5.Q,
799 		  I_LEFT_SHOT.VCC, I_RIGHT_SHOT.VCC,
800 		  I_LEFT_HIT.VCC, I_RIGHT_HIT.VCC)
801 	NET_C(GND,
802 		  I_LEFT_SHOT.GND, I_RIGHT_SHOT.GND,
803 		  I_LEFT_HIT.GND, I_RIGHT_HIT.GND)
804 
805 	ALIAS(IN_LS, I_LEFT_SHOT.Q)
806 	ALIAS(IN_RS, I_RIGHT_SHOT.Q)
807 	ALIAS(IN_LH, I_LEFT_HIT.Q)
808 	ALIAS(IN_RH, I_RIGHT_HIT.Q)
809 
810 #if USE_FRONTIERS
811 	// These frontiers keep the mostly independant halves of the circuit
812 	// (left channel and right channel) from affecting each other and the
813 	// noise generator, which speeds up processing substantially while
814 	// making no audible change in the output. These seem to be the only
815 	// frontiers which improve performance; I haven't been able to find
816 	// any additional beneficial ones from examining the circuit and
817 	// experimenting.
818 	OPTIMIZE_FRONTIER(C303.1, RES_M(1), 50)
819 	OPTIMIZE_FRONTIER(C306.1, RES_M(1), 50)
820 	OPTIMIZE_FRONTIER(C304.1, RES_M(1), 50)
821 	OPTIMIZE_FRONTIER(C305.1, RES_M(1), 50)
822 #endif
823 
824 NETLIST_END()
825