Пример #1
0
int test_config(void) {
	unsigned long status;

	mouse_subscribe_int();

	while (mouse_send_command(MOUSE_STATUS) != 0) {
	};

	if (sys_inb(OUT_BUF, &status) == OK) {
		if (status & BIT(3) & BIT(0)) {
			printf("1:1 - Linear mode\n");
		} else {
			printf("2:1 - Acceleration mode\n");
		}
		if (status & BIT(5)) {
			printf("Info Report: ON\n ");
		} else {
			printf("Info Report: OFF\n ");
		}
		if (status & BIT(6)) {
			printf("remote: ON\n");
		} else {
			printf("remote: OFF\n");
		}
		sys_inb(OUT_BUF, &status);
		printf("X Delta: 0x%x\n", status);

		if (sys_inb(OUT_BUF, &status) == OK) {
			printf("Y Delta: 0x%x\n", status);
		}
	}
	mouse_unsubscribe_int();

	return 0;
}
Пример #2
0
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;
}
Пример #3
0
int test_packet(unsigned short cnt) {

	unsigned long mouse_byte;
	int ipc_status, loops = 0,contador = 0;
	message msg;
	unsigned char packets[3];
	short irq_set = BIT(mouse_subscribe_int());
	enable_packets();
	while (loops != cnt) {
		/* Get a request message. */
		if (driver_receive(ANY, &msg, &ipc_status) != 0) {
			printf("driver_receive failed with: %d");
			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) {
					mouse_byte = mouse_int_handler();
					if (contador == 0) {
						if (!first_byte(mouse_byte)) {
							contador = 0;
							continue;
						}
					}
					packets[contador] = mouse_byte;
					if (contador == 2) {
						contador = 0;
						print_packet(packets);
						loops++;
						continue;
					}
					contador++;
				}
				break;
			default:
				break; /* no other notifications expected: do nothing */
			}
		}
		else { /* received a standard message, not a notification */
			/* no standard messages expected: do nothing */
		}
	}

	return mouse_unsubscribe_int();
}
Пример #4
0
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;
}
Пример #5
0
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;
}