home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.update.uu.se
/
ftp.update.uu.se.2014.03.zip
/
ftp.update.uu.se
/
pub
/
rainbow
/
msdos
/
decus
/
RB140
/
grlib03a.arj
/
MSMOUSE.C
< prev
next >
Wrap
Text File
|
1988-12-19
|
11KB
|
320 lines
/***************************************************/
/* MOUSE SUPPORT mouse.c */
/***************************************************/
#include "stdio.h"
#include "mouse.h"
#define MODEM_OFF 0 /*drop dtr/rts*/
#define MODEM_ON 0x0C /*raise dtr/rts*/
extern int _carry; /*dos flag*/
struct Rci_block {
unsigned char rb_function; /*PKT function */
unsigned char rb_func_retc; /*PKT return code*/
unsigned char rb_character; /*PKT character in/out*/
unsigned char rb_char_stat; /*PKT character status*/
unsigned char rb_device; /*RCI device number*/
unsigned int rb_offset, /*RCI offset*/
rb_segment; /*RCI segment*/
};
static char *Mouse_port[] = {
"NUL",
"AUX", /* port = MDM */
"PRN", /* port = PRT */
"AUX2" /* port = AUX */
};
static struct COMM_BLOCK save_config_; /*save current values*/
static CONDITION_PACKET /* action_ conditions*/
action_ = {FALSE,0,0,0,0,0,0},
noaction_ = {FALSE,0,0,0,0,0,0};
/*************************************************/
/* MSOPEN */
/* msopen(device,control_packet,buffer, */
/* buffer_byte_size,mouse_type); */
/* returns TRUE if mouse avail, else FALSE */
/*************************************************/
msopen(device,mptr,bptr,bcnt,mtype)
int device; /*= port number*/
MOUSE_PACKET *mptr; /*= Mouse control block*/
unsigned char *bptr; /*= new circ. buffer for comms*/
int bcnt; /*= size of buffer in bytes*/
int mtype; /*= mouse type */
{ struct COMM_BLOCK config;
int i, temp;
unsigned int getds_(), getcs_();
unsigned char c, *testbyte_();
if (mptr->Mouse_enabled == TRUE)
msclose(mptr);
mptr->Mouse_programmed = mptr->Mouse_enabled = FALSE;
mptr->Mouse_type = mtype;
mptr->Mouse_bstate = mptr->Deltax = mptr->Deltay = 0;
mptr->X_ratio = Mouse_x_speed;
mptr->X_threshold = Mouse_x_threshold;
mptr->Y_ratio = Mouse_y_speed;
mptr->Y_threshold = Mouse_y_threshold;
mptr->Mouse_device = device; /*see if port is there & open I/O*/
strcpy(mptr->Mouse_port_name,Mouse_port[device]);
mptr->Mouse_handle = msdos((0x3D02), 0, 0, mptr->Mouse_port_name);
if (_carry)
return FALSE;
Msioctl_(mptr, 3, &save_config_); /*save what went on before*/
config.cb_character = MODEM_OFF; /*turn off DTR-RTS*/
Msioctl_(mptr, 14, &config); /*drop modem lines & wait*/
for (i=0; i<10000; i++);
Msioctl_(mptr, 5, &config); /*disable rec interrupts*/
config.cb_control = 1; /*mode (data leads)*/
config.cb_stop_bits = 1; /*stop bits*/
config.cb_data_bits = 3; /*7 data bits*/
config.cb_parity_out = 3; /*no parity*/
config.cb_rcv_baud = 9; /*rx 1200 baud*/
config.cb_xmit_baud = 9; /*tx 1200 baud*/
config.cb_xon_char = config.cb_xoff_char = 0; /*XON/XOFF chars*/
config.cb_in_xon = config.cb_out_xon = 2; /*disable XON/XOFF*/
config.cb_buffer_size = bcnt; /*user buffer*/
config.cb_buffer_offset = bptr;
config.cb_buffer_segment = getds_();
if(Msioctl_(mptr, 0, &config) != 0) /*reprogram Mouse port*/
mptr->Mouse_programmed = TRUE;
Msioctl_(mptr, 4, &config); /*enable rec interrupts*/
config.cb_character = MODEM_ON; /*turn on DTR-RTS*/
Msioctl_(mptr, 14, &config); /*raise modem lines & wait*/
for (i=0; i<64; i++);
if( (temp = msack(mptr)) == TRUE);
rci_attach(mptr,&action_,bptr);
return temp;
}
/***********************************************/
/* Mouse close */
/***********************************************/
msclose(mptr)
MOUSE_PACKET *mptr;
{ struct COMM_BLOCK config;
int ret=TRUE;
Msioctl_(mptr, 5, &config); /*disable rec interrupts*/
if (mptr->Mouse_new_vectors == TRUE) /*reset system vectors*/
rci_detach(mptr);
Msioctl_(mptr, 2, &config); /*reset to defaults Buffer*/
Msioctl_(mptr, 1, &config); /*reset to 'NVM'
& enable rec interrupts*/
Msioctl_(mptr, 5, &config); /*disable rec interrupts*/
if(!Msioctl_(mptr, 0, &save_config_)) /*reprogram Mouse port*/ ret=FALSE;
Msioctl_(mptr, 4, &config); /*enable rec interrupts*/
msdos((0x3E<<8), mptr->Mouse_handle, 0, 0); /*close mouse port*/
mptr->Mouse_programmed = mptr->Mouse_enabled = FALSE;
return ret;
}
/***********************************************/
/* see if a Mouse byte wants to come out */
/* of its hole, return if yes, FF if not */
/***********************************************/
unsigned char *testbyte_(mptr)
MOUSE_PACKET *mptr;
{ struct COMM_BLOCK config;
Msioctl_(mptr, 7, &config); /*anyone home?*/
if (config.cb_func_retc == 0xFF)
return config.cb_character & 0x7F;
return 0xFF;
}
/*************************************************/
/* Attach RCI vector to port */
/*************************************************/
rci_attach(mptr,cptr,buff)
MOUSE_PACKET *mptr;
CONDITION_PACKET *cptr;
char *buff;
{ struct Rci_block rci;
unsigned int getcs_(), _chaddr();
rci.rb_offset = _chaddr(mptr,cptr,buff); /*received char int vectors*/
rci.rb_segment= getcs_();
if(Msioctl_(mptr, 17, &rci) != 0) /*set Mouse port int vector*/
mptr->Mouse_new_vectors = TRUE;
}
/*************************************************/
/* Detach RCI vector from port */
/*************************************************/
rci_detach(mptr)
MOUSE_PACKET *mptr;
{ struct Rci_block rci;
Msioctl_(mptr, 18, &rci); /*reset to defaults RX int*/
mptr->Mouse_new_vectors = FALSE;
}
/*************************************************/
/* MSIOCTL -- communicate with O.S. */
/* pass device#, function, and &command buff. */
/*************************************************/
int Msioctl_(mptr, function, ccb)
MOUSE_PACKET *mptr;
unsigned int function;
struct COMM_BLOCK *ccb;
{
ccb->cb_device = mptr->Mouse_device;
ccb->cb_function = function;
msdos((0x44<<8)+2, mptr->Mouse_handle, 0, ccb);
return ccb->cb_func_retc;
}
/**************************************************/
/* return current Data Segment register */
/**************************************************/
unsigned int getds_()
{ struct {unsigned int rcs,rss,rds,res;} rregs;
segread(&rregs);
return rregs.rds;
}
/**************************************************/
/* return current Code Segment register */
/**************************************************/
unsigned int getcs_()
{ struct {unsigned int rcs,rss,rds,res;} rregs;
segread(&rregs);
return rregs.rcs;
}
/*****************************************************/
/* Serial Microsoft Mouse hardware dependent code */
/*****************************************************/
/*-------------------------- Microsoft Mouse 3 byte packet
;
;
; First byte
;
; +----+----+----+----+----+----+----+----+
; | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
; +----+----+----+----+----+----+----+----+
; | | | | | | | |
; | | | | | | | +---- X6 Delta X
; | | | | | | +--------- X7 Delta X
; | | | | | +-------------- Y6 Delta Y
; | | | | +------------------- Y7 Delta Y
; | | | +------------------------ Right Mouse Button
; | | +----------------------------- Left Mouse Button
; | +---------------------------------- 1 = first byte (synchronize)
; +--------------------------------------- 7 bit ascii (MUST MASK)
; Second byte
;
; +----+----+----+----+----+----+----+----+
; | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
; +----+----+----+----+----+----+----+----+
; | | | | | | | |
; | | | | | | | +---- X0 Delta X
; | | | | | | +--------- X1 Delta X
; | | | | | +-------------- X2 Delta X
; | | | | +------------------- X3 Delta X
; | | | +------------------------ X4 Delta X
; | | +----------------------------- X5 Delta X
; | +---------------------------------- 0 = data byte (not first)
; +--------------------------------------- 7 bit ascii (MUST MASK)
; Third byte
;
; +----+----+----+----+----+----+----+----+
; | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
; +----+----+----+----+----+----+----+----+
; | | | | | | | |
; | | | | | | | +---- Y0 Delta Y
; | | | | | | +--------- Y1 Delta Y
; | | | | | +-------------- Y2 Delta Y
; | | | | +------------------- Y3 Delta Y
; | | | +------------------------ Y4 Delta Y
; | | +----------------------------- Y5 Delta Y
; | +---------------------------------- 0 = data byte (not first)
; +--------------------------------------- 7 bit ascii (MUST MASK)
;
*/
/***********************************************/
/* Microsoft Mouse acknowledge check */
/***********************************************/
msack(mptr)
MOUSE_PACKET *mptr;
{
int i;
unsigned char c;
for (i=0; i<64; i++) /*wait for ACK*/
if ( (c = testbyte_(mptr)) == 'M')
return (mptr->Mouse_enabled = TRUE);
return FALSE;
}
/***********************************************/
/* Microsoft Mouse packet decode */
/***********************************************/
CONDITION_PACKET *msdecode(mptr)
MOUSE_PACKET *mptr;
{
action_.Delta_x = action_.Delta_y = 0; /*reset delta return*/
action_.Movement = FALSE; /*reset interrupt conditions*/
if (mptr->Mouse_enabled != TRUE)
return &action_;
switch (mptr->P_button) {
case TRUE: if (action_.P_button_rel) {
action_.P_button_rel--;
mptr->P_button = FALSE;
}
break;
case FALSE: if (action_.P_button_dep) {
action_.P_button_dep--;
mptr->P_button = TRUE;
}
break;
}
switch (mptr->S_button) {
case TRUE: if (action_.S_button_rel) {
action_.S_button_rel--;
mptr->S_button = FALSE;
}
break;
case FALSE: if (action_.S_button_dep) {
action_.S_button_dep--;
mptr->S_button = TRUE;
}
break;
}
if (mptr->Deltax | mptr->Deltay) { /*if movement ... */
action_.Movement = TRUE; /*flag "mouse moved"*/
action_.Delta_x = mptr->Deltax * mptr->X_ratio; /*add in delta_x*/
action_.Delta_y = mptr->Deltay * mptr->Y_ratio; /*add in delta_y*/
mptr->Deltax = mptr->Deltay = 0;
}
return &action_;
}
testbit_(b,mask) /*test bit, ret != 0 if yes*/
unsigned b,mask;
{ return (b &= mask); }