📄 evnt0.c
字号:
/*************************************************************************/
/* */
/* Copyright (c) 1997 - 1999 Accelerated Technology, Inc. */
/* */
/* PROPRIETARY RIGHTS of Accelerated Technology are involved in the */
/* subject matter of this material. All manufacturing, reproduction, */
/* use, and sales rights pertaining to this subject matter are governed */
/* by the license agreement. The recipient of this software implicitly */
/* accepts the terms of the license. */
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* FILE NAME VERSION */
/* */
/* EVNT0.c 1.9 */
/* */
/* COMPONENT */
/* */
/* All */
/* */
/* DESCRIPTION */
/* */
/* This file contains the EventQueue, StopEvent, KeyEvent, */
/* PeekEvent, MaskEvent, StoreEvent, makeUsrEvent & makeNullEvent */
/* functions. */
/* */
/* AUTHOR */
/* */
/* Robert G. Burrill, Accelerated Technology, Inc. */
/* */
/* DATA STRUCTURES */
/* */
/* None */
/* */
/* FUNCTIONS */
/* */
/* None */
/* */
/* DEPENDENCIES */
/* */
/* None */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* BobB 10/22/98 Added mwStoreEvent */
/* */
/*************************************************************************/
#include "meta_wnd.h"
#include "metconst.h" /* MetaWINDOW Constant & Stucture Definitions */
#include "metports.h" /* MetaWINDOW Port & Bitmap Definitions */
#include "grafdata.h"
#include "wndo.h"
#include "metmacs3.h"
#define kbOldVect 0 /* old key ISR save vector */
#define kbOldSeg 4 /* old key ISR save seg (386) */
#define kbOldxVect 6 /* old key ISR alt (real mode) save vector */
#define kbTmp 10 /* temp storage */
#define KBDVEC 0x09 /* Hardware int */
#define BIOSTIME 0x046C /* offset for bios timer tic */
void makeUsrEvent(long evntPntr, event *usrEvnt);
void makeNullEvent(event *nullEvent);
void StopEvent(void);
int mwStoreEvent(event *argEV);
void nuSegInfo(void);
void mwInputCB(void);
void KBDriverISR(void);
void GrafFree(void *);
point *GrafAlloc(int);
/* Function EventQueue enables (/initializes) and disables event buffer
processing. TF indicates if the event queue is to be Enabled (TF=true=1)
or Disabled (TF=false=0).
The event queue looks like this:
HEAD = next location to store.
TAIL = last location retrieved
(Tail+1 next valid entry).
_______ _______ _______
| | | | | |
| | | | | |
| | | | | |
| | |_______| |_______|
|_______| Head--> |_______| |_______|
Tail-->|_______| Tail--> |_______| Head--> |_______| <--Tail
Head-->|_______| |_______| |_______|
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
|_______| |_______| |_______|
if Tail+1=Head then Next to if Head=Tail then
Buffer-Empty Buffer-Full Buffer-Full */
void EventQueue(int argTF)
{
int queueSize;
int eventSize;
long mallocRtn;
short grafErrValue; /* error value */
long memPntr;
if (argTF) /* Enable(1) or Disable(0)? */
{ /* enable */
stpEventIDV = StopEvent;/* Smart link StopEvent vector */
if (!(gFlags & gfEvtInit)) /* Event-Queue initialized? */
{ /* no, initialize Event-Queue data area */
eventSize = sizeof(event);
queueSize = (int) (q_Size * eventSize);
mallocRtn = (long) GrafAlloc(queueSize);
if (mallocRtn == 0) /* check for null pointer returned */
{
grafErrValue = c_EventQue + c_OutofMem;
nuGrafErr(grafErrValue); /* report error */
return;
}
q_Start = mallocRtn; /* Initialize queue pointers */
q_Tail = mallocRtn;
q_Head = mallocRtn + eventSize;
q_End = mallocRtn + queueSize;
QueueIDV = (long) mwStoreEvent; /* install indirect vector for
posting inputs */
/* get original keyboard handler vectors and save 'em */
CallmwGetVect(KBDVEC, &defKBrd.mrUsr[kbOldVect],
&defKBrd.mrUsr[kbOldSeg], &defKBrd.mrUsr[kbOldxVect]);
/* set default event mask to key up and key down */
defKBrd.mrEventMask = mKEYUP + mKEYDN;
#if CPU386 /* lock memory used by Event ISR */
memPntr = (long) (q_Start); /* lock the queue itself */
CallmwLockMem(memPntr, queueSize);
memPntr = (long) &ISR_STACK; /* lock grafdata */
CallmwLockMem(memPntr, 12000);
memPntr = (long) mwStoreEvent; /* lock ISR and related code */
CallmwLockMem(memPntr, 1000);
memPntr = (long) nuSegInfo;
CallmwLockMem(memPntr, 50);
memPntr = (long) mwInputCB;
CallmwLockMem(memPntr, 100);
#endif
gFlags |= gfEvtInit; /* Flag event queue inited */
}
/* enable event system keyboard ISR */
if (gFlags & gfEvtEnab) return; /* exit if already enabled */
makeNullEvent(&defKBrd.mrEvent); /* init the keyboard state flags in
the key event record */
defKBrd.mrEvent.evntSource = cKEYBOARD;
if (argTF != cUSER) /* if argument = cUSER, then don't install ISR */
{
defKBrd.mrUsr[kbTmp] = 0; /* zero flags */
CallmwSetVect(KBDVEC, (long) KBDriverISR); /* set the keyboard hw int
vector to our routine */
}
gFlags |= gfEvtEnab; /* Flag event queue enabled */
}
else
{ /* Disable queue */
if (gFlags & gfEvtEnab) /* already disabled? */
{ /* no */
gFlags &= ~gfEvtEnab; /* Flag event queue as disabled */
/* restore keyboard ISR */
CallmwRestVect(KBDVEC, &defKBrd.mrUsr[kbOldVect],
&defKBrd.mrUsr[kbOldSeg], &defKBrd.mrUsr[kbOldxVect]);
}
}
return;
}
/* Function StopEvent terminates Event-Queue processing. */
void StopEvent(void)
{
EventQueue(0); /* disable queue */
if (gFlags & gfEvtInit) /* was ever inited? */
{ /* yes */
gFlags &= ~gfEvtInit; /* clear flags */
GrafFree(&q_Start); /* free queue buffer */
}
return;
}
/* Function KeyEvent determines if an event has occured, and returns
the event via the passed pointer if one is available.
If parameter argW is set to TRUE (<>0), KeyEvent will suspend program
execution and wait for an event if one is not immediately available.
If argW is FALSE (=0), KeyEvent will return immediately with a FALSE
status if no events are queued. If an event is available, it is copied
into the event record pointed to by argE, and removed from the queue.
KeyEvent returns a TRUE status when an event is returned. */
int KeyEvent(int argW, event *argE)
{
long eventSize;
long eventPntr;
eventSize = sizeof(event);
do
{
eventPntr = q_Tail + eventSize; /* Increment to next entry location. */
if (eventPntr >= q_End) eventPntr = q_Start; /* reset to begiing
of buffer if at end */
if (eventPntr != q_Head) /* is Buffer-Empty? */
{ /* no, process entry */
makeUsrEvent(eventPntr, argE); /* return event from the queue
to user buffer */
q_Tail = eventPntr; /* remove event */
return(1);
}
} while (argW != 0); /* WAIT for input? */
makeNullEvent(argE); /* No, build a non event */
return(0);
}
/* Function PeekEvent is used to examine events in the event queue, without
removing them from the queue. argNDX is the queue element event to examine
(argNDX=1 is the first queued event). To examine the entire queue, first call
PEEKEVENT with a queue index of 1. If an event is returned (PEEKEVENT is
TRUE), call it again with an argNDX of 2, etc. */
int PeekEvent(int argNDX, event *argEVN)
{
int eventSize;
long eventPntr;
int i;
eventSize = sizeof(event);
eventPntr = q_Tail; /* position to indexed element */
for (i = argNDX; i > 0; i--)
{
eventPntr += eventSize;
if (eventPntr >= q_End) eventPntr = q_Start; /* reset to beginning
of buffer if at end */
if (eventPntr == q_Head) /* is Buffer-Empty? */
{ /* yes, build null event */
makeNullEvent(argEVN);
return(0);
}
}
makeUsrEvent(eventPntr, argEVN); /* return event from the queue
to user buffer */
return(1);
}
/* Function MaskEvent sets the specified mask as the system wide event mask.
Only event types with their coresponding mask bit one will be posted
to the event queue. */
void MaskEvent(short argMASK)
{
eventMask = argMASK;
return;
}
/* Function StoreEvent stores the specified event in the input event queue.
If there is no more room in the event buffer StoreEvent returns with a
FALSE status, otherwise when the event is sucessfully stored a TRUE status
is returned. */
int StoreEvent(event *argEV)
{
if (argEV->evntType & eventMask) return(mwStoreEvent(argEV));
return(0);
}
/* Function mwStoreEvent is an internal routine that stores the event to
the next element in the event queue. It returns true if able to store
the event, else it returns false.
This function must be called with ints disabled */
int mwStoreEvent(event *argEV)
{
event *q_Pntr;
if (q_Head == q_Tail) return(0); /* Buffer full if return */
argEV->evntTime = 0; /* Set event time to 0 since no clock */
q_Pntr = (event *)q_Head;
*q_Pntr++ = *argEV; /* Copy event to queue */
q_Head = (long) q_Pntr;
if (q_Head >= q_End) q_Head = q_Start; /* Reset to beginning of buffer */
return(1);
}
/* Function makeUsrEvent is a local proc to copy over a user event.
User events have the X,Y converted to the current coordinate system */
void makeUsrEvent(long evntPntr, event *usrEvnt)
{
short tempX;
short tempY;
event *tempPntr;
tempPntr = (event*) evntPntr;
*usrEvnt = *tempPntr; /* copy event */
if (globalLevel > 0)
{ /* convert from global to user */
tempX = usrEvnt->evntX;
tempY = usrEvnt->evntY;
G2UP(tempX, tempY, &usrEvnt->evntX, &usrEvnt->evntY);
}
return;
}
/* Function makeNullEvent makes a null event at nullEvent.
Null events have the time, the keyboard state and the X,Y
and buttons from the current input device. */
void makeNullEvent(event *nullEvent)
{
short eventX;
short eventY;
short *timePtr;
/* get the 'state' from the keyboard input device */
nullEvent->evntState = defKBrd.mrEvent.evntState;
/* null out everything else */
nullEvent->evntType = 0;
nullEvent->evntSource = 0;
nullEvent->evntChar = 0;
nullEvent->evntScan = 0;
nullEvent->evntButtons = 0;
/* force the time to zero for now */
timePtr = (short *) BIOSTIME;
nullEvent->evntTime = *timePtr;
/* current input x,y and buttons */
nullEvent->evntButtons = curInput->mrEvent.evntButtons;
eventX = curInput->mrEvent.evntX;
eventY = curInput->mrEvent.evntY;
if (globalLevel > 0)
{
G2UP(eventX, eventY, &eventX, &eventY);
}
nullEvent->evntX = eventX;
nullEvent->evntY = eventY;
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -