1994-10-01 02:56:21 +00:00
|
|
|
/*
|
1995-02-17 02:22:57 +00:00
|
|
|
* APM (Advanced Power Management) BIOS Device Driver
|
1994-10-01 02:56:21 +00:00
|
|
|
*
|
1997-11-04 18:12:51 +00:00
|
|
|
* Copyright (c) 1994-1995 by HOSOKAWA, Tatsumi <hosokawa@jp.FreeBSD.org>
|
1994-10-01 02:56:21 +00:00
|
|
|
*
|
1995-02-17 02:22:57 +00:00
|
|
|
* This software may be used, modified, copied, and distributed, in
|
1994-10-01 02:56:21 +00:00
|
|
|
* both source and binary form provided that the above copyright and
|
1995-05-30 08:16:23 +00:00
|
|
|
* these terms are retained. Under no circumstances is the author
|
|
|
|
* responsible for the proper functioning of this software, nor does
|
|
|
|
* the author assume any responsibility for damages incurred with its
|
1994-10-01 02:56:21 +00:00
|
|
|
* use.
|
|
|
|
*
|
|
|
|
* Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
|
1994-10-01 05:13:37 +00:00
|
|
|
*
|
1997-11-04 18:12:51 +00:00
|
|
|
* $Id: bin2asm.c,v 1.6 1997/02/22 09:29:53 peter Exp $
|
1994-10-01 02:56:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#define NCOLS 8
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
1995-02-17 02:22:57 +00:00
|
|
|
int c, col, lastline;
|
1994-10-01 02:56:21 +00:00
|
|
|
FILE *infile, *outfile;
|
|
|
|
|
|
|
|
if (argc != 3) {
|
|
|
|
fprintf(stderr, "Usage: %s infile outfile\n", argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1994-10-01 02:56:21 +00:00
|
|
|
if ((infile = fopen(argv[1], "rb")) == NULL) {
|
|
|
|
fprintf(stderr, "Can't open %s.\n", argv[1]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((outfile = fopen(argv[2], "wb")) == NULL) {
|
|
|
|
fprintf(stderr, "Can't open %s.\n", argv[2]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
col = 0;
|
|
|
|
|
|
|
|
fprintf(outfile, "/* This file is automatically generated by bin2asm */\n");
|
|
|
|
fprintf(outfile, "/* Original file is '%s' */\n\n", argv[1]);
|
|
|
|
|
1995-02-17 02:22:57 +00:00
|
|
|
lastline = 0;
|
|
|
|
|
1994-10-01 02:56:21 +00:00
|
|
|
while ((c = fgetc(infile)) != EOF) {
|
|
|
|
if (col % NCOLS == 0) {
|
|
|
|
fprintf(outfile, "\t.byte\t");
|
|
|
|
}
|
|
|
|
fprintf(outfile, "0x%02x", c);
|
|
|
|
if (col % NCOLS == NCOLS - 1) {
|
|
|
|
fprintf(outfile, "\n");
|
1995-02-17 02:22:57 +00:00
|
|
|
lastline = 1;
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf(outfile, ", ");
|
1995-02-17 02:22:57 +00:00
|
|
|
lastline = 0;
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
|
|
|
col++;
|
|
|
|
}
|
1995-02-17 02:22:57 +00:00
|
|
|
if (!lastline) {
|
|
|
|
do {
|
|
|
|
fprintf(outfile, "0x00, ");
|
|
|
|
} while ((col++) % NCOLS < NCOLS - 2);
|
|
|
|
fprintf(outfile, "0x00\n");
|
|
|
|
}
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1994-10-01 02:56:21 +00:00
|
|
|
fprintf(outfile, "\n/* Total size = 0x%04x */\n", col);
|
|
|
|
|
|
|
|
fclose(infile);
|
|
|
|
fclose(outfile);
|
|
|
|
return 0;
|
|
|
|
}
|