#!/bin/dash

### configuration
CPUS=${CPUS:-1}
MEM=${MEM:-1536}
VGA_TYPE=${VGA_TYPE:-cirrus} # or std, or vmware (broken)
USESDL=${USESDL--sdl}
HOSTDVD=${HOSTDVD:+-drive if=scsi,file=/dev/$HOSTDVD,format=raw}
NIC=${NIC:-user,hostfwd=tcp::2222-:22}
UEFI_BIOS=${UEFI_BIOS:-uefi-bios.bin}
SOUNDHW=${SOUNDHW--soundhw ac97}

### helpers ###
run_in_my_dir() {
        mydir=$(readlink -f "$0")
        mydir=${mydir%/*}
        cd $mydir
}

###
run_in_my_dir
case $1 in
	uefi) UEFI="-bios $UEFI_BIOS"; shift ;;
esac
[ -e fd64-nls.sfs ]  && HDB="-drive file=fd64-nls.sfs,index=1,media=disk,format=raw"
[ -e fd64-devx.sfs ] && HDD="-drive file=fd64-devx.sfs,index=3,media=disk,format=raw"
[ -e disk.ext3 ]     && HDA="-drive file=disk.ext3,index=0,media=disk,format=raw"
[ "$HOSTDVD" ] && ! lsmod | grep -q ^sg && modprobe sg

exec qemu-system-x86_64 -enable-kvm -soundhw hda \
$USESDL -m $MEM -vga $VGA_TYPE -smp $CPUS \
$UEFI -nic $NIC -usb $SOUNDHW \
-cdrom fatdog.iso $HDA $HDB $HDD $HOSTDVD \
-boot d "$@"
