#!/bin/sh
if [ \( $# -eq 0 \) -o \( "$1" = "--help" \) -o \( "$1" = "-?" \) ]; then
	echo "usage: $0 imagefile [imagefile...]"
	exit 0
fi
if [ $# -eq 1 ]; then
	I="$1"
	case "$1" in
	*image)	;;
	*.)	test -f "$1image" && I="$1image";;
	*)	test -f "$1.image" && I="$1.image"
	esac
	if expr "`hexdump -n 4 -e '"%u"' "$I"`" '>=' 68000 >/dev/null; then
		hexdump -n 80 -e \
		'"version  : %u\n"
		 "header sz: %u\n"
		 "data size: 0x%08x%08x\n"
		 "base addr: 0x%08x%08x\n"
		 "soa oop  : 0x%08x%08x\n"
		 "last hash: 0x%08x%08x\n"
		 1/2 "window  y: %d" 1/2 " x: %d"
		 1/4 ""
		 " flags (full screen,float order,ptid,fim,py,ntgt...): 0x%x\n"
		 "extra mem: %u\n"
		 1/2
		 "n stk pg : %u\n"
		 1/2
		 "code kb  : %u\n"
		 "eden byt : %u\n"
		 1/2
		 "extsem sz: %u\n"
		 1/2
		 "unused   : %u\n"
		 "1stseg sz: %u\n"
		 "freespace: %u\n"' "$I"
	else
		hexdump -n 56 -e \
		'"version  : %u\n"
		 "header sz: %u\n"
		 "data size: %u\n"
		 "base addr: 0x%08x\n"
		 "soa oop  : 0x%08x\n"
		 "last hash: 0x%08x\n"
		 1/2 "window  y: %d" 1/2 " x: %d"
		 " flags (full screen,float order,ptid,fim,py,ntgt...): 0x%x\n"
		 "extra mem: %u\n"
		 1/2
		 "n stk pg : %u\n"
		 1/2
		 "code kb  : %u\n"
		 "eden byt : %u\n"
		 1/2
		 "extsem sz: %u\n"
		 1/2
		 "unused   : %u\n"
		 "1stseg sz: %u\n"
		 "freespace: %u\n"' "$I"
	fi
	exit 0
fi
for f in "$@"; do
	I="$f"
	case "$1" in
	*image)	;;
	*.)	test -f "$1image" && I="$1image";;
	*)	test -f "$1.image" && I="$1.image"
	esac
	echo
	hexdump -n 56 -e \
	"\"$I: version  : %u\n\"
	 \"$I: header sz: %u\n\"
	 \"$I: data size: %u\n\"
	 \"$I: base addr: 0x%08x\n\"
	 \"$I: soa oop  : 0x%08x\n\"
	 \"$I: last hash: 0x%08x\n\"
	 1/2 \"$I: window  y: %d\" 1/2 \" x: %d\n\"
	 \"        flags (full screen,float order,ptid,fim,py,ntgt...): 0x%x\n\"
	 \"$I: extra mem: %u\n\"
	 1/2
	 \"$I: n stk pg : %u\n\"
	 1/2
	 \"$I: code kb  : %u\n\"
	 \"$I: eden byt : %u\n\"
	 1/2
	 \"$I: extsem sz: %u\n\"
	 1/2
	 \"$I: unused   : %u\n\"
	 \"$I: 1stseg sz: %u\n\"
	 \"$I: freespace: %u\n\"" "$I"
done
