Page 1 of 1

Mouse Position?

Posted: Tue Jan 30, 2007 1:19 am
by pcmattman
I've written a CLI OS. Now I want to extend it and allow users to turn on a 'graphics mode'. My main problem is that I need to know how to get mouse data, mainly the position of the cursor. Any ideas?

PS: please tell me how in real-mode assembly

Posted: Tue Jan 30, 2007 4:56 am
by xsix
First of all in real mode you can use INT 0x33. It lets you to use ps/2, serial or whatever any other mouse it supports. But if you're in protected mode, switch back into real mode or work in v86 for mouse would be more than stupid idea, so you have to write your own drivers. And it is more difficult because, if you're writing driver for serial mouse, you need to reprogramm UART and then code driver

Posted: Tue Jan 30, 2007 10:45 am
by Jules
INT 0x33 is provided by the typical 'mouse.com' TSRs in DOS. For your own kernel, you'd need to read stuff from the mouse port directly. PS/2 mice send a message each time they move, describing how much they've moved by. You'd need to set up the port, hook the appropriate interrupt and start interpreting those messages. You access it through the keyboard controller. The interrupt is IRQ 12 and the I/O ports 0x60 and 0x64.

Useful references:

http://maven.smith.edu/~thiebaut/ArtOfA ... H20-2.html -- how to use the keyboard controller, although this is written with the intent of using it for accessing keyboard data, not mouse data.
http://www.computer-engineering.org/ps2mouse/ - a good description of the data formats the mouse sends.

From the first reference, you should be able to see how to switch mouse interrupts on and send initialisation commands to the mouse, then I think from IRQ 12 you simply read data one byte at a time from 0x60 to get the packets, and interpret them as in the second reference.

Posted: Tue Jan 30, 2007 3:19 pm
by pcmattman
Thankyou. I'll look into that. This morning I finished off the window drawing functions so now I just need to get the mouse working.