OpenCores
URL https://opencores.org/ocsvn/mblite/mblite/trunk

Subversion Repositories mblite

[/] [mblite/] [trunk/] [sw/] [util/] [mem2bin.c] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 takar
/******************************************************************************************
2
*   mem2bin: converts a mem file to a binary file
3
*   syntax: mem2bin < filename_in.mem
4
*   author: Tamar Kranenburg
5
*   September, 2008
6
*******************************************************************************************/
7
 
8
#include <stdio.h>
9
 
10
main(int argc, char *argv[])
11
{
12
    unsigned char ch;
13
    unsigned char c1 = 255;
14
    unsigned char c2 = 255;
15
 
16
    FILE *fp;
17
    fp=fopen("out.bin", "wb");
18
 
19
    while (!feof(stdin))
20
    {
21
        ch = getchar() & 0x0ff;
22
        if(ch >= 48 && ch <= 57)
23
        {
24
            /* ASCII digits */
25
            ch -= 48;
26
        }
27
        else if(ch >= 65 && ch <= 70)
28
        {
29
            /* Upper case A to F */
30
            ch -= 55;
31
        }
32
        else if(ch >= 97 && ch <= 102)
33
        {
34
            /* Lower case a to f */
35
            ch -= 87;
36
        }
37
        else if(ch == 47 || ch == 64)
38
        {
39
            /* Comment line (/) or base address line (@) */
40
            while(getchar() != 10)
41
            {
42
                continue;
43
            }
44
            continue;
45
        }
46
        else
47
        {
48
            continue;
49
        }
50
 
51
        if(c1 == 255)
52
        {
53
            c1 = ch;
54
            continue;
55
        }
56
        else if(c2 == 255)
57
        {
58
            c2 = ch;
59
        }
60
        else
61
        {
62
            continue;
63
        }
64
 
65
        fputc(c1*16+c2, fp);
66
        c1 = 255;
67
        c2 = 255;
68
    }
69
    return 0;
70
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.