1 /** @name makebin - turn a .ihx file into a binary image.
8 typedef unsigned char BYTE;
10 #define FILL_BYTE 0xFF
12 int getnibble(char **p)
14 int ret = *((*p)++) - '0';
23 return (getnibble(p) << 4) | getnibble(p);
29 "makebin: convert a Intel IHX file to binary.\n"
30 "Usage: makebin [-p] [-s romsize] [-h]\n");
33 int main(int argc, char **argv)
35 int size = 32768, pack = 0, real_size = 0;
73 fprintf(stderr, "error: couldn't allocate room for the image.\n");
76 memset(rom, FILL_BYTE, size);
77 while (fgets(line, 256, stdin) != NULL) {
82 fprintf(stderr, "error: invalid IHX line.\n");
87 addr = getbyte(&p)<<8 | getbyte(&p);
92 rom[addr++] = getbyte(&p);
100 fwrite(rom, 1, real_size, stdout);
102 fwrite(rom, 1, size, stdout);