From 8a8b59f19b434e3519502d5506d88046e645078f Mon Sep 17 00:00:00 2001 From: Raphael Assenat Date: Sat, 3 Oct 2015 12:00:31 -0400 Subject: [PATCH] Add .hex file loader --- tool/Makefile | 2 +- tool/ihex.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++ tool/ihex.h | 7 +++ 3 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 tool/ihex.c create mode 100644 tool/ihex.h diff --git a/tool/Makefile b/tool/Makefile index 9b77c0d..c23f3c7 100644 --- a/tool/Makefile +++ b/tool/Makefile @@ -8,7 +8,7 @@ PREFIX=/usr/local PROG=gcn64ctl -OBJS=main.o gcn64.o mempak.o gcn64lib.o hexdump.o gc2n64_adapter.o +OBJS=main.o gcn64.o mempak.o gcn64lib.o hexdump.o gc2n64_adapter.o ihex.o .PHONY : clean install diff --git a/tool/ihex.c b/tool/ihex.c new file mode 100644 index 0000000..1422d5b --- /dev/null +++ b/tool/ihex.c @@ -0,0 +1,129 @@ +#include +#include +#include "hexdump.h" + +static unsigned char chk(unsigned char *buf, int len) +{ + int i; + unsigned char r = 0; + + for (i=0; i bufsize) { + fprintf(stderr, "hex file too large\n"); + ret = -6; + goto err; + } + if (address + data_count > max_address) { + max_address = address + data_count; + } + memcpy(dstbuf + address, databuf + 4, data_count); + break; + + case 0x01: // EOF + eof_seen = 1; + break; + + default: + case 0x02: // Extended segment address + case 0x03: // Start segment address + case 0x04: // Extended linear address + case 0x05: // Start linear address + fprintf(stderr, "ihex parser: Unimplemented record type 0x%02x\n", databuf[3]); + ret = -2; + goto err; + } + + } + } while (!feof(fptr)); + + return max_address; + +err: + fclose(fptr); + return ret; +} diff --git a/tool/ihex.h b/tool/ihex.h new file mode 100644 index 0000000..a55d5d6 --- /dev/null +++ b/tool/ihex.h @@ -0,0 +1,7 @@ +#ifndef _ihex_h__ +#define _ihex_h__ + +int load_ihex(const char *file, unsigned char *dstbuf, int bufsize); + +#endif // _ihex_h__ +