# charset="UTF-8" # encoding="UTF-8" # Hint from RealBasic project source of FAM2FDS # (expired) # # I do not have FAM file, I can not verify this script. #!/usr/bin/perl -s require 5.000; use strict; use vars qw{ $ines $fwnes $fmt $mac }; $#ARGV or die "usage $0 [ -fwnes | -ines ] [--] files -fwnes: Insert header -ines: Delete header "; $fmt = $ines ? 'i' : $fwnes ? 'f' : '?'; $mac = $^O =~ /MacOS/; $/ = $\ = "\1*NINTENDO-HVC*"; while (defined(my $arg = shift @ARGV)) { (my $fds = $arg) =~ s/\.fam$// or next; open FAM, "< $arg" or die; binmode FAM;# DOS/WIN my @fam = ; close FAM; my $c = @fam; if (2 > $c) { warn "$arg is not Disk Image...?\n"; next; } $fds .= " ($fmt).fds"; open FDS, "> $fds" or die; binmode FDS;# DOS/WIN if ($fwnes) { print FDS "FDS\x1A", pack('C @11', $c); $mac and eval { MacPerl::SetFileInfo("mcFC", "FDS ", $fds) }; } print FDS @fam[1..-2]; close FDS; $ines and $mac and eval { MacPerl::SetFileInfo("iNES", "Disk", $fds) }; } __END__ #!/usr/bin/env python import getopt import os import re import string import sys mac = os.name == 'mac' or sys.platform == 'darwin' if mac: import MacOS import macostools def writefds(o, f, s): c = string.count(s, '\1*NINTENDO-HVC*') n = open(f, 'wb') if o in ('-f','--fwnes') or not o in ('-i','--ines'): n.write('FDS\x1A' + chr(c) + ('\0' * 11)) n.write(s[:65500 * c]) n.close() if mac: if o in ('-f','--fwnes'): MacOS.SetCreatorAndType(f, 'mcFC', 'FDS ') if o in ('-i','--ines'): MacOS.SetCreatorAndType(f, 'iNES', 'Disk') macostools.touched(f) def eachfile(i, o='-f'): f = open(i, 'rb') s = f.read() f.close p = string.find(s, '\1*NINTENDO-HVC*') if p != -1: writefds(o, i[:-3] + 'fds', s[p:]) else: print i, 'is not Disk Image...?' def usage(): print "Usage:", sys.argv[0], """-[fi] files... -f: Insert header (fwNES) -i: Delete header (iNES) """ sys.exit() def optget(): opts, args = getopt.getopt(sys.argv[1:], 'fi') if not opts or not opts[0][0]: usage() return opts[0][0], args if __name__ == '__main__': o, args = optget() for i in args: if os.path.isfile(i) and i[-4:] == '.fam': eachfile(i, o)