|
Disch, after a lot of trouble I finally found a few bugs in my triangle code and after having corrected them, I realized that you were right
all the time - don't change the linear counter mode on $4008 writes. Thanx. I've used SMB 1 for testing, since I'm very familiar with its music (aren't we all?). After a few changes, it now sounds great. I didn't find
any weird sounds in Mega Man, though.
>- When a write to $400B takes place... the counter goes into load mode (and anything in the load register >gets loaded into the counter). If $4008.7 was 0, it signals the counter to >enter count mode on the next >linear counter clock. This is what the NESSOUND doc specifies... >however... in that next linear clock, >you only go to count mode if $4008.7 is still 0.
This fixed a bug on the lava levels (SMB 1) where some notes were shortened.
>- Changing the mode upon writes to $4008 like the doc specifies seems to cause more problems than it solves. >When a write to $4008 takes place, don't touch the mode of the linear counter.
This fixed a bug in the flag sequence (SMB 1) where some notes were shortened.
>- if the channel is disabled via $4015, the linear counter shouldn't be loaded with the load >value even if in load mode. This doesn't seem right, but it seems to work o_O The channel is always silent when $4015.2 = 1 (Since length counter = 0). The value of the linear counter shouldn't matter. In which game did
you find problems with this?
Below is a brief explanation of my triangle code, with more C-like syntax :) Perhaps it will be useful to anyone who has followed this thread, or perhaps someone will find a bug and tell me about it.
$4008 write: LinearCounterLoad = data & 0x7F if (LinearCounterMode == LOAD) LinearCounter = LinearCounterLoad
$400A write: TimerLoad.low = data Timer = TimerLoad
$400B write: LengthCounter = LengthCounterTable[data >> 3] TimerLoad.high = data & 7 Timer = TimerLoad LinearCounterMode = LOAD LinearCounter = LinearCounterLoad ChangeMode = ($4008.7 == 0)
LinearClock: if (LinearCounterMode == COUNT && LinearCounter) LinearCounter--
if (ChangeMode) ChangeMode = 0 if ($4008.7 = 0) LinearCounterMode = COUNT
LengthClock: if (LengthCounter && ($4008.7 = 0) && ($4015.2 = 0)) LengthCounter--
TriangleStepGenerator: Timer = TimerLoad if (($4015.2 = 0) && LinearCounter && LengthCounter) /* channel enabled? */ if (Output == 0xF) step-- if (Output == 0x0) step++ output += step
Thanx for your help. /Hugin
|