#!/bin/sh

# Create a big tape suitable to be read on an empty machine.

# It starts with track 0, basichelp3, and rebuilds Help-3 for a single drum machine with buffer. The help3 programs are stored on tape station 6.

# Track 0 is read by the three cell loader. Press space after SUM. Write r< after basichelp3 is read.

# MK 2011-04-05

# Remove last occurence of _s by reversing the file and remove the first _s, and reverse again

flx2a <"Main help (5) 8.08.68.flx" | tac | sed '0,/_s/{//d;}' | tac | sed -e '/_iredefine/{ N; s/_s/d41=1,d54=6/g }' >BUILDbuffertape.asc
flx2a <"inithelp (4) 13.01.69.flx" | tac | sed '0,/_s/{//d;}' | tac >>BUILDbuffertape.asc
flx2a <"exit (2) 7.06.68.flx" | tac | sed '0,/_s/{//d;}' | tac >>BUILDbuffertape.asc
flx2a <"binin (1) 22.07.67.flx" | tac | sed '0,/_s/{//d;}' | tac >>BUILDbuffertape.asc
flx2a <"start (3) 21.09.70.flx" | tac | sed '0,/_s/{//d;}' | tac >>BUILDbuffertape.asc
flx2a <"clear ... (10) 8.08.67.flx" | tac | sed '0,/_s/{//d;}' | tac >>BUILDbuffertape.asc
flx2a <"run (2) 10.08.67.flx" | tac | sed '0,/_s/{//d;}' | tac >>BUILDbuffertape.asc
flx2a <"check ... (12) 1.07.70.flx" | tac | sed '0,/_s/{//d;}' | tac >>BUILDbuffertape.asc
# The rest of the programs are placed on tape station 6 (d54)
echo "d35=3" >>BUILDbuffertape.asc 
flx2a <"algol (2) 8.08.67.flx" | tac | sed '0,/_s/{//d;}' | tac >>BUILDbuffertape.asc
flx2a <"binout, ... (2) 9.08.67.flx" | tac | sed '0,/_s/{//d;}' | tac >>BUILDbuffertape.asc
flx2a <"edit (9) 8.07.70.flx" | tac | sed '0,/_s/{//d;}' | tac >>BUILDbuffertape.asc
flx2a <"move (5) 15.12.68.flx" | tac | sed '0,/_s/{//d;}' | tac >>BUILDbuffertape.asc
flx2a <"slip (4) 14.01.69.flx" | tac | sed '0,/_s/{//d;}' | tac >>BUILDbuffertape.asc
flx2a <"print ... (12) 23.01.69.flx" | tac | sed '0,/_s/{//d;}' | tac >>BUILDbuffertape.asc
echo "_e10" >>BUILDbuffertape.asc
# Build tape with track 0 and basichelp3
cat "basic track 0 20.08.67.flx" ../help3bin/basichelp3.flx > BUILDbuffertape.flx
# Append set of tapes
cat <<EOF >>BUILDbuffertape.asc
set,3,1000,1,0,0,tape1<
set,3,1000,1,1,0,tape1.1<
set,3,1000,1,2,0,tape1.2<
set,3,1000,2,0,0,tape2<
set,3,1000,2,1,0,tape2.1<
set,3,1000,2,2,0,tape2.2<
set,3,1000,3,0,0,tape3<
set,3,1000,3,1,0,tape3.1<
set,3,1000,3,2,0,tape3.2<
set,3,1000,4,0,0,tape4<
set,3,1000,4,1,0,tape4.1<
set,3,1000,4,2,0,tape4.2<
set,3,1000,5,0,0,tape5<
set,3,1000,5,1,0,tape5.1<
set,3,1000,5,2,0,tape5.2<
t<
EOF
# Remove checksums and append
sed 's/#061#...//g' BUILDbuffertape.asc|sed 's/#061.//g'|a2flx >>BUILDbuffertape.flx
#rm -f BUILDbuffertape.asc
