Page 1 of 1
mouse implementation
Posted: Sat Jan 03, 2004 4:22 pm
by finda
I want to implement mouse functions now, I can not find a good tutorial about how can I implement mouse driver. All I found is technical documentation of mouse but no idea how can I catch mouse movements. ıll be glad if someone helps...
Re:mouse implementation
Posted: Sun Jan 04, 2004 12:20 pm
by finda
No answer?
Re:mouse implementation
Posted: Sun Jan 04, 2004 2:53 pm
by gaf
Hello finda
Here's a quite complete site about the ps/2 mouse & keyboard
http://govschl.ndsu.nodak.edu/~achapwes ... index.html
And there are also some documents at bonafide
http://osdev.neopages.net/docs.php?cat=8&sort=1
regards,
gaf
Re:mouse implementation
Posted: Mon Jan 05, 2004 1:57 am
by Pype.Clicker
finda wrote:
No answer?
you may also wish to check the .:QuickLinkz:. thread ... the collected knowledge about PS2 and serial mice may be found there ...
Re:mouse implementation
Posted: Mon Jan 05, 2004 3:47 am
by finda
But as I said before most links and tuts in quicklinks part is technical reference, no information about how can I identify mouse, how can I init it..etc...
Re:mouse implementation
Posted: Mon Jan 05, 2004 3:49 am
by finda
When I make a search in forum, some people mentioning that they are going to write a mouse tutorial, is there a completed one from them?
Re:mouse implementation
Posted: Mon Jan 05, 2004 5:08 am
by Tim
If you haven't found one, there isn't one. You will find that tutorials only cover about 1% of OS development. 10% is covered by technical specifications. You can work out 50% on your own. The rest is either impossible or subject to research.
If you think there should be a tutorial on a topic, the best thing to do is learn it from whatever material you can find, then write the tutorial yourself.
Re:mouse implementation
Posted: Mon Jan 05, 2004 7:45 am
by mystran
Tim Robinson wrote:
The rest is either impossible or subject to research.
There are no impossible things, just subjects to research, which might at somepoint include hardware research though... ;D
Re:mouse implementation
Posted: Mon Jan 05, 2004 7:58 am
by Tim
If by "hardware research" you mean "paying ATI or nVidia for their chipset specs", then, yes, it's not impossible. Just very unlikely.
Re:mouse implementation
Posted: Mon Jan 05, 2004 8:43 am
by Pype.Clicker
one approach that often pays is to use the technical specs. to enlight your reading of a working driver (mobius, linux ...)
Re:mouse implementation
Posted: Mon Jan 05, 2004 10:58 am
by Slasher
Well here is some code to start the PS2 mouse
Code: Select all
_mouse_int:
push eax
push edi
push ecx
push ebx
movzx ebx,byte [_mouse_in]
lea edi,[_mouse_data]
in al,0x60
mov [edi+ebx],byte al
inc ebx
cmp ebx,0x03
jb .mouse_out_pre
mov ch,byte [edi] ;multi infor byte
mov [_mouse_button],byte ch ;store mouse button info
test ch,0x40 ;check for X overflow
jz .no_x_overflow
mov [_mouse_dx],byte 0xff ;maximum x value
jmp .check_y_overflow
.mouse_out_pre:
jmp .mouse_out
.no_x_overflow:
mov cl,byte [edi+0x01] ;get change in x byte
mov [_mouse_dx],byte cl
.check_y_overflow:
test ch,0x80 ;check for Y overflow
jz .no_y_overflow
mov [_mouse_dy],byte 0xff ;sign bit set so 255 is maximum
jmp .check_x_sign
.no_y_overflow:
mov cl,byte [edi+0x02] ;get change in y byte
mov [_mouse_dy],byte cl
.check_x_sign:
test ch,0x10
jz .positive_x
movsx eax,byte [_mouse_dx]
jmp .check_y_sign
.positive_x:
movzx eax,byte [_mouse_dx]
.check_y_sign:
test ch,0x20
jz .positive_y
movsx ecx,byte [_mouse_dy]
jmp .going_out
.positive_y:
movzx ecx,byte [_mouse_dy]
.going_out:
mov ebx,0
add [_mouse_x],word ax
neg cx
add [_mouse_y],word cx
push dword [_mouse_semaphore]
call _wake
pop eax
.mouse_out:
mov [_mouse_in],byte bl
mov al,0x20
out 0xa0,al
out 0x20,al
pop ebx
pop ecx
pop edi
pop eax
iret
jmp $
there are no comments but the code is straight forward and follows the specs for the PS2 mouse. This is the mouse interrupt routine to be installed on IRQ 12 (slave pic)
Code: Select all
void initialize_mouse()
{
unsigned char data;
while(test_keyboard_data())
inportb(0x60);
wait_keyboard();
outportb(0x64,0xa8); /*tell controller to enable AUX interface*/
wait_keyboard();
outportb(0x64,0xd4); /*tell controller to send next command to Aux device*/
wait_keyboard();
outportb(0x60,0xea); /*tell device to enable itself*/
wait_keyboard_data();
if(test_keyboard_data())
printf("KEYBOARD ACK 3 [%02x]\n",inportb(0x60));
outportb(0x64,0x20); /*read command byte*/
wait_keyboard_data();
data=inportb(0x60);
printf("Data: [%02x]",data);
data=data|0x43;
printf(" Data: [%02x]",data);
outportb(0x64,0x60); /*write command byte*/
wait_keyboard();
outportb(0x60,data);
wait_keyboard();
k_memset(mouse_data,0,sizeof(mouse_data));
outportb(0x64,0xd4); /*tell controller to send next command to Aux device*/
wait_keyboard();
outportb(0x60,0xf4); /*reset mode*/
wait_keyboard_data();
if(test_keyboard_data())
printf("KEYBOARD ACK 4 [%02x]\n",inportb(0x60));
inportb(0x60);
while(test_keyboard_data())
inportb(0x60);
kenable_level(12);
return;
}
this is the code to initiallise the PS2 mouse.
Can't explain it now (going out) but will answer any questions later.
Re:mouse implementation
Posted: Mon Jan 05, 2004 2:23 pm
by mystran
Tim Robinson wrote:
If by "hardware research" you mean "paying ATI or nVidia for their chipset specs", then, yes, it's not impossible. Just very unlikely.
Actually my point was something like: you could do all the research starting from what you have up to what you need, possibly including other sciences as well (say you want to factor large 2-prime composites, which might include maths and/or quantum physics just to start with) but I agree that it's rather unlikely that any of us is intelligent, rich and lucky enough to do that all within one's lifetime...
In other words, you could call it a joke. (bad one it seems)