root / lab5 / graphics.c @ 100
History | View | Annotate | Download (2.3 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 | 99 | up20180655 | //static vbe_mode_info_t vbe_mem_info;
|
11 | static mmap_t mem_map;
|
||
12 | 95 | up20180655 | |
13 | 99 | up20180655 | int (get_permission)(unsigned int base_addr, unsigned int size) { |
14 | 95 | up20180655 | struct minix_mem_range mmr;
|
15 | 99 | up20180655 | mmr.mr_base = base_addr; |
16 | mmr.mr_limit = base_addr + size; |
||
17 | return sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mmr);
|
||
18 | } |
||
19 | 95 | up20180655 | |
20 | 99 | up20180655 | int (get_permissions_first_mbyte)(void) { |
21 | return get_permission(MBYTE_BASE, MBYTE_SIZE);
|
||
22 | } |
||
23 | 95 | up20180655 | |
24 | 99 | up20180655 | int (vbe_get_mode_information)(uint16_t mode, vbe_mode_info_t *vmi_p) {
|
25 | memset(vmi_p, 0, sizeof(vbe_mode_info_t)); // reset values |
||
26 | 95 | up20180655 | |
27 | 99 | up20180655 | struct reg86 reg_86;
|
28 | memset(®_86, 0, sizeof(reg_86)); // reset struct |
||
29 | 98 | up20180655 | |
30 | 99 | up20180655 | vbe_mode_info_t *virtual_addr = lm_alloc(sizeof(vbe_mode_info_t), &mem_map);
|
31 | 98 | up20180655 | |
32 | 99 | up20180655 | reg_86.intno = VC_BIOS_SERV; |
33 | reg_86.ah = VBE_CALL; |
||
34 | reg_86.al = VBE_MD_INFO; |
||
35 | reg_86.cx = mode; |
||
36 | reg_86.es = PB2BASE(mem_map.phys); |
||
37 | reg_86.di = PB2OFF(mem_map.phys); |
||
38 | // BIOS CALL
|
||
39 | if (sys_int86(®_86)) {
|
||
40 | printf("%s: sys_int86 failed\n", __func__);
|
||
41 | if (free_memory()) {
|
||
42 | printf("%s: lm_free failed\n", __func__);
|
||
43 | return LCF_ERROR;
|
||
44 | } |
||
45 | return BIOS_CALL_ERROR;
|
||
46 | 95 | up20180655 | } |
47 | |||
48 | 99 | up20180655 | vmi_p = memcpy((void*)vmi_p, (void*)virtual_addr, mem_map.size); |
49 | return SUCCESS;
|
||
50 | } |
||
51 | 95 | up20180655 | |
52 | 99 | up20180655 | int (map_vram)(unsigned int vram_base, unsigned int vram_size) { |
53 | int r;
|
||
54 | if ((r = get_permission(vram_base, vram_size)))
|
||
55 | panic("%s: sys_privctl (ADD MEM) failed: %d\n", __func__, r);
|
||
56 | 95 | up20180655 | |
57 | 99 | up20180655 | video_mem = vm_map_phys(SELF, (void *)vram_base, vram_size);
|
58 | 95 | up20180655 | |
59 | if (video_mem == MAP_FAILED)
|
||
60 | 99 | up20180655 | panic("%s: couldn't map video memory.", __func__);
|
61 | 95 | up20180655 | |
62 | 99 | up20180655 | return SUCCESS;
|
63 | } |
||
64 | |||
65 | int (free_memory)(void) { |
||
66 | return lm_free(&mem_map);
|
||
67 | } |
||
68 | |||
69 | int (set_graphics_mode)(uint16_t mode) {
|
||
70 | struct reg86 reg_86;
|
||
71 | |||
72 | 98 | up20180655 | memset(®_86, 0, sizeof(reg_86)); // reset struct |
73 | 96 | up20180655 | |
74 | 99 | up20180655 | // Set Reg86
|
75 | 98 | up20180655 | reg_86.intno = VC_BIOS_SERV; |
76 | reg_86.ah = VBE_CALL; |
||
77 | reg_86.al = SET_VBE_MD; |
||
78 | reg_86.bx = mode | LINEAR_FRAME_BUFFER_MD; |
||
79 | 96 | up20180655 | |
80 | 98 | up20180655 | // BIOS CALL
|
81 | if (sys_int86(®_86)) {
|
||
82 | printf("%s: sys_int86 failed\n", __func__);
|
||
83 | return BIOS_CALL_ERROR;
|
||
84 | } |
||
85 | 99 | up20180655 | |
86 | 95 | up20180655 | return SUCCESS;
|
87 | } |