MEGA65 / mega65-core

MEGA65 FPGA core
Other
240 stars 85 forks source link

SID 8580 won't play certain notes on first invocation #631

Open bubbob42 opened 1 year ago

bubbob42 commented 1 year ago

Test Environment (required)

Describe the bug When SID8580 is enabled, a noise wave won't be played on first attempt.

To Reproduce

  1. Set SID to 8580 (6581 is not affected)
  2. Switch on the machine (cold boot required)
  3. enter: SOUND3,5000,10,2,0,0,3

Expected behavior A noise signal should be played on channel 3. It will only play when repeating the command. This behaviour is present for all SID channels.

johnwayner commented 1 year ago

This issue only effects the NOISE waveform. The issue is resolved once a different waveform is selected and gated on (or Basic's SOUND interrupt shut's down a voice by writing $08 (enabling TEST) to its control register).

@gardners The LFSR is stalled out initially due to it relying on wave_out (which will be all zeroes) for part of its value. Most importantly wave_out[4] will be zero to start and that needs to be 1 to prevent the stall. Basic sets the TEST bit of the CONTROL register which unstalls the LFSR:

(lfsr_noise[17] ^ lfsr_noise[22] ^ reset ^ 'test_ctrl)

Enabling another waveform unstalls the LFSR as well by feeding non-zero values into wave_out.

There is a more traditional implementation of an LFSR commented out below the current one that uses wave_out that seems to work.

I assume there was a reason for the more complicated one. Perhaps it simulates the actual 8580? I have no idea.

Anyway, it can be fixed by reverting back to the commented code or otherwise ensuring the LFSR doesn't ever equal all zeroes.

I can provide a pull request to revert to the commented code, but I don't want to do that without understand why it is the way it is.

lydon42 commented 10 hours ago

@bubbob42 Is this fixed?

With a recent development core and SID 8580 the SOUND command plays the sound every time for me.