Subversion Repositories svn.mios

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
628 adamjking 1
/*
2
 * @(#)HexFileTester.java       beta8   2006/04/23
3
 *
4
 * Copyright (C) 2008    Jason Williams
5
 *
6
 * This application is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 2 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This application is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this application; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 */
20
 
21
import org.midibox.mios.Block;
22
import org.midibox.mios.HexFile;
23
import org.midibox.utils.Utils;
24
 
25
public class HexFileTester {
26
    public static void main(String[] args) {
27
        if (args.length != 1) {
28
            System.out.println("usage: HexFileTester file.hex");
29
            return;
30
        }
31
 
32
        HexFile hexFile = new HexFile();
33
        if (hexFile.read(args[0], false)) {
34
            for (int n = 0; n < hexFile.getBlockCount(); n++) {
35
                Block block = hexFile.getBlock(n);
36
                long lAddressMapped = block.lAddressMapped;
37
 
38
                byte[] axOutData = Utils.convertTo7Bit(block.axData);
39
                byte[] axHeader = new byte[4];
40
 
41
                axHeader[0] = (byte) ((lAddressMapped >> 10) & 0x7F);
42
                axHeader[1] = (byte) ((lAddressMapped >> 3) & 0x7F);
43
                axHeader[2] = (byte) ((block.axData.length >> 10) & 0x7F);
44
                axHeader[3] = (byte) ((block.axData.length >> 3) & 0x7F);
45
 
46
                byte xCS = Utils.calculateChecksum(axHeader, axOutData);
47
                System.out.println("Block "
48
                        + Utils.longToHex(block.lAddressMapped)
49
                        + "-"
50
                        + Utils.longToHex(block.lAddressMapped
51
                                + block.axData.length - 1) + " Checksum="
52
                        + Utils.byteToHex(xCS));
53
 
54
            }
55
        }
56
    }
57
}