예제 #1
0
파일: main.c 프로젝트: selb/rgbds-linux
int main(int argc, char *argv[])
{
	char *tzMainfile;
	int argn = 1;

	argc -= 1;

	if (argc == 0)
		PrintUsage();

	/* yydebug=1; */

	DefaultOptions.endian = ASM_DEFAULT_ENDIAN;
	DefaultOptions.gbgfx[0] = '0';
	DefaultOptions.gbgfx[1] = '1';
	DefaultOptions.gbgfx[2] = '2';
	DefaultOptions.gbgfx[3] = '3';
	DefaultOptions.binary[0] = '0';
	DefaultOptions.binary[1] = '1';
	DefaultOptions.fillchar = -1;	//      fill uninitialised data with random values
	opt_SetCurrentOptions(&DefaultOptions);

	while (argv[argn][0] == '-' && argc) {
		switch (argv[argn][1]) {
		case 'h':
			PrintUsage();
			break;
		case 'i':
			fstk_AddIncludePath(&(argv[argn][2]));
			break;
		case 'o':
			out_SetFileName(&(argv[argn][2]));
			break;
		case 'e':
		case 'g':
		case 'b':
		case 'z':
			opt_Parse(&argv[argn][1]);
			break;
		default:
			printf("*ERROR*\t :\n\tUnknown option '%c'\n",
			       argv[argn][1]);
			exit(5);
			break;
		}
		argn += 1;
		argc -= 1;
	}

	DefaultOptions = CurrentOptions;

	/*tzMainfile=argv[argn++];
	 * argc-=1; */
	tzMainfile = argv[argn];

	setuplex();

	printf("Assembling %s\n", tzMainfile);

	nStartClock = clock();

	nLineNo = 1;
	nTotalLines = 0;
	nIFDepth = 0;
	nPC = 0;
	nPass = 1;
	nErrors = 0;
	sym_PrepPass1();
	if (fstk_Init(tzMainfile)) {
		printf("Pass 1...\n");

		yy_set_state(LEX_STATE_NORMAL);
		opt_SetCurrentOptions(&DefaultOptions);

		if (yyparse() == 0 && nErrors == 0) {
			if (nIFDepth == 0) {
				nTotalLines = 0;
				nLineNo = 1;
				nIFDepth = 0;
				nPC = 0;
				nPass = 2;
				nErrors = 0;
				sym_PrepPass2();
				out_PrepPass2();
				fstk_Init(tzMainfile);
				yy_set_state(LEX_STATE_NORMAL);
				opt_SetCurrentOptions(&DefaultOptions);

				printf("Pass 2...\n");

				if (yyparse() == 0 && nErrors == 0) {
					double timespent;

					nEndClock = clock();
					timespent =
					    ((double)(nEndClock - nStartClock))
					    / (double)CLOCKS_PER_SEC;
					printf
					    ("Success! %ld lines in %d.%02d seconds ",
					     nTotalLines, (int)timespent,
					     ((int)(timespent * 100.0)) % 100);
					if (timespent == 0)
						printf
						    ("(INFINITY lines/minute)\n");
					else
						printf("(%d lines/minute)\n",
						       (int)(60 / timespent *
							     nTotalLines));
					out_WriteObject();
				} else {
					printf
					    ("Assembly aborted in pass 2 (%ld errors)!\n",
					     nErrors);
					//sym_PrintSymbolTable();
					exit(5);
				}
			} else {
				printf
				    ("*ERROR*\t:\tUnterminated IF construct (%ld levels)!\n",
				     nIFDepth);
				exit(5);
			}
		} else {
			printf("Assembly aborted in pass 1 (%ld errors)!\n",
			       nErrors);
			exit(5);
		}
	} else {
		printf("File '%s' not found\n", tzMainfile);
		exit(5);
	}
	return (0);
}
예제 #2
0
파일: main.c 프로젝트: bubbafoley/rgbds-osx
int 
main(int argc, char *argv[])
{
	int ch;
	char *ep;

	struct sOptions newopt;

	char *tzMainfile;

	if (argc == 1)
		PrintUsage();

	/* yydebug=1; */

	DefaultOptions.gbgfx[0] = '0';
	DefaultOptions.gbgfx[1] = '1';
	DefaultOptions.gbgfx[2] = '2';
	DefaultOptions.gbgfx[3] = '3';
	DefaultOptions.binary[0] = '0';
	DefaultOptions.binary[1] = '1';
	DefaultOptions.fillchar = 0;

	opt_SetCurrentOptions(&DefaultOptions);

	newopt = CurrentOptions;

	while ((ch = getopt(argc, argv, "b:g:i:o:p:")) != -1) {
		switch (ch) {
		case 'b':
			if (strlen(optarg) == 2) {
				newopt.binary[0] = optarg[1];
				newopt.binary[1] = optarg[2];
			} else {
				fprintf(stderr, "Must specify exactly "
				    "2 characters for option 'b'\n");
				exit(1);
			}
		case 'g':
			if (strlen(optarg) == 4) {
				newopt.gbgfx[0] = optarg[1];
				newopt.gbgfx[1] = optarg[2];
				newopt.gbgfx[2] = optarg[3];
				newopt.gbgfx[3] = optarg[4];
			} else {
				fprintf(stderr, "Must specify exactly "
				    "4 characters for option 'g'\n");
				exit(1);
			}
			break;
		case 'i':
			fstk_AddIncludePath(optarg);
			break;
		case 'o':
			out_SetFileName(optarg);
			break;
		case 'p':
			newopt.fillchar = strtoul(optarg, &ep, 0);
			if (optarg[0] == '\0' || *ep != '\0') {
				fprintf(stderr,
				    "Invalid argument for option 'p'\n");
				exit(1);
			}
			if (newopt.fillchar < 0 || newopt.fillchar > 0xFF) {
				fprintf(stderr, "Argument for option 'p' "
				    "must be between 0 and 0xFF\n");
				exit(1);
			}
			break;
		default:
			PrintUsage();
		}
	}
	argc -= optind;
	argv += optind;

	opt_SetCurrentOptions(&newopt);

	DefaultOptions = CurrentOptions;

	/* tzMainfile=argv[argn++]; argc-=1; */
	tzMainfile = argv[argc - 1];

	setuplex();

	printf("Assembling %s\n", tzMainfile);

	nStartClock = clock();

	nLineNo = 1;
	nTotalLines = 0;
	nIFDepth = 0;
	nPC = 0;
	nPass = 1;
	nErrors = 0;
	sym_PrepPass1();
	if (fstk_Init(tzMainfile)) {
		printf("Pass 1...\n");

		yy_set_state(LEX_STATE_NORMAL);
		opt_SetCurrentOptions(&DefaultOptions);

		if (yyparse() == 0 && nErrors == 0) {
			if (nIFDepth == 0) {
				nTotalLines = 0;
				nLineNo = 1;
				nIFDepth = 0;
				nPC = 0;
				nPass = 2;
				nErrors = 0;
				sym_PrepPass2();
				out_PrepPass2();
				fstk_Init(tzMainfile);
				yy_set_state(LEX_STATE_NORMAL);
				opt_SetCurrentOptions(&DefaultOptions);

				printf("Pass 2...\n");

				if (yyparse() == 0 && nErrors == 0) {
					double timespent;

					nEndClock = clock();
					timespent =
					    ((double) (nEndClock - nStartClock))
					    / (double) CLOCKS_PER_SEC;
					printf
					    ("Success! %ld lines in %d.%02d seconds ",
					    nTotalLines, (int) timespent,
					    ((int) (timespent * 100.0)) % 100);
					if (timespent == 0)
						printf
						    ("(INFINITY lines/minute)\n");
					else
						printf("(%d lines/minute)\n",
						    (int) (60 / timespent *
							nTotalLines));
					out_WriteObject();
				} else {
					printf
					    ("Assembly aborted in pass 2 (%ld errors)!\n",
					    nErrors);
					//sym_PrintSymbolTable();
					exit(5);
				}
			} else {
				fprintf(stderr,
				    "Unterminated IF construct (%ld levels)!\n",
				    nIFDepth);
				exit(1);
			}
		} else {
			fprintf(stderr,
			    "Assembly aborted in pass 1 (%ld errors)!\n",
			    nErrors);
			exit(1);
		}
	} else {
		printf("File '%s' not found\n", tzMainfile);
		exit(5);
	}
	return (0);
}