Example #1
0
static adv_error cmd_mode_clock(void)
{
	adv_crtc* crtc;
	char buffer[80];
	double freq = 0;

	int i = menu_base + menu_rel;
	if (i >= menu_max)
		return 0;

	crtc = crtc_container_pos(&the_modes, i);

	sncpy(buffer, sizeof(buffer), "");
	switch (cmd_input_key(" Set Vertical/Horizontal/Pixel clock ? ", "vhp")) {
		case 0 :
			if (cmd_input_string(" Vertical clock [Hz] (example 60.0) : ", buffer, 10)!=0)
				return 0;
			freq = strtod(buffer, 0);
			if (freq < 10 || freq > 200) {
				error_set("Invalid vertical clock value, usually in the range 10 - 200.0 [Hz]");
				return -1;
			}
			crtc->pixelclock = freq * crtc->ht * crtc->vt;
			if (crtc_is_interlace(crtc))
				crtc->pixelclock /= 2;
			if (crtc_is_doublescan(crtc))
				crtc->pixelclock *= 2;
			break;
		case 1 :
			if (cmd_input_string(" Horizontal clock [kHz] (example 31.5) : ", buffer, 10)!=0)
				return 0;
			freq = strtod(buffer, 0) * 1E3;
			if (freq < 10*1E3 || freq > 100*1E3) {
				error_set("Invalid horizontal clock value, usually in the range 15.0 - 80.0 [kHz]");
				return -1;
			}
			crtc->pixelclock = freq * crtc->ht;
			break;
		case 2 :
			if (cmd_input_string(" Pixel clock [MHz] (example 14.0) : ", buffer, 10)!=0)
				return 0;
			freq = strtod(buffer, 0) * 1E6;
			if (freq < 1*1E6 || freq > 300*1E6) {
				error_set("Invalid pixel clock value, usually in the range 1.0 - 300.0 [MHz]");
				return -1;
			}
			crtc->pixelclock = freq;
			break;
		default: return 0;
	}

	menu_modify();

	return 0;
}
Example #2
0
static int score_compare_scanline(const struct advance_video_context* context, const adv_crtc* a, const adv_crtc* b)
{
	int as;
	int bs;

	log_std(("emu:video: compare scanline\n"));

	if (context->config.scanlines_flag) {
		if (crtc_is_doublescan(a))
			as = 1;
		else if (crtc_is_interlace(a))
			as = 2;
		else
			as = 0;
		if (crtc_is_doublescan(b))
			bs = 1;
		else if (crtc_is_interlace(b))
			bs = 2;
		else
			bs = 0;
	} else {
		if (crtc_is_doublescan(a))
			as = 0;
		else if (crtc_is_interlace(a))
			as = 2;
		else
			as = 1;
		if (crtc_is_doublescan(b))
			bs = 0;
		else if (crtc_is_interlace(b))
			bs = 2;
		else
			bs = 1;
	}

	if (as < bs)
		return -1;
	if (as > bs)
		return 1;

	return 0;
}
Example #3
0
/* Return the description of a video configuration */
void mode_desc_print(struct advance_video_context* context, char* buffer, unsigned size, const adv_crtc* crtc)
{
	double factor_x = (double)crtc_hsize_get(crtc) / context->state.mode_best_size_x;
	double factor_y = (double)crtc_vsize_get(crtc) / context->state.mode_best_size_y;
	char c;
	if (crtc_is_doublescan(crtc))
		c = 'd';
	else if (crtc_is_interlace(crtc))
		c = 'i';
	else
		c = 's';

	if ((context->config.adjust & ADJUST_ADJUST_X) != 0) {
		/* no real x size, it may be adjusted */
		snprintf(buffer, size, "%4d%c %4.2f", crtc_vsize_get(crtc), c, factor_y);
	} else {
		snprintf(buffer, size, "%4dx%4d%c %4.2fx%4.2f", crtc_hsize_get(crtc), crtc_vsize_get(crtc), c, factor_x, factor_y);
	}
}
void crtc_print(char* buffer, unsigned size, const adv_crtc* crtc)
{
	const char* flag1 = crtc_is_nhsync(crtc) ? " -hsync" : " +hsync";
	const char* flag2 = crtc_is_nvsync(crtc) ? " -vsync" : " +vsync";
	const char* flag3 = crtc_is_doublescan(crtc) ? " doublescan" : "";
	const char* flag4 = crtc_is_interlace(crtc) ? " interlace" : "";

	*buffer = 0;

	if (strchr(crtc->name, ' ')!=0)
		sncatf(buffer, size, "\"%s\"", crtc->name);
	else
		sncatf(buffer, size, "%s", crtc->name);

	sncatf(buffer, size, " %g %d %d %d %d %d %d %d %d%s%s%s%s",
		(double)crtc->pixelclock / 1E6,
		crtc->hde, crtc->hrs, crtc->hre, crtc->ht,
		crtc->vde, crtc->vrs, crtc->vre, crtc->vt,
		flag1, flag2, flag3, flag4
	);
}
Example #5
0
static adv_error none_mode_import(adv_mode* mode, const none_video_mode* none_mode)
{
	sncpy(mode->name, MODE_NAME_MAX, none_mode->crtc.name);

	*DRIVER(mode) = *none_mode;

	mode->driver = &video_none_driver;
	mode->flags = (mode->flags & MODE_FLAGS_USER_MASK)
		| none_mode->index;
	mode->size_x = DRIVER(mode)->crtc.hde;
	mode->size_y = DRIVER(mode)->crtc.vde;
	mode->vclock = crtc_vclock_get(&DRIVER(mode)->crtc);
	mode->hclock = crtc_hclock_get(&DRIVER(mode)->crtc);

	if (crtc_is_doublescan(&none_mode->crtc))
		mode->scan = 1;
	else if (crtc_is_interlace(&none_mode->crtc))
		mode->scan = -1;
	else
		mode->scan = 0;

	return 0;
}
Example #6
0
adv_error vgaline_mode_set(const vgaline_video_mode* mode)
{
	struct vga_regs regs;

	log_std_modeline_c(("vgaline: mode_set modeline", mode->crtc.pixelclock, mode->crtc.hde, mode->crtc.hrs, mode->crtc.hre, mode->crtc.ht, mode->crtc.vde, mode->crtc.vrs, mode->crtc.vre, mode->crtc.vt, crtc_is_nhsync(&mode->crtc), crtc_is_nvsync(&mode->crtc), crtc_is_doublescan(&mode->crtc), crtc_is_interlace(&mode->crtc)));

	if (vgaline_mode_realize(&regs, mode)!=0) {
		return -1;
	}

	vga_mode_set(&regs);

	if (mode->is_text) {
		vgaline_write_line = vgaline_write_line_text;
		switch (mode->font_y) {
			case 8 :
				vga_font_copy(vga_font_bios_8, 8, 0, 1);
				break;
			case 14 :
				vga_font_copy(vga_font_bios_14, 14, 0, 1);
				break;
			case 16 :
				vga_font_copy(vga_font_bios_16, 16, 0, 1);
				break;
		}
		vga_palette_raw_set(vga_palette_bios_text, 0, 256);
	} else {
		vgaline_write_line = vgaline_write_line_graph;
		vga_palette_raw_set(vga_palette_bios_graph, 0, 256);
	}

	vgaline_state.mode_active = 1;

	return 0;
}
Example #7
0
adv_error fb_mode_set(const fb_video_mode* mode)
{
	unsigned req_xres;
	unsigned req_yres;
	unsigned req_bits_per_pixel;

	assert(fb_is_active() && !fb_mode_is_active());

	log_std(("video:fb: fb_mode_set()\n"));

	log_std(("video:fb: get old\n"));

	/* get the current info */
	if (fb_getvar(&fb_state.oldinfo, 0) != 0) {
		error_set("Error getting the variable video mode information.\n");
		goto err;
	}

	fb_log(0, &fb_state.oldinfo);

	fb_preset(&fb_state.varinfo,
		mode->crtc.pixelclock,
		mode->crtc.hde, mode->crtc.hrs, mode->crtc.hre, mode->crtc.ht,
		mode->crtc.vde, mode->crtc.vrs, mode->crtc.vre, mode->crtc.vt,
		crtc_is_doublescan(&mode->crtc), crtc_is_interlace(&mode->crtc), crtc_is_nhsync(&mode->crtc), crtc_is_nvsync(&mode->crtc),
		mode->index, FB_ACTIVATE_NOW
	);

	log_std(("video:fb: set new\n"));

	fb_log(0, &fb_state.varinfo);

	/* save the minimun required data */
	req_xres = fb_state.varinfo.xres;
	req_yres = fb_state.varinfo.yres;
	req_bits_per_pixel = fb_state.varinfo.bits_per_pixel;

	/* set the mode */
	if (fb_setvar(&fb_state.varinfo) != 0) {
		error_set("Error setting the variable video mode information.\n");
		goto err;
	}

	log_std(("video:fb: get new\n"));

	/* get the fixed info */
	if (fb_getfix(&fb_state.fixinfo) != 0) {
		error_set("Error getting the fixed video mode information.\n");
		goto err_restore;
	}

	/* get the variable info */
	if (fb_getvar(&fb_state.varinfo, mode->index) != 0) {
		error_set("Error getting the variable video mode information.\n");
		goto err_restore;
	}

	fb_state.freq = fb_state.varinfo.pixclock;
	fb_state.freq *= fb_state.varinfo.xres + fb_state.varinfo.left_margin + fb_state.varinfo.right_margin + fb_state.varinfo.hsync_len;
	fb_state.freq *= fb_state.varinfo.yres + fb_state.varinfo.upper_margin + fb_state.varinfo.lower_margin + fb_state.varinfo.vsync_len;
	if (fb_state.freq != 0) {
		fb_state.freq = 1000000000000LL / fb_state.freq;
	}

	log_std(("video:fb: frequency %g\n", fb_state.freq));

	fb_log(&fb_state.fixinfo, &fb_state.varinfo);

	/* check the validity of the resulting video mode */
	if (req_xres > fb_state.varinfo.xres
		|| req_yres > fb_state.varinfo.yres
		|| req_bits_per_pixel != fb_state.varinfo.bits_per_pixel
	) {
		log_std(("ERROR:video:fb: request for mode %dx%d %d bits resulted in mode %dx%dx %d bits\n", req_xres, req_yres, req_bits_per_pixel, fb_state.varinfo.xres, fb_state.varinfo.yres, fb_state.varinfo.bits_per_pixel));
		error_set("Error setting the requested video mode.\n");
		goto err_restore;
	}
	if (req_xres != fb_state.varinfo.xres
		|| req_yres != fb_state.varinfo.yres
	) {
		/* allow bigger modes */
		log_std(("WARNING:video:fb: request for mode %dx%d resulted in mode %dx%dx\n", req_xres, req_yres, fb_state.varinfo.xres, fb_state.varinfo.yres));
	}

	if (fb_setup_color() != 0) {
		error_set("Error setting the color information.\n");
		goto err_restore;
	}

	fb_write_line = fb_linear_write_line;

	fb_state.bytes_per_pixel = (fb_state.varinfo.bits_per_pixel + 7) / 8;
	fb_state.bytes_per_scanline = fb_state.fixinfo.line_length;
	fb_state.index = mode->index;

	fb_state.ptr = mmap(0,
		fb_state.fixinfo.smem_len,
		PROT_READ | PROT_WRITE,
		MAP_SHARED,
		fb_state.fd,
		0
	);

	if (fb_state.ptr == MAP_FAILED) {
		error_set("Error mapping the video memory.\n");
		goto err_restore;
	}

	fb_state.wait_last = 0;
	fb_state.wait = fb_wait_detect; /* reset the wait mode */
	fb_state.wait_error = 0;

	fb_state.mode_active = 1;

	return 0;

err_restore:
	fb_setvar(&fb_state.oldinfo); /* ignore error */
err:
	return -1;
}
Example #8
0
static adv_bool test_exe_crtc(int userkey, adv_crtc* crtc)
{
	adv_bool modify = 0;
	unsigned pred_t;
	int xdelta;

	if (crtc->hde % 9 == 0 && crtc->hrs % 9 == 0 && crtc->hre % 9 == 0 && crtc->ht % 9 == 0)
		xdelta = 9;
	else
		xdelta = 8;

	switch (userkey) {
		case 'i' :
			pred_t = crtc->ht;
			crtc->ht -= crtc->ht % xdelta;
			crtc->ht -= xdelta;
			crtc->pixelclock = (double)crtc->pixelclock * crtc->ht / pred_t;
			modify = 1;
			break;
		case 'I' :
			pred_t = crtc->ht;
			crtc->ht -= crtc->ht % xdelta;
			crtc->ht += xdelta;
			crtc->pixelclock = (double)crtc->pixelclock * crtc->ht / pred_t;
			modify = 1;
			break;
		case 'k' :
			crtc->vt -= 1;
			modify = 1;
			break;
		case 'K' :
			crtc->vt += 1;
			modify = 1;
			break;
		case INPUTB_LEFT :
			crtc->hrs -= crtc->hrs % xdelta;
			crtc->hrs += xdelta;
			crtc->hre -= crtc->hre % xdelta;
			crtc->hre += xdelta;
			modify = 1;
			break;
		case INPUTB_RIGHT :
			crtc->hrs -= crtc->hrs % xdelta;
			crtc->hrs -= xdelta;
			crtc->hre -= crtc->hre % xdelta;
			crtc->hre -= xdelta;
			modify = 1;
			break;
		case INPUTB_DOWN :
			crtc->vrs -= 1;
			crtc->vre -= 1;
			modify = 1;
			break;
		case INPUTB_UP :
			crtc->vrs += 1;
			crtc->vre += 1;
			modify = 1;
			break;
		case 'u' :
		case 'U' :
			modify = 1;
			if (crtc_is_nhsync(crtc))
				crtc_phsync_set(crtc);
			else
				crtc_nhsync_set(crtc);
			break;
		case 'j' :
		case 'J' :
			modify = 1;
			if (crtc_is_nvsync(crtc))
				crtc_pvsync_set(crtc);
			else
				crtc_nvsync_set(crtc);
			break;
		case 'e' :
			crtc->hrs -= crtc->hrs % xdelta;
			crtc->hrs += xdelta;
			modify = 1;
			break;
		case 'E' :
			crtc->hrs -= crtc->hrs % xdelta;
			crtc->hrs -= xdelta;
			modify = 1;
			break;
		case 'r' :
			crtc->hre -= crtc->hre % xdelta;
			crtc->hre += xdelta;
			modify = 1;
			break;
		case 'R' :
			crtc->hre -= crtc->hre % xdelta;
			crtc->hre -= xdelta;
			modify = 1;
			break;
		case 'y' :
			crtc->ht -= crtc->ht % xdelta;
			crtc->ht += xdelta;
			modify = 1;
			break;
		case 'Y' :
			crtc->ht -= crtc->ht % xdelta;
			crtc->ht -= xdelta;
			modify = 1;
			break;
		case 'q' :
			crtc->hde -= crtc->hde % xdelta;
			crtc->hde += xdelta;
			modify = 1;
			break;
		case 'Q' :
			crtc->hde -= crtc->hde % xdelta;
			crtc->hde -= xdelta;
			modify = 1;
			break;
		case 'a' :
			++crtc->vde;
			modify = 1;
			break;
		case 'A' :
			--crtc->vde;
			modify = 1;
			break;
		case 'd' :
			++crtc->vrs;
			modify = 1;
			break;
		case 'D' :
			--crtc->vrs;
			modify = 1;
			break;
		case 'f' :
			++crtc->vre;
			modify = 1;
			break;
		case 'F' :
			--crtc->vre;
			modify = 1;
			break;
		case 'h' :
			++crtc->vt;
			modify = 1;
			break;
		case 'H' :
			--crtc->vt;
			modify = 1;
			break;
		case 'x' :
		case 'X' :
			modify = 1;
			if (crtc_is_doublescan(crtc))
				crtc_singlescan_set(crtc);
			else
				crtc_doublescan_set(crtc);
			break;
		case 'c' :
		case 'C' :
			modify = 1;
			if (crtc_is_interlace(crtc))
				crtc_singlescan_set(crtc);
			else
				crtc_interlace_set(crtc);
			break;
		case 'v' :
			modify = 1;
			crtc->pixelclock += 100000;
			break;
		case 'V' :
			modify = 1;
			crtc->pixelclock -= 100000;
			break;
	}
	return modify;
}
Example #9
0
static int test_crtc(int x, int y, adv_crtc* crtc, int print_clock, int print_measured_clock, int print_key)
{
	char buffer[256];

	snprintf(buffer, sizeof(buffer), "Horz  Vert");
	draw_string(x, y, buffer, DRAW_COLOR_WHITE);
	++y;

	if (print_clock) {
		snprintf(buffer, sizeof(buffer), "%4.1f %5.1f %sClock Requested [kHz Hz]", crtc_hclock_get(crtc) / 1E3, crtc_vclock_get(crtc), print_key ? "     " : "");
		draw_string(x, y, buffer, DRAW_COLOR_WHITE);
		++y;
	}

	if (print_measured_clock) {
		snprintf(buffer, sizeof(buffer), "     %5.1f %sClock Measured [Hz]", video_measured_vclock(), print_key ? "     " : "");
		draw_string(x, y, buffer, DRAW_COLOR_WHITE);
		++y;
	}

	snprintf(buffer, sizeof(buffer), "%4d  %4d %sDisplay End", crtc->hde, crtc->vde, print_key ? "[qa] " : "");
	draw_string(x, y, buffer, DRAW_COLOR_WHITE);
	++y;

	snprintf(buffer, sizeof(buffer), "%4d  %4d %sRetrace Start", crtc->hrs, crtc->vrs, print_key ? "[ed] " : "");
	draw_string(x, y, buffer, DRAW_COLOR_WHITE);
	++y;
	if (!(crtc->hde<=crtc->hrs)) {
		snprintf(buffer, sizeof(buffer), "HDE<=HRS");
		draw_string(x, y, buffer, DRAW_COLOR_RED);
		++y;
	}
	if (!(crtc->vde<=crtc->vrs)) {
		snprintf(buffer, sizeof(buffer), "VDE<=VRS");
		draw_string(x, y, buffer, DRAW_COLOR_RED);
		++y;
	}

	snprintf(buffer, sizeof(buffer), "%4d  %4d %sRetrace End", crtc->hre, crtc->vre, print_key ? "[rf] " : "");
	draw_string(x, y, buffer, DRAW_COLOR_WHITE);
	++y;
	if (!(crtc->hrs<crtc->hre)) {
		snprintf(buffer, sizeof(buffer), "HRS<HRE");
		draw_string(x, y, buffer, DRAW_COLOR_RED);
		++y;
	}
	if (!(crtc->vrs<crtc->vre)) {
		snprintf(buffer, sizeof(buffer), "VRE<VRE");
		draw_string(x, y, buffer, DRAW_COLOR_RED);
		++y;
	}

	snprintf(buffer, sizeof(buffer), "%4d  %4d %sTotal", crtc->ht, crtc->vt, print_key ? "[yh] " : "");
	draw_string(x, y, buffer, DRAW_COLOR_WHITE);
	++y;
	if (!(crtc->hre<=crtc->ht)) {
		snprintf(buffer, sizeof(buffer), "HRE<=HT");
		draw_string(x, y, buffer, DRAW_COLOR_RED);
		++y;
	}
	if (!(crtc->vre<=crtc->vt)) {
		snprintf(buffer, sizeof(buffer), "VRE<=VT");
		draw_string(x, y, buffer, DRAW_COLOR_RED);
		++y;
	}

	snprintf(buffer, sizeof(buffer), "   %c     %c %sPolarization", crtc_is_nhsync(crtc) ? '-' : '+', crtc_is_nvsync(crtc) ? '-' : '+', print_key ? "[uj] " : "");
	draw_string(x, y, buffer, DRAW_COLOR_WHITE);
	++y;

	snprintf(buffer, sizeof(buffer), "      %4s %sDoublescan", crtc_is_doublescan(crtc) ? "on" : "off", print_key ? "[x]  " : "");
	draw_string(x, y, buffer, DRAW_COLOR_WHITE);
	++y;

	snprintf(buffer, sizeof(buffer), "      %4s %sInterlaced", crtc_is_interlace(crtc) ? "on" : "off", print_key ? "[c]  " : "");
	draw_string(x, y, buffer, DRAW_COLOR_WHITE);
	++y;

	if (print_clock) {
		snprintf(buffer, sizeof(buffer), "%4.2f      %sPixelclock [MHz]", (double)crtc->pixelclock / 1E6, print_key ? "[v]  " : "");
		draw_string(x, y, buffer, DRAW_COLOR_WHITE);
		++y;
	}

	if (print_key) {
		++y;
		draw_string(x, y, "Q...U  Inc horz (SHIFT dec)", DRAW_COLOR_WHITE);
		++y;
		draw_string(x, y, "A...J  Inc vert (SHIFT dec)", DRAW_COLOR_WHITE);
		++y;
		draw_string(x, y, "I,K    Inc horz/vert size (SHIFT dec)", DRAW_COLOR_WHITE);
		++y;
		draw_string(x, y, "XCV    Flip flag", DRAW_COLOR_WHITE);
		++y;
		draw_string(x, y, "ARROWS Center", DRAW_COLOR_WHITE);
		++y;
	}

	return y;
}
Example #10
0
static void format_info(char* buffer0, char* buffer1, char* buffer2, unsigned size, adv_crtc* crtc)
{
	double HD, HF, HS, HB;
	double VD, VF, VS, VB;
	double f;

	HD = crtc->hde;
	HF = crtc->hrs - crtc->hde;
	HS = crtc->hre - crtc->hrs;
	HB = crtc->ht - crtc->hre;
	f = 1 / (HD+HF+HS+HB);
	HD *= f;
	HF *= f;
	HS *= f;
	HB *= f;

	VD = crtc->vde;
	VF = crtc->vrs - crtc->vde;
	VS = crtc->vre - crtc->vrs;
	VB = crtc->vt - crtc->vre;
	f = 1 / (VD+VF+VS+VB);
	VD *= f;
	VF *= f;
	VS *= f;
	VB *= f;

	snprintf(buffer0, size, "plz clock  dsen rtst rten totl  disp  front sync  back  pclock");
	snprintf(buffer1, size, "h%c %7.3f%5d%5d%5d%5d %6.3f%6.3f%6.3f%6.3f %8.4f", crtc_is_nhsync(crtc) ? '-' : '+', crtc_hclock_get(crtc) / 1E3, crtc->hde, crtc->hrs, crtc->hre, crtc->ht, HD, HF, HS, HB, crtc_pclock_get(crtc) / 1E6);
	snprintf(buffer2, size, "v%c %7.3f%5d%5d%5d%5d %6.3f%6.3f%6.3f%6.3f%s%s", crtc_is_nvsync(crtc) ? '-' : '+', crtc_vclock_get(crtc), crtc->vde, crtc->vrs, crtc->vre, crtc->vt, VD, VF, VS, VB, crtc_is_doublescan(crtc) ? " doublescan" : "", crtc_is_interlace(crtc) ? " interlace" : "");
}