#!/bin/sh
progdir=`dirname "$0"`
homedir="/mnt/mmc/CFW/retroarch"
coredir="${homedir}/.retroarch/cores"
core="pcsx_rearmed_libretro.so"
ROMNAME="$1"
BASEROMNAME=${ROMNAME##*/}
ROMNAMETMP=${BASEROMNAME%.*}
ROMPATH=${ROMNAME%/*}
BIOSDIR="/mnt/mmc/BIOS"

if [ -f "${ROMPATH}/BIOS/${ROMNAMETMP}.bios" ]; then
	cp -f "${ROMPATH}/BIOS/${ROMNAMETMP}.bios" "${BIOSDIR}/psxonpsp660.bin"
	cp -f "${ROMPATH}/BIOS/${ROMNAMETMP}.bios" "${BIOSDIR}/scph101.bin"
	cp -f "${ROMPATH}/BIOS/${ROMNAMETMP}.bios" "${BIOSDIR}/scph1001.bin"
	cd ${homedir}
	HOME=${homedir}/ ${homedir}/retroarch -v -L $coredir/$core "$1"
	cp -f "${progdir}/psxonpsp660.bin" "${BIOSDIR}/psxonpsp660.bin"
	cp -f "${progdir}/scph101.bin" "${BIOSDIR}/scph101.bin"
	cp -f "${progdir}/scph1001.bin" "${BIOSDIR}/scph1001.bin"
	sync
	exit 0
fi

cd ${homedir}
HOME=${homedir}/ ${homedir}/retroarch -v -L $coredir/$core "$1"
sync
