#!/usr/bin/env ruby

print <<EOF
/* this file is generated by makemisc */

#include "nester.h"
#include "nes_mapper.h"
#include "nes_mapper_all.h"

NES_mapper*
GetMapper(int mapper_num)
{
  switch(mapper_num) {
EOF


while l = gets
  if /^class NES_mapper(\d+);/ =~ $_ then 
    print "  case #{$1}:\n"
    print "    return new NES_mapper#{$1}();\n"
    print "\n"
  end
end


print <<EOF
  case 12:
    return new NES_mapperNSF();

  case 184:
    return new NES_mapper122();

  default:
    ERROR("unsupported mapper");
    return NULL;  // mapper not supported
  }
}
EOF
