/*
 * Copyright (c) 2014, Aleksander Osman
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 * * Redistributions of source code must retain the above copyright notice, this
 *   list of conditions and the following disclaimer.
 * 
 * * Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package ao486.utils;

import java.io.File;
import java.io.FileOutputStream;
import java.nio.file.Files;

public class HexToBin {

    /*
    static int hex[] = {
        0xfa,0x33,0xc0,0x8e,0xd0,0xbc,0x00,0x7c,0x16,0x07,0xbb,0x78,0x00,0x36,0xc5,0x37,
        0x1e,0x56,0x16,0x53,0xbf,0x3e,0x7c,0xb9,0x0b,0x00,0xfc,0xf3,0xa4,0x06,0x1f,0xc6,
        0x45,0xfe,0x0f,0x8b,0x0e,0x18,0x7c,0x88,0x4d,0xf9,0x89,0x47,0x02,0xc7,0x07,0x3e,
        0x7c,0xfb,0xcd,0x13,0x72,0x79,0x33,0xc0,0x39,0x06,0x13,0x7c,0x74,0x08,0x8b,0x0e,
        0x13,0x7c,0x89,0x0e,0x20,0x7c,0xa0,0x10,0x7c,0xf7,0x26,0x16,0x7c,0x03,0x06,0x1c,
        0x7c,0x13,0x16,0x1e,0x7c,0x03,0x06,0x0e,0x7c,0x83,0xd2,0x00,0xa3,0x50,0x7c,0x89,
        0x16,0x52,0x7c,0xa3,0x49,0x7c,0x89,0x16,0x4b,0x7c,0xb8,0x20,0x00,0xf7,0x26,0x11,
        0x7c,0x8b,0x1e,0x0b,0x7c,0x03,0xc3,0x48,0xf7,0xf3,0x01,0x06,0x49,0x7c,0x83,0x16,
        0x4b,0x7c,0x00,0xbb,0x00,0x05,0x8b,0x16,0x52,0x7c,0xa1,0x50,0x7c,0xe8,0x92,0x00,
        0x72,0x1d,0xb0,0x01,0xe8,0xac,0x00,0x72,0x16,0x8b,0xfb,0xb9,0x0b,0x00,0xbe,0xe6,
        0x7d,0xf3,0xa6,0x75,0x0a,0x8d,0x7f,0x20,0xb9,0x0b,0x00,0xf3,0xa6,0x74,0x18,0xbe,
        0x9e,0x7d,0xe8,0x5f,0x00,0x33,0xc0,0xcd,0x16,0x5e,0x1f,0x8f,0x04,0x8f,0x44,0x02,
        0xcd,0x19,0x58,0x58,0x58,0xeb,0xe8,0x8b,0x47,0x1a,0x48,0x48,0x8a,0x1e,0x0d,0x7c,
        0x32,0xff,0xf7,0xe3,0x03,0x06,0x49,0x7c,0x13,0x16,0x4b,0x7c,0xbb,0x00,0x07,0xb9,
        0x03,0x00,0x50,0x52,0x51,0xe8,0x3a,0x00,0x72,0xd8,0xb0,0x01,0xe8,0x54,0x00,0x59,
        0x5a,0x58,0x72,0xbb,0x05,0x01,0x00,0x83,0xd2,0x00,0x03,0x1e,0x0b,0x7c,0xe2,0xe2,
        0x8a,0x2e,0x15,0x7c,0x8a,0x16,0x24,0x7c,0x8b,0x1e,0x49,0x7c,0xa1,0x4b,0x7c,0xea,
        0x00,0x00,0x70,0x00,0xac,0x0a,0xc0,0x74,0x29,0xb4,0x0e,0xbb,0x07,0x00,0xcd,0x10,
        0xeb,0xf2,0x3b,0x16,0x18,0x7c,0x73,0x19,0xf7,0x36,0x18,0x7c,0xfe,0xc2,0x88,0x16,
        0x4f,0x7c
    };
    */
    
    /*
    static int hex[] = { 0xe9, 0x35, 0x01, 0x06, 0x16 };
    */
    
    /*
    static int hex[] = {
        0x2e,0x89,0x1e,0x23,0x01,0x2e,0x88,0x2e,
        0x2f,0x01,0x2e,0x88,0x16,0x2d,0x01,0x2e,0x89,0x36,0x31,0x01,0x1e,0x2e,0x8f,0x06,
        0x33,0x01,0x33,0xc9,0x8e,0xd9,0x06,0x8e,0xc1,0x8b,0x36,0x78,0x00,0x8e,0x1e,0x7a,
        0x00,0xbf,0x22,0x05,0xb9,0x0b,0x00,0xfc,0xf3,0xa4,0x06,0x1f,0xc7,0x06,0x78,0x00,
        0x22,0x05,0x8c,0x1e,0x7a,0x00,0x07,0x8b,0x0e,0x0b,0x7c,0x2e,0x89,0x0e,0x1b,0x01,
        0x8a,0x0e,0x0d,0x7c,0x2e,0x88,0x0e,0x37,0x01,0x8b,0x0e,0x18,0x7c,0x2e,0x89,0x0e,
        0x2b,0x01,0x8b,0x0e,0x1a,0x7c,0x2e,0x89,0x0e,0x05,0x01,0x8b,0x0e,0x16,0x7c,0x2e,
        0x89,0x0e,0x15,0x01,0x8b,0x0e,0x0e,0x7c,0x2e,0x89,0x0e,0x1d,0x01,0x8b,0x0e,0x1c,
        0x7c,0x2e,0x89,0x0e,0x17,0x01,0x8b,0x0e,0x13,0x7c,0x2e,0x89,0x0e,0x27,0x01,0x80,
        0x3e,0x26,0x7c,0x29,0x75,0x1e,0x2e,0xa3,0x25,0x01,0xa1,0x1e,0x7c,0x2e,0xa3,0x19,
        0x01,0x83,0xf9,0x00,0x75,0x0e,0xa1,0x20,0x7c,0x2e,0xa3,0x27,0x01,0xa1,0x22,0x7c,
        0x2e,0xa3,0x29,0x01,0xfc,0x33,0xf6,0x8b,0xfe,0xcd,0x12,0xb1,0x06,0xd3,0xe0,0x33,
        0xdb,0x8e,0xdb,0x8b,0x1e,0xbc,0x00,0x8e,0x1e,0xbe,0x00,0x81,0x7f,0x03,0x52,0x50
    };
    */
    
    static int hex[] = {
        //0x3B, 0x55, 0x06, 0x75, 0x0D, 0x3B, 0x4D, 0x08, 0x75, 0x08, 0x3A, 0x45, 0x04 
        //0x2E, 0xA3, 0x9D, 0x02, 0x2E
        //0xCB, 0x8E, 0x06, 0xB0, 0x05, 0xB8, 0x02
        0xeb, 0x3c, 0x90
    };
    
    public static void main(String args[]) throws Exception {
        FileOutputStream out = new FileOutputStream("out.bin");
        
        for(int i : hex) {
            out.write(i);
        }
        out.close();
        
        
        byte bytes[] = Files.readAllBytes(new File("./../bochsDevs/interrupt.txt").toPath());
        String str = new String(bytes);
        
        for(int i=0; i<256; i++) {
            if(str.indexOf(String.format("irq %02x", i)) != -1) System.out.printf("IRQ: 0x%02x\n", i);
        }
    }
}
