⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hex2aray.cpp

📁 DSP 自举过程需要的bin文件生成工具
💻 CPP
字号:
/*==============================================================================
//File : hex2aray.c
//Take an ASCII file generated by hex6x converter and convert it
//in an array of byte in C language.
//
//Date : November 26, 1997
//Author : Eric Biscondi
//Modification :
//
// (c) Copyright Texas Instruments France
//============================================================================*/
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include <string.h>
extern directvideo;

void main(int argc,char *argv[])
{
	FILE *out_file,*in_file;
	char chn_fileo[32],chn_filei[32], name_array[32], charac;
	int i,i1,in,out,out1,out2,line_count, zero_count, j, zero;
//	struct time t;
//	struct date d;
	zero = 0x30;
	/*arguments coming from the shell -------------------------------*/
	if ((argc>0)&&(strcmp(argv[1],"?")==0))
	{
		printf ("dspc6x [-i <file_in>] [-o <file_out>]\n");
	}
	/*initialisation with shell's arguments----------------------------*/
	for (i=1; i<(argc); i++)
	{
		if (!strcmp(strlwr(argv[i]),"-i"))
		{
			if (++i<=argc)
			{
				strcpy(chn_filei,argv[i]);
			}
		}
		else if (!strcmp(strlwr(argv[i]),"-o"))
		{
			if (++i<=argc)
			{
				strcpy(chn_fileo,argv[i]);
			}
		}
		else
		{
			printf ("dspc6x [-i <file_in>] [-o <file_out>]\n");
		}
	}
	/*open in file-----------------------------------------------------*/
	if ((in_file = fopen(chn_filei,"rb")) == NULL)
	{
		printf("Unable to open input file \n");
		exit (1);
	}
	if ((out_file = fopen(chn_fileo,"wb")) == NULL)
	{
		printf("Unable to open output file \n");
		exit (1);
	}
//	gettime(&t);
//	getdate(&d);
	fprintf(out_file,"/***************************************************************************/\n");
	fprintf(out_file,"/* Header file containing C6x code generated from HEX2ARAY.EXE */\n");
	fprintf(out_file,"/* */\n");
	fprintf(out_file,"/* */\n");
//	fprintf(out_file,"/* Date/Time created: %02d/%02d/%02d %2d:%02d:%02d */\n",
//		d.da_mon, d.da_day, d.da_year, t.ti_hour, t.ti_min, t.ti_sec);
	fprintf(out_file,"/* */\n");
	fprintf(out_file,"/* (c) Copyright Texas Instruments*/\n");
	fprintf(out_file,"/***************************************************************************/\n");
	/* Suppress the file name extension */
	i=0;
	do
	{
		sscanf(chn_fileo,"%1s %s", &name_array[i], &chn_fileo);
	}while( name_array[i++] != '.');
	name_array[i-1]='\0';
	fprintf(out_file, "\n\n\nconst char %s[]={",name_array);
	line_count = 0;
	zero_count = 0;
	while((in = fgetc(in_file)) != EOF)
	{
		i = in&0x0ff;
		switch(i) {
		case(0x02):
			break;
		case(0x20):
			break;
		case(0x0d):
			break;
		case(0x0a):
			break;
		case(0x24): /* Case $ */
			while( (in=fgetc(in_file)) != 0x0a);
			break;
		default:
			if( (in = fgetc(in_file)) == EOF) break;
			i1 = in&0x0ff;
			if( (i==0x30) && (i1==0x30) ) /* Zero detection */ {
				zero_count++;
			}
			else {
				if(zero_count != 0) {
					for(j=0 ; j < zero_count ; j++) {
						line_count++;
						fprintf(out_file,"0x");
						fputc(zero, out_file);
						fputc(zero, out_file);
						fprintf(out_file,","); /* Printf "," */
						if (line_count>10) {
							line_count = 0;
							fprintf(out_file,"\n ");
						}
					}
					zero_count=0;
				}
				line_count++;
				fprintf(out_file,"0x");
				fputc(i, out_file);
				fputc(i1, out_file);
				fprintf(out_file,","); /* Printf "," */
				if (line_count>10) {
					line_count = 0;
					fprintf(out_file,"\n ");
				}
			}
		}
	}
	fprintf(out_file,"0x00};");
	fcloseall();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -