📄 udsimnt.c
字号:
/* udsimnt.c - SimNT driver *//* Copyright 2000-2002 Wind River Systems, Inc. All Rights Reserved *//*modification history--------------------01t,24jun03,jlb Update to Tornado 2.201s,17jul02,gav Fix SPR #7267201r,16nov01,msr Fixed SPR #67628: fd not reset to zero.01q,23jul01,msr Fixed problem with UGL_DEVICE_COLOR_32 bitmaps.01p,23may01,msr Fixed SPR #65227 - UGL_COLOR problems01o,23jan01,msr Added mask to protect color index in pixelSet().01n,15dec00,msr Fixed pointer drag problem caused by last checkin.01m,06dec00,msr Fixed to prevent loss of pointer clicks due to full queue.01l,29nov00,msr Fixed SPR #62522 - input drivers now read from pipe.01k,16nov00,msr Added monoBitmapStretchBlt() and transBitmapStretchBlt().01j,16nov00,msr Fixed transBitmapCreateFromDdb().01i,15nov00,msr Fixed SPR #62378.01h,14nov00,msr Added support for middle pointer button.01g,09nov00,msr Fixed colorConvert() and keyboard mapping.01f,23oct00,msr Fixed shift key support.01e,19oct00,msr Fixed arrow keys and other special keys.01d,17oct00,msr Fixed SPR #34966 & #3490801c,13sep00,msr Fixed SPR # 34370 - included <udgenjpg.h>01b,17may00,lcs Replace all windoze routine calls with win_ routine calls & replace all WIN32 structures with WIN_ equivalents01a,15dec99,msr written.*//* DESCRIPTIONThis driver is used with the VxWorks PC simulator to display UGL graphicsin a window on a Microsoft Windows host. It is written straight to the Win32 API.To use this driver, UGL must be compiled with CPU defined as SIMNT. After that,the driver is used just as any other driver. A simulation window appears onthe host when uglModeSet() is called.*//* includes */#include <ugl/ugl.h>#include <ugl/uglmem.h>#include <ugl/uglucode.h>#include <ugl/driver/graphics/simnt/udsimnt.h>#include <ugl/driver/graphics/simnt/ugl_winLib.h>#include <ugl/driver/graphics/generic/udgen.h>#include <ugl/driver/graphics/generic/udgen1.h>#include <ugl/driver/graphics/generic/udgen8.h>#include <ugl/driver/graphics/generic/udgen16.h>#include <ugl/driver/ext/jpeg/udgenjpg.h>#include <string.h>#include <ctype.h>#include <ioLib.h>#include <pipeDrv.h>/* defines */#define UGL_SIMPC_WINDOW_CAPTION "SimPC Driver for WINDML"#define UGL_SIMPC_KBD_RING_BUFFER_SIZE (5 * sizeof (UGL_INPUT_EVENT))#define UGL_SIMPC_PTR_RING_BUFFER_SIZE (20 * sizeof (UGL_INPUT_EVENT))#define UGL_SIMPC_INPUT_POLL_INTERVAL 20/* forward declarations */UGL_LOCAL WIN_LRESULT WIN_CALLBACK uglSimWinProc (WIN_HWND hWnd, WIN_UINT message, WIN_WPARAM wParam, WIN_LPARAM lParam);UGL_UINT32 WINAPI uglSimPcMessageThread (UGL_SIMNT_DRIVER * pSimNtDriver);UGL_LOCAL UGL_STATUS uglSimPcInputDevDestroy (UGL_INPUT_DEVICE * pDevice);UGL_LOCAL UGL_STATUS uglSimPcInputDevFormat (UGL_INPUT_DEVICE * pDevice, UGL_EVENT * pEvent);UGL_LOCAL UGL_STATUS uglSimPcInputDevInfo (UGL_INPUT_DEVICE * pDevice, UGL_DEVICE_REQ request, void * arg);UGL_LOCAL void uglSimPcLinePointGet (const UGL_POINT * p1, const UGL_POINT * p2, int pointNum, UGL_POINT * pN);UGL_STATUS uglSimPcHLine ( UGL_GENERIC_DRIVER *pGenDriver, /* graphics device driver */ int y, /* Y coordinate of line */ int x1, /* X coordinate of line start */ int x2, /* X coordiante of line end */ UGL_COLOR color /* color of line */ );/* globals */UGL_LOCAL WIN_HINSTANCE uglSimPcHInstance; /* Instance of simulator */UGL_LOCAL WIN_HANDLE winThreadId; /* ID of windows thread */UGL_LOCAL WIN_CRITICAL_SECTION criticalSection; /* arbitrate DC usage */UGL_LOCAL int key; /* key for intLock *//* externs */extern int intCnt; /* specifies interrupt level *//* Available Modes */UGL_LOCAL UGL_MODE uglSimPcModeArray [] = { /* Indexed ("pseudo") Color Modes */ {320, 200, 8, 0, UGL_MODE_CRT, UGL_MODE_INDEXED_COLOR }, /* VGA mode 13 */ {320, 240, 8, 0, UGL_MODE_CRT, UGL_MODE_INDEXED_COLOR }, /* VGA Mode "X" */ {640, 480, 8, 0, UGL_MODE_CRT, UGL_MODE_INDEXED_COLOR }, {800, 600, 8, 0, UGL_MODE_CRT, UGL_MODE_INDEXED_COLOR }, {1024, 768, 8, 0, UGL_MODE_CRT, UGL_MODE_INDEXED_COLOR }, {1280, 1024, 8, 0, UGL_MODE_CRT, UGL_MODE_INDEXED_COLOR }, /* Direct ("true") Color Modes */ {320, 240, 16, 0, UGL_MODE_CRT, UGL_MODE_DIRECT_COLOR }, {640, 480, 16, 0, UGL_MODE_CRT, UGL_MODE_DIRECT_COLOR }, {800, 600, 16, 0, UGL_MODE_CRT, UGL_MODE_DIRECT_COLOR }, {1024, 768, 16, 0, UGL_MODE_CRT, UGL_MODE_DIRECT_COLOR }, {1280, 1024, 16, 0, UGL_MODE_CRT, UGL_MODE_DIRECT_COLOR }, };/***************************************************************************** uglSimPcDevCreate - create SimPC graphics device driver**/UGL_UGI_DRIVER * uglSimPcDevCreate ( UGL_ORD instance, /* device instance */ UGL_UINT32 intLevel, /* intLevel */ UGL_UINT32 intVector /* intVector */ ) { UGL_SIMNT_DRIVER * pSimNtDriver; UGL_GENERIC_DRIVER * pGenDriver; UGL_UGI_DRIVER * pDriver = UGL_NULL; WIN_HWND hWndPcSim; /* instances and vectors are not supported */ if (instance != 0 || intLevel != 0 || intVector != 0) return (UGL_NULL); /* get hInstance for windows application */ key = intLock (); hWndPcSim = win_FindWindow ("PCSIM", NULL); /* If hWndPcSim == NULL we may be on VxWorks 5.5 so check with the class for VxWorks 5.5.*/ if (hWndPcSim == NULL) hWndPcSim = win_FindWindow ("SIMPC", NULL); if (hWndPcSim == NULL) { intUnlock (key); return (UGL_NULL); } uglSimPcHInstance = (WIN_HWND)win_GetWindowLong (hWndPcSim, WIN_GWL_HINSTANCE); intUnlock (key); /* Allocate driver structure */ pSimNtDriver = (UGL_SIMNT_DRIVER *)UGL_CALLOC(1, sizeof(UGL_SIMNT_DRIVER)); if (UGL_NULL != pSimNtDriver) { WIN_WNDCLASS wndClass; pGenDriver = &pSimNtDriver->generic; pDriver = &pGenDriver->ugi; /* Register Simulator Window Class */ wndClass.style = WIN_CS_OWNDC; wndClass.lpfnWndProc = uglSimWinProc; wndClass.cbClsExtra = 0; wndClass.cbWndExtra = 0; wndClass.hInstance = 0; key = intLock (); wndClass.hIcon = win_LoadIcon(NULL, WIN_IDI_APPLICATION); wndClass.hCursor = NULL; wndClass.hbrBackground = NULL; wndClass.lpszMenuName = NULL; wndClass.lpszClassName = "UGL Simulator Class"; win_RegisterClass(&wndClass); intUnlock (key); /* Initialize the driver (required by all drivers) */ uglUgiDevInit(pDriver); /* Set UGI Driver API Functions */ pDriver->bitmapBlt = uglSimPcBitmapBlt; pDriver->bitmapCreate = uglSimPcBitmapCreate; pDriver->bitmapDestroy = uglSimPcBitmapDestroy; pDriver->bitmapRead = uglSimPcBitmapRead; pDriver->bitmapWrite = uglSimPcBitmapWrite; pDriver->bitmapStretchBlt = uglSimPcBitmapStretchBlt; pDriver->modeAvailGet = uglSimPcModeAvailGet; pDriver->modeSet = uglSimPcModeSet; pDriver->monoBitmapBlt = uglSimPcMonoBitmapBlt; pDriver->monoBitmapCreate = uglSimPcMonoBitmapCreate; pDriver->monoBitmapDestroy = uglSimPcMonoBitmapDestroy; pDriver->monoBitmapRead = uglSimPcMonoBitmapRead; pDriver->monoBitmapWrite = uglSimPcMonoBitmapWrite; pDriver->monoBitmapStretchBlt = uglSimPcMonoBitmapStretchBlt; pDriver->transBitmapBlt = uglGenericTransBitmapBlt; pDriver->transBitmapCreate = uglGenericTransBitmapCreate; pDriver->transBitmapDestroy = uglGenericTransBitmapDestroy; pDriver->transBitmapRead = uglGenericTransBitmapRead; pDriver->transBitmapWrite = uglGenericTransBitmapWrite; pDriver->transBitmapStretchBlt = uglSimPcTransBitmapStretchBlt; pDriver->transBitmapCreateFromDdb = uglGenericTransBitmapCreateFromDdb; pDriver->cursorBitmapCreate = uglGenericCursorBitmapCreate; pDriver->cursorBitmapDestroy = uglGenericCursorBitmapDestroy; pDriver->cursorInit = uglGenericCursorInit; pDriver->cursorDeinit = uglGenericCursorDeinit; pDriver->cursorHide = uglGenericCursorHide; pDriver->cursorImageGet = uglGenericCursorImageGet; pDriver->cursorImageSet = uglGenericCursorImageSet; pDriver->cursorMove = uglGenericCursorMove; pDriver->cursorPositionGet = uglGenericCursorPositionGet; pDriver->cursorOff = uglGenericCursorOff; pDriver->cursorOn = uglGenericCursorOn; pDriver->cursorShow = uglGenericCursorShow; pDriver->destroy = uglSimPcDevDestroy; pDriver->ellipse = uglSimPcEllipse; pDriver->gcCopy = uglGenericGcCopy; pDriver->gcCreate = uglGenericGcCreate; pDriver->gcDestroy = uglGenericGcDestroy; pDriver->gcSet = uglSimPcGcSet; pDriver->info = uglSimPcInfo; pDriver->line = uglSimPcLine; pDriver->pixelGet = uglSimPcPixelGet; pDriver->pixelSet = uglSimPcPixelSet; pDriver->polygon = uglSimPcPolygon; pDriver->rectangle = uglSimPcRectangle; pDriver->memPoolCreate = uglGenericMemPoolCreate; pDriver->memPoolDestroy = uglGenericMemPoolDestroy; pDriver->pageCreate = uglGenericPageCreate; pDriver->pageDestroy = uglGenericPageDestroy; pDriver->pageCopy = uglGenericPageCopy; pDriver->pageDrawGet = uglGenericPageDrawGet; pDriver->pageDrawSet = uglSimPcPageDrawSet; pDriver->pageVisibleGet = uglGenericPageVisibleGet; pDriver->pageVisibleSet = uglSimPcPageVisibleSet; /* set generic driver functions */ pGenDriver->fill = uglGenericFill; pGenDriver->hLine = uglSimPcHLine; key = intLock (); win_InitializeCriticalSection (&criticalSection); intUnlock (key); /* create/open input pipes */ pSimNtDriver->fdKeyboard = open (SYS_KEYBOARD_NAME, O_WRONLY, 0); if (pSimNtDriver->fdKeyboard == ERROR) { pipeDevCreate (SYS_KEYBOARD_NAME, 50, sizeof (UGL_INPUT_EVENT)); pSimNtDriver->fdKeyboard = open (SYS_KEYBOARD_NAME, O_WRONLY, 0); } pSimNtDriver->fdPointer = open (SYS_POINTER_NAME, O_WRONLY, 0); if (pSimNtDriver->fdPointer == ERROR) { pipeDevCreate (SYS_POINTER_NAME, 50, sizeof (UGL_INPUT_EVENT)); pSimNtDriver->fdPointer = open (SYS_POINTER_NAME, O_WRONLY, 0); } } return (pDriver); }/***************************************************************************** uglSimPcDevDestroy - destroy a SimPC graphics device driver**/UGL_STATUS uglSimPcDevDestroy ( UGL_UGI_DRIVER * pUgiDriver ) { UGL_SIMNT_DRIVER * pDriver = (UGL_SIMNT_DRIVER *)pUgiDriver; if (pUgiDriver->pMode != UGL_NULL) { /* free GDI objects */ key = intLock (); win_DeleteObject (pDriver->hClipRegion); win_DeleteObject (pDriver->hBrush); win_DeleteObject (pDriver->hPen); intUnlock (key); /* free page zero */ UGL_FREE(pUgiDriver->pPageZero->pDdb); UGL_FREE(pUgiDriver->pPageZero); /* free device contexts */ key = intLock (); win_DeleteDC (pDriver->hExtraDc); win_DeleteDC (pDriver->hBltDc); win_DeleteDC (pDriver->hDrawDc); win_ReleaseDC (pDriver->hSimWnd, pDriver->hScreenDc); intUnlock (key); /* Close the simulator window */ key = intLock (); win_PostMessage (pDriver->hSimWnd, WIN_WM_QUIT, 0, 0); win_DestroyWindow (pDriver->hSimWnd); intUnlock (key); } /* destroy clut */ if (pDriver->generic.pClutStruct != UGL_NULL) uglGenericClutDestroy (&pDriver->generic); /* Deinitialize the driver (mandatory) */ uglUgiDevDeinit(pUgiDriver); /* wait for Windows thread to exit */ while (pDriver->threadId) uglOSTaskDelay (50); /* Free the driver */ UGL_FREE(pDriver); return (UGL_STATUS_OK); }/***************************************************************************** uglSimPcModeAvailGet - get available display modes**/UGL_STATUS uglSimPcModeAvailGet ( UGL_UGI_DRIVER * pDriver, UGL_UINT32 * pNumModes, const UGL_MODE ** pModeArray ) { if (pDriver == UGL_NULL) return (UGL_STATUS_ERROR); /* return the mode list */ *pModeArray = uglSimPcModeArray; *pNumModes = sizeof (uglSimPcModeArray) / sizeof (UGL_MODE); return(UGL_STATUS_OK); }/***************************************************************************** uglSimPcModeSet - set display mode**/UGL_STATUS uglSimPcModeSet ( UGL_UGI_DRIVER * pDriver, UGL_MODE * pMode ) { const UGL_MODE * pModeArray; UGL_UINT32 numModes; int i; UGL_SIMNT_DRIVER * pSimNtDriver = (UGL_SIMNT_DRIVER *)pDriver; UGL_GENERIC_DRIVER * pGenDriver = &pSimNtDriver->generic; /* test for valid mode */ (*pDriver->modeAvailGet) (pDriver, &numModes, &pModeArray); for (i = 0; i < numModes; i++) { if (pMode->width == pModeArray[i].width && pMode->height == pModeArray[i].height && pMode->colorDepth == pModeArray[i].colorDepth && pMode->flags == pModeArray[i].flags) { pMode = pDriver->pMode = (UGL_MODE *)&pModeArray[i]; break; } } if (i >= numModes) return (UGL_STATUS_ERROR); /* destroy old clut */ if (pGenDriver->pClutStruct != UGL_NULL) uglGenericClutDestroy (pGenDriver); /* set mode specific driver API functions */ if (pMode->flags & UGL_MODE_DIRECT_COLOR) { pDriver->colorAlloc = uglGenericColorAllocDirect; pDriver->colorFree = UGL_NULL; pDriver->clutSet = UGL_NULL; pDriver->clutGet = UGL_NULL; } else { pDriver->colorAlloc = uglGenericColorAllocIndexed; pDriver->colorFree = uglGenericColorFreeIndexed; pDriver->clutSet = uglGenericClutSet;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -