/** @name makebin - turn a .ihx file into a binary image.
*/
+#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
+#include <string.h>
+
+#if defined(__BORLANDC__) || defined(__MINGW32__) || defined(__CYGWIN__)
+ #include <fcntl.h>
+ #include <io.h>
+#endif
+
typedef unsigned char BYTE;
"Usage: makebin [-p] [-s romsize] [-h]\n");
}
+void fixStdout(void)
+{
+ #if defined(__BORLANDC__) || defined(__MINGW32__) || defined(__CYGWIN__)
+ setmode(fileno(stdout), O_BINARY);
+ #endif
+}
+
+
int main(int argc, char **argv)
{
int size = 32768, pack = 0, real_size = 0;
BYTE *rom;
+ size_t res;
char line[256];
char *p;
argc--;
argv++;
+ fixStdout();
+
while (argc--) {
if (**argv != '-') {
usage();
real_size = addr;
}
- if (pack)
- fwrite(rom, 1, real_size, stdout);
- else
- fwrite(rom, 1, size, stdout);
+ if (pack) {
+ res = fwrite(rom, 1, real_size, stdout);
+ assert(res == real_size);
+ } else {
+ res = fwrite(rom, 1, size, stdout);
+ assert(res == size);
+ }
return 0;
}