Project

General

Profile

Statistics
| Revision:

root / lab5 / graphics.c @ 96

History | View | Annotate | Download (1.85 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 96 up20180655
    mmr.mr_limit = 0xFFFFF;
18 95 up20180655
19 96 up20180655
    struct reg86 reg_86;
20 95 up20180655
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 96 up20180655
        memset(&reg_86, 0, sizeof(reg_86)); // reset struct
48
49
        reg_86.intno = VC_BIOS_SERV;
50
        reg_86.ah = VBE_CALL;
51
        reg_86.al = SET_VBE_MD;
52
        reg_86.bx = mode | LINEAR_FRAME_BUFFER_MD;
53
54
        // BIOS CALL
55
56
        if (sys_int86(&reg_86)) {
57
            printf("%s: sys_int86 failed\n", __func__);
58
            return BIOS_CALL_ERROR;
59
        }
60
61
        memset(&vbe_mem_info, 0, sizeof(vbe_mode_info_t)); // clear mem_info to initialize it
62
63 95 up20180655
//    lm_free(&mem_map);
64
    return SUCCESS;
65
}