* Added a simple Intel IHX to ROM image converter. Will be removed when
authormichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 6 Feb 2000 19:08:17 +0000 (19:08 +0000)
committermichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 6 Feb 2000 19:08:17 +0000 (19:08 +0000)
  link-z80 supports blobs directly.

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@70 4a8a32a2-be11-0410-ad9d-d568d2c75423

device/lib/z80/string.c [new file with mode: 0644]
support/makebin/Makefile [new file with mode: 0644]
support/makebin/makebin.c [new file with mode: 0644]

diff --git a/device/lib/z80/string.c b/device/lib/z80/string.c
new file mode 100644 (file)
index 0000000..4e3583b
--- /dev/null
@@ -0,0 +1,33 @@
+/* Dumb strings stub.
+   Wanted a quick hack for now - will use the libc version later.
+*/
+char *strcpy(char *dest, const char *source)
+{
+    char *ret = dest;
+    while (*dest++ = *source++);
+    return ret;
+}
+
+void *memcpy(void *dest, const void *source, int count)
+{
+    char *d = dest;
+    const char *s = source;
+    while (count--)
+       *d++ = *s++;
+
+    return dest;
+}
+
+int strcmp(const char *s1, const char *s2)
+{
+    int ret = 0;
+
+    while (!(ret = *s1 - *s2) && *s2)
+       ++s1, ++s2;
+
+    if (ret < 0)
+       return -1;
+    else if (ret > 0)
+       return 1;
+    return 0;
+}
diff --git a/support/makebin/Makefile b/support/makebin/Makefile
new file mode 100644 (file)
index 0000000..481910c
--- /dev/null
@@ -0,0 +1,10 @@
+BIN = makebin
+OBJ = makebin.o
+
+all: $(BIN)
+
+clean:
+       rm -f $(BIN) $(OBJ) *~
+
+install: all
+       install --strip $(BIN) /usr/bin
\ No newline at end of file
diff --git a/support/makebin/makebin.c b/support/makebin/makebin.c
new file mode 100644 (file)
index 0000000..f650b3d
--- /dev/null
@@ -0,0 +1,70 @@
+/** @name makebin - turn a .ihx file into a binary image.
+ */
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+typedef unsigned char BYTE;
+
+#define FILL_BYTE 0xFF
+
+int getnibble(char **p)
+{
+  int ret = *((*p)++) - '0';
+  if (ret > 9) {
+    ret -= 'A' - '9' - 1;
+  }
+  return ret;
+}
+
+int getbyte(char **p)
+{
+  return (getnibble(p) << 4) | getnibble(p);
+}
+
+int main(int argc, char **argv)
+{
+    int opt;
+    int size = 32768;
+    BYTE *rom;
+    char line[256];
+    char *p;
+
+    while ((opt = getopt(argc, argv, "s:h"))!=-1) {
+       switch (opt) {
+       case 's':
+           size = atoi(optarg);
+           break;
+       case 'h':
+           printf("makebin: convert a Intel IHX file to binary.\n"
+                  "Usage: %s [-s romsize] [-h]\n", argv[0]);
+           return 0;
+       }
+    }
+    rom = malloc(size);
+    if (rom == NULL) {
+       fprintf(stderr, "error: couldn't allocate room for the image.\n");
+       return -1;
+    }
+    memset(rom, FILL_BYTE, size);
+    while (fgets(line, 256, stdin) != NULL) {
+       int nbytes;
+       int addr;
+
+       if (*line != ':') {
+           fprintf(stderr, "error: invalid IHX line.\n");
+           return -2;
+       }
+       p = line+1;
+       nbytes = getbyte(&p);
+       addr = getbyte(&p)<<8 | getbyte(&p);
+       getbyte(&p);
+
+       while (nbytes--) {
+           if (addr < size)
+               rom[addr++] = getbyte(&p);
+       }
+    }
+    fwrite(rom, 1, size, stdout);
+    return 0;
+}