Advertisement
Guest User

Lab5.c

a guest
Nov 18th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.34 KB | None | 0 0
  1. // IMPORTANT: you must include the following line in all your C files
  2. #include <lcom/lcf.h>
  3.  
  4. #include <lcom/lab5.h>
  5.  
  6. #include <stdint.h>
  7. #include <stdio.h>
  8. #include <math.h>
  9.  
  10. // Any header files included below this line should have been created by you
  11.  
  12. #include "graphics_card.h"
  13. #include "graphics_card_const.h"
  14. #include "i8042.h"
  15. #include "kbd.h"
  16.  
  17. extern uint8_t scancode, stat;
  18.  
  19. extern vbe_mode_info_t mode_info;
  20.  
  21. extern unsigned int hres, vres;
  22.  
  23. int main(int argc, char *argv[]) {
  24. // sets the language of LCF messages (can be either EN-US or PT-PT)
  25. lcf_set_language("EN-US");
  26.  
  27. // enables to log function invocations that are being "wrapped" by LCF
  28. // [comment this out if you don't want/need it]
  29. lcf_trace_calls("/home/lcom/labs/lab5/trace.txt");
  30.  
  31. // enables to save the output of printf function calls on a file
  32. // [comment this out if you don't want/need it]
  33. lcf_log_output("/home/lcom/labs/lab5/output.txt");
  34.  
  35. // handles control over to LCF
  36. // [LCF handles command line arguments and invokes the right function]
  37. if (lcf_start(argc, argv))
  38. return 1;
  39.  
  40. // LCF clean up tasks
  41. // [must be the last statement before return]
  42. lcf_cleanup();
  43.  
  44. return 0;
  45. }
  46.  
  47. int(video_test_init)(uint16_t mode, uint8_t delay) {
  48. if (set_graphics_card_mode(mode) != 0) {vg_exit(); return 1;}
  49.  
  50. sleep(delay);
  51.  
  52. if (vg_exit() != 0) {return 1;} //Voltar para o modo de texto
  53.  
  54. return 0;
  55. }
  56.  
  57. int(video_test_rectangle)(uint16_t mode, uint16_t x, uint16_t y,
  58. uint16_t width, uint16_t height, uint32_t color) {
  59.  
  60. uint8_t bit_no = 0;
  61. int ipc_status,r;
  62. message msg;
  63. uint32_t irq_set = BIT(1);
  64. uint8_t bytes[2];
  65. bool ReadSecond = false;
  66.  
  67. if (kbd_subscribe_int(&bit_no)!=0) {return 1;}
  68.  
  69. if (set_graphics_card_mode(mode) != 0) {vg_exit(); return 1;}
  70.  
  71. if (vg_draw_rectangle(x,y,width,height,color) != 0) {return 1;}
  72.  
  73. while(scancode != ESC){
  74. if ( (r = driver_receive(ANY, &msg, &ipc_status)) != 0 ) {
  75. printf("driver_receive failed with: %d", r);
  76. continue;
  77. }
  78. if (is_ipc_notify(ipc_status)) {
  79. switch (_ENDPOINT_P(msg.m_source)) {
  80. case HARDWARE:
  81. if (msg.m_notify.interrupts & irq_set) {
  82. kbc_ih();
  83. if (ReadSecond) {
  84. ReadSecond = false;
  85. bytes[1] = scancode;
  86. }
  87. else {
  88. bytes[0] = scancode;
  89. if (scancode == SIZE) {
  90. ReadSecond = true;
  91. }
  92. }
  93. }
  94. break;
  95. default:
  96. break;
  97. }
  98. }
  99. }
  100.  
  101.  
  102. if (vg_exit() != 0) {return 1;}
  103.  
  104. if (kbd_unsubscribe_int()!=0) {return 1;}
  105.  
  106. return 0;
  107. }
  108.  
  109. int(video_test_pattern)(uint16_t mode, uint8_t no_rectangles, uint32_t first, uint8_t step) {
  110.  
  111. uint16_t width, height, bot_height, right_width;
  112.  
  113. uint8_t bit_no = 0;
  114. int ipc_status,r;
  115. message msg;
  116. uint32_t irq_set = BIT(1);
  117. uint8_t bytes[2];
  118. bool ReadSecond = false;
  119.  
  120. if (set_graphics_card_mode(mode) != 0) {vg_exit(); return 1;}
  121.  
  122. width = hres / no_rectangles;
  123. height = vres / no_rectangles;
  124. bot_height = vres % no_rectangles;
  125. right_width = hres % no_rectangles;
  126.  
  127. for (unsigned int h = 0 ; h < no_rectangles ; h++) {
  128.  
  129. if (h*height >= (vres - bot_height))
  130. break;
  131.  
  132. for (unsigned int w = 0 ; w < no_rectangles; w++) {
  133.  
  134. if (w*width >= (hres - right_width))
  135. break;
  136.  
  137. if (mode == INDEXED_COLOR_MODE) {
  138. vg_draw_rectangle(w*width,h*height,width,height,indexed_color(w,h,step,first, no_rectangles));
  139. }
  140. else{
  141. //uint32_t red = R(h,step, first);
  142. //uint32_t green = G(w,first,step);
  143. //uint32_t blue = B(w,h,first,step);
  144. //vg_draw_rectangle(w*width,h*height,width,height, ) <--- acabar
  145. }
  146. }
  147. // ACABAR ELSE - RGB COLORS
  148. }
  149.  
  150.  
  151. if (kbd_subscribe_int(&bit_no)!=0) {return 1;}
  152.  
  153. while(scancode != ESC){
  154. if ( (r = driver_receive(ANY, &msg, &ipc_status)) != 0 ) {
  155. printf("driver_receive failed with: %d", r);
  156. continue;
  157. }
  158. if (is_ipc_notify(ipc_status)) {
  159. switch (_ENDPOINT_P(msg.m_source)) {
  160. case HARDWARE:
  161. if (msg.m_notify.interrupts & irq_set) {
  162. kbc_ih();
  163. if (ReadSecond) {
  164. ReadSecond = false;
  165. bytes[1] = scancode;
  166. }
  167. else {
  168. bytes[0] = scancode;
  169. if (scancode == SIZE) {
  170. ReadSecond = true;
  171. }
  172. }
  173. }
  174. break;
  175. default:
  176. break;
  177. }
  178. }
  179. }
  180.  
  181. if (kbd_unsubscribe_int()!=0) {return 1;}
  182.  
  183. if (vg_exit() != 0) {return 1;}
  184.  
  185. return 0;
  186. }
  187.  
  188. int(video_test_xpm)(xpm_map_t xpm, uint16_t x, uint16_t y) {
  189. /* To be completed */
  190. printf("%s(%8p, %u, %u): under construction\n", __func__, xpm, x, y);
  191.  
  192. return 1;
  193. }
  194.  
  195. int(video_test_move)(xpm_map_t xpm, uint16_t xi, uint16_t yi, uint16_t xf, uint16_t yf,
  196. int16_t speed, uint8_t fr_rate) {
  197. /* To be completed */
  198. printf("%s(%8p, %u, %u, %u, %u, %d, %u): under construction\n",
  199. __func__, xpm, xi, yi, xf, yf, speed, fr_rate);
  200.  
  201. return 1;
  202. }
  203.  
  204. int(video_test_controller)() {
  205. /* To be completed */
  206. printf("%s(): under construction\n", __func__);
  207.  
  208. return 1;
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement