home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 March
/
VPR9703A.ISO
/
VPR_DATA
/
DOGA
/
SOURCES
/
POLYEDIT.LZH
/
MODEL
/
INPUTPC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-01-17
|
4KB
|
228 lines
#include <stdio.h>
#include <string.h>
#include <dos.h>
#include "input.h"
#include "graph.h"
#include "view.h"
#define TRUE 1
#define FALSE 0
int MouseX = 0, MouseY = 0 ;
int MouseLeft = 0, MouseRight = 0 ;
int MouseMove = FALSE ;
int KeyCode = 0 ;
int ShiftStat = 0 ;
static int Cx, Cy ;
static int Cursor ;
static int KeySense( void );
static int KeyIn( void );
static void MouseON( int, int );
static void MouseOFF( int, int );
void InitInput()
{
union REGS regs ;
Cx = Cy = 0 ;
CursorOFF();
/* mouse */
regs.x.ax = 0x0000 ;
int86( 0x33, ®s, ®s );
regs.x.ax = 0x0007 ;
regs.x.cx = 0 ;
regs.x.dx = Cols * 8 - 1 ;
int86( 0x33, ®s, ®s );
regs.x.ax = 0x0008 ;
regs.x.cx = 0 ;
regs.x.dx = Lines * 16 - 1 ;
int86( 0x33, ®s, ®s );
}
void ExitInput()
{
}
/* コンソール入力 */
static int FuncKeyCode[] = { 0,
0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44,
0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D,
0x51, 0x49, 0x52, 0x53, 0x48, 0x4B, 0x4D, 0x50,
0x00, 0x00, 0x47, 0x00,
0xFF };
void WaitInput()
{
int col, key ;
union REGS regs ;
static int selectcol ;
static int msw ;
MouseON( MouseX, MouseY );
do
{
/* key */
key = KeySense();
/* mouse */
regs.x.ax = 0x0003 ;
int86( 0x33, ®s, ®s );
/* select color */
selectcol = ( selectcol + 1 ) & 0xFFFF ;
col = ( selectcol >> 3 ) & 511 ;
if ( col >= 256 )
col = 511 - col ;
graph_palet( SELECT_COLOR, 255, 255-col, col );
}
while (msw == regs.x.bx && key == 0
&& (regs.x.bx == 0 || (regs.x.cx == MouseX && regs.x.dx == MouseY)));
#if 0
while( msw == 0 && regs.x.bx == 0 && regs.x.cx == MouseX && regs.x.dx == MouseY && key == 0 );
#endif
/* while( regs.x.bx == msw && regs.x.cx == MouseX && regs.x.dx == MouseY && key == 0 );*/
MouseOFF( MouseX, MouseY );
MouseMove = ( regs.x.cx != MouseX ) || ( regs.x.dx != MouseY );
MouseX = regs.x.cx ;
MouseY = regs.x.dx ;
if ( key )
KeyCode = KeyIn();
else
KeyCode = 0 ;
ShiftStat = ShiftSense();
msw = regs.x.bx ;
MouseLeft = regs.x.bx & 1 ;
MouseRight = ( regs.x.bx & 2 ) >> 1 ;
}
void FlushKey()
{
while( KeySense() )
KeyIn();
}
static int ShiftSense()
{
int ret ;
union REGS regs ;
regs.h.ah = 0x02 ;
int86( 0x16, ®s, ®s );
ret = 0 ;
if ( regs.h.al & 0x03 )
ret |= 1 ;
if ( regs.h.al & 0x04 )
ret |= 2 ;
return ret ;
}
static int KeySense()
{
union REGS regs ;
regs.h.ah = 0x01 ;
int86( 0x16, ®s, ®s );
return ( ( regs.x.flags & 0x040 ) == 0 );
}
static int KeyIn()
{
int i ;
union REGS regs ;
regs.h.ah = 0x00 ;
int86( 0x16, ®s, ®s );
if ( regs.h.al == 0 )
{
for( i = 0 ; FuncKeyCode[i] != 0xff ; i++ )
{
if ( FuncKeyCode[i] == regs.h.ah )
return 0x8000 + i ;
}
return 0 ;
}
else
return regs.h.al ;
}
/*
* * *
* * * * *
* * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * *
* * * * * * * *
* * * * * *
* * * * *
* * *
* *
*/
static short MousePattern[16] = {
0xc000, 0xf000, 0x7c00, 0x7f00, 0x3fc0, 0x3ff0, 0x1ffc, 0x1fff,
0x0ffe, 0x0ffc, 0x07f8, 0x07f0, 0x03e0, 0x03c0, 0x0180, 0x0100 };
static void MouseON( x, y )
int x, y ;
{
graph_pattern_xor( x, y, 0x1f, MousePattern, 16, 16 );
}
static void MouseOFF( x, y )
int x, y ;
{
graph_pattern_xor( x, y, 0x1f, MousePattern, 16, 16 );
}
void Locate( x, y )
int x, y ;
{
Cx = x ;
Cy = y ;
if ( Cursor )
{
}
}
void CursorON()
{
Cursor = TRUE ;
Locate( Cx, Cy );
}
void CursorOFF()
{
Cursor = FALSE ;
}
void Bell()
{
bdos( 6, 7, 0 );
}
void GetCursor( xp, yp )
int *xp, *yp ;
{
*xp = Cx ;
*yp = Cy ;
}