Revision 109
rectangle implemented
lab5.c | ||
---|---|---|
7 | 7 |
|
8 | 8 |
#include "graphics.h" |
9 | 9 |
#include "graphics_macros.h" |
10 |
#include "keyboard.h" |
|
11 |
#include "kbc.h" |
|
12 |
#include "kbc_macros.h" |
|
10 | 13 |
|
11 | 14 |
// Any header files included below this line should have been created by you |
12 | 15 |
|
... | ... | |
39 | 42 |
if ((r = get_permissions_first_mbyte())) |
40 | 43 |
panic("%s: sys_privctl (ADD MEM) failed: %d\n", __func__, r); |
41 | 44 |
|
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 | 45 |
if (vbe_get_mode_information(mode)) { |
50 | 46 |
printf("%s: failed to get information for mode %x.\n", __func__, mode); |
51 | 47 |
if (vg_exit()) |
... | ... | |
55 | 51 |
|
56 | 52 |
map_vram(); // if function fails it aborts program |
57 | 53 |
|
54 |
if (set_graphics_mode(mode)) { |
|
55 |
printf("%s: failed to set graphic mode %x.\n", __func__, mode); |
|
56 |
if (vg_exit()) |
|
57 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
|
58 |
return 1; |
|
59 |
}; |
|
60 |
|
|
58 | 61 |
tickdelay(micros_to_ticks(delay*1e6)); |
59 | 62 |
|
60 | 63 |
if (vg_exit()) { |
... | ... | |
76 | 79 |
int(video_test_rectangle)(uint16_t mode, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint32_t color) { |
77 | 80 |
int r; |
78 | 81 |
if ((r = get_permissions_first_mbyte())) |
79 |
panic("%s: sys_privctl (ADD MEM) failed: %d\n", __func__, r); |
|
82 |
panic("%s: sys_privctl (ADD MEM) failed: %d\n", __func__, r);
|
|
80 | 83 |
|
84 |
if (vbe_get_mode_information(mode)) { |
|
85 |
printf("%s: failed to get information for mode %x.\n", __func__, mode); |
|
86 |
if (vg_exit()) |
|
87 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
|
88 |
return 1; |
|
89 |
} |
|
90 |
|
|
91 |
map_vram(); // if function fails it aborts program |
|
92 |
|
|
81 | 93 |
if (set_graphics_mode(mode)) { |
82 | 94 |
printf("%s: failed to set graphic mode %x.\n", __func__, mode); |
83 | 95 |
if (vg_exit()) printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
84 | 96 |
return 1; |
85 | 97 |
}; |
86 | 98 |
|
87 |
vg_draw_hline(x, y, width, color); |
|
88 |
tickdelay(micros_to_ticks(1000000)); |
|
99 |
if (vg_draw_rectangle(x, y, width, height, color)) { |
|
100 |
if (vg_exit()) { |
|
101 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
|
102 |
if (free_memory()) printf("%s: lm_free failed\n", __func__); |
|
103 |
} |
|
104 |
return 1; |
|
105 |
} |
|
106 |
|
|
107 |
/// loop stuff |
|
108 |
int ipc_status; |
|
109 |
message msg; |
|
110 |
/// Keyboard interrupt handling |
|
111 |
uint8_t kbc_irq_bit = KBC_IRQ; |
|
112 |
int kbc_id = 0; |
|
113 |
int kbc_irq = BIT(kbc_irq_bit); |
|
114 |
if (subscribe_kbc_interrupt(kbc_irq_bit, &kbc_id)) { |
|
115 |
if (vg_exit()) { |
|
116 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
|
117 |
if (free_memory()) printf("%s: lm_free failed\n", __func__); |
|
118 |
} |
|
119 |
return 1; |
|
120 |
} |
|
121 |
/// cycle |
|
122 |
int good = 1; |
|
123 |
while (good) { |
|
124 |
/* Get a request message. */ |
|
125 |
if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { |
|
126 |
printf("driver_receive failed with %d", r); |
|
127 |
continue; |
|
128 |
} |
|
129 |
if (is_ipc_notify(ipc_status)) { /* received notification */ |
|
130 |
switch (_ENDPOINT_P(msg.m_source)) { |
|
131 |
case HARDWARE: /* hardware interrupt notification */ |
|
132 |
if (msg.m_notify.interrupts & kbc_irq) { /* subscribed interrupt */ |
|
133 |
kbc_ih(); |
|
134 |
if (scancode[0] == ESC_BREAK_CODE) good = 0; |
|
135 |
} |
|
136 |
break; |
|
137 |
default: |
|
138 |
break; /* no other notifications expected: do nothing */ |
|
139 |
} |
|
140 |
} else { /* received standart message, not a notification */ |
|
141 |
/* no standart message expected: do nothing */ |
|
142 |
} |
|
143 |
} |
|
144 |
|
|
145 |
if (unsubscribe_interrupt(&kbc_id)) { |
|
146 |
if (vg_exit()) { |
|
147 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
|
148 |
if (free_memory()) printf("%s: lm_free failed\n", __func__); |
|
149 |
} |
|
150 |
return 1; |
|
151 |
}; |
|
152 |
|
|
89 | 153 |
if (vg_exit()) { |
90 | 154 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
91 | 155 |
if (free_memory()) printf("%s: lm_free failed\n", __func__); |
92 | 156 |
return 1; |
93 | 157 |
} |
158 |
|
|
159 |
if (free_memory()) { |
|
160 |
printf("%s: lm_free failed\n", __func__); |
|
161 |
return 1; |
|
162 |
} |
|
163 |
|
|
94 | 164 |
return 0; |
95 | 165 |
} |
96 | 166 |
|
Also available in: Unified diff