Beispiel #1
0
int CheckCdrom() {
	struct iso_directory_record *dir;
	unsigned char time[4], *buf;
	unsigned char mdir[4096];
	char exename[256];
	int i, len, c;

	FreePPFCache();

	time[0] = itob(0);
	time[1] = itob(2);
	time[2] = itob(0x10);

	READTRACK();

	memset(CdromLabel, 0, sizeof(CdromLabel));
	memset(CdromId, 0, sizeof(CdromId));
	memset(exename, 0, sizeof(exename));

	strncpy(CdromLabel, buf + 52, 32);

	// skip head and sub, and go to the root directory record
	dir = (struct iso_directory_record *)&buf[12 + 156]; 

	mmssdd(dir->extent, (char *)time);

	READDIR(mdir);

	if (GetCdromFile(mdir, time, "SYSTEM.CNF;1") != -1) {
		READTRACK();

		sscanf((char *)buf + 12, "BOOT = cdrom:\\%255s", exename);
		if (GetCdromFile(mdir, time, exename) == -1) {
			sscanf((char *)buf + 12, "BOOT = cdrom:%255s", exename);
			if (GetCdromFile(mdir, time, exename) == -1) {
				char *ptr = strstr(buf + 12, "cdrom:");			// possibly the executable is in some subdir
				if (ptr != NULL) {
					ptr += 6;
					while (*ptr == '\\' || *ptr == '/') ptr++;
					strncpy(exename, ptr, 255);
					exename[255] = '\0';
					ptr = exename;
					while (*ptr != '\0' && *ptr != '\r' && *ptr != '\n') ptr++;
					*ptr = '\0';
					if (GetCdromFile(mdir, time, exename) == -1)
					 	return -1;		// main executable not found
				} else
					return -1;
			}
		}
	} else if (GetCdromFile(mdir, time, "PSX.EXE;1") != -1) {
		strcpy(exename, "PSX.EXE;1");
		strcpy(CdromId, "SLUS99999");
	} else
		return -1;		// SYSTEM.CNF and PSX.EXE not found

	if (CdromId[0] == '\0') {
		len = strlen(exename);
		c = 0;
		for (i = 0; i < len; ++i) {
			if (exename[i] == ';' || c >= sizeof(CdromId) - 1)
				break;
			if (isalnum(exename[i])) 
				CdromId[c++] = exename[i];
		}
	}

	if (Config.PsxAuto) { // autodetect system (pal or ntsc)
		if((CdromId[2] == 'e') || (CdromId[2] == 'E') ||
			!strncmp(CdromId, "DTLS3035", 8) ||
			!strncmp(CdromId, "PBPX95001", 9) || // according to redump.org, these PAL
			!strncmp(CdromId, "PBPX95007", 9) || // discs have a non-standard ID;
			!strncmp(CdromId, "PBPX95008", 9))   // add more serials if they are discovered.
			Config.PsxType = PSX_TYPE_PAL; // pal
		else Config.PsxType = PSX_TYPE_NTSC; // ntsc
	}

	if (Config.PsxStock == 0) {
		PsxClockSpeed = 33868800; // 33.8688 MHz (stock)
	} else {
		if (Config.PsxClock == 0) {
			PsxClockSpeed = 16934400; // 16.9344 MHz (0.5x)
		}
		if (Config.PsxClock == 1) {
			PsxClockSpeed = 25401600; // 25.4016 MHz (0.75x)
		}
		if (Config.PsxClock == 2) {
			PsxClockSpeed = 50803200; // 50.8032 MHz (1.5x)
		}
		if (Config.PsxClock == 3) {
			PsxClockSpeed = 67737600; // 67.7376 MHz (2x)
		}
		if (Config.PsxClock == 4) {
			PsxClockSpeed = 101606400; // 101.6064 MHz (3x)
		}
		if (Config.PsxClock == 5) {
			PsxClockSpeed = 135475200; // 135.4752 MHz (4x)
		}
		if (Config.PsxClock == 6) {
			PsxClockSpeed = 169344000; // 169.3440 MHz (5x)
		}
	}

	if (CdromLabel[0] == ' ') {
		strncpy(CdromLabel, CdromId, 9);
	}
	SysPrintf(_("CD-ROM Label: %.32s\n"), CdromLabel);
	SysPrintf(_("CD-ROM ID: %.9s\n"), CdromId);
	SysPrintf(_("CD-ROM EXE Name: %.255s\n"), exename);

	BuildPPFCache();
	LoadSBI(NULL);

	return 0;
}
Beispiel #2
0
int CheckCdrom() {
	struct iso_directory_record *dir;
	unsigned char time[4];
	char *buf;
	unsigned char mdir[4096];
	char exename[256];
	int i, c;

	FreePPFCache();

	time[0] = itob(0);
	time[1] = itob(2);
	time[2] = itob(0x10);

	READTRACK();

	CdromLabel[0] = '\0';
	CdromId[0] = '\0';

	strncpy(CdromLabel, buf + 52, 32);

	// skip head and sub, and go to the root directory record
	dir = (struct iso_directory_record *)&buf[12 + 156]; 

	mmssdd(dir->extent, (char *)time);

	READDIR(mdir);

	if (GetCdromFile(mdir, time, "SYSTEM.CNF;1") != -1) {
		READTRACK();

		sscanf(buf + 12, "BOOT = cdrom:\\%256s", exename);
		if (GetCdromFile(mdir, time, exename) == -1) {
			sscanf(buf + 12, "BOOT = cdrom:%256s", exename);
			if (GetCdromFile(mdir, time, exename) == -1) {
				char *ptr = strstr(buf + 12, "cdrom:");			// possibly the executable is in some subdir
				if (ptr != NULL) {
					ptr += 6;
					while (*ptr == '\\' || *ptr == '/') ptr++;
					strncpy(exename, ptr, 255);
					exename[255] = '\0';
					ptr = exename;
					while (*ptr != '\0' && *ptr != '\r' && *ptr != '\n') ptr++;
					*ptr = '\0';
					if (GetCdromFile(mdir, time, exename) == -1)
					 	return -1;		// main executable not found
				} else
					return -1;
			}
		}
	} else if (GetCdromFile(mdir, time, "PSX.EXE;1") != -1) {
		strcpy(exename, "PSX.EXE;1");
		strcpy(CdromId, "SLUS99999");
	} else
		return -1;		// SYSTEM.CNF and PSX.EXE not found

	if (CdromId[0] == '\0') {
		i = strlen(exename);
		if (i >= 2) {
			if (exename[i - 2] == ';') i-= 2;
			c = 8; i--;
			while (i >= 0 && c >= 0) {
				if (isalnum(exename[i])) CdromId[c--] = exename[i];
				i--;
			}
		}
	}

	if (CdromId[0] == '\0')
		strcpy(CdromId, "SLUS99999");

	if (Config.PsxAuto) { // autodetect system (pal or ntsc)
		if (CdromId[2] == 'e' || CdromId[2] == 'E')
			Config.PsxType = PSX_TYPE_PAL; // pal
		else Config.PsxType = PSX_TYPE_NTSC; // ntsc
	}

	if (CdromLabel[0] == ' ') {
		strncpy(CdromLabel, CdromId, 9);
	}
	SysPrintf(_("CD-ROM Label: %.32s\n"), CdromLabel);
	SysPrintf(_("CD-ROM ID: %.9s\n"), CdromId);

	BuildPPFCache();

	return 0;
}