+void print_usage(int);
+
+void init_areas(void)
+{
+ area[AREA_CSEG].start=area[AREA_CSEG].alloc_position = 0;
+ area[AREA_DSEG].start=area[AREA_DSEG].alloc_position = 0;
+ area[AREA_BSEG].start=area[AREA_BSEG].alloc_position = 0;
+ area[AREA_XSEG].start=area[AREA_XSEG].alloc_position = 0;
+ area[AREA_XISEG].start=area[AREA_XISEG].alloc_position = 0;
+ area[AREA_XINIT].start=area[AREA_XINIT].alloc_position = 0;
+ area[AREA_GSINIT].start=area[AREA_GSINIT].alloc_position = 0;
+ area[AREA_GSFINAL].start=area[AREA_GSFINAL].alloc_position = 0;
+ area[AREA_HOME].start=area[AREA_HOME].alloc_position = 0;
+}
+
+void relPrelude() {
+ //char buffer[132];
+ int i, areas=0, globals=0;
+ struct symbol *p;
+
+ fprintf (frel, "SDCCXA rel, version %1.1f\n", version);
+ for (i=1; i<NUM_AREAS; i++) {
+ if ((area[i].size=area[i].alloc_position-area[i].start)) {
+ areas++;
+ }
+ }
+ for (p=sym_list; p; p=p->next) {
+ if (p->isdef) {
+ // skip temp labels
+ if (p->name[strlen(p->name)-1]!='$') {
+ globals++;
+ }
+ }
+ }
+ fprintf (frel, "H %d areas %d global symbols\n", areas, globals);
+ fprintf (frel, "M %s\n", modulename);
+ for (p=sym_list; p; p=p->next) {
+ if (!p->isdef) {
+ fprintf (frel, "S %s Ref0000\n", p->name);
+ }
+ }
+}
+
+void printVersion() {
+ printf("\nPaul's XA51 Assembler\n");
+ printf("Copyright 1997,2002 Paul Stoffregen\n\n");
+ printf("This program is free software; you can redistribute it\n");
+ printf("and/or modify it under the terms of the GNU General Public\n");
+ printf("License, Version 2, published by the Free Software Foundation\n\n");
+ printf("This program is distributed in the hope that it will be useful,\n");
+ printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
+ printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");
+}
+
+int verbose=0, createSymbolFile=0;
+
+void process_args(int argc, char **argv)
+{
+ int i=0;
+
+ if (argc < 2) print_usage(1);
+
+ while (++i<argc && *argv[i]=='-') {
+ if (strcmp(argv[i], "--version")==0) {
+ printVersion();
+ exit (0);
+ }
+ if (strcmp(argv[i], "--help")==0) {
+ print_usage(0);
+ }
+ if (strcmp(argv[i], "-v")==0) {
+ verbose++;
+ continue;
+ }
+ if (strcmp(argv[i], "-s")==0) {
+ createSymbolFile++;
+ continue;
+ }
+ print_usage(1);
+ }
+
+ if (i!=argc-1) {
+ // only 1 source file for now
+ print_usage(1);
+ }
+
+ strcpy(infilename, argv[i]);
+
+ if (strncasecmp(infilename+strlen(infilename)-4, ".asm", 3)) {
+ fprintf (stderr, "unrecognized input file: \"%s\"\n", argv[i]);
+ print_usage(1);
+ }
+
+ strcpy(modulename, infilename);
+ modulename[strlen(modulename)-4] = '\0';
+ sprintf (outfilename, "%s.rel", modulename);
+ sprintf (listfilename, "%s.lst", modulename);
+ if (createSymbolFile) {
+ sprintf (symfilename, "%s.sym", modulename);
+ }
+}