Subject: Technical question on noise generator

From: "Michael Zapf" <[email-masked]>
Date: Sat, 30 Jan 2010 20:21:54 -0000

I stumbled upon this issue with the noise generator in MESS: 

As you probably know the noise generator has preset rates and one freely definable rate. This is what we know from BASIC:

CALL SOUND(1000,-4,0)

Did you ever try the following:
CALL SOUND(1000,44733,30,44733,30,110,30,-4,0)

and then change the value 110 to other values? What you notice here is exactly what is explained in the Editor/Assembler manual, so just add the fact that you can use it in BASIC as well. Actually, I admit I did not try until today. Also try with -8 for white noise.

However, MESS fails to produce the real sound with the short line. Only the verbose line seems to be emulated correctly. So I wondered why.

As I found, the following values are sent to the sound chip by the long line:
83 00 a3 00 c9 3f 9f bf df e3 f0 9f bf df ff

These are frequency values >003 for generators 1 and 2 which correspond to the highest allowed frequency in TI BASIC (rounded up, 44733 Hz). >3f9 represents 110 Hz. (The frequency value is calculated as 111860.8/freq, and you send the least significant 4 bits first.)

The short line writes this:
80 00 a0 00 c0 00 9f bf df e3 f0 9f bf df ff

As I said, in MESS it does not work correctly. 

What I don't understand yet is what is supposed to happen when the frequency value of >000 is written to generator 3. This value should be illegal. But it seems to have an effect as if it is set to the lowest possible frequency (not the highest), as far as noise production is concerned. This is an important detail which must be corrected in the SN76496 implementation in MESS, but I need some explanation coming from technical specs and not merely an observation.

Does anybody have more information on that? Thierry, I already checked your pages but did not find a solution to that. Do the data sheets reveal more?

Michael

---

From: "Tursi" <[email-masked]>
Date: Sat, 30 Jan 2010 12:49:37 -0800

> What I don't understand yet is what is supposed to happen when the 
> frequency value of >000 is written to generator 3. This value should be 
> illegal. But it seems to have an effect as if it is set to the lowest 
> possible frequency (not the highest), as far as noise production is 
> concerned. This is an important detail which must be corrected in the 
> SN76496 implementation in MESS, but I need some explanation coming from 
> technical specs and not merely an observation.
> Does anybody have more information on that? Thierry, I already checked 
> your pages but did not find a solution to that. Do the data sheets reveal 
> more?
>

I tested this on the real machine when I re-did Classic99's sound. Writing a 
0 to the sound generator results in a count of >400 (ie: one more than the 
maximum writable value of >3FF). This is contrary to many of the similar and 
better documented variants of the sound chip, which are documented to not 
count at all (ie: they emit a flat line, at least according to the SMS Power 
doc). This is not the only way in which the TI's sound chip differs from 
available documentation on related chips, IIRC.

I don't know why the MESS project considers paper more authoritative than 
hardware, but I've never been able to locate a data sheet for the actual 
chip in use, certainly nothing that discusses this behaviour.

---

From: "Michael Zapf" <[email-masked]>
Date: Sat, 30 Jan 2010 22:56:03 -0000

Hello Tursi,
 
thanks for the information!

> maximum writable value of >3FF). 

Just found the specs:

"Each tone generator consists of a frequency synthesis section and an attenuation section. The frequency synthesis section requires 10 bits of information (F0-F9) to define half the period of the desired frequency (f). F0 is the most significant bit and F9 is the least significant bit. This information is loaded into a 10-stage tone counter, which counts down at an N/2 rate where N is the input clock frequency. When the tone counter counts down to zero, a borrow signal is produced. The borrow signal toggles the frequency flip-flop and also reloads the tone counter...."

It *could* make sense: The counter is 10 bit wide, i.e. the max value is >400. So if it decrements first and then checks for 0, a value of 0 for the frequency will cause it to wrap and go the whole way from >3FF to 0 again. 

Michael

---

From: "Tursi" <[email-masked]>
Date: Sat, 30 Jan 2010 18:24:57 -0800

> It *could* make sense: The counter is 10 bit wide, i.e. the max value is 
>  >400. So if it decrements first and then checks for 0, a value of 0 for 
> the frequency will cause it to wrap and go the whole way from >3FF to 0 
> again.
>

It does make sense, but not the way that you are interpreting it.

The range of the counter is from >000 to >3FF. However, the trigger only 
occurs when it counts down to 0. If you start  at 0, the first tick wraps 
around to >3FF, and so it has to run through the whole >400 tick range in 
order to reach the trigger point. This is pretty common in hardware devices.

Apparently some other variants of the chip chose explicitly not to count 
with a value of 0.

---

From: "Tursi" <[email-masked]>
Date: Sun, 31 Jan 2010 00:48:49 -0800

> It does make sense, but not the way that you are interpreting it.

I've not been doing well lately. Reading this again, it's clear we said 
exactly the same thing. Sorry Michael... I saw the "max value is >400" and 
went downhill from that. ;)

---

From: "Michael Zapf" <[email-masked]>
Date: Sun, 31 Jan 2010 14:24:46 -0000

Just did a test in TI BASIC + EA with CALL LOAD(-31744,X). This actually proves my guess: The lowest frequency on the TI is actually not 110 Hz but 109 Hz! This is not only true for the noise generator but also for the tone generator.

Just send the following bytes to -31744 (>8400):

137, 63, 144  (hex: >89 >3F >90)

and then

128, 0, 144 (hex: >80, >00, >90)

and you can notice a very slight shift down in frequency. OK, that's good - I'll look at the sound chip emulation in MESS - I bet that they checked for zero first. 

Michael