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

📄 context.c

📁 WinCE 3.0 BSP, 包含Inter SA1110, Intel_815E, Advantech_PCM9574 等
💻 C
字号:
//
// Permedia3 Sample Display Driver
// context.c
//
// Copyright (c) 2000 Microsoft Corporation. All rights reserved.
//
// This code manages the render context for the driver. There is a single
// 2D context that all GDI and DirectDraw operations occur in, and
// multiple 3D contexts created on demand.

#include "pch.h"  // Precompiled header support.
#include "debug.h"
#include "register.h"
#include "struct.h"
#include "proto.h"

// This structure represents a single unit of a context : a register and
// data value pair.

typedef struct t_CONTEXT_VALUE {

  ULONG Register;
  ULONG Data;

} CONTEXT_VALUE;

// This constant array represents the default context that 2D operations occur
// in. 

static const CONTEXT_VALUE l_Default2DContext[] = {

  // FIFO filtering

  { r_FilterMode,                     0x00000000 },
 
  // Alpha Blending

  { r_AlphaBlendAlphaMode,            0x00000000 },
  { r_AlphaBlendColorMode,            0x00000000 },
  { r_AlphaDestColor,                 0xFFFFFFFF },
  { r_AlphaSourceColor,               0xFFFFFFFF },
  { r_AlphaTestMode,                  0x00000000 },

  // Antialiasing

  { r_AntialiasMode,                  0x00000000 },

  // Stipple

  { r_AreaStippleMode,                0x00000000 },
  { r_LineStippleMode,                0x00000000 },

  // Color Gradient

  //{ r_Color,                          0xFFFFFFFF }, // !TODO! Does this register exist?
  { r_ColorDDAMode,                   0x00000000 },
  { r_ConstantColor,                  0xFFFFFFFF },

  // Chroma Keying

  { r_ChromaFailColor,                0x00000000 },
  { r_ChromaPassColor,                0xFFFFFFFF },
  { r_ChromaTestMode,                 0x00000000 },
  { r_ChromaLower,                    0x00000000 },
  { r_ChromaUpper,                    0xFFFFFFFF },

/*
  !TODO! Need to write Delta registers on board with no Delta chips?

    QUEUE_PXRX_DMA_TAG( __DeltaTagDeltaControl,                (1 << 11) );
    { __DeltaTagDeltaMode,                         (1 << 19) },    // [0x260]
    { __DeltaTagXBias,                          P3_LINES_BIAS_P },    // [0x290]
    { __DeltaTagYBias,                          P3_LINES_BIAS_P },    // [0x291]
*/

  // Depth Buffering

  { r_Depth,                          0x00000000 },
  { r_DepthMode,                      0x00000000 },

  // Dithering

  { r_DitherMode,                     0x00000000 },

  // Framebuffer
  // Individual drawing operations will need to enable reads.

  { r_FBSoftwareWriteMask,            0xFFFFFFFF },
  { r_FBSourceData,                   0x00000000 },
  { r_FBWriteBufferOffset0,           0x00000000 },
  { r_FBWriteBufferOffset1,           0x00000000 },
  { r_FBWriteBufferOffset2,           0x00000000 },
  { r_FBWriteBufferOffset3,           0x00000000 },
  { r_FBWriteMode,                    0x00000000 },
  { r_FBHardwareWriteMask,            0xFFFFFFFF },
  { r_FBDestReadMode,                 0x00000000 },
  { r_FBSourceReadMode,               0x00000000 },
  { r_FBDestReadBufferOffset0,        0x00000000 },
  { r_FBDestReadBufferOffset1,        0x00000000 },
  { r_FBDestReadBufferOffset2,        0x00000000 },
  { r_FBDestReadBufferOffset3,        0x00000000 },
  { r_FBDestReadEnables,              0x00000000 },

  // Fog !TODO! Why is fog on in 2D?

  { r_FogColor,                       0xFFFFFFFF },
  { r_FogMode,                        0x00000001 },

  // Graphics ID

  { r_GIDMode,                        0x00000000 },

  // Rasterizer  

  { r_LogicalOpMode,                  0x00000000 },
  { r_RasterizerMode,                 b_RasterizerMode_MirrorBitMask |
                                      (3 << 7) |  // byteswap bitmasks ABCD => DCBA
                                      b_RasterizerMode_YLimitsEnable },
  { r_RenderPatchOffset,              0x00000000 },
  { r_YLimits,                        0x7FFF0000 },
  { r_YUVMode,                        0x00000000 },

  // Global  

  { r_RouterMode,                     0x00000000 },
  { r_SizeOfFramebuffer,              0x00100000 },
  { r_StatisticMode,                  0x00000000 },
  { r_LUTMode,                        0x00000000 },

  // Scissoring

  { r_ScissorMaxXY,                   0x7FFF7FFF },
  { r_ScissorMode,                    0x00000000 },

  // Stencil 

  { r_StencilData,                    0x00FFFFFF },
  { r_StencilMode,                    0x00040000 },  // !TODO! This value is not a meaningfil bit?

  // Localbuffer

  { r_LBDestReadMode,                 0x00000000 },  
  { r_LBSourceReadMode,               0x00000000 },  
  { r_LBWriteMode,                    0x00000000 },

  // Windowing

  { r_Window,                         0x00000000 },    
  { r_WindowOrigin,                   0x00000000 },    

  // Texture mapping

  { r_TextureApplicationMode,         0x00000000 },    
  { r_TextureCompositeAlphaMode0,     0x00008000 },    
  { r_TextureCompositeAlphaMode1,     0x00008000 },    
  { r_TextureCompositeColorMode0,     0x00000000 },    
  { r_TextureCompositeColorMode1,     0x00008000 },    
  { r_TextureCompositeFactor0,        0xFFFFFFFF },    
  { r_TextureCompositeFactor1,        0xFFFFFFFF },    
  { r_TextureCompositeMode,           0x00000000 },    
  { r_TextureCoordMode,               b_TextureCoordMode_Enable |
                                      (1 << 1) |  // WrapS = Repeat
                                      (1 << 3) |  // WrapT = Repeat
                                      (1 << 17) },  // Type == 2D
  { r_TextureEnvColor,                0xFFFFFFFF },
  { r_TextureFilterMode,              0x00000000 },
  { r_TextureIndexMode0,              b_TextureIndexMode0_Enable |
                                      (10 << 1) |  // texture map log2(width) == log2(1024)
                                      (10 << 5) |  // texture map log2(height) == log2(1024)
                                      (1 << 10) |  // WrapU = Repeat
                                      (1 << 12) |  // WrapV = Repeat
                                      (1 << 14) |  // texture map type == 2D
                                      (1 << 21) }, // nearest neighbour bias = 0
  { r_TextureIndexMode1,              0x00200000 },
  { r_TextureReadMode0,               b_TextureReadMode0_Enable |
                                      (7 << 25) |  // byteswap = HGFEDCBA
                                      b_TextureReadMode0_Mirror },
  { r_TextureReadMode1,               0x00000400 },

  // Level of detail

  { r_TextureLODBiasS,                0x00000000 },
  { r_TextureLODBiasT,                0x00000000 },
  { r_LOD,                            0x00000000 },
  { r_LOD1,                           0x00000000 },
  { r_LODRange0,                      0x00C00000 },
  { r_LODRange1,                      0x00C00000 },

  // Q texture coordinate

  { r_QStart,                         0x00000000 },
  { r_dQdx,                           0x00000000 },    
  { r_dQdy,                           0x00000000 },    
  { r_dQdyDom,                        0x00000000 },    

  // S texture coordinate

  { r_SStart,                         0x00000000 },
  { r_dSdx,                           1 << (32 - 10) },
  { r_dSdy,                           0x00000000 },    
  { r_dSdyDom,                        0x00000000 },    

  // T texture coordinate

  { r_TStart,                         0x00000000 },
  { r_dTdx,                           0x00000000 },    
  { r_dTdy,                           0x00000000 },    
  { r_dTdyDom,                        1 << (32 - 10) },

  // Edge scanning parameters

  { r_dXDom,                          0          },    
  { r_dXSub,                          0          },    
  { r_dY,                             (1 << 16)  }
};

// The total number of entries in the l_Default2DContext.

static const ULONG l_NumDefault2DContext = sizeof(l_Default2DContext) / sizeof(l_Default2DContext[0]);

// This is the current context. 0 indicates the 2D context. 0xFFFFFFFF is a
// sentianl indicating that no context has been set yet.

static ULONG l_CurrentContext = 0xFFFFFFFF;

void
Restore2DContext()
{
  // Restore2DContext
  // This function switches the Permedia3's various mode and setup registers
  // to values appropriate for 2D rendering, meaning text, lines, and blits.

  // Local variables.

  ULONG i;

  Enter(L"Restore2DContext");

  if (l_CurrentContext != 0) {

    // Blast the 2D context out to the chip via DMA.

    WaitForDMASpace(l_NumDefault2DContext * 4);

    for (i = 0; i < l_NumDefault2DContext; i++) {

      QueueDMATag(l_Default2DContext[i].Register,
                  l_Default2DContext[i].Data);    
    }

    EndDMA();

    l_CurrentContext = 0;
  }

  Exit(L"Restore2DContext");
}

⌨️ 快捷键说明

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