Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "video_gr.h"
- vbe_mode_info_t vmi_p;
- static uint16_t x_resolution, y_resolution;// resolution of x and y in pixels --> resolution of the screen
- static uint8_t bits_ppixel; //bits per pixel
- static unsigned int vram_base, vram_size;
- static uint8_t *video_mem;/* Process (virtual) address to which VRAM is mapped */
- struct minix_mem_range mr;
- void *(vg_init)(uint16_t mode){
- int r;
- struct reg86 r86;
- mmap_t mem_map;
- mem_map.phys = 0;
- mem_map.size = 1024 * 1024;
- lm_alloc(mem_map.size, &mem_map);
- if(vbe_get_mode_info(mode, &vmi_p )!=0){//Returns information on the input VBE mode, including screen dimensions, color depth and VRAM physical address.
- printf("It was detected an error in vbe_get_mode_info!\n");
- return NULL;
- }
- x_resolution = vmi_p.XResolution;
- y_resolution = vmi_p.YResolution;
- bits_ppixel = vmi_p.BitsPerPixel;
- vram_base = vmi_p.PhysBasePtr;
- vram_size = (x_resolution*y_resolution)*(bits_ppixel/8);//the size of the buffer needs to be the resolution of the screen times the number of bytes per pixel
- mr.mr_base = (phys_bytes)vram_base;
- mr.mr_limit = vram_base + vram_size ;
- /*Section 4.1*/
- if(OK != (r= sys_privctl(SELF,SYS_PRIV_ADD_MEM,&mr))){//minix 3's kernel call
- /*
- The first argument specifies the process whose privileges will be affected, and the other two arguments depend on the privileges to change.
- */
- panic("sys_privctl(ADD_MEM) failed: %d\n",r);
- }
- /* MAP MEMORY*/
- video_mem = vm_map_phys(SELF, (void *)mr.mr_base, vram_size);
- if(video_mem == MAP_FAILED){
- panic("Couldn't map video memory");
- }
- /* Specify the appropriate register values */
- memset(&r86, 0, sizeof(r86)); /* zero the structure */
- r86.intno = 0x10; /* BIOS video services */
- /*VBE call, function 02 -- Set VBE Mode */
- r86.ax = VBE_CALL;
- r86.bx = LINEAR_FRAME_BUFFER | mode;/* set bit 14: linear framebuffer */
- /* Make the BIOS call */
- if( sys_int86(&r86) != OK ) {
- printf("\tvg_exit(): sys_int86() failed \n");
- return NULL;
- }
- //check if al and ah are correct
- if(r86.ah != VBE_FUNCTION)
- return NULL;
- else if (r86.al != VBE_MODE)
- return NULL;
- return (void *)video_mem;
- }
- int vg_draw_hline(uint16_t x, uint16_t y, uint16_t len,uint32_t color){
- /*
- uint8_t addr;
- uint8_t *p_m;
- uint8_t bytes_ppixel = ceil((bits_ppixel+7)/8);
- addr = (x + x_resolution*y)*(bytes_ppixel);
- p_m = addr + video_mem;//address of the VRAM location with the initial point
- /*if(bytes_ppixel ==1){
- if()
- }*/
- uint8_t aux_color=color & 0xFF;
- for(int j=0;j<len; j++){
- for(int k=0;k<bytes_ppixel;k++){
- *(p_m+k)=aux_color;
- aux_color=aux_color>>8;
- }
- x++;
- }*/
- return 0;
- }
- int vg_draw_retangle(uint16_t x, uint16_t y,uint16_t width, uint16_t height, uint32_t color){
- /*int i =0;
- while(i!=height){
- if(vg_draw_hline(x,y+i,width,color)!=0){
- return 1;
- }
- i++;
- }*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement