? bla.patch ? nesasm ? pceas ? pceas.patch ? test Index: Makefile =================================================================== RCS file: /cvs/huc/src/mkit/as/Makefile,v retrieving revision 1.7 diff -u -p -r1.7 Makefile --- Makefile 9 Apr 2005 15:32:06 -0000 1.7 +++ Makefile 19 Jun 2007 20:40:08 -0000 @@ -4,6 +4,7 @@ # # Defines # +CC=gcc BASEDIR=..d ..d .. include ../../Make_src.inc Index: expr.c =================================================================== RCS file: /cvs/huc/src/mkit/as/expr.c,v retrieving revision 1.1 diff -u -p -r1.1 expr.c --- expr.c 25 Apr 2001 03:49:07 -0000 1.1 +++ expr.c 19 Jun 2007 20:40:08 -0000 @@ -350,7 +350,7 @@ cont: } /* convert back the pointer to an array index */ - *ip = (int)expr - (int)prlnbuf; + *ip = (int)(expr - prlnbuf); /* ok */ return (1); Index: expr.h =================================================================== RCS file: /cvs/huc/src/mkit/as/expr.h,v retrieving revision 1.1 diff -u -p -r1.1 expr.h --- expr.h 25 Apr 2001 03:49:07 -0000 1.1 +++ expr.h 19 Jun 2007 20:40:08 -0000 @@ -50,14 +50,14 @@ int op_pri[] = { }; unsigned int op_stack[64] = { OP_START }; /* operator stack */ -unsigned int val_stack[64]; /* value stack */ -int op_idx, val_idx; /* index in the operator and value stacks */ -int need_operator; /* when set await an operator, else await a value */ -unsigned char *expr; /* pointer to the expression string */ -unsigned char *expr_stack[16]; /* expression stack */ -struct t_symbol *expr_lablptr; /* pointer to the lastest label */ -int expr_lablcnt; /* number of label seen in an expression */ -char *keyword[8] = { /* predefined functions */ +unsigned int val_stack[64]; /* value stack */ +int op_idx, val_idx; /* index in the operator and value stacks */ +int need_operator; /* when set await an operator, else await a value */ +char *expr; /* pointer to the expression string */ +char *expr_stack[16]; /* expression stack */ +struct t_symbol *expr_lablptr; /* pointer to the lastest label */ +int expr_lablcnt; /* number of label seen in an expression */ +char *keyword[8] = { /* predefined functions */ "\7DEFINED", "\4HIGH", "\3LOW", "\4PAGE", "\4BANK", Index: externs.h =================================================================== RCS file: /cvs/huc/src/mkit/as/externs.h,v retrieving revision 1.1 diff -u -p -r1.1 externs.h --- externs.h 25 Apr 2001 03:49:07 -0000 1.1 +++ externs.h 19 Jun 2007 20:40:08 -0000 @@ -29,7 +29,7 @@ extern int pcx_nb_args; /* number of ar extern unsigned int pcx_arg[8]; /* PCX args array */ extern unsigned char *pcx_buf; /* pointer to the PCX buffer */ extern unsigned char pcx_pal[256][3]; /* palette */ -extern unsigned char *expr; /* expression string pointer */ +extern char *expr; /* expression string pointer */ extern int mopt; extern int in_macro; extern int expand_macro; Index: input.c =================================================================== RCS file: /cvs/huc/src/mkit/as/input.c,v retrieving revision 1.1 diff -u -p -r1.1 input.c --- input.c 25 Apr 2001 03:49:07 -0000 1.1 +++ input.c 19 Jun 2007 20:40:08 -0000 @@ -6,50 +6,136 @@ #include "externs.h" #include "protos.h" +#define INITIAL_PATH_SIZE 64 +#define INCREMENT_BASE 16 +#define INCREMENT_BASE_MASK 15 + int infile_error; int infile_num; struct t_input_info input_file[8]; -char incpath[10][128]; +static char *incpath = NULL; +static int *str_offset = NULL; +static int remaining = 0; +static int incpathSize = 0; +static int str_offsetCount = 0; +static int incpathCount = 0; + +/* ---- + * void cleanup_path() + * ---- + * clean up allocated paths + */ +void +cleanup_path(void) +{ + if(incpath) + free(incpath); + + if(str_offset) + free(str_offset); +} + +/* ---- + * int add_path(char*, int) + * ---- + * add a path to includes + */ +int +add_path(char* path, int l) +{ + /* Expand str_offset array if needed */ + if(incpathCount >= str_offsetCount) + { + str_offsetCount += INCREMENT_BASE; + str_offset = (int*)realloc(str_offset, str_offsetCount * sizeof(int)); + if(str_offset == NULL) + return 0; + } + + /* Initialize string offset */ + str_offset[incpathCount] = incpathSize - remaining; + + /* Realloc string buffer if needed */ + if(remaining < l) + { + remaining = incpathSize; + /* evil trick, get the greater multiple of INCREMENT_BASE closer + to (size + l). Note : this only works for INCREMENT_BASE = 2^n*/ + incpathSize = ((incpathSize + l) + INCREMENT_BASE) & ~INCREMENT_BASE_MASK; + remaining = incpathSize - remaining; + incpath = (char*)realloc(incpath, incpathSize); + if(incpath == NULL) + return 0; + } + + remaining -= l; + + /* Copy path */ + strncpy(incpath + str_offset[incpathCount], path, l); + incpath[str_offset[incpathCount] + l - 1] = '\0'; + + ++incpathCount; + + return 1; +} +#ifdef WIN32 +#define ENV_PATH_SEPARATOR ';' +#else +#define ENV_PATH_SEPARATOR ':' +#endif /* ---- - * init_path() + * int init_path() * ---- * init the include path */ -void +int init_path(void) { char *p,*pl; - int i, l; + int ret, l; + /* Get env variable holding PCE path*/ p = getenv(machine->include_env); if (p == NULL) - return; + return 2; - for (i = 0; i < 10; i++) { - - pl = strchr(p, ';'); - - if (pl == NULL) - l = strlen(p); + l = 0; + pl = p; + while(pl != NULL) + { + + /* Jump to next separator */ + pl = strchr(p, ENV_PATH_SEPARATOR); + + /* Compute new substring size */ + if(pl == NULL) + l = strlen(p) + 1; else - l = pl-p; - - if (l == 0) { - incpath[i][0] = '\0'; - } else { - strncpy(incpath[i],p,l); - p += l; - while (*p == ';') p++; + l = pl - p + 1; + + /* Might be empty, jump to next char */ + if(l <= 1) + { + ++p; + continue; } - if (incpath[i][strlen(incpath[i])] != PATH_SEPARATOR) { - strcat(incpath[i], PATH_SEPARATOR_STRING); - } + /* Add path */ + ret = add_path(p, l); + if(!ret) + return 0; + + /* Eat remaining separators */ + while (*p == ENV_PATH_SEPARATOR) ++p; + + p += l; } + + return 1; } @@ -329,11 +415,12 @@ open_file(char *name, char *mode) fileptr = fopen(name, mode); if (fileptr != NULL) return(fileptr); - for (i = 0; i < 10; i++) { - if (strlen(incpath[i])) { - strcpy(testname, incpath[i]); + for (i = 0; i < incpathCount; ++i) { + if (strlen(incpath+str_offset[i])) { + strcpy(testname, incpath+str_offset[i]); + strcat(testname, PATH_SEPARATOR_STRING); strcat(testname, name); - + fileptr = fopen(testname, mode); if (fileptr != NULL) break; } Index: main.c =================================================================== RCS file: /cvs/huc/src/mkit/as/main.c,v retrieving revision 1.12 diff -u -p -r1.12 main.c --- main.c 18 Mar 2002 08:34:28 -0000 1.12 +++ main.c 19 Jun 2007 20:40:09 -0000 @@ -25,6 +25,7 @@ #include #include #include +#include #include "defs.h" #include "externs.h" #include "protos.h" @@ -63,6 +64,15 @@ int list_level; /* output level */ int asm_opt[8]; /* assembler options */ int zero_need; /* counter for trailing empty sectors on CDROM */ +/* ---- + * atexit callback + * ---- + */ +void +cleanup(void) +{ + cleanup_path(); +} /* ---- * main() @@ -75,10 +85,33 @@ main(int argc, char **argv) FILE *fp, *ipl; char *p; char cmd[80]; - int i, j; + int i, j, opt; int file; int ram_bank; + int cd_type; + char need_setup; + char cmd_line_options[] = "sSl:mhI:"; + struct option cmd_line_long_options[] = { + {"segment", 0, 0, 's'}, + {"fullsegment", 0, 0, 'S'}, + {"listing", 1, 0, 'l'}, + {"macro", 0, 0, 'm'}, + {"raw", 0, &header_opt, 0 }, + {"cd", 0, &cd_type, 1 }, + {"scd", 0, &cd_type, 2 }, + {"over", 0, &overlayflag, 1 }, + {"overlay", 0, &overlayflag, 1 }, + {"dev", 0, &develo_opt, 1 }, + {"develo", 0, &develo_opt, 1 }, + {"mx", 0, &mx_opt, 1 }, + {"srec", 0, &srec_opt, 1 }, + {"help", 0, 0, 'h'}, + {0, 0, 0, 0 } + }; + /* register atexit callback */ + atexit(cleanup); + /* get program name */ if ((prg_name = strrchr(argv[0], '/')) != NULL) prg_name++; @@ -111,91 +144,82 @@ main(int argc, char **argv) cd_opt = 0; mx_opt = 0; file = 0; - + cd_type = 0; + + need_setup = 1; + /* display assembler version message */ printf("%s\n\n", machine->asm_title); - - /* parse command line */ - if (argc > 1) { - for (i = 1; i < argc; i++) { - if (argv[i][0] == '-') { - /* segment usage */ - if (!strcmp(argv[i], "-s")) - dump_seg = 1; - else if (!strcmp(argv[i], "-S")) - dump_seg = 2; - - /* forces macros expansion */ - else if (!strcmp(argv[i], "-m")) - mlist_opt = 1; - - /* no header */ - else if (!strcmp(argv[i], "-raw")) - header_opt = 0; - - /* output s-record file */ - else if (!strcmp(argv[i], "-srec")) - srec_opt = 1; - - /* output level */ - else if (!strncmp(argv[i], "-l", 2)) { - /* get level */ - if (strlen(argv[i]) == 2) - list_level = atol(argv[++i]); - else - list_level = atol(&argv[i][2]); - - /* check range */ - if (list_level < 0 || list_level > 3) - list_level = 2; - } - - /* help */ - else if (!strcmp(argv[i], "-?")) { - help(); - return (0); + + while ((opt = getopt_long (argc, argv, cmd_line_options, cmd_line_long_options, &i)) > 0) + { + switch(opt) + { + case 's': + dump_seg = 1; + break; + + case 'S': + dump_seg = 2; + break; + + case 'l': + /* get level */ + list_level = atol(optarg); + + /* check range */ + if (list_level < 0 || list_level > 3) + list_level = 2; + break; + + case 'm': + mlist_opt = 1; + break; + + case 'I': + if(!add_path(optarg, strlen(optarg)+1)) + { + printf("Error while adding include path\n"); + return 0; } + break; + + case 'h': + help(); + return 0; + + default: + return 1; + } + } - else { - /* PCE specific functions */ - if (machine->type == MACHINE_PCE) { - /* cd-rom */ - if (!strcmp(argv[i], "-cd")) { - cd_opt = STANDARD_CD; - scd_opt = 0; - } - - /* super cd-rom */ - else if (!strcmp(argv[i], "-scd")) { - scd_opt = SUPER_CD; - cd_opt = 0; - } - - /* cd-rom overlay */ - else if (!strcmp(argv[i], "-over")) - overlayflag = 1; - else if (!strcmp(argv[i], "-overlay")) - overlayflag = 1; - - /* develo auto-run */ - else if (!strcmp(argv[i], "-develo")) - develo_opt = 1; - else if (!strcmp(argv[i], "-dev")) - develo_opt = 1; - - /* output mx file */ - else if (!strcmp(argv[i], "-mx")) - mx_opt = 1; - } - } - } - else { - strcpy(in_fname, argv[i]); - file++; - } - } + /* check for missing asm file */ + if(optind == argc) + { + fprintf(stderr, "Missing input file\n"); + return 0; + } + + /* get file names */ + for ( ; optind < argc; ++optind, ++file) { + strcpy(in_fname, argv[optind]); } + /* Adjust cdrom type values ... */ + switch(cd_type) { + case 1: + /* cdrom */ + cd_opt = STANDARD_CD; + scd_opt = 0; + break; + + case 2: + /* super cdrom */ + scd_opt = SUPER_CD; + cd_opt = 0; + break; + } + if ( (overlayflag == 1) && ((scd_opt == 0) && (cd_opt == 0)) ) { @@ -238,7 +262,8 @@ main(int argc, char **argv) strcat(in_fname, ".asm"); /* init include path */ - init_path(); + if(!init_path()) + return 0; /* init crc functions */ crc_init(); @@ -607,21 +632,27 @@ help(void) prg_name = machine->asm_name; /* display help */ - printf("%s [-options] [-? (for help)] infile\n\n", prg_name); - printf("-s/S : show segment usage\n"); - printf("-l # : listing file output level (0-3)\n"); - printf("-m : force macro expansion in listing\n"); - printf("-raw : prevent adding a ROM header\n"); + printf("%s [-options] [-h (for help)] infile\n\n", prg_name); + printf("-s/S : show segment usage\n" + "--segment/fullsegment\n" + "-l # : listing file output level (0-3)\n" + "--listing #\n" + "-m : force macro expansion in listing\n" + "--macro\n" + "--raw : prevent adding a ROM header\n" + "-I : add include path\n"); if (machine->type == MACHINE_PCE) { - printf("-cd : create a CD-ROM track image\n"); - printf("-scd : create a Super CD-ROM track image\n"); - printf("-over(lay) : create an executable 'overlay' program segment\n"); - printf("-dev : assemble and run on the Develo Box\n"); - printf("-mx : create a Develo MX file\n"); - } - printf("-srec : create a Motorola S-record file\n"); - printf("infile : file to be assembled\n"); - printf("\n"); + printf("--cd : create a CD-ROM track image\n" + "--scd : create a Super CD-ROM track image\n" + "--over(lay) : create an executable 'overlay' program segment\n" + "--dev(elo) : assemble and run on the Develo Box\n" + "--mx : create a Develo MX file\n"); + } + printf("--srec : create a Motorola S-record file\n" + "-h : help. Displays this message\n" + "--help\n"); + + printf("infile : file to be assembled\n\n"); } Index: map.c =================================================================== RCS file: /cvs/huc/src/mkit/as/map.c,v retrieving revision 1.1 diff -u -p -r1.1 map.c --- map.c 25 Apr 2001 03:49:07 -0000 1.1 +++ map.c 19 Jun 2007 20:40:09 -0000 @@ -41,7 +41,7 @@ pce_load_map(char *fname, int mode) (header[6] << 8) + header[7] - 4; - if (strncmp(header, "FORM", 4) || strncmp(&header[8], "FMAP", 4)) { + if (strncmp((char*)header, "FORM", 4) || strncmp((char*)(header+8), "FMAP", 4)) { /* incorrect header */ if (mode) fatal_error("Invalid FMP format!"); @@ -69,7 +69,7 @@ pce_load_map(char *fname, int mode) break; /* BODY chunk */ - if (strncmp(header, "BODY", 4) == 0) { + if (strncmp((char*)header, "BODY", 4) == 0) { /* add size */ cnt += (size >> 1); Index: pcx.c =================================================================== RCS file: /cvs/huc/src/mkit/as/pcx.c,v retrieving revision 1.2 diff -u -p -r1.2 pcx.c --- pcx.c 25 Apr 2001 04:59:42 -0000 1.2 +++ pcx.c 19 Jun 2007 20:40:09 -0000 @@ -309,9 +309,9 @@ pcx_get_args(int *ip) */ int -pcx_parse_args(int i, int nb, int *a, int *b, int *c, int *d, int size) +pcx_parse_args(int i, int nb, unsigned int *a, unsigned int *b, unsigned int *c, unsigned int *d, int size) { - int x, y, w, h; + unsigned int x, y, w, h; x = 0; y = 0; Index: protos.h =================================================================== RCS file: /cvs/huc/src/mkit/as/protos.h,v retrieving revision 1.3 diff -u -p -r1.3 protos.h --- protos.h 23 May 2001 04:22:02 -0000 1.3 +++ protos.h 19 Jun 2007 20:40:09 -0000 @@ -68,10 +68,12 @@ int func_extract(int ip); int func_getargs(void); /* INPUT.C */ -void init_path(void); -int readline(void); -int open_input(char *name); -int close_input(void); +void cleanup_path(void); +int add_path(char*, int); +int init_path(void); +int readline(void); +int open_input(char *name); +int close_input(void); FILE *open_file(char *fname, char *mode); /* MACRO.C */ @@ -111,7 +113,7 @@ int pcx_pack_16x16_sprite(unsigned char int pcx_set_tile(struct t_symbol *ref, unsigned int offset); int pcx_search_tile(unsigned char *data, int size); int pcx_get_args(int *ip); -int pcx_parse_args(int i, int nb, int *a, int *b, int *c, int *d, int size); +int pcx_parse_args(int i, int nb, unsigned int *a, unsigned int *b, unsigned int *c, unsigned int *d, int size); int pcx_load(char *name); void decode_256(FILE *fp, int w, int h); void decode_16(FILE *fp, int w, int h);