⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcdsim.c

📁 最新IAR6.4软集成开发环境及破解文件
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
*********************************************************************************************************
*                                                uC/GUI
*                        Universal graphic software for embedded applications
*
*                       (c) Copyright 2002, Micrium Inc., Weston, FL
*                       (c) Copyright 2002, SEGGER Microcontroller Systeme GmbH
*
*              礐/GUI is protected by international copyright laws. Knowledge of the
*              source code may not be used to write a similar product. This file may
*              only be used in accordance with a license and should not be redistributed
*              in any way. We appreciate your understanding and fairness.
*
----------------------------------------------------------------------
File        : LCDSIM.C
Purpose     : Driver for Simulator under Windows
---------------------------END-OF-HEADER------------------------------
*/

#include <windows.h>
#include <memory.h>
#include <math.h>

#include "LCD.h"
#include "GUI.h"
#include "LCDSIM.h"
#include "LCDSIM_Private.h"
#include "SIM.h"

/*********************************************************************
*
*       Defines
*
**********************************************************************
*/
#define MARK_MODIFIED(LayerIndex)         { if (_apFix[LayerIndex]) (*(int*)(_apFix[LayerIndex] + LCDSIM_OFF_MODIFY_CNT))++; }
#define MARK_LUT_MODIFIED(LayerIndex)     { ++_LUT_ModifyCnt; if (_apFix[LayerIndex]) *(int*)(_apFix[LayerIndex] + LCDSIM_OFF_LUT_MODIFY_CNT) = _LUT_ModifyCnt; }
#define XY2PTR(x,y, LayerIndex)           ((U8*) (_apaaPixel[LayerIndex] + (    x + _aBytesPerLine[LayerIndex] * y)))
#define XY2PTR_DWORD(x,y, LayerIndex)     ((U32*)(_apaaPixel[LayerIndex] + (4 * x + _aBytesPerLine[LayerIndex] * y)))
#define RETURN_IF_NOT_INITIALIZED(rvalue) if (!_aBPP[0]) return rvalue;
#define RECTWIDTH(lpRect)                 ((lpRect)->right - (lpRect)->left +1)
#define RECTHEIGHT(lpRect)                ((lpRect)->bottom - (lpRect)->top +1)

#ifdef WIN32
  #ifndef ASSERT
    #ifdef _DEBUG
      #define ASSERT(Exp) if (!(Exp)) SIM_ErrorOut("LCDSim.c - Assertion failed: " #Exp);
    #else
      #define ASSERT(Exp)
    #endif
  #endif
#endif

#ifdef LCD_ASSERT
  #undef LCD_ASSERT
#endif
#define LCD_ASSERT(v) ASSERT(v)

#ifdef _MSC_VER
  #define INLINE __forceinline
#else
  #define INLINE
#endif

/*********************************************************************
*
*       Global data
*
**********************************************************************
*/
int LCDSIM_aLCDColorWhite[LCDSIM_MAX_DISPLAYS];
int LCDSIM_aLCDColorBlack[LCDSIM_MAX_DISPLAYS];

/*********************************************************************
*
*       Static data
*
**********************************************************************
*/
static GUI_PID_STATE _State;
static U8* _apaaPixel[LCDSIM_MAX_DISPLAYS];      // pointer to pixel data (video memory)
static U8* _apFix[LCDSIM_MAX_DISPLAYS];          // pointer to data area which contains display info

static int         _NumDisplays;
static int         _LUT_ModifyCnt;
static int         _aBytesPerLine[LCDSIM_MAX_DISPLAYS];
static int         _aFixedPalette[LCDSIM_MAX_DISPLAYS];
static int         _aXSize[LCDSIM_MAX_DISPLAYS];
static int         _aYSize[LCDSIM_MAX_DISPLAYS];
static int         _aVXSize[LCDSIM_MAX_DISPLAYS];
static int         _aVYSize[LCDSIM_MAX_DISPLAYS];
static int         _aBPP[LCDSIM_MAX_DISPLAYS];
static int         _aNumColors[LCDSIM_MAX_DISPLAYS];
static BITMAPINFO* _apBitmapInfo[LCDSIM_MAX_DISPLAYS];

/*********************************************************************
*
*       Static code
*
**********************************************************************
*/
/*********************************************************************
*
*       _CheckBreak: Allow break in debug build
*/
#ifdef _DEBUG
static void _CheckBreak(int x, int y, int LayerIndex) {
  static int LayerIndex_Break = -1;
  static int X_Break = -1;
  static int Y_Break = -1;
  static int BreakCnt;
  if (LayerIndex_Break != -1) {
    if (   ((x == X_Break) | (X_Break == -1))
        && ((y == Y_Break) | (Y_Break == -1))
        && (LayerIndex == LayerIndex_Break))
    {
      BreakCnt++;     // Set breakpoint here !!!
    }
  }
}
#endif

/*********************************************************************
*
*         _NotifyMouseState
*
* Informs the application that the mouse state has changed
*/
static void _NotifyMouseState(void) {
  if (_State.Pressed) {
    GUI_TOUCH_StoreState(_State.x, _State.y);
  } else {
    GUI_TOUCH_StoreState(-1, -1);
  }
  GUI_MOUSE_StoreState(&_State);
}

/*********************************************************************
*
*       _ColorRef2Color
*/
INLINE static U32 _ColorRef2Color(COLORREF ColorRef) {
  return (ColorRef & (255 << 8)) | ((ColorRef & 255) << 16) | ((ColorRef & (255 << 16)) >> 16);
}

/*********************************************************************
*
*       _ColorIndex2COLORREF
*/
INLINE static U32 _ColorIndex2COLORREF(int Index16, int LayerIndex) {
  static U32 _Color;
  static int _Index16_Cache = -1;
  if (_Index16_Cache != Index16) {
    _Index16_Cache = Index16;
    _Color = _ColorRef2Color(LCD_Index2ColorEx(Index16, LayerIndex));
  }
  return _Color;
}

/*********************************************************************
*
*         _COLORREF2Index
*/
static U16 _COLORREF2Index(COLORREF ColorRef) {
  U32 Color;
  Color = _ColorRef2Color(ColorRef);
  return LCD_Color2Index(Color);
}

/*********************************************************************
*
*         _Filter1
*/
static int _Filter1(int Color, int Black, int White, int Shift) {
  Color = (Color >> Shift) & 255;
  White = (White >> Shift) & 255;
  Black = (Black >> Shift) & 255;
  return Black + Color * (White - Black) / 255;
}

/*********************************************************************
*
*         _FilterColor
*/
static int _FilterColor(int Color, int Black, int White) {
  int r, g, b;
  r  = _Filter1(Color, Black, White,  0);
  g  = _Filter1(Color, Black, White,  8);
  b  = _Filter1(Color, Black, White, 16);
  return r | (g <<8) | (b << 16);
}

/*********************************************************************
*
*       Exported code
*
**********************************************************************
*/
/*********************************************************************
*
*         LCDSIM_Init()
*
* Purpose:
* Allocate & Initialize the shared memory area and create
* the bitmap used for display and as simulated video memory.
* The bitmap will be 8bpp for index color modes (LUT) with no more than
* 8 bpp, 24 bpp for all other modes.
* 
*/
char* LCDSIM_Init(void) {
  int i, j;
  int NumColors;
  //
  // Get LCD info from driver
  //
  _NumDisplays = LCD_GetNumLayers();
  for (i = 0; i < LCDSIM_MAX_DISPLAYS; i++) {
    if (!LCDSIM_aLCDColorWhite[i]) {
      LCDSIM_aLCDColorWhite[i] = 0xffffff;
    }
  }
  for (i = 0; i < _NumDisplays ; i++) {
    int XSize             = LCD_GetXSizeEx(i) * LCD_GetXMagEx(i);
    int YSize             = LCD_GetYSizeEx(i) * LCD_GetXMagEx(i);
    int BPP               = LCD_GetBitsPerPixel_L0Ex(i);
    int BytesPerLine      = (BPP <= 8) ? (XSize + 3) & ~3 : (4 * XSize + 3) & ~3;
    int VXSize            = LCD_GetVXSizeEx(i);
    int VYSize            = LCD_GetVYSizeEx(i);
    int DeltaMode         = LCD_GetDeltaModeEx(i);
    if (DeltaMode) {
      NumColors = 1 << BPP;
    } else {
      NumColors = LCD_GetNumColorsEx(i);
    }
    //
    // Alloc shared memory
    //
    {
      char ac[80] = "emWinLCDMap";
      int sizeofSMem = 0x400000+4096;  // Use 4MB to be on the safe side ...
            HANDLE hMap;
            U8*    pSMem;
      if (i) {
        int len = strlen(ac);
        ac[len]   = '0' + i;
        ac[len+1] = 0;
      }
            hMap    = CreateFileMapping((HANDLE)0xffffffff, NULL, PAGE_READWRITE, 0, sizeofSMem, ac);
            pSMem   = (U8*)MapViewOfFile(hMap, FILE_MAP_WRITE | FILE_MAP_READ, 0, 0, sizeofSMem);
            if (!pSMem) {
        return "Could not alloc Server data ...";
            }
      _apFix[i]      = pSMem;
      _apaaPixel[i]  = pSMem+4096;
    }
    _aXSize[i]        = XSize;
    _aYSize[i]        = YSize;
    _aVXSize[i]       = VXSize;
    _aVYSize[i]       = VYSize;
    _aBPP[i]          = LCD_GetBitsPerPixel_L0Ex(i);
    _aFixedPalette[i] = LCD_GetFixedPaletteEx(i);
    _aNumColors[i]    = NumColors;
    _aBytesPerLine[i] = BytesPerLine;
    //
    // Init shared memory and static parameter data
    //
    memset(_apFix[i],0, 4096);
    memset(_apaaPixel[i],0, BytesPerLine * YSize);
    strcpy((char*)_apFix[i], "emWin GSC Simulation");
          *(int*)(_apFix[i] + LCDSIM_OFF_XSIZE) = XSize;
          *(int*)(_apFix[i] + LCDSIM_OFF_YSIZE) = YSize;
          *(int*)(_apFix[i] + LCDSIM_OFF_VXSIZE) = VXSize;
          *(int*)(_apFix[i] + LCDSIM_OFF_VYSIZE) = VYSize;
  //    *(int*)(_apFix[i] + LCDSIM_OFF_CONTROLLER) = LCD_CONTROLLER;
          *(int*)(_apFix[i] + LCDSIM_OFF_BPP) = BPP;
          *(int*)(_apFix[i] + LCDSIM_OFF_NUMCOLORS) = NumColors;
          *(int*)(_apFix[i] + LCDSIM_OFF_DELTA_MODE) = DeltaMode;
          _apBitmapInfo[i] = (BITMAPINFO*) (_apFix[i] + 256);
  // Init simulation colors
    if (BPP == LCD_GetBitsPerPixelEx(i)) {
      if (BPP <= 8) {
        for (j = 0; j < NumColors; j++) {
          LCD_COLOR color = LCD_Index2ColorEx(j, i);
          LCDSIM_SetLUTEntry((U8)j, color, i);
        }
      }
    } else {
      for (j = 0; j < NumColors; j++) {
        LCD_COLOR Color = j * 0x111111;
        LCDSIM_SetLUTEntry((U8)j, Color, i);
      }
    }
	  {
		  //
		  // Init BITMAPINFO
		  //
		  BITMAPINFO* pBitmapInfo;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -