Page 1 of 3

PS/2 mouse driver

Posted: Tue Mar 23, 2004 1:22 pm
by St8ic
I set up unreal mode (with A20), drew a desktop and now I'm working on a mouse driver. Since I'm in unreal mode I was wondering if it might be possible to do a good mouse driver using BIOS inturrupts (Int 33)? I already wrote one, but I'm not even gonna test it it's so bad.

Re:PS/2 mouse driver

Posted: Tue Mar 23, 2004 1:28 pm
by Pype.Clicker
int 33h is not at all a BIOS interrupt. It's something provided by a DOS driver (mouse.sys in most of the case) that stay resident and provide a standardized interface that abstracts mouse protocol decoding ...

Re:PS/2 mouse driver

Posted: Tue Mar 23, 2004 1:55 pm
by DennisCGc
Like pype said, it's just an interrupt made by a mouse driver.
So you have to write your own mouse driver for your OS.
I know a book, which can help you.
But I don't remember the english version of it, (could someone translate this to a proper title ;) ):
"PC Hardware dl. 4 by Hans Messmer" (I don't know the author that well :( )

Re:PS/2 mouse driver

Posted: Tue Mar 23, 2004 2:01 pm
by Candy
DennisCGc wrote: But I don't remember the english version of it, (could someone translate this to a proper title ;) ):
"PC Hardware dl. 4 by Hans Messmer" (I don't know the author that well :( )
The Indispensable PC Hardware Book, Hans-Peter Messmer. ISBN 0-201-59616-4.

If you can find the 3rd ed. buy that. It has 13 appendices as opposed to 6, as well as more pages & more chapters. I'm lucky enough to have both :)

Re:PS/2 mouse driver

Posted: Tue Mar 23, 2004 2:04 pm
by DennisCGc
Candy wrote:
DennisCGc wrote: But I don't remember the english version of it, (could someone translate this to a proper title ;) ):
"PC Hardware dl. 4 by Hans Messmer" (I don't know the author that well :( )
The Indispensable PC Hardware Book, Hans-Peter Messmer. ISBN 0-201-59616-4.

If you can find the 3rd ed. buy that. It has 13 appendices as opposed to 6, as well as more pages & more chapters. I'm lucky enough to have both :)
Thanks for translating ;)

Re:PS/2 mouse driver

Posted: Tue Mar 23, 2004 6:26 pm
by St8ic
Sorry, I meant Int 15:
Int 15/AX=C200h (http://www.ctyme.com/intr/rb-1596.htm)
Int 15/AX=C209h (http://www.ctyme.com/intr/rb-1605.htm)
Things like that?

Re:PS/2 mouse driver

Posted: Wed Mar 24, 2004 3:46 am
by bubach
http://www.hut.fi/~then/mytexts/mouse.html
http://alexfru.narod.ru/emiscdocs.html -look at: "Mouse Programming (specs, docs)"

/ Christoffer

Re:PS/2 mouse driver

Posted: Wed Mar 24, 2004 8:55 am
by DennisCGc
St8ic wrote: Sorry, I meant Int 15:
Int 15/AX=C200h (http://www.ctyme.com/intr/rb-1596.htm)
Int 15/AX=C209h (http://www.ctyme.com/intr/rb-1605.htm)
Things like that?
Why should you use that ?
That's a lot more difficult than programming via the I/O ports.
(At least, I think it is, looking at the registers and format of the packets ;) )

Re:PS/2 mouse driver

Posted: Wed Mar 24, 2004 11:36 am
by St8ic
I could use the ports, but I was wondering if, since I was in unreal mode, it might be easier to do it via BIOS ints. An example for either one would be good.

Bubach:The first link was handy, but offered no code. The second one only offered code that relied on DOS. Thanks anyways.

Re:PS/2 mouse driver

Posted: Wed Mar 24, 2004 11:42 am
by bubach
it took me about 2 min to find that info on google, u will have to try searching a bit on your own then..

/ Christoffer

Re:PS/2 mouse driver

Posted: Fri Mar 26, 2004 10:35 pm
by St8ic
Maybe I'm just terrible at searching ;) .

Could you please just look at Int 15/AX=C209h (http://www.ctyme.com/intr/rb-1605.htm) and tell me how to decode the three bytes returned by the pointer port? It couldn't be that hard, right? I suck at assembly.

I also need routines for drawing and moving the mouse...;D

Re:PS/2 mouse driver

Posted: Sat Mar 27, 2004 10:06 am
by Pype.Clicker
St8ic wrote: Maybe I'm just terrible at searching ;) .

Could you please just look at Int 15/AX=C209h (http://www.ctyme.com/intr/rb-1605.htm) and tell me how to decode the three bytes returned by the pointer port? It couldn't be that hard, right? I suck at assembly.
then don't do it in assembly! Hah... You take the risk of being flamed by asking things that way.
I also need routines for drawing and moving the mouse...;D
Those won't be any different from drawing a sprite with transparent color ... Check some game programming tutorial (programmersheaven.com or something alike): any decent one should have the information you request.

Re:PS/2 mouse driver

Posted: Sat Mar 27, 2004 1:40 pm
by DennisCGc
St8ic wrote: Maybe I'm just terrible at searching ;) .

Could you please just look at Int 15/AX=C209h (http://www.ctyme.com/intr/rb-1605.htm) and tell me how to decode the three bytes returned by the pointer port? It couldn't be that hard, right? I suck at assembly.

I also need routines for drawing and moving the mouse...;D
WHY SHOULD YOU USE IT ?
IT GIVES NOT A BETTER RESULT USING THE BIOS </capsmode> ;)
using i/o ports will be faster, and it would be easier ;D

Re:PS/2 mouse driver

Posted: Sat Mar 27, 2004 7:24 pm
by St8ic
Here's that code I told you about that I'm possitive wouldn't work. Can you list off a couple reasons why? I'm very sorry that the syntax is so bad it's almost offensive. I'm not sure how the 8-bit X and Y movement indicators are calculated from the bits. Here I just add them all together ;)

Code: Select all

_mouse:   mov ax,C200h              ; enable the mouse
          int 15
          mov ax,C205h              ; initialize the mouse
          int 15
.loop:    mov ax,C209h              ; read 3 bytes from mouse into bl, cl and dl
          int 15
          cmp byte [bl+3],1         ; is the left button pressed?
          mov byte [lbpress],1      ; if it is
          mov byte [lbpress],0      ; if it isn't
          cmp byte [bl+4],1         ; is the right button pressed?
          mov byte [rbpress],1      ; if it is
          mov byte [rbpress],0      ; if it isn't
          add byte [cl+8],[xmovement]  ; get 8-bit X-movement indicator
          add byte [cl+7],[xmovement]
          add byte [cl+6],[xmovement]
          add byte [cl+5],[xmovement]
          add byte [cl+4],[xmovement]
          add byte [cl+3],[xmovement]
          add byte [bl+8],[xmovement]
          add byte [bl+7],[xmovement]
          add [xmovement],[xlocation]  ; add movement to current location to get new location
          add byte [dl+8],[ymovement]  ; get 8-bit Y-movement indicator
          add byte [dl+7],[ymovement]
          add byte [dl+6],[ymovement]
          add byte [dl+5],[ymovement]
          add byte [dl+4],[ymovement]
          add byte [dl+3],[ymovement]
          add byte [bl+6],[ymovement]
          add byte [bl+5],[ymovement]
          add [ymovement],[ylocation]  ; add movement to current location to get new location
          LOOP .loop

lbpress db 1
rbpress db 1
xmovement db 0
ymovement db 0
xlocation db 0
ylocation db 0

Re:PS/2 mouse driver

Posted: Sun Mar 28, 2004 1:50 pm
by Pype.Clicker
it looks like you're messing up the access of memory region based at BX plus an offset with accessing the ith bit of a register.

The docs says that BL is the 2nd octet. Obviously the value of interrest is in BL itself, not at a memory location starting at BL. So you shouldn't write

Code: Select all

cmp [bl+3],1
but rather

Code: Select all

test bl,2<<3