Project

General

Profile

Revision 137

corrected problem in 5th function

View differences:

lab5/lab5.c
385 385
        return 1;
386 386
    }
387 387
    ///
388
    uint16_t Dx = xf-xi;
389
    uint16_t Dy = yf-yi;
390
    if(xi != xf) Dy = 0;
391
    else         Dx = 0;
392
    uint16_t v = (speed <= 0 ? 1 : speed);
388
    int16_t v = (speed <= 0 ? 1 : speed);
389
    int16_t vx = 0, vy = 0;
390
    if(xi != xf) vx = v;
391
    else         vy = v;
392

  
393 393
    uint16_t Nt     = (speed <  0 ? -speed : 1);
394 394
    uint32_t ticks_per_frame = frequency/(uint32_t)fr_rate;
395 395

  
......
417 417
                        if(no_interrupts == 0){
418 418
                            i = (i+1)%Nt;
419 419
                            if(i == 0){
420
                                if(vx) draw_rectangle(min(x-v,x),y         , abs(v)         , sprite_get_h(sp), 0);
421
                                if(vy) draw_rectangle(x         ,min(y-v,y),sprite_get_w(sp), abs(v)          , 0);
420 422
                                sprite_set_pos(sp,x,y);
421 423
                                sprite_draw(sp);
422
                                if(Dx) draw_rectangle(min(x,x+v),y         , abs(v)         , sprite_get_h(sp), 0);
423
                                if(Dy) draw_rectangle(x         ,min(y,y+v),sprite_get_w(sp), abs(v)          , 0);
424
                                if(Dx) x += v;
425
                                if(Dy) y += v;
426
                                if(Dx && (x-xi)*(x-xf) >= 0){ x = xf; Dx = 0; }
427
                                if(Dy && (y-yi)*(y-yf) >= 0){ y = yf; Dy = 0; }
424
                                vx = (vx > 0 ? min(vx, xf-x) : max(vx, xf-x) );
425
                                vy = (vy > 0 ? min(vy, yf-y) : max(vy, yf-y) );
426
                                x += vx;
427
                                y += vy;
428 428
                            }
429 429
                        }
430 430
                        timer_int_handler();
......
437 437
        } else { /* received standart message, not a notification */
438 438
            /* no standart message expected: do nothing */
439 439
        }
440
        if(good == 0) continue;
441 440
    }
442 441

  
443 442
    if (unsubscribe_interrupt(&kbc_id)) {
......
448 447
        return 1;
449 448
    };
450 449

  
450
    if (unsubscribe_interrupt(&timer_id)) return 1;
451

  
451 452
    if (vg_exit()) {
452 453
        printf("%s: vg_exit failed to exit to text mode.\n", __func__);
453 454
        if (free_memory_map()) printf("%s: lm_free failed\n", __func__);
lab5/utils.c
36 36
    return (x >= 0) ? (int16_t)(x) : (int16_t)(-x);
37 37
}
38 38

  
39
uint16_t min(uint16_t a, uint16_t b){
40
    return (b < a ? b : a);
41
}
39
int16_t min(int16_t a, int16_t b){ return (b < a ? b : a); }
40
int16_t max(int16_t a, int16_t b){ return (a < b ? b : a); }
lab5/utils.h
29 29
 */
30 30
int (util_sys_inb)(int port, uint8_t *value);
31 31

  
32
uint16_t min(uint16_t a, uint16_t b);
32
int16_t min(int16_t a, int16_t b);
33
int16_t max(int16_t a, int16_t b);
33 34

  
35

  
34 36
#endif //UTILS_H_INCLUDED

Also available in: Unified diff