1 /*
2 将数据文件转化成MASM.EXE能编译的数据 98.zbin
3
4 */
5
6
7 #include <stdio.h>
8 #include <bios.h>
9 #include <io.h>
10 #include <dos.h>
11 #include <dir.h>
12 void main()
13 {
14 char name[40];
15 FILE *p; int m,n;
16 char *v;
17 long size;
18 int i,j;
19 char ch;
20 char *first=" \tcode segment\n \t assume cs:code,ds:code \n \torg 100h\n begin:\n";
21 char *end=" \tcode ends\n \tend begin";
22 int len1,len2;
23 void *buf;
24 char drive[3];char dir[20];char fname[10];char ext[4];
25 char newname[50];
26 char *extt=".asm";
27
28 printf("enter the file name:\n");
29 scanf("%s", name);
30 if((p=fopen(name,"rb"))==NULL)
31 { printf("cann't open < %s > file!\n",name);
32 exit(0);}
33 size=filelength(fileno(p));
34 buf=(char *)malloc(size);
35 fread(buf,size,1,p);
36 fclose(p);
37 fnsplit(name,drive,dir,fname,ext);
38 fnmerge(newname,drive,dir,fname,extt);
39 if((p=fopen(newname,"wb"))==NULL)
40 {
41 printf("can't creat < %s > file!\n",newname);
42 exit(0);
43 }
44 fprintf(p,"%s\n",first);
45 fprintf(p," db ");
46 for(i=0,v=buf;i<size;i++,v++)
47 {
48 n=*v;
49 m=n;
50 n=n&0x0f0;
51 n=n>>4;
52 m=m&0x0f;
53 if(i==0)
54 {
55 fprintf(p,"0%x%xh,",n,m);
56 continue;
57 }
58 if((i%15)==0)
59 {
60 fprintf(p,"0%x%xh",n,m);
61 fputc(0x0d,p);
62 fputc(0x0a,p);
63 if(i==(size-1))
64 continue;
65 fprintf(p," db ");}
66 else
67 {if(i==(size-1))
68 fprintf(p,"0%x%xh",n,m);
69 else
70 fprintf(p,"0%x%xh,",n,m);
71 }
72 }
73 fprintf(p,"\n%s",end);
74 fcloseall();
75 printf(" \t PLEASE EDIT %s\n",newname);
76
77 }
78