home *** CD-ROM | disk | FTP | other *** search
- // Program name.. Zinc Interface Library
- // Filename...... MOUSE.CPP
- // Version....... 1.0
- //
- // COPYRIGHT (C) 1990. All Rights Reserved.
- // Zinc Software Incorporated. Pleasant Grove, Utah USA
-
- #pragma inline
-
- #include <dos.h>
- #include "ui_evt.hpp"
-
- static USHORT _oldMouseMask = 0;
-
- UI_EVENT_MANAGER *_eventManagerPtr = 0;
- UI_EVENT _mouseEvent;
- int _mouseCellWidth;
- int _mouseCellHeight;
- long _mouseTime;
- int _mouseEnabled;
-
- static UCHAR _oldButtonState = 0;
- static int _processing;
-
- struct {
- USHORT offset;
- USHORT segment;
- } _oldMouseISR;
-
- void far MouseISR(void)
- {
- asm cli // Disable interrupts.
- asm push ds
- #if !defined(__HUGE__)
- asm mov ax, DGROUP
- asm mov ds, ax // Get the proper value to DS.
- #endif
-
- asm mov ax, [_processing] // Check for active interrupt.
- asm or ax, ax
- asm jz NotProcessing
- asm sti
- asm jmp EndIsr
-
- NotProcessing:
- asm inc ax
- asm mov [_processing], ax
- asm sti
-
- _mouseEvent.position.column = _CX;
- _mouseEvent.position.line = _DX;
- _BH = _BL;
- asm xor bh, _oldButtonState
- asm mov _oldButtonState, bl
- _mouseEvent.rawCode = (((_BH << 4) | _BL) << 8) | (*((UCHAR far *) 0x417L) & 0xF);
- _mouseEvent.type = E_MOUSE;
- _mouseEvent.position.column /= _mouseCellWidth;
- _mouseEvent.position.line /= _mouseCellHeight;
- if (_mouseEnabled && _eventManagerPtr)
- {
- UI_EVENT event;
- if (_eventManagerPtr->Get(event, Q_END | Q_NO_DESTROY | Q_NO_BLOCK | Q_NO_POLL) != -2 &&
- event.type == E_MOUSE && event.rawCode == _mouseEvent.rawCode)
- _eventManagerPtr->Get(event, Q_END | Q_NO_POLL);
- _eventManagerPtr->Put(_mouseEvent, Q_END);
- }
- _mouseTime = *((long far *)0x46CL);
- if (UI_DEVICE::altPressed != ALT_NOT_PRESSED)
- UI_DEVICE::altPressed = ALT_PRESSED_AND_EVENTS_RECEIVED;
-
- asm xor ax, ax
- asm mov [_processing], ax
-
- EndIsr:
- asm pop ds
- }
-
- static int InstallHandler(void)
- {
- _AX = 0;
- geninterrupt(0x33);
- if (_AX == -1)
- {
- void far *isrPtr;
-
- isrPtr = MouseISR;
- _CX = 0xFF; // Enable all events.
- _DX = FP_OFF(isrPtr);
- _BX = FP_SEG(isrPtr);
- _ES = _BX;
- _AX = 12; // Set Interrupt Subroutine call
- geninterrupt(0x33);
- return TRUE;
- }
- return FALSE;
- }
-
- static void RestoreHandler()
- {
- _CX = _oldMouseMask;
- _DX = _oldMouseISR.offset;
- _BX = _oldMouseISR.segment;
- _ES = _BX;
- _AX = 12;
- geninterrupt(0x33);
- }
-
- UI_MS_MOUSE::UI_MS_MOUSE(USHORT initialState) :
- UI_DEVICE(E_MOUSE, initialState)
- {
- installed = FALSE;
- _mouseEnabled = TRUE;
-
- UCHAR far * far *mouse_vec = (UCHAR far * far *) (4 * 0x33);
- if (*mouse_vec && **mouse_vec != 0xCF)
- {
- _AX = 20;
- _BX = 0;
- _DX = 0;
- _CX = 0;
- geninterrupt(0x33);
- _oldMouseMask = _CX;
- _BX = _ES;
- _oldMouseISR.segment = _BX;
- _oldMouseISR.offset = _DX;
- installed = TRUE;
- }
-
- // Get the mouse pointer.
- for (int i = 0; _pointerTable[i]; i++)
- if (_pointerTable[i]->logicalType == DM_VIEW)
- {
- pointer = _pointerTable[i];
- break;
- }
- }
-
- UI_MS_MOUSE::~UI_MS_MOUSE(void)
- {
- // Uninstall the mouse.
- if (installed)
- RestoreHandler();
- }
-
- int UI_MS_MOUSE::Event(const UI_EVENT &event)
- {
- // Make sure the mouse is installed.
- if (!installed)
- return (0);
-
- if (display->isText)
- {
- _mouseCellWidth = (display->columns == 40) ? 16 : 640 / display->columns;
- _mouseCellHeight = 8;
- }
- else
- {
- _mouseCellWidth = 1;
- _mouseCellHeight = 1;
- }
- USHORT ccode = event.rawCode;
- int t_state = state;
- UI_MOUSE_POINTER *oldPointer = pointer;
-
- // See if the mouse has been initialized.
- if (ccode == D_INITIALIZE)
- {
- installed = InstallHandler();
- if (!installed)
- return (0);
- _eventManagerPtr = eventManager;
- _DX = (display->columns - 1) * _mouseCellWidth;
- _CX = 0;
- _AX = 7;
- geninterrupt(0x33); // Set min. & max. horizontal cursor position.
- _DX = (display->lines - 1) * _mouseCellHeight;
- _CX = 0;
- _AX = 8;
- geninterrupt(0x33); // Set min. & max. horizontal cursor position.
- Display();
- ccode = state;
- t_state = D_OFF;
- }
-
- switch (ccode)
- {
- case D_HIDE:
- _AX = 11;
- geninterrupt(0x33); // See if mouse is moving.
- if (_CX || _DX)
- {
- // Insure the mouse is turned off if it is moving.
- column = event.region.left * _mouseCellWidth;
- line = event.region.top * _mouseCellHeight;
- }
- else
- {
- _AX = 3;
- geninterrupt(0x33); // Get the mouse position.
- column = _CX;
- line = _DX;
- }
- // Continue to D_SHOW.
-
- case D_SHOW:
- UI_REGION region;
- region.left = column;
- region.top = line;
- if (display->isText)
- {
- region.left /= _mouseCellWidth;
- region.top /= _mouseCellHeight;
- region.right = region.left;
- region.bottom = region.top;
- }
- else
- {
- region.left -= pointer->graphicsCursorHorizontal + 8;
- region.top -= pointer->graphicsCursorVertical + 4;
- region.right = region.left + 31;
- region.bottom = region.top + 23;
- }
- if (Max(event.region.left, region.left) > Min(event.region.right, region.right) ||
- Max(event.region.top, region.top) > Min(event.region.bottom, region.bottom))
- return(0);
- state = (ccode == D_SHOW) ? D_ON : D_OFF;
- break;
-
- case D_POSITION:
- _DX = event.position.line;
- _CX = event.position.column;
- _AX = 4;
- geninterrupt(0x33);
- break;
-
- case D_OFF:
- case D_ON:
- _mouseEnabled = enabled = (event.rawCode == D_OFF) ? FALSE : TRUE;
- break;
-
- case D_RESTORE:
- RestoreHandler();
- return (state);
-
- case DM_USER_DEFINED:
- pointer = (UI_MOUSE_POINTER *)event.data; break;
- // Continue to default.
-
- default:
- // Try to find the new match.
- for (int i = 0; _pointerTable[i]; i++)
- if (_pointerTable[i]->logicalType == event.rawCode)
- {
- pointer = _pointerTable[i];
- break;
- }
- break;
- }
-
- // Change the mouse state.
- if (pointer != oldPointer)
- Display();
- if (t_state != state)
- {
- _AX = (state != D_OFF) ? 1 : 2;
- geninterrupt(0x33);
- }
-
- // Return the device state.
- return (state);
- }
-
- void UI_MS_MOUSE::SetSensitivity(int horizontal, int vertical, int doubleSpeed)
- {
- if (installed)
- {
- _BX = horizontal;
- _CX = vertical;
- _DX = doubleSpeed;
- _AX = 26;
- geninterrupt(0x33);
- }
- }
-
- void UI_MS_MOUSE::Display(void)
- {
- if (!display || !pointer)
- return;
- else if (display->isText)
- {
- _DX = pointer->textScreenMask;
- _CX = pointer->textCursorMask;
- _BX = 0; // BX = 0 for software cursor.
- _AX = 10;
- }
- else
- {
- _DX = (USHORT)pointer->graphicsCursorMask;
- _CX = pointer->graphicsCursorVertical;
- _BX = pointer->graphicsCursorHorizontal;
- _ES = _DS;
- _AX = 9; // Set Graphics Cursor call.
- }
- geninterrupt(0x33);
- }
-
- void UI_MS_MOUSE::Poll(void)
- {
- }
-