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