#include <io.h>
#include <dos.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char * argv[]) {
FILE *in, *out;
int counter, i;
unsigned char inch;
long fs;

     randomize();

     if (argc<2) {
	printf("DUMPASM inputfile outputfile \n");
	printf("Dumps binary as assembler DB statements to be included in a .asm project.\n");
	printf("MAY-27-2005 - (c) 2005 Chris Evans 1-916-501-1423, http://bbx.flnet.org/\n");
	} else {
	if ((in = fopen(argv[1], "rb")) == NULL) {
	   fprintf(stderr, "Cant open input.\n");
	   return 1; }
	if ((out = fopen(argv[2], "wb")) == NULL) {
	   fprintf(stderr, "Cant open output.\n");
	   return 1; }
	fs = filelength(fileno(in));
	counter=0;
	fprintf(out, "; ===========================================================================\n");
	fprintf(out, "; %s - Hexadecimal dump\n",argv[1]);
	fprintf(out, "; ===========================================================================\n");
	fprintf(out, "data_%x: db ",random(65535));
	while (!feof(in)) {
	       inch = 0x0000;
	       inch = fgetc(in);
	       /* inch = inch & 0x00FF; */
	       counter++;
	       if ((inch>0x90) || (inch<0x10)) fprintf(out,"0");
	       fprintf(out, "%xh", inch);
	       if (counter>12) {
		   counter=0;
		   fprintf(out, "\n           db ");
		   } else {
		     fprintf(out, ", ");
		   }
	       }
	fprintf(out, " 00h\n");
	fprintf(out, "size_%x: dd %d\n",random(65535),fs);
	fprintf(out, "; ===========================================================================\n");
	fclose(in);
	fclose(out);
	return 0;
	}
}
