I'm working on the envelope generator at the moment.
There are basically 4 parameters of interest:
AR - attack rate
DR - decay rate
SL - sustain level
RR - release rate.
Setting EGT to 1 will cause the envelope to pause when the decay reaches the sustain level, and it remains at that level until the key is released (KON = 0) then it drops to zero volume (-96dB) following the release rate. If EGT is 0, then it goes directly from the decay to release as soon as it reaches the sustain level.
Also involved is the KRS key rate scaling, which means that higher pitched notes (as defined either by the most significant bits of the F-number, or by the block number) have faster rates.
The OPL4 application guide gives quite a lot of detailed information about how these parameters affect the real world values of the envelope, but you need to bear in mind that the sample rate of the OPL4 differs from the OPL3 and from my investigations so far, it looks as though the OPL4 figures are correct in terms of number of samples, rather than milliseconds, so with a faster sample rate, you actually get a shorter envelope on the OPL3 than on the OPL4 (around 10% shorter)
Decay and release should be straightforward because in these stages, the envelope is linear (in the dB domain) and so a simple count up until the envelopes reaches 8192 (-96dB) would suffice. The documentation says that the envelope resolution is 0.1875 dB which I think would therefore be a value of 16 per increment.
Attack rate however has me stumped for the moment. Although the little sketch in the OPL3 datasheet shows that the attack phase is linear, this is not true, the OPL2 and OPL4 datasheets both show an exponential curve for the attack, and this is borne out by the experimental evidence. There are a maximum of 32 steps in the attack ( fewer if the attack rate is very fast ). An attack rate value of 52 (AR = 13) has 32 samples in the attack phase, an attack rate value of 48 (AR = 12) has 64 samples in the attack phase, but pairs of samples show the same envelope attenuation. I am however struggling to find a plausible algorithm to match the experimental results.