#!/bin/bash
### BEGIN BOOT SCRIPT INFO
#Long-Name: OpenMSX
### END BOOT SCRIPT INFO
### BEGIN BOOT SCRIPT INSTALLATION DEFAULTS
#Launch-Mode: gui-only
### END BOOT SCRIPT INSTALLATION DEFAULTS
#
#This script uses a standard run scriptlet called RUN_OPENMSX which is optional
#if the standard disk image names and default machine (Philips NMS-8250) are
#being used and no non-default options are required.
#
#Disk image base names:
#
#fda		first floppy drive
#ide_hda	first Sunrise IDE hard disk
#
#These may have the extension .dsk or .img
#
#The machine can be changed by setting $OPENMSX_MACHINE

SCRIPT_ARGS=("$@")

. bootscriptfunctions.sh

_IMG_SUFFIXES=".dsk .img"

get_img_name -o fda
if [ "$IMGNAME" ]
then
	FDA_OPT="-diska"
	FDA_IMG="$IMGNAME"
fi

get_img_name -o ide_hda
if [ "$IMGNAME" ]
then
	IDE_EXT_OPT="-ext"
	IDE_EXT_ARG="ide"
	HDA_OPT="-hda"
	HDA_IMG="$IMGNAME"
fi

if [ -z "$FDA_IMG" -a -z "$HDA_IMG" ]
then
	echo "no floppy (fda.img) or hard disk (ide_hda.img) image found" >&2
	exit 1
fi

run_openmsx()
{
	if [ -z "$OPENMSX_MACHINE" ]
	then
		OPENMSX_MACHINE="Philips_NMS_8250"
	fi
	export OPENMSX_HOME="$PWD/openMSX"
	exec openmsx -machine "$OPENMSX_MACHINE" \
		$IDE_EXT_OPT $IDE_EXT_ARG \
		$HDA_OPT $HDA_IMG \
		$FDA_OPT $FDA_IMG \
		"$@" "${SCRIPT_ARGS[@]}"
}

OPTIONAL_SCRIPTLET=1
OPTIONAL_RUN=1
call_run_scriptlet openmsx
