#!/usr/local/bin/perl -w
use strict;

add_file("boot", 512);
end_file();
add_file("mini-root", 5120);
end_file();
end_tape();

sub end_file {
  print "\x00\x00\x00\x00";
}

sub end_tape {
  print "\xff\xff\xff\xff";
}

sub add_file {
  my($filename, $blocksize) = @_;
  my($block, $bytes_read, $length);

  open(FILE, $filename) || die("Can't open $filename: $!");
  while($bytes_read = read(FILE, $block, $blocksize)) {
    if($bytes_read < $blocksize) {
      $block .= "\x00" x ($blocksize - $bytes_read);
      $bytes_read = $blocksize;
    }
    $length = pack("V", $bytes_read);
    print $length, $block, $length;
  }
  close(FILE);
}

