#!/bin/sh

MAJOR=14
MAX_CARDS=4
PERM=666
DSP_MINOR=3

function create_device () {
  rm -f $1
  echo -n "Creating $1..."
  mknod -m $PERM $1 c $MAJOR $2
  echo " done"
}

function create_device1 () {
  rm -f $1
  minor=$2
  echo -n "Creating $1..."
  mknod -m $PERM $1 c $MAJOR $minor
  echo " done"
}

function create_devices () {
  tmp=0
  rm -f $1 $1?
  echo -n "Creating $1?..."
  while [ $tmp -lt $MAX_CARDS ]; do
    minor=$[ $2 + $tmp ]
    mknod -m $PERM $1$tmp c $MAJOR $minor
    tmp=$[ $tmp + 1 ]
  done
  echo " done"
}

function create_devices2 () {
  tmp=0
  rm -f $1 $1?
  echo -n "Creating $1??..."
  while [ $tmp -lt $MAX_CARDS ]; do
    tmp1=0
    while [ $tmp1 -lt $3 ]; do
      minor=$[ $tmp * $3 ]
      minor=$[ $2 + $minor + $tmp1 ]
      mknod -m $PERM $1$tmp$tmp1 c $MAJOR $minor
      tmp1=$[ $tmp1 + 1 ]
    done
    tmp=$[ $tmp + 1 ]
  done
  echo " done"
}

if test "$1" = "-?" || test "$1" = "-h" || test "$1" = "--help"; then
  echo "Usage: snddevices [max]"
  exit
fi

if test "$1" = "max"; then
  DSP_MINOR=19
fi

# OSS (Lite) compatible devices...

if test $MAJOR -eq 14; then
  create_device /dev/mixer		0
  create_device /dev/sequencer		1
  create_device /dev/midi		2
  create_device /dev/dsp		$DSP_MINOR
  create_device /dev/audio		4
  create_device /dev/dsp1		5
  create_device /dev/dsp8		3
  create_device /dev/dsp16		5
  create_device /dev/sndstat		6
  create_device /dev/sequencer2		8
  create_device /dev/music		8
  create_device /dev/dmmidi0		9
  create_device /dev/dmfm0		10
  create_device /dev/adsp		12	# alternate dsp
  create_device /dev/amidi		13	# alternate midi
  create_device /dev/admmidi		14	# alternate direct midi
fi

# New devices...

mv -f /dev/sndstat /dev/1sndstat
rm -f /dev/snd*
mv -f /dev/1sndstat /dev/sndstat
create_device1	/dev/sndseq		136
create_devices  /dev/sndcontrol		144
create_devices2 /dev/sndmixer		152	2
create_devices2 /dev/sndpcm		168	4
create_devices2 /dev/sndmidi		200	4
create_devices	/dev/sndfm		248
