Page 1 of 1

How KON and KOF registers of DSP work?

Posted: Sat Sep 17, 2011 11:54 pm
by Shiru
I've got unexpected problem with KOF register, it does not work as I expect, and my attempts to figure it out work differently in different emulators.

These two registers aren't documented much, as it is pretty basic thing. The manual gives pretty cryptic description:
(1) KON, KOF
"Key on" and "Key off". D0-D7 correspond to Voice 0-7. When "1", key
on or key off are carried out ; when "0", neither is carried out.
These two registers need not be reset. With KOF, in regard to any
Voice in which "1" is written, whether in the ADSR mode or GAIN mode,
1 to 0 decreases at the rate of 8 nsec by means of the addition of the
fixed value 1/256. In writing in a succession of KON and KOF. two
Ts (62.4 microsec) or more should be released. (In writing in a
sucession of various data in less than two Ts, the data written in
may not be operable later.)
I would expect them to work this way: when you write KON, channels those bits are in 1 in this write will start play, and those bits are in 0, continue to do what they did; when you write KOF, it is the same but channels stops.

This assumption about KON proved to be working, in emulators at least - everything works just like expected. However, when I needed to use KOF, I got a problem. Emulators either aren't react on KOF writes at all (channels continue to play), or stop play sound on this channel at all (bsnes).

Random experiments with using these registers some other way (for example, like it was enable flags instead of triggers) weren't successful, KON logic brokes, KOF continue to not work.

The question is - how these registers supposed to work?

Posted: Sun Sep 18, 2011 3:48 am
by d4s
Your problem is most likely related to timing.
To put it bluntly, writing to KON/KOFF in fast succession causes problems.
Refer to Anomie's S-DSP Doc.

Posted: Sun Sep 18, 2011 12:48 pm
by Shiru
I would guess timing problems in music player, but I also have this problem in very simple test - just KON, wait few seconds, KOF. Anyway, thanks for the link, I haven't seen this doc before and it seems there is a lot of rare info that could be useful.

Posted: Mon Sep 19, 2011 2:20 am
by Shiru
Problem solved.

First, my simple test wasn't working properly because of a bug in my code.

Second, although these two registers are documented as one, with the short text that quoted above, their logic seems to be different. These are my assumptions that gave correct result:

- When write to KON, every bit that is set will restart corresponding channel. So you only need to set bits when you need to restart channel, it is not 'active' or 'enable' flag, it is 'start' trigger.

- When write to KOF, every bit stops corresponding channel, and channel remains stopped while this bit is set. If you don't reset it before next KON, it would not allow channel to play. It is not 'stop' trigger, it is 'disable' flag.

Posted: Mon Sep 19, 2011 2:56 am
by mic_
It is not 'stop' trigger, it is 'disable'
Wouldn't it be both? The release-phase of the envelope (if you're using the ADSR feature) begins when you do KOF on a channel, doesn't it?

Posted: Mon Sep 19, 2011 3:16 am
by Shiru
Maybe. Important thing is that KOF bit should be cleared to make next sound possible.

By the way, ZSNES and Snes9x 1.51 don't care about this, they will play new sound by KON write regardless of KOF.

Posted: Mon Sep 19, 2011 3:41 am
by bazz
Shiru, I made a Test program that is a GUI for the Nintendo Sound Driver called 'Kankichi' YOu may find it useful.. Try it out.

You can play with the DSP register and see visual data real time on the SNES...

Bazz's Sound GUI
Image

Posted: Mon Sep 19, 2011 5:13 am
by mic_
Shiru wrote:Maybe. Important thing is that KOF bit should be cleared to make next sound possible.

By the way, ZSNES and Snes9x 1.51 don't care about this, they will play new sound by KON write regardless of KOF.
No problem, I never use anything other than BSNES and real HW for testing SNES stuff ;)

Posted: Mon Sep 19, 2011 10:48 am
by bazz
i have tested my prog on real hardware too mate ;)

Posted: Sun Sep 25, 2011 6:51 am
by Near
Shiru wrote:By the way, ZSNES and Snes9x 1.51 don't care about this, they will play new sound by KON write regardless of KOF.
Yep, that's what causes Der Langrisser to eventually crash on them, among other problems. They've known about the bug since '98, and it's fixed in 9X v1.52+ (but note that some of the console/handheld ports of 9X tend to backport v1.51's engine because it's faster.)