#!/usr/bin/perl

print "Content-type:text/html\n\n";

print "<style>body { font-family: sans-serif; }</style>";

$partsraw = <<__EOQ__;
player1colors
playercolors
pfcolors
pfheights
no_blank_lines
readpaddle
background
__EOQ__

    @parts = split(/\n/,$partsraw);

    $v = 1;
    foreach $part (@parts){
	$val{$part} = $v;
	$v *= 2;
    }


    $okcombosraw = <<__EOQ__;
player1colors!loss of missile1.
no_blank_lines!loss of missile0.
pfcolors
pfheights
pfcolors pfheights!Colors and height are fixed.
pfcolors pfheights background!Colors and height are fixed.
pfcolors no_blank_lines!loss of missile0.
pfcolors no_blank_lines background!loss of missile0.
player1colors no_blank_lines!loss of missile1 and missile0.
player1colors pfcolors!loss of missile1.
player1colors pfheights!loss of missile1.
player1colors pfcolors pfheights!loss of missile1 and colors and height are fixed.
player1colors pfcolors background!loss of missile1.
player1colors pfheights background!loss of missile1.
player1colors pfcolors pfheights background!loss of missile1 and colors and height are fixed.
player1colors no_blank_lines readpaddle!loss of missile1 and missile0.
player1colors no_blank_lines pfcolors!loss of missile1 and missile0.
player1colors no_blank_lines pfcolors background!loss of missile1 and missile0.
playercolors player1colors pfcolors!loss of missile1 and missile0.
playercolors player1colors pfheights!loss of missile1 and missile0.
playercolors player1colors pfcolors pfheights!loss of missile1 and missile0 & colors and height are fixed.
playercolors player1colors pfcolors background!loss of missile1 and missile0.
playercolors player1colors pfheights background!loss of missile1 and missile0.
playercolors player1colors pfcolors pfheights background|loss of missile1 and missile0 & colors and height are fixed.
no_blank_lines readpaddle!loss of missile0.
__EOQ__

# %combocosts = ("pfcolors pfheights background", "DERRP");






    @okcombos = split(/\n/,$okcombosraw);

foreach $rawcombo (@okcombos){
    @firststuffs = split(/\!/,$rawcombo);
    $combo = $firststuffs[0];
    $desc =  $firststuffs[1];
    #print "$combo TO $desc";
    $combocosts{$combo} = $desc;  
    
    @stuffs = split(/\s+/,$combo);
    $sum = 0;
    foreach $stuff (@stuffs){
	    $sum += $val{$stuff};
    }
#    print "$combo $sum<br>";
    $isok{$sum} = 1;
}
print <<__EOQ__;
<head>
<title>batari BASIC kernel-don't-panic</title>
</head>
<h2>batari BASIC kernel-don't-panic</h2>
batari BASIC has a number of options to let the kernel do interesting things.<br><br>
Unfortunately, many of these options are mutually incompatible, and some of them are dependent 
on other options!
<br><br>
The <a href="http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#kerneloptions">batari Basic Command List</a> (maintained by Random Terrain, and where this raw data was lifted from) describes the various options and lists the valid singletons and combinations, but I found it difficult to grasp what worked with what from the list. This chart makes it easier.
<br><br>

__EOQ__

print qq(<table border=1>);
print qq(<tr><th></th><th colspan="7"><i>settings</i></th></tr>);
print qq(<tr><th><i>allowed arguments to follow 'set kernel options'</i></th>);

    foreach $part (@parts){
	print qq(<th>$part</th>);
    }
print qq(</tr>);
for($i = 1; $i <= 128; $i++){
    @usedparts = ();
        foreach $part (@parts){
	    if($val{$part} & $i){
		push  @usedparts,$part;

	    }
    }
    $single = 0;
    if($#usedparts == 0){
	$single = 1;
    }

    if($isok{$i}){
    	print qq(<tr>);
    	# if(! $single) {
    	$key = join(" ",@usedparts);
    	print "<th><tt>$key</tt><br>\n";
    	$cost = $combocosts{$key};
    	#print "$cost";
    	print "</th>";
    	
    	
        #} else {
    	#print "<th><tt><i>",join(" ",@usedparts),"</i></tt></th>\n";
    
        # }
    	foreach $part (@parts){
                if($val{$part} & $i){
    		print qq(<th bgcolor="#9999FF">X</th>);
                } else {
    		print "<th>&nbsp;</th>";
    	    }
    	}
    
    	print qq(</tr>);
        }
}

print qq(</table border=1>);

