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)
28 int size = 32768, pack = 0, real_size = 0;
33 while ((opt = getopt(argc, argv, "ps:h"))!=-1) {
39 printf("makebin: convert a Intel IHX file to binary.\n"
40 "Usage: %s [-p] [-s romsize] [-h]\n", argv[0]);
51 fprintf(stderr, "error: couldn't allocate room for the image.\n");
54 memset(rom, FILL_BYTE, size);
55 while (fgets(line, 256, stdin) != NULL) {
60 fprintf(stderr, "error: invalid IHX line.\n");
65 addr = getbyte(&p)<<8 | getbyte(&p);
70 rom[addr++] = getbyte(&p);
78 fwrite(rom, 1, real_size, stdout);
80 fwrite(rom, 1, size, stdout);