Project

General

Profile

Revision 95

added files

View differences:

lab5/Makefile
1
# name of the program (Minix service)
2
PROG=lab5
3

  
4
# source code files to be compiled
5
SRCS = lab5.c graphics.c
6

  
7
# additional compilation flags
8
# "-Wall -Wextra -Werror -I . -std=c11 -Wno-unused-parameter" are already set
9
CFLAGS += -pedantic
10

  
11
# list of library dependencies (for Lab 2, only LCF library)
12
DPADD += ${LIBLCF}
13
LDADD += -llcf
14

  
15
# include LCOM's makefile that does all the "heavy lifting"
16
.include <minix.lcom.mk>
0 17

  
lab5/errors.h
1
#ifndef ERRORS_H_INCLUDED
2
#define ERRORS_H_INCLUDED
3

  
4
enum errors {
5
    SUCCESS = 0,        /* @brief Sucessful */
6
    NULL_PTR,           /* @brief Null Pointer Error */
7
    LCF_ERROR,          /* @brief Error originated on LCF */
8
    SBCR_ERROR,         /* @brief Error on Subscribing Interrupt */
9
    UNSBCR_ERROR,       /* @brief Error on Unsubscring Interrupt*/
10
    READ_ERROR,         /* @brief Error on Reading from Port */
11
    WRITE_ERROR,        /* @brief Error on Writing to Port */
12
    TIMEOUT_ERROR,      /* @brief Timeout error */
13
    INVALID_COMMAND,    /* @brief Invalid Command issued */
14
    INVALID_STATE,      /* @brief State machine reached an invalid state */
15
    BIOS_CALL_ERROR,    /* @brief Error upon BIOS call */
16
    OTHER_ERROR         /* @brief Unspecified error */
17
};
18

  
19
#endif //ERRORS_H_INCLUDED
0 20

  
lab5/graphics.c
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 = 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
}
0 50

  
lab5/graphics.h
1
#ifndef GRAPHICS_H_INCLUDED
2
#define GRAPHICS_H_INCLUDED
3

  
4
#include <stdint.h>
5

  
6
/**
7
 * @brief
8
 * @param mode
9
 * @return
10
 */
11
int (set_graphics_mode)(uint16_t mode);
12

  
13
#endif /* end of include guard: GRAPHICS_H_INCLUDED */
0 14

  
lab5/graphics_macros.h
1
#ifndef GRAPHICS_MACROS_H_INCLUDED
2
#define GRAPHICS_MACROS_H_INCLUDED
3

  
4
#define VC_BIOS_SERV  0x10 /** @brief TODO */
5
#define VBE_CALL      0x4F /** @brief TODO */
6

  
7
// Graphics Functions
8
#define VBE_CTRL_INFO       0x00 /** @brief Get VBE Controller Information */
9
#define VBE_MD_INFO         0x01 /** @brief Get VBE Mode Information */
10
#define SET_VBE_MD          0x02 /** @brief Set VBE Mode */
11

  
12
// Error codes (AH)
13
#define AH_SUCCESS          0x00
14
#define AH_FUNC_CALL_FAIL   0x01
15
#define AH_FUNC_NOT_SUPP    0x02
16
#define AH_FUNC_INVALID     0x03
17

  
18
// Graphics modes
19
#define INDEXED_1024_768        0x105
20
#define DIRECT_640_480          0x110
21
#define DIRECT_800_600          0x115
22
#define DIRECT_1280_1024        0x11A
23
#define DIRECT_1152_864         0x14C
24
#define LINEAR_FRAME_BUFFER_MD  BIT(14)
25

  
26
#endif /* end of include guard: GRAPHICS_MACROS_H_INCLUDED */
0 27

  

Also available in: Unified diff