From da5ade526c6f614e337918af7d56e9fcd9ccb180 Mon Sep 17 00:00:00 2001 From: michaelh Date: Sun, 6 Feb 2000 19:08:17 +0000 Subject: [PATCH] * Added a simple Intel IHX to ROM image converter. Will be removed when 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 | 33 ++++++++++++++++++ support/makebin/Makefile | 10 ++++++ support/makebin/makebin.c | 70 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 device/lib/z80/string.c create mode 100644 support/makebin/Makefile create mode 100644 support/makebin/makebin.c diff --git a/device/lib/z80/string.c b/device/lib/z80/string.c new file mode 100644 index 00000000..4e3583b2 --- /dev/null +++ b/device/lib/z80/string.c @@ -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 index 00000000..481910c7 --- /dev/null +++ b/support/makebin/Makefile @@ -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 index 00000000..f650b3d2 --- /dev/null +++ b/support/makebin/makebin.c @@ -0,0 +1,70 @@ +/** @name makebin - turn a .ihx file into a binary image. + */ +#include +#include +#include + +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; +} -- 2.30.2