1 /** @name makebin - turn a .ihx file into a binary image.
9 #if defined(__BORLANDC__) || defined(__MINGW32__) || defined(__CYGWIN__)
15 typedef unsigned char BYTE;
17 #define FILL_BYTE 0xFF
19 int getnibble(char **p)
21 int ret = *((*p)++) - '0';
30 return (getnibble(p) << 4) | getnibble(p);
36 "makebin: convert a Intel IHX file to binary.\n"
37 "Usage: makebin [-p] [-s romsize] [-h]\n");
42 #if defined(__BORLANDC__) || defined(__MINGW32__) || defined(__CYGWIN__)
43 setmode(fileno(stdout), O_BINARY);
48 int main(int argc, char **argv)
50 int size = 32768, pack = 0, real_size = 0;
91 fprintf(stderr, "error: couldn't allocate room for the image.\n");
94 memset(rom, FILL_BYTE, size);
95 while (fgets(line, 256, stdin) != NULL) {
100 fprintf(stderr, "error: invalid IHX line.\n");
104 nbytes = getbyte(&p);
105 addr = getbyte(&p)<<8 | getbyte(&p);
110 rom[addr++] = getbyte(&p);
113 if (addr > real_size)
118 res = fwrite(rom, 1, real_size, stdout);
119 assert(res == real_size);
121 res = fwrite(rom, 1, size, stdout);