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

Subversion Repositories mips789

[/] [mips789/] [branches/] [avendor/] [CTool/] [genmif.c] - Blame information for rev 51

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 35 mcupro
/******************************************************************
2
 *                                                                *
3
 *    Author: Liwei                                               *
4
 *                                                                *
5
 *    This file is part of the "mips789" project.                 *
6
 *    Downloaded from:                                            *
7
 *    http://www.opencores.org/pdownloads.cgi/list/mips789        *
8
 *                                                                *
9
 *    If you encountered any problem, please contact me via       *
10
 *    Email:mcupro@opencores.org  or mcupro@163.com               *
11
 *                                                                *
12
 ******************************************************************/
13
 
14 10 mcupro
#include "stdio.h"
15
#include "stdlib.h"
16
#define DEFAULT_LEN  "2048"
17 15 mcupro
/*Liwei 2007-8-29*/
18 10 mcupro
char HEX[]="0123456789ABCDEF" ;
19
char hex[]="0123456789abcdef" ;
20
unsigned char hex2byte(char hex_char)
21
{
22
    unsigned char i ;
23
    for(i=0;i<16;++i)if(HEX[i]==hex_char)return i ;
24
    for(i=0;i<16;++i)if(hex[i]==hex_char)return i ;
25
    return 0 ;
26
}
27
unsigned int par2u32(char*par)
28
{
29
    unsigned int i,ret=0 ;
30
    if(par==NULL)return ;
31
    if((0==strncmp(par,"0x",2))||(0==strncmp(par,"0X",2)))
32
    for(i=2;;++i)
33
    {
34 35 mcupro
        if(par[i]=='\0')return ret ;if(par[i]==' ')return ret ;
35 10 mcupro
        ret=ret*16+hex2byte(par[i]);
36
    }
37
    else
38
    for(i=0;;++i)
39
    {
40 35 mcupro
        if(par[i]=='\0')return ret ;if(par[i]==' ')return ret ;
41 10 mcupro
        ret=ret*10+hex2byte(par[i]);
42
    }
43
    return 0 ;
44
}
45
/****************************/
46
 
47
 
48
void main(int argc,char*argv[])
49
{
50
    int j=4,base=0,i=0 ;
51
    char str1[100],str2[111];
52
    FILE*ff=fopen("code.txt","r");
53
    FILE*ft ;
54
    for(j=0;j<4;++j)
55
    {
56
        if(j==0)
57
        ft=fopen("qu2_ram0.mif","w");
58
        else if(j==1)
59
        ft=fopen("qu2_ram1.mif","w");
60
        else if(j==2)
61
        ft=fopen("qu2_ram2.mif","w");
62
        else if(j==3)
63
        ft=fopen("qu2_ram3.mif","w");
64
        base=(NULL!=argv[1])?par2u32(argv[1]):0 ;
65
        base=base/4 ;
66
        fprintf(ft,"WIDTH=8;\n");
67
        fprintf(ft,"DEPTH=%s;\n\n",DEFAULT_LEN);
68
        fprintf(ft,"ADDRESS_RADIX=HEX;\n");
69
        fprintf(ft,"DATA_RADIX=HEX;\n\n");
70
        fprintf(ft,"CONTENT BEGIN \n");
71
        i=base ;
72
 
73
        if(base)while(i)
74
        {
75
            fprintf(ft,"   %X  :    %s;\n  ",base-i,"00");
76
            --i ;
77
        }
78
 
79
        rewind(ff);
80
        rewind(ff);
81
        rewind(ff);
82
        i=-1 ;
83
 
84
        while(fgets(str2,100,ff))
85
        {
86
            ++i ;
87
            if(3==j)
88
            {
89
                str2[2]=0 ;
90
                fprintf(ft,"   %X  :    %s;\n  ",i+base,&str2[0]);
91
            }
92
            else if(2==j)
93
            {
94
                str2[4]=0 ;
95
                fprintf(ft,"   %X  :    %s;\n  ",i+base,&str2[2]);
96
            }
97
            else if(1==j)
98
            {
99
                str2[6]=0 ;
100
                fprintf(ft,"   %X  :    %s;\n  ",i+base,&str2[4]);
101
            }
102
            else if(0==j)
103
            {
104
                str2[8]=0 ;
105
                fprintf(ft,"   %X  :    %s;\n  ",i+base,&str2[6]);
106
            }
107
        }
108
        fprintf(ft,"END;");
109
    }
110
}

powered by: WebSVN 2.1.0

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