#!/usr/bin/perl

open IN,$ARGV[0] or die;

$mode='0';
$MA=0;
$clock=0;
$execute='';
$step=0;

while($l=<IN>)
{
  chomp($l);
  if($l =~ /Mode(.*?): MA=(\d+).*clock: (\d+)$/)
  {
    $mode = $1;
    $MA = $2;
    $clock = $3;
    if($mode eq "1" && $MA==5)
    {
      print "1 Mode: $mode MA: $MA $execute\n";
    }
    else
    {
      if($mode eq "2")
      {
	print "1 Mode: $mode MA: $MA $execute\n";
      }
      else
      {
	print "1 Mode: $mode MA: $MA\n";
      }
    }
    if($step)
    {
      print "0\n";
      $step=0;
    }
  }
  elsif($l =~ /^Execute\[(.*)\]: (.*) +clock:/)
  {
    $address = $1;
    $instructions = $2;
    $h = $address =~ /h/;
    $two = $instructions =~ /,/;
#   print "h: $h two: $two instructions: $instructions\n";
    if($two && $h)
    {
      $instructions =~ /.*, (..)/;
      $execute = $1;
    }
    else
    {
      $instructions =~ /^(..)/;
      $execute = $1;
    }
  }
  elsif($l =~ /^Gm_step/)
  {
    $step=1;
  }
}

