Example #1
0
int pla_parse(const void *data, size_t length, jed_data *result)
{
	const UINT8 *src = (const UINT8 *)data;
	const UINT8 *srcend = src + length;

	parse_info pinfo;
	memset(&pinfo, 0, sizeof(pinfo));

	result->numfuses = 0;
	memset(result->fusemap, 0, sizeof(result->fusemap));

	while (src < srcend)
	{
		switch (*src)
		{
			// comment line
			case '#':
				while (src < srcend && !iscrlf(*src))
					src++;
				break;

			// keyword
			case '.':
				src++;
				if (!process_field(result, &src, srcend, &pinfo))
					return JEDERR_INVALID_DATA;
				break;

			// terms
			case '0': case '1': case '-': case '~':
				if (!process_terms(result, &src, srcend, &pinfo))
					return JEDERR_INVALID_DATA;
				break;

			default:
				src++;
				break;
		}
	}

	// write output polarity
	if (pinfo.xorptr > 0)
	{
		if (LOG_PARSE) printf("Polarity: ");

		for (int i = 0; i < pinfo.outputs; i++)
		{
			int bit = pinfo.xorval[i/32] >> (i & 31) & 1;
			jed_set_fuse(result, result->numfuses++, bit);
			if (LOG_PARSE) printf("%d", bit);
		}
		if (LOG_PARSE) printf("\n");
	}

	return JEDERR_NONE;
}
Example #2
0
int pla_parse(const void *data, size_t length, jed_data *result)
{
	const UINT8 *cursrc = (const UINT8 *)data;
	const UINT8 *srcend = cursrc + length;
	const UINT8 *scan;
	parse_info pinfo;

	result->numfuses = 0;
	memset(result->fusemap, 0x00, sizeof(result->fusemap));

	while (cursrc < srcend)
	{
		if (*cursrc == '#')
		{
			cursrc++;
			while (cursrc < srcend && !iscrlf(*cursrc))
				cursrc++;
		}
		else if (*cursrc == '.')
		{
			scan = cursrc;
			while (scan < srcend && !iscrlf(*scan))
				scan++;
			if (scan >= srcend)
				return JEDERR_INVALID_DATA;

			process_field(result, cursrc, srcend, &pinfo);

			cursrc = scan + 1;
		}

		cursrc++;
	}

	return JEDERR_NONE;
}
Example #3
0
File: jedparse.c Project: Fulg/mame
int jed_parse(const void *data, size_t length, jed_data *result)
{
	const UINT8 *cursrc = (const UINT8 *)data;
	const UINT8 *srcend = cursrc + length;
	const UINT8 *scan;
	jed_parse_info pinfo;
	UINT16 checksum;
	int i;

	/* initialize the output and the intermediate info struct */
	memset(result, 0, sizeof(*result));
	memset(&pinfo, 0, sizeof(pinfo));

	/* first scan for the STX character; ignore anything prior */
	while (cursrc < srcend && *cursrc != 0x02)
		cursrc++;
	if (cursrc >= srcend)
		return JEDERR_INVALID_DATA;

	/* then scan to see if we have an ETX */
	scan = cursrc;
	checksum = 0;
	while (scan < srcend && *scan != 0x03)
		checksum += *scan++ & 0x7f;
	if (scan >= srcend)
		return JEDERR_INVALID_DATA;

	/* see if there is a transmission checksum at the end */
	checksum += *scan;
	if (scan + 4 < srcend && ishex(scan[1]) && ishex(scan[2]) && ishex(scan[3]) && ishex(scan[4]))
	{
		UINT16 dessum = (hexval(scan[1]) << 12) | (hexval(scan[2]) << 8) | (hexval(scan[3]) << 4) | hexval(scan[4] << 0);
		if (dessum != 0 && dessum != checksum)
			return JEDERR_BAD_XMIT_SUM;
	}

	/* the ETX becomes the real srcend */
	srcend = scan;

	/* blast through the comment field */
	cursrc++;
	while (cursrc < srcend && *cursrc != '*')
		cursrc++;

	/* now loop over fields and decide which ones go in the file output */
	cursrc++;
	while (cursrc < srcend)
	{
		/* skip over delimiters */
		while (cursrc < srcend && isdelim(*cursrc))
			cursrc++;
		if (cursrc >= srcend)
			break;

		/* end of field is an asterisk -- find it */
		scan = cursrc;
		while (scan < srcend && *scan != '*')
			scan++;
		if (scan >= srcend)
			return JEDERR_INVALID_DATA;

		/* process the field */
		process_field(result, cursrc, scan, &pinfo);

		/* advance past it */
		cursrc = scan + 1;
	}

	/* if we got an explicit fuse count, override our computed count */
	if (pinfo.explicit_numfuses != 0)
		result->numfuses = pinfo.explicit_numfuses;

	/* clear out leftover bits */
	if (result->numfuses % 8 != 0)
		result->fusemap[result->numfuses / 8] &= (1 << (result->numfuses % 8)) - 1;
	memset(&result->fusemap[(result->numfuses + 7) / 8], 0, sizeof(result->fusemap) - (result->numfuses + 7) / 8);

	/* validate the checksum */
	checksum = 0;
	for (i = 0; i < (result->numfuses + 7) / 8; i++)
		checksum += result->fusemap[i];
	if (pinfo.checksum != 0 && checksum != pinfo.checksum)
		return JEDERR_BAD_FUSE_SUM;

	return JEDERR_NONE;
}