OpenCores
URL https://opencores.org/ocsvn/w11/w11/trunk

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.74/] [tools/] [bin/] [tap2file] - Blame information for rev 38

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 31 wfjm
#!/usr/bin/perl -w
2
# $Id: tap2file 686 2015-06-04 21:08:08Z mueller $
3
#
4
# Copyright 2015- by Walter F.J. Mueller 
5
#
6
# This program is free software; you may redistribute and/or modify it under
7
# the terms of the GNU General Public License as published by the Free
8
# Software Foundation, either version 2, or at your option any later version.
9
#
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
12
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13
# for complete details.
14
#
15
#  Revision History:
16
# Date         Rev Version  Comment
17
# 2015-06-03   686   1.0.1  add print_usage; cleanups
18
# 2015-05-24   684   1.0    Initial version
19
#
20
# Expand a simh tape container file (.tap) to a set of files
21
#
22
# Usage:  tap2file [--pref=pref] file
23
#
24
use 5.14.0;                                 # require Perl 5.14 or higher
25
use strict;                                 # require strict checking
26
 
27
use Getopt::Long;
28
 
29
my %opts = ();
30
 
31
GetOptions(\%opts, "pref=s", "help")
32
  or die "bad options";
33
 
34
sub close_ofile;
35
sub print_usage;
36
 
37
if (scalar(@ARGV) == 0 || exists $opts{help}) {
38
  print_usage;
39
  exit 0;
40
}
41
 
42
my $ifile = shift @ARGV;
43
exit 0 unless defined $ifile;
44
 
45
open(IFILE, "<$ifile") || die("Can't open $ifile: $!");
46
 
47
my $basename = $ifile;
48
$basename = $1 if $ifile =~ m|.*/(.*)|;
49
my $fstem = $basename;
50
$fstem = $1 if $basename =~ m|(.*)\..*|;
51
 
52
my $pref = (exists $opts{pref}) ? $opts{pref} : "${fstem}_";
53
 
54
my $nfile = 0;
55
my $nrec  = 0;
56
my $rlmin = 0;
57
my $rlmax = 0;
58
my $ofile = "";
59
 
60
my $block;
61
my $nb;
62
 
63
while ($nb = read(IFILE, $block, 4)) {
64
  my $metabeg = unpack("V", $block);
65
 
66
  if ($metabeg == 0x00000000) {
67
    close_ofile;
68
    $nfile += 1;
69
    next;
70
  }
71
  if ($metabeg == 0xffffffff) {
72
    last;
73
  }
74
 
75
  unless (defined fileno OFILE) {
76
    $ofile = sprintf("%s%02d.dat", $pref,$nfile);
77
    open(OFILE, ">$ofile") || die("Can't open $ofile: $!");
78
  }
79
 
80
  $nb = read(IFILE, $block, $metabeg);
81
  print OFILE $block;
82
  if ($nrec == 0) {
83
    $rlmin = $metabeg;
84
    $rlmax = $metabeg;
85
  } else {
86
    $rlmin = $metabeg if $metabeg < $rlmin;
87
    $rlmax = $metabeg if $metabeg > $rlmin;
88
  }
89
  $nrec += 1;
90
 
91
  $nb = read(IFILE, $block, 4);
92
  my $metaend = unpack("V", $block);
93
  if ($nb != 4 || not defined $metaend) {
94
    printf "bad meta tag:  beg=%8.8x\n", $metabeg;
95
    last;
96
  }
97
  if ($metaend != $metabeg) {
98
    printf "bad meta tags: beg=%8.8x end=%8.8x\n", $metabeg,$metaend;
99
    last;
100
  }
101
}
102
 
103
close_ofile;
104
exit 0;
105
 
106
# ----------------------------------------------------------------------------
107
sub close_ofile {
108
  return unless (defined fileno OFILE);
109
  close(OFILE);
110
  if ($rlmin == $rlmax) {
111
    printf "%s: %6d records, length %5d\n",
112
    $ofile, $nrec, $rlmin;
113
  } else {
114
    printf "%s: %6d records, length min=%5d, max=%5d\n",
115
    $ofile, $nrec, $rlmin, $rlmax;
116
  }
117
  $nrec  = 0;
118
  $rlmin = 0;
119
  $rlmax = 0;
120
}
121
 
122
# ----------------------------------------------------------------------------
123
sub print_usage {
124
  print "usage: tap2file [options] ifile\n";
125
  print "  ifile    input tap file\n";
126
  print "  Options\n";
127
  print "    --pref=p     use p as prefix for generated files\n";
128
  print "    --help       this message\n";
129
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.