📄 event.c
字号:
EVT.evtq[EVT.oldMove].relative_y += mickeyY; } else { EVT.oldMove = EVT.freeHead; /* Save id of this move event */ addMouseEvent(EVT_MOUSEMOVE,0,x,y,mickeyX,mickeyY,butstate); } _EVT_restoreInt(ps); } if (mask & 0x2A) { ps = _EVT_disableInt(); buttonMask = 0; if (mask & 2) buttonMask |= EVT_LEFTBMASK; if (mask & 8) buttonMask |= EVT_RIGHTBMASK; if (mask & 32) buttonMask |= EVT_MIDDLEBMASK; addMouseEvent(EVT_MOUSEDOWN,buttonMask,x,y,0,0,butstate); EVT.oldMove = -1; _EVT_restoreInt(ps); } if (mask & 0x54) { ps = _EVT_disableInt(); buttonMask = 0; if (mask & 2) buttonMask |= EVT_LEFTBMASK; if (mask & 8) buttonMask |= EVT_RIGHTBMASK; if (mask & 32) buttonMask |= EVT_MIDDLEBMASK; addMouseEvent(EVT_MOUSEUP,buttonMask,x,y,0,0,butstate); EVT.oldMove = -1; _EVT_restoreInt(ps); } EVT.oldKey = -1;}/****************************************************************************REMARKS:Keyboard interrupt handler function.NOTE: Interrupts are OFF when this routine is called by the keyboard ISR, and we leave them OFF the entire time.****************************************************************************/static void EVTAPI keyboardISR(void){ processRawScanCode(PM_inpb(0x60)); PM_outpb(0x20,0x20);}/****************************************************************************REMARKS:Safely abort the event module upon catching a fatal error.****************************************************************************/void _EVT_abort(){ EVT_exit(); PM_fatalError("Unhandled exception!");}/****************************************************************************PARAMETERS:mouseMove - Callback function to call wheneve the mouse needs to be movedREMARKS:Initiliase the event handling module. Here we install our mouse handling ISRto be called whenever any button's are pressed or released. We also buildthe free list of events in the event queue.We use handler number 2 of the mouse libraries interrupt handlers for ourevent handling routines.****************************************************************************/void EVTAPI EVT_init( _EVT_mouseMoveHandler mouseMove){ int i; PM_init(); EVT.mouseMove = mouseMove; _EVT_biosPtr = PM_getBIOSPointer(); EVT_resume(); /* Grab all characters pending in the keyboard buffer and stuff * them into our event buffer. This allows us to pick up any keypresses * while the program is initialising. */ while ((i = _EVT_getKeyCode()) != 0) addKeyEvent(EVT_KEYDOWN,i);}/****************************************************************************REMARKS:Initiailises the internal event handling modules. The EVT_suspend functioncan be called to suspend event handling (such as when shelling out to DOS),and this function can be used to resume it again later.****************************************************************************/void EVTAPI EVT_resume(void){ static int locked = 0; int stat; uchar mods; PM_lockHandle lh; /* Unused in DOS */ if (_EVT_useEvents) { /* Initialise the event queue and enable our interrupt handlers */ initEventQueue();#ifndef NO_KEYBOARD_INTERRUPT PM_setKeyHandler(keyboardISR);#endif#ifndef NO_MOUSE_INTERRUPT if ((haveMouse = detectMouse()) != 0) { int oldmode = _EVT_foolMouse(); PM_setMouseHandler(0xFFFF,mouseISR); _EVT_unfoolMouse(oldmode); }#endif /* Read the keyboard modifier flags from the BIOS to get the * correct initialisation state. The only state we care about is * the correct toggle state flags such as SCROLLLOCK, NUMLOCK and * CAPSLOCK. */ EVT.keyModifiers = 0; mods = PM_getByte(_EVT_biosPtr+0x17); if (mods & 0x10) EVT.keyModifiers |= EVT_SCROLLLOCK; if (mods & 0x20) EVT.keyModifiers |= EVT_NUMLOCK; if (mods & 0x40) EVT.keyModifiers |= EVT_CAPSLOCK; /* Lock all of the code and data used by our protected mode interrupt * handling routines, so that it will continue to work correctly * under real mode. */ if (!locked) { /* It is difficult to ensure that we lock our global data, so we * do this by taking the address of a variable locking all data * 2Kb on either side. This should properly cover the global data * used by the module (the other alternative is to declare the * variables in assembler, in which case we know it will be * correct). */ stat = !PM_lockDataPages(&EVT,sizeof(EVT),&lh); stat |= !PM_lockDataPages(&_EVT_biosPtr,sizeof(_EVT_biosPtr),&lh); stat |= !PM_lockCodePages((__codePtr)_EVT_cCodeStart,(int)_EVT_cCodeEnd-(int)_EVT_cCodeStart,&lh); stat |= !PM_lockCodePages((__codePtr)_EVT_codeStart,(int)_EVT_codeEnd-(int)_EVT_codeStart,&lh); if (stat) { PM_fatalError("Page locking services failed - interrupt handling not safe!"); exit(1); } locked = 1; } /* Catch program termination signals so we can clean up properly */ signal(SIGABRT, _EVT_abort); signal(SIGFPE, _EVT_abort); signal(SIGINT, _EVT_abort); _EVT_installed = true; }}/****************************************************************************REMARKSChanges the range of coordinates returned by the mouse functions to thespecified range of values. This is used when changing between graphicsmodes set the range of mouse coordinates for the new display mode.****************************************************************************/void EVTAPI EVT_setMouseRange( int xRes, int yRes){ RMREGS regs; if (haveMouse) { int oldmode = _EVT_foolMouse(); PM_resetMouseDriver(1); regs.x.ax = 7; /* Mouse function 7 - Set horizontal min and max */ regs.x.cx = 0; regs.x.dx = xRes; PM_int86(0x33,®s,®s); regs.x.ax = 8; /* Mouse function 8 - Set vertical min and max */ regs.x.cx = 0; regs.x.dx = yRes; PM_int86(0x33,®s,®s); _EVT_unfoolMouse(oldmode); }}/****************************************************************************REMARKSModifes the mouse coordinates as necessary if scaling to OS coordinates,and sets the OS mouse cursor position.****************************************************************************/void _EVT_setMousePos( int *x, int *y){ RMREGS regs; if (haveMouse) { int oldmode = _EVT_foolMouse(); regs.x.ax = 4; /* Mouse function 4 - Set mouse position */ regs.x.cx = *x; /* New horizontal coordinate */ regs.x.dx = *y; /* New vertical coordinate */ PM_int86(0x33,®s,®s); _EVT_unfoolMouse(oldmode); }}/****************************************************************************REMARKSSuspends all of our event handling operations. This is also used tode-install the event handling code.****************************************************************************/void EVTAPI EVT_suspend(void){ uchar mods; if (_EVT_installed) { /* Restore the interrupt handlers */ PM_restoreKeyHandler(); if (haveMouse) PM_restoreMouseHandler(); signal(SIGABRT, SIG_DFL); signal(SIGFPE, SIG_DFL); signal(SIGINT, SIG_DFL); /* Set the keyboard modifier flags in the BIOS to our values */ EVT_allowLEDS(true); mods = PM_getByte(_EVT_biosPtr+0x17) & ~0x70; if (EVT.keyModifiers & EVT_SCROLLLOCK) mods |= 0x10; if (EVT.keyModifiers & EVT_NUMLOCK) mods |= 0x20; if (EVT.keyModifiers & EVT_CAPSLOCK) mods |= 0x40; PM_setByte(_EVT_biosPtr+0x17,mods); /* Flag that we are no longer installed */ _EVT_installed = false; }}/****************************************************************************REMARKSExits the event module for program terminatation.****************************************************************************/void EVTAPI EVT_exit(void){ EVT_suspend();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -