Пример #1
0
static int gfx_check_vbe_mode_info(struct vbe_info *info, int mode,
                                   struct vbe_mode_info *mode_info)
{
    uint16_t *mp = info->video_modes;

    while (*mp != 0xFFFF) {
        if (*mp == mode)
            break;
        mp++;
    }

    if (*mp == 0xFFFF)
        return error("VBE mode %Xh not supported by graphics card or VBE driver", mode);

    if (vbe_get_mode_info(mode, mode_info) != 0)
        return error("Obtaining mode information for VBE mode %4X failed", mode);

    if (!test_bit(mode_info->mode_attributes, VBE_MODE_SUPPORTED_BY_HARDWARE))
        return error("VBE mode %Xh not supported by hardware configuration", mode);

    if (test_bit(mode_info->mode_attributes, VBE_MODE_NOT_VGA_COMPATIBLE))
        return error("VBE mode %Xh not VGA compatible", mode);

    if (!test_bit(mode_info->mode_attributes, VBE_LINEAR_FRAMEBUFFER_SUPPORTED))
        return error("Linear framebuffer not supported in VBE mode %Xh", mode);

    if (mode_info->number_of_image_pages < 1)
        return error("Insufficient graphics memory for double buffering");

    return 0;
}
Пример #2
0
//initializes video graphics mode
void *vg_init(unsigned short mode)
{
	/* Allow memory mapping */

	vbe_mode_info_t info;
	if(vbe_get_mode_info(mode, &info))
		return NULL;

	unsigned long vram_base ;/*= VRAM_PHYS_ADDR;*/
	unsigned long vram_size;
	h_res = info.XResolution;
	v_res = info.YResolution;
	bits_per_pixel = (unsigned) info.BitsPerPixel;
	bytes_per_pixel = bits_per_pixel/8;
	vram_phys_addr =  (void*)info.PhysBasePtr;
	vram_base = (unsigned long) info.PhysBasePtr;
	vram_size=(h_res * v_res * bits_per_pixel )/8;
	secondary_buf = malloc(vram_size);
	if(secondary_buf== NULL)
	{
		printf("Not enough memory for secondary buffer\n");
		return NULL;
	}
	map_virtual_memory(vram_base, vram_size, (void**)&video_mem);
	if(set_video_mode(mode))
		return NULL;
	return video_mem;
}
Пример #3
0
void *vg_init(unsigned short mode)
{
	struct reg86u reg86;

	reg86.u.b.intno = VBE_INTERRUPT_VECTOR; /* BIOS video services */
	reg86.u.b.ah = VBE_FUNCTION;
	reg86.u.b.al = VBE_SET_VBE_MODE;
	reg86.u.w.bx = mode | BIT(VBE_MODE_NUMBER_LINEAR_FLAT_FRAME_BUFFER_BIT);

	vbe_mode_info_t vbe_mode_info;
	if (sys_int86(&reg86) == OK)
	{
		if (reg86.u.w.ax == VBE_FUNCTION_SUPPORTED | VBE_FUNCTION_CALL_SUCCESSFUL)
		{
			if(vbe_get_mode_info(mode, &vbe_mode_info))
			{
				return NULL;
			}
			else
			{
				int r;
				struct mem_range mr;
				unsigned mr_size;

				h_res = vbe_mode_info.XResolution;
				v_res = vbe_mode_info.YResolution;
				bits_per_pixel = vbe_mode_info.BitsPerPixel;

				/* Allow memory mapping */

				mr.mr_base = vbe_mode_info.PhysBasePtr;
				mr_size = h_res * v_res * bits_per_pixel;
				mr.mr_limit = mr.mr_base + mr_size;

				if(sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mr))
				{
					return NULL;
				}

				/* Map memory */

				video_mem = vm_map_phys(SELF, (void *)mr.mr_base, mr_size);

				if(video_mem != MAP_FAILED)
				{
					if ((double_buffer = malloc(h_res * v_res * bits_per_pixel / 8)) != NULL)
					{
						if ((mouse_buffer = malloc(h_res * v_res * bits_per_pixel / 8)) != NULL)
						{
							return video_mem;
						}
					}
				}
			}
		}
	}
	return NULL;
}
Пример #4
0
void vbe_set_graphics(void)
{
	u8 rval;

	vbe_info_t info;
	rval = vbe_info(&info);
	if (rval != 0)
		return;

	DEBUG_PRINTF_VBE("VbeSignature: %s\n", info.signature);
	DEBUG_PRINTF_VBE("VbeVersion: 0x%04x\n", info.version);
	DEBUG_PRINTF_VBE("OemString: %s\n", info.oem_string_ptr);
	DEBUG_PRINTF_VBE("Capabilities:\n");
	DEBUG_PRINTF_VBE("\tDAC: %s\n",
			 (info.capabilities & 0x1) ==
			 0 ? "fixed 6bit" : "switchable 6/8bit");
	DEBUG_PRINTF_VBE("\tVGA: %s\n",
			 (info.capabilities & 0x2) ==
			 0 ? "compatible" : "not compatible");
	DEBUG_PRINTF_VBE("\tRAMDAC: %s\n",
			 (info.capabilities & 0x4) ==
			 0 ? "normal" : "use blank bit in Function 09h");

	mode_info.video_mode = (1 << 14) | CONFIG_FRAMEBUFFER_VESA_MODE;
	vbe_get_mode_info(&mode_info);
	vbe_set_mode(&mode_info);

#if CONFIG_BOOTSPLASH
	unsigned char *framebuffer =
		(unsigned char *) le32_to_cpu(mode_info.vesa.phys_base_ptr);
	DEBUG_PRINTF_VBE("FRAMEBUFFER: 0x%p\n", framebuffer);

	struct jpeg_decdata *decdata;

	/* Switching Intel IGD to 1MB video memory will break this. Who
	 * cares. */
	// int imagesize = 1024*768*2;

	unsigned char *jpeg = cbfs_get_file_content(CBFS_DEFAULT_MEDIA,
						    "bootsplash.jpg",
						    CBFS_TYPE_BOOTSPLASH,
						    NULL);
	if (!jpeg) {
		DEBUG_PRINTF_VBE("Could not find bootsplash.jpg\n");
		return;
	}
	DEBUG_PRINTF_VBE("Splash at %p ...\n", jpeg);
	dump(jpeg, 64);

	decdata = malloc(sizeof(*decdata));
	int ret = 0;
	DEBUG_PRINTF_VBE("Decompressing boot splash screen...\n");
	ret = jpeg_decode(jpeg, framebuffer, 1024, 768, 16, decdata);
	DEBUG_PRINTF_VBE("returns %x\n", ret);
#endif
}
Пример #5
0
void* vg_init(unsigned short mode) {
	struct mem_range mr;
	vbe_mode_info_t vmi_p;
	struct reg86u reg86;

	reg86.u.b.intno = BIOS_VIDEO;
	reg86.u.b.ah = VBE;
	reg86.u.b.al = SET_VBE;
	reg86.u.w.bx = BIT(LINEAR_BIT) | mode;

	if (sys_int86(&reg86)) {
		printf("vg_init()::bios call didn't return 0\n");
		return NULL;
	}

	if (vbe_get_mode_info(mode, &vmi_p) == -1) {
		printf("vg_init()::failed in vbe_get_mode_info");
		return NULL;
	}

	h_res = vmi_p.XResolution;
	v_res = vmi_p.YResolution;
	bits_per_pixel = vmi_p.BitsPerPixel;
	if (bits_per_pixel / 8 > 0)
		bytes_per_pixel = bits_per_pixel / 8;
	else
		bytes_per_pixel = 1;
	vram_size = h_res * v_res * bytes_per_pixel;

	int r;

	/* Allow memory mapping */

	mr.mr_base = vmi_p.PhysBasePtr;
	mr.mr_limit = mr.mr_base + vram_size;

	if (sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mr) != 0) {
		panic("video_txt: sys_privctl (ADD_MEM) failed: %d\n", r);
		return NULL;
	}

	/* Map memory */

	video_mem = vm_map_phys(SELF, (void *) mr.mr_base, vram_size);
	buffer = malloc(vram_size);

	if (video_mem == MAP_FAILED) {
		panic("video_txt couldn't map video memory");
		return NULL;
	}

	return video_mem;

}
Пример #6
0
status_t
vesa_set_display_mode(vesa_info& info, uint32 mode)
{
	if (mode >= info.shared_info->vesa_mode_count)
		return B_ENTRY_NOT_FOUND;

	// Prepare vm86 mode environment
	struct vm86_state vmState;
	status_t status = vm86_prepare(&vmState, 0x20000);
	if (status != B_OK) {
		dprintf(DEVICE_NAME": vesa_set_display_mode(): vm86_prepare failed\n");
		return status;
	}

	// Get mode information
	struct vbe_mode_info modeInfo;
	status = vbe_get_mode_info(vmState, info.modes[mode].mode, &modeInfo);
	if (status != B_OK) {
		dprintf(DEVICE_NAME": vesa_set_display_mode(): cannot get mode info\n");
		goto out;
	}

	// Set mode
	status = vbe_set_mode(vmState, info.modes[mode].mode);
	if (status != B_OK) {
		dprintf(DEVICE_NAME": vesa_set_display_mode(): cannot set mode\n");
		goto out;
	}

	if (info.modes[mode].bits_per_pixel <= 8)
		vbe_set_bits_per_gun(vmState, info, 8);

	// Map new frame buffer if necessary

	status = remap_frame_buffer(info, modeInfo.physical_base, modeInfo.width,
		modeInfo.height, modeInfo.bits_per_pixel, modeInfo.bytes_per_row,
		false);
	if (status == B_OK) {
		// Update shared frame buffer information
		info.shared_info->current_mode.virtual_width = modeInfo.width;
		info.shared_info->current_mode.virtual_height = modeInfo.height;
		info.shared_info->current_mode.space = get_color_space_for_depth(
			modeInfo.bits_per_pixel);
	}

out:
	vm86_cleanup(&vmState);
	return status;
}
Пример #7
0
void *vg_init(unsigned short mode) {


	vbe_mode_info_t config;

	if ( vbe_set_mode(VBE_MODE, mode) == 1) //set graphic mode
		return NULL;

	if (vbe_get_mode_info(mode, &config) != 0) //get vbe info
	{
		return NULL;
	}

	h_res = config.XResolution; //store X Resolution
	v_res = config.YResolution; //store Y Resolution
	bits_per_pixel = config.BitsPerPixel; //store Bits Per Pixel
	vram_size = (config.XResolution * config.YResolution * config.BitsPerPixel) / 8; //store the size of the vram


	int r;
	struct mem_range mr;

	/* Allow memory mapping */

	mr.mr_base = (config.PhysBasePtr);
	mr.mr_limit = mr.mr_base + (config.XResolution * config.YResolution * config.BitsPerPixel) / 8;

	if( OK != (r = sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mr)))
		panic("video_txt: sys_privctl (ADD_MEM) failed: %d\n", r);

	/* Map memory */

	video_mem = vm_map_phys(SELF, (void *)mr.mr_base, (config.XResolution * config.YResolution * config.BitsPerPixel) / 8);

	if(video_mem == MAP_FAILED)
		panic("video_txt couldn't map video memory");


	if (video_mem == NULL)
	{
		printf("vg_init: Error!\n");
		vg_exit();
		return NULL;
	}
	return config.PhysBasePtr;
}
Пример #8
0
void *test_init(unsigned short mode, unsigned short delay) {

	char *video_mem;
	vbe_mode_info_t vbe;
	video_mem = vg_init(mode);

	if (vbe_get_mode_info(mode, &vbe) == 1) {
		printf("Failed vbe_get_mode_info().\n");
		return;
	}

	timer_test_int(delay);

	if (vg_exit() == 1) {
		printf("Failed vg_exit().\n");
		return;
	}

	printf("Physical Adress VRAM: 0x%x",vbe.PhysBasePtr);
	return video_mem;
}
Пример #9
0
void *test_init(unsigned short mode, unsigned short delay) {
	void *ret;
	vbe_mode_info_t vmi_p;

	if ((ret = vg_init(mode)) == NULL)
		return NULL;

	timer_test_int(delay);

	if (vbe_get_mode_info(mode, &vmi_p) != 0)
		return NULL;

	if (vg_exit() != 0)
		return NULL;

	//test to see if vbe_get_mode_info is working
	printf("X res: %d\nY res: %d\nBits per pixel: %d\nPhysical Address: %x",
			vmi_p.XResolution, vmi_p.YResolution, vmi_p.BitsPerPixel,
			vmi_p.PhysBasePtr);

	return ret;
}
Пример #10
0
static u32
vbe_get_info(void)
{
	u8 rval;
	int i;

	// XXX FIXME these need to be filled with sane values

	// get a copy of input struct...
	screen_info_input_t input;
	// output is pointer to the address passed as argv[4]
	screen_info_t local_output;
	screen_info_t *output = &local_output;
	// zero input
	memset(&input, 0, sizeof(screen_info_input_t));
	// zero output
	memset(&output, 0, sizeof(screen_info_t));

	vbe_info_t info;
	rval = vbe_info(&info);
	if (rval != 0)
		return rval;

	DEBUG_PRINTF_VBE("VbeSignature: %s\n", info.signature);
	DEBUG_PRINTF_VBE("VbeVersion: 0x%04x\n", info.version);
	DEBUG_PRINTF_VBE("OemString: %s\n", info.oem_string_ptr);
	DEBUG_PRINTF_VBE("Capabilities:\n");
	DEBUG_PRINTF_VBE("\tDAC: %s\n",
			 (info.capabilities & 0x1) ==
			 0 ? "fixed 6bit" : "switchable 6/8bit");
	DEBUG_PRINTF_VBE("\tVGA: %s\n",
			 (info.capabilities & 0x2) ==
			 0 ? "compatible" : "not compatible");
	DEBUG_PRINTF_VBE("\tRAMDAC: %s\n",
			 (info.capabilities & 0x4) ==
			 0 ? "normal" : "use blank bit in Function 09h");

	// argv[4] may be a pointer with enough space to return screen_info_t
	// as input, it must contain a screen_info_input_t with the following content:
	// byte[0:3] = "DDC\0" (zero-terminated signature header)
	// byte[4:5] = reserved space for the return struct... just in case we ever change
	//             the struct and don't have reserved enough memory (and let's hope the struct
	//             never gets larger than 64KB)
	// byte[6] = monitor port number for DDC requests ("only" one byte... so lets hope we never have more than 255 monitors...
	// byte[7:8] = max. screen width (OF may want to limit this)
	// byte[9] = required color depth in bpp
	if (strncmp((char *) input.signature, "DDC", 4) != 0) {
		printf
		    ("%s: Invalid input signature! expected: %s, is: %s\n",
		     __func__, "DDC", input.signature);
		return -1;
	}
	if (input.size_reserved != sizeof(screen_info_t)) {
		printf
		    ("%s: Size of return struct is wrong, required: %d, available: %d\n",
		     __func__, (int) sizeof(screen_info_t),
		     input.size_reserved);
		return -1;
	}

	vbe_ddc_info_t ddc_info;
	ddc_info.port_number = input.monitor_number;
	vbe_get_ddc_info(&ddc_info);

#if 0
	DEBUG_PRINTF_VBE("DDC: edid_tranfer_time: %d\n",
			 ddc_info.edid_transfer_time);
	DEBUG_PRINTF_VBE("DDC: ddc_level: %x\n", ddc_info.ddc_level);
	DEBUG_PRINTF_VBE("DDC: EDID: \n");
	CHECK_DBG(DEBUG_VBE) {
		dump(ddc_info.edid_block_zero,
		     sizeof(ddc_info.edid_block_zero));
	}
#endif
/* This could fail because of alignment issues, so use a longer form.
	*((u64 *) ddc_info.edid_block_zero) != (u64) 0x00FFFFFFFFFFFF00ULL
*/
	if (ddc_info.edid_block_zero[0] != 0x00 ||
	    ddc_info.edid_block_zero[1] != 0xFF ||
	    ddc_info.edid_block_zero[2] != 0xFF ||
	    ddc_info.edid_block_zero[3] != 0xFF ||
	    ddc_info.edid_block_zero[4] != 0xFF ||
	    ddc_info.edid_block_zero[5] != 0xFF ||
	    ddc_info.edid_block_zero[6] != 0xFF ||
	    ddc_info.edid_block_zero[7] != 0x00 ) {
		// invalid EDID signature... probably no monitor

		output->display_type = 0x0;
		return 0;
	} else if ((ddc_info.edid_block_zero[20] & 0x80) != 0) {
		// digital display
		output->display_type = 2;
	} else {
		// analog
		output->display_type = 1;
	}
	DEBUG_PRINTF_VBE("DDC: found display type %d\n", output->display_type);
	memcpy(output->edid_block_zero, ddc_info.edid_block_zero,
	       sizeof(ddc_info.edid_block_zero));
	i = 0;
	vbe_mode_info_t mode_info;
	vbe_mode_info_t best_mode_info;
	// initialize best_mode to 0
	memset(&best_mode_info, 0, sizeof(best_mode_info));
	while ((mode_info.video_mode = info.video_mode_list[i]) != 0xFFFF) {
		//DEBUG_PRINTF_VBE("%x: Mode: %04x\n", i, mode_info.video_mode);
		vbe_get_mode_info(&mode_info);

		// FIXME all these values are little endian!

		DEBUG_PRINTF_VBE("Video Mode 0x%04x available, %s\n",
				 mode_info.video_mode,
				 (le16_to_cpu(mode_info.vesa.mode_attributes) & 0x1) ==
				 0 ? "not supported" : "supported");
		DEBUG_PRINTF_VBE("\tTTY: %s\n",
				 (le16_to_cpu(mode_info.vesa.mode_attributes) & 0x4) ==
				 0 ? "no" : "yes");
		DEBUG_PRINTF_VBE("\tMode: %s %s\n",
				 (le16_to_cpu(mode_info.vesa.mode_attributes) & 0x8) ==
				 0 ? "monochrome" : "color",
				 (le16_to_cpu(mode_info.vesa.mode_attributes) & 0x10) ==
				 0 ? "text" : "graphics");
		DEBUG_PRINTF_VBE("\tVGA: %s\n",
				 (le16_to_cpu(mode_info.vesa.mode_attributes) & 0x20) ==
				 0 ? "compatible" : "not compatible");
		DEBUG_PRINTF_VBE("\tWindowed Mode: %s\n",
				 (le16_to_cpu(mode_info.vesa.mode_attributes) & 0x40) ==
				 0 ? "yes" : "no");
		DEBUG_PRINTF_VBE("\tFramebuffer: %s\n",
				 (le16_to_cpu(mode_info.vesa.mode_attributes) & 0x80) ==
				 0 ? "no" : "yes");
		DEBUG_PRINTF_VBE("\tResolution: %dx%d\n",
				 le16_to_cpu(mode_info.vesa.x_resolution),
				 le16_to_cpu(mode_info.vesa.y_resolution));
		DEBUG_PRINTF_VBE("\tChar Size: %dx%d\n",
				 mode_info.vesa.x_charsize, mode_info.vesa.y_charsize);
		DEBUG_PRINTF_VBE("\tColor Depth: %dbpp\n",
				 mode_info.vesa.bits_per_pixel);
		DEBUG_PRINTF_VBE("\tMemory Model: 0x%x\n",
				 mode_info.vesa.memory_model);
		DEBUG_PRINTF_VBE("\tFramebuffer Offset: %08x\n",
				 le32_to_cpu(mode_info.vesa.phys_base_ptr));

		if ((mode_info.vesa.bits_per_pixel == input.color_depth)
		    && (le16_to_cpu(mode_info.vesa.x_resolution) <= input.max_screen_width)
		    && ((le16_to_cpu(mode_info.vesa.mode_attributes) & 0x80) != 0)	// framebuffer mode
		    && ((le16_to_cpu(mode_info.vesa.mode_attributes) & 0x10) != 0)	// graphics
		    && ((le16_to_cpu(mode_info.vesa.mode_attributes) & 0x8) != 0)	// color
		    && (le16_to_cpu(mode_info.vesa.x_resolution) > le16_to_cpu(best_mode_info.vesa.x_resolution)))	// better than previous best_mode
		{
			// yiiiihaah... we found a new best mode
			memcpy(&best_mode_info, &mode_info, sizeof(mode_info));
		}
		i++;
	}

	if (best_mode_info.video_mode != 0) {
		DEBUG_PRINTF_VBE
		    ("Best Video Mode found: 0x%x, %dx%d, %dbpp, framebuffer_address: 0x%x\n",
		     best_mode_info.video_mode,
		     best_mode_info.vesa.x_resolution,
		     best_mode_info.vesa.y_resolution,
		     best_mode_info.vesa.bits_per_pixel,
		     le32_to_cpu(best_mode_info.vesa.phys_base_ptr));

		//printf("Mode Info Dump:");
		//dump(best_mode_info.mode_info_block, 64);

		// set the video mode
		vbe_set_mode(&best_mode_info);

		if ((info.capabilities & 0x1) != 0) {
			// switch to 8 bit palette format
			vbe_set_palette_format(8);
		}
		// setup a palette:
		// - first 216 colors are mixed colors for each component in 6 steps
		//   (6*6*6=216)
		// - then 10 shades of the three primary colors
		// - then 10 shades of grey
		// -------
		// = 256 colors
		//
		// - finally black is color 0 and white color FF (because SLOF expects it
		//   this way...)
		// this resembles the palette that the kernel/X Server seems to expect...

		u8 mixed_color_values[6] =
		    { 0xFF, 0xDA, 0xB3, 0x87, 0x54, 0x00 };
		u8 primary_color_values[10] =
		    { 0xF3, 0xE7, 0xCD, 0xC0, 0xA5, 0x96, 0x77, 0x66, 0x3F,
			0x27
		};
		u8 mc_size = sizeof(mixed_color_values);
		u8 prim_size = sizeof(primary_color_values);

		u8 curr_color_index;
		u32 curr_color;

		u8 r, g, b;
		// 216 mixed colors
		for (r = 0; r < mc_size; r++) {
			for (g = 0; g < mc_size; g++) {
				for (b = 0; b < mc_size; b++) {
					curr_color_index =
					    (r * mc_size * mc_size) +
					    (g * mc_size) + b;
					curr_color = 0;
					curr_color |= ((u32) mixed_color_values[r]) << 16;	//red value
					curr_color |= ((u32) mixed_color_values[g]) << 8;	//green value
					curr_color |= (u32) mixed_color_values[b];	//blue value
					vbe_set_color(curr_color_index,
						      curr_color);
				}
			}
		}

		// 10 shades of each primary color
		// red
		for (r = 0; r < prim_size; r++) {
			curr_color_index = mc_size * mc_size * mc_size + r;
			curr_color = ((u32) primary_color_values[r]) << 16;
			vbe_set_color(curr_color_index, curr_color);
		}
		//green
		for (g = 0; g < prim_size; g++) {
			curr_color_index =
			    mc_size * mc_size * mc_size + prim_size + g;
			curr_color = ((u32) primary_color_values[g]) << 8;
			vbe_set_color(curr_color_index, curr_color);
		}
		//blue
		for (b = 0; b < prim_size; b++) {
			curr_color_index =
			    mc_size * mc_size * mc_size + prim_size * 2 + b;
			curr_color = (u32) primary_color_values[b];
			vbe_set_color(curr_color_index, curr_color);
		}
		// 10 shades of grey
		for (i = 0; i < prim_size; i++) {
			curr_color_index =
			    mc_size * mc_size * mc_size + prim_size * 3 + i;
			curr_color = 0;
			curr_color |= ((u32) primary_color_values[i]) << 16;	//red
			curr_color |= ((u32) primary_color_values[i]) << 8;	//green
			curr_color |= ((u32) primary_color_values[i]);	//blue
			vbe_set_color(curr_color_index, curr_color);
		}

		// SLOF is using color 0x0 (black) and 0xFF (white) to draw to the screen...
		vbe_set_color(0x00, 0x00000000);
		vbe_set_color(0xFF, 0x00FFFFFF);

		output->screen_width = le16_to_cpu(best_mode_info.vesa.x_resolution);
		output->screen_height = le16_to_cpu(best_mode_info.vesa.y_resolution);
		output->screen_linebytes = le16_to_cpu(best_mode_info.vesa.bytes_per_scanline);
		output->color_depth = best_mode_info.vesa.bits_per_pixel;
		output->framebuffer_address =
		    le32_to_cpu(best_mode_info.vesa.phys_base_ptr);
	} else {
		printf("%s: No suitable video mode found!\n", __func__);
		//unset display_type...
		output->display_type = 0;
	}
	return 0;
}
Пример #11
0
void * vg_init(unsigned long mode) {

	// -----------------------
	// -Non-Hardcoded Version-
	// -----------------------

	struct reg86u reg86;
	vbe_mode_info_t vmi;
	
	int r;
	struct mem_range mr;

	reg86.u.w.ax = 0x4F02;
	reg86.u.w.bx = 1<<14|mode;
	reg86.u.b.intno = 0x10;

	if(sys_int86(&reg86) != OK) {
		printf("set_vbe_mode: sys_int86() failed\n");
		return NULL;
	}
	else {
		vbe_get_mode_info(mode, &vmi);

		h_res = vmi.XResolution;
		v_res = vmi.YResolution;
		bits_per_pixel = vmi.BitsPerPixel;

		mr.mr_base = vmi.PhysBasePtr;
		mr.mr_limit = mr.mr_base + (h_res * v_res * (bits_per_pixel / 8));
		
		if((r = sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mr)) != OK) {
			panic("vg_init: sys_privctl (ADD_MEM) failed: %d\n", r);
			return NULL;
		}
		else {
			video_mem = vm_map_phys(SELF, (void *)mr.mr_base, (h_res * v_res * (bits_per_pixel / 8)));

			if(video_mem == MAP_FAILED){
				panic("vg_init: Couldn't map video memory!\n");
				return NULL;
			} else
				return video_mem;
		}
	}

	// -------------------
	// -Hardcoded Version-
	// -------------------
	/*
	struct reg86u reg86;
	vbe_mode_info_t vmi;

	int r;
	struct mem_range mr;

	reg86.u.w.ax = 0x4F02;
	reg86.u.w.bx = 1<<14|mode;
	reg86.u.b.intno = 0x10;

	if(sys_int86(&reg86) != OK) {
		printf("set_vbe_mode: sys_int86() failed\n");
		return NULL;
	}
	else {

		h_res = H_RES;
		v_res = V_RES;
		bits_per_pixel = BITS_PER_PIXEL;

		mr.mr_base = VRAM_PHYS_ADDR;
		mr.mr_limit = mr.mr_base + (h_res * v_res * (bits_per_pixel / 8));

		if((r = sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mr)) != OK) {
			panic("vg_init: sys_privctl (ADD_MEM) failed: %d\n", r);
			return NULL;
		}
		else {
			video_mem = vm_map_phys(SELF, (void *)mr.mr_base, (h_res * v_res * (bits_per_pixel / 8)));

			if(video_mem == MAP_FAILED){
				panic("vg_init: Couldn't map video memory!\n");
				return NULL;
			} else
				return video_mem;
		}
	}*/

}
Пример #12
0
void *vg_init(unsigned short mode) {
	vbe_mode_info_t info;
	struct reg86u reg86;
	int r;
	struct mem_range mr;

	reg86.u.b.intno = BIOS_VIDEO_INT; /* BIOS video services */
	reg86.u.w.ax = SET_VBE_MODE; /* Set Video Mode function */
	reg86.u.w.bx = SET_LINEAR_MODE | mode; /* Mode */

	if (sys_int86(&reg86) != OK) { // Sets video mode
		printf("\tvg_init(): sys_int86() failed \n");
		return NULL;
	}

	switch (reg86.u.w.ax) {
	case VBE_FUNC_CALL_FAILED:
		printf("\tvg_init(): sys_int86() function call failed.\n");
		return NULL;
		break;
	case VBE_FUNC_NOT_SUPPORTED:
		printf("\tvg_init(): sys_int86() function not supported.\n");
		return NULL;
		break;
	case VBE_FUNC_INVALID_CUR_MODE:
		printf(
				"\tvg_init(): sys_int86() function invalid in current video mode.\n");
		return NULL;
		break;
	}

	if (lm_init() == NULL) {
		printf("\tvg_init(): lm_init() failed \n");
		return NULL;
	}

	if (vbe_get_mode_info(mode, &info) != OK) { // Gets info
		printf("\tvg_init(): vbe_get_mode_info() failed \n");
		return NULL;
	}

	h_res = info.XResolution;
	v_res = info.YResolution; //Sets global variables
	bits_per_pixel = info.BitsPerPixel;

	//Allow memory mapping

	mr.mr_base = (phys_bytes)(info.PhysBasePtr);
	mr.mr_limit = mr.mr_base
			+ info.XResolution * info.YResolution * info.BitsPerPixel / 8;

	if (OK != (r = sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mr)))
		panic("video_txt: sys_privctl (ADD_MEM) failed: %d\n", r);

	// Map memory

	video_mem = vm_map_phys(SELF, (void *) mr.mr_base,
			info.XResolution * info.YResolution * info.BitsPerPixel / 8);

	double_buffer = malloc(h_res * v_res * sizeof(char));

	/*if(video_mem == MAP_FAILED)
	 panic("video_txt couldn't map video memory");*/

	return video_mem;
}
Пример #13
0
int main(int argc, char **argv)
{
	struct vbe_info *vbe_info = NULL;
	struct vbe_mode_info *mode_info = NULL;
	u_int16_t *mode_list = NULL;
	int mode_count = 0;
	float vesa_version;

	/* Get basic information. */
	vbe_info = vbe_get_vbe_info();
	if(vbe_info == NULL) {
		printf("VESA BIOS Extensions not detected.\n");
		exit(0);
	}

	/* Print the signature, should be "VESA <digit>.<digit>". */
	printf("%c%c%c%c %d.%d detected.\n",
	       vbe_info->signature[0], vbe_info->signature[1],
	       vbe_info->signature[2], vbe_info->signature[3],
	       vbe_info->version[1], vbe_info->version[0]);
	vesa_version =  (vbe_info->version[1]) + (vbe_info->version[0]) / 10.0;

	/* List supported standard modes. */
	mode_list = vbe_info->mode_list.list;
	if(*mode_list != 0xffff) {
		printf("Supported modes:\n");
	}
	/* Count the number of modes. */
	for(;*mode_list != 0xffff; mode_list++) {
		mode_count++;
	}
	/* Sort the mode list, because my ATI doesn't.  Grrr... */
	mode_list = vbe_info->mode_list.list;
	if(*mode_list != 0xffff) {
		qsort(mode_list, mode_count, sizeof(u_int16_t), compare_16);
	}
	/* Dump info about the video mode. */
	for(;*mode_list != 0xffff; mode_list++) {
		int j;
		/* Mode number. */
		printf("0x%03x\t", *mode_list);
		for(j = 0; known_vesa_modes[j].x != 0; j++) {
		/* If it's a standard mode, print info about it. */
		if(known_vesa_modes[j].number == *mode_list) {
			printf("Specs list this as %dx%d, %d colors.",
			       known_vesa_modes[j].x,
			       known_vesa_modes[j].y,
			       known_vesa_modes[j].colors);
		}}
		printf("\n");
		/* Get mode information from the BIOS.  Should never fail. */
		mode_info = vbe_get_mode_info(*mode_list);
		if(mode_info == NULL) {
			printf("Get mode information not supported by BIOS.\n");
			exit(0);
		}

		/* Report what the BIOS says about the mode, should agree
		   with VESA on standard modes. */
		if(mode_info->w && mode_info->h && mode_info->bpp) {
			printf("\tBIOS reports this as %dx%d, %d bpp",
			       mode_info->w, mode_info->h,
			       mode_info->bpp);
		}
		if(mode_info->bytes_per_scanline) {
			printf(", %d bytes per scanline.",
			       mode_info->bytes_per_scanline);
		}
		printf("\n");
		/* Check the 'supported' bit.  Should be set, because this is
		   in the main supported modes list. */
		printf("\t%s, ", mode_info->mode_attributes.supported ?
		       "Supported" : "Not supported");
		/* Color?  Graphics? */
		printf("%s ", mode_info->mode_attributes.color ?
		       "Color" : "Monochrome");
		printf("%s.\n", mode_info->mode_attributes.graphics ?
		       "Graphics" : "Text");
		/* Check for LFB stuff.  Ralf's list says that you need to
		   query with bit 14 set to check if an LFB version of the mode
		   is available, but the ATI always returns true. */
		if(vesa_version >= 2.0) {
			/* Regular info about the current mode. */
			struct vbe_mode_info *info = NULL;
			printf("\t%sVGA compatible.\n",
			       mode_info->mode_attributes.not_vga_compatible ?
			       "Not " : "");
			printf("\tThis is %san LFB mode.\n",
			       mode_info->mode_attributes.lfb ?
			       "" : "not ");
			/* Info about the LFB variant mode (bit 14 set). */
			info = vbe_get_mode_info(*mode_list |
						 VBE_LINEAR_FRAMEBUFFER);
			if(info) {
				if(info->mode_attributes.lfb) {
					printf("\tLFB variant available.\n");
				}
				free(info);
			}
			if((mode_info->mode_attributes.lfb) ||
			   (info && (info->mode_attributes.lfb))) {
				printf("\tLFB at address 0x%8x.\n",
				       mode_info->linear_buffer_address);
			}
		}
		/* Memory model: EGA = icky bit planes, packed-pixel = palette,
		   direct color = LFB compatible but needs bank switches. */
		printf("\tMemory model: ");
		switch(mode_info->memory_model) {
			case memory_model_text: {
				printf("text.\n");
				break;
			}
       			case memory_model_cga: {
				printf("CGA.\n");
				break;
			}
       			case memory_model_hgc: {
				printf("Hercules.\n");
				break;
			}
       			case memory_model_ega16: {
				printf("EGA.\n");
				break;
			}
       			case memory_model_packed_pixel: {
				printf("packed-pixel.\n");
				break;
			}
       			case memory_model_sequ256: {
				printf("sequential 256.\n");
				break;
			}
       			case memory_model_direct_color: {
				printf("direct color.\n");
				break;
			}
       			case memory_model_yuv: {
				printf("YUV.\n");
				break;
			}
			default : {
				printf("unknown/OEM.\n");
			}
		}
	}
	return 0;
}
Пример #14
0
void *vg_init(unsigned short mode)
{
	struct reg86u r;
	vbe_mode_info_t *info = malloc(sizeof(vbe_mode_info_t));

	if (vbe_get_mode_info(mode, info) != 0)
	{
		return NULL;
	}
	h_res=info->XResolution;
	v_res=info->YResolution;
	bits_per_pixel=info->BitsPerPixel;

	printf("%d\n", h_res);

	int erro;
	struct mem_range mr;

	/* Allow memory mapping */

	unsigned int vram_size = h_res * v_res * (bits_per_pixel/8);

	mr.mr_base = (phys_bytes)(info->PhysBasePtr);
	mr.mr_limit = mr.mr_base + vram_size;

	if( OK != (erro = sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mr)))
		panic("video_gr: sys_privctl (ADD_MEM) failed: %d\n", erro);

	/* Map memory */

	video_mem = vm_map_phys(SELF, (void *)mr.mr_base, vram_size);

	if(video_mem == MAP_FAILED)
		panic("video_gr couldn't map video memory");

	r.u.w.ax = SET_MODE; // VBE call, function 02 -- set VBE mode
	r.u.w.bx = BIT(LINEAR_MODEL_BIT)|mode; // set bit 14: linear framebuffer
	r.u.b.intno = BIOS_SERVICE;
	if( sys_int86(&r) != OK ) {
		printf("set_vbe_mode: sys_int86() failed \n");
		return NULL;
	}
	switch(r.u.b.ah){
	case 0x01:
		printf("Function call failed \n");
		return NULL;
		break;
	case 0x02:
		printf("Function is not supported in current HW configuration \n");
		return NULL;
		break;
	case 0x03:
		printf("Function is invalid in current video mode \n");
		return NULL;
		break;
	default:
		break;
	}
	vram_phisical_address = info->PhysBasePtr;
	return video_mem;
}
Пример #15
0
int racinix_start()
{
	//vg_exit(); // Fix darker colors first time the mode is changed.
	vg_init(RACINIX_VIDEO_MODE);
	vbe_get_mode_info(RACINIX_VIDEO_MODE, &vmi);

	mouse_position = vectorCreate(vmi.XResolution / 2, vmi.YResolution / 2);

	// Initialize pointers to NULL so that in case of error the program is terminated properly.
	race = NULL;
	bitmap_background = NULL;
	bitmap_mouse_cursor = NULL;
	bitmap_red_car = NULL;
	bitmap_blue_car = NULL;
	bitmap_credits = NULL;
	bitmap_speedometer = NULL;
	font_impact = NULL;
	ad = NULL;

	bitmap_background = bitmap_load(RACINIX_FOLDER_IMAGES "background.bmp");
	if (bitmap_background == NULL)
	{
		return 1;
	}
	bitmap_mouse_cursor = bitmap_load(RACINIX_FOLDER_IMAGES "cursor.bmp");
	if (bitmap_mouse_cursor == NULL)
	{
		return 1;
	}
	bitmap_red_car = bitmap_load(RACINIX_FOLDER_IMAGES "red_car.bmp");
	if (bitmap_red_car == NULL)
	{
		return 1;
	}
	bitmap_blue_car = bitmap_load(RACINIX_FOLDER_IMAGES "blue_car.bmp");
	if (bitmap_blue_car == NULL)
	{
		return 1;
	}
	bitmap_credits = bitmap_load(RACINIX_FOLDER_IMAGES "credits.bmp");
	if (bitmap_credits == NULL)
	{
		return 1;
	}
	bitmap_speedometer = bitmap_load(RACINIX_FOLDER_IMAGES "speedometer.bmp");
	if (bitmap_speedometer == NULL)
	{
		return 1;
	}
	font_impact = font_load(RACINIX_FOLDER_FONTS "impact");
	if (font_impact == NULL)
	{
		return 1;
	}

	if ((ad = ad_create(RACINIX_FILE_ADS, 120, font_impact, RACINIX_COLOR_ORANGE)) == NULL)
	{
		return 1;
	}

	vehicle_keys[0].accelerate = KEY_W;
	vehicle_keys[0].brake = KEY_S;
	vehicle_keys[0].turn_left = KEY_A;
	vehicle_keys[0].turn_right = KEY_D;

	vehicle_keys[1].accelerate = KEY_ARR_UP;
	vehicle_keys[1].brake = KEY_ARR_DOWN;
	vehicle_keys[1].turn_left = KEY_ARR_LEFT;
	vehicle_keys[1].turn_right = KEY_ARR_RIGHT;

	vehicle_colors[0] = VIDEO_GR_RED;
	vehicle_colors[1] = VIDEO_GR_BLUE;

	vehicle_bitmaps[0] = bitmap_red_car;
	vehicle_bitmaps[1] = bitmap_blue_car;
	if (racinix_dispatcher())
	{
		return 1;
	}
	return 0;
}