From 26ade836b415681f8fba4b5331f98f3e937e5899 Mon Sep 17 00:00:00 2001 From: matsutsuka Date: Tue, 15 Dec 2009 07:13:14 +0000 Subject: [PATCH] synchronized with updated version; fixed Unix environment handling --- tools/z80/hex2bin/Makefile | 8 ++-- tools/z80/hex2bin/README.txt | 23 +++++------ tools/z80/hex2bin/src/hexameter.c | 66 ++++++++++++++++--------------- tools/z80/hex2bin/src/ihx2bin.c | 55 ++++++++++++-------------- tools/z80/hex2bin/src/ihx2bin.h | 4 +- 5 files changed, 77 insertions(+), 79 deletions(-) diff --git a/tools/z80/hex2bin/Makefile b/tools/z80/hex2bin/Makefile index 65aa70a5b..fc6bbe659 100644 --- a/tools/z80/hex2bin/Makefile +++ b/tools/z80/hex2bin/Makefile @@ -2,11 +2,11 @@ # Makefile for hexameter # @author Takahide Matsutsuka # -# $Id: Makefile,v 1.2 2008/07/20 07:44:39 matsutsuka Exp $ +# $Id: Makefile,v 1.3 2009/12/15 07:13:14 matsutsuka Exp $ # -CFLAGS = -std=c99 -g -mno-cygwin -Wall -#CFLAGS = -std=c99 -g -Wall +#CFLAGS = -std=c99 -g -mno-cygwin -Wall +CFLAGS = -g -Wall SOURCEDIR = src SOURCES = hexameter.c ihx2bin.c OBJECTDIR = bin @@ -24,7 +24,7 @@ hexameter: $(OBJECTS) clean: rm -rf bin rm -f *~ *.stackdump - rm -f *~ hexameter.exe + rm -f *~ hexameter hexameter.exe $(OBJECTDIR)/%.o: %.c $(CC) $(CFLAGS) -c $< -o $@ diff --git a/tools/z80/hex2bin/README.txt b/tools/z80/hex2bin/README.txt index ff3f17875..f45f498b8 100644 --- a/tools/z80/hex2bin/README.txt +++ b/tools/z80/hex2bin/README.txt @@ -58,7 +58,7 @@ b) Compile your code using SDCC. default crt0 object. The customized crt0.o file is in lib directory of this release. -c) Convert ihx file to cas file using hex2cas. +c) Convert ihx file to cas file using hexameter hexameter [ihx_file|binary_file ...] The ihx files are just attached in the specified order. @@ -144,17 +144,18 @@ For type 03 (byte) and 04 (word), bytes field has no effect. 6/ History -3/29/2003 1.0.0 First version -4/20/2003 1.0.1 Mode option has been added -9/01/2007 1.1.0 ROM-mode has been added -9/28/2007 1.2.0 Customized crt0 has been introduced to clear global data -3/15/2008 1.3.0 VRAM options introduced -4/28/2008 1.4.0 Header file option introduced - -5/17/2008 2.0.0 Migrated to hexameter, to support more flexible configurations -7/16/2008 2.1.0 Support arguments in ihx file, remove prefix/suffix instead -7/18/2008 2.1.1 Cygwin dependency has been removed +03/29/2003 1.0.0 First version +04/20/2003 1.0.1 Mode option has been added +09/01/2007 1.1.0 ROM-mode has been added +09/28/2007 1.2.0 Customized crt0 has been introduced to clear global data +03/15/2008 1.3.0 VRAM options introduced +04/28/2008 1.4.0 Header file option introduced +05/17/2008 2.0.0 Migrated to hexameter, to support more flexible configurations +07/16/2008 2.1.0 Support arguments in ihx file, remove prefix/suffix instead +07/18/2008 2.1.1 Cygwin dependency has been removed +10/02/2008 2.1.2 Template for sdos 1.1 has been added +12/14/2009 2.1.3 A minor bug in Linux environment has been fixed Enjoy! diff --git a/tools/z80/hex2bin/src/hexameter.c b/tools/z80/hex2bin/src/hexameter.c index 29b6a2547..5cb32d8ef 100644 --- a/tools/z80/hex2bin/src/hexameter.c +++ b/tools/z80/hex2bin/src/hexameter.c @@ -1,41 +1,38 @@ /* - * Copyright (c) 2003-2008, Takahide Matsutsuka. - * All rights reserved. + * Copyright (c) 2003-2009, Takahide Matsutsuka. + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. The end-user documentation included with the redistribution, if - * any, must include the following acknowlegement: - * "This product includes software developed by Takahide Matsutsuka." - * Alternately, this acknowlegement may appear in the software itself, - * if and wherever such third-party acknowlegements normally appear. - * 4. The name of the author may not be used to endorse or promote + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote * products derived from this software without specific prior - * written permission. + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id: hexameter.c,v 1.3 2009/12/15 07:13:14 matsutsuka Exp $ * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. */ /* - * A main file for hex2cas. + * A main file for hexameter. */ #define MAX_PATH 1024 @@ -151,8 +148,8 @@ unsigned char analyzeOption(int argc, char **argv, Configuration *config) { break; case 'h': - printf("Hexameter: Convert Intel HEX file (ihx) to binary file, ver. 2.1.0\n"); - printf("Copyright (c) 2003-2008 Takahide Matsutsuka \n"); + printf("Hexameter: Convert Intel HEX file (ihx) to binary file, ver. 2.1.3\n"); + printf("Copyright (c) 2003-2009 Takahide Matsutsuka \n"); printf("Usage: hexameter [options] [...]\n"); printf("Options:\n"); printf(" -v verbose output\n"); @@ -299,15 +296,20 @@ int main(int argc, char **argv) { memset(&config, 0, sizeof(Configuration)); +#ifndef __CYGWIN__ + r = analyzeOption(argc, argv, &config); + if (r) { + return r; + } +#endif while (optind < argc) { +#ifdef __CYGWIN__ r = analyzeOption(argc, argv, &config); if (r) { return r; } - if (optind == argc) { - break; - } - if (config.length == MAXFILES) { +#endif + if (config.length >= MAXFILES) { printf("too much files specified\n"); return 1; } diff --git a/tools/z80/hex2bin/src/ihx2bin.c b/tools/z80/hex2bin/src/ihx2bin.c index 199f9ccc4..5724a4ffe 100644 --- a/tools/z80/hex2bin/src/ihx2bin.c +++ b/tools/z80/hex2bin/src/ihx2bin.c @@ -1,37 +1,34 @@ /* * Copyright (c) 2003-2008, Takahide Matsutsuka. - * All rights reserved. + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. The end-user documentation included with the redistribution, if - * any, must include the following acknowlegement: - * "This product includes software developed by Takahide Matsutsuka." - * Alternately, this acknowlegement may appear in the software itself, - * if and wherever such third-party acknowlegements normally appear. - * 4. The name of the author may not be used to endorse or promote + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * 3. The name of the author may not be used to endorse or promote * products derived from this software without specific prior - * written permission. + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id: ihx2bin.c,v 1.3 2009/12/15 07:13:14 matsutsuka Exp $ * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. */ /* @@ -53,7 +50,7 @@ typedef struct { unsigned int start; unsigned int end; - unsigned char buffer[MEMORY_SIZE]; + char buffer[MEMORY_SIZE]; // current line int type; unsigned int address; @@ -127,15 +124,13 @@ void replace(FILE* in, struct ConvertInfo *info, Memory *memory) { if (!strcmp(name, info->defs[i].name)) { int tmp; char value[DEF_VALUELEN]; + memset(value, 0, DEF_VALUELEN); // replace! switch (memory->type) { case TYPE_STRING: - for (j = 0; j < memory->length; j++) { - memory->buffer[memory->address] = value[j] = info->defs[i].value[j]; - memory->address++; - } - value[j] = 0; + strncpy(&memory->buffer[memory->address], info->defs[i].value, memory->length); + strncpy(value, &memory->buffer[memory->address], memory->length); if (info->verbose) { printf("[%s]->[%s], ", name, value); } diff --git a/tools/z80/hex2bin/src/ihx2bin.h b/tools/z80/hex2bin/src/ihx2bin.h index afa05f42c..43c0c11ce 100644 --- a/tools/z80/hex2bin/src/ihx2bin.h +++ b/tools/z80/hex2bin/src/ihx2bin.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2007, Takahide Matsutsuka. + * Copyright (c) 2003-2008, Takahide Matsutsuka. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,7 +27,7 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: ihx2bin.h,v 1.2 2008/07/20 07:44:39 matsutsuka Exp $ + * $Id: ihx2bin.h,v 1.3 2009/12/15 07:13:14 matsutsuka Exp $ * */