root / lab5 / graphics.c @ 97
History | View | Annotate | Download (1.78 KB)
1 |
#include "graphics.h" |
---|---|
2 |
#include "graphics_macros.h" |
3 |
#include "errors.h" |
4 |
|
5 |
#include <lcom/lcf.h> |
6 |
|
7 |
#include <stdio.h> |
8 |
|
9 |
static void *video_mem; /** @brief Frame-buffer VM address */ |
10 |
static vbe_mode_info_t vbe_mem_info;
|
11 |
//static mmap_t mem_map;
|
12 |
|
13 |
int (set_graphics_mode)(uint16_t mode) {
|
14 |
int r;
|
15 |
struct minix_mem_range mmr;
|
16 |
mmr.mr_base = 0x0;
|
17 |
mmr.mr_limit = 0xFFFFF;
|
18 |
|
19 |
struct reg86 reg_86;
|
20 |
|
21 |
if ((r = sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mmr)))
|
22 |
panic("sys_privctl (ADD MEM) failed: %d\n", r);
|
23 |
|
24 |
if (vbe_get_mode_info(mode, &vbe_mem_info)) {
|
25 |
printf("vbe_get_mode_info: Failed to get VBE Mode Info for mode %x\n", mode);
|
26 |
return LCF_ERROR;
|
27 |
} |
28 |
unsigned int vram_base = vbe_mem_info.PhysBasePtr; |
29 |
unsigned int vram_size = vbe_mem_info.XResolution * vbe_mem_info.YResolution * (vbe_mem_info.BitsPerPixel >> 3); |
30 |
|
31 |
// Allow memory mapping
|
32 |
mmr.mr_base = vram_base; |
33 |
mmr.mr_limit = vram_base + vram_size; |
34 |
|
35 |
if ((r = sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mmr)))
|
36 |
panic("sys_privctl (ADD MEM) failed: %d\n", r);
|
37 |
|
38 |
// Map memory
|
39 |
|
40 |
video_mem = vm_map_phys(SELF, (void *)mmr.mr_base, vram_size);
|
41 |
|
42 |
if (video_mem == MAP_FAILED)
|
43 |
panic("Error: couldn't map video memory.");
|
44 |
|
45 |
memset(®_86, 0, sizeof(reg_86)); // reset struct |
46 |
|
47 |
reg_86.intno = VC_BIOS_SERV; |
48 |
reg_86.ah = VBE_CALL; |
49 |
reg_86.al = SET_VBE_MD; |
50 |
reg_86.bx = mode | LINEAR_FRAME_BUFFER_MD; |
51 |
|
52 |
// BIOS CALL
|
53 |
|
54 |
if (sys_int86(®_86)) {
|
55 |
printf("%s: sys_int86 failed\n", __func__);
|
56 |
return BIOS_CALL_ERROR;
|
57 |
} |
58 |
|
59 |
memset(&vbe_mem_info, 0, sizeof(vbe_mode_info_t)); // clear mem_info to initialize it |
60 |
|
61 |
// lm_free(&mem_map);
|
62 |
return SUCCESS;
|
63 |
} |