Revision 138
input checkers
lab5.c | ||
---|---|---|
53 | 53 |
|
54 | 54 |
if (set_graphics_mode(mode)) { |
55 | 55 |
printf("%s: failed to set graphic mode %x.\n", __func__, mode); |
56 |
if (vg_exit()) |
|
56 |
if (vg_exit()) {
|
|
57 | 57 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
58 |
} |
|
59 |
if (free_memory_map()) { |
|
60 |
printf("%s: lm_free failed\n", __func__); |
|
61 |
} |
|
58 | 62 |
return 1; |
59 | 63 |
}; |
60 | 64 |
|
... | ... | |
90 | 94 |
|
91 | 95 |
if (set_graphics_mode(mode)) { |
92 | 96 |
printf("%s: failed to set graphic mode %x.\n", __func__, mode); |
93 |
if (vg_exit()) printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
|
97 |
if (vg_exit()) { |
|
98 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
|
99 |
} |
|
100 |
if (free_memory_map()) { |
|
101 |
printf("%s: lm_free failed\n", __func__); |
|
102 |
} |
|
94 | 103 |
return 1; |
95 | 104 |
}; |
96 | 105 |
|
97 |
if (vg_draw_rectangle(x, y, width, height, color)) { |
|
98 |
if (vg_exit()) { |
|
99 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
|
100 |
if (free_memory_map()) printf("%s: lm_free failed\n", __func__); |
|
106 |
uint16_t w = (x + width > get_XRes()) ? (get_XRes() - x) : (width); |
|
107 |
uint16_t h = (y + height > get_YRes()) ? (get_YRes() - y) : (height); |
|
108 |
|
|
109 |
if (x < get_XRes() && y < get_YRes()) { |
|
110 |
if (vg_draw_rectangle(x, y, w, h, color)) { |
|
111 |
if (vg_exit()) { |
|
112 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
|
113 |
} |
|
114 |
if (free_memory_map()) { |
|
115 |
printf("%s: lm_free failed\n", __func__); |
|
116 |
} |
|
117 |
return 1; |
|
101 | 118 |
} |
102 |
return 1; |
|
103 | 119 |
} |
104 | 120 |
|
105 | 121 |
/// loop stuff |
... | ... | |
112 | 128 |
if (subscribe_kbc_interrupt(kbc_irq_bit, &kbc_id)) { |
113 | 129 |
if (vg_exit()) { |
114 | 130 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
115 |
if (free_memory_map()) printf("%s: lm_free failed\n", __func__); |
|
116 | 131 |
} |
132 |
if (free_memory_map()) { |
|
133 |
printf("%s: lm_free failed\n", __func__); |
|
134 |
} |
|
117 | 135 |
return 1; |
118 | 136 |
} |
119 | 137 |
/// cycle |
... | ... | |
143 | 161 |
if (unsubscribe_interrupt(&kbc_id)) { |
144 | 162 |
if (vg_exit()) { |
145 | 163 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
146 |
if (free_memory_map()) printf("%s: lm_free failed\n", __func__); |
|
147 | 164 |
} |
165 |
if (free_memory_map()) { |
|
166 |
printf("%s: lm_free failed\n", __func__); |
|
167 |
} |
|
148 | 168 |
return 1; |
149 | 169 |
}; |
150 | 170 |
|
... | ... | |
177 | 197 |
if (set_graphics_mode(mode)) { |
178 | 198 |
printf("%s: failed to set graphic mode %x.\n", __func__, mode); |
179 | 199 |
if (vg_exit()) printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
200 |
if (free_memory_map()) { |
|
201 |
printf("%s: lm_free failed\n", __func__); |
|
202 |
} |
|
180 | 203 |
return 1; |
181 | 204 |
}; |
182 | 205 |
|
... | ... | |
194 | 217 |
B = (GET_BLU(first) + (col+row)*step) % (1 << get_BlueMaskSize()); |
195 | 218 |
color = SET_COLOR(R,G,B); |
196 | 219 |
} |
197 |
if (vg_draw_rectangle(col*W,row*H,W,H,color)) { |
|
198 |
if (vg_exit()) { |
|
199 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
|
200 |
if (free_memory_map()) printf("%s: lm_free failed\n", __func__); |
|
220 |
uint16_t x = col * W; |
|
221 |
uint16_t y = row * H; |
|
222 |
uint16_t w = (x + W > get_XRes()) ? (get_XRes() - x) : (W); |
|
223 |
uint16_t h = (y + H > get_YRes()) ? (get_YRes() - y) : (H); |
|
224 |
|
|
225 |
if (x < get_XRes() && y < get_YRes()) { |
|
226 |
if (vg_draw_rectangle(x,y,w,h,color)) { |
|
227 |
if (vg_exit()) { |
|
228 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
|
229 |
} |
|
230 |
if (free_memory_map()) { |
|
231 |
printf("%s: lm_free failed\n", __func__); |
|
232 |
} |
|
233 |
return 1; |
|
201 | 234 |
} |
202 |
return 1; |
|
203 | 235 |
} |
204 | 236 |
} |
205 | 237 |
} |
... | ... | |
213 | 245 |
if (subscribe_kbc_interrupt(kbc_irq_bit, &kbc_id)) { |
214 | 246 |
if (vg_exit()) { |
215 | 247 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
216 |
if (free_memory_map()) printf("%s: lm_free failed\n", __func__); |
|
217 | 248 |
} |
249 |
if (free_memory_map()) { |
|
250 |
printf("%s: lm_free failed\n", __func__); |
|
251 |
} |
|
218 | 252 |
return 1; |
219 | 253 |
} |
220 | 254 |
/// cycle |
... | ... | |
244 | 278 |
if (unsubscribe_interrupt(&kbc_id)) { |
245 | 279 |
if (vg_exit()) { |
246 | 280 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
247 |
if (free_memory_map()) printf("%s: lm_free failed\n", __func__); |
|
248 | 281 |
} |
282 |
if (free_memory_map()) { |
|
283 |
printf("%s: lm_free failed\n", __func__); |
|
284 |
} |
|
249 | 285 |
return 1; |
250 | 286 |
}; |
251 | 287 |
|
... | ... | |
278 | 314 |
if (set_graphics_mode(INDEXED_1024_768)) { |
279 | 315 |
printf("%s: failed to set graphic mode %x.\n", __func__, INDEXED_1024_768); |
280 | 316 |
if (vg_exit()) printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
317 |
if (free_memory_map()) { |
|
318 |
printf("%s: lm_free failed\n", __func__); |
|
319 |
} |
|
281 | 320 |
return 1; |
282 | 321 |
}; |
283 | 322 |
|
... | ... | |
295 | 334 |
if (subscribe_kbc_interrupt(kbc_irq_bit, &kbc_id)) { |
296 | 335 |
if (vg_exit()) { |
297 | 336 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
298 |
if (free_memory_map()) printf("%s: lm_free failed\n", __func__); |
|
299 | 337 |
} |
338 |
if (free_memory_map()) { |
|
339 |
printf("%s: lm_free failed\n", __func__); |
|
340 |
} |
|
300 | 341 |
return 1; |
301 | 342 |
} |
302 | 343 |
/// cycle |
... | ... | |
326 | 367 |
if (unsubscribe_interrupt(&kbc_id)) { |
327 | 368 |
if (vg_exit()) { |
328 | 369 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
329 |
if (free_memory_map()) printf("%s: lm_free failed\n", __func__); |
|
330 | 370 |
} |
371 |
if (free_memory_map()) { |
|
372 |
printf("%s: lm_free failed\n", __func__); |
|
373 |
} |
|
331 | 374 |
return 1; |
332 | 375 |
}; |
333 | 376 |
|
... | ... | |
360 | 403 |
if (set_graphics_mode(INDEXED_1024_768)) { |
361 | 404 |
printf("%s: failed to set graphic mode %x.\n", __func__, INDEXED_1024_768); |
362 | 405 |
if (vg_exit()) printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
406 |
if (free_memory_map()) { |
|
407 |
printf("%s: lm_free failed\n", __func__); |
|
408 |
} |
|
363 | 409 |
return 1; |
364 | 410 |
}; |
365 | 411 |
|
... | ... | |
370 | 416 |
uint8_t timer_irq_bit = 0; |
371 | 417 |
int timer_id = 0; |
372 | 418 |
int timer_irq = BIT(timer_irq_bit); |
373 |
if(subscribe_timer_interrupt(timer_irq_bit, &timer_id)) return 1; |
|
419 |
if(subscribe_timer_interrupt(timer_irq_bit, &timer_id)) { |
|
420 |
if (vg_exit()) printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
|
421 |
if (free_memory_map()) { |
|
422 |
printf("%s: lm_free failed\n", __func__); |
|
423 |
} |
|
424 |
return 1; |
|
425 |
} |
|
374 | 426 |
|
375 | 427 |
no_interrupts = 0; |
376 | 428 |
/// Keyboard interrupt handling |
... | ... | |
380 | 432 |
if (subscribe_kbc_interrupt(kbc_irq_bit, &kbc_id)) { |
381 | 433 |
if (vg_exit()) { |
382 | 434 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
383 |
if (free_memory_map()) printf("%s: lm_free failed\n", __func__); |
|
384 | 435 |
} |
436 |
if (free_memory_map()) { |
|
437 |
printf("%s: lm_free failed\n", __func__); |
|
438 |
} |
|
385 | 439 |
return 1; |
386 | 440 |
} |
387 | 441 |
/// |
... | ... | |
442 | 496 |
if (unsubscribe_interrupt(&kbc_id)) { |
443 | 497 |
if (vg_exit()) { |
444 | 498 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
445 |
if (free_memory_map()) printf("%s: lm_free failed\n", __func__); |
|
446 | 499 |
} |
500 |
if (free_memory_map()) { |
|
501 |
printf("%s: lm_free failed\n", __func__); |
|
502 |
} |
|
447 | 503 |
return 1; |
448 | 504 |
}; |
449 | 505 |
|
450 |
if (unsubscribe_interrupt(&timer_id)) return 1; |
|
506 |
if (unsubscribe_interrupt(&timer_id)) { |
|
507 |
if (vg_exit()) { |
|
508 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
|
509 |
} |
|
510 |
if (free_memory_map()) { |
|
511 |
printf("%s: lm_free failed\n", __func__); |
|
512 |
} |
|
513 |
return 1; |
|
514 |
} |
|
451 | 515 |
|
452 | 516 |
if (vg_exit()) { |
453 | 517 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
... | ... | |
467 | 531 |
|
468 | 532 |
vg_vbe_contr_info_t cntrl_info; |
469 | 533 |
|
470 |
vbe_get_controller_information(&cntrl_info); |
|
534 |
if (vbe_get_controller_information(&cntrl_info)) { |
|
535 |
printf("%s: vbe_get_controller_information failed to get controller info.\n", __func__); |
|
536 |
return 1; |
|
537 |
} |
|
471 | 538 |
|
472 |
vg_display_vbe_contr_info(&cntrl_info); |
|
539 |
if (vg_display_vbe_contr_info(&cntrl_info)) { |
|
540 |
printf("%s: vg_display_vbe_contr_info failed to display controller info.\n", __func__); |
|
541 |
return 1; |
|
542 |
} |
|
473 | 543 |
|
474 | 544 |
return 0; |
475 | 545 |
} |
Also available in: Unified diff