#!env python
###############################################################################
#
# Copyright (C) 2015 Nintendo.  All rights reserved.
#
# These coded instructions, statements, and computer programs contain
# proprietary information of Nintendo of America Inc. and/or Nintendo
# Company Ltd., and are protected by Federal copyright law.  They may
# not be disclosed to third parties or copied or duplicated in any form,
# in whole or in part, without the prior written consent of Nintendo.
#
###############################################################################

import sys, os, struct

if __name__== "__main__":
    argv = sys.argv
    argc = len(argv)

    if argc > 1:
        argv = argv[1:]
    else:
        print "Usage: %s target_files" % (argv[0])
        sys.exit(2)

    for target_file in argv:
        # open target file
        target = open(target_file, 'rb')
        target_data = target.read()
        target.close()
    
        # parse target file and make data
        target_data_array = struct.unpack(str(len(target_data))+'B', target_data)
        target_data_array = [ format(x, '#04x') for x in target_data_array ]
        output_str = ",".join(target_data_array)
    
        # output data
        output_file = target_file + ".inc"
        output = open(output_file, 'w')
        output.write(output_str)
        output.close()
    
        print "output to " + output_file


