Serial Mouse Problem...

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
ComputerPsi
Member
Member
Posts: 83
Joined: Fri Oct 22, 2004 11:00 pm

Serial Mouse Problem...

Post by ComputerPsi »

Hello. I tried to create an interrupt handler for a serial mouse, but it doesn't seem to work correctly. Here is the code of the handler:

Code: Select all

INT_0xC:		;COM1 (Serial Mouse) Interrupt Called.
	sti

	push dx
	push ax
	push si

	push cs
	pop ds

	mov	si, mouse
	call	Print_String	;Write a "M"

	mov al,0x20	;Make the interrupt vector happy, and
	out 0x20,al	;tell it this interrupt is done with its job ;-)

	pop si
	pop ax
	pop dx

	IRET
As you can see, it only writes a "M" on the screen, when the interrupt is called. (Not really a driver).

Here is the initialization code for the serial:

Code: Select all

mouse2:

		mov	si,0x3f8

		mov	dx,si		;SET DLAB ON
		add	dx,3
		mov	al,0x80
		out	dx,al
		nop

		mov	dx,si		;set Baud rate (low)
		mov	al,0x60
		out	dx,al
		nop
					;/* Default 0x03 =  38,400 BPS */
					;/*         0x01 = 115,200 BPS */
					;/*         0x02 =  57,600 BPS */
					;/*         0x06 =  19,200 BPS */
					;/*         0x0C =   9,600 BPS */
					;/*         0x18 =   4,800 BPS */
					;/*         0x30 =   2,400 BPS */
					;/*         0x60 =   1,200 BPS */

		mov	dx,si		;set Baud rate (high)
		inc	dx
		mov	al,0
		out	dx,al
		nop

		mov	dx,si		;8 Bits, No Parity, 1 Stop Bit
		add	dx,3
		mov	al,0x3
		out	dx,al
		nop

		mov	dx,si		;FIFO Control Register
		add	dx,4
		mov	al,0xb
		out	dx,al
		nop

		mov	dx,si		;Turn on DTR, RTS, and OUT2
		add	dx,2
		mov	al,0xc7
		out	dx,al
		nop

		mov	dx,si		;Interrupt when data received
		inc	dx
		mov	al,1
		out	dx,al
		nop
For some reason, when I run the code, the interrupt is only called once, when the computer boots up. If I move the mouse, or click, it doesn't call the interrupt. Does anybody know what is the problem? The serial mouse is on COM1 (int C-IRQ4).
Last edited by ComputerPsi on Sat Oct 23, 2004 11:00 pm, edited 2 times in total.
slasher
Posts: 17
Joined: Sun Oct 24, 2004 11:00 pm
Contact:

Re: Serial Mouse Problem...

Post by slasher »

Have you tried sending 0x20 to the slave pic as well?

mov al,0x20
out 0xa0,al
ComputerPsi
Member
Member
Posts: 83
Joined: Fri Oct 22, 2004 11:00 pm

Re: Serial Mouse Problem...

Post by ComputerPsi »

Why would you do that if you are not using the slave pic??
Anything is possible if you put your mind to it.
ComputerPsi
Anton
Member
Member
Posts: 30
Joined: Thu Oct 21, 2004 11:00 pm
Location: Moscow, Russian Federation

Re: Serial Mouse Problem...

Post by Anton »

I thinkthat you need to read the mouse data(from ports), or else the mouse will not know that you are able to receive more data.(It's buffers are overfull)
Daidalos
Posts: 3
Joined: Mon Oct 25, 2004 11:00 pm
Contact:

Re: Serial Mouse Problem...

Post by Daidalos »

Anton wrote:I thinkthat you need to read the mouse data(from ports), or else the mouse will not know that you are able to receive more data.(It's buffers are overfull)
Exactly. You've informed the PIC that you're done handling the interrupt, but you haven't informed the serial chip. The serial chip isn't going to send you any more interrupts until you handle the first one.
ComputerPsi
Member
Member
Posts: 83
Joined: Fri Oct 22, 2004 11:00 pm

Re: Serial Mouse Problem...

Post by ComputerPsi »

OK.. I fixed it by using this code:

Code: Select all

INT_0xC:		;COM1 (Serial Mouse) Interrupt Called.

	pusha		;backup everything

	push cs
	pop ds

        mov dx,3fdh			;line status register.
        in al,dx
	sub dx,5
;	test al,2
;	jz @nooverrun		; jump if no overrun occured
;
;	in al,dx			; else flush receive buffer,
;	jmp @exitIRQh		;  and exit

;@nooverrun:
        in al,dx			;Receive the incoming byte.

	mov si, msgmouse
	call print_string	;Write a "M"

	mov al,0x20	;Make the interrupt vector happy, and
	out 0x20,al	;tell it this interrupt is done with its job ;-)

@exitIRQh:
	popa		;Put back everything how it was.
	IRET
When I run this, then when I move the mouse, "M" appears. The problem is that the mouse keeps sending the message non-stop.
If I uncomment the commented lines, then the M never gets shown, which probably means that the sent message is overrun. Does anybody know how to fix this?
Anton
Member
Member
Posts: 30
Joined: Thu Oct 21, 2004 11:00 pm
Location: Moscow, Russian Federation

Re: Serial Mouse Problem...

Post by Anton »

First of all the last lines of code
mov si, msgmouse
call print_string ;Write a "M"

mov al,0x20 ;Make the interrupt vector happy, and
out 0x20,al ;tell it this interrupt is done with its job ;-)

@exitIRQh:
popa ;Put back everything how it was.
IRET

should look like this(you forgot to do mov al,0x20 out 0x20,al in case of a overrun!)
mov si, msgmouse
call print_string ;Write a "M"

@exitIRQh:
mov al,0x20 ;Make the interrupt vector happy, and
out 0x20,al ;tell it this interrupt is done with its job ;-)

popa ;Put back everything how it was.
IRET


Anton.
ComputerPsi
Member
Member
Posts: 83
Joined: Fri Oct 22, 2004 11:00 pm

Re: Serial Mouse Problem...

Post by ComputerPsi »

Thanks for the response, I didn't see that error. When I fixed it, M still appears when a message is sent, with the uncommented lines. But... the original problem still continues.... when I move the mouse, "M" gets drawn on the screen, but it keeps on getting drawn, non-stop. Does anybody know what is the problem?
Anything is possible if you put your mind to it.
ComputerPsi
ComputerPsi
Member
Member
Posts: 83
Joined: Fri Oct 22, 2004 11:00 pm

Re: Serial Mouse Problem...

Post by ComputerPsi »

OK, I found out that there seems to be some type of "Framing Error" from LSR line status. I'm not sure what that is.. I'm trying to figure it out right now... Does anybody know what this is?
Anything is possible if you put your mind to it.
ComputerPsi
ComputerPsi
Member
Member
Posts: 83
Joined: Fri Oct 22, 2004 11:00 pm

Re: Serial Mouse Problem...

Post by ComputerPsi »

OK, thanks everybody. I understood what was wrong. As soon as the mouse started sending messages, it continued to send them, even if the mouse was not moving. This happens to be a normal behavior. "Framing Error" was something completely different, that I made a mistake on. *Starts writing mouse driver*
Anything is possible if you put your mind to it.
ComputerPsi
User avatar
smiddy
Member
Member
Posts: 127
Joined: Sun Oct 24, 2004 11:00 pm
Location: In my cube, like a good leming. ;-)

Re: Serial Mouse Problem...

Post by smiddy »

Out of curiosity what information is the mouse sending?

Does it continue to tell that it hasn't moved? Perhaps you can change your printing of the 'M' only when ther is movement or a button press or wheel movement? But then you'd almost have a complete driver,eh? ;-)
-smiddy
ComputerPsi
Member
Member
Posts: 83
Joined: Fri Oct 22, 2004 11:00 pm

Re: Serial Mouse Problem...

Post by ComputerPsi »

Actually, any time the mouse gets moved or clicked. A message sent, from a Logitech mouse is a 5 byte message, containing the button information (3 buttons), and x,y positions, between the first time and the second time it was moved. If it is from a microsoft mouse, 3 bytes are send, with similar information, just with only 2 buttons. I actually almost have a driver... but there is a long time to finishing it. I still have to write some code that would detect a mouse on COM2, COM3, COM4, PS/2, and BUS.... But, I'll only do that, when I already have a decent OS, that needs to support such features.
Anything is possible if you put your mind to it.
ComputerPsi
Anton
Member
Member
Posts: 30
Joined: Thu Oct 21, 2004 11:00 pm
Location: Moscow, Russian Federation

Re: Serial Mouse Problem...

Post by Anton »

ComputerPsi wrote:As soon as the mouse started sending messages, it continued to send them, even if the mouse was not moving. This happens to be a normal behavior.
It is not. The mouse is not supposed to be sending any information unless you move it.
Do you know what FIFO is?(You seem to be using it) I think that FIFO is for modem connections and not for the mouse.(And that's what making these interrupts since it can't wakeup the DMA(you are supposed to use it, if you use FIFO))
ComputerPsi
Member
Member
Posts: 83
Joined: Fri Oct 22, 2004 11:00 pm

Re: Serial Mouse Problem...

Post by ComputerPsi »

Anton, Well, maybe it's not, but everything else is acting normal. When the mouse is not moving, it sends NULL bytes. When it is moving, or sending some message, it is sent. About the FIFO, I originally though it was needed, but after I looked at some other codes, I saw that it can work without FIFO, so I removed that.

Edit:
OK, sorry, my mistake. The mouse only sends messages when it is moved, or clicked.
Last edited by ComputerPsi on Fri Oct 29, 2004 11:00 pm, edited 1 time in total.
Anything is possible if you put your mind to it.
ComputerPsi
Anton
Member
Member
Posts: 30
Joined: Thu Oct 21, 2004 11:00 pm
Location: Moscow, Russian Federation

Re: Serial Mouse Problem...

Post by Anton »

ComputerPsi wrote:The mouse only sends messages when it is moved, or clicked.
Exactly. :) This is the way it should be.
Post Reply