Skip to content

Analog Simulation

Article by MiSTer core developer Jegor van Opdorp (SupraDeus/jopdorp)

Many old computers have analog parts, for example audio boards that have partly analog synthesis and old desktop computers with tape input.

Currently there is no convenient way to directly simulate electronic circuits, for example based in their spice netlists, in real time on the MiSTer. So to implement these type of circuits in fpga, you will have to come up with some kind of simulation of the behavior of the electronic circuit.

The Arcade-Battlezone core is an example of a core with analog sound synthesis.

A way to approach the problem:

  1. Find youtube video's of people playing the actual game, to get some idea of the sounds it has.
  2. Play the game in an emulator, paying extra attention to sounds that do not sound the same in the emulator as in the video of the actual machine.
  3. Identify the digital and analog parts of the schematic.

    • One thing to keep in mind is that the digital parts run at the system clock speed, or sometimes a separate clock source that is closer to the audible frequency spectrum, in Arcade Battlezone there is a 12khz input to a digital noise circuit, of which the output goes into and analog integrator circuit. This creates an axplosion sound. The implementation of this sound is listed at "inverting amplifier" below. The analog parts will be outputting at audio sample rate, i.e. 48khz
  4. Implement all the digital parts, common digital components in sound systems are:

    • linear feedback shift register:
      linear feedback shift register
      An implementation of a similar circuit in arcade battlezone can be found here:

    • flipflops, like the jk flipflop, implemented here:

  5. Identify analog circuits with isolated behavior, i.e. 1 input, 1 output. These can be individually implemented and tested.

  6. Identify common, easily recognisable and implementable parts, such as:

  7. low pass filters
    low pass
    This can be implemented using an iir low pass filter, you can find the parameters using this spreadsheet

    Some implementations of iir filters:

    A simpler type:

  8. high pass filters

    high pass filter

  9. inverting amplifiers

    inverting amplifier

    This is essentially a sign inversion of the sample, followed by a (fixed sign) multiplication.

  10. non inverting amplifiers

    non inverting amplifier

    This is just a (fixed sign) multiplication of the sample

  11. differential amplifiers

    differential amplifier

  12. inverting integrators

    inverting integrator

    or

    inverting integrator 2

    This is essentially a sign inversion of the sample, followed by a multiplication, with the result being stored in a reg.

    The multiplication is run repeatedly, each audio clock cycle, Resulting in a "release/decay" type amplifier envelope.

    An example of an implementation of this can be found here

  13. other common opamp circuits

  14. additive mixers

    additive mixer

    An additive mixer just adds up/averages two signals. If the resistance is higher for one signal than the other, this will result in a volume difference between them.

  15. All the parts that are going to need more attention, make note of what these parts are an try to guess what they are for. Differentiators and integrators combined with 555 timers and noise inputs can be tricky.

  16. Implement the mixers
  17. Implement the filters
  18. Implement the difficult parts of the circuit:
  19. Implement the circuit in a simlator.
  20. Figure out what input goes into the circuit when the game gets played.
  21. Run the simulation with the correct input and save the output as a wav file
  22. Analyse the output by looking at it in a wave editor like audacity and listening to it.
  23. Is the input always the same? (not noise as input) Does the circuit always response in the same way? (not generating noise)
    1. Sample the output of the simulation
    2. Convert the sample into an array literal and trigger it as needed, usually the sample will just be triggered by a pulse in this case.
  24. If the analog circuit has noise as input or has variable inputs such as a number controlled frequency or speed you will need to:
    1. make a mathematical model of the analog circuit.
    2. implement the model in an easy to use programming language such as python
    3. compare the output of the mathematical model with the output of the circuit simulation using the same inputs. They have to be close, but not identical, but they should be identical to the hearing.
    4. rework your mathematical model to not have to use any dividers in real time, this is done in two steps
      1. by algebra
      2. by precalculating any left-over divisions into division lookup-tables
    5. you can also create other kind of lookup tables, for example a sine wave.
    6. implement the mathematical model in HDL
    7. verify the outputs of the HDL with a tesbench
    8. hook up the chip to the rest of our core!

Developer journeys of analog circuit implementations

MiSTer - Head On

Informational resources

Code examples

Tooling