root / lab5 / graphics.c @ 95
History | View | Annotate | Download (1.38 KB)
1 | 95 | up20180655 | #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 = 0xFFFF;
|
||
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 | lm_init(true);
|
||
25 | // lm_alloc(sizeof(vbe_mode_info_t), &mem_map);
|
||
26 | if (vbe_get_mode_info(mode, &vbe_mem_info)) {
|
||
27 | printf("vbe_get_mode_info: Failed to get VBE Mode Info for mode %x\n", mode);
|
||
28 | return LCF_ERROR;
|
||
29 | } |
||
30 | unsigned int vram_base = vbe_mem_info.PhysBasePtr; |
||
31 | unsigned int vram_size = vbe_mem_info.XResolution * vbe_mem_info.YResolution * (vbe_mem_info.BitsPerPixel >> 3); |
||
32 | |||
33 | // Allow memory mapping
|
||
34 | mmr.mr_base = vram_base; |
||
35 | mmr.mr_limit = vram_base + vram_size; |
||
36 | |||
37 | if ((r = sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mmr)))
|
||
38 | panic("sys_privctl (ADD MEM) failed: %d\n", r);
|
||
39 | |||
40 | // Map memory
|
||
41 | |||
42 | video_mem = vm_map_phys(SELF, (void *)mmr.mr_base, vram_size);
|
||
43 | |||
44 | if (video_mem == MAP_FAILED)
|
||
45 | panic("Error: couldn't map video memory.");
|
||
46 | |||
47 | // lm_free(&mem_map);
|
||
48 | return SUCCESS;
|
||
49 | } |