#!/bin/bash
#
# Dump a given arcnet buffer to stdout (defaults to buffer #0)
#
# This program requires root privileges and the hexdump command...
#
# It also assumes your ARCnet card has its memory at 0xD0000.
#

endhappily()
{
	rm -f "$TMPNAME-1" "$TMPNAME-2"
	exit 0
}

VAL=`date +%H%M%S`
TMPNAME=/tmp/hdump-$VAL

trap endhappily EXIT

hdump()
{
	hexdump -e '"%08_ax  " 16/1 "%02X " " \n"'  $* >$TMPNAME-1
	hexdump -e '16/1 "%_p" "\n"'		    $* >$TMPNAME-2
	paste -d ' ' $TMPNAME-1 $TMPNAME-2
}


# 0xD0000 is the start of arcnet memory
MEMSTART=851968

# if we were given a buffer number, add it to our offset.
if [ -n "$1" ]; then
	MEMSTART=`expr $1 '*' 512 + $MEMSTART`
fi

echo Memory dump starting at: $MEMSTART

hdump -s $MEMSTART -n 512 </dev/mem
