Example #1
0
static int
midi_adlib_open(int data_length, byte *data_ptr, int data2_length,
		byte *data2_ptr, void *seq)
{
	int nrdevs, i, n;
	struct synth_info info;
	struct sbi_instrument sbi;

	if (data_length < 1344) {
		printf ("invalid patch.003");
		return -1;
	}

	for (i = 0; i < 48; i++) 
		make_sbi((adlib_def *)(data_ptr+(28 * i)), adlib_sbi[i]);

	if (data_length > 1344)
		for (i = 48; i < 96; i++) 
			make_sbi((adlib_def *)(data_ptr+2+(28 * i)), adlib_sbi[i]);

	memset(instr, 0, sizeof(instr));
 
	if (!IS_VALID_FD(seqfd=open("/dev/sequencer", O_WRONLY, 0))) {
		perror("/dev/sequencer");
		return(-1);
	}
	if (ioctl(seqfd, SNDCTL_SEQ_NRSYNTHS, &nrdevs) == -1) {
		perror("/dev/sequencer");
		return(-1);
	}
	for (i=0;i<nrdevs && dev==-1;i++) {
		info.device = i;
		if (ioctl(seqfd, SNDCTL_SYNTH_INFO, &info)==-1) {
			perror("info: /dev/sequencer");
			return(-1);
		}
		if (info.synth_type == SYNTH_TYPE_FM)
			dev = i;
	}
	if (dev == -1) {
		fprintf(stderr, "ADLIB: FM synthesizer not detected\n");
		return(-1);
	}

	/*  free_voices = info.nr_voices; */
	adlib_init_lists();

	printf("ADLIB: Loading patches into synthesizer\n");
	sbi.device = dev;
	sbi.key = FM_PATCH;
	for (i = 0; i < 96; i++) {
		for (n = 0; n < 32; n++)
			memcpy(sbi.operators, &adlib_sbi[i], sizeof(sbi_instr_data));
		sbi.channel=i;
		SEQ_WRPATCH(&sbi, sizeof(sbi));
		SEQ_DUMPBUF();
	}
	SEQ_START_TIMER();
	SEQ_SET_TEMPO(60);
	SEQ_DUMPBUF();
	return 0;
}
Example #2
0
static void
_scir_load_resource(resource_mgr_t *mgr, resource_t *res, int protect)
{
	char *cwd = sci_getcwd();
	char filename[14];
	int fh;
	resource_t backup;

	memcpy(&backup, res, sizeof(resource_t));
	/* Enter resource directory */
	chdir(mgr->resource_path);

	/* First try lower-case name */
	if (res->file == SCI_RESOURCE_FILE_PATCH) {

		if (!patch_sprintfers[mgr->sci_version]) {
			sciprintf("Resource manager's SCI version (%d) has no patch file name printers -> internal error!\n",
				  mgr->sci_version);
			exit(1);
		}

		/* Get patch file name */
		patch_sprintfers[mgr->sci_version](filename, res);
	} else
		sprintf(filename, "resource.%03i", res->file);

	fh = open(filename, O_RDONLY | O_BINARY);


	if (!IS_VALID_FD(fh)) {
		char *raiser = filename;
		while (*raiser) {
			*raiser = toupper(*raiser); /* Uppercasify */
			++raiser;
		}
		fh = sci_open(filename, O_RDONLY|O_BINARY);
	}    /* Try case-insensitively name */

	if (!IS_VALID_FD(fh)) {
		sciprintf("Failed to open %s/%s!\n",
			  mgr->resource_path, filename);
		res->data = NULL;
		res->status = SCI_STATUS_NOMALLOC;
		res->size = 0;
		chdir(cwd);
		free(cwd);
		return;
	}


	lseek(fh, res->file_offset, SEEK_SET);

	if (res->file == SCI_RESOURCE_FILE_PATCH)
		_scir_load_from_patch_file(fh, res, filename);
	else if (!decompressors[mgr->sci_version]) {
		/* Check whether we support this at all */
		sciprintf("Resource manager's SCI version (%d) is invalid!\n",
			  mgr->sci_version);
		exit(1);
	} else {
		int error = /* Decompress from regular resource file */
			decompressors[mgr->sci_version](res, fh, mgr->sci_version);

		if (error) {
			sciprintf("Error %d occured while reading %s.%03d"
				  " from resource file: %s\n",
				  error, sci_resource_types[res->type], res->number,
				  sci_error_types[error]);

			if (protect)
				memcpy(res, &backup, sizeof(resource_t));

			res->data = NULL;
			res->status = SCI_STATUS_NOMALLOC;
			res->size = 0;
			chdir(cwd);
			free(cwd);
			return;
		}
	}

	close(fh);
	chdir(cwd);
	free(cwd);
}
Example #3
0
int
sci_test_view_type(resource_mgr_t *mgr)
{
	int fh;
	char filename[14];
	int compression;
	resource_t *res;
	int i;

	mgr->sci_version = SCI_VERSION_AUTODETECT;

	for (i=0;i<1000;i++)
	{
		res = scir_test_resource(mgr, sci_view, i);

		if (!res) continue;

		if (res->file == SCI_RESOURCE_FILE_PATCH)
			continue;

		sprintf(filename, "resource.%03i", res->file);
		fh = open(filename, O_RDONLY | O_BINARY);


		if (!IS_VALID_FD(fh)) {
			char *raiser = filename;
			while (*raiser) {
				*raiser = toupper(*raiser); /* Uppercasify */
				++raiser;
			}
			fh = sci_open(filename, O_RDONLY|O_BINARY);
		}    /* Try case-insensitively name */
		
		if (!IS_VALID_FD(fh)) continue;
		lseek(fh, res->file_offset, SEEK_SET);

		compression = sci0_get_compression_method(fh);
		close(fh);

		if (compression == 3)
			return (mgr->sci_version = SCI_VERSION_01_VGA);
	}

	/* Try the same thing with pics */
	for (i=0;i<1000;i++)
	{
		res = scir_test_resource(mgr, sci_pic, i);

		if (!res) continue;

		if (res->file == SCI_RESOURCE_FILE_PATCH)
			continue;

		sprintf(filename, "resource.%03i", res->file);
		fh = open(filename, O_RDONLY | O_BINARY);


		if (!IS_VALID_FD(fh)) {
			char *raiser = filename;
			while (*raiser) {
				*raiser = toupper(*raiser); /* Uppercasify */
				++raiser;
			}
			fh = sci_open(filename, O_RDONLY|O_BINARY);
		}    /* Try case-insensitively name */
		
		if (!IS_VALID_FD(fh)) continue;
		lseek(fh, res->file_offset, SEEK_SET);

		compression = sci0_get_compression_method(fh);
		close(fh);

		if (compression == 3)
			return (mgr->sci_version = SCI_VERSION_01_VGA);
	}

	return mgr->sci_version;
}
Example #4
0
const char *  /* Original version by Solomon Peachy */
version_guess_from_hashcode(sci_version_t *result, int *res_version, guint32 *code)
{
	int i;
	int fd = -1;
	int left = VERSION_DETECT_HASH_SIZE;
	guint32 hash_code;
	guint8 buf[VERSION_DETECT_BUF_SIZE];

	if (IS_VALID_FD(fd = sci_open("resource.001", O_RDONLY|O_BINARY))) {
		hash_code = HASHCODE_MAGIC_RESOURCE_001;
	} else if (IS_VALID_FD(fd = sci_open("resource.000", O_RDONLY|O_BINARY))) {
		hash_code = HASHCODE_MAGIC_RESOURCE_000;
	} else {
		sciprintf("Warning: Could not find RESOURCE.000 or RESOURCE.001, cannot determine hash code\n");
		*code = 0;
		/* complete and utter failure */
		return NULL;
	}

	while (left > 0) {
		int len = read(fd, buf, left < VERSION_DETECT_BUF_SIZE ? left : VERSION_DETECT_BUF_SIZE);

		if (len == -1) {
			sciprintf("Warning: read error while computing hash code for resource file\n");
			*code = 0;
			return NULL;
		}

		if (len == 0)
			/* EOF */
			break;

		for (i = 0; i < len; i++)
			hash_code = (hash_code * 19) + *(buf + i);

		/* This is the string hashing algorithm used by Objective Caml 3.08; the general idea
		** of multiplying the previous hash code with a prime number between 5 and 23 appears
		** to be generally considered to be a "good" approach to exhausting the entire 32 bit
		** number space in a somewhat equal distribution. For large chunks of data, such as
		** SCI resource files, this should both perform well and yield a good distribution,
		** or at least that's what standard library designers have been assuming for quite a
		** while. */

		left -= len;
	}

	close(fd);

	*code = hash_code;

	for (i = 0 ; sci_games[i].name ; i++) {
		if (sci_games[i].id == hash_code) {
			*result = sci_games[i].version;
			*res_version = sci_games[i].res_version;
			return sci_games[i].name;
		}
	}

	return NULL; /* Failed to find matching game */
}