Revision 127
5th function doing what it is supposed to, except there is 'one or more missing/unexpected function calls'
lab5.c | ||
---|---|---|
11 | 11 |
#include "keyboard.h" |
12 | 12 |
#include "kbc.h" |
13 | 13 |
#include "kbc_macros.h" |
14 |
#include "timer.h" |
|
14 | 15 |
|
15 | 16 |
// Any header files included below this line should have been created by you |
16 | 17 |
|
... | ... | |
345 | 346 |
} |
346 | 347 |
|
347 | 348 |
int(video_test_move)(xpm_map_t xpm, uint16_t xi, uint16_t yi, uint16_t xf, uint16_t yf, int16_t speed, uint8_t fr_rate) { |
349 |
int r; |
|
348 | 350 |
|
349 |
return 1; |
|
351 |
if (vbe_get_mode_information(INDEXED_1024_768)) { |
|
352 |
printf("%s: failed to get information for mode %x.\n", __func__, INDEXED_1024_768); |
|
353 |
if (vg_exit()) |
|
354 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
|
355 |
return 1; |
|
356 |
} |
|
357 |
|
|
358 |
map_vram(); // if function fails it aborts program |
|
359 |
|
|
360 |
if (set_graphics_mode(INDEXED_1024_768)) { |
|
361 |
printf("%s: failed to set graphic mode %x.\n", __func__, INDEXED_1024_768); |
|
362 |
if (vg_exit()) printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
|
363 |
return 1; |
|
364 |
}; |
|
365 |
|
|
366 |
sprite_t *sp = sprite_ctor(xpm); |
|
367 |
|
|
368 |
/// Timer interrupt handling |
|
369 |
const uint32_t frequency = sys_hz(); // Frequency asummed at 60Hz |
|
370 |
uint8_t timer_irq_bit = 0; |
|
371 |
int timer_id = 0; |
|
372 |
int timer_irq = BIT(timer_irq_bit); |
|
373 |
if(subscribe_timer_interrupt(timer_irq_bit, &timer_id)) return 1; |
|
374 |
|
|
375 |
no_interrupts = 0; |
|
376 |
/// Keyboard interrupt handling |
|
377 |
uint8_t kbc_irq_bit = KBC_IRQ; |
|
378 |
int kbc_id = 0; |
|
379 |
int kbc_irq = BIT(kbc_irq_bit); |
|
380 |
if (subscribe_kbc_interrupt(kbc_irq_bit, &kbc_id)) { |
|
381 |
if (vg_exit()) { |
|
382 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
|
383 |
if (free_memory()) printf("%s: lm_free failed\n", __func__); |
|
384 |
} |
|
385 |
return 1; |
|
386 |
} |
|
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); |
|
393 |
uint16_t Nt = (speed < 0 ? -speed : 1); |
|
394 |
uint32_t dt = frequency/(uint32_t)fr_rate; |
|
395 |
|
|
396 |
/// loop stuff |
|
397 |
int ipc_status; |
|
398 |
message msg; |
|
399 |
/// cycle |
|
400 |
uint16_t x = xi, y = yi; |
|
401 |
int i = Nt-1; |
|
402 |
int good = 1; |
|
403 |
while (good) { |
|
404 |
|
|
405 |
/* Get a request message. */ |
|
406 |
if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { |
|
407 |
printf("driver_receive failed with %d", r); |
|
408 |
continue; |
|
409 |
} |
|
410 |
if (is_ipc_notify(ipc_status)) { /* received notification */ |
|
411 |
switch (_ENDPOINT_P(msg.m_source)) { |
|
412 |
case HARDWARE: /* hardware interrupt notification */ |
|
413 |
if (msg.m_notify.interrupts & timer_irq) { /* subscribed interrupt */ |
|
414 |
timer_int_handler(); |
|
415 |
} |
|
416 |
if (msg.m_notify.interrupts & kbc_irq) { /* subscribed interrupt */ |
|
417 |
kbc_ih(); |
|
418 |
if (scancode[0] == ESC_BREAK_CODE) good = 0; |
|
419 |
} |
|
420 |
break; |
|
421 |
default: |
|
422 |
break; /* no other notifications expected: do nothing */ |
|
423 |
} |
|
424 |
} else { /* received standart message, not a notification */ |
|
425 |
/* no standart message expected: do nothing */ |
|
426 |
} |
|
427 |
if(good == 0) continue; |
|
428 |
if(no_interrupts == dt){ |
|
429 |
no_interrupts = 0; |
|
430 |
i = (i+1)%Nt; |
|
431 |
if(i == 0){ |
|
432 |
if(dx) x += dframe; |
|
433 |
if(dy) y += dframe; |
|
434 |
if((dx < 0 && x <= xf)|| |
|
435 |
(dx > 0 && x >= xf)){ |
|
436 |
x = xf; |
|
437 |
good = 0; |
|
438 |
} |
|
439 |
if((dy < 0 && y <= yf)|| |
|
440 |
(dy > 0 && y >= yf)){ |
|
441 |
y = yf; |
|
442 |
good = 0; |
|
443 |
} |
|
444 |
sprite_set_pos(sp,x,y); |
|
445 |
sprite_draw(sp); |
|
446 |
} |
|
447 |
} |
|
448 |
} |
|
449 |
|
|
450 |
if (unsubscribe_interrupt(&kbc_id)) { |
|
451 |
if (vg_exit()) { |
|
452 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
|
453 |
if (free_memory()) printf("%s: lm_free failed\n", __func__); |
|
454 |
} |
|
455 |
return 1; |
|
456 |
}; |
|
457 |
|
|
458 |
if (vg_exit()) { |
|
459 |
printf("%s: vg_exit failed to exit to text mode.\n", __func__); |
|
460 |
if (free_memory()) printf("%s: lm_free failed\n", __func__); |
|
461 |
return 1; |
|
462 |
} |
|
463 |
|
|
464 |
if (free_memory()) { |
|
465 |
printf("%s: lm_free failed\n", __func__); |
|
466 |
return 1; |
|
467 |
} |
|
468 |
|
|
469 |
return 0; |
|
350 | 470 |
} |
351 | 471 |
|
352 | 472 |
int(video_test_controller)() { |
Also available in: Unified diff