http://bootgod.dyndns.org:7777/imagegen ... &width=600 < Gimmick! cart.
The only difference between Sunsoft 5B and FME-7 (which is used by Dynamite Batman) is the full AY chip is found in the Sunsoft 5B.
Quoting Disch:
Code:
Sound:
---------------------------
Sunsoft 5B appears to be identical to the AY 3-8910 (or a similar chip -- possibly a different AY 3-891x or a
YM2149). The only game to use the sound, Gimmick!, does not use the envelope or noise functionality that
exists on the AY 3-891x, however, through testing it has been shown that such functionality does in fact
exist.
The sound info below is a simplified version of the behavior. Envelope and Noise are not covered (aside from
the noise shift formula), and registers relating to those areas are not mentioned. However the information
below is enough to satisfy Gimmick! If you want further information and full register descriptions, consult
an AY 3-8910 datasheet or doc.
Sunsoft 5B has 3 Square channels (no configurable duty cycle -- always play at 50% duty). Each operate
similarly to the native NES sound channels. They output sound at 1 octave lower than what may be expected,
though (see below).
Sound Regs:
---------------------------
$C000: [.... AAAA] Address for use with $E000
$E000: [DDDD DDDD] Data port:
R:0 -> [FFFF FFFF] Chan 0, Low 8 bits of Freq
R:1 -> [.... FFFF] Chan 0, High 4 bits of Freq
R:2 -> [FFFF FFFF] Chan 1, Low 8 bits of Freq
R:3 -> [.... FFFF] Chan 1, High 4 bits of Freq
R:4 -> [FFFF FFFF] Chan 2, Low 8 bits of Freq
R:5 -> [.... FFFF] Chan 2, High 4 bits of Freq
R:7 -> [.... .CBA] Channel disable flags (0=enabled, 1=disabled)
C = Disable Chan 2
B = Disable Chan 1
A = Disable Chan 0
R:8 -> [.... VVVV] Chan 0, Volume
R:9 -> [.... VVVV] Chan 1, Volume
R:A -> [.... VVVV] Chan 2, Volume
Operation:
---------------------------
For tone generation, a counter is counted up each CPU cycle. When it reaches the given 'F' value, it resets
to zero, and another step through the duty cycle is taken. These squares' duty cycles are fixed at 50%
(AY 3-8910 docs say 8/16, but see below).
Emulating in this fashion, with a 16-step duty, these channels play 1 octave higher than they should!
Therefore, either channels are only clocked every other CPU cycle... or (what I find to be easiest to
emulate) the duty is actually 16/32 instead of 8/16, or something else is going on. I do not know which is
actually happening.
The generated tone in Hz can be calculated with the following:
CPU_CLOCK
Hz = -------------
(F+1) * 32
When the duty cycle outputs high, 'V' is output, otherwise 0 is output. When the channel is disabled (see
R:7), 0 is forced as output for the channel.
Non-linear volume:
---------------------------
Output volume is non-linear... increasing in steps of 3 dB.
Output can be calculated with the following pseudo-code:
vol = 1.0;
for(i = 0; i < 0x10; ++i)
{
sunsoft_out[i] = vol * base;
vol *= step;
}
Where 'base' can be adjusted to match your native NES sound channel levels, and 'step' is "10^(dB/20)".
For 3 dB, 'step' would be ~1.4125
Noise Formula:
---------------------------
>> >>
+-->[nnnn nnnn nnnn nnnn]->output
| | |
| | ++
| | |
| v v
+-------------------XOR
- 16-bit right-shift reg
- bits 0,3 (before shift) XOR to create new input bit
- bit 0 is shifted to output
- initial feed is 1
http://www.ym2149.com/ay8910.pdf < AY datasheet.
So from what we can determine from Disch's notes is the envelope and noise generator registers are missing from most emulators because Gimmick! does not use them.
If we were to program for the Sunsoft 5B, we would set the AY register with $C000, let's say #$06 for noise (or #$0B, #$0C, or #$0D for envelope), and then write data to those registers through $E000.
The AY is capable of interchanging pulse to noise for all three of its channels with its mixer register and the envelope register is capable of producing an additional "buzzer" channel by quick modulation; making the AY generally a 3 +1 virtual channel sound chip.
For chip music, it2nsf (
http://mukunda.com/projects.html) currently supports limited Sunsoft 5B support; meaning only the three channels as pulses.
If the full AY were emulated on PowerPak, Nintendulator, Nestopia, player plugins, etc... there would be more chances for original 2a0x+AY chip music.
We're already partially there... ;D