mirror of
https://github.com/SEPPDROID/Digital-Research-Source-Code.git
synced 2025-10-23 00:14:25 +00:00
1 line
1.1 KiB
C
1 line
1.1 KiB
C
/* -*-c,save-*- */
|
|
|
|
#include <stdio.h>
|
|
|
|
#define FAST register
|
|
|
|
#define LOCAL static
|
|
|
|
#define GLOBAL extern
|
|
|
|
#define BLOCK_SIZE 32
|
|
|
|
|
|
|
|
|
|
|
|
main(argc,argv)
|
|
|
|
int argc;
|
|
|
|
char *argv[];
|
|
|
|
{FAST FILE *infile;
|
|
|
|
FILE *fopenb();
|
|
|
|
char block_buff[BLOCK_SIZE];
|
|
|
|
FAST int rec_num,bytes;
|
|
|
|
|
|
|
|
if (argc != 2) {
|
|
|
|
fprintf(stderr,"Usage: tohex infile [>outfile]\n");
|
|
|
|
abort(1);
|
|
|
|
}
|
|
|
|
infile = fopenb(argv[1],"r");
|
|
|
|
if (infile == NULL) {
|
|
|
|
perror("tohex: fopenb error");
|
|
|
|
abort(2);
|
|
|
|
}
|
|
|
|
rec_num = 0;
|
|
|
|
while ((bytes = fread(&block_buff[0],1,BLOCK_SIZE,infile)) > 0) {
|
|
|
|
put_hex(&block_buff[0],bytes,rec_num++);
|
|
|
|
}
|
|
|
|
put_hex(block_buff,0,rec_num);
|
|
|
|
fclose(infile);
|
|
|
|
}
|
|
|
|
put_hex(buff,buffsiz,recnum)
|
|
|
|
FAST char *buff;
|
|
|
|
FAST int buffsiz,recnum;
|
|
|
|
{
|
|
|
|
FAST int checksum,n;
|
|
|
|
|
|
|
|
printf(";%02x%04x",buffsiz,recnum);
|
|
|
|
checksum = buffsiz + (recnum & 0x00ff) + ((recnum >> 8) & 0x00ff);
|
|
|
|
while ((buffsiz--)>0) {
|
|
|
|
n = *buff++;
|
|
|
|
n &= 0x00ff;
|
|
|
|
checksum += n;
|
|
|
|
printf("%02x",n);
|
|
|
|
}
|
|
|
|
printf("%04x\n",checksum);
|
|
|
|
}
|
|
|
|
buffsiz--)>0) {
|
|
|
|
n = *buff++;
|
|
|
|
n &= 0x00ff;
|
|
|
|
checksum += n;
|
|
|
|
printf("%02x",n);
|
|
|
|
}
|
|
|
|
printf("% |