1 /** @name makebin - turn a .ihx file into a binary image.
8 #if defined(__BORLANDC__) || defined(__MINGW32__) || defined(__CYGWIN__)
14 typedef unsigned char BYTE;
16 #define FILL_BYTE 0xFF
18 int getnibble(char **p)
20 int ret = *((*p)++) - '0';
29 return (getnibble(p) << 4) | getnibble(p);
35 "makebin: convert a Intel IHX file to binary.\n"
36 "Usage: makebin [-p] [-s romsize] [-h]\n");
41 #if defined(__BORLANDC__) || defined(__MINGW32__) || defined(__CYGWIN__)
42 setmode(fileno(stdout), O_BINARY);
47 int main(int argc, char **argv)
49 int size = 32768, pack = 0, real_size = 0;
89 fprintf(stderr, "error: couldn't allocate room for the image.\n");
92 memset(rom, FILL_BYTE, size);
93 while (fgets(line, 256, stdin) != NULL) {
98 fprintf(stderr, "error: invalid IHX line.\n");
102 nbytes = getbyte(&p);
103 addr = getbyte(&p)<<8 | getbyte(&p);
108 rom[addr++] = getbyte(&p);
111 if (addr > real_size)
116 fwrite(rom, 1, real_size, stdout);
118 fwrite(rom, 1, size, stdout);