#!/usr/bin/perl # # Copyright © 2015-2020 by Vincent Slyngstad # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS LISTED ABOVE BE LIABLE # FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # # Except as contained in this notice, the names of the authors above # shall not be used in advertising or otherwise to promote the sale, use # or other dealings in this Software without prior written authorization # from those authors. # Dump the file if it is really in TSS BASIC format. # TSS BASIC stores line numbers in binary in a single word. # The sixbit text of the BASIC source code follows, ending in 0000. # The logical end-of-file is a word (line number) of 03777. # Pick a block size (in words!) $bsize = 128; $upack = "S$bsize"; # Process the argument(s). The -q option toggles quiet mode, in which the # FOCAL text is not output. $quiet = 0; for $file (@ARGV) { if ($file =~ /-q/i) { $quiet = !$quiet; next; } # Open the file open(INPUT, $file) || die "$file: $!"; binmode(INPUT); # # Read in each block. @buf = (); for ($block = 0; ; $block++) { read(INPUT, $buf, 2*$bsize) || last; push(@buf, unpack($upack, $buf)); } # # Check for a valid BASIC file. Accumulate source code. $fail = $oline = 0; $basic = ""; while (@buf) { $line = shift @buf; last if $line == 03777; $fail = 1 if $line <= $oline; $fail = 1 if $line > 03777; last if $fail; $basic .= sprintf("%d", $line); while (@buf) { $word = shift @buf; $c = $word >> 6; last unless $c; $c = $c + 0100 unless $c >= 040; $basic .= pack('C', $c); $c = $word & 077; last unless $c; $c = $c + 0100 unless $c >= 040; $basic .= pack('C', $c); # grep($_ = ($_ + 040), @c); } $basic .= "\r\n"; } warn "$file: not a BASIC file\n" if $fail; # exit $fail if $fail; # warn "$file:\n"; $quiet = 1 if $fail; print $basic unless $quiet; } exit 0;