#!/bin/sh
# Convert an X64 Commodore 64 disk archive into a D64 format archive
# This consists of stripping the 64 byte header from the X64 archive
# 95-07-06  Dan Fandrich <dan@fch.wimsey.bc.ca>

if [ $# -eq 0 -o "$1" = "-h" -o "$1" = "-?" ] ; then
	echo Usage: `basename $0` infile.x64 [outfile.d64] >&2
	echo Converts an X64 format archive into a D64 archive by stripping the X64 header >&2
	exit 1
fi

# Verify that the input file is a X64 archive by computing a checksum on the
# X64 magic number
# Need a head that accepts -c to provide characters instead of lines
if [ "`head -4c $1 | sum -s`" != "253 1" ] ; then
#if [ "`head -4c $1 | sum`" != "253 1" ] ; then
	echo `basename $0`: $1 is not an X64 archive >&2
	exit 2
fi

# Using 64 as block size because it is a multiple of 256, the sector size,
# and it is the size of the X64 header
if [ "$2" = "" ] ; then
	dd if=$1 bs=64 skip=1
else
	dd if=$1 of=$2 bs=64 skip=1
fi
