A new kind of hard-restart

This article explains how to perform a stable hard-restart; i.e. it not only zeros the envelope and captures the envelope rate counter, but it sets RC to a known value.

Back in 2011 I wanted to get the SID envelope generator into a known state to the cycle level, so I could then take some measurements of envelope behaviour. At the time, the best routine I could manage took well over three frames, as I had to twice recapture a potential rate-counter escape. The first frame and a half was spent on an ordinary hard-restart (OHR), then following some limit manipulations to get the rate counter into one of a number of states that were all equal modulo nine, a second OHR waas required to fold the potential values back into a known state.

Then in early April 2015, lft had a cunning plan. The first step was still to perform an OHR, as per my original. His innovation was to use the 'safe' transition from a slow attack to a fast decay to perform the recapture; if this is all done up around env=$fe, it can be performed in just a couple of hundred cycles

The envelope overflow bug (where an attack triggered when env=$ff causes env to wrap back to $00) can then be used to bring the envelope back down.

The CPU intensive part of the process takes a mere ten raster lines.

The core implementation is included below; details of how the magic part works to follow in a future update.