Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int video_test_move(char *xpm[], unsigned short xi, unsigned short yi, unsigned short xf, unsigned short yf, short s, unsigned short f) {
- //--------------------------
- // EXIT
- //-----------------------------------------------------
- int timer_irq=timer_subscribe_int();
- int kbd_irq=kbc_subscribe_int();
- int ipc_status;
- message msg;
- int r;
- int counter = 0;
- unsigned long scancode;
- double velocity = s;
- //double distance = sqrt(xi*xi + yi*yi);
- //double time = distance/velocity;
- double time = 3;
- if(kbd_irq>=0){
- kbd_irq=BIT(kbd_irq);
- } else {
- printf("Error in video_test_square::kbc_subscribe_int()\n");
- return 1;
- }
- if(timer_irq>=0){
- timer_irq=BIT(timer_irq);
- } else {
- printf("Error in timer_test_int::timer_subscribe_int()\n");
- return 1;
- }
- //-----------------------------------------------------------
- if(vg_init(0x105) == NULL){
- printf("Cannot initialize in graphics mode 0x105");
- return 1;
- }
- //--------------------------------------------
- // EXIT ON ESC
- //------------------------------------------------------------
- while(counter < (time*60) && scancode != BREAKCODE_ESC) {
- /* Get a request message. */
- if ( (r = driver_receive(ANY, &msg, &ipc_status)) != 0 ) {
- printf("driver_receive failed with: %d", r);
- continue;
- }
- if (is_ipc_notify(ipc_status)) { /* received notification */
- switch (_ENDPOINT_P(msg.m_source)) {
- case HARDWARE: /* hardware interrupt notification */
- if (msg.NOTIFY_ARG & timer_irq) { /* subscribed interrupt - timer */
- counter++;
- if(counter%2==0){ //30 frames per second
- xi += velocity / 30;
- yi += velocity / 30;
- }
- if(xi < xf && yi < yf)
- vg_draw_xpm(xpm, xi, yi);
- }
- if (msg.NOTIFY_ARG & kbd_irq) { /* subscribed interrupt - keyboard */
- scancode=kbc_read();
- }
- break;
- default:
- break; /* no other notifications expected: do nothing */
- }
- } else { /* received a standard message, not a notification */
- /* no standard messages expected: do nothing */
- }
- }
- vg_exit();
- //Unsubscribe timer 0 interrupts
- if( timer_unsubscribe_int()){
- printf("Unsubscribe failed\n In kbd_test_timed_scan::timer_unsubscribe_int()\n");
- return 1;
- }
- //Unsubscribe kbd interrupts
- if(kbc_unsubscribe_int()){
- printf("Unsubscribe failed\n In kbd_test_scan::kbc_unsubscribe_int()\n");
- return 1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement