1 /** @name makebin - turn a .ihx file into a binary image.
7 typedef unsigned char BYTE;
11 int getnibble(char **p)
13 int ret = *((*p)++) - '0';
22 return (getnibble(p) << 4) | getnibble(p);
25 int main(int argc, char **argv)
33 while ((opt = getopt(argc, argv, "s:h"))!=-1) {
39 printf("makebin: convert a Intel IHX file to binary.\n"
40 "Usage: %s [-s romsize] [-h]\n", argv[0]);
46 fprintf(stderr, "error: couldn't allocate room for the image.\n");
49 memset(rom, FILL_BYTE, size);
50 while (fgets(line, 256, stdin) != NULL) {
55 fprintf(stderr, "error: invalid IHX line.\n");
60 addr = getbyte(&p)<<8 | getbyte(&p);
65 rom[addr++] = getbyte(&p);
68 fwrite(rom, 1, size, stdout);