Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. #include "video_gr.h"
  2.  
  3. vbe_mode_info_t vmi_p;
  4. static uint16_t x_resolution, y_resolution;// resolution of x and y in pixels --> resolution of the screen
  5. static uint8_t bits_ppixel; //bits per pixel
  6. static unsigned int vram_base, vram_size;
  7. static uint8_t *video_mem;/* Process (virtual) address to which VRAM is mapped */
  8.  
  9. struct minix_mem_range mr;
  10.  
  11.  
  12. void *(vg_init)(uint16_t mode){
  13.  
  14. int r;
  15. struct reg86 r86;
  16. mmap_t mem_map;
  17. mem_map.phys = 0;
  18. mem_map.size = 1024 * 1024;
  19. lm_alloc(mem_map.size, &mem_map);
  20.  
  21. 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.
  22. printf("It was detected an error in vbe_get_mode_info!\n");
  23. return NULL;
  24. }
  25.  
  26. x_resolution = vmi_p.XResolution;
  27. y_resolution = vmi_p.YResolution;
  28. bits_ppixel = vmi_p.BitsPerPixel;
  29.  
  30. vram_base = vmi_p.PhysBasePtr;
  31. 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
  32.  
  33. mr.mr_base = (phys_bytes)vram_base;
  34. mr.mr_limit = vram_base + vram_size ;
  35.  
  36. /*Section 4.1*/
  37.  
  38. if(OK != (r= sys_privctl(SELF,SYS_PRIV_ADD_MEM,&mr))){//minix 3's kernel call
  39. /*
  40. The first argument specifies the process whose privileges will be affected, and the other two arguments depend on the privileges to change.
  41.  
  42. */
  43. panic("sys_privctl(ADD_MEM) failed: %d\n",r);
  44. }
  45. /* MAP MEMORY*/
  46. video_mem = vm_map_phys(SELF, (void *)mr.mr_base, vram_size);
  47.  
  48. if(video_mem == MAP_FAILED){
  49. panic("Couldn't map video memory");
  50. }
  51.  
  52. /* Specify the appropriate register values */
  53.  
  54. memset(&r86, 0, sizeof(r86)); /* zero the structure */
  55.  
  56. r86.intno = 0x10; /* BIOS video services */
  57. /*VBE call, function 02 -- Set VBE Mode */
  58. r86.ax = VBE_CALL;
  59. r86.bx = LINEAR_FRAME_BUFFER | mode;/* set bit 14: linear framebuffer */
  60.  
  61. /* Make the BIOS call */
  62.  
  63. if( sys_int86(&r86) != OK ) {
  64. printf("\tvg_exit(): sys_int86() failed \n");
  65. return NULL;
  66. }
  67. //check if al and ah are correct
  68. if(r86.ah != VBE_FUNCTION)
  69. return NULL;
  70. else if (r86.al != VBE_MODE)
  71. return NULL;
  72.  
  73.  
  74. return (void *)video_mem;
  75. }
  76.  
  77.  
  78. int vg_draw_hline(uint16_t x, uint16_t y, uint16_t len,uint32_t color){
  79. /*
  80. uint8_t addr;
  81. uint8_t *p_m;
  82. uint8_t bytes_ppixel = ceil((bits_ppixel+7)/8);
  83. addr = (x + x_resolution*y)*(bytes_ppixel);
  84.  
  85. p_m = addr + video_mem;//address of the VRAM location with the initial point
  86.  
  87. /*if(bytes_ppixel ==1){
  88. if()
  89. }*/
  90. uint8_t aux_color=color & 0xFF;
  91.  
  92.  
  93. for(int j=0;j<len; j++){
  94.  
  95. for(int k=0;k<bytes_ppixel;k++){
  96. *(p_m+k)=aux_color;
  97. aux_color=aux_color>>8;
  98.  
  99. }
  100. x++;
  101. }*/
  102.  
  103. return 0;
  104. }
  105.  
  106.  
  107.  
  108. int vg_draw_retangle(uint16_t x, uint16_t y,uint16_t width, uint16_t height, uint32_t color){
  109. /*int i =0;
  110. while(i!=height){
  111. if(vg_draw_hline(x,y+i,width,color)!=0){
  112. return 1;
  113. }
  114. i++;
  115. }*/
  116.  
  117. return 0;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement