** Bug Description **
Attack followed by release before the next rising edge of do_count_5 should cause ADSR to wrap from 00 to FF.
The currently implemented comparisons versus envelope of 0x00 are not completely correct because there is a window where real hardware can underflow below zero to the value of FF (and counting contunues downward) during the st_releese phase of cur_state.
A proposed fix is attached, but it's only one way of implementing such a fix.
To Reproduce
Run the following in PAL mode: scumball_env3.prg.gz
I've added a hex indication of ENV3 at the top left of the psid64 screen to provide visual feedback in addition to SID's. Pressing '1' will start playing Tim Follin's Scumball from the beginning, so this is easy to test and verify by banging on the '1' key over and over.
Expected behavior
On original hardware and other SID implementations, at an initial start state of ENV=0, ENV will bypass over Attack and will count down from FF toward zero when the control register is presented with a rapid GATE=1 .. GATE=0 sequence of updates and the GATE=0 is encountered before the next do_count_5=1 cycle. The ultimate1541 VHDL's ENV is frozen at zero, so voice 3 of Scumball on the 1541ultimate SID (presumably also C64U) is silent during the song's intro sound effect when it should add a whooshing noise to what would otherwise be a descending, whistling sound.
There are two, main contributing factors:
- Attack vs Release state are to be updated at 1MHz clock granularity, not at a larger do_count_5 interval.
- Underflow on release is allowed to occur if ENV=0 during attack and is immediately followed by release before the next do_count_5 would increment ENV to 1. In effect, the updating side effects of the attack phase are completely bypassed as there is a rapid state machine switch to Release, so release can underflow to FF.
Screenshots
The following is the output from siddump, but it is missing information due to multiple register writes to CR3 during the same frame, so please also consult with the second screenshot that lists all stores encountered by SID:

Now, the screen shot with siddump instrumented to show all of voice 3's stores:

Applies to (please complete the following information):
Ultimate 1541 cart as determined from here: https://github.com/GideonZ/1541ultimate/blob/master/fpga/sid6581/vhdl_source/adsr_multi.vhd
Presumably also affects C64U. I don't have mine handy at the moment, but the test is easy to perform as it's completely obvious in a very reliable manner on song init.
Additional context
VHDL changes that work for me are here. These follow the reSID implementations concept of an external hold_zero as an underflow interlock rather than an explicit comparison in relevant ADSR states to zero.
adsr_multi.vhd.gz
Note that if there are missing sound effects in other Follin Brothers tunes using the Stephen Ruddy driver, this issue may very well be the cause.
** Bug Description **
Attack followed by release before the next rising edge of do_count_5 should cause ADSR to wrap from 00 to FF.
The currently implemented comparisons versus envelope of 0x00 are not completely correct because there is a window where real hardware can underflow below zero to the value of FF (and counting contunues downward) during the st_releese phase of cur_state.
A proposed fix is attached, but it's only one way of implementing such a fix.
To Reproduce
Run the following in PAL mode: scumball_env3.prg.gz
I've added a hex indication of ENV3 at the top left of the psid64 screen to provide visual feedback in addition to SID's. Pressing '1' will start playing Tim Follin's Scumball from the beginning, so this is easy to test and verify by banging on the '1' key over and over.
Expected behavior
On original hardware and other SID implementations, at an initial start state of ENV=0, ENV will bypass over Attack and will count down from FF toward zero when the control register is presented with a rapid GATE=1 .. GATE=0 sequence of updates and the GATE=0 is encountered before the next do_count_5=1 cycle. The ultimate1541 VHDL's ENV is frozen at zero, so voice 3 of Scumball on the 1541ultimate SID (presumably also C64U) is silent during the song's intro sound effect when it should add a whooshing noise to what would otherwise be a descending, whistling sound.
There are two, main contributing factors:
Screenshots

The following is the output from siddump, but it is missing information due to multiple register writes to CR3 during the same frame, so please also consult with the second screenshot that lists all stores encountered by SID:
Now, the screen shot with siddump instrumented to show all of voice 3's stores:

Applies to (please complete the following information):
Ultimate 1541 cart as determined from here: https://github.com/GideonZ/1541ultimate/blob/master/fpga/sid6581/vhdl_source/adsr_multi.vhd
Presumably also affects C64U. I don't have mine handy at the moment, but the test is easy to perform as it's completely obvious in a very reliable manner on song init.
Additional context
VHDL changes that work for me are here. These follow the reSID implementations concept of an external hold_zero as an underflow interlock rather than an explicit comparison in relevant ADSR states to zero.
adsr_multi.vhd.gz
Note that if there are missing sound effects in other Follin Brothers tunes using the Stephen Ruddy driver, this issue may very well be the cause.