[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Shell script to add Binary II header



I grabbed a few disk images from one of the archives today...found they
weren't marked as to block order and really weren't set up for transferring
to a real Apple II (as opposed to an emulator).  I sorted out which images
were DOS 3.3 order and which were ProDOS order, then used CiderPress to put
the images into ShrinkIt archives.

There's just one little problem: CiderPress won't create ShrinkIt archives
with the Binary II headers they should have when residing on non-Apple II
systems.

The shell script tacked onto the end of this post takes a ShrinkIt archive
as input, adds a Binary II header to the beginning, and pads the file length
to a multiple of 128 bytes.  I've tested the files it produces against
NuLib2 and CiderPress; my Apple IIs are still packed up from my last move,
so I haven't had a chance to transfer them over to one and unpack them
there.

It was developed & tested under Cygwin (running on Windows), but should work
anywhere a Bourne-compatible shell is available.  It doesn't use any
nonstandard programs to do its work; just things like wc, awk, dd, etc. that
should be on every computer.

  _/_
 / v \ Scott Alfter (remove the obvious to send mail)
(IIGS( http://alfter.us/            Top-posting!
 \_^_/                              >What's the most annoying thing on Usenet?

---------------------------------snip here---------------------------------
#!/bin/sh
size=`wc "$1" | awk '{print $3}'`
bc128=`echo $size | awk '{bc=$0/128; if (bc-int(bc)>0) {bc=int(bc)+1} else {bc=int(bc)}; print bc }'`
bc512=`echo $size | awk '{bc=$0/512; if (bc-int(bc)>0) {bc=int(bc)+1} else {bc=int(bc)}; print bc }'`

echo -n >/var/tmp/tmp$$

# Binary II header documented at http://www.textfiles.com/apple/binaryii.txt

echo -ne '\x0a\x47\x4C' >>/var/tmp/tmp$$ # ID bytes
echo -ne '\xD3' >>/var/tmp/tmp$$ # access 
echo -ne '\xE0' >>/var/tmp/tmp$$ # filetype: archive
echo -ne '\x02\x80' >>/var/tmp/tmp$$ # auxtype: ShrinkIt archive
echo -ne '\x01\x01\x00' >>/var/tmp/tmp$$ # storage type & filesize...but not of the actual file?
eval `date -r "$1" +"year=%y; month=%m; day=%d; hour=%H; min=%M"`
year=`expr $year \* 512`
month=`expr $month \* 32`
packdate=`expr $year + $month`
packdate=`expr $packdate + $day`
packdate1=`expr $packdate / 256`
packdate0=`expr $packdate % 256`
echo $packdate0 $packdate1 $min $hour | awk '{printf("echo -ne '\''\\x%02x\\x%02x\\x%02x\\x%02x'\''",$1,$2,$3,$4,$5,$6)}' | sh >/var/tmp/tmp$$.2
cat /var/tmp/tmp$$.2 /var/tmp/tmp$$.2 >>/var/tmp/tmp$$ && rm /var/tmp/tmp$$.2 # modified & created timestamps
echo -ne '\x02' >>/var/tmp/tmp$$ # ID
echo -ne '\x00' >>/var/tmp/tmp$$ # reserved
h=`expr $size / 65536`
m=`expr $size % 65536`
m=`expr $m / 256`
l=`expr $size % 256`
echo $l $m $h | awk '{printf("echo -ne '\''\\x%02x\\x%02x\\x%02x'\''",$1,$2,$3)}' | sh >>/var/tmp/tmp$$ # filesize
echo -n "$1" | wc | awk '{printf("echo -ne '\''\\x%02x'\''",$3)}' | sh >>/var/tmp/tmp$$ # length of filename
(echo -n "$1"; dd if=/dev/zero bs=64 count=1) >/var/tmp/tmp$$.3 && \
dd if=/var/tmp/tmp$$.3 bs=64 count=1 >>/var/tmp/tmp$$ && rm /var/tmp/tmp$$.3 # filename
dd if=/dev/zero bs=23 count=1 >>/var/tmp/tmp$$ # reserved
dd if=/dev/zero bs=6 count=1 >>/var/tmp/tmp$$ # ProDOS 16 attributes
echo -ne '\x01\x00\x00\x00' >>/var/tmp/tmp$$ # space needed...but not of this file?
echo -ne '\x00' >>/var/tmp/tmp$$ # OS type: ProDOS
echo -ne '\x00\x00' >>/var/tmp/tmp$$ # native filetype (ignored for ProDOS)
echo -ne '\x00' >>/var/tmp/tmp$$ # phantom file flag
echo -ne '\x00' >>/var/tmp/tmp$$ # data flags
echo -ne '\x00' >>/var/tmp/tmp$$ # Binary II version number
echo -ne '\x00' >>/var/tmp/tmp$$ # file count

cat "$1" >>/var/tmp/tmp$$ # file data
dd if=/dev/zero bs=128 count=1 >>/var/tmp/tmp$$ # zero padding at end

dd if=/var/tmp/tmp$$ of="${1%.sdk}.bxy" bs=128 count=`expr $bc128 + 1`

rm /var/tmp/tmp$$

--- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---