#!/bin/bash

INSMOD="/sbin/insmod"
MODDIR="../modules"
MAP="../snd.map"
OLDMAP="../snd.map.old"

function basic() {
  if ! $INSMOD -m $MODDIR/snd.o > $MAP; then exit 1; fi
  if ! $INSMOD -m $MODDIR/snd-mixer.o >> $MAP; then exit 1; fi
  if ! $INSMOD -m $MODDIR/snd-pcm.o >> $MAP; then exit 1; fi
  if ! $INSMOD -m $MODDIR/snd-pcm-oss.o >> $MAP; then exit 1; fi  
  if ! $INSMOD -m $MODDIR/snd-midi.o >> $MAP; then exit 1; fi
}

function insert() {
  if ! $INSMOD -m $MODDIR/$@ >> $MAP; then exit 1; fi
}

if [ -z "$1" ]; then
  echo "Specify soundcard ID..."
  exit
fi

mv -f $MAP $OLDMAP

./remove

case "$1" in
  interwave|iw)
    basic
    insert snd-cs4231.o
    insert snd-gus.o
    insert snd-interwave.o snd_dma1=5 snd_dma2=6 snd_midi=1
    cat /etc/sound/0/mixer0 > /proc/sound/0/mixer0
    ;;
  es1688)
    basic
    insert snd-es1688.o
    insert snd-mpu401-uart.o 
    insert snd-audiodrive1688.o snd_mpu_port=0x330
    ;;
  sb16)
    basic
    insert snd-sb-dsp.o
    insert snd-mpu401-uart.o 
    insert snd-sb16.o snd_irq=5 snd_dma8=1 snd_dma16=5
    cat /etc/sound/0/mixer0 > /proc/sound/0/mixer0
    ;;
  sb8)
    basic
    insert snd-sb-dsp.o
    insert snd-sb8.o snd_irq=5 snd_dma8=1
    ;;
  gusm*|max)
    basic
    insert snd-cs4231.o
    insert snd-gus.o
    insert snd-gusmax.o
    cat /etc/sound/0/mixer0 > /proc/sound/0/mixer0
    ;;
  gusc*|clas*)
    basic
    insert snd-gus.o
    insert snd-gusclassic.o snd_irq=11 snd_dma1=6 snd_dma2=7
    cat /etc/sound/1/mixer0 > /proc/sound/0/mixer0
    ;;
  guse*|ext*)
    basic
    insert snd-es1688.o
    insert snd-mpu401-uart.o 
    insert snd-gus.o
    insert snd-gusextreme.o snd_irq1=11 snd_mpu_port=0x300
    ;;
  opl3sa)
    basic
    insert snd-cs4231.o
    insert snd-opl3sa.o snd_port=0x370 snd_wss_port=0x530 \
                        snd_fm_port=0x388 snd_midi_port=0x330 \
                        snd_irq=5 snd_dma1=0 snd_dma2=1
    ;;
  mozart)
    basic
    insert snd-ad1848.o
    insert snd-mozart.o
    ;;
  p1)
    basic
    insert snd-sb-dsp.o
    insert snd-mpu401-uart.o 
    insert snd-sb16.o snd_irq=5 snd_dma8=1 snd_dma16=5 snd_mpu_port=0x330
    insert snd-gus.o
    insert snd-gusclassic.o snd_dma2=-1
    cat /etc/sound/0/mixer0 > /proc/sound/0/mixer0
    cat /etc/sound/1/mixer0 > /proc/sound/1/mixer0
    ;;
  p2)
    basic
    insert snd-cs4231.o
    insert snd-es1688.o
    insert snd-mpu401-uart.o 
    insert snd-gus.o
    insert snd-gusmax.o
    insert snd-gusextreme.o snd_irq1=11 snd_mpu_port=0x300
    ;;
  detect)
    if ! $INSMOD -m $MODDIR/snd.o > $MAP; then exit 1; fi
    if ! $INSMOD -m $MODDIR/snd-detect.o >> $MAP; then exit 1; fi
    cat /dev/snddetect
    ;;
  *)
    echo "Unknown soundcard $1..."
    ;;
esac
echo "Insert done..."
