|
|
DataMuseum.dkPresents historical artifacts from the history of: Regnecentalen RC-900 |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Regnecentalen RC-900 Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T U b
Length: 6953 (0x1b29)
Types: TextFile
Notes: UNIX file
Names: »bmouse.c«
└─⟦0cfe73749⟧ Bits:30004154/config.imd SW95707I VP/ix MS-DOS emulator Rel. 1.1
└─⟦0cfe73749⟧ UNIX Filesystem
└─⟦this⟧ »vc/new/usr/vpix/src/bmouse/bmouse.c«
/* @(#)bmouse.c 3.3 - 88/05/25 */
/*
***************************************************
*
* MODULE: BMOUSE
*
* Copyright (c) 1986, 1987 by Phoenix Technologies Ltd
*
* Emulates the Microsoft(TM) Bus Mouse
*
***************************************************
*/
/*
***************************************************
* INCLUDES AND DEFINES
***************************************************
*/
#include "ptypes.h"
#include "v86error.h"
#include "gdi.h"
typedef struct
{
int dx;
int dy;
int buttons;
int irqnnn;
int irqenb;
int irqset;
int addr;
BYTE portb;
BYTE portc;
PFI oldior;
PFI oldiow;
} BMSE;
#define MOUSE_IRQN 5
#define SIGNAL_NUM 5
#define BASE_ADDR 0x0230 /* lowest port address on mouse card */
#define TICK_RATE 40L /* send irq every 40 msecs */
#define NO_TICK -1L /* don't send irq */
/*
***************************************************
* DATA
***************************************************
*/
LOCAL BMSE _bmse = { -1, 0, 0, 0, 0, 0, 0, 0 };
LOCAL TIMER_HDL _h_tmr;
LOCAL BYTE _bmse_path[128];
LOCAL BYTE mouse_open = FALSE;
/*
***************************************************
* FUNCTIONS
***************************************************
*/
EXTERN VOID gdi_int_set(); /* gdi interface routines */
EXTERN VOID gdi_int_clear();
EXTERN int gdi_close_func();
EXTERN PFI gdi_in_func();
EXTERN PFI gdi_out_func();
EXTERN PFI gdi_int_reg_func();
EXTERN char *gdi_cnf_path();
EXTERN TIMER_HDL gdi_timer_func();
EXTERN int gdi_timer_release();
EXTERN long gdi_timer_interval();
EXTERN int gdi_vterm_func();
EXTERN int bmsemd_init(); /* UNIX driver interface routines */
EXTERN int bmsemd_close();
EXTERN VOID bmsemd_read();
EXTERN int bmsemd_release();
EXTERN int bmsemd_acquire();
GLOBAL VOID init_bmouse(); /* start up */
GLOBAL int close_bmouse(); /* shut down */
GLOBAL long tick_bmouse(); /* periodic interrupt */
GLOBAL int pr_bmouse(); /* port read of a mouse port */
GLOBAL int pw_bmouse(); /* port write of a mouse port */
GLOBAL VOID xy_bmouse(); /* send movement data to mouse */
GLOBAL VOID btn_bmouse(); /* send button data to mouse */
GLOBAL int read_bmouse(); /* pass kernel's signal to bmsemd_read */
LOCAL VOID bmouse_getdata();
LOCAL VOID bmouse_irqenb();
\f
/*
***************************************************
* ENTRY POINTS
***************************************************
*/
/*
* FUNCTION: INIT_BMOUSE
* start up bus mouse
*
* ENTRY PARAMETERS:
* nnn -- IRQ number
* path -- file name for machine dependant init
*
* EXIT PARAMETERS:
* rc -- OK or ERR
*/
GLOBAL VOID init_bmouse( gdi_dev )
struct gdevice *gdi_dev;
{
char *path;
/* check vpix.cnf entry first */
path = gdi_cnf_path( "MOUSE" );
/* only use default path in etc/vpixdevs file if none is
specified in users vpix.cnf file */
if( !path )
path = gdi_dev->gdi_dname;
if( path )
{
strcpy ( _bmse_path, path );
gdi_close_func( close_bmouse );
gdi_vterm_func( bmsemd_release, bmsemd_acquire );
_bmse.oldior = gdi_in_func( BASE_ADDR, pr_bmouse );
_bmse.oldiow = gdi_out_func( BASE_ADDR, pw_bmouse );
gdi_int_reg_func( SIGNAL_NUM, read_bmouse );
_bmse.irqnnn = MOUSE_IRQN;
_bmse.dx = _bmse.dy = 0;
_bmse.buttons = 0xE0;
if( bmsemd_init( path ) != ERR )
{
_h_tmr = gdi_timer_func( tick_bmouse );
mouse_open = TRUE;
}
else
{
mouse_open = FALSE;
}
}
}
/*
* FUNCTION: CLOSE_BMOUSE
* shut down bus mouse
*
* ENTRY PARAMETERS
* none
*
* EXIT PARAMETERS
* rc -- OK or ERR
*/
GLOBAL int close_bmouse()
{
if ( _bmse.irqnnn && _bmse.irqset )
gdi_int_clear( _bmse.irqnnn );
_bmse.irqnnn = -1;
if ( _h_tmr )
{
gdi_timer_release( _h_tmr );
_h_tmr = (TIMER_HDL)0;
}
return( bmsemd_close() );
}
\f
/*
* FUNCTION: TICK_BMOUSE
* send interrupt at an approx. 30Hz rate
*
* ENTRY PARAMETERS
* msecs -- time elapsed since last call
*
* EXIT PARAMETERS
* none
*/
GLOBAL long tick_bmouse( msecs )
long msecs;
{
if ( _bmse.irqnnn != -1 )
{
if ( _bmse.irqset )
{
gdi_int_clear( _bmse.irqnnn );
_bmse.irqset = FALSE;
}
if ( _bmse.irqenb )
{
gdi_int_set( _bmse.irqnnn );
_bmse.irqset = TRUE;
}
}
return( msecs );
}
\f
/*
* FUNCTION: PR_BMOUSE
* read from a bus-mouse I/O port
*
* ENTRY PARAMETERS
* port -- I/O address
* pdata -- pointer to stuff with data read from port
*
* EXIT PARAMETERS
* rc -- OK, or ERR on bad port address
*/
GLOBAL int pr_bmouse( port, pdata )
WORD port;
BYTE *pdata;
{
int rc = OK;
switch ( (port&0xFFF3) - BASE_ADDR )
{
case 0:
bmouse_getdata( pdata );
break;
case 1:
*pdata = _bmse.portb;
break;
case 2:
_bmse.portc ^= 1 << (5-_bmse.irqnnn);
*pdata = _bmse.portc;
break;
case 3:
*pdata = 0xFF;
break;
default:
rc = ( *_bmse.oldior ) ( port, pdata );
break;
}
return( rc );
}
\f
/*
* FUNCTION: PW_BMOUSE
* write to a bus-mouse I/O port
*
* ENTRY PARAMETERS
* port -- I/O address
* pdata -- pointer to data to write to port
*
* EXIT PARAMETERS
* rc -- OK, or ERR on bad port address
*/
GLOBAL int pw_bmouse( port, pdata )
WORD port;
BYTE *pdata;
{
int rc = OK;
int lastenb;
switch ( (port&0xFFF3) - BASE_ADDR )
{
case 0:
break;
case 1:
_bmse.portb = *pdata;
break;
case 2:
_bmse.addr = (*pdata >> 5) & 0x03;
lastenb = _bmse.irqenb;
_bmse.irqenb = !(*pdata & 0x10);
if ( _bmse.irqenb != lastenb )
bmouse_irqenb( _bmse.irqenb ? TICK_RATE : NO_TICK );
if ( !(*pdata & 0x80) )
_bmse.dx = _bmse.dy = 0;
break;
case 3:
if ( !_bmse.irqenb )
bmouse_irqenb( TICK_RATE );
_bmse.irqenb = TRUE;
break;
default:
rc = ( *_bmse.oldior ) ( port, pdata );
break;
}
return( rc );
}
\f
/*
* FUNCTION: XY_BMOUSE
* record mouse movement
*
* ENTRY PARAMETERS
* dx, dy -- signed mouse movement data
*
* EXIT PARAMETERS
* none
*/
GLOBAL VOID xy_bmouse( dx, dy )
int dx, dy;
{
_bmse.dx += dx;
_bmse.dy += dy;
}
\f
/*
* FUNCTION: BTN_BMOUSE
* record mouse button press or release
*
* ENTRY PARAMETERS:
* btn -- 0-2 for left, middle, right button
* state -- TRUE if button pressed, FALSE for released
*
* EXIT PARAMETERS
* none
*/
GLOBAL VOID btn_bmouse( btn, state )
int btn;
int state;
{
btn = 2 - btn;
if ( state )
_bmse.buttons &= ~(0x0020<<btn);
else
_bmse.buttons |= (0x0020<<btn);
}
GLOBAL int read_bmouse()
{
bmsemd_read();
return(0);
}
\f
/*
***************************************************
* LOCAL FUNCTIONS
***************************************************
*/
LOCAL VOID bmouse_getdata( pdata )
BYTE *pdata;
{
int data;
data = (_bmse.addr&2 ? _bmse.dy : _bmse.dx) >> (_bmse.addr&1 ? 5 : 1);
*pdata = (data & 0x0F) | _bmse.buttons;
}
/*
* FUNCTION: BMOUSE_IRQENB
* call to signal that interrupts should start
*
* INPUT PARAMETERS
* none
* OUTPUT PARAMETERS
* none
*/
LOCAL VOID bmouse_irqenb( period )
long period;
{
gdi_timer_interval( _h_tmr, period );
}