Google Groups unterstützt keine neuen Usenet-Beiträge oder ‑Abos mehr. Bisherige Inhalte sind weiterhin sichtbar.

PS/2 mouse input

0 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Martin Cote

ungelesen,
15.06.2002, 20:56:0415.06.02
an
Hi,

I'm trying to handle my PS/2 mouse interruptions (IRQ 12) via ports. I've
read somewhere that when the mouse is configured correctly (as stream mode),
it starts to make interruptions regularly giving 3 bytes each time. They are
supposed to have the following format:

+--+--+--+--+--+--+--+--+
|YO|XO|YN|XN|re|re|RI|LE| byte 0
+--+--+--+--+--+--+--+--+
+--+--+--+--+--+--+--+--+
| Delta X | byte 1
+--+--+--+--+--+--+--+--+
+--+--+--+--+--+--+--+--+
| Delta Y | byte 2
+--+--+--+--+--+--+--+--+

So, I have used something like that:

;;========================
;; Mouse initialization

mov al, 0xA8
out al, 0x64 ; activate mouse

mov al, 0xD4
out 0x64
mov al, 0xFF
out 0x60 ; reset mouse

in al, 0x60 ; 0xFA
in al, 0x60 ; 0xAA
in al, 0x60 ; 0x00

mov al, 0xD4
out 0x64
out 0xF4 ; start mouse

in al, 0x60 ; 0xFA


;;=======================
;; Interrupt handler

in al, 0x60 ; byte 0
in ah, 0x60 ; byte 1
in bl, 0x60 ; byte 2

The problem is that is doesn't seem to work... An I have no idea why. If
someone can help, I would be really grantful...

Thanks a lot!

Martin


Debs

ungelesen,
18.06.2002, 21:56:0018.06.02
an
Hello cyberfolk!

On Sun, 16 Jun 2002 00:56:04 +0000 (UTC), Martin Cote spake thus:

I haven't done any PS2 mouse programming, so I can't comment on that,
but there are a few things in your code that don't look right to me.
What assembler are you using? I note that a lot of your "out"
instructions are only given an immediate operand, and no register or
size, so I'm wondering how the assembler knows whether you mean "out
imm,al" or "out imm,ax", which have different code and will do
different things when executed (sometimes, trying to send a word to a
port will do something different to sending a byte, and vice-versa).

>
>mov al, 0xA8
>out al, 0x64 ; activate mouse

Should that be

out 0x64,al

??


>
>mov al, 0xD4
>out 0x64

out 0x64,al

or

out 0x64,ax

As explained above :) That occurs at several places in your code,
using 3 different ports in total, none of which specify whether to use
AL or AX as the source.

Although this may not be your entire problem, if your assembler is
generating code for above instructions it may not be generating what
you intended for it to generate.


--
Debs
de...@dwiles.nospam.demon.co.uk
----
You have the right to remain silent. Anything you say will be misquoted and used against you.

Alexei A. Frounze

ungelesen,
23.06.2002, 06:55:5723.06.02
an

I have a driver for PS/2 mouse (use 16-bit Turbo/Borland C/C++ compiler to
compile):
--------------8<-------------
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>

#define short_delay() __emit__ (0xEB, 0)

void interrupt (*old_handler)();
int first=1;
int x=0, y=0, b=0;

unsigned char kbd_read() {
unsigned char res;
unsigned n;

n = 0xFFFF;
while (n--)
if ( inportb(0x64) & 1 ) {
n = 1;
break;
}

if (!n) return 0;

res = inportb (0x60);

return res;
}

void kbd_write (unsigned char value) {
unsigned n;

n = 0xFFFF;
while (n--)
if ( inportb(0x64) & 2 == 0 ) {
n = 1;
break;
}

if (!n) return;

outportb (0x60, value);

n = 0xFFFF;
while (n--)
if ( inportb(0x64) & 2 == 0) {
n = 1;
break;
}

if (!n) return;
}

void kbd_cmd (unsigned char cmd) {
outportb (0x64, cmd);
}

void interrupt new_handler() {
int dx, dy, nx, ny, nb;

kbd_cmd (0xAD);

if (first) {
kbd_read();
kbd_read();
kbd_read();
first = 0;
} else {
nb = kbd_read();
dx = kbd_read();
dy = kbd_read();
if (dx & 0x80) dx = dx-256;
if (dy & 0x80) dy = dy-256;
dy = -dy;
nb &= 7;
nx = x + dx;
ny = y + dy;
if (nx < 0) nx = 0; if (nx > 639) nx = 639;
if (ny < 0) ny = 0; if (ny > 199) ny = 199;

x = nx;
y = ny;
b = nb;
}

kbd_cmd (0xAE);

outportb (0xA0, 0x20);
outportb (0x20, 0x20);
}

void main() {
int imask;
unsigned char z;

clrscr();
old_handler = getvect (0x74); // save IRQ12 ISR
imask = inportb(0xA1); // get IRQ mask

disable();

setvect (0x74, new_handler); // set new IRQ12 ISR
outportb (0xA1, imask & ~(1<<4)); // unmask IRQ12

kbd_cmd (0xA8); // enable mouse

kbd_cmd (0x20);
z = kbd_read() | 2;
kbd_cmd (0x60);
kbd_write (z); // enable mouse interrupt

kbd_cmd (0xD4);
kbd_write (0xF4); // enable data transmission

enable();

while (!kbhit()) {
gotoxy (1+x/8, 1+y/8);
}
getch();

disable();

kbd_cmd (0xD4);
kbd_write (0xF5); // disable data transmission

kbd_cmd (0x20);
z = kbd_read() & ~2;
kbd_cmd (0x60);
kbd_write (z); // disable mouse interrupt

kbd_cmd (0xA7); // disable mouse

outportb (0xA1, imask); // mask IRQ12
setvect (0x74, old_handler); // restore IRQ12 ISR

enable();
}
--------------8<-------------

Good Luck
Alexei A. Frounze
http://alexfru.narod.ru
http://members.tripod.com/protected_mode/

0 neue Nachrichten