source: vital-to8-sdk/tools/bin2to8bin.c @ 2

Last change on this file since 2 was 1, checked in by svn, 5 years ago

Import initial

File size: 1.7 KB
Line 
1// taken from somewhere
2#include <stdio.h>
3#include <stdlib.h>
4#include <strings.h>
5
6
7unsigned char fill=0x00;
8 
9static int
10LoadBinFile(char *fname,char *binFname,int start,int exec)
11{
12   unsigned char mem[0x10000];
13   int i;
14   int size;
15   FILE *f;
16
17   // clears mem
18   for (i=0;i<0x10000;i++) mem[i]=fill;
19   
20   f=fopen(fname,"rb");
21   size=fread(mem,1,0x10000,f);
22   fprintf(stderr,"Size : 0x%x start:0x%x exec:0x%x\n",size,start,exec);
23   fclose(f);
24   // we now have bin in mem from low to high... that is basiicaly what an stobin is supposed to do...
25   f=fopen(binFname,"wb");
26   
27
28   fputc(0x00,f);
29   // size 16bit big endian
30   fputc((((size)&0xFF00)>>8),f);
31   fputc(((size)&0xFF),f);
32   // begin address
33   fputc(((start&0xFF00)>>8),f);
34   fputc((start&0xFF),f);
35   // data
36   for (i=0;i<size;i++)
37       fputc(mem[i],f);
38   fputc(0xFF,f);
39   fputc(0x00,f);
40   fputc(0x00,f);
41   // run address (ie begin address here)
42   fputc(((exec&0xFF00)>>8),f);
43   fputc((exec&0xFF),f);           
44   fclose(f);
45   return 0;
46}
47
48int
49main(int argc, char *argv[]) {
50        char *file_in=NULL;
51        char *file_out=NULL;
52       
53        int start=-1;
54        int exec=-1;
55       
56        int argnum;
57       
58        for (argnum=1;argnum<argc;argnum++) {
59                if (strncmp(argv[argnum],"-o",2)==0) file_out=&argv[argnum][2];
60                if (strncmp(argv[argnum],"-i",2)==0) file_in=&argv[argnum][2];
61                if (strncmp(argv[argnum],"-start",6)==0)
62                        sscanf(&argv[argnum][6],"%x",&start);
63                if (strncmp(argv[argnum],"-exec",5)==0)
64                        sscanf(&argv[argnum][5],"%x",&exec);
65        }
66       
67        if (file_in==NULL) { fprintf(stderr,"No input file");exit(-1);};
68        if (file_out==NULL) { fprintf(stderr,"No output file");exit(-1);};
69
70        LoadBinFile(file_in,file_out,start,exec);
71        return 0;
72       
73}
Note: See TracBrowser for help on using the repository browser.