OSDev http://osdev.su/ |
|
использование мышки в ос http://osdev.su/viewtopic.php?f=6&t=1209 |
Страница 1 из 1 |
Автор: | Andrzp [ 01 фев 2017, 13:16 ] |
Заголовок сообщения: | использование мышки в ос |
есть рабочий код драйвера мыши который отлично работает если подключена ps/2 мышь, но не работает если подключена usb mouse (проверял на новых материнках включение в BIOS эмуляции порта 60/64 не помогло, в некоторых новых материнках вообще нет опции включения эмуляции ps/2), на вики английской вроде написано что можно отправить команды чтобы получать от usb мыши стандартное irq12 но конкретного кода нету, может кто знает как сделать чтобы работала usb мышь от стандартного irq 12. Ниже код на C: #define MOUSE_PORT 0x60 #define MOUSE_STATUS 0x64 #define MOUSE_ABIT 0x02 #define MOUSE_BBIT 0x01 #define MOUSE_F_BIT 0x20 #define MOUSE_V_BIT 0x08 int mousex=300; //начальное положение курсора int mousey=300; int lastmousex; int lastmousey; uint8_t mouse_cycle=0; int8_t mouse_byte[3]; int mouse_x; int mouse_y; inline void mouse_wait(unsigned char a_type) //unsigned char { unsigned int _time_out=100000; //unsigned int if(a_type==0) { while(_time_out--) //Data { if((inportb(0x64) & 1)==1) { return; } } return; } else { while(_time_out--) //Signal { if((inportb(0x64) & 2)==0) { return; } } return; } } inline void mouse_write(unsigned char a_write) //unsigned char { //Wait to be able to send a command mouse_wait(1); //Tell the mouse we are sending a command outportb(0x64, 0xD4); //Wait for the final part mouse_wait(1); //Finally write outportb(0x60, a_write); } unsigned char mouse_read() { //Get's response from mouse mouse_wait(0); return inportb(0x60); } void mouse_handler(struct regs *r) { uint8_t status = inportb(MOUSE_STATUS); while (status & MOUSE_BBIT) { int8_t mouse_in = inportb(MOUSE_PORT); if (status & MOUSE_F_BIT) { switch(mouse_cycle) { case 0: mouse_byte[0]=inportb(0x60); mouse_cycle++; break; case 1: mouse_byte[1]=inportb(0x60); mouse_cycle++; break; case 2: mouse_byte[2]=inportb(0x60); if (mouse_byte[0] & 0x80 || mouse_byte[0] & 0x40) { /* x/y overflow? bad packet! */ break; } mouse_x=mouse_byte[1]; mouse_y=mouse_byte[2]; if (mouse_byte[0] & 0x01) { PutLineh(); } if (mouse_byte[0] & 0x02) { } if (mouse_byte[0] & 0x04) { } mousex=mousex+mouse_x; //получаем координаты курсора mousey=mousey-mouse_y; if (mousex<0) { mousex = 0; } if (mousey<0) { mousey = 0; } if (mousex>1024) { mousex = 1024; } if (mousey>768) { mousey = 768; } if (mousex!=lastmousex || mousey!=lastmousey) //рисование курсора { asm( "movl lastmousex,%eax\n\t" "movl %eax,(xm)\n\t" "movl lastmousey,%ebx\n\t" "movl %ebx,(ym)\n\t" ); DelMouse(); //удаляем курсор, востанавливаем фон asm( "movl mousex,%eax\n\t" "movl %eax,(xm)\n\t" "movl mousey,%ebx\n\t" "movl %ebx,(ym)\n\t" ); CopyFon(); //копируем фон под курсором PutMouse(); //выводим курсор lastmousex=mousex; lastmousey=mousey; } mouse_cycle=0; break; } } status = inportb(MOUSE_STATUS); } } void mouse_install() { unsigned char _status; //unsigned char __asm__ __volatile__ ("cli"); //Enable the auxiliary mouse device mouse_wait(1); outportb(0x64, 0xA8); //Enable the interrupts mouse_wait(1); outportb(0x64, 0x20); mouse_wait(0); _status=(inportb(0x60) | 2); mouse_wait(1); outportb(0x64, 0x60); mouse_wait(1); outportb(0x60, _status); //Tell the mouse to use default settings mouse_write(0xF6); mouse_read(); //Acknowledge //Enable the mouse mouse_write(0xF4); mouse_read(); //Acknowledge __asm__ __volatile__ ("sti"); irq_install_handler(12, mouse_handler); } |
Автор: | Himik [ 01 фев 2017, 17:55 ] |
Заголовок сообщения: | Re: использование мышки в ос |
Это надо из реального режима INT 15 - SYSTEM - POINTING DEVICE BIOS INTERFACE (PS) - ENABLE/DISABLE AX = C200h BH = new state 00h disabled 01h enabled Return: CF set on error AH = status (see #00522) Note: IBM classifies this function as required (Table 00522) Values for pointing device function status: 00h successful 01h invalid function 02h invalid input 03h interface error 04h need to resend 05h no device handler installed |
Страница 1 из 1 | Часовой пояс: UTC + 3 часа |
Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ |