mirror of https://github.com/stella-emu/stella.git
Refactored the PERL properties set tools, in preparation for additional tools.
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2378 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
47c5f4681e
commit
716dd485cb
|
@ -0,0 +1,118 @@
|
|||
package PropSet;
|
||||
|
||||
my %prop_type = (
|
||||
"Cartridge.MD5" => 0,
|
||||
"Cartridge.Manufacturer" => 1,
|
||||
"Cartridge.ModelNo" => 2,
|
||||
"Cartridge.Name" => 3,
|
||||
"Cartridge.Note" => 4,
|
||||
"Cartridge.Rarity" => 5,
|
||||
"Cartridge.Sound" => 6,
|
||||
"Cartridge.Type" => 7,
|
||||
"Console.LeftDifficulty" => 8,
|
||||
"Console.RightDifficulty" => 9,
|
||||
"Console.TelevisionType" => 10,
|
||||
"Console.SwapPorts" => 11,
|
||||
"Controller.Left" => 12,
|
||||
"Controller.Right" => 13,
|
||||
"Controller.SwapPaddles" => 14,
|
||||
"Controller.MouseAxis" => 15,
|
||||
"Display.Format" => 16,
|
||||
"Display.YStart" => 17,
|
||||
"Display.Height" => 18,
|
||||
"Display.Phosphor" => 19,
|
||||
"Display.PPBlend" => 20
|
||||
);
|
||||
|
||||
my @prop_defaults = (
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"Untitled",
|
||||
"",
|
||||
"",
|
||||
"MONO",
|
||||
"AUTO-DETECT",
|
||||
"B",
|
||||
"B",
|
||||
"COLOR",
|
||||
"NO",
|
||||
"JOYSTICK",
|
||||
"JOYSTICK",
|
||||
"NO",
|
||||
"AUTO",
|
||||
"AUTO-DETECT",
|
||||
"34",
|
||||
"210",
|
||||
"NO",
|
||||
"77"
|
||||
);
|
||||
|
||||
# Load and parse a properties file into an hash table of property
|
||||
# objects, indexed by md5sum
|
||||
sub load_prop_set($) {
|
||||
my $file = $_[0];
|
||||
print "Loading properties from file: $file\n";
|
||||
|
||||
my @props = ();
|
||||
while(($key, $value) = each(%prop_type)) {
|
||||
$props[$value] = "";
|
||||
}
|
||||
|
||||
my %propset = ();
|
||||
open(INFILE, $file);
|
||||
foreach $line (<INFILE>) {
|
||||
chomp $line;
|
||||
|
||||
# Start a new item
|
||||
if ($line =~ /^""/) {
|
||||
my $key = $props[$prop_type{'Cartridge.MD5'}];
|
||||
# print "Inserting properties for key = $key\n";
|
||||
|
||||
if(defined($propset{$key})) {
|
||||
print "Duplicate: $key\n";
|
||||
}
|
||||
$propset{$key} = [ @props ];
|
||||
|
||||
undef @props;
|
||||
while(($key, $value) = each(%prop_type)) {
|
||||
$props[$value] = "";
|
||||
}
|
||||
} elsif ($line !~ /^$/) {
|
||||
($key, $value) = ($line =~ m/"(.*)" "(.*)"/);
|
||||
if (defined $prop_type{$key}) {
|
||||
$index = $prop_type{$key};
|
||||
$props[$index] = $value;
|
||||
} else {
|
||||
print "ERROR: $line\n";
|
||||
print "Invalid key = \'$key\' for md5 = \'$props[0]\', ignoring ...\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
close(INFILE);
|
||||
return %propset;
|
||||
}
|
||||
|
||||
# Get the number of property tags in one PropSet element
|
||||
sub num_prop_types {
|
||||
return keys( %prop_type );
|
||||
}
|
||||
|
||||
# Convert a properties set into a C++ compatible string
|
||||
sub build_prop_string {
|
||||
my @array = @_;
|
||||
my $result = " { ";
|
||||
my @items = ();
|
||||
for (my $i = 0; $i < @array; $i++) {
|
||||
if($prop_defaults[$i] ne $array[$i]) {
|
||||
push(@items, "\"$array[$i]\"");
|
||||
} else {
|
||||
push(@items, "\"\"");
|
||||
}
|
||||
}
|
||||
|
||||
$result .= join(", ", @items);
|
||||
$result .= " }";
|
||||
|
||||
return $result;
|
||||
}
|
|
@ -1,105 +1,17 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
my @props = ();
|
||||
my %propset = ();
|
||||
use PropSet;
|
||||
|
||||
my %proptype = (
|
||||
"Cartridge.MD5" => 0,
|
||||
"Cartridge.Manufacturer" => 1,
|
||||
"Cartridge.ModelNo" => 2,
|
||||
"Cartridge.Name" => 3,
|
||||
"Cartridge.Note" => 4,
|
||||
"Cartridge.Rarity" => 5,
|
||||
"Cartridge.Sound" => 6,
|
||||
"Cartridge.Type" => 7,
|
||||
"Console.LeftDifficulty" => 8,
|
||||
"Console.RightDifficulty" => 9,
|
||||
"Console.TelevisionType" => 10,
|
||||
"Console.SwapPorts" => 11,
|
||||
"Controller.Left" => 12,
|
||||
"Controller.Right" => 13,
|
||||
"Controller.SwapPaddles" => 14,
|
||||
"Controller.MouseAxis" => 15,
|
||||
"Display.Format" => 16,
|
||||
"Display.YStart" => 17,
|
||||
"Display.Height" => 18,
|
||||
"Display.Phosphor" => 19,
|
||||
"Display.PPBlend" => 20
|
||||
);
|
||||
|
||||
my @prop_defaults = (
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"Untitled",
|
||||
"",
|
||||
"",
|
||||
"MONO",
|
||||
"AUTO-DETECT",
|
||||
"B",
|
||||
"B",
|
||||
"COLOR",
|
||||
"NO",
|
||||
"JOYSTICK",
|
||||
"JOYSTICK",
|
||||
"NO",
|
||||
"AUTO",
|
||||
"AUTO-DETECT",
|
||||
"34",
|
||||
"210",
|
||||
"NO",
|
||||
"77"
|
||||
);
|
||||
|
||||
|
||||
@props = ();
|
||||
while(($key, $value) = each(%proptype)) {
|
||||
$props[$value] = "";
|
||||
}
|
||||
|
||||
print "@ARGV\n";
|
||||
usage() if @ARGV != 2;
|
||||
|
||||
# Must provide input and output files
|
||||
open(INFILE, "$ARGV[0]");
|
||||
open(OUTFILE, ">$ARGV[1]");
|
||||
my %propset = PropSet::load_prop_set($ARGV[0]);
|
||||
my $setsize = keys (%propset);
|
||||
my $typesize = PropSet::num_prop_types();
|
||||
|
||||
# Parse the properties file into an array of property objects
|
||||
foreach $line (<INFILE>) {
|
||||
chomp $line;
|
||||
|
||||
# Start a new item
|
||||
if ($line =~ /^""/) {
|
||||
my $key = $props[$proptype{'Cartridge.MD5'}];
|
||||
# print "Inserting properties for key = $key\n";
|
||||
|
||||
if(defined($propset{$key})) {
|
||||
print "Duplicate: $key\n";
|
||||
}
|
||||
$propset{$key} = [ @props ];
|
||||
|
||||
undef @props;
|
||||
while(($key, $value) = each(%proptype)) {
|
||||
$props[$value] = "";
|
||||
}
|
||||
} elsif ($line !~ /^$/) {
|
||||
($key, $value) = ($line =~ m/"(.*)" "(.*)"/);
|
||||
if (defined $proptype{$key}) {
|
||||
$index = $proptype{$key};
|
||||
$props[$index] = $value;
|
||||
} else {
|
||||
print "ERROR: $line\n";
|
||||
print "Invalid key = \'$key\' for md5 = \'$props[0]\', ignoring ...\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my $size = keys (%propset);
|
||||
printf "Valid properties found: $size\n";
|
||||
printf "Valid properties found: $setsize\n";
|
||||
|
||||
# Construct the output file in C++ format
|
||||
# Walk the results array and print each item
|
||||
# This array will now contain the original tree converted to a BST in array format
|
||||
open(OUTFILE, ">$ARGV[1]");
|
||||
print OUTFILE "//============================================================================\n";
|
||||
print OUTFILE "//\n";
|
||||
print OUTFILE "// SSSS tt lll lll\n";
|
||||
|
@ -128,16 +40,17 @@ print OUTFILE " located in the src/tools directory. All properties changes\n";
|
|||
print OUTFILE " should be made in stella.pro, and then this file should be\n";
|
||||
print OUTFILE " regenerated and the application recompiled.\n";
|
||||
print OUTFILE "*/\n";
|
||||
print OUTFILE "\n#define DEF_PROPS_SIZE " . $size;
|
||||
print OUTFILE "\n#define DEF_PROPS_SIZE " . $setsize;
|
||||
print OUTFILE "\n\n";
|
||||
print OUTFILE "static const char* DefProps[DEF_PROPS_SIZE][" . keys( %proptype ) . "] = {\n";
|
||||
print OUTFILE "static const char* DefProps[DEF_PROPS_SIZE][" . $typesize . "] = {\n";
|
||||
|
||||
# Walk the hash map and print each item in order of md5sum
|
||||
my $idx = 0;
|
||||
for my $key ( sort keys %propset )
|
||||
{
|
||||
print OUTFILE build_prop_string(@{ $propset{$key} });
|
||||
print OUTFILE PropSet::build_prop_string(@{ $propset{$key} });
|
||||
|
||||
if ($idx+1 < $size) {
|
||||
if ($idx+1 < $setsize) {
|
||||
print OUTFILE ", ";
|
||||
}
|
||||
print OUTFILE "\n";
|
||||
|
@ -148,7 +61,6 @@ print OUTFILE "};\n";
|
|||
print OUTFILE "\n";
|
||||
print OUTFILE "#endif\n";
|
||||
|
||||
close(INFILE);
|
||||
close(OUTFILE);
|
||||
|
||||
|
||||
|
@ -156,21 +68,3 @@ sub usage {
|
|||
print "create_props.pl <INPUT STELLA PROPS> <OUTPUT C++ header>\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
sub build_prop_string {
|
||||
my @array = @_;
|
||||
my $result = " { ";
|
||||
my @items = ();
|
||||
for (my $i = 0; $i < @array; $i++) {
|
||||
if($prop_defaults[$i] ne $array[$i]) {
|
||||
push(@items, "\"$array[$i]\"");
|
||||
} else {
|
||||
push(@items, "\"\"");
|
||||
}
|
||||
}
|
||||
|
||||
$result .= join(", ", @items);
|
||||
$result .= " }";
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use File::Basename;
|
||||
|
||||
usage() if @ARGV < 2;
|
||||
|
||||
$numfiles = @ARGV;
|
||||
$outfile = $ARGV[$numfiles-1];
|
||||
|
||||
# Construct the output file in C++ format
|
||||
# Walk the ARGV list and convert each item
|
||||
open(OUTFILE, ">$outfile");
|
||||
|
||||
print OUTFILE "//============================================================================\n";
|
||||
print OUTFILE "//\n";
|
||||
print OUTFILE "// SSSS tt lll lll\n";
|
||||
print OUTFILE "// SS SS tt ll ll\n";
|
||||
print OUTFILE "// SS tttttt eeee ll ll aaaa\n";
|
||||
print OUTFILE "// SSSS tt ee ee ll ll aa\n";
|
||||
print OUTFILE "// SS tt eeeeee ll ll aaaaa -- \"An Atari 2600 VCS Emulator\"\n";
|
||||
print OUTFILE "// SS SS tt ee ll ll aa aa\n";
|
||||
print OUTFILE "// SSSS ttt eeeee llll llll aaaaa\n";
|
||||
print OUTFILE "//\n";
|
||||
print OUTFILE "// Copyright (c) 1995-2012 by Bradford W. Mott, Stephen Anthony\n";
|
||||
print OUTFILE "// and the Stella Team\n";
|
||||
print OUTFILE "//\n";
|
||||
print OUTFILE "// See the file \"License.txt\" for information on usage and redistribution of\n";
|
||||
print OUTFILE "// this file, and for a DISCLAIMER OF ALL WARRANTIES.\n";
|
||||
print OUTFILE "//\n";
|
||||
print OUTFILE "// \$Id\$\n";
|
||||
print OUTFILE "//============================================================================\n";
|
||||
print OUTFILE "\n";
|
||||
print OUTFILE "#ifndef GL_SHADER_PROGS_HXX\n";
|
||||
print OUTFILE "#define GL_SHADER_PROGS_HXX\n";
|
||||
print OUTFILE "\n";
|
||||
print OUTFILE "/**\n";
|
||||
print OUTFILE " This code is generated using the 'create_shaders.pl' script,\n";
|
||||
print OUTFILE " located in the src/tools directory.\n";
|
||||
print OUTFILE "*/\n";
|
||||
print OUTFILE "\n";
|
||||
print OUTFILE "namespace GLShader {\n\n";
|
||||
|
||||
for ($i = 0; $i < $numfiles - 1; $i++)
|
||||
{
|
||||
open(INFILE, "$ARGV[$i]");
|
||||
|
||||
($base,$path,$type) = fileparse($ARGV[$i]);
|
||||
$base =~ s/\./_/g;
|
||||
|
||||
print OUTFILE "static const char* " . $base . "[] = {\n";
|
||||
foreach $line (<INFILE>)
|
||||
{
|
||||
chomp($line);
|
||||
print OUTFILE "\"" . $line . "\\n\"\n";
|
||||
}
|
||||
print OUTFILE "\"\\0\"\n";
|
||||
print OUTFILE "};\n\n";
|
||||
|
||||
close(INFILE);
|
||||
}
|
||||
|
||||
print OUTFILE "} // namespace GLShader\n\n";
|
||||
print OUTFILE "#endif\n";
|
||||
|
||||
close(OUTFILE);
|
||||
|
||||
|
||||
sub usage {
|
||||
print "create_shaders.pl <shader programs> <OUTPUT C++ header>\n";
|
||||
exit(0);
|
||||
}
|
Loading…
Reference in New Issue