Revision 103
changed vbe_mode_info to static
lab5/graphics.c | ||
---|---|---|
7 | 7 |
#include <stdio.h> |
8 | 8 |
|
9 | 9 |
static void *video_mem; /** @brief Frame-buffer VM address */ |
10 |
//static vbe_mode_info_t vbe_mem_info;
|
|
10 |
static vbe_mode_info_t vbe_mem_info; |
|
11 | 11 |
static mmap_t mem_map; |
12 | 12 |
|
13 | 13 |
int (get_permission)(unsigned int base_addr, unsigned int size) { |
... | ... | |
21 | 21 |
return get_permission(MBYTE_BASE, MBYTE_SIZE); |
22 | 22 |
} |
23 | 23 |
|
24 |
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
|
|
24 |
int (vbe_get_mode_information)(uint16_t mode) { |
|
25 |
memset(&vbe_mem_info, 0, sizeof(vbe_mode_info_t)); // reset values
|
|
26 | 26 |
|
27 | 27 |
struct reg86 reg_86; |
28 |
memset(®_86, 0, sizeof(reg_86)); // reset struct
|
|
28 |
memset(®_86, 0, sizeof(struct reg86)); // reset struct
|
|
29 | 29 |
|
30 | 30 |
vbe_mode_info_t *virtual_addr = lm_alloc(sizeof(vbe_mode_info_t), &mem_map); |
31 | 31 |
|
... | ... | |
45 | 45 |
return BIOS_CALL_ERROR; |
46 | 46 |
} |
47 | 47 |
|
48 |
vmi_p = memcpy((void*)vmi_p, (void*)virtual_addr, mem_map.size);
|
|
48 |
memcpy((void*)&vbe_mem_info, (void*)virtual_addr, mem_map.size);
|
|
49 | 49 |
return SUCCESS; |
50 | 50 |
} |
51 | 51 |
|
52 |
int (map_vram)(unsigned int vram_base, unsigned int vram_size) { |
|
52 |
phys_bytes get_phys_addr(void) { |
|
53 |
return vbe_mem_info.PhysBasePtr; |
|
54 |
} |
|
55 |
|
|
56 |
unsigned int get_vram_size(void) { |
|
57 |
return vbe_mem_info.XResolution * vbe_mem_info.YResolution * ((vbe_mem_info.BitsPerPixel + 7) >> 3); |
|
58 |
} |
|
59 |
|
|
60 |
uint16_t get_XRes(void) { |
|
61 |
return vbe_mem_info.XResolution; |
|
62 |
} |
|
63 |
|
|
64 |
uint16_t get_YRes(void) { |
|
65 |
return vbe_mem_info.YResolution; |
|
66 |
} |
|
67 |
|
|
68 |
uint16_t get_bits_pixel(void) { |
|
69 |
return vbe_mem_info.BitsPerPixel; |
|
70 |
} |
|
71 |
|
|
72 |
int (map_vram)(void) { |
|
53 | 73 |
int r; |
74 |
unsigned int vram_base = get_phys_addr(); |
|
75 |
unsigned int vram_size = get_vram_size(); |
|
54 | 76 |
if ((r = get_permission(vram_base, vram_size))) |
55 | 77 |
panic("%s: sys_privctl (ADD MEM) failed: %d\n", __func__, r); |
56 | 78 |
|
... | ... | |
63 | 85 |
} |
64 | 86 |
|
65 | 87 |
int (free_memory)(void) { |
66 |
return lm_free(&mem_map); |
|
88 |
return !lm_free(&mem_map);
|
|
67 | 89 |
} |
68 | 90 |
|
69 | 91 |
int (set_graphics_mode)(uint16_t mode) { |
70 | 92 |
struct reg86 reg_86; |
71 | 93 |
|
72 |
memset(®_86, 0, sizeof(reg_86)); // reset struct
|
|
94 |
memset(®_86, 0, sizeof(struct reg86)); // reset struct
|
|
73 | 95 |
|
74 | 96 |
// Set Reg86 |
75 | 97 |
reg_86.intno = VC_BIOS_SERV; |
lab5/graphics.h | ||
---|---|---|
8 | 8 |
|
9 | 9 |
int (get_permissions_first_mbyte)(void); |
10 | 10 |
|
11 |
int (vbe_get_mode_information)(uint16_t mode, vbe_mode_info_t *vmi_p);
|
|
11 |
int (vbe_get_mode_information)(uint16_t mode); |
|
12 | 12 |
|
13 |
int (map_vram)(unsigned int vram_base, unsigned int vram_size);
|
|
13 |
phys_bytes get_phys_addr(void);
|
|
14 | 14 |
|
15 |
unsigned int get_vram_size(void); |
|
16 |
|
|
17 |
uint16_t get_XRes(void); |
|
18 |
|
|
19 |
uint16_t get_YRes(void); |
|
20 |
|
|
21 |
uint16_t get_bits_pixel(void); |
|
22 |
|
|
23 |
int (map_vram)(void); |
|
24 |
|
|
15 | 25 |
int (free_memory)(void); |
16 | 26 |
|
17 | 27 |
/** |
lab5/lab5.c | ||
---|---|---|
37 | 37 |
int(video_test_init)(uint16_t mode, uint8_t delay) { |
38 | 38 |
int r; |
39 | 39 |
if ((r = get_permissions_first_mbyte())) |
40 |
panic("%s: sys_privctl (ADD MEM) failed: %d\n", __func__, r); |
|
40 |
panic("%s: sys_privctl (ADD MEM) failed: %d\n", __func__, r);
|
|
41 | 41 |
|
42 | 42 |
if (set_graphics_mode(mode)) { |
43 | 43 |
printf("%s: failed to set graphic mode %x.\n", __func__, mode); |
44 | 44 |
if (vg_exit()) |
45 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
|
45 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__);
|
|
46 | 46 |
return 1; |
47 | 47 |
}; |
48 | 48 |
|
49 |
vbe_mode_info_t vbe_mem_info; |
|
50 |
|
|
51 |
if (vbe_get_mode_information(mode, &vbe_mem_info)) { |
|
49 |
if (vbe_get_mode_information(mode)) { |
|
52 | 50 |
printf("%s: failed to get information for mode %x.\n", __func__, mode); |
53 | 51 |
if (vg_exit()) |
54 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
|
52 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__);
|
|
55 | 53 |
return 1; |
56 | 54 |
} |
57 | 55 |
|
58 |
unsigned int vram_base = vbe_mem_info.PhysBasePtr; |
|
59 |
unsigned int vram_size = vbe_mem_info.XResolution * vbe_mem_info.YResolution * ((vbe_mem_info.BitsPerPixel + 7) >> 3); |
|
56 |
map_vram(); // if function fails it aborts program |
|
60 | 57 |
|
61 |
map_vram(vram_base, vram_size); // if function fails it aborts program |
|
62 |
|
|
63 | 58 |
tickdelay(micros_to_ticks(delay*1e6)); |
64 | 59 |
|
65 | 60 |
if (vg_exit()) { |
66 | 61 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
67 | 62 |
if (free_memory()) |
68 |
printf("%s: lm_free failed\n", __func__); |
|
63 |
printf("%s: lm_free failed\n", __func__);
|
|
69 | 64 |
return 1; |
70 | 65 |
} |
71 | 66 |
|
... | ... | |
73 | 68 |
printf("%s: lm_free failed\n", __func__); |
74 | 69 |
return 1; |
75 | 70 |
} |
71 |
|
|
76 | 72 |
return 0; |
77 | 73 |
} |
78 | 74 |
|
... | ... | |
98 | 94 |
} |
99 | 95 |
|
100 | 96 |
int(video_test_pattern)(uint16_t mode, uint8_t no_rectangles, uint32_t first, uint8_t step) { |
101 |
return 0; |
|
97 |
/* To be completed */ |
|
98 |
printf("%s(0x%03x, %u, 0x%08x, %d): under construction\n", __func__, |
|
99 |
mode, no_rectangles, first, step); |
|
100 |
|
|
101 |
return 1; |
|
102 | 102 |
} |
103 | 103 |
|
104 | 104 |
int(video_test_xpm)(xpm_map_t xpm, uint16_t x, uint16_t y) { |
Also available in: Unified diff