Exemple #1
0
/*
 *	scalar initializer
 *
 */
long scalar_initializer (long typ, long id, long stor)
{
	long i;

	if (stor == CONST)
		new_const();
	if (match("=")) {
		if (stor != CONST)
			error("can't initialize non-const scalars");
		blanks();
		if (ch() == ';') {
			error("value missing");
			return (-1);
		}
		if (ch() == '\"' && id == POINTER)
			i = get_string_ptr(typ);
		else
			i = get_raw_value(';');
		if (const_val_idx < MAX_CONST_VALUE)
			const_val[const_val_idx++] = i;
		blanks();
		if (ch() != ';') {
			error("syntax error");
			return (-1);
		}
	}
	return (1);
}
Exemple #2
0
void
do_inc_ex(int type)
{
	int end;
	int i;
	INTPTR_T j;
	int num;
	int nb_tile;
	char label[NAMESIZE];
	char label2[NAMESIZE];
	char str[NAMESIZE+32];
	struct {
		char fname[FILENAMESIZE];
		INTPTR_T  arg[5];
	} tiles[16];

	if(!match("(")) {
		error("missing '('");
		kill_line();
		return;
	}

	readstr(); /* read the label name */
	strcpy(label, litq2);
	strcpy(label2, litq2);
	strcpy(str, "__data__");
	for(i = (int)strlen(label2), j = 0; i < NAMEMAX; i++)
		label2[i] = str[j++];
	label2[i] = '\0';
	addglb(label2, ARRAY, CINT, 0, EXTERN);
	addglb(label, ARRAY, CINT, 0, EXTERN);

	if(!match(",")) {
		error("comma missing");
		kill_line();
		return;
	}

	end = 0;
	num = 0;
	nb_tile = 0;
	while (!end) {
		// if (match("\\"));
	    if(!readqstr()) {
			error("not a file name");
			kill_line();
			return;
		}
		if(!match(",")) {
			error("comma missing");
			kill_line();
			return;
		}
		strcpy(tiles[num].fname, litq2);

		for (i = 0; i < 5; i++) {
			// if (match("\\"));
			if(!number(&tiles[num].arg[i])) {
				error("not a number");
				kill_line();
				return;
			}
			if (match(")")) {
				if (i == 4) {
					kill_line();
					end = 1;
					break;
				}
				else {
					error("arg missing");
					kill_line();
					return;
				}
			}
			if(!match(",")) {
				error("comma missing");
				kill_line();
				return;
			}
			while((ch() == ' ') || (ch() == '\t'))
				gch();
			if (ch() == '\0') {
				error("arg missing");
				kill_line();
				return;
			}
		}
		nb_tile += tiles[num].arg[2] * tiles[num].arg[3];
		num++;
		if (num == 16) {
			if(!end) {
				error("too many args (max 16 files)");
				kill_line();
				return;
			}
		}
	}

	/* create const array to hold extra infos */
	new_const();
	const_val[const_val_idx++] = const_data_idx;	/* number of tile */
	sprintf(str, "%i", nb_tile);
	add_buffer(str, '(');
	const_data[const_data_idx++] = '\0';
	const_val[const_val_idx++] = const_data_idx;	/* tile size */
	sprintf(str, "%i", type);
	add_buffer(str, '(');
	const_data[const_data_idx++] = '\0';
	const_val[const_val_idx++] = const_data_idx;	/* tile bank */
	sprintf(str, "BANK(_%s)", label2);
	add_buffer(str, '(');
	const_data[const_data_idx++] = '\0';
	const_val[const_val_idx++] = const_data_idx;	/* tile addr */
	sprintf(str, "     _%s", label2);
	add_buffer(str, '(');
	const_data[const_data_idx++] = '\0';
	const_val[const_val_idx++] = -(litptr + 1024);	/* pal idx table addr */
	add_const(CINT);

	/* create pal idx table */
	for(i = 0; i < num; i++) {
		j = tiles[i].arg[2] * tiles[i].arg[3];
		while (j) {
			j--;
			if (litptr < LITMAX)
				litq[litptr++] = (tiles[i].arg[4] << 4);
		}
	}

	/* dump incchr/tile cmds */
	ol(".data");
	if (type == 8)
		ol(".dw $0800");
	else
		ol(".dw $1000");
	prefix();
	outstr(label2);
	outstr(":\n");
	for(i = 0; i < num; i++) {
		if (type == 8)
			ot(".incchr \"");
		else
			ot(".inctile \"");
		outstr(tiles[i].fname);
		outstr("\"");
		for (j = 0; j < 4; j++) {
			outstr(",");
			outdec(tiles[i].arg[j]);
		}
		newl();
	}
	ol(".code");
	kill_line();
}
Exemple #3
0
/*
 *	array initializer
 *
 */
long array_initializer (long typ, long id, long stor)
{
	long nb;
	long k;
	long i;

	nb = 0;
	k = needsub();

	if (stor == CONST)
		new_const();
	if (match("=")) {
		if (stor != CONST)
			error("can't initialize non-const arrays");
		if (!match("{")) {
			error("syntax error");
			return (-1);
		}
		if (!match("}")) {
			for (;;) {
				if (match("}")) {
					error("value missing");
					break;
				}
				if (match(",")) {
					error("value missing");
					continue;
				}
				if ((ch() == '\"') && (id == POINTER))
					i = get_string_ptr(typ);
				else
					i = get_raw_value(',');
				nb++;
				blanks();
				if (const_val_idx < MAX_CONST_VALUE)
					const_val[const_val_idx++] = i;
				if ((ch() != ',') && (ch() != '}')) {
					error("syntax error");
					return (-1);
				}
				if (match("}"))
					break;
				gch();
			}
		}
		if (k == 0)
			k = nb;
		if (nb > k) {
			nb = k;
			error("excess elements in array initializer");
		}
	}
	if (stor == CONST) {
		while (nb < k) {
			nb++;
			if (const_val_idx < MAX_CONST_VALUE)
				const_val[const_val_idx++] = -1;
		}
	}
	return (k);
}