int timer_test_int(unsigned long time) { if (timer_subscribe_int()) { return 1; } int r, ipc_status; message msg; time_counter = 0; while (time_counter <= time * TIMER_DEFAULT_FREQ) { /* 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 & BIT(TIMER0_HOOK_BIT)) { /////// /* subscribed interrupt */ timer_int_handler(); if(time_counter % TIMER_DEFAULT_FREQ == 0) { printf("Segundos decorridos: %d\n", time_counter / TIMER_DEFAULT_FREQ); } } break; default: break; /* no other notifications expected: do nothing */ } } else { /* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } } return timer_unsubscribe_int(); }
int start() { unsigned short character = 0x00; int ipc_status; message msg; int irq_set_kb = kb_subscribe_int(); int irq_set_timer = timer_subscribe_int(); int irq_set_mouse = mouse_subscribe_int(); int r; unsigned char packet[3]; unsigned short counter = 0; space_invaders_font = font_init("spaceinvader_font_transparent.bmp"); srand(1); options_load(); mouse_init(); init_state(); highscore_load(); vg_init(VBE_VIDEO_MODE); while (1) { //TODO change condition /* 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 & irq_set_kb) { /* keyboard interrupt */ character = kb_int_handler(); if (character != KB_2BYTE_SCODE) kb_event_handler(character); } if (msg.NOTIFY_ARG & irq_set_mouse){ /* mouse interrupt */ mouse_int_handler(counter, packet); if(packet[0] != MOUSE_ACK && (packet[0] & BIT(3))) counter++; if(counter == 3){ counter = 0; mouse_event_handler(packet); } } if (msg.NOTIFY_ARG & irq_set_timer){ /* timer interrupt */ timer_int_handler(); } break; default: break; /* no other notifications expected: do nothing */ } } else { /* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } } return 0; }
int kbd_test_timed_scan(unsigned short n) { int ipc_status; message msg; int validation = 0; int counter = 0; // usado para evitar chamar a função driver_receive várias vezes int receive; //subscribe() já verifica se não há problemas. int irq_set1 = kbd_subscribe(); int irq_set2 = timer_subscribe_int(); //Para quando a tecla ESC é libertada, ou quando passam n segundos sem input while (!validation) { /* Get a request message. */ receive = driver_receive(ANY, &msg, &ipc_status); if (receive != 0) { printf("driver_receive failed with: %d", receive); continue; } if (is_ipc_notify(ipc_status)) { /* received notification */ switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: /* hardware interrupt notification */ if (msg.NOTIFY_ARG & irq_set1) { /* subscribed interrupt */ validation = kbd_handler_c(); /* process it */ counter = 0; } if (msg.NOTIFY_ARG & irq_set2) { /* subscribed interrupt */ counter++; /* process it */ if (counter == n*60) { printf("\n\tkbd_test_scan() stopped, press ENTER to continue!\n"); validation = 1; } } break; default: break; /* no other notifications expected: do nothing */ } } else { /* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } } // unsubscribe_int() já verifica se não há problemas. kbd_unsubscribe(); timer_unsubscribe_int(); return 0; }
void *test_init(unsigned short mode, unsigned short delay) { void* video_mem = NULL; if((video_mem=vg_init(mode)) == NULL) { printf("test_init(): vg_init() failed"); return NULL; } int failure=0; int timer_irq_set=0; if((timer_irq_set = timer_subscribe_int()) < 0){//subscribe timer 0 interrupts printf("test_move(): timer_subscribe_int() failed \n"); failure = 1; } int ipc_status; message msg; int r; //unsigned long ticks=0; if(!failure){ do{ /* 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_set){ timer_int_handler(); } break; default: break; /* no other notifications expected: do nothing */ } } else {/* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } } while(get_ticks() < delay * 60); } if(timer_unsubscribe_int()){//unsubscribe interrupts printf("test_move(): timer_unsubscribe_int() failed\n"); failure = 1; } if(vg_exit()){ printf("test_init(): vg_exit() failed"); return NULL; } printf("Physical Address of VRAM: 0x%X\n", get_vram_phys_addr()); return (void*)get_video_mem(); }
int subscribe_all() { if (timer_subscribe_int() == -1) return -1; if (kbd_subscribe_int() == -1) { timer_unsubscribe_int(); return -1; } if (mouse_subscribe_int() == -1) { kbd_unsubscribe_int(); timer_unsubscribe_int(); return -1; } if (rtc_subscribe_int() == -1) { kbd_unsubscribe_int(); timer_unsubscribe_int(); mouse_unsubscribe_int(); return -1; } if (sp1_subscribe_int() == -1) { kbd_unsubscribe_int(); timer_unsubscribe_int(); mouse_unsubscribe_int(); rtc_unsubscribe_int(); return -1; } if (sp2_subscribe_int() == -1) { kbd_unsubscribe_int(); timer_unsubscribe_int(); mouse_unsubscribe_int(); rtc_unsubscribe_int(); sp1_unsubscribe_int(); return -1; } return 0; }
int timer_test_int(unsigned long time) { int irq_set = timer_subscribe_int(); //subscreve e inicia as interrupções do timer0 timer_set_square(0,60); //coloca a frequencia a 60 int ipc_status; int r; message msg; unsigned i = 0; while( i < time) { // enquando a contagem é menor que o valor passado no parametro /* 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 & irq_set) { /* subscribed interrupt */ timer_int_handler(); if (counter % 60 == 0) //a cada segundo (60 contagens a 60 de frequencia) { i++; printf("%d", i); // imprime o valor do segundo. printf("\n"); } } break; default: break; /* no other notifications expected: do nothing */ } } else { /* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } } if (timer_unsubscribe_int() != OK) //termina a subscrição, caso dê erro retorna 1 return 1; return 0; }
int kbd_test_timed_scan(unsigned short n){ int r; unsigned long data = 0, irq_set_KBD, irq_set_TIMER; int ipc_status; message msg; unsigned long limit = 60 * n; irq_set_KBD = kbd_subscribe_int(); irq_set_TIMER = timer_subscribe_int(); while (data != ESC_CODE){ if(/*get_counter() >= limit*/1){ printf("Your time ran out!!!\n\n"); break; } 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 &BIT(irq_set_KBD)) { data = kbd_read_buff(); if(BIT(7) & data) printf("Break code: 0x%2X", data); else printf("Make code: 0x%2X", data); printf("\n ----///---- \n"); //reset_counter(); } if (msg.NOTIFY_ARG &BIT(irq_set_TIMER)) { //timer_int_handler(); }break; default: break; } } } kbd_unsubscribe_int(); timer_unsubscribe_int(); return 0; }
int set_repetitive_task(unsigned long freq, void(*func)()) { if (doing_task) // Current task must be stopped first { return 1; } if (timer_subscribe_int()) { return 1; } if (timer_set_square(0, freq)) { return 1; } int r, ipc_status; message msg; time_counter = 0; doing_task = true; while (doing_task) { /* Get a request message. */ if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { continue; } if (is_ipc_notify(ipc_status)) { /* received notification */ switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: /* hardware interrupt notification */ if (msg.NOTIFY_ARG & BIT(TIMER0_HOOK_BIT)) { /* subscribed interrupt */ timer_int_handler(); func(); } break; default: break; /* no other notifications expected: do nothing */ } } else { /* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } } return 0; }
int test_async(unsigned short idle_time) { int ipc_status; message msg; int time = 0; int receive; unsigned long clean; int irq_set_mouse = mouse_subscribe(); int irq_set_timer = timer_subscribe_int(); counter = 0; interrupts = 0; while (time < idle_time * 60) { receive = driver_receive(ANY, &msg, &ipc_status); if (receive != 0) { printf("driver_receive failed with: %d", receive); continue; } if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: if (msg.NOTIFY_ARG & irq_set_mouse) { mouse_handler(); time = 0; } if (msg.NOTIFY_ARG & irq_set_timer) { time++; } break; default: break; } } else { } } mouse_unsubscribe(); timer_unsubscribe_int(); printf("\n\tpress ANY KEY to continue\n"); mouse_read(&clean); return 0; }
int kbd_test_timed_scan(unsigned short n) { int ipc_status; unsigned char result = 0; message msg; int kbd_interrupt = kbd_subscribe_int(); int timer_interrupt = timer_subscribe_int(); if (kbd_interrupt == ERROR || timer_interrupt == ERROR) { printf("kbd_test_timed_scan()::kernel call didn't return 0\n"); return 1; } while (result != KEY_ESC && timer_count < n * 60) { if (driver_receive(ANY, &msg, &ipc_status) != OK) { printf("kbd_test_timed_scan()::driver_receive failed\n"); continue; } if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: if (msg.NOTIFY_ARG & timer_interrupt) { timer_int_handler(); if (timer_count >= n * 60) { printf("kbd_test_timed_scan()::timed out\n"); } } if (msg.NOTIFY_ARG & kbd_interrupt) { result = kbd_int_handler_C(); if (result == KEY_ESC) { printf( "kbd_test_timed_scan()::esc was pressed, press any key to continue\n"); } } break; } } } timer_unsubscribe_int(); kbd_unsubscribe_int(); return 0; }
int timer_test_int(unsigned long time) { if(time == 0){ printf("Error: Time interval must be positive.\n"); return EXIT_FAILURE; } counter = 0; // initialize "counter" global variable int irq_set = timer_subscribe_int(); int interrupt = BIT(irq_set); int r; int ipc_status; message msg; while( (time * 60) >= counter ) { /* You may want to use a different condition */ /* 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 & interrupt) { timer_int_handler(); if (counter % 60 == 0) printf("1 segundo decorrido, Interrupcoes totais (60/segundo): %d \n", counter); } break; default: break; /* no other notifications expected: do nothing */ } } else { /* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } } timer_unsubscribe_int(); printf("Timer_test_int concluido.\n"); return EXIT_SUCCESS; }
int timer_test_int(unsigned long time) { int ipc_status; message msg; int r; if(timer_subscribe_int() < 0){ printf("ERROR SUBSCRIBING/ENABLING INTERRUPTS ON TIMER 0\n"); return 1; } while(timerInt.counter <= (time*60)){ r = driver_receive(ANY, &msg, &ipc_status); if( r != 0){ printf("driver_receive failed with: %d\n", r); continue; } if(is_ipc_notify(ipc_status)){ switch(_ENDPOINT_P(msg.m_source)){ case HARDWARE: if((msg.NOTIFY_ARG & TIMER_BIT_MASK) && (timerInt.counter % 60 == 0)){ // timer_int_handler(); } break; default: break; } } else { } timerInt.counter++; } if(timer_unsubscribe_int()) return 1; else return 0; }
int timer0_sleep(int n){ int r; int irq_set_timer; int ipc_status; message msg; int time = 60 * n; irq_set_timer = timer_subscribe_int(); while( /*get_counter() < time*/1 ) { r = driver_receive(ANY, &msg, &ipc_status); if ( 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 & BIT(irq_set_timer)) { /* subscribed interrupt */ //timer_int_handler(); } break; default: break; /* no other notifications expected: do nothing */ } } else { /* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } } timer_unsubscribe_int(); //reset_counter(); return 0; }
int test_move(unsigned short xi, unsigned short yi, char *xpm[], unsigned short hor, short delta, unsigned short time1) { if(xpm == NULL) return 1; char* video_mem = NULL; int failure =0; int width, height; char* pix = NULL; if((pix = (char*) read_xpm(xpm, &width, &height)) == NULL) return 1; if((video_mem=(char *)vg_init(VBE_MODE_RES_1024x768)) == NULL) { printf("test_move(): vg_init() failed"); return 1; } int kbd_irq_set = 0; int timer_irq_set=0; if((kbd_irq_set = kbd_subscribe_int(0)) < 0){//subscribe kbd interrupts printf("test_move(): kbd_subscribe_int() failed \n"); failure = 1; } if((timer_irq_set = timer_subscribe_int()) < 0){//subscribe timer 0 interrupts printf("test_move(): timer_subscribe_int() failed \n"); failure = 1; } int ipc_status; message msg; int r; double step = (double)delta/(time1*60); double xfp = xi; double yfp = yi; if(!failure){ do{ /* 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 & kbd_irq_set) /* subscribed kbd interrupt */ if(kbd_int_handler()) failure = 1; if(msg.NOTIFY_ARG & timer_irq_set){ if(get_ticks() < time1 * 60){//enquanto tempo desjado nao passou timer_int_handler(); blank_secondary_buf();//clear buffer draw_pixmap(get_secondary_buf(),(int) xfp, (int) yfp, height, width, pix); commit_to_video_mem(); if(hor) xfp += step;//se movimento horizontal incrementar x else yfp +=step;//senao incrementar y } } break; default: break; /* no other notifications expected: do nothing */ } } else {/* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } } while(get_scancode() != ESC_BREAK && !failure); } if(timer_unsubscribe_int()){//unsubscribe interrupts printf("test_move(): timer_unsubscribe_int() failed\n"); failure = 1; } if(kbd_unsubscribe_int()){//unsubscribe interrupts printf("test_move(): kbd_unsubscribe_int() failed\n"); failure = 1; } printf("Done\n"); if(vg_exit()){ printf("test_move(): vg_exit() failed"); return 1; } return failure; }
int racinix_dispatcher() { unsigned rtc_hook_id = RTC_HOOK_BIT; if (rtc_subscribe_int(&rtc_hook_id, false, true, false) < 0) { return 1; } unsigned long seed = racinix_generate_seed(); srand(seed); if (racinix_rtc_reprogram_alarm()) { return 1; } unsigned mouse_hook_id = MOUSE_HOOK_BIT; if (mouse_subscribe_int(&mouse_hook_id) == -1) { return 1; } if (mouse_set_stream_mode(MOUSE_NUM_TRIES)) { return 1; } if (mouse_enable_stream_mode(MOUSE_NUM_TRIES)) { return 1; } mouse_discard_interrupts(MOUSE_NUM_TRIES, MOUSE_HOOK_BIT); if (keyboard_subscribe_int() == -1) { return 1; } unsigned char timer_hook_bit; if ((timer_hook_bit = timer_subscribe_int()) < 0) { return 1; } unsigned serial_hook_id = SERIAL_HOOK_BIT; if (serial_subscribe_int(&serial_hook_id, RACINIX_SERIAL_PORT_NUMBER, RACINIX_SERIAL_TRIGGER_LEVEL) == -1) { return 1; } if (serial_set(RACINIX_SERIAL_PORT_NUMBER, RACINIX_SERIAL_NUM_BITS, RACINIX_SERIAL_NUM_STOP_BITS, RACINIX_SERIAL_PARITY, RACINIX_SERIAL_BAUD_RATE)) { return 1; } mouse_data_packet_t old_mouse_data_packet, new_mouse_data_packet; old_mouse_data_packet.left_button = old_mouse_data_packet.middle_button = old_mouse_data_packet.right_button = false; int r, ipc_status; unsigned fps_counter; message msg; key_t key; while(1) // Main loop { // Get a request message. if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { // Driver receive fail continue; } if (is_ipc_notify(ipc_status)) { // received notification if (_ENDPOINT_P(msg.m_source) == HARDWARE) // hardware interrupt notification { // Keyboard if (msg.NOTIFY_ARG & BIT(KEYBOARD_HOOK_BIT)) { if ((key = racinix_keyboard_int_handler()) == -1) { return 1; } if (racinix_event_handler(RACINIX_EVENT_KEYSTROKE, kbd_keys[key].makecode, kbd_keys[key].pressed) == -1) { break; } } // Timer if (msg.NOTIFY_ARG & BIT(timer_hook_bit)) { if (racinix_serial_int_handler()) // Sometimes VMWare stops sending interrupts for no reason... { return 1; } if ((fps_counter = racinix_timer_int_handler()) != -1) { if (racinix_event_handler(RACINIX_EVENT_NEW_FRAME, fps_counter) == RACINIX_STATE_END) { break; } } } // Mouse if (msg.NOTIFY_ARG & BIT(MOUSE_HOOK_BIT)) { if (racinix_mouse_int_handler(&new_mouse_data_packet) == 0) // Packet ready { if (racinix_event_handler(RACINIX_EVENT_MOUSE_MOVEMENT, &new_mouse_data_packet) == RACINIX_STATE_END) { break; } if (new_mouse_data_packet.left_button != old_mouse_data_packet.left_button) { if (racinix_event_handler(RACINIX_EVENT_MOUSE_LEFT_BTN, new_mouse_data_packet.left_button) == RACINIX_STATE_END) { break; } } if (new_mouse_data_packet.right_button != old_mouse_data_packet.right_button) { if (racinix_event_handler(RACINIX_EVENT_MOUSE_RIGHT_BTN, new_mouse_data_packet.right_button) == RACINIX_STATE_END) { break; } } old_mouse_data_packet = new_mouse_data_packet; } } // Serial port if (msg.NOTIFY_ARG & BIT(SERIAL_HOOK_BIT)) { if (racinix_serial_int_handler()) { break; } } // RTC if (msg.NOTIFY_ARG & BIT(RTC_HOOK_BIT)) { if (racinix_rtc_int_handler()) { break; } } } } } timer_unsubscribe_int(); keyboard_unsubscribe_int(); mouse_disable_stream_mode(MOUSE_NUM_TRIES); mouse_unsubscribe_int(mouse_hook_id); rtc_unsubscribe_int(rtc_hook_id); return 0; }
int kbd_test_timed_scan(unsigned short n) { int counter1=0; int i=0; int ipc_status; int r; message msg; int irq_set1; int irq_set2; if(( irq_set1 = KBD_subscribe_int())== -1) return -1; if((irq_set2 = timer_subscribe_int()) == -1) return -1; while(keyboard != ESC_KEY) { /* 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 & irq_set1) { /* subscribed interrupt */ KDB_handler_C(); i = 0; } if(msg.NOTIFY_ARG & irq_set2) { counter1++; if(counter1 % 60 == 0) { i++; //printf("%d",i); //printf("\n"); } if(i == n) { keyboard= ESC_KEY; printf("O tempo acabou!\n"); } } break; default: break; /* no other notifications expected: do nothing */ } } else { /* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } } if(KBD_unsubscribe_int()!= OK) return -1; if(timer_unsubscribe_int()!= OK) return -1; return 0; }
int test_async(unsigned short idle_time) { int counter1=0; int i=0; int irq_set1; int irq_set2; int ipc_status; int r; char packets[3]; unsigned long resp; message msg; int contador = 0; int firstCicle = 0; //fazer funcao para activar stream mode if ((irq_set1 = MOUSE_subscribe_int()) == -1) return -1; /*if (sys_outb(KBC_CMD_REG, ENABLE_MOUSE) != OK) return -1;*/ if (sys_outb(KBC_CMD_REG, KBDCOMMAND) != OK) return -1; if (sys_outb(OUT_BUF, SEND_PACKET) != OK) return -1; if (rec_cmd() != ACK) { printf("Nenhum ACK recebido"); return -1; } if((irq_set2 = timer_subscribe_int()) == -1) return -1; while(i < idle_time) { /* 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 & irq_set1) { /* subscribed interrupt */ MOUSE_int_handler(); i=0; if (((BIT(3) & mouse_char) == BIT(3)) && (contador == 0) && (firstCicle == 1)) { packets[0] = mouse_char; contador++; } else if (contador == 1) { packets[1] = mouse_char; contador++; } else if (contador == 2) { packets[2] = mouse_char; print_array(packets); contador = 0; } firstCicle = 1; } if(msg.NOTIFY_ARG & irq_set2) { counter1++; if(counter1 % 60 == 0) { i++; //printf("%d",i); //printf("\n"); } } break; default: break; /* no other notifications expected: do nothing */ } } else { /* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } } if (MOUSE_unsubscribe_int() != OK) return -1; if(timer_unsubscribe_int()!= OK) return -1; return 0; }
///susbscribes the devices used in game void subscribe_interrupts() { keyboard_subscribe_int(); timer_subscribe_int(); RTC_subscribe(); }
int test_move(unsigned short xi, unsigned short yi, char *xpm[], unsigned short hor, short delta, unsigned short time) { int width, height; char* pixmap; int ipc_status; message msg; int irq_set_timer = timer_subscribe_int(); int irq_set_keyboard = kb_subscribe_int(); int r; unsigned short counter = 0; long character; float pixmap_speed, next_position; if (vg_init(VBE_VIDEO_MODE) == NULL) return 1; if ((pixmap = (char*) read_xpm(xpm, &width, &height)) == NULL) return 1; pixmap_speed = (float) (delta) / (time * 60); //TODO encontrar TICKS_PER_SEC; nao existe if (irq_set_timer >= 0) irq_set_timer = BIT(irq_set_timer); else irq_set_timer = 0; if (irq_set_keyboard >= 0) irq_set_keyboard = BIT(irq_set_keyboard); else irq_set_keyboard = 0; next_position = 0; while (counter < time && character != ESC_BREAKCODE) { /* You may want to use a different condition */ /* 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 & irq_set_timer) { /* subscribed interrupt */ timed_scan_int_handler(&counter); vg_move_pixmap(xi, yi, width, height, pixmap, hor, next_position); vg_update_screen(); next_position += pixmap_speed; } if (msg.NOTIFY_ARG & irq_set_keyboard) { /* subscribed interrupt */ character = kb_int_handler(); } break; default: break; /* no other notifications expected: do nothing */ } } else { /* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } } free(pixmap); return vg_exit(); }
int test_async(unsigned short idle_time) { int conta = 0, ind = 0, r, ipc_status, conta_timer = 0, fim = 0; unsigned long irq_set_mouse, irq_set_timer; char cmd, packet[3]; int tmp = 60 * idle_time; message msg; if ((irq_set_timer = timer_subscribe_int()) == -1) { printf("Unable to subscribe timer!\n"); return 1; } if ((irq_set_mouse = mouse_subscribe()) == -1) { printf("Unable to subscribe mouse!\n"); return 1; } if (sys_outb(STAT_REG, 0xA8) != OK) //rato enable printf("Error\n"); if (sys_outb(STAT_REG, W_TO_MOUSE) != OK) printf("Error-MC\n"); if (sys_outb(OUT_BUF, ENABLE_SEND) != OK) printf("Error-SEND\n"); // Enable Sending Data Packets while (fim == 0) { if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { printf("driver_receive failed with: %d", r); continue; } if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: if (msg.NOTIFY_ARG & irq_set_mouse) { conta_timer = 0; cmd = mouse_read(); switch (ind) { case 0: if (cmd & BIT(3)) packet[0] = cmd; ind++; break; case 1: packet[1] = cmd; ind++; break; case 2: packet[2] = cmd; conta++; ind = 0; mouse_print(packet); break; } } if (msg.NOTIFY_ARG & irq_set_timer) { conta_timer++; if (conta_timer >= tmp) { fim = 1; } } break; default: break; } } else { } } printf("Acabou o tempo de espera!\n"); if (sys_outb(STAT_REG, W_TO_MOUSE) != OK) printf("ERROR-MC"); if (sys_outb(OUT_BUF, DISABLE_STREAM) != OK) printf("ERROR-DISABLE_STREAM"); if (mouse_unsubscribe() == -1) printf("falhou unsubscribe mouse!\n"); if (timer_unsubscribe_int() == -1) printf("Falhou unsubscribe timer!\n"); return 0; }