Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. int video_test_move(char *xpm[], unsigned short xi, unsigned short yi, unsigned short xf, unsigned short yf, short s, unsigned short f) {
  2.  
  3. //--------------------------
  4. // EXIT
  5. //-----------------------------------------------------
  6. int timer_irq=timer_subscribe_int();
  7. int kbd_irq=kbc_subscribe_int();
  8.  
  9. int ipc_status;
  10. message msg;
  11. int r;
  12. int counter = 0;
  13. unsigned long scancode;
  14. double velocity = s;
  15. //double distance = sqrt(xi*xi + yi*yi);
  16. //double time = distance/velocity;
  17. double time = 3;
  18.  
  19. if(kbd_irq>=0){
  20. kbd_irq=BIT(kbd_irq);
  21. } else {
  22. printf("Error in video_test_square::kbc_subscribe_int()\n");
  23. return 1;
  24. }
  25.  
  26.  
  27. if(timer_irq>=0){
  28. timer_irq=BIT(timer_irq);
  29. } else {
  30. printf("Error in timer_test_int::timer_subscribe_int()\n");
  31. return 1;
  32. }
  33. //-----------------------------------------------------------
  34.  
  35.  
  36. if(vg_init(0x105) == NULL){
  37. printf("Cannot initialize in graphics mode 0x105");
  38. return 1;
  39. }
  40.  
  41.  
  42. //--------------------------------------------
  43. // EXIT ON ESC
  44. //------------------------------------------------------------
  45.  
  46. while(counter < (time*60) && scancode != BREAKCODE_ESC) {
  47. /* Get a request message. */
  48. if ( (r = driver_receive(ANY, &msg, &ipc_status)) != 0 ) {
  49. printf("driver_receive failed with: %d", r);
  50. continue;
  51. }
  52. if (is_ipc_notify(ipc_status)) { /* received notification */
  53. switch (_ENDPOINT_P(msg.m_source)) {
  54. case HARDWARE: /* hardware interrupt notification */
  55.  
  56. if (msg.NOTIFY_ARG & timer_irq) { /* subscribed interrupt - timer */
  57.  
  58. counter++;
  59. if(counter%2==0){ //30 frames per second
  60. xi += velocity / 30;
  61. yi += velocity / 30;
  62. }
  63. if(xi < xf && yi < yf)
  64. vg_draw_xpm(xpm, xi, yi);
  65. }
  66.  
  67. if (msg.NOTIFY_ARG & kbd_irq) { /* subscribed interrupt - keyboard */
  68. scancode=kbc_read();
  69. }
  70.  
  71. break;
  72. default:
  73. break; /* no other notifications expected: do nothing */
  74. }
  75. } else { /* received a standard message, not a notification */
  76. /* no standard messages expected: do nothing */
  77. }
  78. }
  79.  
  80.  
  81.  
  82. vg_exit();
  83.  
  84. //Unsubscribe timer 0 interrupts
  85. if( timer_unsubscribe_int()){
  86. printf("Unsubscribe failed\n In kbd_test_timed_scan::timer_unsubscribe_int()\n");
  87. return 1;
  88. }
  89.  
  90. //Unsubscribe kbd interrupts
  91. if(kbc_unsubscribe_int()){
  92. printf("Unsubscribe failed\n In kbd_test_scan::kbc_unsubscribe_int()\n");
  93. return 1;
  94. }
  95.  
  96. return 0;
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement