Esempio n. 1
0
static SPWAW_ERROR
load_map (int fd, SPWAW_SNAP_MAP_RAW *map)
{
	SPWAW_ERROR	rc = SPWERR_OK;
	long		pos;
	SNAP_MAPHDR	maphdr;
	CBIO		cbio;

	pos = bseekget (fd);

	memset (&maphdr, 0, sizeof (maphdr));
	if (!bread (fd, (char *)&maphdr, sizeof (maphdr), false))
		FAILGOTO (SPWERR_FRFAILED, "bread(maphdr)", handle_error);

	map->width  = maphdr.width;
	map->height = maphdr.height;

	map->size = maphdr.size;
	map->data = safe_smalloc (SPWAW_SNAP_MAP_DRAW, map->size);
	COOMGOTO (map->data, "SPWAW_SNAP_MAP_DRAW map", handle_error);

	bseekset (fd, pos + maphdr.data);

	cbio.data = (char *)map->data; cbio.size = map->size; cbio.comp = &(maphdr.comp);
	if (!cbread (fd, cbio, "raw map data"))
		FAILGOTO (SPWERR_FRFAILED, "cbread(raw map data)", handle_error);

	return (SPWERR_OK);

handle_error:
	if (map->data) free (map->data);
	return (rc);
}
Esempio n. 2
0
void rcalib()
{
FILE *fc;
int cb;
	printf("\nCb = %x",cb = cbread());
	printf("\nFsl = %x",rfuses(0));
	printf("\nFsh = %x",rfuses(1));
	printf("\nFse = %x",rextfuses());

//	if((fc=fopen("osc.inc","w")) == NULL) {
//		printf("can\'t create osc.inc");
//		return;
//	}
//	fprintf(fc,"\n\t.dw\t0x00%02x\n\n",cb & 0xff);
//	fclose(fc);
}
Esempio n. 3
0
static SPWAW_ERROR
load_oob_units (int fd, long pos, SNAP_OOBHDR oobhdr, SPWAW_SNAP_OOB_RAW *oob, STRTAB *stab, ULONG version)
{
	SPWAW_ERROR	rc = SPWERR_OK;
	long		size;
	char		*data = NULL;
	CBIO		cbio;
	SBR		*sbr = NULL;

	oob->units.cnt = oobhdr.ucnt;
	size = oobhdr.usize;
	data = safe_smalloc (char, size);
	COOMGOTO (data, "SPWAW_SNAP_OOB_UEL data", handle_error);

	bseekset (fd, pos + oobhdr.upos);
	cbio.data = data; cbio.size = size; cbio.comp = &(oobhdr.ucomp);
	if (!cbread (fd, cbio, "unit data")) FAILGOTO (SPWERR_FRFAILED, "cbread(unit data) failed", handle_error);

	sbr = sbread_init (data, size);
	if (!sbr) FAILGOTO (SPWERR_FRFAILED, "sbread_init() failed", handle_error);

	oob->units.raw = safe_nmalloc (SPWAW_SNAP_OOB_UELRAW, oobhdr.ucnt);
	COOMGOTO (oob->units.raw, "SPWAW_SNAP_OOB_UELRAW list", handle_error);

	rc = load_oobu_list (sbr, oobhdr.ucnt, oob, stab, version);
	ERRORGOTO ("load_oobu_list()", handle_error);

	rc = build_uridx (&(oob->units)); ROE ("build_uridx()");

	sbread_stop (sbr); sbr = NULL;
	safe_free (data);

	/* For version 10, we also need to perform the legacy detection of units and crews */
	if (version == SNAP_VERSION_V10) {
		rc = snapshot_legacy_ldrcrw_detect (oobhdr.ucnt, oob);
		ERRORGOTO ("snapshot_legacy_ldrcrw_detect()", handle_error);
	}

	return (SPWERR_OK);

handle_error:
	if (sbr) sbread_stop (sbr);
	if (data) safe_free (data);
	return (rc);
}
Esempio n. 4
0
static SPWAW_ERROR
load_oob_formations (int fd, long pos, SNAP_OOBHDR oobhdr, SPWAW_SNAP_OOB_RAW *oob, STRTAB *stab)
{
	SPWAW_ERROR	rc = SPWERR_OK;
	long		size;
	char		*data = NULL;
	CBIO		cbio;
	SBR		*sbr = NULL;

	oob->formations.cnt = oobhdr.fcnt;
	oob->formations.start = oobhdr.fstart;
	size = oobhdr.fsize;
	data = safe_smalloc (char, size);
	COOMGOTO (data, "SPWAW_SNAP_OOB_FEL data", handle_error);

	bseekset (fd, pos + oobhdr.fpos);
	cbio.data = data; cbio.size = size; cbio.comp = &(oobhdr.fcomp);
	if (!cbread (fd, cbio, "formation data")) FAILGOTO (SPWERR_FRFAILED, "cbread(formation data) failed", handle_error);

	sbr = sbread_init (data, size);
	if (!sbr) FAILGOTO (SPWERR_FRFAILED, "sbread_init() failed", handle_error);

	oob->formations.raw = safe_nmalloc (SPWAW_SNAP_OOB_FELRAW, oobhdr.fcnt);
	COOMGOTO (oob->formations.raw, "SPWAW_SNAP_OOB_FELRAW list", handle_error);

	rc = load_oobf_list (sbr, oobhdr.fcnt, oob, stab);
	ERRORGOTO ("load_oobf_list()", handle_error);

	rc = build_fridx (&(oob->formations)); ROE ("build_fridx()");

	sbread_stop (sbr); sbr = NULL;
	safe_free (data);

	return (SPWERR_OK);

handle_error:
	if (sbr) sbread_stop (sbr);
	if (data) safe_free (data);
	return (rc);
}
Esempio n. 5
0
SPWAW_ERROR
snapload (int fd, SPWAW_SNAPSHOT *dst, STRTAB *stabptr)
{
	SPWAW_ERROR	rc = SPWERR_OK;
	STRTAB		*stab = stabptr;
	long		pos;
	SNAP_HEADER	mhdr;
	SNAP_SOURCE	shdr;
	SNAP_INFO	ihdr;
	SNAP		snap;
	CBIO		cbio;

	CNULLARG (dst);
	if (!stabptr) stab = (STRTAB *)dst->stab;

	pos = bseekget (fd);

	memset (&snap, 0, sizeof (snap));

	rc = snaploadhdrs (fd, &mhdr, &shdr, &ihdr);
	ERRORGOTO ("snaploadhdrs()", handle_error);

	if (mhdr.oobdat) {
		rc = SPWOOB_new (&(dst->oobdat));
		ERRORGOTO ("SPWOOB_new()", handle_error);
		dst->freeoobdat = true;

		bseekset (fd, pos + mhdr.oobdat);
		rc = SPWOOB_load (dst->oobdat, fd);
		ERRORGOTO ("SPWOOB_load()", handle_error);
	}

	if (!stabptr) {
		bseekset (fd, pos + mhdr.stab);
		rc = STRTAB_fdload (stab, fd);
		ERRORGOTO ("STRTAB_fdload()", handle_error);
	}

	dst->src.path = STRTAB_getstr (stab, shdr.path);
	dst->src.file = STRTAB_getstr (stab, shdr.file);
	dst->src.date = *((FILETIME *)&(shdr.date));

	bseekset (fd, mhdr.snap.data + pos);
	/* We are now backwards compatible with version 11 and older */
	if (mhdr.version <= SNAP_VERSION_V11) {
		rc = snapshot_load_v11_snap (fd, &mhdr, &snap);
		ROE ("snapshot_load_v11_snap(snapshot game data)");
	} else {
		cbio.data = (char *)&snap; cbio.size = mhdr.snap.size; cbio.comp = &(mhdr.snap.comp);
		if (!cbread (fd, cbio, "snapshot game data"))
			FAILGOTO (SPWERR_FRFAILED, "cbread(snapshot game data) failed", handle_error);
	}
	load_snap (&snap, stab, dst);

	bseekset (fd, pos + mhdr.map);
	rc = load_map (fd, &(dst->raw.game.map));
	ERRORGOTO ("load_map(map)", handle_error);

	bseekset (fd, pos + mhdr.oobp1);
	rc = load_oob (fd, &(dst->raw.OOBp1), stab, mhdr.version);
	ERRORGOTO ("load_oob(oobP1)", handle_error);

	bseekset (fd, pos + mhdr.oobp2);
	rc = load_oob (fd, &(dst->raw.OOBp2), stab, mhdr.version);
	ERRORGOTO ("load_oob(OOBp2)", handle_error);

	dst->type = (SPWAW_BATTLE_TYPE)ihdr.type;

	return (SPWERR_OK);

handle_error:
	snapclean (dst, stabptr);
	return (rc);
}