Exemple #1
0
int cgl_read_one_dist(struct airgen *airgen, FILE *fp)
{
	int err;
	uint8_t buf[DIST_HDR_SIZE];
	int16_t buf2[DIST_NUM_SHORTS];
	size_t nread;

	nread = fread(buf, sizeof(uint8_t), DIST_HDR_SIZE, fp);
	if (nread < DIST_HDR_SIZE)
		return -EBADDIST;
	err = read_short((int16_t*)buf2, DIST_NUM_SHORTS, fp);
	if (err)
		return -EBADDIST;
	airgen->dir  = (buf[0] >> 0) & 0x03;
	airgen->spin = (buf[0] >> 4) & 0x01;
	parse_tile_simple(buf2 + 0x00, airgen->base, 40, 40);
	airgen->tex_x = airgen->base->tex_x;
	parse_tile_normal(buf2 + 0x04, airgen->pipes);
	airgen->pipes->collision_test = Bitmap;
	struct rect r;
	parse_rect(buf2 + 0x0e, &r);
	rect_to_tile(&r, airgen->act);
	set_type(airgen->act, Transparent, RectPoint, AirgenAction, airgen);
	return 0;
}
Exemple #2
0
int cgl_read_one_vent(struct fan *fan, FILE *fp)
{
	int err;
	uint8_t buf[VENT_HDR_SIZE];
	int16_t buf2[VENT_NUM_SHORTS];
	size_t nread;

	nread = fread(buf, sizeof(uint8_t), VENT_HDR_SIZE, fp);
	if (nread < VENT_HDR_SIZE)
		return -EBADVENT;
	err = read_short((int16_t*)buf2, VENT_NUM_SHORTS, fp);
	if (err)
		return -EBADVENT;
	fan->dir   = (buf[0] >> 0) & 0x03;
	fan->power = (buf[0] >> 4) & 0x01;
	parse_tile_simple(buf2 + 0x00, fan->base, 48, 48);
	fan->tex_x = fan->base->tex_x;
	parse_tile_normal(buf2 + 0x04, fan->pipes);
	fan->pipes->collision_test = Bitmap;
	struct rect r;
	parse_rect(buf2 + 0x0e, &r);
	rect_to_tile(&r, fan->act);
	set_type(fan->act, Transparent, RectPoint, FanAction, fan);
	return 0;
}
Exemple #3
0
int cgl_read_one_magn(struct magnet *magnet, FILE *fp)
{
	int err;
	uint8_t buf[MAGN_HDR_SIZE];
	int16_t buf2[MAGN_NUM_SHORTS];
	size_t nread;

	nread = fread(buf, sizeof(uint8_t), MAGN_HDR_SIZE, fp);
	if (nread < MAGN_HDR_SIZE)
		return -EBADMAGN;
	err = read_short((int16_t*)buf2, MAGN_NUM_SHORTS, fp);
	if (err)
		return -EBADMAGN;
	magnet->dir = buf[0] & 0x03;
	parse_tile_simple(buf2 + 0x00, magnet->base, 32, 32);
	parse_tile_normal(buf2 + 0x04, magnet->magn);
	magnet->tex_x = magnet->magn->tex_x;
	magnet->magn->collision_test = Bitmap;
	struct rect r;
	parse_rect(buf2 + 0x0e, &r);
	rect_to_tile(&r, magnet->act);
	set_type(magnet->act, Transparent, RectPoint, MagnetAction, magnet);
	return 0;
}
static int parse_args(int argc, char *argv[], struct setup *s)
{
	if (argc <= 1)
		usage(argv[0]);

	int c, ret;
	memset(s, 0, sizeof(*s));

	while ((c = getopt(argc, argv, "M:o:i:S:f:F:s:t:b:h")) != -1) {
		switch (c) {
		case 'M':
			strncpy(s->module, optarg, 31);
			break;
		case 'o':
			ret = sscanf(optarg, "%u:%u:%31s", &s->conId, &s->crtId,
				s->modestr);
			if (WARN_ON(ret != 3, "incorrect mode description\n"))
				return -1;
			break;
		case 'i':
			strncpy(s->video, optarg, 31);
			break;
		case 'S':
			ret = sscanf(optarg, "%u,%u", &s->w, &s->h);
			if (WARN_ON(ret != 2, "incorrect input size\n"))
				return -1;
			s->use_wh = 1;
			break;
		case 'f':
			if (WARN_ON(strlen(optarg) != 4, "invalid fourcc\n"))
				return -1;
			s->in_fourcc = ((unsigned)optarg[0] << 0) |
				((unsigned)optarg[1] << 8) |
				((unsigned)optarg[2] << 16) |
				((unsigned)optarg[3] << 24);
			break;
		case 'F':
			if (WARN_ON(strlen(optarg) != 4, "invalid fourcc\n"))
				return -1;
			s->out_fourcc = ((unsigned)optarg[0] << 0) |
				((unsigned)optarg[1] << 8) |
				((unsigned)optarg[2] << 16) |
				((unsigned)optarg[3] << 24);
			break;
		case 's':
			ret = parse_rect(optarg, &s->crop);
			if (WARN_ON(ret, "incorrect crop area\n"))
				return -1;
			s->use_crop = 1;
			break;
		case 't':
			ret = parse_rect(optarg, &s->compose);
			if (WARN_ON(ret, "incorrect compose area\n"))
				return -1;
			s->use_compose = 1;
			break;
		case 'b':
			ret = sscanf(optarg, "%u", &s->buffer_count);
			if (WARN_ON(ret != 1, "incorrect buffer count\n"))
				return -1;
			break;
		case '?':
		case 'h':
			usage(argv[0]);
			return -1;
		}
	}

	return 0;
}
Exemple #5
0
int cgl_read_one_barr(struct lgate *lgate, FILE *fp)
{
	static const vector base_dims[][5] = {
		{{32, 32}, {24, 16}, {0, 0}, {40, 4}, {32, 20}},
		{{32, 32}, {16, 24}, {0, 0}, {4, 40}, {20, 32}}
	};
	int err;
	uint8_t buf[ONEW_HDR_SIZE];
	int16_t buf2[ONEW_NUM_SHORTS];
	size_t nread;

	nread = fread(buf, sizeof(uint8_t), ONEW_HDR_SIZE, fp);
	if (nread < ONEW_HDR_SIZE)
		return -EBADBARR;
	err = read_short((int16_t*)buf2, ONEW_NUM_SHORTS, fp);
	if (err)
		return -EBADBARR;
	/* fill with header information */
	lgate->type    = (buf[0] >> 0) & 0x03;
	lgate->has_end = (buf[0] >> 2) & 0x01;
	lgate->keys[0] = (buf[0] >> 7) & 0x01;
	lgate->keys[1] = (buf[0] >> 6) & 0x01;
	lgate->keys[2] = (buf[0] >> 5) & 0x01;
	lgate->keys[3] = (buf[0] >> 4) & 0x01;
	if (lgate->type == GateTop || lgate->type == GateBottom)
		lgate->orient = Vertical;
	else
		lgate->orient = Horizontal;
	assert(buf2[0] == buf2[1]);
	lgate->len = lgate->max_len = buf2[0];
	parse_packed_tiles(buf2 + 0x02, 5, lgate->base, base_dims[lgate->orient]);
	/* prepare lgate's bar */
	switch (lgate->orient) {
	case Vertical:
		parse_tile_minimal(buf2 + 0x16, lgate->bar,
				GATE_BAR_THICKNESS, lgate->len,
				LVGATE_TEX_X, LVGATE_TEX_Y);
		break;
	case Horizontal:
		parse_tile_minimal(buf2 + 0x16, lgate->bar,
				lgate->len, GATE_BAR_THICKNESS,
				LHGATE_TEX_X, LHGATE_TEX_Y);
		break;
	}
	lgate->bar->collision_test = Bitmap;
	struct rect r;
	parse_rect(buf2 + 0x1c, &r);
	rect_to_tile(&r, lgate->act);
	set_type(lgate->act, Transparent, RectPoint, LGateAction, lgate);
	if (!lgate->has_end)
		set_type(lgate->base[4], Transparent, NoCollision, 0, NULL);
	if (lgate->type == GateLeft)
		lgate->bar->tex_x += GATE_BAR_LEN - lgate->len;
	if (lgate->type == GateTop)
		lgate->bar->tex_y += GATE_BAR_LEN - lgate->len;
	set_light_tile(lgate->light[0], 0,
			lgate->base[0]->x + 6,  lgate->base[0]->y + 6);
	set_light_tile(lgate->light[1], 1,
			lgate->base[0]->x + 18, lgate->base[0]->y + 6);
	set_light_tile(lgate->light[2], 2,
			lgate->base[0]->x + 6,  lgate->base[0]->y + 18);
	set_light_tile(lgate->light[3], 3,
			lgate->base[0]->x + 18, lgate->base[0]->y + 18);
	return 0;
}
Exemple #6
0
int cgl_read_one_onew(struct gate *gate, FILE *fp)
{
	static const vector base_dims[][5] = {
		{{32, 32}, {32, 16}, {32, 32}, {40, 4}, {32, 20}},
		{{32, 32}, {16, 32}, {32, 32}, {4, 40}, {20, 32}}
	};
	int err;
	uint8_t buf[ONEW_HDR_SIZE];
	int16_t buf2[ONEW_NUM_SHORTS];
	size_t nread;

	nread = fread(buf, sizeof(uint8_t), ONEW_HDR_SIZE, fp);
	if (nread < ONEW_HDR_SIZE)
		return -EBADONEW;
	err = read_short((int16_t*)buf2, ONEW_NUM_SHORTS, fp);
	if (err)
		return -EBADONEW;
	/* fill with header information */
	gate->type    = (buf[0] >> 0) & 0x03;
	gate->dir     = (buf[0] >> 2) & 0x01;
	gate->has_end = (buf[0] >> 3) & 0x01;
	gate->orient  = (buf[0] >> 4) & 0x01;
	assert(buf2[0] == buf2[1]);
	gate->len = gate->max_len = buf2[0];
	parse_packed_tiles(buf2 + 0x02, 5, gate->base, base_dims[gate->orient]);
	/* prepare gate's bar */
	switch (gate->orient) {
	case Vertical:
		parse_tile_minimal(buf2 + 0x16, gate->bar,
				GATE_BAR_THICKNESS, gate->len,
				VGATE_TEX_X, VGATE_TEX_Y);
		break;
	case Horizontal:
		parse_tile_minimal(buf2 + 0x16, gate->bar,
				gate->len, GATE_BAR_THICKNESS,
				HGATE_TEX_X, HGATE_TEX_Y);
		break;
	}
	gate->bar->collision_test = Bitmap;
	struct rect r;
	parse_rect(buf2 + 0x1c, &r);
	rect_to_tile(&r, gate->act);
	set_type(gate->act, Transparent, RectPoint, GateAction, gate);
	if (!gate->has_end)
		set_type(gate->base[4], Transparent, NoCollision, 0, NULL);
	if (gate->type == GateLeft)
		gate->bar->tex_x += GATE_BAR_LEN - gate->len;
	if (gate->type == GateTop)
		gate->bar->tex_y += GATE_BAR_LEN - gate->len;
	/* add blue arrow */
	gate->arrow->w = 16;
	gate->arrow->h = 16;
	switch (gate->dir) {
	case 0:
		gate->arrow->x = gate->base[0]->x + ARROW_OFFSET;
		gate->arrow->y = gate->base[0]->y + ARROW_OFFSET;
		break;
	case 1:
		gate->arrow->x = gate->base[2]->x + ARROW_OFFSET;
		gate->arrow->y = gate->base[2]->y + ARROW_OFFSET;
		break;
	}
	int arrow_dir = gate->type - 1;
	if (gate->dir == 1)
		arrow_dir += 2;
	arrow_dir = (arrow_dir + 4) % 4;
	gate->arrow->tex_y = ARROW_TEX_Y;
	gate->arrow->tex_x = ARROW_SIDE * arrow_dir;
	gate->arrow->z = DYN_TILES_OVERLAY_Z;
	return 0;
}