root / lab5 / lab5.c @ 102
History | View | Annotate | Download (3.77 KB)
1 | 93 | up20180655 | #include <lcom/lcf.h> |
---|---|---|---|
2 | |||
3 | #include <lcom/lab5.h> |
||
4 | |||
5 | #include <stdint.h> |
||
6 | #include <stdio.h> |
||
7 | |||
8 | 94 | up20180655 | #include "graphics.h" |
9 | #include "graphics_macros.h" |
||
10 | |||
11 | 93 | up20180655 | // Any header files included below this line should have been created by you
|
12 | |||
13 | int main(int argc, char *argv[]) { |
||
14 | 102 | up20180642 | // sets the language of LCF messages (can be either EN-US or PT-PT)
|
15 | lcf_set_language("EN-US");
|
||
16 | 93 | up20180655 | |
17 | 102 | up20180642 | // enables to log function invocations that are being "wrapped" by LCF
|
18 | // [comment this out if you don't want/need it]
|
||
19 | lcf_trace_calls("/home/lcom/labs/lab5/trace.txt");
|
||
20 | 93 | up20180655 | |
21 | 102 | up20180642 | // enables to save the output of printf function calls on a file
|
22 | // [comment this out if you don't want/need it]
|
||
23 | lcf_log_output("/home/lcom/labs/lab5/output.txt");
|
||
24 | 93 | up20180655 | |
25 | 102 | up20180642 | // handles control over to LCF
|
26 | // [LCF handles command line arguments and invokes the right function]
|
||
27 | if (lcf_start(argc, argv))
|
||
28 | 93 | up20180655 | return 1; |
29 | |||
30 | 102 | up20180642 | // LCF clean up tasks
|
31 | // [must be the last statement before return]
|
||
32 | lcf_cleanup(); |
||
33 | 93 | up20180655 | |
34 | 102 | up20180642 | return 0; |
35 | 93 | up20180655 | } |
36 | |||
37 | int(video_test_init)(uint16_t mode, uint8_t delay) {
|
||
38 | 99 | up20180655 | int r;
|
39 | if ((r = get_permissions_first_mbyte()))
|
||
40 | 102 | up20180642 | panic("%s: sys_privctl (ADD MEM) failed: %d\n", __func__, r);
|
41 | 93 | up20180655 | |
42 | 99 | up20180655 | if (set_graphics_mode(mode)) {
|
43 | printf("%s: failed to set graphic mode %x.\n", __func__, mode);
|
||
44 | if (vg_exit())
|
||
45 | 102 | up20180642 | printf("%s: vg_exit failed to exit to text mode.\n", __func__);
|
46 | 99 | up20180655 | return 1; |
47 | }; |
||
48 | 102 | up20180642 | |
49 | 99 | up20180655 | vbe_mode_info_t vbe_mem_info; |
50 | |||
51 | if (vbe_get_mode_information(mode, &vbe_mem_info)) {
|
||
52 | printf("%s: failed to get information for mode %x.\n", __func__, mode);
|
||
53 | if (vg_exit())
|
||
54 | 102 | up20180642 | printf("%s: vg_exit failed to exit to text mode.\n", __func__);
|
55 | 99 | up20180655 | return 1; |
56 | } |
||
57 | |||
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); |
||
60 | |||
61 | map_vram(vram_base, vram_size); // if function fails it aborts program
|
||
62 | 102 | up20180642 | |
63 | 96 | up20180655 | tickdelay(micros_to_ticks(delay*1e6));
|
64 | 94 | up20180655 | |
65 | 99 | up20180655 | if (vg_exit()) {
|
66 | printf("%s: vg_exit failed to exit to text mode.\n", __func__);
|
||
67 | 102 | up20180642 | if (free_memory())
|
68 | printf("%s: lm_free failed\n", __func__);
|
||
69 | 99 | up20180655 | return 1; |
70 | } |
||
71 | 102 | up20180642 | |
72 | 99 | up20180655 | if (free_memory()) {
|
73 | printf("%s: lm_free failed\n", __func__);
|
||
74 | return 1; |
||
75 | 102 | up20180642 | } |
76 | 94 | up20180655 | return 0; |
77 | 93 | up20180655 | } |
78 | |||
79 | 102 | up20180642 | int(video_test_rectangle)(uint16_t mode, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint32_t color) {
|
80 | int r;
|
||
81 | if ((r = get_permissions_first_mbyte()))
|
||
82 | panic("%s: sys_privctl (ADD MEM) failed: %d\n", __func__, r);
|
||
83 | 93 | up20180655 | |
84 | 102 | up20180642 | if (set_graphics_mode(mode)) {
|
85 | printf("%s: failed to set graphic mode %x.\n", __func__, mode);
|
||
86 | if (vg_exit()) printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
||
87 | return 1; |
||
88 | }; |
||
89 | |||
90 | vg_draw_hline(x, y, width, color); |
||
91 | tickdelay(micros_to_ticks(1000000));
|
||
92 | if (vg_exit()) {
|
||
93 | printf("%s: vg_exit failed to exit to text mode.\n", __func__);
|
||
94 | if (free_memory()) printf("%s: lm_free failed\n", __func__); |
||
95 | return 1; |
||
96 | } |
||
97 | return 0; |
||
98 | 93 | up20180655 | } |
99 | |||
100 | int(video_test_pattern)(uint16_t mode, uint8_t no_rectangles, uint32_t first, uint8_t step) {
|
||
101 | 100 | up20180655 | return 0; |
102 | 93 | up20180655 | } |
103 | |||
104 | int(video_test_xpm)(xpm_map_t xpm, uint16_t x, uint16_t y) {
|
||
105 | 102 | up20180642 | /* To be completed */
|
106 | printf("%s(%8p, %u, %u): under construction\n", __func__, xpm, x, y);
|
||
107 | 93 | up20180655 | |
108 | 102 | up20180642 | return 1; |
109 | 93 | up20180655 | } |
110 | |||
111 | 102 | up20180642 | int(video_test_move)(xpm_map_t xpm, uint16_t xi, uint16_t yi, uint16_t xf, uint16_t yf, int16_t speed, uint8_t fr_rate) {
|
112 | /* To be completed */
|
||
113 | printf("%s(%8p, %u, %u, %u, %u, %d, %u): under construction\n",
|
||
114 | __func__, xpm, xi, yi, xf, yf, speed, fr_rate); |
||
115 | 93 | up20180655 | |
116 | 102 | up20180642 | return 1; |
117 | 93 | up20180655 | } |
118 | |||
119 | int(video_test_controller)() {
|
||
120 | 102 | up20180642 | /* To be completed */
|
121 | printf("%s(): under construction\n", __func__);
|
||
122 | 93 | up20180655 | |
123 | 102 | up20180642 | return 1; |
124 | 93 | up20180655 | } |