How KON and KOF registers of DSP work?

Discussion of hardware and software development for Super NES and Super Famicom.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

How KON and KOF registers of DSP work?

Post 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?
d4s
Posts: 94
Joined: Mon Jul 14, 2008 4:02 pm

Post 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.
Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

Post 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.
Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

Post 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.
mic_
Posts: 922
Joined: Thu Oct 05, 2006 6:29 am

Post 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?
Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

Post 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.
User avatar
bazz
Posts: 476
Joined: Fri Sep 02, 2011 8:34 pm
Contact:

Post 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
mic_
Posts: 922
Joined: Thu Oct 05, 2006 6:29 am

Post 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 ;)
User avatar
bazz
Posts: 476
Joined: Fri Sep 02, 2011 8:34 pm
Contact:

Post by bazz »

i have tested my prog on real hardware too mate ;)
Near
Founder of higan project
Posts: 1553
Joined: Mon Mar 27, 2006 5:23 pm

Post 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.)
Post Reply