Re: ps/2 mouse w/o int33
- From: Dirk Wolfgang Glomp <spamtrap@xxxxxxxxxx>
- Date: Sun, 06 Nov 2005 07:55:32 +0100
spamtrap@xxxxxxxxxx schrieb:
> aanderson@xxxxxxxxxxxxxxxxx wrote:
>
>>i want to program ps/2 mouse for use in my toy os. anyone know how? ive
>>search the net but cant find anything...
>
> Well, there is this...
> http://www.nondot.org/sabre/os/articles/HumanInterfaceDevices/
> ... to get you started. But those examples use DOS calls so they won't
> be available to *your* OS but it might give you ideas for the design of
> your own routines. What you need is info on BIOS calls, so look at
> HelpPC:
>
> http://heim.ifi.uio.no/~stanisls/helppc/
> http://www.faqs.org/faqs/assembly-language/x86/general/part1/section-6.html
....int 15?
> ...and Ralph Brown's Interrupt List:
>
> http://www.cs.cmu.edu/afs/cs/user/ralf/pub/WWW/files.html
> http://www.ctyme.com/rbrown.htm
> But if you also want to write your own "toy BIOS", then go back to here
> to get the BIOS source:
>
> http://www.nondot.org/sabre/os/articles/MiscellaneousSoftware/
>
> Nathan.
I found nothing about to initialize a PS2-mouse w/o int33.
http://cutemouse.sourceforge.net
....i dont find the PS2-part.
----------------------
RBIL
PORT 0060-006F - KEYBOARD CONTROLLER 804x (8041, 8042) (or PPI (8255) on
PC,XT)
Note: XT uses ports 60h-63h, AT uses ports 60h-64h
0060 RW KB controller data port or keyboard input buffer (ISA, EISA)
should only be read from after status port bit0 = 1
should only be written to if status port bit1 = 0
0060 R- KeyBoard or KB controller data output buffer (via PPI on XT)
PC: input from port A of 8255, if bit7 in 61h set (see #P0396)
get scancodes, special codes (in PC: with bit7 in 61h cleared)
(see #P0390)
0061 R- KB controller port B control register (ISA, EISA)
system control port for compatibility with 8255 (see #P0393)
0061 -W KB controller port B (ISA, EISA) (PS/2 port A is at 0092)
system control port for compatibility with 8255 (see #P0392)
0064 R- keyboard controller read status (see #P0398,#P0399,#P0400)
0064 -W keyboard controller input buffer (ISA, EISA) (see #P0401)
(Table P0387)
Values for Mouse functions (for PS/2-like pointing devices):
Value Count Description
E6h sngl set mouse scaling to 1:1
E7h sngl set mouse scaling to 2:1
E8h double set mouse resolution
(00h=1/mm, 01h=2/mm, 02h=4/mm, 03h=8/mm)
E9h sngl get mouse information
read two status bytes:
byte 0: flags (see #P0388)
byte 1: resolution
EAh sngl set mouse to stream mode (mouse sends data on any changes)
EBh sngl get mouse data (from mouse to controller) (see #P0389)
on reading, each data packet consists of 8 bytes:
ECh sngl reset mouse wrap mode (to normal mode)
EEh sngl set wrap mode
F0h sngl set remote mode (instead of stream mode), mouse sends data
only on issueing command EBh.
F2h sngl read mouse ID (read one, two?? ID bytes)
00h=mouse
F3h double set mouse sample rate in reports per second
0Ah=10/s 50h= 80/s
14h=20/s 64h=100/s
28h=40/s C8h=200/s
3Ch=60/s
F4h sngl enable mouse (in stream mode)
F5h sngl disable mouse (in steam mode), set default parameters
F6h sngl reset to defaults: 100/s, scaling 1:1, stream-mode, 4/mm,
disabled
FEh sngl resend last mouse data (8 bytes, see EBh)
FFh sngl reset mouse
Notes: must issue command D4h to PORT 0064h first to access mouse functions
all commands except ECh and FFh are acknowledged by FAh (ACK) or
FEh (Resend); get mouse ID (F2h) returns mouse ID.
SeeAlso: #P0386
Bitfields for mouse status byte 0:
Bit(s) Description (Table P0388)
7 unused
6 remote rather than stream mode
5 mouse enabled
4 scaling set to 2:1
3 unused
2 left button pressed
1 unused
0 right button pressed
SeeAlso: #P0387,#P0389
Format of mouse data packet:
Offset Size Description (Table P0389)
00h BYTE status
bit7 : y-data overrun
bit6 : x-data overrun
bit5 : y-data negative
bit4 : x-data negative
bit3-2=0: reserved
bit1 : right button pressed
bit0 : left button pressed
01h BYTE reserved
02h BYTE x-data
03h BYTE reserved
04h BYTE y-data
05h BYTE reserved
06h BYTE z-data (0)
07h BYTE reserved
SeeAlso: #P0387,#P0388
(Table P0390)
Values for keyboard special codes:
FAh (mouse) Acknowledge (all commands except commands ECh,F2h,FFh)
FEh (mouse) CPU to controller should resend last mouse-command
SeeAlso: PORT 0060h-R
Bitfields for keyboard controller read status (ISA, EISA):
Bit(s) Description (Table P0398)
3 =1 data written to input register is command (PORT 0064h)
=0 data written to input register is data (PORT 0060h)
1 input buffer full (input 60/64 has data for 8042)
no write access allowed until bit clears
0 output buffer full (output 60 has data for system)
bit is cleared after read access
SeeAlso: PORT 0064h-R,#P0399,#P0400,#P0401
Bitfields for keyboard controller read status (MCA):
Bit(s) Description (Table P0399)
5 mouse output buffer full
3 =1 data written to input register is command (PORT 0064h)
=0 data written to input register is data (PORT 0060h)
1 input buffer full (60/64 has data for 804x)
no write access allowed until bit clears
0 output buffer full (output 60 has data for system)
bit is cleared after read access
SeeAlso: #P0398,#P0400,#P0401
(Table P0401)
Values for keyboard controller commands (data goes to PORT 0060h):
Value Description
A7h MCA disable mouse port
A8h MCA enable mouse port
A9h MCA test mouse port, return test result on PORT 0060h (see #P0406)
C0h read read input port and place on PORT 0060h
bit 1 (MCA) current mouse serial data input state
D3h MCA Enhanced Command: write pointing device out.buf.
D4h MCA write to mouse/pointing device instead of to keyboard; this
controller command must precede every PORT 0060h command
directed to the mouse, otherwise it will be sent to the
keyboard
Bitfields for keyboard command byte (alternate description):
Bit(s) Description (Table P0404)
5 IBM PC mode
no parity, no stop bits, no translation
(PS/2) force mouse clock low
1 (AT) reserved (0)
(PS/2) enable mouse output buffer full interrupt (IRQ12)
SeeAlso: #P0403,#P0405
Bitfields for keyboard controller output port:
Bit(s) Description (Table P0405)
3 (MCA) mouse data (output)
2 (MCA) mouse clock (output)
used by Intel 386sx Chipset with AMI/Phoenix BIOSes for BIOS-specific
configuration of turbo switch
0 system reset
Note: bit 0 (system reset) should always be set when writing the output
port, as the system may hang constantly; use pulse output port
(command FEh) instead.
SeeAlso: #P0404
(Table P0406)
Values for keyboard/mouse test result on PORT 0060h:
00h no error
01h keyboard clock line stuck low
02h keyboard clock line stuck high
03h keyboard data line is stuck low
04h keyboard data line stuck high
SeeAlso: #P0401
-------------------------------------------------------------------------------------------------
http://www.computer-engineering.org/ps2mouse/
Movement Data Packet:
The standard PS/2 mouse sends movement/button information to the host
using the following 3-byte packet (4):
Byte 1
Bit 7 Y overflow
Bit 6 X overflow
Bit 5 Y sign bit
Bit 4 X sign bit
Bit 3 Always 1
Bit 2 Middle Btn
Bit 1 Right Btn
Bit 0 Left Btn
Byte 2 X Movement
Byte 3 Y Movement
The movement counters are 9-bit 2's complement integers,
where the most significant bit appears as a sign bit in Byte 1 of the
movement data packet.
These counters are updated when the mouse reads its input and finds
movement has occurred.
Their value is the amount of movement that has occurred
since the last movement data packet was sent to the host
(ie, after a packet is sent to the host, the movement counters are reset.)
The range of values that can be expressed by the movement counters is
-255 to +255.
If this range is exceeded, the appropriate overflow bit is set.
As I mentioned earlier,
the movement counters are reset whenever a movement data packet is
successfully sent to the host.
They are also reset after the mouse receives any command from the host
other than the "Resend" (0xFE) command.
Modes of Operation:
Data reporting is handled according to the mode in which the mouse is
operating.
There are four standard modes of operation:
* Reset - The mouse enters Reset mode at power-up or after receiving the
"Reset" (0xFF) command.
* Stream - This is the default mode (after Reset finishes executing) and
is the mode in which most software uses the mouse. If the host has
previously set the mouse to Remote mode, it may re-enter Stream mode by
sending the "Set Stream Mode" (0xEA) command to the mouse.
* Remote - Remote mode is useful in some situations and may be entered
by sending the "Set Remote Mode" (0xF0) command to the mouse.
* Wrap - This mode isn't particularly useful except for testing the
connection between the mouse and its host.
Wrap mode may be entered by sending the "Set Wrap Mode" (0xEE) command
to the mouse.
To exit Wrap mode, the host must issue the "Reset" (0xFF) command or
"Reset Wrap Mode" (0xEC) command.
If the "Reset" (0xFF) command is recieved, the mouse will enter Reset
mode.
If the "Reset Wrap Mode" (0xEC) command is received, the mouse will
enter the mode it was in prior to Wrap Mode.
(Note: The mouse may also enter "extended" modes of operation, as
described later in this document.
However, this is not a feature of the standard PS/2 mouse.)
Reset Mode:
The mouse enters reset mode at power-on or in response to the "Reset"
(0xFF) command.
After entring this mode, the mouse performs a diagnostic self-test
referred to as BAT (Basic Assurance Test)
and sets the following default values:
* Sample Rate = 100 samples/sec
* Resolution = 4 counts/mm
* Scaling = 1:1
* Data Reporting Disabled
It then sends a BAT completion code of either AAh (BAT successful) or
FCh (Error).
The host's response to a completion code other than AAh is undefined.
Following the BAT completion code (AAh or FCh), the mouse sends its
device ID of 00h.
This distinguishes it from a keyboard, or a mouse in an extended mode.
I have read documents saything the host is not supposed to transmit any
data until it receives a device ID.
However I've found that some BIOS's will send the "Reset" command
immediately following the 0xAA received
after a power-on reset.
After the mouse has sent its device ID to the host, it will enter Stream
Mode.
Note that one of the default values set by the mouse is "Data Reporting
Disabled".
This means the mouse will not issue any movement data packets until it
receives the "Enable Data Reporting" command.
Stream Mode:
In stream mode, the mouse sends movement data when it detects movement
or a change in state of one or more mouse buttons.
The maximum rate at which this data reporting may occur is known as the
sample rate.
This parameter ranges from 10 samples/sec to 200 samples/sec.
Its default value is 100 samples/sec and the host may change that value
by using the "Set Sample Rate" command.
Stream mode is the default mode of operation following reset.
Remote Mode:
In this mode the mouse reads its inputs and updates its counters/flags
at the current sample rate,
but it does not automatically issue data packets when movement has occured.
Instead, the host must poll the mouse using the "Read Data" command.
Upon receiving this command the mouse will send a single movement data
packet and reset its movement counters.
Wrap Mode:
This is an "echoing" mode in which every byte received by the mouse is
sent back to the host.
Even if the byte represents a valid command, the mouse will not respond
to that command--it will only echo
that byte back to the host.
There are two exceptions to this: the "Reset" command and "Reset Wrap
Mode" command.
The mouse treats these as valid commands and does not echo them back to
the host.
Command Set:
The following is the set of command accepted by the standard PS/2 mouse.
If the mouse is in Stream mode,
the host should disable data reporting (command F5h) before sending any
other commands.
* FFh (Reset) - The mouse responds to this command with "acknowledge"
(FAh) then enters Reset Mode.
* FEh (Resend) - The host sends this command whenever it receives
invalid data from the mouse.
The mouse responds by resending the last(2) packet(3) it sent to the host.
If the mouse responds to the "Resend" command with another invalid packet,
the host may either issue another "Resend" command, issue an "Error"
command,
cycle the mouse's power supply to reset the mouse, or it may inhibit
communication
(by bringing the Clock line low). The action taken depends on the host.
* F6h (Set Defaults) - The mouse responds with "acknowledge" (FAh) then
loads the following values:
Sampling rate = 100, Resolution = 4 counts/mm, Scaling = 1:1, Disable
Data Reporting.
The mouse then resets its movement counters and enters stream mode.
* F5h (Disable Data Reporting) - The mouse responds with "acknowledge" (FAh)
then disables data reporting and resets its movement counters.
This only effects data reporting in Stream mode and does not disable
sampling.
Disabled stream mode funcions the same as remote mode.
* F4h (Enable Data Reporting) - The mouse responds with "acknowledge" (FAh)
then enables data reporting and resets its movement counters.
This command may be issued while the mouse is in Remote Mode (or
Stream mode),
but it will only effect data reporting in Stream mode.
* F3h (Set Sample Rate) - The mouse responds with "acknowledge" (FAh)
then reads one more byte from the host.
The mouse saves this byte as the new sample rate. After receiving the
sample rate,
the mouse again responds with "acknowledge" (0xFA) and resets its
movement counters.
Valid sample rates are 10, 20, 40, 60, 80, 100, and 200 samples/sec.
* F2h (Get Device ID) - The mouse responds with "acknowledge" (FAh)
followed by its device ID (00h for the standard PS/2 mouse.)
The mouse should also reset its movement counters.
* F0h (Set Remote Mode) - The mouse responds with "acknowledge" (FAh)
then resets its movement counters and enters remote mode.
* EEh (Set Wrap Mode) - The mouse responds with "acknowledge" (FAh)
then resets its movement counters and enters wrap mode.
* ECh (Reset Wrap Mode) - The mouse responds with "acknowledge" (FAh)
then resets its movement counters and enters the mode it was in prior
to wrap mode (Stream Mode or Remote Mode.)
* EBh (Read Data) - The mouse responds with acknowledge (FAh) then sends
a movement data packet.
This is the only way to read data in Remote Mode. After the data
packets has been successfully sent,
it resets its movement counters.
* EAh (Set Stream Mode) - The mouse responds with "acknowledge"
then resets its movement counters and enters steram mode.
* E9h (Status Request) - The mouse responds with "acknowledge"
then sends the following 3-byte status packet (then resets its
movement counters.):
Byte 1
Bit 7 Always 0
Bit 6 Mode
Bit 5 Enable
Bit 4 Scaling
Bit 3 Always 0
Bit 2 Left Btn
Bit 1 Middle Btn
Bit 0 Right Btn
Byte 2 Resolution
Byte 3 Sample Rate
Right, Middle, Left Btn = 1 if button pressed; 0 if button is not pressed.
Scaling = 1 if scaling is 2:1; 0 if scaling is 1:1. (See commands E7h
and E6h)
Enable = 1 if data reporting is enabled; 0 if data reporting is
disabled. (See commands F5h and F4h)
Mode = 1 if Remote Mode is enabled; 0 if Stream mode is enabled. (See
commands F0h and EAh)
* E8h (Set Resolution) - The mouse responds with acknowledge (FAh)
then reads one byte from the host and again responds with acknowledge
(FAh)
then resets its movement counters. The byte read from the host
determines the resolution as follows:
Byte Read from Host
Resolution
0x00
1 count/mm
0x01
2 count/mm
0x02
4 count/mm
0x03
8 count/mm
* E7h (Set Scaling 2:1) - The mouse responds with acknowledge (FAh)
then enables 2:1 scaling (discussed earlier in this document.)
* E6h (Set Scaling 1:1) - The mouse responds with acknowledge (FAh)
then enables 1:1 scaling (discussed earlier in this document.)
The only commands the standard PS/2 mouse will send to the host are the
"Resend" (FEh) and "Error" (FCh).
They both work the same as they do as host-to-device commands.
Initialization:
The PS/2 mouse is normally detected/initialized only when the computer
is booting up.
That is, the mouse is not hot-pluggable and you must restart your
computer whenever you add/remove a PS/2 mouse
(furthermore, some motherboards may be damaged if you add/remove a PS/2
mouse while the computer is running.)
The initial detection of the PS/2 mouse occurrs during POST.
If a mouse is detected, the BIOS will allow the operating system to
configure/enable the mouse.
Otherwise, it will inhibit communication on the mouse's bus.
If you boot the computer with a mouse attached, then detach/reattach the
mouse while in Windows,
the OS may be able to detect the mouse was reattached.
Microsoft tried to support this, but it only works about 50% of the time.
The following is the communication between my computer (running Win98SE)
and mouse when it boots up with a standard PS/2 mouse attached.
It is fairly typical of how a PS/2 mouse is initialized
and if you want to emulate a PS/2 mouse it must (at minimum) be able
to support the following sequence of commands...
* Power-on Reset:
Mouse: AA Self-test passed
Mouse: 00 Mouse ID
Host: FF Reset command
Mouse: FA Acknowledge
Mouse: AA Self-test passed
Mouse: 00 Mouse ID
Host: FF Reset command
Mouse: FA Acknowledge
Mouse: AA Self-test passed
Mouse: 00 Mouse ID
Host: FF Reset command
Mouse: FA Acknowledge
Mouse: AA Self-test passed
Mouse: 00 Mouse ID
Host: F3 Set Sample Rate : Attempt to Enter Microsoft
Mouse: FA Acknowledge : Scrolling Mouse mode
Host: C8 decimal 200 :
Mouse: FA Acknowledge :
Host: F3 Set Sample Rate :
Mouse: FA Acknowledge :
Host: 64 decimal 100 :
Mouse: FA Acknowledge :
Host: F3 Set Sample Rate :
Mouse: FA Acknowledge :
Host: 50 decimal 80 :
Mouse: FA Acknowledge :
Host: F2 Read Device Type :
Mouse: FA Acknowledge :
Mouse: 00 Mouse ID : Response 03 if microsoft scrolling
mouse
Host: F3 Set Sample Rate
Mouse: FA Acknowledge
Host: 0A decimal 10
Mouse: FA Acknowledge
Host: F2 Read Device Type
Mouse: FA Acknowledge
Mouse: 00 Mouse ID
Host: E8 Set resolution
Mouse: FA Acknowledge
Host: 03 8 Counts/mm
Mouse: FA Acknowledge
Host: E6 Set Scaling 1:1
Mouse: FA Acknowledge
Host: F3 Set Sample Rate
Mouse: FA Acknowledge
Host: 28 decimal 40
Mouse: FA Acknowledge
Host: F4 Enable
Mouse: FA Acknowledge
Initialization complete...
If I then press the Left Button...
Mouse: 09 1 1 00001001; bit0 = Left button state; bit3 = always 1
Mouse: 00 1 1 No X-movement
Mouse: 00 1 1 No Y-movement
... and release the Left Button:
Mouse: 08 0 1 00001000 bit0 = Left button state; bit3 = always 1
Mouse: 00 1 1 No X-movement
Mouse: 00 1 1 No Y-movement
The following is the communication between my computer (running Win98SE)
and mouse when it boots up with an (emulated) Intellimouse...
* Power-on Reset:
Mouse: AA Self-test passed
Mouse: 00 Mouse ID
Host: FF Reset command
Mouse: FA Acknowledge
Mouse: AA Self-test passed
Mouse: 00 Mouse ID
Host: FF Reset command
Mouse: FA Acknowledge
Mouse: AA Self-test passed
Mouse: 00 Mouse ID
Host: FF Reset command
Mouse: FA Acknowledge
Mouse: AA Self-test passed
Mouse: 00 Mouse ID
Host: F3 Set Sample Rate : Attempt to Enter Microsoft
Mouse: FA Acknowledge : Scrolling Mouse mode
Host: C8 decimal 200 :
Mouse: FA Acknowledge :
Host: F3 Set Sample Rate :
Mouse: FA Acknowledge :
Host: 64 decimal 100 :
Mouse: FA Acknowledge :
Host: F3 Set Sample Rate :
Mouse: FA Acknowledge :
Host: 50 decimal 80 :
Mouse: FA Acknowledge :
Host: F2 Read Device Type :
Mouse: FA Acknowledge :
Mouse: 03 Mouse ID : Response 03 if microsoft scrolling
mouse
Host: E8 Set Resolution
Mouse: FA Acknowledge
Host: 03 8 counts/mm
Mouse: FA Acknowledge
Host: E6 Set scaling 1:1
Dev: FA Acknowledge
Host: F3 Set Sample Rate
Mouse: FA Acknowledge
Host: 28 decimal 40
Mouse: FA Acknowledge
Host: F4 Enable device
Mouse: FA Acknowledge
If I then press the left mouse button:
Mouse: 09 00001001 bit0 = Left button state; bit3 = always 1
Mouse: 00 No X-movement
Mouse: 00 No Y-movement
Mouse: 00 No Z-movement
...and then release the left mouse button button:
Mouse: 08 00001000 bit0 = Left button state; bit3 = always 1
Mouse: 00 No X-movement
Mouse: 00 No Y-movement
Mouse: 00 No Z-movement
After I downloaded/installed the Microsoft's Intellimouse drivers with
support for the 4th and 5th buttons,
the following sequence was found:
... (starts same as before) ...
Host: F3 Set Sample Rate : Attempt to Enter Microsoft
Mouse: FA Acknowledge : Scrolling Mouse mode.
Host: C8 decimal 200 :
Mouse: FA Acknowledge :
Host: F3 Set Sample Rate :
Mouse: FA Acknowledge :
Host: 64 decimal 100 :
Mouse: FA Acknowledge :
Host: F3 Set Sample Rate :
Mouse: FA Acknowledge :
Host: 50 decimal 80 :
Mouse: FA Acknowledge :
Host: F2 Read Device Type :
Mouse: FA Acknowledge :
Mouse: 03 Mouse ID : Response 03 if microsoft scrolling mouse.
Host: F3 Set Sample Rate : Attempt to Enter Microsoft 5-button
Mouse: FA Acknowledge : Scrolling Mouse mode.
Host: C8 decimal 200 :
Mouse: FA Acknowledge :
Host: F3 Set Sample Rate :
Mouse: FA Acknowledge :
Host: C8 decimal 200 :
Mouse: FA Acknowledge :
Host: F3 Set Sample Rate :
Mouse: FA Acknowledge :
Host: 50 decimal 80 :
Mouse: FA Acknowledge :
Host: F2 Read Device Type :
Mouse: FA Acknowledge :
Mouse: 04 Mouse ID : Response 04 if 5-button scrolling mouse.
... rest of initialization same as before ...
---------------------------------------------------------------------
http://www.ragestorm.net/samples/ps2mouse.cpp
// PS2Mouse example for drivers
// http://ragestorm.net
#include <dos.h>
#include <stdio.h>
#include <conio.h>
#define MOUSE_INTERRUPT_NO (0x74)
#define KEYB_PORT (0x60)
#define KEYB_CTRL (0x64)
#define KEYB_ACK (0xfa)
// find wheel
unsigned char ps2_init_string[] = { 0xf3, 0xc8, 0xf3, 0x64, 0xf3, 0x50,
0x00 };
// find buttons
unsigned char ps2_init_string2[] = { 0xf3, 0xc8, 0xf3, 0xc8, 0xf3, 0x50,
0x00 };
// real init
unsigned char ps2_init_string3[] = { 0xf6, 0xe6, 0xf4, 0xf3, 0x64, 0xe8,
0x03, 0x00 };
// mouse type
unsigned char extwheel = 0xff, extbuttons = 0xff;
int mx = 0, my = 0, mz = 0;
void interrupt (*old_handler)(...);
void interrupt new_handler(...);
unsigned int buttons[5] = {0, 0, 0, 0, 0};
void kbd_command_send(unsigned int port, unsigned char val)
{
unsigned long timeout;
unsigned char stat;
for (timeout = 500000l; timeout != 0; timeout--)
{
stat = inportb(KEYB_CTRL);
if ((stat & 0x02) == 0) break;
}
if (timeout != 0) outportb(port, val);
else printf("didn't send!\n");
}
unsigned char kbd_command_read()
{
unsigned long timeout;
unsigned char stat, data;
for (timeout = 500000l; timeout != 0; timeout--)
{
stat = inportb(KEYB_CTRL);
if ((stat & 0x01) != 0)
{
data = inportb(KEYB_PORT);
if ((stat & 0xC0) == 0) return data;
}
}
printf("didn't read!\n");
return -1;
}
unsigned char kbd_command_send_ack(unsigned int port, unsigned char val)
{
unsigned int ret_val = 0;
kbd_command_send(port, val);
ret_val = kbd_command_read();
if (ret_val != KEYB_ACK)
printf("[keyboard] error: expected 0x%x, got 0x%x\n", val, ret_val);
return ret_val;
}
void install_ps2_driver()
{
unsigned char* ch = 0;
kbd_command_send(KEYB_CTRL, 0xa8); // enable aux
kbd_command_send(KEYB_CTRL, 0xa9); // check aux interface
printf("interface response: 0x%x\n", kbd_command_read());
kbd_command_send(KEYB_CTRL, 0xd4); // write to aux
kbd_command_send_ack(KEYB_PORT, 0xf2); // identify mouse
printf("id response: 0x%x\n", kbd_command_read());
for (ch = ps2_init_string; *ch != '\0'; ch++) {
kbd_command_send(KEYB_CTRL, 0xd4);
kbd_command_send_ack(KEYB_PORT, *ch);
}
kbd_command_send(KEYB_CTRL, 0xd4); // write to aux
kbd_command_send_ack(KEYB_PORT, 0xf2); // identify mouse
printf("wheel mouse was found: %d\n", (extwheel =
kbd_command_read())==0x03);
for (ch = ps2_init_string2; *ch != '\0'; ch++) {
kbd_command_send(KEYB_CTRL, 0xd4);
kbd_command_send_ack(KEYB_PORT, *ch);
}
kbd_command_send(KEYB_CTRL, 0xd4); // write to aux
kbd_command_send_ack(KEYB_PORT, 0xf2); // identify mouse
printf(">3 buttons mouse was found: %d\n", (extbuttons =
kbd_command_read())==0x04);
for (ch = ps2_init_string3; *ch != '\0'; ch++) {
kbd_command_send(KEYB_CTRL, 0xd4);
kbd_command_send_ack(KEYB_PORT, *ch);
}
kbd_command_send(KEYB_CTRL, 0xd4); // write to aux
kbd_command_send(KEYB_PORT, 0xf4); // enable mouse
printf("enable response: 0x%x\n", kbd_command_read());
printf("extwheel = %d, extbuttons = %d\n", extwheel, extbuttons);
old_handler = getvect(MOUSE_INTERRUPT_NO);
setvect(MOUSE_INTERRUPT_NO, new_handler);
// enable IRQ 12 at PIC 2
outportb(0x21, inportb(0x21) & ~0x10);
}
int ok = 0;
void interrupt new_handler(...)
{
static unsigned char buf[4] = {0, 0, 0, 0};
int dx, dy, dz;
asm cli
kbd_command_send(KEYB_CTRL, 0xad); // disable keyb
ok = 1;
buf[0] = kbd_command_read();
buf[1] = kbd_command_read();
buf[2] = kbd_command_read();
buf[3] = 0;
if ((extwheel == 0x03) || (extbuttons == 0x04)) {
buf[3] = kbd_command_read();
}
buttons[0] = buf[0] & 1;
buttons[1] = (buf[0] & 2) >> 1;
buttons[2] = (buf[0] & 4) >> 2;
buttons[3] = (buf[3] & 0x10) >> 4;
buttons[4] = (buf[3] & 0x20) >> 5;
dx = (buf[0] & 0x10) ? buf[1] - 256 : buf[1];
dy = (buf[0] & 0x20) ? -(buf[2] - 256) : -buf[2];
dz = (buf[3] & 0x08) ? (buf[3]&7) - 8 : buf[3]&7;
if (dx > 5 || dx < -5)
dx *= 4;
if (dy > 5 || dy < -5)
dy *= 4;
mx += dx;
my += dy;
mz += dz;
if (mx > 80) mx = 80;
if (mx < 1) mx = 1;
if (my > 24) my = 24;
if (my < 1) my = 1;
kbd_command_send(KEYB_CTRL, 0xae); // enable keyb
asm sti
outportb(0xa0, 0x20); // eoi slave
outportb(0x20, 0x20); // eoi master
}
void remove_ps2_driver()
{
//disable IRQ 12 at PIC2
outportb(0x21, inportb(0x21) | 0x10);
setvect(MOUSE_INTERRUPT_NO, old_handler);
kbd_command_send(KEYB_CTRL, 0xd4); // write to aux
kbd_command_send(KEYB_PORT, 0xf5); // disable aux
printf("disable response: 0x%x\n", kbd_command_read());
kbd_command_send(KEYB_CTRL, 0xd4); // write to aux
kbd_command_send(KEYB_PORT, 0xff); // reset mouse
printf("reset response: 0x%x\n", kbd_command_read());
}
void main()
{
clrscr();
install_ps2_driver();
while(!buttons[0]) {
clrscr();
gotoxy(mx, my);
printf("Û");
}
remove_ps2_driver();
}
----------------------------------------------------------------------
RBIL
INT 15 - SYSTEM - POINTING DEVICE BIOS INTERFACE (PS) - ENABLE/DISABLE
AX = C200h
BH = new state
00h disabled
01h enabled
Return: CF set on error
AH = status (see #00522)
Note: IBM classifies this function as required
SeeAlso: AX=C201h,AX=C207h,AX=C208h
(Table 00522)
Values for pointing device function status:
00h successful
01h invalid function
02h invalid input
03h interface error
04h need to resend
05h no device handler installed
--------M-15C201-----------------------------
INT 15 - SYSTEM - POINTING DEVICE BIOS INTERFACE (PS) - RESET
AX = C201h
Return: CF set on error
AH = status (see #00522)
CF clear if successful
BH = device ID
BL = value returned by attached device after reset
AAh if device is a mouse
Notes: after successful completion of this call, the pointing device is set
as follows: disabled, sample rate 100 Hz, resolution 4 counts/mm,
scaling 1:1, unchanged data package size
this function should be called before rebooting the system (see
INT 15/AH=4Fh), since otherwise the mouse may behave erratically on
some systems after the boot. Before calling this function, the
caller should check that the INT 15h vector is in fact initialized
(on some very old machines the IVT may contain 0000h:0000h).
IBM classifies this function as required
SeeAlso: INT 33/AX=0000h,AX=C200h,AX=C207h
--------M-15C202-----------------------------
INT 15 - SYSTEM - POINTING DEVICE BIOS INTERFACE (PS) - SET SAMPLING RATE
AX = C202h
BH = sampling rate
00h 10/second
01h 20/second
02h 40/second
03h 60/second
04h 80/second
05h 100/second
06h 200/second
Return: CF set on error
AH = status (see #00522)
SeeAlso: INT 33/AX=001Ch
--------M-15C203-----------------------------
INT 15 - SYSTEM - POINTING DEVICE BIOS INTERFACE (PS) - SET RESOLUTION
AX = C203h
BH = resolution (see #00523)
Return: CF set on error
AH = status (see #00522)
(Table 00523)
Values for pointing device resolution:
00h one count per mm
01h two counts per mm
02h four counts per mm
03h eight counts per mm
--------M-15C204-----------------------------
INT 15 - SYSTEM - POINTING DEVICE BIOS INTERFACE (PS) - GET TYPE
AX = C204h
Return: CF set on error
AH = status (see #00522)
CF clear if successful
BH = device ID
--------M-15C205-----------------------------
INT 15 - SYSTEM - POINTING DEVICE BIOS INTERFACE (PS) - INITIALIZE
AX = C205h
BH = data package size (1 - 8 bytes)
Return: CF set on error
AH = status (see #00522)
Note: the pointing device is set as follows: disabled, 100 Hz sample rate,
resolution 4 counts/mm, scaling 1:1
SeeAlso: AX=C201h
--------M-15C206-----------------------------
INT 15 - SYSTEM - POINTING DEVICE BIOS INTERFACE (PS) - EXTENDED COMMANDS
AX = C206h
BH = subfunction
00h return device status
Return: BL = pointing device status (see #00524)
CL = resolution (see #00523)
DL = sample rate, reports per second
01h set scaling at 1:1
02h set scaling at 2:1
Return: CF set on error
AH = status (see #00522)
Bitfields for pointing device status:
Bit(s) Description (Table 00524)
0 right button pressed
1 reserved
2 left button pressed
3 reserved
4 0 if 1:1 scaling, 1 if 2:1 scaling
5 device enabled
6 0 if stream mode, 1 if remote mode
7 reserved
--------M-15C207-----------------------------
INT 15 - SYSTEM - POINTING DEVICE BIOS INTERFACE (PS) - SET DEVICE
HANDLER ADDR
AX = C207h
ES:BX -> FAR user device handler or 0000h:0000h to cancel
Return: CF set on error
AH = status (see #00522)
Note: when the subroutine is called, it is passed the following values on
the stack; the handler should return with a FAR return without
popping the stack:
WORD 1: status (see #00525)
WORD 2: X data (high byte = 00h)
WORD 3: Y data (high byte = 00h)
WORD 4: 0000h
SeeAlso: INT 33/AX=000Ch
Bitfields for pointing device status:
Bit(s) Description (Table 00525)
15-8 reserved (0)
7 Y data overflowed
6 X data overflowed
5 Y data is negative
4 X data is negative
3 reserved (1)
2 reserved (0)
1 right button pressed
0 left button pressed
--------M-15C208-----------------------------
INT 15 - SYSTEM - POINTING DEVICE BIOS INTERFACE - WRITE TO POINTER PORT
AX = C208h
BL = byte to be sent to the pointing device
Note: IBM classifies this function as optional
SeeAlso: AX=C200h,AX=C209h
--------M-15C209-----------------------------
INT 15 - SYSTEM - POINTING DEVICE BIOS INTERFACE - READ FROM POINTER PORT
AX = C209h
Return: BL = first byte read from pointing device
CL = second byte read
DL = third byte read
Note: IBM classifies this function as optional
SeeAlso: AX=C200h,AX=C208h
--------------------------------------------------------------------------
If anybody get a propper result please mail me.
Dirk
.
- Follow-Ups:
- Re: ps/2 mouse w/o int33
- From: aanderson@xxxxxxxxxxxxxxxxx
- Re: ps/2 mouse w/o int33
- References:
- ps/2 mouse w/o int33
- From: aanderson@xxxxxxxxxxxxxxxxx
- Re: ps/2 mouse w/o int33
- From: spamtrap
- ps/2 mouse w/o int33
- Prev by Date: Re: ps/2 mouse w/o int33
- Next by Date: Why the setjmp and longjmp I wrote can not work?
- Previous by thread: Re: ps/2 mouse w/o int33
- Next by thread: Re: ps/2 mouse w/o int33
- Index(es):