Project

General

Profile

Statistics
| Revision:

root / lab5 / graphics.c @ 98

History | View | Annotate | Download (1.71 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

    
25
    memset(&vbe_mem_info, 0, sizeof(vbe_mode_info_t)); // clear mem_info to initialize it
26

    
27
    if (vbe_get_mode_info(mode, &vbe_mem_info)) {
28
        printf("vbe_get_mode_info: Failed to get VBE Mode Info for mode %x\n", mode);
29
        return LCF_ERROR;
30
    }
31
    unsigned int vram_base = vbe_mem_info.PhysBasePtr;
32
    unsigned int vram_size = vbe_mem_info.XResolution * vbe_mem_info.YResolution * (vbe_mem_info.BitsPerPixel >> 3);
33

    
34
    // Allow memory mapping
35
    mmr.mr_base =  vram_base;
36
    mmr.mr_limit = vram_base + vram_size;
37

    
38
    if ((r = sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mmr)))
39
        panic("sys_privctl (ADD MEM) failed: %d\n", r);
40

    
41
    // Map memory
42

    
43
    video_mem = vm_map_phys(SELF, (void *)mmr.mr_base, vram_size);
44

    
45
    if (video_mem == MAP_FAILED)
46
        panic("Error: couldn't map video memory.");
47

    
48
    memset(&reg_86, 0, sizeof(reg_86)); // reset struct
49

    
50
    reg_86.intno = VC_BIOS_SERV;
51
    reg_86.ah = VBE_CALL;
52
    reg_86.al = SET_VBE_MD;
53
    reg_86.bx = mode | LINEAR_FRAME_BUFFER_MD;
54

    
55
    // BIOS CALL
56

    
57
    if (sys_int86(&reg_86)) {
58
        printf("%s: sys_int86 failed\n", __func__);
59
        return BIOS_CALL_ERROR;
60
    }
61
    return SUCCESS;
62
}