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

Subversion Repositories m65c02

[/] [m65c02/] [trunk/] [Utils/] [BIN2TXT.C] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 MichaelA
#include 
2
#include 
3
#include 
4
 
5
void main(int argc, char* argv[])
6
{
7
    FILE    *in, *out;
8
    int     i, j;
9
    char    ch;
10
    double  m;
11
 
12
    printf("Converts a binary output from AS65 into Xilinx-compatible Memory Intialization File\n");
13
    printf("\nThe number of arguments supplied: %d\n", argc);
14
    if(argc < 2) {
15
        printf("\n\tProgram requires the following two arguments: infile outfile.\n");
16
        printf("\tinfile : input binary mode file output of AS65 assembler\n");
17
        printf("\toutfile: filename of output file into ASCII Hex representation of input file is written\n\n");
18
    } else {
19
        for(i = 0; i < argc; i++) {
20
            printf("argv[%d] = %s\n", i, argv[i]);
21
        }
22
 
23
        if((in = fopen(argv[1], "rb")) == NULL) {
24
            fprintf(stderr, "Cannot open input file.\n");
25
        }
26
 
27
        if((out = fopen(argv[2], "wt")) == NULL) {
28
            fprintf(stderr, "Cannot open output file.\n");
29
        }
30
 
31
        i = 0;
32
        while(!feof(in)) {
33
           ch = fgetc(in);
34
           //printf("%02X ", ch);
35
           fprintf(out, "%02X\n", ch);
36
           i += 1;
37
        }
38
 
39
        m = log(i-1)/log(2.0);
40
 
41
        if((m - ((int) m)) != 0) {
42
            j = (1 << (((int) m) + 1));
43
        } else {
44
            j = (1 <<  ((int) m)     );
45
        }
46
 
47
        printf("\n\nm = %12.6g; i = %d; j = %d, ch = %d\n\n", m, i, j, ch);
48
 
49
        if(j > i) {
50
            for(; i < j; i++) {
51
                fprintf(out, "00\n");
52
            }
53
        }
54
 
55
        fclose(in);
56
        fclose(out);
57
    }
58
}

powered by: WebSVN 2.1.0

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