Project

General

Profile

Revision 135

more organized

View differences:

lab5/lab5.c
401 401
    int i = Nt-1;
402 402
    int good = 1;
403 403
    while (good) {
404

  
405 404
        /* Get a request message. */
406 405
        if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
407 406
            printf("driver_receive failed with %d", r);
......
410 409
        if (is_ipc_notify(ipc_status)) { /* received notification */
411 410
            switch (_ENDPOINT_P(msg.m_source)) {
412 411
                case HARDWARE: /* hardware interrupt notification */
412
                    if (msg.m_notify.interrupts & kbc_irq) { /* subscribed interrupt */
413
                        kbc_ih();
414
                        if (scancode[0] == ESC_BREAK_CODE) good = 0;
415
                    }
413 416
                    if (msg.m_notify.interrupts & timer_irq) { /* subscribed interrupt */
414
                        timer_int_handler();
415 417
                        if(no_interrupts == dt){
416 418
                            no_interrupts = 0;
417 419
                            i = (i+1)%Nt;
418
                            if(i == 0 && (dx || dy)){
420
                            if(i == 0){
421
                                sprite_set_pos(sp,x,y);
422
                                sprite_draw(sp);
423
                                static int cnt = 0;
424
                                cnt++; printf("printed %d times\n", cnt);
419 425
                                if(dx) draw_rectangle(min(x,x+dframe),y              , abs(dframe)    , sprite_get_h(sp), 0);
420 426
                                if(dy) draw_rectangle(x              ,min(y,y+dframe),sprite_get_w(sp), abs(dframe)     , 0);
421 427
                                if(dx) x += dframe;
422 428
                                if(dy) y += dframe;
423
                                if(dx && (x-xi)*(x-xf) >= 0){
424
                                    x = xf;
425
                                    dx = 0;
426
                                }
427
                                if(dy && (y-yi)*(y-yf) >= 0){
428
                                    y = yf;
429
                                    dy = 0;
430
                                }
431
                                sprite_set_pos(sp,x,y);
432
                                sprite_draw(sp);
429
                                if(dx && (x-xi)*(x-xf) >= 0){ x = xf; dx = 0; }
430
                                if(dy && (y-yi)*(y-yf) >= 0){ y = yf; dy = 0; }
433 431
                            }
434 432
                        }
433
                        timer_int_handler();
435 434
                    }
436
                    if (msg.m_notify.interrupts & kbc_irq) { /* subscribed interrupt */
437
                        kbc_ih();
438
                        if (scancode[0] == ESC_BREAK_CODE) good = 0;
439
                    }
440 435
                    break;
441 436
                default:
442 437
                    break; /* no other notifications expected: do nothing */

Also available in: Unified diff