Revision 136
more organized
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 dframe = (speed <= 0 ? 1 : speed);
|
|
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);
|
|
393 | 393 |
uint16_t Nt = (speed < 0 ? -speed : 1); |
394 |
uint32_t dt = frequency/(uint32_t)fr_rate;
|
|
394 |
uint32_t ticks_per_frame = frequency/(uint32_t)fr_rate;
|
|
395 | 395 |
|
396 | 396 |
/// loop stuff |
397 | 397 |
int ipc_status; |
398 | 398 |
message msg; |
399 | 399 |
/// cycle |
400 | 400 |
uint16_t x = xi, y = yi; |
401 |
int i = Nt-1; |
|
401 |
int i = Nt-1; //Nt-1
|
|
402 | 402 |
int good = 1; |
403 | 403 |
while (good) { |
404 | 404 |
/* Get a request message. */ |
... | ... | |
414 | 414 |
if (scancode[0] == ESC_BREAK_CODE) good = 0; |
415 | 415 |
} |
416 | 416 |
if (msg.m_notify.interrupts & timer_irq) { /* subscribed interrupt */ |
417 |
if(no_interrupts == dt){ |
|
418 |
no_interrupts = 0; |
|
417 |
if(no_interrupts == 0){ |
|
419 | 418 |
i = (i+1)%Nt; |
420 | 419 |
if(i == 0){ |
421 | 420 |
sprite_set_pos(sp,x,y); |
422 | 421 |
sprite_draw(sp); |
423 |
static int cnt = 0; |
|
424 |
cnt++; printf("printed %d times\n", cnt); |
|
425 |
if(dx) draw_rectangle(min(x,x+dframe),y , abs(dframe) , sprite_get_h(sp), 0); |
|
426 |
if(dy) draw_rectangle(x ,min(y,y+dframe),sprite_get_w(sp), abs(dframe) , 0); |
|
427 |
if(dx) x += dframe; |
|
428 |
if(dy) y += dframe; |
|
429 |
if(dx && (x-xi)*(x-xf) >= 0){ x = xf; dx = 0; } |
|
430 |
if(dy && (y-yi)*(y-yf) >= 0){ y = yf; dy = 0; } |
|
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; } |
|
431 | 428 |
} |
432 | 429 |
} |
433 | 430 |
timer_int_handler(); |
431 |
no_interrupts %= ticks_per_frame; |
|
434 | 432 |
} |
435 | 433 |
break; |
436 | 434 |
default: |
Also available in: Unified diff