Subversion Repositories spacemission

Rev

Rev 1 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. unit DXRender;
  2.  
  3. interface
  4.  
  5. {$INCLUDE DelphiXcfg.inc}
  6.  
  7. uses
  8.   Windows,
  9. {$IfDef StandardDX}
  10.   DirectDraw,
  11.   {$ifdef DX7}
  12.   Direct3D;
  13.   {$endif}
  14.   {$IfDef DX9}
  15.   Direct3D9, Direct3D, D3DX9, {Direct3D8,} DX7toDX8;
  16.   {$EndIf}
  17. {$Else}
  18.   DirectX;
  19. {$EndIf}
  20.  
  21. const
  22.   DXR_MAXTEXTURE = 4;
  23.  
  24. type
  25.   TDXR_Value = Double;
  26.  
  27.   TDXR_Color = DWORD;
  28.   TDXR_SurfaceColor = DWORD;
  29.  
  30.   {  TDXR_Option  }
  31.  
  32.   PDXR_Option = ^TDXR_Option;
  33.   TDXR_Option = (
  34.     DXR_OPTION_VERSION,
  35.     DXR_OPTION_MMXENABLE,
  36.     DXR_OPTION_RENDERPRIMITIVES
  37.   );                            
  38.  
  39.   {  TDXR_ShadeMode  }
  40.  
  41.   TDXR_ShadeMode = (
  42.     DXR_SHADEMODE_FLAT,
  43.     DXR_SHADEMODE_GOURAUD
  44.   );
  45.  
  46.   {  TDXR_Blend  }
  47.  
  48.   TDXR_Blend = (
  49.     // for blending
  50.     DXR_BLEND_ZERO,                        // r=0
  51.     DXR_BLEND_ONE1,                        // r=c1
  52.     DXR_BLEND_ONE2,                        // r=c2
  53.     DXR_BLEND_ONE1_ADD_ONE2,               // r=c1+c2
  54.     DXR_BLEND_ONE1_SUB_ONE2,               // r=c1-c2
  55.     DXR_BLEND_ONE2_SUB_ONE1,               // r=c2-c1
  56.     DXR_BLEND_ONE1_MUL_ONE2,               // r=c1*c2
  57.     DXR_BLEND_SRCALPHA1,                   // r=c1*a1
  58.     DXR_BLEND_SRCALPHA1_ADD_ONE2,          // r=c1*a1+c2
  59.     DXR_BLEND_ONE2_SUB_SRCALPHA1,          // r=c2-c1*a1
  60.     DXR_BLEND_SRCALPHA1_ADD_INVSRCALPHA2,  // r=c1*a1+c2*(1-a2)
  61.     DXR_BLEND_INVSRCALPHA1_ADD_SRCALPHA2,  // r=c1*(1-a1)+c2*a2
  62.     // for lighting
  63.     DXR_BLEND_DECAL,                       // r=c1
  64.     DXR_BLEND_DECALALPHA,                  // r=c1    ra=a2
  65.     DXR_BLEND_MODULATE,                    // r=c1*c2 ra=a2
  66.     DXR_BLEND_MODULATEALPHA,               // r=c1*c2
  67.     DXR_BLEND_ADD                          // r=c1+c2 ra=a2
  68.   );
  69.  
  70.   {  TDXR_TextureFilter  }
  71.  
  72.   TDXR_TextureFilter = (
  73.     DXR_TEXTUREFILTER_NEAREST,
  74.     DXR_TEXTUREFILTER_LINEAR,
  75.     DXR_TEXTUREFILTER_MIPMAP_NEAREST,
  76.     DXR_TEXTUREFILTER_MIPMAP_LINEAR
  77.   );
  78.  
  79.   {  TDXR_TextureAddress  }
  80.  
  81.   TDXR_TextureAddress = (
  82.     DXR_TEXTUREADDRESS_TILE,           // tx=tx and WidthMask ty=ty and HeightMask
  83.     DXR_TEXTUREADDRESS_DONOTCLIP       // tx=tx               ty=ty
  84.   );
  85.  
  86.   {  TDXR_CmpFunc  }
  87.  
  88.   TDXR_CmpFunc = (
  89.     DXR_CMPFUNC_NEVER,
  90.     DXR_CMPFUNC_LESS,
  91.     DXR_CMPFUNC_EQUAL,
  92.     DXR_CMPFUNC_LESSEQUAL,
  93.     DXR_CMPFUNC_GREATER,
  94.     DXR_CMPFUNC_NOTEQUAL,
  95.     DXR_CMPFUNC_GREATEREQUAL,
  96.     DXR_CMPFUNC_ALWAYS
  97.   );
  98.  
  99.   {  TDXR_ColorType  }
  100.  
  101.   TDXR_ColorType = (
  102.     DXR_COLORTYPE_INDEXED,     // Palette indexed color
  103.     DXR_COLORTYPE_RGB          // RGB color
  104.   );
  105.  
  106.   {  TDXR_ColorChannel  }
  107.  
  108.   TDXR_ColorChannel = record
  109.     Mask: DWORD;                // Bit Mask
  110.     BitCount: DWORD;            // Number of bit
  111.     rshift: DWORD;
  112.     lshift: DWORD;
  113.   end;
  114.  
  115.   {  TDXR_Surface  }
  116.  
  117.   PDXR_Surface = ^TDXR_Surface;
  118.   TDXR_Surface = record
  119.     ColorType: TDXR_ColorType;   // Color type
  120.     Width, Height: DWORD;        // Size of surface
  121.     WidthBit, HeightBit: DWORD;  // Size of surface (Number of bit)
  122.     Width2, Height2: DWORD;      // 1 shl WidthBit, 1 shl HeightBit
  123.     WidthMask, HeightMask: DWORD;// Bit Mask of size of surface
  124.     BitCount: DWORD;             // BitCount per Pixel(1, 2, 4, 8, 16, 24, 32 only)
  125.     Bits: Pointer;               // Pointer to pixeldata(x:0 y:0)
  126.     Pitch: Integer;              // Offset of next scanline
  127.     PitchBit: Integer;           // Offset of next scanline (Number of bit)
  128.     MipmapChain: PDXR_Surface;
  129.     case Integer of
  130.       0: (
  131.         { Indexed color }
  132.         idx_index: TDXR_ColorChannel;  // Index channel
  133.         idx_alpha: TDXR_ColorChannel;  // Alpha channel
  134.         idx_palette: array[0..255] of TPaletteEntry;
  135.                                        // Palette
  136.       );
  137.       1: (
  138.         { RGB color }
  139.         rgb_red: TDXR_ColorChannel;    // Red channel
  140.         rgb_green: TDXR_ColorChannel;  // Green channel
  141.         rgb_blue: TDXR_ColorChannel;   // Blue channel
  142.         rgb_alpha: TDXR_ColorChannel;  // Alpha channel
  143.       );
  144.   end;
  145.  
  146.   {  TDXR_Vertex  }
  147.  
  148.   PDXR_Vertex = ^TDXR_Vertex;
  149.   TDXR_Vertex = record
  150.     sx: TDXR_Value;            // Screen coordinates
  151.     sy: TDXR_Value;
  152.     sz: TDXR_Value;
  153.     rhw: TDXR_Value;           // 1/sz
  154.     color: TDXR_Color;
  155.     specular: TDXR_Color;
  156.     tu, tv: array[0..DXR_MAXTEXTURE-1] of TDXR_Value;
  157.   end;
  158.  
  159.   PPDXR_Vertex = ^PDXR_Vertex;
  160.  
  161.   {  TDXR_PrimitiveType  }
  162.  
  163.   TDXR_PrimitiveType = (
  164.     DXR_PRIMITIVETYPE_TRIANGLELIST,
  165.     DXR_PRIMITIVETYPE_TRIANGLESTRIP
  166.   );
  167.  
  168.   {  TDXR_TextureLayerBlend  }
  169.  
  170.   TDXR_TextureLayerBlend = (
  171.     DXR_TEXTURELAYERBLEND_TEXTURE,
  172.     DXR_TEXTURELAYERBLEND_LAST,
  173.     DXR_TEXTURELAYERBLEND_NOBLEND
  174.   );
  175.  
  176.   {  TDXR_TextureLayer  }
  177.  
  178.   PDXR_TextureLayer = ^TDXR_TextureLayer;
  179.   TDXR_TextureLayer = record
  180.     Surface: PDXR_Surface;
  181.     LayerBlend: TDXR_TextureLayerBlend;
  182.     Blend: TDXR_Blend;
  183.     ColorKeyEnable: Boolean;
  184.     ColorKey: TDXR_SurfaceColor;
  185.     TextureAddress: TDXR_TextureAddress;
  186.     BumpTexture: Integer;
  187.   end;
  188.  
  189.   {  TDXR_Cull  }
  190.  
  191.   TDXR_Cull = (
  192.     DXR_CULL_NONE,
  193.     DXR_CULL_CW,
  194.     DXR_CULL_CCW
  195.   );
  196.  
  197.   {  TDXR_RenderStates  }
  198.  
  199.   TDXR_RenderStates = record
  200.     DitherEnable: Boolean;
  201.     SpecularEnable: Boolean;
  202.     CullMode: TDXR_Cull;
  203.     Shade: TDXR_ShadeMode;
  204.     TexBlend: TDXR_Blend;
  205.     Blend: TDXR_Blend;
  206.     TextureEnable: Boolean;
  207.     TextureList: array[0..DXR_MAXTEXTURE-1] of TDXR_TextureLayer;
  208.     TextureFilter: TDXR_TextureFilter;
  209.     ZBuffer: PDXR_Surface;
  210.     ZFunc: TDXR_CmpFunc;
  211.     ZWriteEnable: Boolean;
  212.     EnableDrawLine: Integer;
  213.   end;
  214.  
  215. function dxrGetOption(Option: TDXR_Option): DWORD;
  216. procedure dxrSetOption(Option: TDXR_Option; Value: DWORD);
  217.  
  218. procedure dxrMakeIndexedSurface(var Surface: TDXR_Surface; Width, Height, BitCount: DWORD;
  219.   Bits: Pointer; pitch: Integer; idx_index, idx_alpha: DWORD);
  220. procedure dxrMakeRGBSurface(var Surface: TDXR_Surface; Width, Height, BitCount: DWORD;
  221.   Bits: Pointer; pitch: Integer; rgb_red, rgb_green, rgb_blue, rgb_alpha: DWORD);
  222. function dxrScanLine(const Surface: TDXR_Surface; y: DWORD): Pointer;
  223. procedure dxrZBufferClear(const Surface: TDXR_Surface);
  224.  
  225. function dxrDDSurfaceLock(DDSurface: {$IFDEF D3D_deprecated}IDirectDrawSurface{$ELSE}IDirectDrawSurface7{$ENDIF}; var Surface: TDXR_Surface): Boolean; {$IFDEF VER9UP}inline;{$ENDIF}
  226. function dxrDDSurfaceLock2(DDSurface: {$IFDEF D3D_deprecated}IDirectDrawSurface{$ELSE}IDirectDrawSurface7{$ENDIF}; var ddsd: {$IFDEF D3D_deprecated}TDDSurfaceDesc{$ELSE}TDDSurfaceDesc2{$ENDIF};
  227.   var Surface: TDXR_Surface): Boolean; {$IFDEF VER9UP}inline;{$ENDIF}
  228. procedure dxrDDSurfaceUnLock(DDSurface: {$IFDEF D3D_deprecated}IDirectDrawSurface{$ELSE}IDirectDrawSurface7{$ENDIF}; const Surface: TDXR_Surface); {$IFDEF VER9UP}inline;{$ENDIF}
  229.  
  230. procedure dxrDefRenderStates(var States: TDXR_RenderStates);
  231.  
  232. procedure dxrDrawPrimitive(const Dest: TDXR_Surface; const States: TDXR_RenderStates; PrimitiveType: TDXR_PrimitiveType;
  233.   VertexList: PDXR_Vertex; VertexCount: DWORD);
  234. procedure dxrDrawPointeredPrimitive(const Dest: TDXR_Surface; const States: TDXR_RenderStates; PrimitiveType: TDXR_PrimitiveType;
  235.   VertexList: PPDXR_Vertex; VertexCount: DWORD);
  236. procedure dxrDrawIndexedPrimitive(const Dest: TDXR_Surface; const States: TDXR_RenderStates; PrimitiveType: TDXR_PrimitiveType;
  237.   VertexList: PDXR_Vertex; VertexCount: DWORD; IndexList: PDWORD; IndexCount: DWORD);
  238.  
  239. procedure dxrCopyRectBlend(const Dest, Src: TDXR_Surface;
  240.   const DestRect, SrcRect: TRect; Blend: TDXR_Blend; Alpha: Integer;
  241.   ColorKeyEnable: Boolean; ColorKey: DWORD);
  242.  
  243. procedure dxrFillRectColorBlend(const Dest: TDXR_Surface;
  244.   const DestRect: TRect; Blend: TDXR_Blend; Col: COLORREF);
  245.  
  246. procedure dxrDrawWaveXBlend(const Dest, Src: TDXR_Surface;
  247.   X, Y, Width, Height: Integer; const SrcRect: TRect; amp, Len, ph: Integer;
  248.   Blend: TDXR_Blend; Alpha: Integer;
  249.   ColorKeyEnable: Boolean; ColorKey: DWORD);
  250.  
  251. procedure dxrDrawRotateBlend(const Dest, Src: TDXR_Surface;
  252.   X, Y, Width, Height: Integer; const SrcRect: TRect; CenterX, CenterY: Double;
  253.   Angle: Integer; Blend: TDXR_Blend; Alpha: Integer;
  254.   ColorKeyEnable: Boolean; ColorKey: DWORD);
  255.  
  256. implementation
  257.  
  258. const
  259.   TextureAxisFloatBit = 16;
  260.   TextureAxisFloat = 1 shl TextureAxisFloatBit;
  261.  
  262.   ColorFloatBit = 8;
  263.   ColorFloat = 1 shl ColorFloatBit;
  264.                
  265. type
  266.  
  267.   PInteger = ^Integer;
  268.  
  269.   {  TDXRMachine  }
  270.  
  271.   TDXRMachine_TreeType = (
  272.     DXR_TREETYPE_LOADBLACK,      // Load black color
  273.     DXR_TREETYPE_LOADCOLOR,      // Load vertex color
  274.     DXR_TREETYPE_LOADCONSTCOLOR, // Load constant color
  275.     DXR_TREETYPE_LOADTEXTURE,    // Load texel
  276.     DXR_TREETYPE_LOADBUMPTEXTURE,// Load texel with Bump mapping
  277.                                  //   dx := nx + (BumpTexture[nx-1, ny]-BumpTexture[nx+1, ny]);
  278.                                  //   dy := ny + (BumpTexture[nx, ny-1]-BumpTexture[nx, ny+1]);
  279.     DXR_TREETYPE_LOADDESTPIXEL,  // Load dest pixel
  280.     DXR_TREETYPE_BLEND           // Blend color
  281.   );
  282.  
  283.   TDXRColorChannel = (chRed, chGreen, chBlue, chAlpha);
  284.   TDXRColorChannels = set of TDXRColorChannel;
  285.  
  286.   PDXRMachine_Color = ^TDXRMachine_Color;
  287.   TDXRMachine_Color = packed record
  288.     R, G, B, A: WORD;
  289.   end;
  290.  
  291.   PDXRMachine_Axis = ^TDXRMachine_Axis;
  292.   TDXRMachine_Axis = packed record
  293.     X, Y: Integer;
  294.   end;
  295.  
  296.   PDXRMachine_Int64 = ^TDXRMachine_Int64;
  297.   TDXRMachine_Int64 = Comp;
  298.  
  299.   PDXRMachine_Reg_Color = ^TDXRMachine_Reg_Color;
  300.   TDXRMachine_Reg_Color = record
  301.     Enable: Boolean;
  302.     nColor: TDXRMachine_Color;
  303.     iColor: TDXRMachine_Color;
  304.     Gouraud: Boolean;
  305.     Channels: TDXRColorChannels;
  306.   end;
  307.  
  308.   PDXRMachine_Reg_Texture = ^TDXRMachine_Reg_Texture;
  309.   TDXRMachine_Reg_Texture = record
  310.     Enable: Boolean;
  311.     Surface: PDXR_Surface;
  312.     nAxis: TDXRMachine_Axis;
  313.     iAxis: TDXRMachine_Axis;
  314.     iAxisConstant: Boolean;
  315.     Filter: TDXR_TextureFilter;
  316.     ColorKeyEnable: Boolean;
  317.     ColorKey: TDXR_SurfaceColor;
  318.     EnableChannels: TDXRColorChannels;
  319.     TextureAddress: TDXR_TextureAddress;
  320.     DefaultColor: TDXRMachine_Color;
  321.   end;
  322.  
  323.   TDXRMachine_Reg_RHW = record
  324.     Enable: Boolean;
  325.     nRHW: TDXRMachine_Int64;
  326.     iRHW: TDXRMachine_Int64;
  327.   end;
  328.  
  329.   TDXRMachine_Reg_Dither = record
  330.     Enable: Boolean;
  331.   end;
  332.  
  333.   TDXRMachine_Reg_ZBuffer = record
  334.     Enable: Boolean;
  335.     Surface: PDXR_Surface;
  336.     CmpFunc: TDXR_CmpFunc;
  337.     WriteEnable: Boolean;
  338.   end;
  339.  
  340.   TDXRMachine_Reg_Axis = record
  341.     Axis: TDXRMachine_Axis;
  342.     IncEnable: Boolean;
  343.   end;
  344.  
  345.   PDXRMachine_Tree = ^TDXRMachine_Tree;
  346.   TDXRMachine_Tree = record
  347.     Typ: TDXRMachine_TreeType;
  348.     Channels: TDXRColorChannels;
  349.     case TDXRMachine_TreeType of
  350.       DXR_TREETYPE_LOADBLACK: (
  351.         );
  352.       DXR_TREETYPE_LOADCOLOR: (
  353.         Color: Integer
  354.         );
  355.       DXR_TREETYPE_LOADCONSTCOLOR: (
  356.         ConstColor: TDXRMachine_Color;
  357.         );
  358.       DXR_TREETYPE_LOADTEXTURE: (
  359.         Texture: Integer
  360.         );
  361.       DXR_TREETYPE_LOADBUMPTEXTURE: (
  362.         _Texture: Integer;
  363.         BumpTexture: Integer;
  364.         );
  365.       DXR_TREETYPE_LOADDESTPIXEL: (
  366.         );
  367.       DXR_TREETYPE_BLEND: (
  368.         Blend: TDXR_Blend;
  369.         BlendTree1: PDXRMachine_Tree;
  370.         BlendTree2: PDXRMachine_Tree;
  371.         );
  372.   end;
  373.  
  374.   TDXRMachine = class
  375.   private
  376.     FBuf: Pointer;
  377.     FCall: Pointer;
  378.     FCompiled: Boolean;
  379.     FTreeCount: Integer;
  380.     FTreeList: array[0..127] of TDXRMachine_Tree;
  381.     FMMXUsed: Boolean;
  382.     F_ZBuf: Pointer;
  383.     F_BiLinearAxis: TDXRMachine_Axis;
  384.     F_BiLinearCol1: TDXRMachine_Color;
  385.     F_BiLinearCol2: TDXRMachine_Color;
  386.     F_BiLinearCol3: TDXRMachine_Color;
  387.     F_BiLinearCol4: TDXRMachine_Color;
  388.     F_BumpAxis: TDXRMachine_Axis;
  389.     F_BumpAxis2: TDXRMachine_Axis;
  390.     F_BumpTempCol: DWORD;
  391.     FStack: array[0..255] of TDXRMachine_Color;
  392.     procedure GenerateCode(var Code: Pointer; Tree: PDXRMachine_Tree);
  393.   public
  394.     Dest: PDXR_Surface;
  395.     ColorList: array[0..7] of TDXRMachine_Reg_Color;
  396.     ColorIndex: array[0..7] of Integer;
  397.     ColorIndexCount: Integer;
  398.     TextureList: array[0..7] of TDXRMachine_Reg_Texture;
  399.     TextureIndex: array[0..7] of Integer;
  400.     TextureIndexCount: Integer;
  401.     Dither: TDXRMachine_Reg_Dither;
  402.     ZBuffer: TDXRMachine_Reg_ZBuffer;
  403.     Axis: TDXRMachine_Reg_Axis;
  404.     RHW: TDXRMachine_Reg_RHW;
  405.     constructor Create;
  406.     destructor Destroy; override;
  407.     function CreateTree: PDXRMachine_Tree; {$IFDEF VER9UP}inline;{$ENDIF}
  408.     function CreateTree2(Typ: TDXRMachine_TreeType): PDXRMachine_Tree; {$IFDEF VER9UP}inline;{$ENDIF}
  409.     function CreateTree_LoadColor(Color: DWORD): PDXRMachine_Tree; {$IFDEF VER9UP}inline;{$ENDIF}
  410.     function CreateTree_LoadConstColor(R, G, B, A: Byte): PDXRMachine_Tree; {$IFDEF VER9UP}inline;{$ENDIF}
  411.     function CreateTree_LoadTexture(Texture: DWORD): PDXRMachine_Tree; {$IFDEF VER9UP}inline;{$ENDIF}
  412.     function CreateTree_LoadBumpTexture(Texture, BumpTexture: DWORD): PDXRMachine_Tree; {$IFDEF VER9UP}inline;{$ENDIF}
  413.     function CreateTree_Blend(Blend: TDXR_Blend; BlendTree1, BlendTree2: PDXRMachine_Tree): PDXRMachine_Tree; {$IFDEF VER9UP}inline;{$ENDIF}
  414.     procedure Initialize; {$IFDEF VER9UP}inline;{$ENDIF}
  415.     procedure Compile(Tree: PDXRMachine_Tree);
  416.     procedure Run(Count: Integer);
  417.     property Compiled: Boolean read FCompiled write FCompiled;
  418.   end;
  419.  
  420. const
  421.   CPUIDF_FPU  = 1 shl 0;  {  Floating-point unit on-chip  }
  422.   CPUIDF_VME  = 1 shl 1;  {  Virtual Mode Extension  }
  423.   CPUIDF_DE   = 1 shl 2;  {  Debugging Extension  }
  424.   CPUIDF_PSE  = 1 shl 3;  {  Page Size Extension  }
  425.   CPUIDF_TSC  = 1 shl 4;  {  Time Stamp Counter  }
  426.   CPUIDF_MSR  = 1 shl 5;  {  Mode Spacific Registers  }
  427.   CPUIDF_PAE  = 1 shl 6;  {  Physical Address Extension  }
  428.   CPUIDF_MCE  = 1 shl 7;  {  Machine Check Exception  }
  429.   CPUIDF_CX8  = 1 shl 8;  {  CMPXCHG8 Instruction Supported  }
  430.   CPUIDF_APIC = 1 shl 9;  {  On-chip APIC Hardware Supported }
  431.   CPUIDF_MTRR = 1 shl 12; {  Memory Type Range Registers  }
  432.   CPUIDF_PGE  = 1 shl 13; {  Page Global Enable  }
  433.   CPUIDF_MCA  = 1 shl 14; {  Machine Check Architecture  }
  434.   CPUIDF_CMOV = 1 shl 15; {  Conditional Move Instruction Supported  }
  435.   CPUIDF_MMX  = 1 shl 23; {  Intel Architecture MMX Technology supported  }
  436.  
  437. var
  438.   CPUIDVendor: array[0..11] of Char;
  439.   CPUIDSignature: Integer;
  440.   CPUIDFeatures: Integer;
  441.   UseMMX: Boolean;
  442.  
  443.   RenderPrimitiveCount: Integer;
  444.  
  445. procedure ReadCPUID;
  446. begin
  447.   asm
  448.     push ebx
  449.  
  450.     pushfd
  451.     pop eax
  452.     mov ecx,eax
  453.     xor eax,$200000
  454.     push eax
  455.     popfd
  456.     pushfd
  457.     pop eax
  458.     xor eax,ecx
  459.     jz @@exit
  460.  
  461.     mov eax,0
  462.     db $0F,$A2                  ///cpuid
  463.     cmp eax,1
  464.     jl @@exit
  465.  
  466.     {  Vendor ID  }
  467.     mov eax,0
  468.     db $0F,$A2                  ///cpuid
  469.     mov dword ptr [CPUIDVendor], ebx
  470.     mov dword ptr [CPUIDVendor+4], edx
  471.     mov dword ptr [CPUIDVendor+8], ecx
  472.  
  473.     {  Features, Signature  }
  474.     mov eax,1
  475.     db $0F,$A2                  ///cpuid
  476.     mov CPUIDSignature,eax
  477.     mov CPUIDFeatures,edx
  478.   @@exit:
  479.     pop ebx
  480.   end;
  481.   UseMMX := CPUIDFeatures and CPUIDF_MMX<>0;
  482. end;
  483.  
  484. function dxrGetOption(Option: TDXR_Option): DWORD;
  485. begin
  486.   Result := 0;
  487.   case Option of
  488.     DXR_OPTION_VERSION:
  489.         begin
  490.           Result := 1*100 + 0;
  491.         end;
  492.     DXR_OPTION_MMXENABLE:
  493.         begin
  494.           Result := DWORD(LongBool(UseMMX));
  495.         end;
  496.     DXR_OPTION_RENDERPRIMITIVES:
  497.         begin
  498.           Result := RenderPrimitiveCount;
  499.         end;
  500.   end;
  501. end;
  502.  
  503. procedure dxrSetOption(Option: TDXR_Option; Value: DWORD);
  504. begin
  505.   case Option of
  506.     DXR_OPTION_MMXENABLE:
  507.         begin
  508.           UseMMX := LongBool(Value) and (CPUIDFeatures and CPUIDF_MMX<>0);
  509.         end;
  510.     DXR_OPTION_RENDERPRIMITIVES:
  511.         begin
  512.           RenderPrimitiveCount := Value;
  513.         end;
  514.   end;
  515. end;
  516.  
  517. function GetBitCount(B: Integer): DWORD;
  518. begin
  519.   Result := 31;
  520.   while (Result>0) and (((1 shl Result) and B)=0) do Dec(Result);
  521. end;
  522.  
  523. function GetFirstZeroBitCount(B: Integer): DWORD;
  524. begin
  525.   Result := 0;
  526.   while (Result<31) and (((1 shl Result) and B)=0) do Inc(Result);
  527. end;
  528.  
  529. function GetOneBitCount(B: Integer): DWORD;
  530. var
  531.   i: Integer;
  532. begin
  533.   Result := 0;
  534.   for i:=0 to 31 do
  535.     Inc(Result, Ord(b and (1 shl i)<>0));
  536. end;
  537.  
  538. function dxrMakeColorChannel(Mask: DWORD; indexed: Boolean): TDXR_ColorChannel;
  539. var
  540.   i: Integer;
  541. begin
  542.   Result.BitCount := GetOneBitCount(Mask shr (GetFirstZeroBitCount(Mask)));
  543.   Result.Mask := Mask;
  544.  
  545.   if indexed then
  546.   begin
  547.     Result.rshift := GetFirstZeroBitCount(Mask);
  548.     Result.lshift := 0;
  549.   end else
  550.   begin
  551.     i :=  GetFirstZeroBitCount(Mask)-(8-Result.BitCount);
  552.  
  553.     if i<0 then
  554.     begin
  555.       Result.lshift := -i;
  556.       Result.rshift := 0;
  557.     end else
  558.     begin
  559.       Result.lshift := 0;
  560.       Result.rshift := DWORD(i);
  561.     end;
  562.   end;
  563. end;
  564.  
  565. procedure dxrMakeIndexedSurface(var Surface: TDXR_Surface; Width, Height, BitCount: DWORD;
  566.   Bits: Pointer; pitch: Integer; idx_index, idx_alpha: DWORD);
  567. begin
  568.   FillChar(Surface, SizeOf(Surface), 0);
  569.  
  570.   Surface.ColorType := DXR_COLORTYPE_INDEXED;
  571.   Surface.Width := Width;
  572.   Surface.Height := Height;
  573.   Surface.WidthBit := GetBitCount(Width);
  574.   Surface.HeightBit := GetBitCount(Height);
  575.   Surface.Width2 := 1 shl Surface.WidthBit;
  576.   Surface.Height2 := 1 shl Surface.HeightBit;
  577.   Surface.WidthMask := Surface.Width-1;
  578.   Surface.HeightMask := Surface.Height2-1;
  579.  
  580.   Surface.BitCount := BitCount;
  581.   Surface.Bits := Bits;
  582.   Surface.Pitch := Pitch;
  583.   Surface.PitchBit := GetBitCount(Abs(Pitch));
  584.  
  585.   Surface.idx_index := dxrMakeColorChannel(idx_index, True);
  586.   Surface.idx_alpha := dxrMakeColorChannel(idx_alpha, False);
  587. end;
  588.  
  589. procedure dxrMakeRGBSurface(var Surface: TDXR_Surface; Width, Height, BitCount: DWORD;
  590.   Bits: Pointer; pitch: Integer; rgb_red, rgb_green, rgb_blue, rgb_alpha: DWORD);
  591. begin
  592.   FillChar(Surface, SizeOf(Surface), 0);
  593.  
  594.   Surface.ColorType := DXR_COLORTYPE_RGB;
  595.   Surface.Width := Width;
  596.   Surface.Height := Height;
  597.   Surface.WidthBit := GetBitCount(Width);
  598.   Surface.HeightBit := GetBitCount(Height);
  599.   Surface.Width2 := 1 shl Surface.WidthBit;
  600.   Surface.Height2 := 1 shl Surface.HeightBit;
  601.   Surface.WidthMask := Surface.Width-1;
  602.   Surface.HeightMask := Surface.Height2-1;
  603.  
  604.   Surface.BitCount := BitCount;
  605.   Surface.Bits := Bits;
  606.   Surface.Pitch := Pitch;
  607.   Surface.PitchBit := GetBitCount(Abs(Pitch));
  608.  
  609.   Surface.rgb_red := dxrMakeColorChannel(rgb_red, False);
  610.   Surface.rgb_green := dxrMakeColorChannel(rgb_green, False);
  611.   Surface.rgb_blue := dxrMakeColorChannel(rgb_blue, False);
  612.   Surface.rgb_alpha := dxrMakeColorChannel(rgb_alpha, False);
  613. end;
  614.  
  615. function dxrCompareSurface(const Surface1, Surface2: TDXR_Surface): Boolean;
  616. begin
  617.   if Surface1.ColorType=DXR_COLORTYPE_INDEXED then
  618.   begin
  619.     Result := (Surface2.ColorType=DXR_COLORTYPE_INDEXED) and
  620.       (Surface1.idx_index.Mask=Surface2.idx_index.Mask) and
  621.       (Surface1.idx_alpha.Mask=Surface2.idx_alpha.Mask);
  622.   end else if Surface1.ColorType=DXR_COLORTYPE_RGB then
  623.   begin
  624.     Result := (Surface2.ColorType=DXR_COLORTYPE_RGB) and
  625.       (Surface1.rgb_red.Mask=Surface2.rgb_red.Mask) and
  626.       (Surface1.rgb_green.Mask=Surface2.rgb_green.Mask) and
  627.       (Surface1.rgb_blue.Mask=Surface2.rgb_blue.Mask) and
  628.       (Surface1.rgb_alpha.Mask=Surface2.rgb_alpha.Mask);
  629.   end else
  630.     Result := False;
  631. end;
  632.  
  633. function dxrDDSurfaceLock(DDSurface: {$IFDEF D3D_deprecated}IDirectDrawSurface{$ELSE}IDirectDrawSurface7{$ENDIF}; var Surface: TDXR_Surface): Boolean;
  634. var
  635.   ddsd: {$IFDEF D3D_deprecated}TDDSurfaceDesc{$ELSE}TDDSurfaceDesc2{$ENDIF};
  636. begin
  637.   Result := dxrDDSurfaceLock2(DDSurface, ddsd, Surface);
  638. end;
  639.                                                                                    
  640. function dxrDDSurfaceLock2(DDSurface: {$IFDEF D3D_deprecated}IDirectDrawSurface{$ELSE}IDirectDrawSurface7{$ENDIF}; var ddsd: {$IFDEF D3D_deprecated}TDDSurfaceDesc{$ELSE}TDDSurfaceDesc2{$ENDIF};
  641.   var Surface: TDXR_Surface): Boolean;
  642. const
  643.   DDPF_PALETTEINDEXED = DDPF_PALETTEINDEXED1 or DDPF_PALETTEINDEXED2 or
  644.     DDPF_PALETTEINDEXED4 or DDPF_PALETTEINDEXED8;
  645. begin
  646.   ddsd.dwSize := SizeOf(ddsd);
  647.   Result := DDSurface.Lock(nil, ddsd, DDLOCK_WAIT, 0)=DD_OK;
  648.   if Result then
  649.   begin
  650.     FillChar(Surface, SizeOf(Surface), 0);
  651.     if ddsd.ddpfPixelFormat.dwFlags and DDPF_PALETTEINDEXED<>0 then
  652.     begin
  653.       dxrMakeIndexedSurface(Surface, ddsd.dwWidth, ddsd.dwHeight, ddsd.ddpfPixelFormat.dwRGBBitCount,
  654.         ddsd.lpSurface, ddsd.lPitch, (1 shl ddsd.ddpfPixelFormat.dwRGBBitCount)-1, 0);
  655.     end else
  656.     begin
  657.       if ddsd.ddpfPixelFormat.dwFlags and DDPF_ALPHAPIXELS<>0 then
  658.       begin
  659.         dxrMakeRGBSurface(Surface, ddsd.dwWidth, ddsd.dwHeight, ddsd.ddpfPixelFormat.dwRGBBitCount,
  660.           ddsd.lpSurface, ddsd.lPitch, ddsd.ddpfPixelFormat.dwRBitMask, ddsd.ddpfPixelFormat.dwGBitMask,
  661.           ddsd.ddpfPixelFormat.dwBBitMask, ddsd.ddpfPixelFormat.dwRGBAlphaBitMask);
  662.       end else
  663.       begin
  664.         dxrMakeRGBSurface(Surface, ddsd.dwWidth, ddsd.dwHeight, ddsd.ddpfPixelFormat.dwRGBBitCount,
  665.           ddsd.lpSurface, ddsd.lPitch, ddsd.ddpfPixelFormat.dwRBitMask, ddsd.ddpfPixelFormat.dwGBitMask,
  666.           ddsd.ddpfPixelFormat.dwBBitMask, 0);
  667.       end;                          
  668.     end;
  669.   end;
  670. end;
  671.  
  672. procedure dxrDDSurfaceUnLock(DDSurface: {$IFDEF D3D_deprecated}IDirectDrawSurface{$ELSE}IDirectDrawSurface7{$ENDIF}; const Surface: TDXR_Surface);
  673. begin
  674.   DDSurface.Unlock(Surface.Bits);
  675. end;
  676.  
  677. function dxrScanLine(const Surface: TDXR_Surface; y: DWORD): Pointer;
  678. begin
  679.   Result := Pointer(Integer(Surface.Bits)+Surface.Pitch*Integer(y));
  680. end;
  681.  
  682. procedure dxrZBufferClear(const Surface: TDXR_Surface);
  683. var
  684.   i: Integer;
  685. begin
  686.   for i:=0 to Surface.Height-1 do
  687.     FillChar(dxrScanLine(Surface, i)^, Abs(Surface.Pitch), $FF);
  688. end;
  689.  
  690. {  TDXRMachine  }
  691.  
  692. constructor TDXRMachine.Create;
  693. begin
  694.   inherited Create;
  695.   FBuf := VirtualAlloc(nil, 2048, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
  696. end;
  697.  
  698. destructor TDXRMachine.Destroy;
  699. begin
  700.   VirtualFree(FBuf, 0, MEM_RELEASE);
  701.   inherited Destroy;
  702. end;
  703.  
  704. procedure TDXRMachine.Initialize;
  705. begin
  706.   FCall := nil;
  707.   ColorIndexCount := 0;
  708.   TextureIndexCount := 0;
  709.  
  710.   FTreeCount := 0;
  711.  
  712.   Dest := nil;
  713.   FCompiled := False;
  714.   FMMXUsed := False;
  715.  
  716.   FillChar(ColorList, SizeOf(ColorList), 0);
  717.   FillChar(TextureList, SizeOf(TextureList), 0);
  718.   FillChar(Dither, SizeOf(Dither), 0);
  719.   FillChar(ZBuffer, SizeOf(ZBuffer), 0);
  720.   FillChar(Axis, SizeOf(Axis), 0);
  721.   FillChar(RHW, SizeOf(RHW), 0);
  722. end;
  723.  
  724. function TDXRMachine.CreateTree: PDXRMachine_Tree;
  725. begin
  726.   Result := @FTreeList[FTreeCount];
  727.   FillChar(Result^, SizeOf(Result^), 0);
  728.   Inc(FTreeCount);
  729. end;
  730.  
  731. function TDXRMachine.CreateTree2(Typ: TDXRMachine_TreeType): PDXRMachine_Tree;
  732. begin
  733.   Result := CreateTree;
  734.   Result.Typ := Typ;
  735. end;
  736.  
  737. function TDXRMachine.CreateTree_LoadColor(Color: DWORD): PDXRMachine_Tree;
  738. begin
  739.   Result := CreateTree;
  740.   Result.Typ := DXR_TREETYPE_LOADCOLOR;
  741.   Result.Color := Color;
  742. end;
  743.  
  744. function TDXRMachine.CreateTree_LoadConstColor(R, G, B, A: Byte): PDXRMachine_Tree;
  745. begin
  746.   Result := CreateTree;
  747.   Result.Typ := DXR_TREETYPE_LOADCONSTCOLOR;
  748.   Result.ConstColor.R := R shl 8;
  749.   Result.ConstColor.G := G shl 8;
  750.   Result.ConstColor.B := B shl 8;
  751.   Result.ConstColor.A := A shl 8;
  752. end;
  753.  
  754. function TDXRMachine.CreateTree_LoadTexture(Texture: DWORD): PDXRMachine_Tree;
  755. begin
  756.   Result := CreateTree;
  757.   Result.Typ := DXR_TREETYPE_LOADTEXTURE;
  758.   Result.Texture := Texture;
  759. end;
  760.  
  761. function TDXRMachine.CreateTree_LoadBumpTexture(Texture, BumpTexture: DWORD): PDXRMachine_Tree;
  762. begin
  763.   Result := CreateTree;
  764.   Result.Typ := DXR_TREETYPE_LOADBUMPTEXTURE;
  765.   Result.Texture := Texture;
  766.   Result.BumpTexture := BumpTexture;
  767. end;
  768.  
  769. function TDXRMachine.CreateTree_Blend(Blend: TDXR_Blend; BlendTree1, BlendTree2: PDXRMachine_Tree): PDXRMachine_Tree;
  770. begin
  771.   Result := CreateTree;
  772.   Result.Typ := DXR_TREETYPE_BLEND;
  773.   Result.Blend := Blend;
  774.   Result.BlendTree1 := BlendTree1;
  775.   Result.BlendTree2 := BlendTree2;
  776. end;
  777.  
  778. procedure TDXRMachine.Compile;
  779.  
  780.   function GetSurfaceChannels(const Surface: TDXR_Surface): TDXRColorChannels;
  781.   begin
  782.     Result := [];
  783.  
  784.     if Surface.ColorType=DXR_COLORTYPE_INDEXED then
  785.     begin
  786.       if Surface.idx_index.Mask<>0 then Result := Result + [chRed, chGreen, chBlue];
  787.       if Surface.idx_alpha.Mask<>0 then Result := Result + [chAlpha];
  788.     end else
  789.     begin
  790.       if Surface.rgb_red.Mask<>0 then Result := Result + [chRed];
  791.       if Surface.rgb_green.Mask<>0 then Result := Result + [chGreen];
  792.       if Surface.rgb_blue.Mask<>0 then Result := Result + [chBlue];
  793.       if Surface.rgb_alpha.Mask<>0 then Result := Result + [chAlpha];
  794.     end;
  795.   end;
  796.  
  797.   procedure OptimizeTree(var Tree: PDXRMachine_Tree);
  798.  
  799.     procedure GetBlendChannels(Blend: TDXR_Blend; var Col1_1, Col1_2, Col2_1, Col2_2: TDXRColorChannels);
  800.     begin
  801.       case Blend of
  802.         DXR_BLEND_ZERO:
  803.           begin
  804.             Col1_1 := [];
  805.             Col1_2 := [];
  806.             Col2_1 := [];
  807.             Col2_2 := [];
  808.           end;
  809.         DXR_BLEND_ONE1:
  810.           begin
  811.             Col1_1 := [chRed, chGreen, chBlue, chAlpha];
  812.             Col1_2 := [];
  813.             Col2_1 := [];
  814.             Col2_2 := [];
  815.           end;
  816.         DXR_BLEND_ONE2:
  817.           begin
  818.             Col1_1 := [];
  819.             Col1_2 := [];
  820.             Col2_1 := [chRed, chGreen, chBlue, chAlpha];
  821.             Col2_2 := [];
  822.           end;
  823.         DXR_BLEND_ONE1_ADD_ONE2, DXR_BLEND_ONE1_SUB_ONE2:
  824.           begin
  825.             Col1_1 := [chRed, chGreen, chBlue, chAlpha];
  826.             Col1_2 := [];
  827.             Col2_1 := [chRed, chGreen, chBlue, chAlpha];
  828.             Col2_2 := [];
  829.           end;
  830.         DXR_BLEND_ONE2_SUB_ONE1, DXR_BLEND_ONE1_MUL_ONE2:
  831.           begin
  832.             Col1_1 := [chRed, chGreen, chBlue, chAlpha];
  833.             Col1_2 := [];
  834.             Col2_1 := [chRed, chGreen, chBlue, chAlpha];
  835.             Col2_2 := [];
  836.           end;
  837.         DXR_BLEND_SRCALPHA1:
  838.           begin
  839.             Col1_1 := [chRed, chGreen, chBlue];
  840.             Col1_2 := [chAlpha];
  841.             Col2_1 := [];
  842.             Col2_2 := [];
  843.           end;
  844.         DXR_BLEND_SRCALPHA1_ADD_ONE2:
  845.           begin
  846.             Col1_1 := [chRed, chGreen, chBlue];
  847.             Col1_2 := [chAlpha];
  848.             Col2_1 := [chRed, chGreen, chBlue, chAlpha];
  849.             Col2_2 := [];
  850.           end;
  851.         DXR_BLEND_ONE2_SUB_SRCALPHA1:
  852.           begin
  853.             Col1_1 := [chRed, chGreen, chBlue];
  854.             Col1_2 := [chAlpha];
  855.             Col2_1 := [chRed, chGreen, chBlue, chAlpha];
  856.             Col2_2 := [];
  857.           end;
  858.         DXR_BLEND_SRCALPHA1_ADD_INVSRCALPHA2:
  859.           begin
  860.             Col1_1 := [chRed, chGreen, chBlue];
  861.             Col1_2 := [chAlpha];
  862.             Col2_1 := [chRed, chGreen, chBlue, chAlpha];
  863.             Col2_2 := [];
  864.           end;
  865.         DXR_BLEND_INVSRCALPHA1_ADD_SRCALPHA2:
  866.           begin
  867.             Col1_1 := [chRed, chGreen, chBlue];
  868.             Col1_2 := [chAlpha];
  869.             Col2_1 := [chRed, chGreen, chBlue, chAlpha];
  870.             Col2_2 := [];
  871.           end;
  872.  
  873.         DXR_BLEND_DECAL:
  874.           begin
  875.             Col1_1 := [chRed, chGreen, chBlue, chAlpha];
  876.             Col1_2 := [];
  877.             Col2_1 := [];
  878.             Col2_2 := [];
  879.           end;
  880.         DXR_BLEND_DECALALPHA:
  881.           begin
  882.             Col1_1 := [chRed, chGreen, chBlue];
  883.             Col1_2 := [];
  884.             Col2_1 := [];
  885.             Col2_2 := [chAlpha];
  886.           end;
  887.         DXR_BLEND_MODULATE:
  888.           begin
  889.             Col1_1 := [chRed, chGreen, chBlue, chAlpha];
  890.             Col1_2 := [];
  891.             Col2_1 := [chRed, chGreen, chBlue, chAlpha];
  892.             Col2_2 := [];
  893.           end;
  894.         DXR_BLEND_MODULATEALPHA:
  895.           begin
  896.             Col1_1 := [chRed, chGreen, chBlue];
  897.             Col1_2 := [chAlpha];
  898.             Col2_1 := [chRed, chGreen, chBlue];
  899.             Col2_2 := [chAlpha];
  900.           end;
  901.         DXR_BLEND_ADD:
  902.           begin
  903.             Col1_1 := [chRed, chGreen, chBlue, chAlpha];
  904.             Col1_2 := [];
  905.             Col2_1 := [chRed, chGreen, chBlue, chAlpha];
  906.             Col2_2 := [];
  907.           end;
  908.       end;
  909.     end;
  910.  
  911.   var
  912.     c: TDXRColorChannels;
  913.     Col1_1, Col1_2, Col2_1, Col2_2: TDXRColorChannels;
  914.   begin
  915.     case Tree.Typ of
  916.       DXR_TREETYPE_LOADBLACK:
  917.           begin
  918.             // Load black color
  919.           end;
  920.       DXR_TREETYPE_LOADCOLOR:
  921.           begin
  922.             // Load color
  923.           end;
  924.       DXR_TREETYPE_LOADTEXTURE:
  925.           begin
  926.             // Load texel
  927.           end;
  928.       DXR_TREETYPE_LOADBUMPTEXTURE:
  929.           begin
  930.             // Load texel with Bump mapping
  931.           end;
  932.       DXR_TREETYPE_LOADDESTPIXEL:
  933.           begin
  934.             // Load dest pixel
  935.           end;
  936.       DXR_TREETYPE_BLEND:
  937.           begin
  938.             // Blend color
  939.             GetBlendChannels(Tree.Blend, Col1_1, Col1_2, Col2_1, Col2_2);
  940.  
  941.             Tree.BlendTree1.Channels := Tree.Channels*Col1_1+Col1_2;
  942.             Tree.BlendTree2.Channels := Tree.Channels*Col2_1+Col2_2;
  943.  
  944.             OptimizeTree(Tree.BlendTree1);
  945.             OptimizeTree(Tree.BlendTree2);
  946.  
  947.             if (Tree.Blend=DXR_BLEND_ZERO) then
  948.             begin
  949.               c := Tree.Channels; Tree^.Typ := DXR_TREETYPE_LOADBLACK; Tree.Channels := c;
  950.             end else
  951.             if (Tree.Blend in [DXR_BLEND_ONE1, DXR_BLEND_DECAL]) then
  952.             begin
  953.               c := Tree.Channels; Tree := Tree.BlendTree1; Tree.Channels := c;
  954.             end else
  955.             if (Tree.Blend=DXR_BLEND_ONE2) then
  956.             begin
  957.               c := Tree.Channels; Tree := Tree.BlendTree2; Tree.Channels := c;
  958.             end else
  959.             if (Tree.Blend in [DXR_BLEND_ONE1_ADD_ONE2, DXR_BLEND_ONE2_SUB_ONE1]) and
  960.               (Tree.BlendTree2.Typ=DXR_TREETYPE_LOADBLACK) then
  961.             begin
  962.               c := Tree.Channels; Tree := Tree.BlendTree1; Tree.Channels := c;
  963.             end else
  964.             if (Tree.Blend in [DXR_BLEND_ONE1_ADD_ONE2, DXR_BLEND_ONE2_SUB_ONE1]) and
  965.               (Tree.BlendTree1.Typ=DXR_TREETYPE_LOADBLACK) then
  966.             begin
  967.               c := Tree.Channels; Tree := Tree.BlendTree2; Tree.Channels := c;
  968.             end else
  969.             begin
  970.               if (Col1_1=[]) and (Col1_2=[]) then Tree.BlendTree1 := nil;
  971.               if (Col2_1=[]) and (Col2_2=[]) then Tree.BlendTree2 := nil;
  972.             end;
  973.           end;
  974.     end;
  975.   end;
  976.  
  977.   procedure GetEnableChannels(Tree: PDXRMachine_Tree);
  978.   begin
  979.     case Tree.Typ of
  980.       DXR_TREETYPE_LOADBLACK:
  981.           begin
  982.             // Load black color
  983.           end;
  984.       DXR_TREETYPE_LOADCOLOR:
  985.           begin
  986.             // Load color
  987.             ColorList[Tree.Color].Channels := ColorList[Tree.Color].Channels + Tree.Channels;
  988.             ColorList[Tree.Color].Enable := ColorList[Tree.Color].Channels<>[];
  989.           end;
  990.       DXR_TREETYPE_LOADTEXTURE:
  991.           begin
  992.             // Load texel
  993.             TextureList[Tree.Texture].EnableChannels := TextureList[Tree.Texture].EnableChannels +
  994.               Tree.Channels*GetSurfaceChannels(TextureList[Tree.Texture].Surface^);
  995.             TextureList[Tree.Texture].Enable := TextureList[Tree.Texture].EnableChannels<>[];
  996.           end;
  997.       DXR_TREETYPE_LOADBUMPTEXTURE:
  998.           begin
  999.             // Load texel with Bump mapping
  1000.             TextureList[Tree.Texture].EnableChannels := TextureList[Tree.Texture].EnableChannels +
  1001.               Tree.Channels*GetSurfaceChannels(TextureList[Tree.Texture].Surface^);
  1002.             TextureList[Tree.Texture].Enable := TextureList[Tree.Texture].EnableChannels<>[];
  1003.             TextureList[Tree.BumpTexture].Enable := True;
  1004.           end;
  1005.       DXR_TREETYPE_LOADDESTPIXEL:
  1006.           begin
  1007.             // Load dest pixel
  1008.           end;
  1009.       DXR_TREETYPE_BLEND:
  1010.           begin
  1011.             // Blend color
  1012.             if Tree.BlendTree1<>nil then GetEnableChannels(Tree.BlendTree1);
  1013.             if Tree.BlendTree2<>nil then GetEnableChannels(Tree.BlendTree2);
  1014.           end;
  1015.     end;
  1016.   end;
  1017.  
  1018. var
  1019.   Code: Pointer;
  1020.   i: Integer;
  1021. begin
  1022.   {  Optimize tree  }
  1023.   Tree.Channels := GetSurfaceChannels(Dest^);
  1024.   OptimizeTree(Tree);
  1025.  
  1026.   {  Get enable channels  }
  1027.   GetEnableChannels(Tree);
  1028.  
  1029.   for i:=Low(ColorList) to High(ColorList) do
  1030.     if ColorList[i].Enable then
  1031.     begin
  1032.       ColorIndex[ColorIndexCount] := i;
  1033.       Inc(ColorIndexCount);
  1034.     end;
  1035.  
  1036.   for i:=Low(TextureList) to High(TextureList) do
  1037.     if TextureList[i].Enable then
  1038.     begin
  1039.       TextureIndex[TextureIndexCount] := i;
  1040.       Inc(TextureIndexCount);
  1041.     end;
  1042.  
  1043.   ZBuffer.Enable := ZBuffer.Surface<>nil;
  1044.  
  1045.   RHW.Enable := ZBuffer.Enable;
  1046.   Axis.IncEnable := Dither.Enable;
  1047.  
  1048.   {  Generate X86 code  }
  1049.   Code := FBuf; GenerateCode(Code, Tree);
  1050.  
  1051.   FCompiled := True;
  1052. end;
  1053.  
  1054. const
  1055.   Mask1: array[0..7] of DWORD= ($80, $40, $20, $10, $08, $04, $02, $01);
  1056.   Mask2: array[0..3] of DWORD= ($C0, $30, $0C, $03);
  1057.   Mask4: array[0..1] of DWORD= ($F0, $0F);
  1058.  
  1059.   Shift1: array[0..7] of DWORD= (7, 6, 5, 4, 3, 2, 1, 0);
  1060.   Shift2: array[0..3] of DWORD= (6, 4, 2, 0);
  1061.   Shift4: array[0..1] of DWORD= (4, 0);
  1062.  
  1063. var
  1064.   _null: Byte;
  1065.  
  1066.   // Saturation addition table
  1067.   //   Result := Min(n+j, 255)
  1068.   _AddTable: array[0..256*2-1] of Byte;
  1069.   _SubTable: array[-255..255] of Byte;
  1070.  
  1071.   // Byte to QWORD convert table
  1072.   //   Result := (n shl 56)+(n shl 48)+(n shl 32)+(n shl 24)+(n shl 16)+(n shl 8)+n
  1073.   _ByteToQWORDTable: array[0..255, 0..3] of WORD;
  1074.  
  1075.   _BlackColor: TDXRMachine_Color = (R: 0; G: 0; B: 0; A: 0);
  1076.  
  1077. procedure Init;
  1078. var
  1079.   i: Integer;
  1080. begin
  1081.   for i:=Low(_AddTable) to High(_AddTable) do
  1082.   begin
  1083.     if i>255 then
  1084.       _AddTable[i] := 255
  1085.     else
  1086.       _AddTable[i] := i;
  1087.   end;
  1088.  
  1089.   for i:=Low(_SubTable) to High(_SubTable) do
  1090.   begin
  1091.     if i<0 then
  1092.       _SubTable[i] := 0
  1093.     else
  1094.       _SubTable[i] := i;
  1095.   end;
  1096.  
  1097.   for i:=0 to 255 do
  1098.   begin
  1099.     _ByteToQWORDTable[i, 0] := i;
  1100.     _ByteToQWORDTable[i, 1] := i;
  1101.     _ByteToQWORDTable[i, 2] := i;
  1102.     _ByteToQWORDTable[i, 3] := i;
  1103.   end;
  1104. end;
  1105.  
  1106. procedure TDXRMachine.GenerateCode(var Code: Pointer; Tree: PDXRMachine_Tree);
  1107. var
  1108.   SkipAddress: Pointer;
  1109.  
  1110.   procedure genCmpFunc(var Code: Pointer; Func: TDXR_CmpFunc; JmpAdress: Pointer);
  1111.  
  1112.     procedure genShortJmp(var Code: Pointer; JmpCode: Pointer; sC: Byte);
  1113.     type
  1114.       PShortJmp = ^TShortJmp;
  1115.       TShortJmp = packed record
  1116.         c: Byte;
  1117.         A: ShortInt;
  1118.       end;
  1119.     begin
  1120.       with PShortJmp(Code)^ do
  1121.       begin
  1122.         c := sC;
  1123.         A := Integer(JmpCode)-(Integer(Code)+2);
  1124.       end;
  1125.       Inc(Integer(Code), 2);
  1126.     end;
  1127.  
  1128.     procedure genNearJmp(var Code: Pointer; JmpCode: Pointer; nC: Byte);
  1129.     type
  1130.       PNearJmp = ^TNearJmp;
  1131.       TNearJmp = packed record
  1132.         c: Byte;
  1133.         A: Integer;
  1134.       end;
  1135.     begin
  1136.       with PNearJmp(Code)^ do
  1137.       begin
  1138.         c := nC;
  1139.         A := Integer(JmpCode)-(Integer(Code)+5);
  1140.       end;
  1141.       Inc(Integer(Code), 5);
  1142.     end;
  1143.  
  1144.     procedure genNearJmp2(var Code: Pointer; JmpCode: Pointer; nC1, nC2: Byte);
  1145.     type
  1146.       PNearJmp2 = ^TNearJmp2;
  1147.       TNearJmp2 = packed record
  1148.         c1, c2: Byte;
  1149.         A: Integer;
  1150.       end;
  1151.     begin
  1152.       with PNearJmp2(Code)^ do
  1153.       begin
  1154.         c1 := nC1;
  1155.         c2 := nC2;
  1156.         A := Integer(JmpCode)-(Integer(Code)+6);
  1157.       end;
  1158.       Inc(Integer(Code), 6);
  1159.     end;
  1160.  
  1161.     procedure genFlagJmp(var Code: Pointer; JmpCode: Pointer; sC, nC1, nC2: Byte);
  1162.     var
  1163.       i: Integer;
  1164.     begin
  1165.       i := Integer(JmpCode)-(Integer(Code)+2);
  1166.       if abs(i)<128 then
  1167.         genShortJmp(Code, JmpCode, sC)
  1168.       else
  1169.         genNearJmp2(Code, JmpCode, nC1, nC2);
  1170.     end;
  1171.  
  1172.     procedure genJmp(var Code: Pointer; JmpCode: Pointer);
  1173.     var
  1174.       i: Integer;
  1175.     begin
  1176.       i := Integer(JmpCode)-(Integer(Code)+2);
  1177.       if abs(i)<128 then
  1178.         genShortJmp(Code, JmpCode, $EB)
  1179.       else
  1180.         genNearJmp(Code, JmpCode, $E9);
  1181.     end;
  1182.  
  1183.   begin
  1184.     case Func of
  1185.       DXR_CMPFUNC_NEVER:
  1186.           begin
  1187.             {  if (False) then Jump }
  1188.           end;
  1189.       DXR_CMPFUNC_LESS:
  1190.           begin
  1191.             {  if (New<Old) then Jump  }
  1192.             genFlagJmp(Code, JmpAdress, $7C, $0F, $8C);
  1193.           end;
  1194.       DXR_CMPFUNC_EQUAL:
  1195.           begin
  1196.             {  if (New=Old) then Jump  }
  1197.             genFlagJmp(Code, JmpAdress, $74, $0F, $84);
  1198.           end;
  1199.       DXR_CMPFUNC_LESSEQUAL:
  1200.           begin
  1201.             {  if (New<=Old) then Jump  }
  1202.             genFlagJmp(Code, JmpAdress, $7E, $0F, $8E);
  1203.           end;
  1204.       DXR_CMPFUNC_GREATER:
  1205.           begin
  1206.             {  if (New>Old) then Jump  }
  1207.             genFlagJmp(Code, JmpAdress, $7F, $0F, $8F);
  1208.           end;
  1209.       DXR_CMPFUNC_NOTEQUAL:
  1210.           begin
  1211.             {  if (New<>Old) then Jump  }
  1212.             genFlagJmp(Code, JmpAdress, $75, $0F, $85);
  1213.           end;
  1214.       DXR_CMPFUNC_GREATEREQUAL:
  1215.           begin
  1216.             {  if (New>=Old) then Jump  }
  1217.             genFlagJmp(Code, JmpAdress, $7D, $0F, $8D);
  1218.           end;
  1219.       DXR_CMPFUNC_ALWAYS:
  1220.           begin
  1221.             {  if (True) then Break }
  1222.             genJmp(Code, JmpAdress);
  1223.           end;
  1224.     end;
  1225.   end;
  1226.  
  1227.   procedure genInitDestAddress(var Code: Pointer);
  1228.   var
  1229.     _Axis: Pointer;
  1230.     ByteCount, Pitch: DWORD;
  1231.     Bits: Pointer;
  1232.   begin
  1233.     _Axis := @Axis.Axis;
  1234.  
  1235.     ByteCount := Dest.BitCount shr 3;
  1236.     Pitch := Dest.pitch;
  1237.     Bits := Dest.Bits;
  1238.  
  1239.     asm
  1240.       jmp @@EndCode
  1241.     @@StartCode:
  1242.       mov eax,dword ptr [offset _null]{}@@AxisX:
  1243.       imul eax,$11{}        @@ByteCount: // Dest.BitCount div 8
  1244.       mov edi,dword ptr [offset _null]{}@@AxisY:
  1245.       imul edi,$11111111{}  @@Pitch: // Dest.pitch
  1246.       add edi,$11111111{}   @@Bits:  // Dest.Bits
  1247.       add edi,eax
  1248.     @@EndCode:
  1249.       {$I DXRender.inc}
  1250.       {  @@AxisX  }
  1251.       mov eax,_Axis; add eax,TDXRMachine_Axis.X
  1252.       mov edx,offset @@AxisX-4
  1253.       sub edx,offset @@StartCode
  1254.       mov dword ptr [ecx+edx],eax
  1255.  
  1256.       {  @@AxisY  }
  1257.       mov eax,_Axis; add eax,TDXRMachine_Axis.Y
  1258.       mov edx,offset @@AxisY-4
  1259.       sub edx,offset @@StartCode
  1260.       mov dword ptr [ecx+edx],eax
  1261.  
  1262.       {  @@ByteCount  }
  1263.       mov eax,ByteCount
  1264.       mov edx,offset @@ByteCount-1
  1265.       sub edx,offset @@StartCode
  1266.       mov byte ptr [ecx+edx],al
  1267.  
  1268.       {  @@Pitch  }
  1269.       mov eax,Pitch
  1270.       mov edx,offset @@Pitch-4
  1271.       sub edx,offset @@StartCode
  1272.       mov dword ptr [ecx+edx],eax
  1273.  
  1274.       {  @@Bits  }
  1275.       mov eax,Bits
  1276.       mov edx,offset @@Bits-4
  1277.       sub edx,offset @@StartCode
  1278.       mov dword ptr [ecx+edx],eax
  1279.     end;
  1280.   end;
  1281.  
  1282.   procedure genInitZBuffer(var Code: Pointer);
  1283.   var
  1284.     _Axis: Pointer;
  1285.     ByteCount, Pitch: DWORD;
  1286.     Bits, _ZBuf: Pointer;
  1287.   begin
  1288.     if not ZBuffer.Enable then Exit;
  1289.  
  1290.     _Axis := @Axis.Axis;
  1291.  
  1292.     ByteCount := ZBuffer.Surface.BitCount div 8;
  1293.     Pitch := ZBuffer.Surface.Pitch;
  1294.     Bits := ZBuffer.Surface.Bits;
  1295.  
  1296.     _ZBuf := @F_ZBuf;
  1297.  
  1298.     asm
  1299.       jmp @@EndCode
  1300.     @@StartCode:
  1301.       mov edx,dword ptr [offset _null]{}@@AxisX:
  1302.       imul edx,$11{}        @@ByteCount: // States.ZBuffer.BitCount div 8
  1303.       mov eax,dword ptr [offset _null]{}@@AxisY:
  1304.       imul eax,$11111111{}  @@Pitch: // States.ZBuffer.pitch
  1305.       add eax,$11111111{}   @@Bits:  // States.ZBuffer.Bits
  1306.       add eax,edx
  1307.       mov dword ptr [offset _null],eax{}@@_ZBuf:
  1308.     @@EndCode:
  1309.       {$I DXRender.inc}
  1310.       {  @@AxisX  }
  1311.       mov eax,_Axis; add eax,TDXRMachine_Axis.X
  1312.       mov edx,offset @@AxisX-4
  1313.       sub edx,offset @@StartCode
  1314.       mov dword ptr [ecx+edx],eax
  1315.  
  1316.       {  @@AxisY  }
  1317.       mov eax,_Axis; add eax,TDXRMachine_Axis.Y
  1318.       mov edx,offset @@AxisY-4
  1319.       sub edx,offset @@StartCode
  1320.       mov dword ptr [ecx+edx],eax
  1321.  
  1322.       {  @@ByteCount  }
  1323.       mov eax,ByteCount
  1324.       mov edx,offset @@ByteCount-1
  1325.       sub edx,offset @@StartCode
  1326.       mov byte ptr [ecx+edx],al
  1327.  
  1328.       {  @@Pitch  }
  1329.       mov eax,Pitch
  1330.       mov edx,offset @@Pitch-4
  1331.       sub edx,offset @@StartCode
  1332.       mov dword ptr [ecx+edx],eax
  1333.  
  1334.       {  @@Bits  }
  1335.       mov eax,Bits
  1336.       mov edx,offset @@Bits-4
  1337.       sub edx,offset @@StartCode
  1338.       mov dword ptr [ecx+edx],eax
  1339.  
  1340.       {  @@_ZBuf  }
  1341.       mov eax,_ZBuf
  1342.       mov edx,offset @@_ZBuf-4
  1343.       sub edx,offset @@StartCode
  1344.       mov dword ptr [ecx+edx],eax
  1345.     end;
  1346.   end;
  1347.  
  1348.   procedure genZBufferTest(var Code: Pointer);
  1349.   var
  1350.     _ZBuf, _RHW: Pointer;
  1351.   begin
  1352.     if not ZBuffer.Enable then Exit;
  1353.  
  1354.     _ZBuf := @F_ZBuf;
  1355.     _RHW := @RHW.nRHW;
  1356.  
  1357.     asm
  1358.       jmp @@EndCode
  1359.     @@StartCode:
  1360.       mov edx,dword ptr [offset _null]{}@@_ZBuf:
  1361.       mov ebx,dword ptr [offset _null]{}@@_RHW:
  1362.     @@EndCode:
  1363.       {$I DXRender.inc}
  1364.       {  @@_ZBuf  }
  1365.       mov eax,_ZBuf
  1366.       mov edx,offset @@_ZBuf-4
  1367.       sub edx,offset @@StartCode
  1368.       mov dword ptr [ecx+edx],eax
  1369.  
  1370.       {  @@_RHW  }
  1371.       mov eax,_RHW; add eax,4
  1372.       mov edx,offset @@_RHW-4
  1373.       sub edx,offset @@StartCode
  1374.       mov dword ptr [ecx+edx],eax
  1375.     end;
  1376.  
  1377.     if ZBuffer.CmpFunc<>DXR_CMPFUNC_ALWAYS then
  1378.     begin
  1379.       case ZBuffer.Surface.BitCount of
  1380.         8: begin
  1381.              asm
  1382.                jmp @@EndCode
  1383.              @@StartCode:
  1384.                movzx eax,byte ptr [edx]
  1385.              @@EndCode:
  1386.                {$I DXRender.inc}
  1387.              end;
  1388.            end;
  1389.        16: begin
  1390.              asm
  1391.                jmp @@EndCode
  1392.              @@StartCode:
  1393.                movzx eax,word ptr [edx]
  1394.              @@EndCode:
  1395.                {$I DXRender.inc}
  1396.              end;
  1397.            end;
  1398.        24: begin
  1399.              asm
  1400.                jmp @@EndCode
  1401.              @@StartCode:
  1402.                movzx ax,byte ptr [edx+2]
  1403.                shl eax,16
  1404.                mov ax,word ptr [edx]
  1405.              @@EndCode:
  1406.                {$I DXRender.inc}
  1407.              end;
  1408.            end;
  1409.        32: begin
  1410.              asm
  1411.                jmp @@EndCode
  1412.              @@StartCode:
  1413.                mov eax,dword ptr [edx]
  1414.              @@EndCode:
  1415.                {$I DXRender.inc}
  1416.              end;
  1417.            end;
  1418.       end;
  1419.  
  1420.       asm
  1421.         jmp @@EndCode
  1422.       @@StartCode:
  1423.         cmp eax,ebx
  1424.       @@EndCode:
  1425.         {$I DXRender.inc}
  1426.       end;
  1427.       genCmpFunc(Code, ZBuffer.CmpFunc, SkipAddress);
  1428.     end;
  1429.  
  1430.     if ZBuffer.WriteEnable then
  1431.     begin
  1432.       case ZBuffer.Surface.BitCount of
  1433.         8: begin
  1434.              asm
  1435.                jmp @@EndCode
  1436.              @@StartCode:
  1437.                mov byte ptr [edx],bl
  1438.              @@EndCode:
  1439.                {$I DXRender.inc}
  1440.              end;
  1441.            end;
  1442.        16: begin
  1443.              asm
  1444.                jmp @@EndCode
  1445.              @@StartCode:
  1446.                mov word ptr [edx],bx
  1447.              @@EndCode:
  1448.                {$I DXRender.inc}
  1449.              end;
  1450.            end;
  1451.        24: begin
  1452.              asm
  1453.                jmp @@EndCode
  1454.              @@StartCode:
  1455.                mov word ptr [edx],bx
  1456.                bswap ebx
  1457.                mov byte ptr [edx+2],bh
  1458.              @@EndCode:
  1459.                {$I DXRender.inc}
  1460.              end;
  1461.            end;
  1462.        32: begin
  1463.              asm
  1464.                jmp @@EndCode
  1465.              @@StartCode:
  1466.                mov dword ptr [edx],ebx
  1467.              @@EndCode:
  1468.                {$I DXRender.inc}
  1469.              end;
  1470.            end;
  1471.       end;
  1472.     end;
  1473.   end;
  1474.  
  1475.   procedure genUpdateZBufferAddress(var Code: Pointer);
  1476.   var
  1477.     ByteCount: DWORD;
  1478.     _ZBuf: Pointer;
  1479.   begin
  1480.     if not ZBuffer.Enable then Exit;
  1481.  
  1482.     ByteCount := ZBuffer.Surface.BitCount shr 3;
  1483.  
  1484.     _ZBuf := @F_ZBuf;
  1485.  
  1486.     asm
  1487.       jmp @@EndCode
  1488.     @@StartCode:
  1489.       add dword ptr [offset _null],$11{}@@_ZBuf:
  1490.     @@EndCode:
  1491.       {$I DXRender.inc}
  1492.       {  @@_ZBuf  }
  1493.       mov eax,ByteCount
  1494.       mov edx,offset @@_ZBuf-1
  1495.       sub edx,offset @@StartCode
  1496.       mov byte ptr [ecx+edx],al
  1497.  
  1498.       {  @@_ZBuf  }
  1499.       mov eax,_ZBuf
  1500.       mov edx,offset @@_ZBuf-5
  1501.       sub edx,offset @@StartCode
  1502.       mov dword ptr [ecx+edx],eax
  1503.     end;
  1504.   end;
  1505.  
  1506.   procedure genReadDestPixel(var Code: Pointer);
  1507.   begin
  1508.     case Dest.BitCount of
  1509.       8: begin
  1510.            asm
  1511.              jmp @@EndCode
  1512.            @@StartCode:
  1513.              movzx eax,byte ptr [edi]
  1514.            @@EndCode:
  1515.              {$I DXRender.inc}
  1516.            end;
  1517.          end;
  1518.      16: begin
  1519.            asm
  1520.              jmp @@EndCode
  1521.            @@StartCode:
  1522.              movzx eax,word ptr [edi]
  1523.            @@EndCode:
  1524.              {$I DXRender.inc}
  1525.            end;
  1526.          end;
  1527.      24: begin
  1528.            asm
  1529.              jmp @@EndCode
  1530.            @@StartCode:
  1531.              movzx eax,byte ptr [edi+2]
  1532.              shl eax,16
  1533.              mov ax,word ptr [edi]
  1534.            @@EndCode:
  1535.              {$I DXRender.inc}
  1536.            end;
  1537.          end;
  1538.      32: begin
  1539.            asm
  1540.              jmp @@EndCode
  1541.            @@StartCode:
  1542.              mov eax,dword ptr [edi]
  1543.            @@EndCode:
  1544.              {$I DXRender.inc}
  1545.            end;
  1546.          end;
  1547.     end;
  1548.   end;
  1549.  
  1550.   procedure genWriteDestPixel(var Code: Pointer);
  1551.   begin
  1552.     case Dest.BitCount of
  1553.       8: begin
  1554.            asm
  1555.              jmp @@EndCode
  1556.            @@StartCode:
  1557.              mov byte ptr [edi],al
  1558.            @@EndCode:
  1559.              {$I DXRender.inc}
  1560.            end;
  1561.          end;
  1562.      16: begin
  1563.            asm
  1564.              jmp @@EndCode
  1565.            @@StartCode:
  1566.              mov word ptr [edi],ax
  1567.            @@EndCode:
  1568.              {$I DXRender.inc}
  1569.            end;
  1570.          end;
  1571.      24: begin
  1572.            asm
  1573.              jmp @@EndCode
  1574.            @@StartCode:
  1575.              mov word ptr [edi],ax
  1576.              bswap eax
  1577.              mov byte ptr [edi+2],ah
  1578.            @@EndCode:
  1579.              {$I DXRender.inc}
  1580.            end;
  1581.          end;
  1582.      32: begin
  1583.            asm
  1584.              jmp @@EndCode
  1585.            @@StartCode:
  1586.              mov dword ptr [edi],eax
  1587.            @@EndCode:
  1588.              {$I DXRender.inc}
  1589.            end;
  1590.          end;
  1591.     end;
  1592.   end;
  1593.  
  1594.   procedure genUpdateDestAddress(var Code: Pointer);
  1595.   var
  1596.     ByteCount: DWORD;
  1597.   begin
  1598.     ByteCount := Dest.BitCount shr 3;
  1599.  
  1600.     if ByteCount=1 then
  1601.     begin
  1602.       asm
  1603.         jmp @@EndCode
  1604.       @@StartCode:
  1605.         inc edi
  1606.       @@EndCode:
  1607.         {$I DXRender.inc}
  1608.       end;
  1609.     end else
  1610.     begin
  1611.       asm
  1612.         jmp @@EndCode
  1613.       @@StartCode:
  1614.         add edi,$11{}@@ByteCount:    // Dest.BitCount div 8;
  1615.       @@EndCode:
  1616.         {$I DXRender.inc}
  1617.         {  @@ByteCount  }
  1618.         mov eax,ByteCount
  1619.         mov edx,offset @@ByteCount-1
  1620.         sub edx,offset @@StartCode
  1621.         mov byte ptr [ecx+edx],al
  1622.       end;
  1623.     end;
  1624.   end;
  1625.  
  1626.   procedure genReadSurfacePixel_Tile(var Code: Pointer; const Source: TDXR_Surface; Axis: PDXRMachine_Axis);
  1627.   begin
  1628.     case Source.BitCount of
  1629.       1: begin
  1630.            asm
  1631.              jmp @@EndCode
  1632.            @@StartCode:
  1633.              mov esi,dword ptr [offset _null]{}//TexY
  1634.                                  @@TexY:
  1635.              shr esi,16
  1636.              and esi,$11111111{} @@MaskY:   // Source.HeightMask
  1637.              imul esi,$11111111{}@@Pitch:   // Source.pitch
  1638.              mov edx,dword ptr [offset _null]{}//TexX
  1639.                                  @@TexX:
  1640.              shr edx,16
  1641.              and edx,$11111111{} @@MaskX:   // Source.WidthMask
  1642.              mov ebx,edx
  1643.              shr edx,3
  1644.              and ebx,7
  1645.              movzx eax,byte ptr [esi+edx+$11111111]
  1646.                                  @@Bits:   // Source.Bits
  1647.              and eax,dword ptr [offset Mask1+ebx*4]
  1648.              push ecx
  1649.              mov ecx,dword ptr [offset Shift1+ebx*4]
  1650.              shr eax,cl
  1651.              pop ecx
  1652.            @@EndCode:
  1653.              {$I DXRender.inc}
  1654.              {  @@TexX  }
  1655.              mov eax,Axis; add eax,TDXRMachine_Axis.X
  1656.              mov edx,offset @@TexX-4
  1657.              sub edx,offset @@StartCode
  1658.              mov dword ptr [ecx+edx],eax
  1659.  
  1660.              {  @@TexY  }
  1661.              mov eax,Axis; add eax,TDXRMachine_Axis.Y
  1662.              mov edx,offset @@TexY-4
  1663.              sub edx,offset @@StartCode
  1664.              mov dword ptr [ecx+edx],eax
  1665.  
  1666.              {  @@MaskY  }
  1667.              mov eax,Source; mov eax,[eax + TDXR_Surface.HeightMask]
  1668.              mov edx,offset @@MaskY-4
  1669.              sub edx,offset @@StartCode
  1670.              mov dword ptr [ecx+edx],eax
  1671.  
  1672.              {  @@Pitch  }
  1673.              mov eax,Source; mov eax,[eax + TDXR_Surface.Pitch]
  1674.              mov edx,offset @@Pitch-4
  1675.              sub edx,offset @@StartCode
  1676.              mov dword ptr [ecx+edx],eax
  1677.  
  1678.              {  @@MaskX  }
  1679.              mov eax,Source; mov eax,[eax + TDXR_Surface.WidthMask]
  1680.              mov edx,offset @@MaskX-4
  1681.              sub edx,offset @@StartCode
  1682.              mov dword ptr [ecx+edx],eax
  1683.  
  1684.              {  @@Bits  }
  1685.              mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  1686.              mov edx,offset @@Bits-4
  1687.              sub edx,offset @@StartCode
  1688.              mov dword ptr [ecx+edx],eax
  1689.            end;
  1690.          end;
  1691.       2: begin
  1692.            asm
  1693.              jmp @@EndCode
  1694.            @@StartCode:
  1695.              mov esi,dword ptr [offset _null]{}//TexY
  1696.                                  @@TexY:
  1697.              shr esi,16
  1698.              and esi,$11111111{} @@MaskY:  // Source.HeightMask
  1699.              imul esi,$11111111{}@@Pitch:  // Source.pitch
  1700.              mov edx,dword ptr [offset _null]{}//TexX
  1701.                                  @@TexX:
  1702.              shr edx,16
  1703.              and edx,$11111111{} @@MaskX:  // Source.WidthMask
  1704.              mov ebx,edx
  1705.              shr edx,2
  1706.              and ebx,3
  1707.              movzx eax,byte ptr [esi+edx+$11111111]
  1708.                                  @@Bits:   // Source.Bits
  1709.              and eax,dword ptr [offset Mask2+ebx*4]
  1710.              push ecx
  1711.              mov ecx,dword ptr [offset Shift2+ebx*4]
  1712.              shr eax,cl
  1713.              pop ecx
  1714.            @@EndCode:
  1715.              {$I DXRender.inc}
  1716.              {  @@TexX  }
  1717.              mov eax,Axis; add eax,TDXRMachine_Axis.X
  1718.              mov edx,offset @@TexX-4
  1719.              sub edx,offset @@StartCode
  1720.              mov dword ptr [ecx+edx],eax
  1721.  
  1722.              {  @@TexY  }
  1723.              mov eax,Axis; add eax,TDXRMachine_Axis.Y
  1724.              mov edx,offset @@TexY-4
  1725.              sub edx,offset @@StartCode
  1726.              mov dword ptr [ecx+edx],eax
  1727.  
  1728.              {  @@MaskY  }
  1729.              mov eax,Source; mov eax,[eax + TDXR_Surface.HeightMask]
  1730.              mov edx,offset @@MaskY-4
  1731.              sub edx,offset @@StartCode
  1732.              mov dword ptr [ecx+edx],eax
  1733.  
  1734.              {  @@Pitch  }
  1735.              mov eax,Source; mov eax,[eax + TDXR_Surface.Pitch]
  1736.              mov edx,offset @@Pitch-4
  1737.              sub edx,offset @@StartCode
  1738.              mov dword ptr [ecx+edx],eax
  1739.  
  1740.              {  @@MaskX  }
  1741.              mov eax,Source; mov eax,[eax + TDXR_Surface.WidthMask]
  1742.              mov edx,offset @@MaskX-4
  1743.              sub edx,offset @@StartCode
  1744.              mov dword ptr [ecx+edx],eax
  1745.              {  @@Bits  }
  1746.              mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  1747.              mov edx,offset @@Bits-4
  1748.              sub edx,offset @@StartCode
  1749.              mov dword ptr [ecx+edx],eax
  1750.            end;
  1751.          end;
  1752.       4: begin
  1753.            asm
  1754.              jmp @@EndCode
  1755.            @@StartCode:
  1756.              mov esi,dword ptr [offset _null]{}//TexY
  1757.                                  @@TexY:
  1758.              shr esi,16
  1759.              and esi,$11111111{} @@MaskY:  // Source.HeightMask
  1760.              imul esi,$11111111{}@@Pitch:  // Source.pitch
  1761.              mov edx,dword ptr [offset _null]{}//TexX
  1762.                                  @@TexX:
  1763.              shr edx,16
  1764.              and edx,$11111111{} @@MaskX:  // Source.WidthMask
  1765.              mov ebx,edx
  1766.              shr edx,1
  1767.              and ebx,1
  1768.              movzx eax,byte ptr [esi+edx+$11111111]
  1769.                                  @@Bits:   // Source.Bits
  1770.              and eax,dword ptr [offset Mask4+ebx*4]
  1771.              push ecx
  1772.              mov ecx,dword ptr [offset Shift4+ebx*4]
  1773.              shr eax,cl
  1774.              pop ecx
  1775.            @@EndCode:
  1776.              {$I DXRender.inc}
  1777.              {  @@TexX  }
  1778.              mov eax,Axis; add eax,TDXRMachine_Axis.X
  1779.              mov edx,offset @@TexX-4
  1780.              sub edx,offset @@StartCode
  1781.              mov dword ptr [ecx+edx],eax
  1782.  
  1783.              {  @@TexY  }
  1784.              mov eax,Axis; add eax,TDXRMachine_Axis.Y
  1785.              mov edx,offset @@TexY-4
  1786.              sub edx,offset @@StartCode
  1787.              mov dword ptr [ecx+edx],eax
  1788.  
  1789.              {  @@MaskY  }
  1790.              mov eax,Source; mov eax,[eax + TDXR_Surface.HeightMask]
  1791.              mov edx,offset @@MaskY-4
  1792.              sub edx,offset @@StartCode
  1793.              mov dword ptr [ecx+edx],eax
  1794.  
  1795.              {  @@Pitch  }
  1796.              mov eax,Source; mov eax,[eax + TDXR_Surface.Pitch]
  1797.              mov edx,offset @@Pitch-4
  1798.              sub edx,offset @@StartCode
  1799.              mov dword ptr [ecx+edx],eax
  1800.  
  1801.              {  @@MaskX  }
  1802.              mov eax,Source; mov eax,[eax + TDXR_Surface.WidthMask]
  1803.              mov edx,offset @@MaskX-4
  1804.              sub edx,offset @@StartCode
  1805.              mov dword ptr [ecx+edx],eax
  1806.  
  1807.              {  @@Bits  }
  1808.              mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  1809.              mov edx,offset @@Bits-4
  1810.              sub edx,offset @@StartCode
  1811.              mov dword ptr [ecx+edx],eax
  1812.            end;
  1813.          end;
  1814.       8: begin
  1815.            if Source.pitch=(1 shl Source.PitchBit) then
  1816.            begin
  1817.              asm
  1818.                jmp @@EndCode
  1819.              @@StartCode:
  1820.                mov esi,dword ptr [offset _null]{}@@TexY: //TexY
  1821.                mov edx,dword ptr [offset _null]{}@@TexX: //TexX
  1822.                shr esi,$11{}       @@YShift: // 16-Source.PitchBit
  1823.                shr edx,16
  1824.                and esi,$11111111{} @@MaskY:  // Source.HeightMask shl Source.PitchBit
  1825.                and edx,$11111111{} @@MaskX:  // Source.WidthMask
  1826.                movzx eax,byte ptr [$11111111+esi+edx]
  1827.                                    @@Bits:   // Source.Bits
  1828.              @@EndCode:
  1829.                {$I DXRender.inc}
  1830.                {  @@TexX  }
  1831.                mov eax,Axis; add eax,TDXRMachine_Axis.X
  1832.                mov edx,offset @@TexX-4
  1833.                sub edx,offset @@StartCode
  1834.                mov dword ptr [ecx+edx],eax
  1835.  
  1836.                {  @@TexY  }
  1837.                mov eax,Axis; add eax,TDXRMachine_Axis.Y
  1838.                mov edx,offset @@TexY-4
  1839.                sub edx,offset @@StartCode
  1840.                mov dword ptr [ecx+edx],eax
  1841.  
  1842.                {  @@YShift  }
  1843.                push ebx
  1844.                mov eax,16
  1845.                mov ebx,Source; sub eax,[ebx + TDXR_Surface.PitchBit]
  1846.                pop ebx
  1847.                mov edx,offset @@YShift-1
  1848.                sub edx,offset @@StartCode
  1849.                mov byte ptr [ecx+edx],al
  1850.  
  1851.                {  @@MaskY  }
  1852.                push ecx
  1853.                mov ecx,Source; mov ecx,[ecx + TDXR_Surface.PitchBit]
  1854.                mov eax,Source; mov eax,[eax + TDXR_Surface.HeightMask]
  1855.                shl eax,cl
  1856.                pop ecx
  1857.                mov edx,offset @@MaskY-4
  1858.                sub edx,offset @@StartCode
  1859.                mov dword ptr [ecx+edx],eax
  1860.  
  1861.                {  @@MaskX  }
  1862.                mov eax,Source; mov eax,[eax + TDXR_Surface.WidthMask]
  1863.                mov edx,offset @@MaskX-4
  1864.                sub edx,offset @@StartCode
  1865.                mov dword ptr [ecx+edx],eax
  1866.  
  1867.                {  @@Bits  }
  1868.                mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  1869.                mov edx,offset @@Bits-4
  1870.                sub edx,offset @@StartCode
  1871.                mov dword ptr [ecx+edx],eax
  1872.              end;
  1873.            end else
  1874.            if -Source.pitch=(1 shl Source.PitchBit) then
  1875.            begin
  1876.              asm
  1877.                jmp @@EndCode
  1878.              @@StartCode:
  1879.                mov esi,dword ptr [offset _null]{}@@TexY: //TexY
  1880.                mov edx,dword ptr [offset _null]{}@@TexX: //TexX
  1881.                shr esi,$11{}       @@YShift: // 16-Source.PitchBit
  1882.                shr edx,16
  1883.                and esi,$11111111{} @@MaskY:  // Source.HeightMask shl Source.PitchBit
  1884.                and edx,$11111111{} @@MaskX:  // Source.WidthMask
  1885.                neg esi
  1886.                movzx eax,byte ptr [$11111111+esi+edx]
  1887.                                    @@Bits:   // Source.Bits
  1888.              @@EndCode:
  1889.                {$I DXRender.inc}
  1890.                {  @@TexX  }
  1891.                mov eax,Axis; add eax,TDXRMachine_Axis.X
  1892.                mov edx,offset @@TexX-4
  1893.                sub edx,offset @@StartCode
  1894.                mov dword ptr [ecx+edx],eax
  1895.  
  1896.                {  @@TexY  }
  1897.                mov eax,Axis; add eax,TDXRMachine_Axis.Y
  1898.                mov edx,offset @@TexY-4
  1899.                sub edx,offset @@StartCode
  1900.                mov dword ptr [ecx+edx],eax
  1901.  
  1902.                {  @@YShift  }
  1903.                push ebx
  1904.                mov eax,16
  1905.                mov ebx,Source; sub eax,[ebx + TDXR_Surface.PitchBit]
  1906.                pop ebx
  1907.                mov edx,offset @@YShift-1
  1908.                sub edx,offset @@StartCode
  1909.                mov byte ptr [ecx+edx],al
  1910.  
  1911.                {  @@MaskY  }
  1912.                push ecx
  1913.                mov ecx,Source; mov ecx,[ecx + TDXR_Surface.PitchBit]
  1914.                mov eax,Source; mov eax,[eax + TDXR_Surface.HeightMask]
  1915.                shl eax,cl
  1916.                pop ecx
  1917.                mov edx,offset @@MaskY-4
  1918.                sub edx,offset @@StartCode
  1919.                mov dword ptr [ecx+edx],eax
  1920.  
  1921.                {  @@MaskX  }
  1922.                mov eax,Source; mov eax,[eax + TDXR_Surface.WidthMask]
  1923.                mov edx,offset @@MaskX-4
  1924.                sub edx,offset @@StartCode
  1925.                mov dword ptr [ecx+edx],eax
  1926.  
  1927.                {  @@Bits  }
  1928.                mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  1929.                mov edx,offset @@Bits-4
  1930.                sub edx,offset @@StartCode
  1931.                mov dword ptr [ecx+edx],eax
  1932.              end;
  1933.            end else
  1934.            begin
  1935.              asm
  1936.                jmp @@EndCode
  1937.              @@StartCode:
  1938.                mov esi,dword ptr [offset _null]{}@@TexY: //TexY
  1939.                mov edx,dword ptr [offset _null]{}@@TexX: //TexX
  1940.                shr esi,16
  1941.                shr edx,16
  1942.                and esi,$11111111{} @@MaskY:  // Source.HeightMask
  1943.                and edx,$11111111{} @@MaskX:  // Source.WidthMask
  1944.                imul esi,$11111111{}@@Pitch:  // Source.pitch
  1945.                movzx eax,byte ptr [esi+edx+$11111111]
  1946.                                    @@Bits:   // Source.Bits
  1947.              @@EndCode:
  1948.                {$I DXRender.inc}
  1949.                {  @@TexX  }
  1950.                mov eax,Axis; add eax,TDXRMachine_Axis.X
  1951.                mov edx,offset @@TexX-4
  1952.                sub edx,offset @@StartCode
  1953.                mov dword ptr [ecx+edx],eax
  1954.  
  1955.                {  @@TexY  }
  1956.                mov eax,Axis; add eax,TDXRMachine_Axis.Y
  1957.                mov edx,offset @@TexY-4
  1958.                sub edx,offset @@StartCode
  1959.                mov dword ptr [ecx+edx],eax
  1960.  
  1961.                {  @@MaskY  }
  1962.                mov eax,Source; mov eax,[eax + TDXR_Surface.HeightMask]
  1963.                mov edx,offset @@MaskY-4
  1964.                sub edx,offset @@StartCode
  1965.                mov dword ptr [ecx+edx],eax
  1966.  
  1967.                {  @@Pitch  }
  1968.                mov eax,Source; mov eax,[eax + TDXR_Surface.Pitch]
  1969.                mov edx,offset @@Pitch-4
  1970.                sub edx,offset @@StartCode
  1971.                mov dword ptr [ecx+edx],eax
  1972.  
  1973.                {  @@MaskX  }
  1974.                mov eax,Source; mov eax,[eax + TDXR_Surface.WidthMask]
  1975.                mov edx,offset @@MaskX-4
  1976.                sub edx,offset @@StartCode
  1977.                mov dword ptr [ecx+edx],eax
  1978.  
  1979.                {  @@Bits  }
  1980.                mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  1981.                mov edx,offset @@Bits-4
  1982.                sub edx,offset @@StartCode
  1983.                mov dword ptr [ecx+edx],eax
  1984.              end;
  1985.            end;
  1986.          end;
  1987.      16: begin
  1988.            if Source.pitch=(1 shl Source.PitchBit) then
  1989.            begin
  1990.              asm
  1991.                jmp @@EndCode
  1992.              @@StartCode:
  1993.                mov esi,dword ptr [offset _null]{}@@TexY: //TexY
  1994.                mov edx,dword ptr [offset _null]{}@@TexX: //TexX
  1995.                shr esi,$11{}       @@YShift: // 16-Source.PitchBit
  1996.                shr edx,16
  1997.                and esi,$11111111{} @@MaskY:  // Source.HeightMask shl Source.PitchBit
  1998.                and edx,$11111111{} @@MaskX:  // Source.WidthMask
  1999.                movzx eax,word ptr [$11111111+esi+edx*2]
  2000.                                    @@Bits:   // Source.Bits
  2001.              @@EndCode:
  2002.                {$I DXRender.inc}
  2003.                {  @@TexX  }
  2004.                mov eax,Axis; add eax,TDXRMachine_Axis.X
  2005.                mov edx,offset @@TexX-4
  2006.                sub edx,offset @@StartCode
  2007.                mov dword ptr [ecx+edx],eax
  2008.  
  2009.                {  @@TexY  }
  2010.                mov eax,Axis; add eax,TDXRMachine_Axis.Y
  2011.                mov edx,offset @@TexY-4
  2012.                sub edx,offset @@StartCode
  2013.                mov dword ptr [ecx+edx],eax
  2014.  
  2015.                {  @@YShift  }
  2016.                push ebx
  2017.                mov eax,16
  2018.                mov ebx,Source; sub eax,[ebx + TDXR_Surface.PitchBit]
  2019.                pop ebx
  2020.                mov edx,offset @@YShift-1
  2021.                sub edx,offset @@StartCode
  2022.                mov byte ptr [ecx+edx],al
  2023.  
  2024.                {  @@MaskY  }
  2025.                push ecx
  2026.                mov ecx,Source; mov ecx,[ecx + TDXR_Surface.PitchBit]
  2027.                mov eax,Source; mov eax,[eax + TDXR_Surface.HeightMask]
  2028.                shl eax,cl
  2029.                pop ecx
  2030.                mov edx,offset @@MaskY-4
  2031.                sub edx,offset @@StartCode
  2032.                mov dword ptr [ecx+edx],eax
  2033.  
  2034.                {  @@MaskX  }
  2035.                mov eax,Source; mov eax,[eax + TDXR_Surface.WidthMask]
  2036.                mov edx,offset @@MaskX-4
  2037.                sub edx,offset @@StartCode
  2038.                mov dword ptr [ecx+edx],eax
  2039.  
  2040.                {  @@Bits  }
  2041.                mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  2042.                mov edx,offset @@Bits-4
  2043.                sub edx,offset @@StartCode
  2044.                mov dword ptr [ecx+edx],eax
  2045.              end;
  2046.            end else
  2047.            if -Source.pitch=(1 shl Source.PitchBit) then
  2048.            begin
  2049.              asm
  2050.                jmp @@EndCode
  2051.              @@StartCode:
  2052.                mov esi,dword ptr [offset _null]{}@@TexY: //TexY
  2053.                mov edx,dword ptr [offset _null]{}@@TexX: //TexX
  2054.                shr esi,$11{}       @@YShift: // 16-Source.PitchBit
  2055.                shr edx,16
  2056.                and esi,$11111111{} @@MaskY:  // Source.HeightMask shl Source.PitchBit
  2057.                and edx,$11111111{} @@MaskX:  // Source.WidthMask
  2058.                neg esi
  2059.                movzx eax,word ptr [$11111111+esi+edx*2]
  2060.                                    @@Bits:   // Source.Bits
  2061.              @@EndCode:
  2062.                {$I DXRender.inc}
  2063.                {  @@TexX  }
  2064.                mov eax,Axis; add eax,TDXRMachine_Axis.X
  2065.                mov edx,offset @@TexX-4
  2066.                sub edx,offset @@StartCode
  2067.                mov dword ptr [ecx+edx],eax
  2068.  
  2069.                {  @@TexY  }
  2070.                mov eax,Axis; add eax,TDXRMachine_Axis.Y
  2071.                mov edx,offset @@TexY-4
  2072.                sub edx,offset @@StartCode
  2073.                mov dword ptr [ecx+edx],eax
  2074.  
  2075.                {  @@YShift  }
  2076.                push ebx
  2077.                mov eax,16
  2078.                mov ebx,Source; sub eax,[ebx + TDXR_Surface.PitchBit]
  2079.                pop ebx
  2080.                mov edx,offset @@YShift-1
  2081.                sub edx,offset @@StartCode
  2082.                mov byte ptr [ecx+edx],al
  2083.  
  2084.                {  @@MaskY  }
  2085.                push ecx
  2086.                mov ecx,Source; mov ecx,[ecx + TDXR_Surface.PitchBit]
  2087.                mov eax,Source; mov eax,[eax + TDXR_Surface.HeightMask]
  2088.                shl eax,cl
  2089.                pop ecx
  2090.                mov edx,offset @@MaskY-4
  2091.                sub edx,offset @@StartCode
  2092.                mov dword ptr [ecx+edx],eax
  2093.  
  2094.                {  @@MaskX  }
  2095.                mov eax,Source; mov eax,[eax + TDXR_Surface.WidthMask]
  2096.                mov edx,offset @@MaskX-4
  2097.                sub edx,offset @@StartCode
  2098.                mov dword ptr [ecx+edx],eax
  2099.  
  2100.                {  @@Bits  }
  2101.                mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  2102.                mov edx,offset @@Bits-4
  2103.                sub edx,offset @@StartCode
  2104.                mov dword ptr [ecx+edx],eax
  2105.              end;
  2106.            end else
  2107.            begin
  2108.              asm
  2109.                jmp @@EndCode
  2110.              @@StartCode:
  2111.                mov esi,dword ptr [offset _null]{}@@TexY: //TexY
  2112.                mov edx,dword ptr [offset _null]{}@@TexX: //TexX
  2113.                shr esi,16
  2114.                shr edx,16
  2115.                and esi,$11111111{} @@MaskY:  // Source.HeightMask
  2116.                and edx,$11111111{} @@MaskX:  // Source.WidthMask
  2117.                imul esi,$11111111{}@@Pitch:  // Source.pitch
  2118.                movzx eax,word ptr [esi+edx*2+$11111111]
  2119.                                    @@Bits:   // Source.Bits
  2120.              @@EndCode:
  2121.                {$I DXRender.inc}
  2122.                {  @@TexX  }
  2123.                mov eax,Axis; add eax,TDXRMachine_Axis.X
  2124.                mov edx,offset @@TexX-4
  2125.                sub edx,offset @@StartCode
  2126.                mov dword ptr [ecx+edx],eax
  2127.  
  2128.                {  @@TexY  }
  2129.                mov eax,Axis; add eax,TDXRMachine_Axis.Y
  2130.                mov edx,offset @@TexY-4
  2131.                sub edx,offset @@StartCode
  2132.                mov dword ptr [ecx+edx],eax
  2133.  
  2134.                {  @@MaskY  }
  2135.                mov eax,Source; mov eax,[eax + TDXR_Surface.HeightMask]
  2136.                mov edx,offset @@MaskY-4
  2137.                sub edx,offset @@StartCode
  2138.                mov dword ptr [ecx+edx],eax
  2139.  
  2140.                {  @@Pitch  }
  2141.                mov eax,Source; mov eax,[eax + TDXR_Surface.Pitch]
  2142.                mov edx,offset @@Pitch-4
  2143.                sub edx,offset @@StartCode
  2144.                mov dword ptr [ecx+edx],eax
  2145.  
  2146.                {  @@MaskX  }
  2147.                mov eax,Source; mov eax,[eax + TDXR_Surface.WidthMask]
  2148.                mov edx,offset @@MaskX-4
  2149.                sub edx,offset @@StartCode
  2150.                mov dword ptr [ecx+edx],eax
  2151.  
  2152.                {  @@Bits  }
  2153.                mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  2154.                mov edx,offset @@Bits-4
  2155.                sub edx,offset @@StartCode
  2156.                mov dword ptr [ecx+edx],eax
  2157.              end;
  2158.            end;
  2159.          end;
  2160.      24: begin
  2161.            asm
  2162.              jmp @@EndCode
  2163.            @@StartCode:
  2164.              mov esi,dword ptr [offset _null]{}//TexY
  2165.                                  @@TexY:
  2166.              mov edx,dword ptr [offset _null]{}//TexX
  2167.                                  @@TexX:
  2168.              shr esi,16
  2169.              shr edx,16
  2170.              and esi,$11111111{} @@MaskY:  // Source.HeightMask
  2171.              and edx,$11111111{} @@MaskX:  // Source.WidthMask
  2172.              imul esi,$11111111{}@@Pitch:  // Source.pitch
  2173.              lea edx,[edx+edx*2+$11111111] // Source.Bits
  2174.                                  @@Bits:
  2175.              movzx eax,byte ptr [esi+edx+2]
  2176.              shl eax,16
  2177.              mov ax,word ptr [esi+edx]
  2178.            @@EndCode:
  2179.              {$I DXRender.inc}
  2180.              {  @@TexX  }
  2181.              mov eax,Axis; add eax,TDXRMachine_Axis.X
  2182.              mov edx,offset @@TexX-4
  2183.              sub edx,offset @@StartCode
  2184.              mov dword ptr [ecx+edx],eax
  2185.  
  2186.              {  @@TexY  }
  2187.              mov eax,Axis; add eax,TDXRMachine_Axis.Y
  2188.              mov edx,offset @@TexY-4
  2189.              sub edx,offset @@StartCode
  2190.              mov dword ptr [ecx+edx],eax
  2191.  
  2192.              {  @@MaskY  }
  2193.              mov eax,Source; mov eax,[eax + TDXR_Surface.HeightMask]
  2194.              mov edx,offset @@MaskY-4
  2195.              sub edx,offset @@StartCode
  2196.              mov dword ptr [ecx+edx],eax
  2197.  
  2198.              {  @@Pitch  }
  2199.              mov eax,Source; mov eax,[eax + TDXR_Surface.Pitch]
  2200.              mov edx,offset @@Pitch-4
  2201.              sub edx,offset @@StartCode
  2202.              mov dword ptr [ecx+edx],eax
  2203.  
  2204.              {  @@MaskX  }
  2205.              mov eax,Source; mov eax,[eax + TDXR_Surface.WidthMask]
  2206.              mov edx,offset @@MaskX-4
  2207.              sub edx,offset @@StartCode
  2208.              mov dword ptr [ecx+edx],eax
  2209.  
  2210.              {  @@Bits  }
  2211.              mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  2212.              mov edx,offset @@Bits-4
  2213.              sub edx,offset @@StartCode
  2214.              mov dword ptr [ecx+edx],eax
  2215.            end;
  2216.          end;
  2217.      32: begin
  2218.            if Source.pitch=(1 shl Source.PitchBit) then
  2219.            begin
  2220.              asm
  2221.                jmp @@EndCode
  2222.              @@StartCode:
  2223.                mov esi,dword ptr [offset _null]{}@@TexY: //TexY
  2224.                mov edx,dword ptr [offset _null]{}@@TexX: //TexX
  2225.                shr esi,$11{}       @@YShift: // 16-Source.PitchBit
  2226.                shr edx,16
  2227.                and esi,$11111111{} @@MaskY:  // Source.HeightMask shl Source.PitchBit
  2228.                and edx,$11111111{} @@MaskX:  // Source.WidthMask
  2229.                mov eax,dword ptr [$11111111+esi+edx*4]
  2230.                                    @@Bits:   // Source.Bits
  2231.              @@EndCode:
  2232.                {$I DXRender.inc}
  2233.                {  @@TexX  }
  2234.                mov eax,Axis; add eax,TDXRMachine_Axis.X
  2235.                mov edx,offset @@TexX-4
  2236.                sub edx,offset @@StartCode
  2237.                mov dword ptr [ecx+edx],eax
  2238.  
  2239.                {  @@TexY  }
  2240.                mov eax,Axis; add eax,TDXRMachine_Axis.Y
  2241.                mov edx,offset @@TexY-4
  2242.                sub edx,offset @@StartCode
  2243.                mov dword ptr [ecx+edx],eax
  2244.  
  2245.                {  @@YShift  }
  2246.                push ebx
  2247.                mov eax,16
  2248.                mov ebx,Source; sub eax,[ebx + TDXR_Surface.PitchBit]
  2249.                pop ebx
  2250.                mov edx,offset @@YShift-1
  2251.                sub edx,offset @@StartCode
  2252.                mov byte ptr [ecx+edx],al
  2253.  
  2254.                {  @@MaskY  }
  2255.                push ecx
  2256.                mov ecx,Source; mov ecx,[ecx + TDXR_Surface.PitchBit]
  2257.                mov eax,Source; mov eax,[eax + TDXR_Surface.HeightMask]
  2258.                shl eax,cl
  2259.                pop ecx
  2260.                mov edx,offset @@MaskY-4
  2261.                sub edx,offset @@StartCode
  2262.                mov dword ptr [ecx+edx],eax
  2263.  
  2264.                {  @@MaskX  }
  2265.                mov eax,Source; mov eax,[eax + TDXR_Surface.WidthMask]
  2266.                mov edx,offset @@MaskX-4
  2267.                sub edx,offset @@StartCode
  2268.                mov dword ptr [ecx+edx],eax
  2269.  
  2270.                {  @@Bits  }
  2271.                mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  2272.                mov edx,offset @@Bits-4
  2273.                sub edx,offset @@StartCode
  2274.                mov dword ptr [ecx+edx],eax
  2275.              end;
  2276.            end else
  2277.            if -Source.pitch=(1 shl Source.PitchBit) then
  2278.            begin
  2279.              asm
  2280.                jmp @@EndCode
  2281.              @@StartCode:
  2282.                mov esi,dword ptr [offset _null]{}@@TexY: //TexY
  2283.                mov edx,dword ptr [offset _null]{}@@TexX: //TexX
  2284.                shr esi,$11{}       @@YShift: // 16-Source.PitchBit
  2285.                shr edx,16
  2286.                and esi,$11111111{} @@MaskY:  // Source.HeightMask shl Source.PitchBit
  2287.                and edx,$11111111{} @@MaskX:  // Source.WidthMask
  2288.                neg esi
  2289.                mov eax,dword ptr [$11111111+esi+edx*4]
  2290.                                    @@Bits:   // Source.Bits
  2291.              @@EndCode:
  2292.                {$I DXRender.inc}
  2293.                {  @@TexX  }
  2294.                mov eax,Axis; add eax,TDXRMachine_Axis.X
  2295.                mov edx,offset @@TexX-4
  2296.                sub edx,offset @@StartCode
  2297.                mov dword ptr [ecx+edx],eax
  2298.  
  2299.                {  @@TexY  }
  2300.                mov eax,Axis; add eax,TDXRMachine_Axis.Y
  2301.                mov edx,offset @@TexY-4
  2302.                sub edx,offset @@StartCode
  2303.                mov dword ptr [ecx+edx],eax
  2304.  
  2305.                {  @@YShift  }
  2306.                push ebx
  2307.                mov eax,16
  2308.                mov ebx,Source; sub eax,[ebx + TDXR_Surface.PitchBit]
  2309.                pop ebx
  2310.                mov edx,offset @@YShift-1
  2311.                sub edx,offset @@StartCode
  2312.                mov byte ptr [ecx+edx],al
  2313.  
  2314.                {  @@MaskY  }
  2315.                push ecx
  2316.                mov ecx,Source; mov ecx,[ecx + TDXR_Surface.PitchBit]
  2317.                mov eax,Source; mov eax,[eax + TDXR_Surface.HeightMask]
  2318.                shl eax,cl
  2319.                pop ecx
  2320.                mov edx,offset @@MaskY-4
  2321.                sub edx,offset @@StartCode
  2322.                mov dword ptr [ecx+edx],eax
  2323.  
  2324.                {  @@MaskX  }
  2325.                mov eax,Source; mov eax,[eax + TDXR_Surface.WidthMask]
  2326.                mov edx,offset @@MaskX-4
  2327.                sub edx,offset @@StartCode
  2328.                mov dword ptr [ecx+edx],eax
  2329.  
  2330.                {  @@Bits  }
  2331.                mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  2332.                mov edx,offset @@Bits-4
  2333.                sub edx,offset @@StartCode
  2334.                mov dword ptr [ecx+edx],eax
  2335.              end;
  2336.            end else
  2337.            begin
  2338.              asm
  2339.                jmp @@EndCode
  2340.              @@StartCode:
  2341.                mov esi,dword ptr [offset _null]{}@@TexY: //TexY
  2342.                mov edx,dword ptr [offset _null]{}@@TexX: //TexX
  2343.                shr esi,16
  2344.                shr edx,16
  2345.                and esi,$11111111{} @@MaskY:  // Source.HeightMask
  2346.                and edx,$11111111{} @@MaskX:  // Source.WidthMask
  2347.                imul esi,$11111111{}@@Pitch:  // Source.pitch
  2348.                mov eax,dword ptr [esi+edx*4+$11111111]
  2349.                                    @@Bits:   // Source.Bits
  2350.              @@EndCode:
  2351.                {$I DXRender.inc}
  2352.                {  @@TexX  }
  2353.                mov eax,Axis; add eax,TDXRMachine_Axis.X
  2354.                mov edx,offset @@TexX-4
  2355.                sub edx,offset @@StartCode
  2356.                mov dword ptr [ecx+edx],eax
  2357.  
  2358.                {  @@TexY  }
  2359.                mov eax,Axis; add eax,TDXRMachine_Axis.Y
  2360.                mov edx,offset @@TexY-4
  2361.                sub edx,offset @@StartCode
  2362.                mov dword ptr [ecx+edx],eax
  2363.  
  2364.                {  @@MaskY  }
  2365.                mov eax,Source; mov eax,[eax + TDXR_Surface.HeightMask]
  2366.                mov edx,offset @@MaskY-4
  2367.                sub edx,offset @@StartCode
  2368.                mov dword ptr [ecx+edx],eax
  2369.  
  2370.                {  @@Pitch  }
  2371.                mov eax,Source; mov eax,[eax + TDXR_Surface.Pitch]
  2372.                mov edx,offset @@Pitch-4
  2373.                sub edx,offset @@StartCode
  2374.                mov dword ptr [ecx+edx],eax
  2375.  
  2376.                {  @@MaskX  }
  2377.                mov eax,Source; mov eax,[eax + TDXR_Surface.WidthMask]
  2378.                mov edx,offset @@MaskX-4
  2379.                sub edx,offset @@StartCode
  2380.                mov dword ptr [ecx+edx],eax
  2381.  
  2382.                {  @@Bits  }
  2383.                mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  2384.                mov edx,offset @@Bits-4
  2385.                sub edx,offset @@StartCode
  2386.                mov dword ptr [ecx+edx],eax
  2387.              end;
  2388.            end;
  2389.          end;
  2390.     end;
  2391.   end;
  2392.  
  2393.   procedure genReadSurfacePixel_DoNotClip(var Code: Pointer; const Source: TDXR_Surface; Axis: PDXRMachine_Axis);
  2394.   begin
  2395.     case Source.BitCount of
  2396.       1: begin
  2397.            asm
  2398.              jmp @@EndCode
  2399.            @@StartCode:
  2400.              mov esi,dword ptr [offset _null]{}//TexY
  2401.                                  @@TexY:
  2402.              shr esi,16
  2403.              imul esi,$11111111{}@@Pitch:   // Source.pitch
  2404.              mov edx,dword ptr [offset _null]{}//TexX
  2405.                                  @@TexX:
  2406.              shr edx,16
  2407.              mov ebx,edx
  2408.              shr edx,3
  2409.              and ebx,7
  2410.              movzx eax,byte ptr [esi+edx+$11111111]
  2411.                                  @@Bits:   // Source.Bits
  2412.              and eax,dword ptr [offset Mask1+ebx*4]
  2413.              push ecx
  2414.              mov ecx,dword ptr [offset Shift1+ebx*4]
  2415.              shr eax,cl
  2416.              pop ecx
  2417.            @@EndCode:
  2418.              {$I DXRender.inc}
  2419.              {  @@TexX  }
  2420.              mov eax,Axis; add eax,TDXRMachine_Axis.X
  2421.              mov edx,offset @@TexX-4
  2422.              sub edx,offset @@StartCode
  2423.              mov dword ptr [ecx+edx],eax
  2424.  
  2425.              {  @@TexY  }
  2426.              mov eax,Axis; add eax,TDXRMachine_Axis.Y
  2427.              mov edx,offset @@TexY-4
  2428.              sub edx,offset @@StartCode
  2429.              mov dword ptr [ecx+edx],eax
  2430.  
  2431.              {  @@Pitch  }
  2432.              mov eax,Source; mov eax,[eax + TDXR_Surface.Pitch]
  2433.              mov edx,offset @@Pitch-4
  2434.              sub edx,offset @@StartCode
  2435.              mov dword ptr [ecx+edx],eax
  2436.  
  2437.              {  @@Bits  }
  2438.              mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  2439.              mov edx,offset @@Bits-4
  2440.              sub edx,offset @@StartCode
  2441.              mov dword ptr [ecx+edx],eax
  2442.            end;
  2443.          end;
  2444.       2: begin
  2445.            asm
  2446.              jmp @@EndCode
  2447.            @@StartCode:
  2448.              mov esi,dword ptr [offset _null]{}//TexY
  2449.                                  @@TexY:
  2450.              shr esi,16
  2451.              imul esi,$11111111{}@@Pitch:  // Source.pitch
  2452.              mov edx,dword ptr [offset _null]{}//TexX
  2453.                                  @@TexX:
  2454.              shr edx,16
  2455.              mov ebx,edx
  2456.              shr edx,2
  2457.              and ebx,3
  2458.              movzx eax,byte ptr [esi+edx+$11111111]
  2459.                                  @@Bits:   // Source.Bits
  2460.              and eax,dword ptr [offset Mask2+ebx*4]
  2461.              push ecx
  2462.              mov ecx,dword ptr [offset Shift2+ebx*4]
  2463.              shr eax,cl
  2464.              pop ecx
  2465.            @@EndCode:
  2466.              {$I DXRender.inc}
  2467.              {  @@TexX  }
  2468.              mov eax,Axis; add eax,TDXRMachine_Axis.X
  2469.              mov edx,offset @@TexX-4
  2470.              sub edx,offset @@StartCode
  2471.              mov dword ptr [ecx+edx],eax
  2472.  
  2473.              {  @@TexY  }
  2474.              mov eax,Axis; add eax,TDXRMachine_Axis.Y
  2475.              mov edx,offset @@TexY-4
  2476.              sub edx,offset @@StartCode
  2477.              mov dword ptr [ecx+edx],eax
  2478.  
  2479.              {  @@Pitch  }
  2480.              mov eax,Source; mov eax,[eax + TDXR_Surface.Pitch]
  2481.              mov edx,offset @@Pitch-4
  2482.              sub edx,offset @@StartCode
  2483.              mov dword ptr [ecx+edx],eax
  2484.  
  2485.              {  @@Bits  }
  2486.              mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  2487.              mov edx,offset @@Bits-4
  2488.              sub edx,offset @@StartCode
  2489.              mov dword ptr [ecx+edx],eax
  2490.            end;
  2491.          end;
  2492.       4: begin
  2493.            asm
  2494.              jmp @@EndCode
  2495.            @@StartCode:
  2496.              mov esi,dword ptr [offset _null]{}//TexY
  2497.                                  @@TexY:
  2498.              shr esi,16
  2499.              imul esi,$11111111{}@@Pitch:  // Source.pitch
  2500.              mov edx,dword ptr [offset _null]{}//TexX
  2501.                                  @@TexX:
  2502.              shr edx,16
  2503.              mov ebx,edx
  2504.              shr edx,1
  2505.              and ebx,1
  2506.              movzx eax,byte ptr [esi+edx+$11111111]
  2507.                                  @@Bits:   // Source.Bits
  2508.              and eax,dword ptr [offset Mask4+ebx*4]
  2509.              push ecx
  2510.              mov ecx,dword ptr [offset Shift4+ebx*4]
  2511.              shr eax,cl
  2512.              pop ecx
  2513.            @@EndCode:
  2514.              {$I DXRender.inc}
  2515.              {  @@TexX  }
  2516.              mov eax,Axis; add eax,TDXRMachine_Axis.X
  2517.              mov edx,offset @@TexX-4
  2518.              sub edx,offset @@StartCode
  2519.              mov dword ptr [ecx+edx],eax
  2520.  
  2521.              {  @@TexY  }
  2522.              mov eax,Axis; add eax,TDXRMachine_Axis.Y
  2523.              mov edx,offset @@TexY-4
  2524.              sub edx,offset @@StartCode
  2525.              mov dword ptr [ecx+edx],eax
  2526.  
  2527.              {  @@Pitch  }
  2528.              mov eax,Source; mov eax,[eax + TDXR_Surface.Pitch]
  2529.              mov edx,offset @@Pitch-4
  2530.              sub edx,offset @@StartCode
  2531.              mov dword ptr [ecx+edx],eax
  2532.  
  2533.              {  @@Bits  }
  2534.              mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  2535.              mov edx,offset @@Bits-4
  2536.              sub edx,offset @@StartCode
  2537.              mov dword ptr [ecx+edx],eax
  2538.            end;
  2539.          end;
  2540.       8: begin
  2541.            if Source.pitch=(1 shl Source.PitchBit) then
  2542.            begin
  2543.              asm
  2544.                jmp @@EndCode
  2545.              @@StartCode:
  2546.                mov esi,dword ptr [offset _null]{}@@TexY: //TexY
  2547.                mov edx,dword ptr [offset _null]{}@@TexX: //TexX
  2548.                shr esi,16
  2549.                shr edx,16
  2550.                shl esi,$11{}       @@PitchBit: // Source.PitchBit
  2551.                movzx eax,byte ptr [$11111111+esi+edx]
  2552.                                    @@Bits:     // Source.Bits
  2553.              @@EndCode:
  2554.                {$I DXRender.inc}
  2555.                {  @@TexX  }
  2556.                mov eax,Axis; add eax,TDXRMachine_Axis.X
  2557.                mov edx,offset @@TexX-4
  2558.                sub edx,offset @@StartCode
  2559.                mov dword ptr [ecx+edx],eax
  2560.  
  2561.                {  @@TexY  }
  2562.                mov eax,Axis; add eax,TDXRMachine_Axis.Y
  2563.                mov edx,offset @@TexY-4
  2564.                sub edx,offset @@StartCode
  2565.                mov dword ptr [ecx+edx],eax
  2566.  
  2567.                {  @@PitchBit  }
  2568.                mov eax,Source; mov eax,[eax + TDXR_Surface.PitchBit]
  2569.                mov edx,offset @@PitchBit-1
  2570.                sub edx,offset @@StartCode
  2571.                mov byte ptr [ecx+edx],al
  2572.  
  2573.                {  @@Bits  }
  2574.                mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  2575.                mov edx,offset @@Bits-4
  2576.                sub edx,offset @@StartCode
  2577.                mov dword ptr [ecx+edx],eax
  2578.              end;
  2579.            end else
  2580.            if -Source.pitch=(1 shl Source.PitchBit) then
  2581.            begin
  2582.              asm
  2583.                jmp @@EndCode
  2584.              @@StartCode:
  2585.                mov esi,dword ptr [offset _null]{}@@TexY: //TexY
  2586.                mov edx,dword ptr [offset _null]{}@@TexX: //TexX
  2587.                shr esi,16
  2588.                shr edx,16
  2589.                shl esi,$11{}       @@PitchBit: // Source.PitchBit
  2590.                neg esi
  2591.                movzx eax,byte ptr [$11111111+esi+edx]
  2592.                                    @@Bits:     // Source.Bits
  2593.              @@EndCode:
  2594.                {$I DXRender.inc}
  2595.                {  @@TexX  }
  2596.                mov eax,Axis; add eax,TDXRMachine_Axis.X
  2597.                mov edx,offset @@TexX-4
  2598.                sub edx,offset @@StartCode
  2599.                mov dword ptr [ecx+edx],eax
  2600.  
  2601.                {  @@TexY  }
  2602.                mov eax,Axis; add eax,TDXRMachine_Axis.Y
  2603.                mov edx,offset @@TexY-4
  2604.                sub edx,offset @@StartCode
  2605.                mov dword ptr [ecx+edx],eax
  2606.  
  2607.                {  @@PitchBit  }
  2608.                mov eax,Source; mov eax,[eax + TDXR_Surface.PitchBit]
  2609.                mov edx,offset @@PitchBit-1
  2610.                sub edx,offset @@StartCode
  2611.                mov byte ptr [ecx+edx],al
  2612.  
  2613.                {  @@Bits  }
  2614.                mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  2615.                mov edx,offset @@Bits-4
  2616.                sub edx,offset @@StartCode
  2617.                mov dword ptr [ecx+edx],eax
  2618.              end;
  2619.            end else
  2620.            begin
  2621.              asm
  2622.                jmp @@EndCode
  2623.              @@StartCode:
  2624.                mov esi,dword ptr [offset _null]{}@@TexY: //TexY
  2625.                mov edx,dword ptr [offset _null]{}@@TexX: //TexX
  2626.                shr esi,16
  2627.                shr edx,16
  2628.                imul esi,$11111111{}@@Pitch:  // Source.pitch
  2629.                movzx eax,byte ptr [esi+edx+$11111111]
  2630.                                    @@Bits:   // Source.Bits
  2631.              @@EndCode:
  2632.                {$I DXRender.inc}
  2633.                {  @@TexX  }
  2634.                mov eax,Axis; add eax,TDXRMachine_Axis.X
  2635.                mov edx,offset @@TexX-4
  2636.                sub edx,offset @@StartCode
  2637.                mov dword ptr [ecx+edx],eax
  2638.  
  2639.                {  @@TexY  }
  2640.                mov eax,Axis; add eax,TDXRMachine_Axis.Y
  2641.                mov edx,offset @@TexY-4
  2642.                sub edx,offset @@StartCode
  2643.                mov dword ptr [ecx+edx],eax
  2644.  
  2645.                {  @@Pitch  }
  2646.                mov eax,Source; mov eax,[eax + TDXR_Surface.Pitch]
  2647.                mov edx,offset @@Pitch-4
  2648.                sub edx,offset @@StartCode
  2649.                mov dword ptr [ecx+edx],eax
  2650.  
  2651.                {  @@Bits  }
  2652.                mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  2653.                mov edx,offset @@Bits-4
  2654.                sub edx,offset @@StartCode
  2655.                mov dword ptr [ecx+edx],eax
  2656.              end;
  2657.            end;
  2658.          end;
  2659.      16: begin
  2660.            if Source.pitch=(1 shl Source.PitchBit) then
  2661.            begin
  2662.              asm
  2663.                jmp @@EndCode
  2664.              @@StartCode:
  2665.                mov esi,dword ptr [offset _null]{}@@TexY: //TexY
  2666.                mov edx,dword ptr [offset _null]{}@@TexX: //TexX
  2667.                shr esi,16
  2668.                shr edx,16
  2669.                shl esi,$11{}       @@PitchBit: // Source.PitchBit
  2670.                movzx eax,word ptr [$11111111+esi+edx*2]
  2671.                                    @@Bits:     // Source.Bits
  2672.              @@EndCode:
  2673.                {$I DXRender.inc}
  2674.                {  @@TexX  }
  2675.                mov eax,Axis; add eax,TDXRMachine_Axis.X
  2676.                mov edx,offset @@TexX-4
  2677.                sub edx,offset @@StartCode
  2678.                mov dword ptr [ecx+edx],eax
  2679.  
  2680.                {  @@TexY  }
  2681.                mov eax,Axis; add eax,TDXRMachine_Axis.Y
  2682.                mov edx,offset @@TexY-4
  2683.                sub edx,offset @@StartCode
  2684.                mov dword ptr [ecx+edx],eax
  2685.  
  2686.                {  @@PitchBit  }
  2687.                mov eax,Source; mov eax,[eax + TDXR_Surface.PitchBit]
  2688.                mov edx,offset @@PitchBit-1
  2689.                sub edx,offset @@StartCode
  2690.                mov byte ptr [ecx+edx],al
  2691.  
  2692.                {  @@Bits  }
  2693.                mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  2694.                mov edx,offset @@Bits-4
  2695.                sub edx,offset @@StartCode
  2696.                mov dword ptr [ecx+edx],eax
  2697.              end;
  2698.            end else
  2699.            if -Source.pitch=(1 shl Source.PitchBit) then
  2700.            begin
  2701.              asm
  2702.                jmp @@EndCode
  2703.              @@StartCode:
  2704.                mov esi,dword ptr [offset _null]{}@@TexY: //TexY
  2705.                mov edx,dword ptr [offset _null]{}@@TexX: //TexX
  2706.                shr esi,16
  2707.                shr edx,16
  2708.                shl esi,$11{}       @@PitchBit: // Source.PitchBit
  2709.                neg esi
  2710.                movzx eax,word ptr [$11111111+esi+edx*2]
  2711.                                    @@Bits:     // Source.Bits
  2712.              @@EndCode:
  2713.                {$I DXRender.inc}
  2714.                {  @@TexX  }
  2715.                mov eax,Axis; add eax,TDXRMachine_Axis.X
  2716.                mov edx,offset @@TexX-4
  2717.                sub edx,offset @@StartCode
  2718.                mov dword ptr [ecx+edx],eax
  2719.  
  2720.                {  @@TexY  }
  2721.                mov eax,Axis; add eax,TDXRMachine_Axis.Y
  2722.                mov edx,offset @@TexY-4
  2723.                sub edx,offset @@StartCode
  2724.                mov dword ptr [ecx+edx],eax
  2725.  
  2726.                {  @@PitchBit  }
  2727.                mov eax,Source; mov eax,[eax + TDXR_Surface.PitchBit]
  2728.                mov edx,offset @@PitchBit-1
  2729.                sub edx,offset @@StartCode
  2730.                mov byte ptr [ecx+edx],al
  2731.  
  2732.                {  @@Bits  }
  2733.                mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  2734.                mov edx,offset @@Bits-4
  2735.                sub edx,offset @@StartCode
  2736.                mov dword ptr [ecx+edx],eax
  2737.              end;
  2738.            end else
  2739.            begin
  2740.              asm
  2741.                jmp @@EndCode
  2742.              @@StartCode:
  2743.                mov esi,dword ptr [offset _null]{}@@TexY: //TexY
  2744.                mov edx,dword ptr [offset _null]{}@@TexX: //TexX
  2745.                shr esi,16
  2746.                shr edx,16
  2747.                imul esi,$11111111{}@@Pitch:  // Source.pitch
  2748.                movzx eax,word ptr [esi+edx*2+$11111111]
  2749.                                    @@Bits:   // Source.Bits
  2750.              @@EndCode:
  2751.                {$I DXRender.inc}
  2752.                {  @@TexX  }
  2753.                mov eax,Axis; add eax,TDXRMachine_Axis.X
  2754.                mov edx,offset @@TexX-4
  2755.                sub edx,offset @@StartCode
  2756.                mov dword ptr [ecx+edx],eax
  2757.  
  2758.                {  @@TexY  }
  2759.                mov eax,Axis; add eax,TDXRMachine_Axis.Y
  2760.                mov edx,offset @@TexY-4
  2761.                sub edx,offset @@StartCode
  2762.                mov dword ptr [ecx+edx],eax
  2763.  
  2764.                {  @@Pitch  }
  2765.                mov eax,Source; mov eax,[eax + TDXR_Surface.Pitch]
  2766.                mov edx,offset @@Pitch-4
  2767.                sub edx,offset @@StartCode
  2768.                mov dword ptr [ecx+edx],eax
  2769.  
  2770.                {  @@Bits  }
  2771.                mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  2772.                mov edx,offset @@Bits-4
  2773.                sub edx,offset @@StartCode
  2774.                mov dword ptr [ecx+edx],eax
  2775.              end;
  2776.            end;
  2777.          end;
  2778.      24: begin
  2779.            asm
  2780.              jmp @@EndCode
  2781.            @@StartCode:
  2782.              mov esi,dword ptr [offset _null]{}//TexY
  2783.                                  @@TexY:
  2784.              mov edx,dword ptr [offset _null]{}//TexX
  2785.                                  @@TexX:
  2786.              shr esi,16
  2787.              shr edx,16
  2788.              imul esi,$11111111{}@@Pitch:  // Source.pitch
  2789.              lea edx,[edx+edx*2+$11111111] // Source.Bits
  2790.                                  @@Bits:
  2791.              movzx eax,byte ptr [esi+edx+2]
  2792.              shl eax,16
  2793.              mov ax,word ptr [esi+edx]
  2794.            @@EndCode:
  2795.              {$I DXRender.inc}
  2796.              {  @@TexX  }
  2797.              mov eax,Axis; add eax,TDXRMachine_Axis.X
  2798.              mov edx,offset @@TexX-4
  2799.              sub edx,offset @@StartCode
  2800.              mov dword ptr [ecx+edx],eax
  2801.  
  2802.              {  @@TexY  }
  2803.              mov eax,Axis; add eax,TDXRMachine_Axis.Y
  2804.              mov edx,offset @@TexY-4
  2805.              sub edx,offset @@StartCode
  2806.              mov dword ptr [ecx+edx],eax
  2807.  
  2808.              {  @@Pitch  }
  2809.              mov eax,Source; mov eax,[eax + TDXR_Surface.Pitch]
  2810.              mov edx,offset @@Pitch-4
  2811.              sub edx,offset @@StartCode
  2812.              mov dword ptr [ecx+edx],eax
  2813.  
  2814.              {  @@Bits  }
  2815.              mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  2816.              mov edx,offset @@Bits-4
  2817.              sub edx,offset @@StartCode
  2818.              mov dword ptr [ecx+edx],eax
  2819.            end;
  2820.          end;
  2821.      32: begin
  2822.            if Source.pitch=(1 shl Source.PitchBit) then
  2823.            begin
  2824.              asm
  2825.                jmp @@EndCode
  2826.              @@StartCode:
  2827.                mov esi,dword ptr [offset _null]{}@@TexY: //TexY
  2828.                mov edx,dword ptr [offset _null]{}@@TexX: //TexX
  2829.                shr esi,16
  2830.                shr edx,16
  2831.                shl esi,$11{}       @@PitchBit: // Source.PitchBit
  2832.                mov eax,dword ptr [$11111111+esi+edx*4]
  2833.                                    @@Bits:     // Source.Bits
  2834.              @@EndCode:
  2835.                {$I DXRender.inc}
  2836.                {  @@TexX  }
  2837.                mov eax,Axis; add eax,TDXRMachine_Axis.X
  2838.                mov edx,offset @@TexX-4
  2839.                sub edx,offset @@StartCode
  2840.                mov dword ptr [ecx+edx],eax
  2841.  
  2842.                {  @@TexY  }
  2843.                mov eax,Axis; add eax,TDXRMachine_Axis.Y
  2844.                mov edx,offset @@TexY-4
  2845.                sub edx,offset @@StartCode
  2846.                mov dword ptr [ecx+edx],eax
  2847.  
  2848.                {  @@PitchBit  }
  2849.                mov eax,Source; mov eax,[eax + TDXR_Surface.PitchBit]
  2850.                mov edx,offset @@PitchBit-1
  2851.                sub edx,offset @@StartCode
  2852.                mov byte ptr [ecx+edx],al
  2853.  
  2854.                {  @@Bits  }
  2855.                mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  2856.                mov edx,offset @@Bits-4
  2857.                sub edx,offset @@StartCode
  2858.                mov dword ptr [ecx+edx],eax
  2859.              end;
  2860.            end else
  2861.            if -Source.pitch=(1 shl Source.PitchBit) then
  2862.            begin
  2863.              asm
  2864.                jmp @@EndCode
  2865.              @@StartCode:
  2866.                mov esi,dword ptr [offset _null]{}@@TexY: //TexY
  2867.                mov edx,dword ptr [offset _null]{}@@TexX: //TexX
  2868.                shr esi,16
  2869.                shr edx,16
  2870.                shl esi,$11{}       @@PitchBit: // Source.PitchBit
  2871.                neg esi
  2872.                mov eax,dword ptr [$11111111+esi+edx*4]
  2873.                                    @@Bits:     // Source.Bits
  2874.              @@EndCode:
  2875.                {$I DXRender.inc}
  2876.                {  @@TexX  }
  2877.                mov eax,Axis; add eax,TDXRMachine_Axis.X
  2878.                mov edx,offset @@TexX-4
  2879.                sub edx,offset @@StartCode
  2880.                mov dword ptr [ecx+edx],eax
  2881.  
  2882.                {  @@TexY  }
  2883.                mov eax,Axis; add eax,TDXRMachine_Axis.Y
  2884.                mov edx,offset @@TexY-4
  2885.                sub edx,offset @@StartCode
  2886.                mov dword ptr [ecx+edx],eax
  2887.  
  2888.                {  @@PitchBit  }
  2889.                mov eax,Source; mov eax,[eax + TDXR_Surface.PitchBit]
  2890.                mov edx,offset @@PitchBit-1
  2891.                sub edx,offset @@StartCode
  2892.                mov byte ptr [ecx+edx],al
  2893.  
  2894.                {  @@Bits  }
  2895.                mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  2896.                mov edx,offset @@Bits-4
  2897.                sub edx,offset @@StartCode
  2898.                mov dword ptr [ecx+edx],eax
  2899.              end;
  2900.            end else
  2901.            begin
  2902.              asm
  2903.                jmp @@EndCode
  2904.              @@StartCode:
  2905.                mov esi,dword ptr [offset _null]{}@@TexY: //TexY
  2906.                mov edx,dword ptr [offset _null]{}@@TexX: //TexX
  2907.                shr esi,16
  2908.                shr edx,16
  2909.                imul esi,$11111111{}@@Pitch:  // Source.pitch
  2910.                mov eax,dword ptr [esi+edx*4+$11111111]
  2911.                                    @@Bits:   // Source.Bits
  2912.              @@EndCode:
  2913.                {$I DXRender.inc}
  2914.                {  @@TexX  }
  2915.                mov eax,Axis; add eax,TDXRMachine_Axis.X
  2916.                mov edx,offset @@TexX-4
  2917.                sub edx,offset @@StartCode
  2918.                mov dword ptr [ecx+edx],eax
  2919.  
  2920.                {  @@TexY  }
  2921.                mov eax,Axis; add eax,TDXRMachine_Axis.Y
  2922.                mov edx,offset @@TexY-4
  2923.                sub edx,offset @@StartCode
  2924.                mov dword ptr [ecx+edx],eax
  2925.  
  2926.                {  @@Pitch  }
  2927.                mov eax,Source; mov eax,[eax + TDXR_Surface.Pitch]
  2928.                mov edx,offset @@Pitch-4
  2929.                sub edx,offset @@StartCode
  2930.                mov dword ptr [ecx+edx],eax
  2931.  
  2932.                {  @@Bits  }
  2933.                mov eax,Source; mov eax,[eax + TDXR_Surface.Bits]
  2934.                mov edx,offset @@Bits-4
  2935.                sub edx,offset @@StartCode
  2936.                mov dword ptr [ecx+edx],eax
  2937.              end;
  2938.            end;
  2939.          end;
  2940.     end;
  2941.   end;
  2942.  
  2943.   procedure genReadSurfacePixel(var Code: Pointer; const Texture: TDXRMachine_Reg_Texture; Axis: PDXRMachine_Axis);
  2944.   begin
  2945.     case Texture.TextureAddress of
  2946.       DXR_TEXTUREADDRESS_TILE     : genReadSurfacePixel_Tile(Code, Texture.Surface^, Axis);
  2947.       DXR_TEXTUREADDRESS_DONOTCLIP: genReadSurfacePixel_DoNotClip(Code, Texture.Surface^, Axis);
  2948.     end;
  2949.   end;
  2950.  
  2951.   procedure genDecodeColor(var Code: Pointer; const Surface: TDXR_Surface; Dest: PDXRMachine_Color;
  2952.     EnableChannels: TDXRColorChannels; DefaultColor: TDXRMachine_Color);
  2953.   var
  2954.     dcR, dcG, dcB, dcA: Word;
  2955.   begin
  2956.     if EnableChannels=[] then Exit;
  2957.  
  2958.     dcR := DefaultColor.R;
  2959.     dcG := DefaultColor.G;
  2960.     dcB := DefaultColor.B;
  2961.     dcA := DefaultColor.A;
  2962.  
  2963.     if Surface.ColorType=DXR_COLORTYPE_INDEXED then
  2964.     begin
  2965.       {  Index Channel  }
  2966.       if EnableChannels*[chRed, chGreen, chBlue]<>[] then
  2967.       begin
  2968.         if Surface.idx_index.Mask<>0 then
  2969.         begin
  2970.           if (Surface.idx_index.rshift=0) and (Surface.idx_index.lshift=0) and
  2971.             (Surface.idx_index.Mask=DWORD((1 shl Surface.BitCount)-1)) and (Surface.idx_alpha.Mask=0) then
  2972.           begin
  2973.             asm
  2974.               jmp @@EndCode
  2975.             @@StartCode:
  2976.               {  Index channel  }
  2977.               mov edx,dword ptr [eax*4+$11111111]
  2978.                                   {}@@idx_indexPal:// @Surface.idx_palette
  2979.  
  2980.               mov byte ptr [offset _null],dl{}@@DestR:// @Dest.R
  2981.               mov byte ptr [offset _null],dh{}@@DestG:// @Dest.G
  2982.               bswap edx
  2983.               mov byte ptr [offset _null],dh{}@@DestB:// @Dest.B
  2984.             @@EndCode:
  2985.               {$I DXRender.inc}
  2986.               {  @@idx_indexPal  }
  2987.               mov eax,Surface; lea eax,dword ptr [eax + TDXR_Surface.idx_palette]
  2988.               mov edx,offset @@idx_indexPal-4
  2989.               sub edx,offset @@StartCode
  2990.               mov dword ptr [ecx+edx],eax
  2991.  
  2992.               {  @@DestR  }
  2993.               mov eax,Dest; add eax,Byte(TDXRMachine_Color.R+1)
  2994.               mov edx,offset @@DestR-4
  2995.               sub edx,offset @@StartCode
  2996.               mov dword ptr [ecx+edx],eax
  2997.  
  2998.               {  @@DestG  }
  2999.               mov eax,Dest; add eax,Byte(TDXRMachine_Color.G+1)
  3000.               mov edx,offset @@DestG-4
  3001.               sub edx,offset @@StartCode
  3002.               mov dword ptr [ecx+edx],eax
  3003.  
  3004.               {  @@DestB  }
  3005.               mov eax,Dest; add eax,Byte(TDXRMachine_Color.B+1)
  3006.               mov edx,offset @@DestB-4
  3007.               sub edx,offset @@StartCode
  3008.               mov dword ptr [ecx+edx],eax
  3009.             end;
  3010.           end else
  3011.           if Surface.idx_index.rshift<>0 then
  3012.           begin
  3013.             asm
  3014.               jmp @@EndCode
  3015.             @@StartCode:
  3016.               {  Index channel  }
  3017.               mov edx,eax
  3018.               and edx,$11111111{}@@idx_indexMask:   // Surface.idx_index.Mask
  3019.               shr edx,$11      {}@@idx_indexRShift: // Surface.idx_index.rshift
  3020.               mov edx,dword ptr [edx*4+$11111111]
  3021.                                {}@@idx_indexPal:    // @Surface.idx_palette
  3022.  
  3023.               mov byte ptr [offset _null],dl{}@@DestR:// @Dest.R
  3024.               mov byte ptr [offset _null],dh{}@@DestG:// @Dest.G
  3025.               bswap edx
  3026.               mov byte ptr [offset _null],dh{}@@DestB:// @Dest.B
  3027.             @@EndCode:
  3028.               {$I DXRender.inc}
  3029.               {  @@idx_indexMask  }
  3030.               mov eax,Surface; mov eax,[eax + TDXR_Surface.idx_index.Mask]
  3031.               mov edx,offset @@idx_indexMask-4
  3032.               sub edx,offset @@StartCode
  3033.               mov dword ptr [ecx+edx],eax
  3034.  
  3035.               {  @@idx_indexRShift  }
  3036.               mov eax,Surface; mov eax,[eax + TDXR_Surface.idx_index.rshift]
  3037.               mov edx,offset @@idx_indexRShift-1
  3038.               sub edx,offset @@StartCode
  3039.               mov byte ptr [ecx+edx],al
  3040.  
  3041.               {  @@idx_indexPal  }
  3042.               mov eax,Surface; lea eax,dword ptr [eax + TDXR_Surface.idx_palette]
  3043.               mov edx,offset @@idx_indexPal-4
  3044.               sub edx,offset @@StartCode
  3045.               mov dword ptr [ecx+edx],eax
  3046.  
  3047.               {  @@DestR  }
  3048.               mov eax,Dest; add eax,Byte(TDXRMachine_Color.R+1)
  3049.               mov edx,offset @@DestR-4
  3050.               sub edx,offset @@StartCode
  3051.               mov dword ptr [ecx+edx],eax
  3052.  
  3053.               {  @@DestG  }
  3054.               mov eax,Dest; add eax,Byte(TDXRMachine_Color.G+1)
  3055.               mov edx,offset @@DestG-4
  3056.               sub edx,offset @@StartCode
  3057.               mov dword ptr [ecx+edx],eax
  3058.  
  3059.               {  @@DestB  }
  3060.               mov eax,Dest; add eax,Byte(TDXRMachine_Color.B+1)
  3061.               mov edx,offset @@DestB-4
  3062.               sub edx,offset @@StartCode
  3063.               mov dword ptr [ecx+edx],eax
  3064.             end;
  3065.           end else
  3066.           begin
  3067.             asm
  3068.               jmp @@EndCode
  3069.             @@StartCode:
  3070.               {  Index channel  }
  3071.               mov edx,eax
  3072.               and edx,$11111111{}@@idx_indexMask:   // Surface.idx_index.Mask
  3073.               shl edx,$11      {}@@idx_indexLShift: // Surface.idx_index.lshift
  3074.               mov edx,dword ptr [edx*4+$11111111]
  3075.                                {}@@idx_indexPal:    // @Surface.idx_palette
  3076.  
  3077.               mov byte ptr [offset _null],dl{}@@DestR:// @Dest.R
  3078.               mov byte ptr [offset _null],dh{}@@DestG:// @Dest.G
  3079.               bswap edx
  3080.               mov byte ptr [offset _null],dh{}@@DestB:// @Dest.B
  3081.             @@EndCode:
  3082.               {$I DXRender.inc}
  3083.               {  @@idx_indexMask  }
  3084.               mov eax,Surface; mov eax,[eax + TDXR_Surface.idx_index.Mask]
  3085.               mov edx,offset @@idx_indexMask-4
  3086.               sub edx,offset @@StartCode
  3087.               mov dword ptr [ecx+edx],eax
  3088.  
  3089.               {  @@idx_indexLShift  }
  3090.               mov eax,Surface; mov eax,[eax + TDXR_Surface.idx_index.lshift]
  3091.               mov edx,offset @@idx_indexLShift-1
  3092.               sub edx,offset @@StartCode
  3093.               mov byte ptr [ecx+edx],al
  3094.  
  3095.               {  @@idx_indexPal  }
  3096.               mov eax,Surface; lea eax,dword ptr [eax + TDXR_Surface.idx_palette]
  3097.               mov edx,offset @@idx_indexPal-4
  3098.               sub edx,offset @@StartCode
  3099.               mov dword ptr [ecx+edx],eax
  3100.  
  3101.               {  @@DestR  }
  3102.               mov eax,Dest; add eax,Byte(TDXRMachine_Color.R+1)
  3103.               mov edx,offset @@DestR-4
  3104.               sub edx,offset @@StartCode
  3105.               mov dword ptr [ecx+edx],eax
  3106.  
  3107.               {  @@DestG  }
  3108.               mov eax,Dest; add eax,Byte(TDXRMachine_Color.G+1)
  3109.               mov edx,offset @@DestG-4
  3110.               sub edx,offset @@StartCode
  3111.               mov dword ptr [ecx+edx],eax
  3112.  
  3113.               {  @@DestB  }
  3114.               mov eax,Dest; add eax,Byte(TDXRMachine_Color.B+1)
  3115.               mov edx,offset @@DestB-4
  3116.               sub edx,offset @@StartCode
  3117.               mov dword ptr [ecx+edx],eax
  3118.             end;
  3119.           end;
  3120.         end else
  3121.         begin
  3122.           asm
  3123.             jmp @@EndCode
  3124.           @@StartCode:
  3125.             mov word ptr [offset _null],$1111{}@@DestR:// @Dest.R
  3126.             mov word ptr [offset _null],$1111{}@@DestG:// @Dest.G
  3127.             mov word ptr [offset _null],$1111{}@@DestB:// @Dest.B
  3128.           @@EndCode:
  3129.             {$I DXRender.inc}
  3130.             {  @@DestR  }
  3131.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.R)
  3132.             mov edx,offset @@DestR-6
  3133.             sub edx,offset @@StartCode
  3134.             mov dword ptr [ecx+edx],eax
  3135.  
  3136.             mov ax,dcR
  3137.             mov edx,offset @@DestR-2
  3138.             sub edx,offset @@StartCode
  3139.             mov word ptr [ecx+edx],ax
  3140.  
  3141.             {  @@DestG  }
  3142.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.G)
  3143.             mov edx,offset @@DestG-6
  3144.             sub edx,offset @@StartCode
  3145.             mov dword ptr [ecx+edx],eax
  3146.  
  3147.             mov ax,dcG
  3148.             mov edx,offset @@DestG-2
  3149.             sub edx,offset @@StartCode
  3150.             mov word ptr [ecx+edx],ax
  3151.  
  3152.             {  @@DestB  }
  3153.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.B)
  3154.             mov edx,offset @@DestB-6
  3155.             sub edx,offset @@StartCode
  3156.             mov dword ptr [ecx+edx],eax
  3157.  
  3158.             mov ax,dcB
  3159.             mov edx,offset @@DestB-2
  3160.             sub edx,offset @@StartCode
  3161.             mov word ptr [ecx+edx],ax
  3162.           end;
  3163.         end;
  3164.       end;
  3165.  
  3166.       {  Alpha Channel  }
  3167.       if chAlpha in EnableChannels then
  3168.       begin
  3169.         if Surface.idx_alpha.Mask<>0 then
  3170.         begin
  3171.           if Surface.idx_alpha.rshift<>0 then
  3172.           begin
  3173.             asm
  3174.               jmp @@EndCode
  3175.             @@StartCode:
  3176.               mov edx,eax
  3177.               and edx,$11111111{}@@idx_alphaMask:   // Surface.idx_alpha.Mask
  3178.               shr edx,$11      {}@@idx_alphaRShift: // Surface.idx_alpha.rshift
  3179.               mov byte ptr [offset _null],dl{}@@Dest:// @Dest.A
  3180.             @@EndCode:
  3181.               {$I DXRender.inc}
  3182.               {  @@idx_alphaMask  }
  3183.               mov eax,Surface; mov eax,[eax + TDXR_Surface.idx_alpha.Mask]
  3184.               mov edx,offset @@idx_alphaMask-4
  3185.               sub edx,offset @@StartCode
  3186.               mov dword ptr [ecx+edx],eax
  3187.  
  3188.               {  @@idx_alphaRShift  }
  3189.               mov eax,Surface; mov eax,[eax + TDXR_Surface.idx_alpha.rshift]
  3190.               mov edx,offset @@idx_alphaRShift-1
  3191.               sub edx,offset @@StartCode
  3192.               mov byte ptr [ecx+edx],al
  3193.  
  3194.               {  @@Dest  }
  3195.               mov eax,Dest; add eax,Byte(TDXRMachine_Color.A+1)
  3196.               mov edx,offset @@Dest-4
  3197.               sub edx,offset @@StartCode
  3198.               mov dword ptr [ecx+edx],eax
  3199.             end;
  3200.           end else
  3201.           begin
  3202.             asm
  3203.               jmp @@EndCode
  3204.             @@StartCode:
  3205.               mov edx,eax
  3206.               and edx,$11111111{}@@idx_alphaMask:   // Surface.idx_alpha.Mask
  3207.               shl edx,$11      {}@@idx_alphaLShift: // Surface.idx_alpha.lshift
  3208.               mov byte ptr [offset _null],dl{}@@Dest:// @Dest.A
  3209.             @@EndCode:
  3210.               {$I DXRender.inc}
  3211.               {  @@idx_alphaMask  }
  3212.               mov eax,Surface; mov eax,[eax + TDXR_Surface.idx_alpha.Mask]
  3213.               mov edx,offset @@idx_alphaMask-4
  3214.               sub edx,offset @@StartCode
  3215.               mov dword ptr [ecx+edx],eax
  3216.  
  3217.               {  @@idx_alphaLShift  }
  3218.               mov eax,Surface; mov eax,[eax + TDXR_Surface.idx_alpha.lshift]
  3219.               mov edx,offset @@idx_alphaLShift-1
  3220.               sub edx,offset @@StartCode
  3221.               mov byte ptr [ecx+edx],al
  3222.  
  3223.               {  @@Dest  }
  3224.               mov eax,Dest; add eax,Byte(TDXRMachine_Color.A+1)
  3225.               mov edx,offset @@Dest-4
  3226.               sub edx,offset @@StartCode
  3227.               mov dword ptr [ecx+edx],eax
  3228.             end;
  3229.           end;
  3230.         end else
  3231.         begin
  3232.           asm
  3233.             jmp @@EndCode
  3234.           @@StartCode:
  3235.             mov word ptr [offset _null],$1111{}@@Dest:// @Dest.A
  3236.           @@EndCode:
  3237.             {$I DXRender.inc}
  3238.             {  @@Dest  }
  3239.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.A)
  3240.             mov edx,offset @@Dest-6
  3241.             sub edx,offset @@StartCode
  3242.             mov dword ptr [ecx+edx],eax
  3243.  
  3244.             mov ax,dcA
  3245.             mov edx,offset @@Dest-2
  3246.             sub edx,offset @@StartCode
  3247.             mov word ptr [ecx+edx],ax
  3248.           end;
  3249.         end;
  3250.       end;
  3251.     end else if Surface.ColorType=DXR_COLORTYPE_RGB then
  3252.     begin
  3253.       {  Red Channel  }
  3254.       if chRed in EnableChannels then
  3255.       begin
  3256.         if Surface.rgb_red.Mask<>0 then
  3257.         begin
  3258.           if Surface.rgb_red.rshift<>0 then
  3259.           begin
  3260.             asm
  3261.               jmp @@EndCode
  3262.             @@StartCode:
  3263.               mov edx,eax
  3264.               and edx,$11111111{}@@Mask:    // Surface.rgb_red.Mask
  3265.               shr edx,$11      {}@@RShift:  // Surface.rgb_red.rshift
  3266.               mov byte ptr [offset _null],dl{}@@Dest:// @Dest.R
  3267.             @@EndCode:
  3268.               {$I DXRender.inc}
  3269.               {  @@Mask  }
  3270.               mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_red.Mask]
  3271.               mov edx,offset @@Mask-4
  3272.               sub edx,offset @@StartCode
  3273.               mov dword ptr [ecx+edx],eax
  3274.  
  3275.               {  @@RShift  }
  3276.               mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_red.rshift]
  3277.               mov edx,offset @@RShift-1
  3278.               sub edx,offset @@StartCode
  3279.               mov byte ptr [ecx+edx],al
  3280.  
  3281.               {  @@Dest  }
  3282.               mov eax,Dest; add eax,Byte(TDXRMachine_Color.R+1)
  3283.               mov edx,offset @@Dest-4
  3284.               sub edx,offset @@StartCode
  3285.               mov dword ptr [ecx+edx],eax
  3286.             end;
  3287.           end else
  3288.           begin
  3289.             asm
  3290.               jmp @@EndCode
  3291.             @@StartCode:
  3292.               mov edx,eax
  3293.               and edx,$11111111{}@@Mask:    // Surface.rgb_red.Mask
  3294.               shl edx,$11      {}@@LShift:  // Surface.rgb_red.lshift
  3295.               mov byte ptr [offset _null],dl{}@@Dest:// @Dest.R
  3296.             @@EndCode:
  3297.               {$I DXRender.inc}
  3298.               {  @@Mask  }
  3299.               mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_red.Mask]
  3300.               mov edx,offset @@Mask-4
  3301.               sub edx,offset @@StartCode
  3302.               mov dword ptr [ecx+edx],eax
  3303.  
  3304.               {  @@LShift  }
  3305.               mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_red.lshift]
  3306.               mov edx,offset @@LShift-1
  3307.               sub edx,offset @@StartCode
  3308.               mov byte ptr [ecx+edx],al
  3309.  
  3310.               {  @@Dest  }
  3311.               mov eax,Dest; add eax,Byte(TDXRMachine_Color.R+1)
  3312.               mov edx,offset @@Dest-4
  3313.               sub edx,offset @@StartCode
  3314.               mov dword ptr [ecx+edx],eax
  3315.             end;
  3316.           end;
  3317.         end else
  3318.         begin
  3319.           asm
  3320.             jmp @@EndCode
  3321.           @@StartCode:
  3322.             mov word ptr [offset _null],$1111{}@@Dest:// @Dest.R
  3323.           @@EndCode:
  3324.             {$I DXRender.inc}
  3325.             {  @@Dest  }
  3326.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.R)
  3327.             mov edx,offset @@Dest-6
  3328.             sub edx,offset @@StartCode
  3329.             mov dword ptr [ecx+edx],eax
  3330.  
  3331.             mov ax,dcR
  3332.             mov edx,offset @@Dest-2
  3333.             sub edx,offset @@StartCode
  3334.             mov word ptr [ecx+edx],ax
  3335.           end;
  3336.         end;
  3337.       end;
  3338.  
  3339.       {  Green Channel  }
  3340.       if chGreen in EnableChannels then
  3341.       begin
  3342.         if Surface.rgb_green.Mask<>0 then
  3343.         begin
  3344.           if Surface.rgb_green.rshift<>0 then
  3345.           begin
  3346.             asm
  3347.               jmp @@EndCode
  3348.             @@StartCode:
  3349.               mov edx,eax
  3350.               and edx,$11111111{}@@Mask:    // Surface.rgb_green.Mask
  3351.               shr edx,$11      {}@@RShift:  // Surface.rgb_green.rshift
  3352.               mov byte ptr [offset _null],dl{}@@Dest:// @Dest.G
  3353.             @@EndCode:
  3354.               {$I DXRender.inc}
  3355.               {  @@Mask  }
  3356.               mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_green.Mask]
  3357.               mov edx,offset @@Mask-4
  3358.               sub edx,offset @@StartCode
  3359.               mov dword ptr [ecx+edx],eax
  3360.  
  3361.               {  @@RShift  }
  3362.               mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_green.rshift]
  3363.               mov edx,offset @@RShift-1
  3364.               sub edx,offset @@StartCode
  3365.               mov byte ptr [ecx+edx],al
  3366.  
  3367.               {  @@Dest  }
  3368.               mov eax,Dest; add eax,Byte(TDXRMachine_Color.G+1)
  3369.               mov edx,offset @@Dest-4
  3370.               sub edx,offset @@StartCode
  3371.               mov dword ptr [ecx+edx],eax
  3372.             end;
  3373.           end else
  3374.           begin
  3375.             asm
  3376.               jmp @@EndCode
  3377.             @@StartCode:
  3378.               mov edx,eax
  3379.               and edx,$11111111{}@@Mask:    // Surface.rgb_green.Mask
  3380.               shl edx,$11      {}@@LShift:  // Surface.rgb_green.lshift
  3381.               mov byte ptr [offset _null],dl{}@@Dest:// @Dest.G
  3382.             @@EndCode:
  3383.               {$I DXRender.inc}
  3384.               {  @@Mask  }
  3385.               mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_green.Mask]
  3386.               mov edx,offset @@Mask-4
  3387.               sub edx,offset @@StartCode
  3388.               mov dword ptr [ecx+edx],eax
  3389.  
  3390.               {  @@LShift  }
  3391.               mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_green.lshift]
  3392.               mov edx,offset @@LShift-1
  3393.               sub edx,offset @@StartCode
  3394.               mov byte ptr [ecx+edx],al
  3395.  
  3396.               {  @@Dest  }
  3397.               mov eax,Dest; add eax,Byte(TDXRMachine_Color.G+1)
  3398.               mov edx,offset @@Dest-4
  3399.               sub edx,offset @@StartCode
  3400.               mov dword ptr [ecx+edx],eax
  3401.             end;
  3402.           end;
  3403.         end else
  3404.         begin
  3405.           asm
  3406.             jmp @@EndCode
  3407.           @@StartCode:
  3408.             mov word ptr [offset _null],$1111{}@@Dest:// @Dest.G
  3409.           @@EndCode:
  3410.             {$I DXRender.inc}
  3411.             {  @@Dest  }
  3412.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.G)
  3413.             mov edx,offset @@Dest-6
  3414.             sub edx,offset @@StartCode
  3415.             mov dword ptr [ecx+edx],eax
  3416.  
  3417.             mov ax,dcG
  3418.             mov edx,offset @@Dest-2
  3419.             sub edx,offset @@StartCode
  3420.             mov word ptr [ecx+edx],ax
  3421.           end;
  3422.         end;
  3423.       end;
  3424.  
  3425.       {  Blue Channel  }
  3426.       if chBlue in EnableChannels then
  3427.       begin
  3428.         if Surface.rgb_blue.Mask<>0 then
  3429.         begin
  3430.           if Surface.rgb_blue.rshift<>0 then
  3431.           begin
  3432.             asm
  3433.               jmp @@EndCode
  3434.             @@StartCode:
  3435.               mov edx,eax
  3436.               and edx,$11111111{}@@Mask:    // Surface.rgb_blue.Mask
  3437.               shr edx,$11      {}@@RShift:  // Surface.rgb_blue.rshift
  3438.               mov byte ptr [offset _null],dl{}@@Dest:// @Dest.B
  3439.             @@EndCode:
  3440.               {$I DXRender.inc}
  3441.               {  @@Mask  }
  3442.               mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_blue.Mask]
  3443.               mov edx,offset @@Mask-4
  3444.               sub edx,offset @@StartCode
  3445.               mov dword ptr [ecx+edx],eax
  3446.  
  3447.               {  @@RShift  }
  3448.               mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_blue.rshift]
  3449.               mov edx,offset @@RShift-1
  3450.               sub edx,offset @@StartCode
  3451.               mov byte ptr [ecx+edx],al
  3452.  
  3453.               {  @@Dest  }
  3454.               mov eax,Dest; add eax,Byte(TDXRMachine_Color.B+1)
  3455.               mov edx,offset @@Dest-4
  3456.               sub edx,offset @@StartCode
  3457.               mov dword ptr [ecx+edx],eax
  3458.             end;
  3459.           end else
  3460.           begin
  3461.             asm
  3462.               jmp @@EndCode
  3463.             @@StartCode:
  3464.               mov edx,eax
  3465.               and edx,$11111111{}@@Mask:    // Surface.rgb_blue.Mask
  3466.               shl edx,$11      {}@@LShift:  // Surface.rgb_blue.lshift
  3467.               mov byte ptr [offset _null],dl{}@@Dest:// @Dest.B
  3468.             @@EndCode:
  3469.               {$I DXRender.inc}
  3470.               {  @@Mask  }
  3471.               mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_blue.Mask]
  3472.               mov edx,offset @@Mask-4
  3473.               sub edx,offset @@StartCode
  3474.               mov dword ptr [ecx+edx],eax
  3475.  
  3476.               {  @@LShift  }
  3477.               mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_blue.lshift]
  3478.               mov edx,offset @@LShift-1
  3479.               sub edx,offset @@StartCode
  3480.               mov byte ptr [ecx+edx],al
  3481.  
  3482.               {  @@Dest  }
  3483.               mov eax,Dest; add eax,Byte(TDXRMachine_Color.B+1)
  3484.               mov edx,offset @@Dest-4
  3485.               sub edx,offset @@StartCode
  3486.               mov dword ptr [ecx+edx],eax
  3487.             end;
  3488.           end;
  3489.         end else
  3490.         begin
  3491.           asm
  3492.             jmp @@EndCode
  3493.           @@StartCode:
  3494.             mov word ptr [offset _null],$1111{}@@Dest:// @Dest.B
  3495.           @@EndCode:
  3496.             {$I DXRender.inc}
  3497.             {  @@Dest  }
  3498.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.B)
  3499.             mov edx,offset @@Dest-6
  3500.             sub edx,offset @@StartCode
  3501.             mov dword ptr [ecx+edx],eax
  3502.  
  3503.             mov ax,dcB
  3504.             mov edx,offset @@Dest-2
  3505.             sub edx,offset @@StartCode
  3506.             mov word ptr [ecx+edx],ax
  3507.           end;
  3508.         end;
  3509.       end;
  3510.  
  3511.       {  Alpha Channel  }
  3512.       if chAlpha in EnableChannels then
  3513.       begin
  3514.         if Surface.rgb_alpha.Mask<>0 then
  3515.         begin
  3516.           if Surface.rgb_alpha.rshift<>0 then
  3517.           begin
  3518.             asm
  3519.               jmp @@EndCode
  3520.             @@StartCode:
  3521.               mov edx,eax
  3522.               and edx,$11111111{}@@Mask:    // Surface.rgb_alpha.Mask
  3523.               shr edx,$11      {}@@RShift:  // Surface.rgb_alpha.rshift
  3524.               mov byte ptr [offset _null],dl{}@@Dest:// @Dest.A
  3525.             @@EndCode:
  3526.               {$I DXRender.inc}
  3527.               {  @@Mask  }
  3528.               mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_alpha.Mask]
  3529.               mov edx,offset @@Mask-4
  3530.               sub edx,offset @@StartCode
  3531.               mov dword ptr [ecx+edx],eax
  3532.  
  3533.               {  @@RShift  }
  3534.               mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_alpha.rshift]
  3535.               mov edx,offset @@RShift-1
  3536.               sub edx,offset @@StartCode
  3537.               mov byte ptr [ecx+edx],al
  3538.  
  3539.               {  @@Dest  }
  3540.               mov eax,Dest; add eax,Byte(TDXRMachine_Color.A+1)
  3541.               mov edx,offset @@Dest-4
  3542.               sub edx,offset @@StartCode
  3543.               mov dword ptr [ecx+edx],eax
  3544.             end;
  3545.           end else
  3546.           begin
  3547.             asm
  3548.               jmp @@EndCode
  3549.             @@StartCode:
  3550.               mov edx,eax
  3551.               and edx,$11111111{}@@Mask:    // Surface.rgb_alpha.Mask
  3552.               shl edx,$11      {}@@LShift:  // Surface.rgb_alpha.lshift
  3553.               mov byte ptr [offset _null],dl{}@@Dest:// @Dest.A
  3554.             @@EndCode:
  3555.               {$I DXRender.inc}
  3556.               {  @@Mask  }
  3557.               mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_alpha.Mask]
  3558.               mov edx,offset @@Mask-4
  3559.               sub edx,offset @@StartCode
  3560.               mov dword ptr [ecx+edx],eax
  3561.  
  3562.               {  @@LShift  }
  3563.               mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_alpha.lshift]
  3564.               mov edx,offset @@LShift-1
  3565.               sub edx,offset @@StartCode
  3566.               mov byte ptr [ecx+edx],al
  3567.  
  3568.               {  @@Dest  }
  3569.               mov eax,Dest; add eax,Byte(TDXRMachine_Color.A+1)
  3570.               mov edx,offset @@Dest-4
  3571.               sub edx,offset @@StartCode
  3572.               mov dword ptr [ecx+edx],eax
  3573.             end;
  3574.           end;
  3575.         end else
  3576.         begin
  3577.           asm
  3578.             jmp @@EndCode
  3579.           @@StartCode:
  3580.             mov word ptr [offset _null],$1111{}@@Dest:// @Dest.A
  3581.           @@EndCode:
  3582.             {$I DXRender.inc}
  3583.             {  @@Dest  }
  3584.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.A)
  3585.             mov edx,offset @@Dest-6
  3586.             sub edx,offset @@StartCode
  3587.             mov dword ptr [ecx+edx],eax
  3588.  
  3589.             mov ax,dcA
  3590.             mov edx,offset @@Dest-2
  3591.             sub edx,offset @@StartCode
  3592.             mov word ptr [ecx+edx],ax
  3593.           end;
  3594.         end;
  3595.       end;
  3596.     end;
  3597.   end;
  3598.  
  3599.   procedure genEncodeColor(var Code: Pointer; const Surface: TDXR_Surface; Src: PDXRMachine_Color; EnableChannels: TDXRColorChannels);
  3600.   begin
  3601.     asm
  3602.       jmp @@EndCode
  3603.     @@StartCode:
  3604.       xor eax,eax
  3605.     @@EndCode:
  3606.       {$I DXRender.inc}
  3607.     end;
  3608.  
  3609.     {  Red channel  }
  3610.     if chRed in EnableChannels then
  3611.     begin
  3612.       if Surface.rgb_red.rshift<>0 then
  3613.       begin
  3614.         asm
  3615.           jmp @@EndCode
  3616.         @@StartCode:
  3617.           movzx edx,byte ptr [offset _null]{}@@Src:// @Src.R
  3618.           shl edx,$11      {}@@rgb_redRShift:  // Surface.rgb_red.rshift
  3619.           and edx,$11111111{}@@rgb_redMask:    // Surface.rgb_red.Mask
  3620.           or eax,edx
  3621.         @@EndCode:
  3622.           {$I DXRender.inc}
  3623.           {  @@Src  }
  3624.           mov eax,Src; add eax,Byte(TDXRMachine_Color.R+1)
  3625.           mov edx,offset @@Src-4
  3626.           sub edx,offset @@StartCode
  3627.           mov dword ptr [ecx+edx],eax
  3628.  
  3629.           {  @@rgb_redMask  }
  3630.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_red.Mask]
  3631.           mov edx,offset @@rgb_redMask-4
  3632.           sub edx,offset @@StartCode
  3633.           mov dword ptr [ecx+edx],eax
  3634.  
  3635.           {  @@rgb_redRShift  }
  3636.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_red.rshift]
  3637.           mov edx,offset @@rgb_redRShift-1
  3638.           sub edx,offset @@StartCode
  3639.           mov byte ptr [ecx+edx],al
  3640.         end;
  3641.       end else
  3642.       begin
  3643.         asm
  3644.           jmp @@EndCode
  3645.         @@StartCode:
  3646.           movzx edx,byte ptr [offset _null]{}@@Src:// @Src.R
  3647.           shr edx,$11      {}@@rgb_redLShift:  // Surface.rgb_red.lshift
  3648.           and edx,$11111111{}@@rgb_redMask:    // Surface.rgb_red.Mask
  3649.           or eax,edx
  3650.         @@EndCode:
  3651.           {$I DXRender.inc}
  3652.           {  @@Src  }
  3653.           mov eax,Src; add eax,Byte(TDXRMachine_Color.R+1)
  3654.           mov edx,offset @@Src-4
  3655.           sub edx,offset @@StartCode
  3656.           mov dword ptr [ecx+edx],eax
  3657.  
  3658.           {  @@rgb_redMask  }
  3659.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_red.Mask]
  3660.           mov edx,offset @@rgb_redMask-4
  3661.           sub edx,offset @@StartCode
  3662.           mov dword ptr [ecx+edx],eax
  3663.  
  3664.           {  @@rgb_redLShift  }
  3665.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_red.lshift]
  3666.           mov edx,offset @@rgb_redLShift-1
  3667.           sub edx,offset @@StartCode
  3668.           mov byte ptr [ecx+edx],al
  3669.         end;
  3670.       end;
  3671.     end;
  3672.  
  3673.     {  Green channel  }
  3674.     if chGreen in EnableChannels then
  3675.     begin
  3676.       if Surface.rgb_green.rshift<>0 then
  3677.       begin
  3678.         asm
  3679.           jmp @@EndCode
  3680.         @@StartCode:
  3681.           movzx edx,byte ptr [offset _null]{}@@Src:// @Src.G
  3682.           shl edx,$11      {}@@rgb_greenRShift:  // Surface.rgb_green.rshift
  3683.           and edx,$11111111{}@@rgb_greenMask:    // Surface.rgb_green.Mask
  3684.           or eax,edx
  3685.         @@EndCode:
  3686.           {$I DXRender.inc}
  3687.           {  @@Src  }
  3688.           mov eax,Src; add eax,Byte(TDXRMachine_Color.G+1)
  3689.           mov edx,offset @@Src-4
  3690.           sub edx,offset @@StartCode
  3691.           mov dword ptr [ecx+edx],eax
  3692.  
  3693.           {  @@rgb_greenMask  }
  3694.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_green.Mask]
  3695.           mov edx,offset @@rgb_greenMask-4
  3696.           sub edx,offset @@StartCode
  3697.           mov dword ptr [ecx+edx],eax
  3698.  
  3699.           {  @@rgb_greenRShift  }
  3700.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_green.rshift]
  3701.           mov edx,offset @@rgb_greenRShift-1
  3702.           sub edx,offset @@StartCode
  3703.           mov byte ptr [ecx+edx],al
  3704.         end;
  3705.       end else
  3706.       begin
  3707.         asm
  3708.           jmp @@EndCode
  3709.         @@StartCode:
  3710.           movzx edx,byte ptr [offset _null]{}@@Src:// @Src.G
  3711.           shr edx,$11      {}@@rgb_greenLShift:  // Surface.rgb_green.lshift
  3712.           and edx,$11111111{}@@rgb_greenMask:    // Surface.rgb_green.Mask
  3713.           or eax,edx
  3714.         @@EndCode:
  3715.           {$I DXRender.inc}
  3716.           {  @@Src  }
  3717.           mov eax,Src; add eax,Byte(TDXRMachine_Color.G+1)
  3718.           mov edx,offset @@Src-4
  3719.           sub edx,offset @@StartCode
  3720.           mov dword ptr [ecx+edx],eax
  3721.  
  3722.           {  @@rgb_greenMask  }
  3723.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_green.Mask]
  3724.           mov edx,offset @@rgb_greenMask-4
  3725.           sub edx,offset @@StartCode
  3726.           mov dword ptr [ecx+edx],eax
  3727.  
  3728.           {  @@rgb_greenLShift  }
  3729.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_green.lshift]
  3730.           mov edx,offset @@rgb_greenLShift-1
  3731.           sub edx,offset @@StartCode
  3732.           mov byte ptr [ecx+edx],al
  3733.         end;
  3734.       end;
  3735.     end;
  3736.  
  3737.     {  Blue channel  }
  3738.     if chBlue in EnableChannels then
  3739.     begin
  3740.       if Surface.rgb_blue.rshift<>0 then
  3741.       begin
  3742.         asm
  3743.           jmp @@EndCode
  3744.         @@StartCode:
  3745.           movzx edx,byte ptr [offset _null]{}@@Src:// @Src.B
  3746.           shl edx,$11      {}@@rgb_blueRShift:  // Surface.rgb_blue.rshift
  3747.           and edx,$11111111{}@@rgb_blueMask:    // Surface.rgb_blue.Mask
  3748.           or eax,edx
  3749.         @@EndCode:
  3750.           {$I DXRender.inc}
  3751.           {  @@Src  }
  3752.           mov eax,Src; add eax,Byte(TDXRMachine_Color.B+1)
  3753.           mov edx,offset @@Src-4
  3754.           sub edx,offset @@StartCode
  3755.           mov dword ptr [ecx+edx],eax
  3756.  
  3757.           {  @@rgb_blueMask  }
  3758.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_blue.Mask]
  3759.           mov edx,offset @@rgb_blueMask-4
  3760.           sub edx,offset @@StartCode
  3761.           mov dword ptr [ecx+edx],eax
  3762.  
  3763.           {  @@rgb_blueRShift  }
  3764.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_blue.rshift]
  3765.           mov edx,offset @@rgb_blueRShift-1
  3766.           sub edx,offset @@StartCode
  3767.           mov byte ptr [ecx+edx],al
  3768.         end;
  3769.       end else
  3770.       begin
  3771.         asm
  3772.           jmp @@EndCode
  3773.         @@StartCode:
  3774.           movzx edx,byte ptr [offset _null]{}@@Src:// @Src.B
  3775.           shr edx,$11      {}@@rgb_blueLShift:  // Surface.rgb_blue.lshift
  3776.           and edx,$11111111{}@@rgb_blueMask:    // Surface.rgb_blue.Mask
  3777.           or eax,edx
  3778.         @@EndCode:
  3779.           {$I DXRender.inc}
  3780.           {  @@Src  }
  3781.           mov eax,Src; add eax,Byte(TDXRMachine_Color.B+1)
  3782.           mov edx,offset @@Src-4
  3783.           sub edx,offset @@StartCode
  3784.           mov dword ptr [ecx+edx],eax
  3785.  
  3786.           {  @@rgb_blueMask  }
  3787.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_blue.Mask]
  3788.           mov edx,offset @@rgb_blueMask-4
  3789.           sub edx,offset @@StartCode
  3790.           mov dword ptr [ecx+edx],eax
  3791.  
  3792.           {  @@rgb_blueLShift  }
  3793.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_blue.lshift]
  3794.           mov edx,offset @@rgb_blueLShift-1
  3795.           sub edx,offset @@StartCode
  3796.           mov byte ptr [ecx+edx],al
  3797.         end;
  3798.       end;
  3799.     end;
  3800.  
  3801.     {  Alpha channel  }
  3802.     if chAlpha in EnableChannels then
  3803.     begin
  3804.       if Surface.rgb_alpha.rshift<>0 then
  3805.       begin
  3806.         asm
  3807.           jmp @@EndCode
  3808.         @@StartCode:
  3809.           movzx edx,byte ptr [offset _null]{}@@Src:// @Src.A
  3810.           shl edx,$11      {}@@rgb_alphaRShift: // Surface.rgb_alpha.rshift
  3811.           and edx,$11111111{}@@rgb_alphaMask:   // Surface.rgb_alpha.Mask
  3812.           or eax,edx
  3813.         @@EndCode:
  3814.           {$I DXRender.inc}
  3815.           {  @@Src  }
  3816.           mov eax,Src; add eax,Byte(TDXRMachine_Color.A+1)
  3817.           mov edx,offset @@Src-4
  3818.           sub edx,offset @@StartCode
  3819.           mov dword ptr [ecx+edx],eax
  3820.  
  3821.           {  @@rgb_alphaMask  }
  3822.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_alpha.Mask]
  3823.           mov edx,offset @@rgb_alphaMask-4
  3824.           sub edx,offset @@StartCode
  3825.           mov dword ptr [ecx+edx],eax
  3826.  
  3827.           {  @@rgb_alphaRShift  }
  3828.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_alpha.rshift]
  3829.           mov edx,offset @@rgb_alphaRShift-1
  3830.           sub edx,offset @@StartCode
  3831.           mov byte ptr [ecx+edx],al
  3832.         end;
  3833.       end else
  3834.       begin
  3835.         asm
  3836.           jmp @@EndCode
  3837.         @@StartCode:
  3838.           movzx edx,byte ptr [offset _null]{}@@Src:// @Src.A
  3839.           shr edx,$11      {}@@rgb_alphaLShift: // Surface.rgb_alpha.lshift
  3840.           and edx,$11111111{}@@rgb_alphaMask:   // Surface.rgb_alpha.Mask
  3841.           or eax,edx
  3842.         @@EndCode:
  3843.           {$I DXRender.inc}
  3844.           {  @@Src  }
  3845.           mov eax,Src; add eax,Byte(TDXRMachine_Color.A+1)
  3846.           mov edx,offset @@Src-4
  3847.           sub edx,offset @@StartCode
  3848.           mov dword ptr [ecx+edx],eax
  3849.  
  3850.           {  @@rgb_alphaMask  }
  3851.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_alpha.Mask]
  3852.           mov edx,offset @@rgb_alphaMask-4
  3853.           sub edx,offset @@StartCode
  3854.           mov dword ptr [ecx+edx],eax
  3855.  
  3856.           {  @@rgb_alphaLShift  }
  3857.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_alpha.lshift]
  3858.           mov edx,offset @@rgb_alphaLShift-1
  3859.           sub edx,offset @@StartCode
  3860.           mov byte ptr [ecx+edx],al
  3861.         end;
  3862.       end;
  3863.     end;
  3864.   end;
  3865.  
  3866.   procedure genEncodeColor_with_Dither(var Code: Pointer; const Surface: TDXR_Surface; Src: PDXRMachine_Color;
  3867.     Axis: PDXRMachine_Axis; EnableChannels: TDXRColorChannels);
  3868.   const
  3869.     m: array[0..3, 0..3] of Byte = ((0, 0, 0, 0), (1, 0, 0, 0), (1, 0, 0, 1), (1, 1, 1, 0));
  3870.   begin
  3871.     asm
  3872.       jmp @@EndCode
  3873.     @@StartCode:
  3874.       xor eax,eax
  3875.       movzx ebp,byte ptr [offset _null]{}@@AxisX:
  3876.       movzx edx,byte ptr [offset _null]{}@@AxisY:
  3877.       and ebp,1
  3878.       and edx,1
  3879.       lea ebp,[offset m+ebp*2+edx]
  3880.     @@EndCode:
  3881.       {$I DXRender.inc}
  3882.       {  @@AxisX  }
  3883.       mov eax,Axis; add eax,TDXRMachine_Axis.X
  3884.       mov edx,offset @@AxisX-4
  3885.       sub edx,offset @@StartCode
  3886.       mov dword ptr [ecx+edx],eax
  3887.  
  3888.       {  @@AxisY  }
  3889.       mov eax,Axis; add eax,TDXRMachine_Axis.Y
  3890.       mov edx,offset @@AxisY-4
  3891.       sub edx,offset @@StartCode
  3892.       mov dword ptr [ecx+edx],eax
  3893.     end;
  3894.  
  3895.     {  Red channel  }
  3896.     if chRed in EnableChannels then
  3897.     begin
  3898.       asm
  3899.         jmp @@EndCode
  3900.       @@StartCode:
  3901.         movzx edx,byte ptr [offset _null]{}@@Src:// @Src.R
  3902.       @@EndCode:
  3903.         {$I DXRender.inc}
  3904.         {  @@Src  }
  3905.         mov eax,Src; add eax,Byte(TDXRMachine_Color.R+1)
  3906.         mov edx,offset @@Src-4
  3907.         sub edx,offset @@StartCode
  3908.         mov dword ptr [ecx+edx],eax
  3909.       end;
  3910.  
  3911.       if Surface.rgb_red.Bitcount<7 then
  3912.       begin
  3913.         asm
  3914.           jmp @@EndCode
  3915.         @@StartCode:
  3916.           mov ebx,edx
  3917.           shr ebx,$11       {}@@BitCount:  // 6-bitcount
  3918.           and ebx,3
  3919.           movzx ebx,byte ptr [ebp+ebx*4]
  3920.           shl ebx,$11       {}@@BitCount2: // 8-bitcount
  3921.           movzx edx,byte [offset (_AddTable+edx+ebx)]
  3922.         @@EndCode:
  3923.           {$I DXRender.inc}
  3924.           {  @@BitCount  }
  3925.           mov eax,6; mov edx,Surface; sub eax,[edx + TDXR_Surface.rgb_red.Bitcount]
  3926.           mov edx,offset @@BitCount-1
  3927.           sub edx,offset @@StartCode
  3928.           mov byte ptr [ecx+edx],al
  3929.  
  3930.           {  @@BitCount2  }
  3931.           mov eax,8; mov edx,Surface; sub eax,[edx + TDXR_Surface.rgb_red.Bitcount]
  3932.           mov edx,offset @@BitCount2-1
  3933.           sub edx,offset @@StartCode
  3934.           mov byte ptr [ecx+edx],al
  3935.         end;
  3936.       end;
  3937.  
  3938.       if Surface.rgb_red.rshift<>0 then
  3939.       begin
  3940.         asm
  3941.           jmp @@EndCode
  3942.         @@StartCode:
  3943.           shl edx,$11      {}@@rgb_redRShift:  // Surface.rgb_red.rshift
  3944.           and edx,$11111111{}@@rgb_redMask:    // Surface.rgb_red.Mask
  3945.           or eax,edx
  3946.         @@EndCode:
  3947.           {$I DXRender.inc}
  3948.           {  @@rgb_redMask  }
  3949.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_red.Mask]
  3950.           mov edx,offset @@rgb_redMask-4
  3951.           sub edx,offset @@StartCode
  3952.           mov dword ptr [ecx+edx],eax
  3953.  
  3954.           {  @@rgb_redRShift  }
  3955.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_red.rshift]
  3956.           mov edx,offset @@rgb_redRShift-1
  3957.           sub edx,offset @@StartCode
  3958.           mov byte ptr [ecx+edx],al
  3959.         end;
  3960.       end else
  3961.       begin
  3962.         asm
  3963.           jmp @@EndCode
  3964.         @@StartCode:
  3965.           shr edx,$11      {}@@rgb_redLShift:  // Surface.rgb_red.lshift
  3966.           and edx,$11111111{}@@rgb_redMask:    // Surface.rgb_red.Mask
  3967.           or eax,edx
  3968.         @@EndCode:
  3969.           {$I DXRender.inc}
  3970.           {  @@rgb_redMask  }
  3971.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_red.Mask]
  3972.           mov edx,offset @@rgb_redMask-4
  3973.           sub edx,offset @@StartCode
  3974.           mov dword ptr [ecx+edx],eax
  3975.  
  3976.           {  @@rgb_redLShift  }
  3977.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_red.lshift]
  3978.           mov edx,offset @@rgb_redLShift-1
  3979.           sub edx,offset @@StartCode
  3980.           mov byte ptr [ecx+edx],al
  3981.         end;
  3982.       end;
  3983.     end;
  3984.  
  3985.     {  Green channel  }
  3986.     if chGreen in EnableChannels then
  3987.     begin
  3988.       asm
  3989.         jmp @@EndCode
  3990.       @@StartCode:
  3991.         movzx edx,byte ptr [offset _null]{}@@Src:// @Src.G
  3992.       @@EndCode:
  3993.         {$I DXRender.inc}
  3994.         {  @@Src  }
  3995.         mov eax,Src; add eax,Byte(TDXRMachine_Color.G+1)
  3996.         mov edx,offset @@Src-4
  3997.         sub edx,offset @@StartCode
  3998.         mov dword ptr [ecx+edx],eax
  3999.       end;
  4000.  
  4001.       if Surface.rgb_green.Bitcount<7 then
  4002.       begin
  4003.         asm
  4004.           jmp @@EndCode
  4005.         @@StartCode:
  4006.           mov ebx,edx
  4007.           shr ebx,$11       {}@@BitCount:  // 6-bitcount
  4008.           and ebx,3
  4009.           movzx ebx,byte ptr [ebp+ebx*4]
  4010.           shl ebx,$11       {}@@BitCount2: // 8-bitcount
  4011.           movzx edx,byte [offset (_AddTable+edx+ebx)]
  4012.         @@EndCode:
  4013.           {$I DXRender.inc}
  4014.           {  @@BitCount  }
  4015.           mov eax,6; mov edx,Surface; sub eax,[edx + TDXR_Surface.rgb_green.Bitcount]
  4016.           mov edx,offset @@BitCount-1
  4017.           sub edx,offset @@StartCode
  4018.           mov byte ptr [ecx+edx],al
  4019.  
  4020.           {  @@BitCount2  }
  4021.           mov eax,8; mov edx,Surface; sub eax,[edx + TDXR_Surface.rgb_green.Bitcount]
  4022.           mov edx,offset @@BitCount2-1
  4023.           sub edx,offset @@StartCode
  4024.           mov byte ptr [ecx+edx],al
  4025.         end;
  4026.       end;
  4027.  
  4028.       if Surface.rgb_green.rshift<>0 then
  4029.       begin
  4030.         asm
  4031.           jmp @@EndCode
  4032.         @@StartCode:
  4033.           shl edx,$11      {}@@rgb_greenRShift:  // Surface.rgb_green.rshift
  4034.           and edx,$11111111{}@@rgb_greenMask:    // Surface.rgb_green.Mask
  4035.           or eax,edx
  4036.         @@EndCode:
  4037.           {$I DXRender.inc}
  4038.           {  @@rgb_greenMask  }
  4039.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_green.Mask]
  4040.           mov edx,offset @@rgb_greenMask-4
  4041.           sub edx,offset @@StartCode
  4042.           mov dword ptr [ecx+edx],eax
  4043.  
  4044.           {  @@rgb_greenRShift  }
  4045.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_green.rshift]
  4046.           mov edx,offset @@rgb_greenRShift-1
  4047.           sub edx,offset @@StartCode
  4048.           mov byte ptr [ecx+edx],al
  4049.         end;
  4050.       end else
  4051.       begin
  4052.         asm
  4053.           jmp @@EndCode
  4054.         @@StartCode:
  4055.           shr edx,$11      {}@@rgb_greenLShift:  // Surface.rgb_green.lshift
  4056.           and edx,$11111111{}@@rgb_greenMask:    // Surface.rgb_green.Mask
  4057.           or eax,edx
  4058.         @@EndCode:
  4059.           {$I DXRender.inc}
  4060.           {  @@rgb_greenMask  }
  4061.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_green.Mask]
  4062.           mov edx,offset @@rgb_greenMask-4
  4063.           sub edx,offset @@StartCode
  4064.           mov dword ptr [ecx+edx],eax
  4065.  
  4066.           {  @@rgb_greenLShift  }
  4067.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_green.lshift]
  4068.           mov edx,offset @@rgb_greenLShift-1
  4069.           sub edx,offset @@StartCode
  4070.           mov byte ptr [ecx+edx],al
  4071.         end;
  4072.       end;
  4073.     end;
  4074.  
  4075.     {  Blue channel  }
  4076.     if chBlue in EnableChannels then
  4077.     begin
  4078.       asm
  4079.         jmp @@EndCode
  4080.       @@StartCode:
  4081.         movzx edx,byte ptr [offset _null]{}@@Src:// @Src.B
  4082.       @@EndCode:
  4083.         {$I DXRender.inc}
  4084.         {  @@Src  }
  4085.         mov eax,Src; add eax,Byte(TDXRMachine_Color.B+1)
  4086.         mov edx,offset @@Src-4
  4087.         sub edx,offset @@StartCode
  4088.         mov dword ptr [ecx+edx],eax
  4089.       end;
  4090.  
  4091.       if Surface.rgb_blue.Bitcount<7 then
  4092.       begin
  4093.         asm
  4094.           jmp @@EndCode
  4095.         @@StartCode:
  4096.           mov ebx,edx
  4097.           shr ebx,$11       {}@@BitCount:  // 6-bitcount
  4098.           and ebx,3
  4099.           movzx ebx,byte ptr [ebp+ebx*4]
  4100.           shl ebx,$11       {}@@BitCount2: // 8-bitcount
  4101.           movzx edx,byte [offset (_AddTable+edx+ebx)]
  4102.         @@EndCode:
  4103.           {$I DXRender.inc}
  4104.           {  @@BitCount  }
  4105.           mov eax,6; mov edx,Surface; sub eax,[edx + TDXR_Surface.rgb_blue.Bitcount]
  4106.           mov edx,offset @@BitCount-1
  4107.           sub edx,offset @@StartCode
  4108.           mov byte ptr [ecx+edx],al
  4109.  
  4110.           {  @@BitCount2  }
  4111.           mov eax,8; mov edx,Surface; sub eax,[edx + TDXR_Surface.rgb_blue.Bitcount]
  4112.           mov edx,offset @@BitCount2-1
  4113.           sub edx,offset @@StartCode
  4114.           mov byte ptr [ecx+edx],al
  4115.         end;
  4116.       end;
  4117.  
  4118.       if Surface.rgb_blue.rshift<>0 then
  4119.       begin
  4120.         asm
  4121.           jmp @@EndCode
  4122.         @@StartCode:
  4123.           shl edx,$11      {}@@rgb_blueRShift:  // Surface.rgb_blue.rshift
  4124.           and edx,$11111111{}@@rgb_blueMask:    // Surface.rgb_blue.Mask
  4125.           or eax,edx
  4126.         @@EndCode:
  4127.           {$I DXRender.inc}
  4128.           {  @@rgb_blueMask  }
  4129.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_blue.Mask]
  4130.           mov edx,offset @@rgb_blueMask-4
  4131.           sub edx,offset @@StartCode
  4132.           mov dword ptr [ecx+edx],eax
  4133.  
  4134.           {  @@rgb_blueRShift  }
  4135.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_blue.rshift]
  4136.           mov edx,offset @@rgb_blueRShift-1
  4137.           sub edx,offset @@StartCode
  4138.           mov byte ptr [ecx+edx],al
  4139.         end;
  4140.       end else
  4141.       begin
  4142.         asm
  4143.           jmp @@EndCode
  4144.         @@StartCode:
  4145.           shr edx,$11      {}@@rgb_blueLShift:  // Surface.rgb_blue.lshift
  4146.           and edx,$11111111{}@@rgb_blueMask:    // Surface.rgb_blue.Mask
  4147.           or eax,edx
  4148.         @@EndCode:
  4149.           {$I DXRender.inc}
  4150.           {  @@rgb_blueMask  }
  4151.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_blue.Mask]
  4152.           mov edx,offset @@rgb_blueMask-4
  4153.           sub edx,offset @@StartCode
  4154.           mov dword ptr [ecx+edx],eax
  4155.  
  4156.           {  @@rgb_blueLShift  }
  4157.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_blue.lshift]
  4158.           mov edx,offset @@rgb_blueLShift-1
  4159.           sub edx,offset @@StartCode
  4160.           mov byte ptr [ecx+edx],al
  4161.         end;
  4162.       end;
  4163.     end;
  4164.  
  4165.     {  Alpha channel  }
  4166.     if chAlpha in EnableChannels then
  4167.     begin
  4168.       asm
  4169.         jmp @@EndCode
  4170.       @@StartCode:
  4171.         movzx edx,byte ptr [offset _null]{}@@Src:// @Src.R
  4172.       @@EndCode:
  4173.         {$I DXRender.inc}
  4174.         {  @@Src  }
  4175.         mov eax,Src; add eax,Byte(TDXRMachine_Color.A+1)
  4176.         mov edx,offset @@Src-4
  4177.         sub edx,offset @@StartCode
  4178.         mov dword ptr [ecx+edx],eax
  4179.       end;
  4180.  
  4181.       if Surface.rgb_alpha.Bitcount<7 then
  4182.       begin
  4183.         asm
  4184.           jmp @@EndCode
  4185.         @@StartCode:
  4186.           mov ebx,edx
  4187.           shr ebx,$11       {}@@BitCount:  // 6-bitcount
  4188.           and ebx,3
  4189.           movzx ebx,byte ptr [ebp+ebx]
  4190.           shl ebx,$11       {}@@BitCount2: // 8-bitcount
  4191.           movzx edx,byte [offset (_AddTable+edx+ebx)]
  4192.         @@EndCode:
  4193.           {$I DXRender.inc}
  4194.           {  @@BitCount  }
  4195.           mov eax,6; mov edx,Surface; sub eax,[edx + TDXR_Surface.rgb_alpha.Bitcount]
  4196.           mov edx,offset @@BitCount-1
  4197.           sub edx,offset @@StartCode
  4198.           mov byte ptr [ecx+edx],al
  4199.  
  4200.           {  @@BitCount2  }
  4201.           mov eax,8; mov edx,Surface; sub eax,[edx + TDXR_Surface.rgb_alpha.Bitcount]
  4202.           mov edx,offset @@BitCount2-1
  4203.           sub edx,offset @@StartCode
  4204.           mov byte ptr [ecx+edx],al
  4205.         end;
  4206.       end;
  4207.  
  4208.       if Surface.rgb_alpha.rshift<>0 then
  4209.       begin
  4210.         asm
  4211.           jmp @@EndCode
  4212.         @@StartCode:
  4213.           shl edx,$11      {}@@rgb_alphaRShift:  // Surface.rgb_alpha.rshift
  4214.           and edx,$11111111{}@@rgb_alphaMask:    // Surface.rgb_alpha.Mask
  4215.           or eax,edx
  4216.         @@EndCode:
  4217.           {$I DXRender.inc}
  4218.           {  @@rgb_alphaMask  }
  4219.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_alpha.Mask]
  4220.           mov edx,offset @@rgb_alphaMask-4
  4221.           sub edx,offset @@StartCode
  4222.           mov dword ptr [ecx+edx],eax
  4223.  
  4224.           {  @@rgb_alphaRShift  }
  4225.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_alpha.rshift]
  4226.           mov edx,offset @@rgb_alphaRShift-1
  4227.           sub edx,offset @@StartCode
  4228.           mov byte ptr [ecx+edx],al
  4229.         end;
  4230.       end else
  4231.       begin
  4232.         asm
  4233.           jmp @@EndCode
  4234.         @@StartCode:
  4235.           shr edx,$11      {}@@rgb_alphaLShift:  // Surface.rgb_alpha.lshift
  4236.           and edx,$11111111{}@@rgb_alphaMask:    // Surface.rgb_alpha.Mask
  4237.           or eax,edx
  4238.         @@EndCode:
  4239.           {$I DXRender.inc}
  4240.           {  @@rgb_alphaMask  }
  4241.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_alpha.Mask]
  4242.           mov edx,offset @@rgb_alphaMask-4
  4243.           sub edx,offset @@StartCode
  4244.           mov dword ptr [ecx+edx],eax
  4245.  
  4246.           {  @@rgb_alphaLShift  }
  4247.           mov eax,Surface; mov eax,[eax + TDXR_Surface.rgb_alpha.lshift]
  4248.           mov edx,offset @@rgb_alphaLShift-1
  4249.           sub edx,offset @@StartCode
  4250.           mov byte ptr [ecx+edx],al
  4251.         end;
  4252.       end;
  4253.     end;
  4254.   end;
  4255.  
  4256.   procedure genEncodeColor2(var Code: Pointer; const Surface: TDXR_Surface; Src: PDXRMachine_Color; EnableChannels: TDXRColorChannels);
  4257.   begin
  4258.     if Dither.Enable then
  4259.     begin
  4260.       genEncodeColor_with_Dither(Code, Surface, Src, @Axis.Axis, EnableChannels)
  4261.     end else
  4262.     begin
  4263.       genEncodeColor(Code, Surface, Src, EnableChannels);
  4264.     end;
  4265.   end;
  4266.  
  4267.   procedure genColorKey(var Code: Pointer; const Texture: TDXRMachine_Reg_Texture);
  4268.   var
  4269.     TransparentMask, TransparentColor: DWORD;
  4270.   begin
  4271.     if not Texture.ColorKeyEnable then Exit;
  4272.  
  4273.     if Texture.Surface.ColorType=DXR_COLORTYPE_INDEXED then
  4274.     begin
  4275.       TransparentMask := not Texture.Surface.idx_alpha.Mask;
  4276.     end else if Texture.Surface.ColorType=DXR_COLORTYPE_RGB then
  4277.     begin
  4278.       TransparentMask := not Texture.Surface.rgb_alpha.Mask;
  4279.     end;
  4280.  
  4281.     TransparentColor := Texture.ColorKey;
  4282.  
  4283.     if TransparentMask=$FFFFFFFF then
  4284.     begin
  4285.       if Texture.Surface.BitCount=32 then
  4286.       begin
  4287.         if TransparentColor=0 then
  4288.         begin
  4289.           asm
  4290.             jmp @@EndCode
  4291.           @@StartCode:
  4292.             and eax,$FFFFFF
  4293.           @@EndCode:
  4294.             {$I DXRender.inc}
  4295.           end;
  4296.         end else
  4297.         begin
  4298.           asm
  4299.             jmp @@EndCode
  4300.           @@StartCode:
  4301.             and eax,$FFFFFF
  4302.             cmp eax,$11111111{}@@TransColor: // Process.Texture.TransparentColor
  4303.           @@EndCode:
  4304.             {$I DXRender.inc}
  4305.             {  @@TransColor  }
  4306.             mov eax,TransparentColor
  4307.             mov edx,offset @@TransColor-4
  4308.             sub edx,offset @@StartCode
  4309.             mov dword ptr [ecx+edx],eax
  4310.           end;
  4311.         end;
  4312.       end else
  4313.       begin
  4314.         if TransparentColor=0 then
  4315.         begin
  4316.           asm
  4317.             jmp @@EndCode
  4318.           @@StartCode:
  4319.             test eax,eax
  4320.           @@EndCode:
  4321.             {$I DXRender.inc}
  4322.           end;
  4323.         end else
  4324.         begin
  4325.           asm
  4326.             jmp @@EndCode
  4327.           @@StartCode:
  4328.             cmp eax,$11111111{}@@TransColor: // Process.Texture.TransparentColor
  4329.           @@EndCode:
  4330.             {$I DXRender.inc}
  4331.             {  @@TransColor  }
  4332.             mov eax,TransparentColor
  4333.             mov edx,offset @@TransColor-4
  4334.             sub edx,offset @@StartCode
  4335.             mov dword ptr [ecx+edx],eax
  4336.           end;
  4337.         end;
  4338.       end;
  4339.     end else
  4340.     begin
  4341.       if Texture.Surface.BitCount=32 then
  4342.         TransparentMask := TransparentMask and $FFFFFF;
  4343.  
  4344.       asm
  4345.         jmp @@EndCode
  4346.       @@StartCode:
  4347.         mov edx,eax
  4348.         and edx,$11111111{}@@TransMask:  // TransparentMask
  4349.         cmp edx,$11111111{}@@TransColor: // Process.Texture.TransparentColor
  4350.       @@EndCode:
  4351.         {$I DXRender.inc}
  4352.         {  @@TransMask  }
  4353.         mov eax,TransparentMask
  4354.         mov edx,offset @@TransMask-4
  4355.         sub edx,offset @@StartCode
  4356.         mov dword ptr [ecx+edx],eax
  4357.  
  4358.         {  @@TransColor  }
  4359.         mov eax,TransparentColor
  4360.         mov edx,offset @@TransColor-4
  4361.         sub edx,offset @@StartCode
  4362.         mov dword ptr [ecx+edx],eax
  4363.       end;
  4364.     end;
  4365.  
  4366.     genCmpFunc(Code, DXR_CMPFUNC_EQUAL, SkipAddress);
  4367.   end;
  4368.  
  4369.   procedure genReadTexture_Nearest(var Code: Pointer; Dest: PDXRMachine_Color;
  4370.     const Texture: TDXRMachine_Reg_Texture; const Axis: TDXRMachine_Axis; EnableChannels: TDXRColorChannels);
  4371.   begin
  4372.     if EnableChannels=[] then Exit;
  4373.  
  4374.     genReadSurfacePixel(Code, Texture, @Axis);
  4375.     genColorKey(Code, Texture);
  4376.     genDecodeColor(Code, Texture.Surface^, Dest, EnableChannels, Texture.DefaultColor);
  4377.   end;
  4378.  
  4379.   procedure genReadTexture_BiLinear(var Code: Pointer; Dest: PDXRMachine_Color;
  4380.     const Texture: TDXRMachine_Reg_Texture; const Axis: TDXRMachine_Axis; EnableChannels: TDXRColorChannels);
  4381.   var
  4382.     _Axis, _BiLinearAxis, _BiLinearCol1, _BiLinearCol2, _BiLinearCol3, _BiLinearCol4: Pointer;
  4383.   begin
  4384.     if EnableChannels=[] then Exit;
  4385.  
  4386.     _Axis := @Axis;
  4387.     _BiLinearAxis := @F_BiLinearAxis;
  4388.     _BiLinearCol1 := @F_BiLinearCol1;
  4389.     _BiLinearCol2 := @F_BiLinearCol2;
  4390.     _BiLinearCol3 := @F_BiLinearCol3;
  4391.     _BiLinearCol4 := @F_BiLinearCol4;
  4392.  
  4393.     genReadSurfacePixel(Code, Texture, _Axis);
  4394.     genColorKey(Code, Texture);
  4395.     genDecodeColor(Code, Texture.Surface^, _BiLinearCol1, EnableChannels, Texture.DefaultColor);
  4396.  
  4397.     asm
  4398.       jmp @@EndCode
  4399.     @@StartCode:
  4400.       mov eax,dword ptr [offset _null]{}@@TexX:
  4401.       mov edx,dword ptr [offset _null]{}@@TexY:
  4402.       add eax,65536
  4403.       mov dword ptr [offset _null],edx{}@@AxisY:
  4404.       mov dword ptr [offset _null],eax{}@@AxisX:
  4405.     @@EndCode:
  4406.       {$I DXRender.inc}
  4407.       {  @@TexX  }
  4408.       mov eax,_Axis; add eax,TDXRMachine_Axis.X
  4409.       mov edx,offset @@TexX-4
  4410.       sub edx,offset @@StartCode
  4411.       mov dword ptr [ecx+edx],eax
  4412.  
  4413.       {  @@TexY  }
  4414.       mov eax,_Axis; add eax,TDXRMachine_Axis.Y
  4415.       mov edx,offset @@TexY-4
  4416.       sub edx,offset @@StartCode
  4417.       mov dword ptr [ecx+edx],eax
  4418.  
  4419.       {  @@AxisX  }
  4420.       mov eax,_BiLinearAxis; add eax,TDXRMachine_Axis.X
  4421.       mov edx,offset @@AxisX-4
  4422.       sub edx,offset @@StartCode
  4423.       mov dword ptr [ecx+edx],eax
  4424.  
  4425.       {  @@AxisY  }
  4426.       mov eax,_BiLinearAxis; add eax,TDXRMachine_Axis.Y
  4427.       mov edx,offset @@AxisY-4
  4428.       sub edx,offset @@StartCode
  4429.       mov dword ptr [ecx+edx],eax
  4430.     end;
  4431.     genReadSurfacePixel(Code, Texture, _BiLinearAxis);
  4432.     genDecodeColor(Code, Texture.Surface^, _BiLinearCol2, EnableChannels, Texture.DefaultColor);
  4433.  
  4434.     asm
  4435.       jmp @@EndCode
  4436.     @@StartCode:
  4437.       add dword ptr [offset _null],65536{}@@AxisY:
  4438.     @@EndCode:
  4439.       {$I DXRender.inc}
  4440.       {  @@AxisY  }
  4441.       mov eax,_BiLinearAxis; add eax,TDXRMachine_Axis.Y
  4442.       mov edx,offset @@AxisY-8
  4443.       sub edx,offset @@StartCode
  4444.       mov dword ptr [ecx+edx],eax
  4445.     end;
  4446.     genReadSurfacePixel(Code, Texture, _BiLinearAxis);
  4447.     genDecodeColor(Code, Texture.Surface^, _BiLinearCol4, EnableChannels, Texture.DefaultColor);
  4448.  
  4449.     asm
  4450.       jmp @@EndCode
  4451.     @@StartCode:
  4452.       sub dword ptr [offset _null],65536{}@@AxisX:
  4453.     @@EndCode:
  4454.       {$I DXRender.inc}
  4455.       {  @@AxisX  }
  4456.       mov eax,_BiLinearAxis; add eax,TDXRMachine_Axis.X
  4457.       mov edx,offset @@AxisX-8
  4458.       sub edx,offset @@StartCode
  4459.       mov dword ptr [ecx+edx],eax
  4460.     end;
  4461.     genReadSurfacePixel(Code, Texture, _BiLinearAxis);
  4462.     genDecodeColor(Code, Texture.Surface^, _BiLinearCol3, EnableChannels, Texture.DefaultColor);
  4463.                  (*
  4464.     if UseMMX then
  4465.     begin
  4466.       asm
  4467.         jmp @@EndCode
  4468.       @@StartCode:
  4469.         movzx eax,byte ptr [offset _null]{}@@TexX:
  4470.         movzx edx,byte ptr [offset _null]{}@@TexY:
  4471.  
  4472.         db $0F,$6F,$1C,$C5,$11,$11,$11,$11///movq mm3,qword ptr [$11111111+eax*8]
  4473.                                @@_ByteToQWORDTable1:
  4474.         xor eax,$FF
  4475.         db $0F,$6F,$24,$C5,$11,$11,$11,$11///movq mm4,qword ptr [$11111111+eax*8]
  4476.                                @@_ByteToQWORDTable2:
  4477.  
  4478.         db $0F,$6F,$05,$11,$11,$11,$11///movq mm0,qword ptr [$11111111]
  4479.                                @@_BiLinearCol1:
  4480.         db $0F,$6F,$0D,$11,$11,$11,$11///movq mm1,qword ptr [$11111111]
  4481.                                @@_BiLinearCol2:
  4482.  
  4483.         db $0F,$D5,$C3        ///pmullw mm0,mm3
  4484.         db $0F,$D5,$CC        ///pmullw mm1,mm4
  4485.         db $0F,$FD,$C1        ///paddw mm0,mm1
  4486.         db $0F,$71,$D0,$08    ///psrlw mm0,8
  4487.  
  4488.         db $0F,$6F,$0D,$11,$11,$11,$11///movq mm1,qword ptr [$11111111]
  4489.                                @@_BiLinearCol3:
  4490.         db $0F,$6F,$15,$11,$11,$11,$11///movq mm2,qword ptr [$11111111]
  4491.                                @@_BiLinearCol4:
  4492.  
  4493.         db $0F,$D5,$CB        ///pmullw mm1,mm3
  4494.         db $0F,$D5,$D4        ///pmullw mm2,mm4
  4495.         db $0F,$FD,$CA        ///paddw mm1,mm2
  4496.         db $0F,$71,$D1,$08    ///psrlw mm1,8
  4497.  
  4498.         db $0F,$D5,$04,$D5,$11,$11,$11,$11///pmullw mm0,qword ptr [$11111111+edx*8]
  4499.                                @@_ByteToQWORDTable3:
  4500.         xor edx,$FF
  4501.         db $0F,$D5,$0C,$D5,$11,$11,$11,$11///pmullw mm1,qword ptr [$11111111+edx*8]
  4502.                                @@_ByteToQWORDTable4:
  4503.         db $0F,$FD,$C1        ///paddw mm0,mm1
  4504.         db $0F,$71,$D0,$08    ///psrlw mm0,8
  4505.  
  4506.         db $0F,$7F,$05,$11,$11,$11,$11///movq qword ptr [$11111111],mm0
  4507.                                @@Dest:
  4508.       @@EndCode:
  4509.         {$I DXRender.inc}
  4510.         {  @@TexX  }
  4511.         mov eax,_Axis; add eax,TDXRMachine_Axis.X+1
  4512.         mov edx,offset @@TexX-4
  4513.         sub edx,offset @@StartCode
  4514.         mov dword ptr [ecx+edx],eax
  4515.  
  4516.         {  @@TexY  }
  4517.         mov eax,_Axis; add eax,TDXRMachine_Axis.Y+1
  4518.         mov edx,offset @@TexY-4
  4519.         sub edx,offset @@StartCode
  4520.         mov dword ptr [ecx+edx],eax
  4521.  
  4522.         {  @@_ByteToQWORDTable1  }
  4523.         mov eax,offset _ByteToQWORDTable
  4524.         mov edx,offset @@_ByteToQWORDTable1-4
  4525.         sub edx,offset @@StartCode
  4526.         mov dword ptr [ecx+edx],eax
  4527.  
  4528.         {  @@_ByteToQWORDTable2  }
  4529.         mov eax,offset _ByteToQWORDTable
  4530.         mov edx,offset @@_ByteToQWORDTable2-4
  4531.         sub edx,offset @@StartCode
  4532.         mov dword ptr [ecx+edx],eax
  4533.  
  4534.         {  @@_ByteToQWORDTable3  }
  4535.         mov eax,offset _ByteToQWORDTable
  4536.         mov edx,offset @@_ByteToQWORDTable3-4
  4537.         sub edx,offset @@StartCode
  4538.         mov dword ptr [ecx+edx],eax
  4539.  
  4540.         {  @@_ByteToQWORDTable4  }
  4541.         mov eax,offset _ByteToQWORDTable
  4542.         mov edx,offset @@_ByteToQWORDTable4-4
  4543.         sub edx,offset @@StartCode
  4544.         mov dword ptr [ecx+edx],eax
  4545.  
  4546.         {  @@_BiLinearCol1  }
  4547.         mov eax,_BiLinearCol1
  4548.         mov edx,offset @@_BiLinearCol1-4
  4549.         sub edx,offset @@StartCode
  4550.         mov dword ptr [ecx+edx],eax
  4551.  
  4552.         {  @@_BiLinearCol2  }
  4553.         mov eax,_BiLinearCol2
  4554.         mov edx,offset @@_BiLinearCol2-4
  4555.         sub edx,offset @@StartCode
  4556.         mov dword ptr [ecx+edx],eax
  4557.  
  4558.         {  @@_BiLinearCol3  }
  4559.         mov eax,_BiLinearCol3
  4560.         mov edx,offset @@_BiLinearCol3-4
  4561.         sub edx,offset @@StartCode
  4562.         mov dword ptr [ecx+edx],eax
  4563.  
  4564.         {  @@_BiLinearCol4  }
  4565.         mov eax,_BiLinearCol4
  4566.         mov edx,offset @@_BiLinearCol4-4
  4567.         sub edx,offset @@StartCode
  4568.         mov dword ptr [ecx+edx],eax
  4569.  
  4570.         {  @@Dest  }
  4571.         mov eax,Dest
  4572.         mov edx,offset @@Dest-4
  4573.         sub edx,offset @@StartCode
  4574.         mov dword ptr [ecx+edx],eax
  4575.       end;
  4576.     end else       *)
  4577.     begin
  4578.       {  Red Channel  }
  4579.       if chRed in EnableChannels then
  4580.       begin
  4581.         asm
  4582.           jmp @@EndCode
  4583.         @@StartCode:
  4584.           movzx eax,byte ptr [offset _null]{}@@_BiLinearCol2:
  4585.           movzx edx,byte ptr [offset _null]{}@@TexX:
  4586.           imul eax,edx
  4587.           movzx ebx,byte ptr [offset _null]{}@@_BiLinearCol1:
  4588.           xor edx,$FF
  4589.           imul ebx,edx
  4590.           add ebx,eax
  4591.           xor edx,$FF
  4592.  
  4593.           movzx eax,byte ptr [offset _null]{}@@_BiLinearCol4:
  4594.           imul eax,edx
  4595.           movzx ebp,byte ptr [offset _null]{}@@_BiLinearCol3:
  4596.           xor edx,$FF
  4597.           imul ebp,edx
  4598.           add eax,ebp
  4599.  
  4600.           movzx edx,byte ptr [offset _Null]{}@@TexY:
  4601.           imul eax,edx
  4602.           xor edx,$FF
  4603.           imul ebx,edx
  4604.           add eax,ebx
  4605.           shr eax,16
  4606.  
  4607.           mov byte ptr [offset _Null],al{}@@Dest:
  4608.         @@EndCode:
  4609.           {$I DXRender.inc}
  4610.           {  @@_BiLinearCol1  }
  4611.           mov eax,_BiLinearCol1; add eax,Byte(TDXRMachine_Color.R+1)
  4612.           mov edx,offset @@_BiLinearCol1-4
  4613.           sub edx,offset @@StartCode
  4614.           mov dword ptr [ecx+edx],eax
  4615.  
  4616.           {  @@_BiLinearCol2  }
  4617.           mov eax,_BiLinearCol2; add eax,Byte(TDXRMachine_Color.R+1)
  4618.           mov edx,offset @@_BiLinearCol2-4
  4619.           sub edx,offset @@StartCode
  4620.           mov dword ptr [ecx+edx],eax
  4621.  
  4622.           {  @@_BiLinearCol3  }
  4623.           mov eax,_BiLinearCol3; add eax,Byte(TDXRMachine_Color.R+1)
  4624.           mov edx,offset @@_BiLinearCol3-4
  4625.           sub edx,offset @@StartCode
  4626.           mov dword ptr [ecx+edx],eax
  4627.  
  4628.           {  @@_BiLinearCol4  }
  4629.           mov eax,_BiLinearCol4; add eax,Byte(TDXRMachine_Color.R+1)
  4630.           mov edx,offset @@_BiLinearCol4-4
  4631.           sub edx,offset @@StartCode
  4632.           mov dword ptr [ecx+edx],eax
  4633.  
  4634.           {  @@TexX  }
  4635.           mov eax,_Axis; add eax,TDXRMachine_Axis.X+1
  4636.           mov edx,offset @@TexX-4
  4637.           sub edx,offset @@StartCode
  4638.           mov dword ptr [ecx+edx],eax
  4639.  
  4640.           {  @@TexY  }
  4641.           mov eax,_Axis; add eax,TDXRMachine_Axis.Y+1
  4642.           mov edx,offset @@TexY-4
  4643.           sub edx,offset @@StartCode
  4644.           mov dword ptr [ecx+edx],eax
  4645.  
  4646.           {  @@Dest  }
  4647.           mov eax,Dest; add eax,Byte(TDXRMachine_Color.R+1)
  4648.           mov edx,offset @@Dest-4
  4649.           sub edx,offset @@StartCode
  4650.           mov dword ptr [ecx+edx],eax
  4651.         end;
  4652.       end;
  4653.  
  4654.       {  Green Channel  }
  4655.       if chGreen in EnableChannels then
  4656.       begin
  4657.         asm
  4658.           jmp @@EndCode
  4659.         @@StartCode:
  4660.           movzx eax,byte ptr [offset _null]{}@@_BiLinearCol2:
  4661.           movzx edx,byte ptr [offset _null]{}@@TexX:
  4662.           imul eax,edx
  4663.           movzx ebx,byte ptr [offset _null]{}@@_BiLinearCol1:
  4664.           xor edx,$FF
  4665.           imul ebx,edx
  4666.           add ebx,eax
  4667.           xor edx,$FF
  4668.  
  4669.           movzx eax,byte ptr [offset _null]{}@@_BiLinearCol4:
  4670.           imul eax,edx
  4671.           movzx ebp,byte ptr [offset _null]{}@@_BiLinearCol3:
  4672.           xor edx,$FF
  4673.           imul ebp,edx
  4674.           add eax,ebp
  4675.  
  4676.           movzx edx,byte ptr [offset _Null]{}@@TexY:
  4677.           imul eax,edx
  4678.           xor edx,$FF
  4679.           imul ebx,edx
  4680.           add eax,ebx
  4681.           shr eax,16
  4682.  
  4683.           mov byte ptr [offset _Null],al{}@@Dest:
  4684.         @@EndCode:
  4685.           {$I DXRender.inc}
  4686.           {  @@_BiLinearCol1  }
  4687.           mov eax,_BiLinearCol1; add eax,Byte(TDXRMachine_Color.G+1)
  4688.           mov edx,offset @@_BiLinearCol1-4
  4689.           sub edx,offset @@StartCode
  4690.           mov dword ptr [ecx+edx],eax
  4691.  
  4692.           {  @@_BiLinearCol2  }
  4693.           mov eax,_BiLinearCol2; add eax,Byte(TDXRMachine_Color.G+1)
  4694.           mov edx,offset @@_BiLinearCol2-4
  4695.           sub edx,offset @@StartCode
  4696.           mov dword ptr [ecx+edx],eax
  4697.  
  4698.           {  @@_BiLinearCol3  }
  4699.           mov eax,_BiLinearCol3; add eax,Byte(TDXRMachine_Color.G+1)
  4700.           mov edx,offset @@_BiLinearCol3-4
  4701.           sub edx,offset @@StartCode
  4702.           mov dword ptr [ecx+edx],eax
  4703.  
  4704.           {  @@_BiLinearCol4  }
  4705.           mov eax,_BiLinearCol4; add eax,Byte(TDXRMachine_Color.G+1)
  4706.           mov edx,offset @@_BiLinearCol4-4
  4707.           sub edx,offset @@StartCode
  4708.           mov dword ptr [ecx+edx],eax
  4709.  
  4710.           {  @@TexX  }
  4711.           mov eax,_Axis; add eax,TDXRMachine_Axis.X+1
  4712.           mov edx,offset @@TexX-4
  4713.           sub edx,offset @@StartCode
  4714.           mov dword ptr [ecx+edx],eax
  4715.  
  4716.           {  @@TexY  }
  4717.           mov eax,_Axis; add eax,TDXRMachine_Axis.Y+1
  4718.           mov edx,offset @@TexY-4
  4719.           sub edx,offset @@StartCode
  4720.           mov dword ptr [ecx+edx],eax
  4721.  
  4722.           {  @@Dest  }
  4723.           mov eax,Dest; add eax,Byte(TDXRMachine_Color.G+1)
  4724.           mov edx,offset @@Dest-4
  4725.           sub edx,offset @@StartCode
  4726.           mov dword ptr [ecx+edx],eax
  4727.         end;
  4728.       end;
  4729.  
  4730.       {  Blue Channel  }
  4731.       if chBlue in EnableChannels then
  4732.       begin
  4733.         asm
  4734.           jmp @@EndCode
  4735.         @@StartCode:
  4736.           movzx eax,byte ptr [offset _null]{}@@_BiLinearCol2:
  4737.           movzx edx,byte ptr [offset _null]{}@@TexX:
  4738.           imul eax,edx
  4739.           movzx ebx,byte ptr [offset _null]{}@@_BiLinearCol1:
  4740.           xor edx,$FF
  4741.           imul ebx,edx
  4742.           add ebx,eax
  4743.           xor edx,$FF
  4744.  
  4745.           movzx eax,byte ptr [offset _null]{}@@_BiLinearCol4:
  4746.           imul eax,edx
  4747.           movzx ebp,byte ptr [offset _null]{}@@_BiLinearCol3:
  4748.           xor edx,$FF
  4749.           imul ebp,edx
  4750.           add eax,ebp
  4751.  
  4752.           movzx edx,byte ptr [offset _Null]{}@@TexY:
  4753.           imul eax,edx
  4754.           xor edx,$FF
  4755.           imul ebx,edx
  4756.           add eax,ebx
  4757.           shr eax,16
  4758.  
  4759.           mov byte ptr [offset _Null],al{}@@Dest:
  4760.         @@EndCode:
  4761.           {$I DXRender.inc}
  4762.           {  @@_BiLinearCol1  }
  4763.           mov eax,_BiLinearCol1; add eax,Byte(TDXRMachine_Color.B+1)
  4764.           mov edx,offset @@_BiLinearCol1-4
  4765.           sub edx,offset @@StartCode
  4766.           mov dword ptr [ecx+edx],eax
  4767.  
  4768.           {  @@_BiLinearCol2  }
  4769.           mov eax,_BiLinearCol2; add eax,Byte(TDXRMachine_Color.B+1)
  4770.           mov edx,offset @@_BiLinearCol2-4
  4771.           sub edx,offset @@StartCode
  4772.           mov dword ptr [ecx+edx],eax
  4773.  
  4774.           {  @@_BiLinearCol3  }
  4775.           mov eax,_BiLinearCol3; add eax,Byte(TDXRMachine_Color.B+1)
  4776.           mov edx,offset @@_BiLinearCol3-4
  4777.           sub edx,offset @@StartCode
  4778.           mov dword ptr [ecx+edx],eax
  4779.  
  4780.           {  @@_BiLinearCol4  }
  4781.           mov eax,_BiLinearCol4; add eax,Byte(TDXRMachine_Color.B+1)
  4782.           mov edx,offset @@_BiLinearCol4-4
  4783.           sub edx,offset @@StartCode
  4784.           mov dword ptr [ecx+edx],eax
  4785.  
  4786.           {  @@TexX  }
  4787.           mov eax,_Axis; add eax,TDXRMachine_Axis.X+1
  4788.           mov edx,offset @@TexX-4
  4789.           sub edx,offset @@StartCode
  4790.           mov dword ptr [ecx+edx],eax
  4791.  
  4792.           {  @@TexY  }
  4793.           mov eax,_Axis; add eax,TDXRMachine_Axis.Y+1
  4794.           mov edx,offset @@TexY-4
  4795.           sub edx,offset @@StartCode
  4796.           mov dword ptr [ecx+edx],eax
  4797.  
  4798.           {  @@Dest  }
  4799.           mov eax,Dest; add eax,Byte(TDXRMachine_Color.B+1)
  4800.           mov edx,offset @@Dest-4
  4801.           sub edx,offset @@StartCode
  4802.           mov dword ptr [ecx+edx],eax
  4803.         end;
  4804.       end;
  4805.  
  4806.       {  Alpha Channel  }
  4807.       if chAlpha in EnableChannels then
  4808.       begin
  4809.         asm
  4810.           jmp @@EndCode
  4811.         @@StartCode:
  4812.           movzx eax,byte ptr [offset _null]{}@@_BiLinearCol2:
  4813.           movzx edx,byte ptr [offset _null]{}@@TexX:
  4814.           imul eax,edx
  4815.           movzx ebx,byte ptr [offset _null]{}@@_BiLinearCol1:
  4816.           xor edx,$FF
  4817.           imul ebx,edx
  4818.           add ebx,eax
  4819.           xor edx,$FF
  4820.  
  4821.           movzx eax,byte ptr [offset _null]{}@@_BiLinearCol4:
  4822.           imul eax,edx
  4823.           movzx ebp,byte ptr [offset _null]{}@@_BiLinearCol3:
  4824.           xor edx,$FF
  4825.           imul ebp,edx
  4826.           add eax,ebp
  4827.  
  4828.           movzx edx,byte ptr [offset _Null]{}@@TexY:
  4829.           imul eax,edx
  4830.           xor edx,$FF
  4831.           imul ebx,edx
  4832.           add eax,ebx
  4833.           shr eax,16
  4834.  
  4835.           mov byte ptr [offset _Null],al{}@@Dest:
  4836.         @@EndCode:
  4837.           {$I DXRender.inc}
  4838.           {  @@_BiLinearCol1  }
  4839.           mov eax,_BiLinearCol1; add eax,Byte(TDXRMachine_Color.A+1)
  4840.           mov edx,offset @@_BiLinearCol1-4
  4841.           sub edx,offset @@StartCode
  4842.           mov dword ptr [ecx+edx],eax
  4843.  
  4844.           {  @@_BiLinearCol2  }
  4845.           mov eax,_BiLinearCol2; add eax,Byte(TDXRMachine_Color.A+1)
  4846.           mov edx,offset @@_BiLinearCol2-4
  4847.           sub edx,offset @@StartCode
  4848.           mov dword ptr [ecx+edx],eax
  4849.  
  4850.           {  @@_BiLinearCol3  }
  4851.           mov eax,_BiLinearCol3; add eax,Byte(TDXRMachine_Color.A+1)
  4852.           mov edx,offset @@_BiLinearCol3-4
  4853.           sub edx,offset @@StartCode
  4854.           mov dword ptr [ecx+edx],eax
  4855.  
  4856.           {  @@_BiLinearCol4  }
  4857.           mov eax,_BiLinearCol4; add eax,Byte(TDXRMachine_Color.A+1)
  4858.           mov edx,offset @@_BiLinearCol4-4
  4859.           sub edx,offset @@StartCode
  4860.           mov dword ptr [ecx+edx],eax
  4861.  
  4862.           {  @@TexX  }
  4863.           mov eax,_Axis; add eax,TDXRMachine_Axis.X+1
  4864.           mov edx,offset @@TexX-4
  4865.           sub edx,offset @@StartCode
  4866.           mov dword ptr [ecx+edx],eax
  4867.  
  4868.           {  @@TexY  }
  4869.           mov eax,_Axis; add eax,TDXRMachine_Axis.Y+1
  4870.           mov edx,offset @@TexY-4
  4871.           sub edx,offset @@StartCode
  4872.           mov dword ptr [ecx+edx],eax
  4873.  
  4874.           {  @@Dest  }
  4875.           mov eax,Dest; add eax,Byte(TDXRMachine_Color.A+1)
  4876.           mov edx,offset @@Dest-4
  4877.           sub edx,offset @@StartCode
  4878.           mov dword ptr [ecx+edx],eax
  4879.         end;
  4880.       end;
  4881.     end;
  4882.   end;
  4883.  
  4884.   procedure genReadTexture(var Code: Pointer; Dest: PDXRMachine_Color;
  4885.     const Texture: TDXRMachine_Reg_Texture; EnableChannels: TDXRColorChannels);
  4886.   begin
  4887.     if Texture.Filter in [DXR_TEXTUREFILTER_LINEAR, DXR_TEXTUREFILTER_MIPMAP_LINEAR] then
  4888.       genReadTexture_BiLinear(Code, Dest, Texture, Texture.nAxis, EnableChannels)
  4889.     else
  4890.       genReadTexture_Nearest(Code, Dest, Texture, Texture.nAxis, EnableChannels);
  4891.   end;
  4892.  
  4893.   procedure genReadBumpTexture_Nearest(var Code: Pointer; Dest: PDXRMachine_Color;
  4894.     const Texture, BumpTexture: TDXRMachine_Reg_Texture; EnableChannels: TDXRColorChannels);
  4895.   var
  4896.     _Axis, _Axis2, _iAxis, _BumpAxis, _BumpAxis2: PDXRMachine_Axis;
  4897.     _BumpTempCol: Pointer;
  4898.   begin
  4899.     if EnableChannels=[] then Exit;
  4900.  
  4901.     _Axis := @BumpTexture.nAxis;
  4902.     _Axis2 := @Texture.nAxis;
  4903.     _iAxis := @BumpTexture.iAxis;
  4904.     _BumpAxis := @F_BumpAxis;
  4905.     _BumpAxis2 := @F_BumpAxis2;
  4906.     _BumpTempCol := @F_BumpTempCol;
  4907.  
  4908.     {  X  }
  4909.     asm
  4910.       jmp @@EndCode
  4911.     @@StartCode:
  4912.       mov eax,dword ptr [offset _null]{}@@TexX:
  4913.       mov edx,dword ptr [offset _null]{}@@TexY:
  4914.       sub eax,dword ptr [offset _null]{}@@iTexX:
  4915.       mov dword ptr [offset _null],edx{}@@AxisY:
  4916.       mov dword ptr [offset _null],eax{}@@AxisX:
  4917.     @@EndCode:
  4918.       {$I DXRender.inc}
  4919.       {  @@TexX  }
  4920.       mov eax,_Axis; add eax,TDXRMachine_Axis.X
  4921.       mov edx,offset @@TexX-4
  4922.       sub edx,offset @@StartCode
  4923.       mov dword ptr [ecx+edx],eax
  4924.  
  4925.       {  @@TexY  }
  4926.       mov eax,_Axis; add eax,TDXRMachine_Axis.Y
  4927.       mov edx,offset @@TexY-4
  4928.       sub edx,offset @@StartCode
  4929.       mov dword ptr [ecx+edx],eax
  4930.  
  4931.       {  @@iTexX  }
  4932.       mov eax,_iAxis; add eax,TDXRMachine_Axis.X
  4933.       mov edx,offset @@iTexX-4
  4934.       sub edx,offset @@StartCode
  4935.       mov dword ptr [ecx+edx],eax
  4936.  
  4937.       {  @@AxisX  }
  4938.       mov eax,_BumpAxis; add eax,TDXRMachine_Axis.X
  4939.       mov edx,offset @@AxisX-4
  4940.       sub edx,offset @@StartCode
  4941.       mov dword ptr [ecx+edx],eax
  4942.  
  4943.       {  @@AxisY  }
  4944.       mov eax,_BumpAxis; add eax,TDXRMachine_Axis.Y
  4945.       mov edx,offset @@AxisY-4
  4946.       sub edx,offset @@StartCode
  4947.       mov dword ptr [ecx+edx],eax
  4948.     end;
  4949.     genReadSurfacePixel(Code, BumpTexture, _BumpAxis);
  4950.  
  4951.     asm
  4952.       jmp @@EndCode
  4953.     @@StartCode:
  4954.       mov dword ptr [offset _null],eax{}@@BumpTempCol:
  4955.     @@EndCode:
  4956.       {$I DXRender.inc}
  4957.       {  @@BumpTempCol  }
  4958.       mov eax,_BumpTempCol
  4959.       mov edx,offset @@BumpTempCol-4
  4960.       sub edx,offset @@StartCode
  4961.       mov dword ptr [ecx+edx],eax
  4962.     end;
  4963.  
  4964.     asm
  4965.       jmp @@EndCode
  4966.     @@StartCode:
  4967.       mov edx,dword ptr [offset _null]{}@@iAxisX:
  4968.       add dword ptr [offset _null],edx{}@@AxisX:
  4969.     @@EndCode:
  4970.       {$I DXRender.inc}
  4971.       {  @@iAxisX  }
  4972.       mov eax,_iAxis; add eax,TDXRMachine_Axis.X
  4973.       mov edx,offset @@iAxisX-4
  4974.       sub edx,offset @@StartCode
  4975.       mov dword ptr [ecx+edx],eax
  4976.  
  4977.       {  @@AxisX  }
  4978.       mov eax,_BumpAxis; add eax,TDXRMachine_Axis.X
  4979.       mov edx,offset @@AxisX-4
  4980.       sub edx,offset @@StartCode
  4981.       mov dword ptr [ecx+edx],eax
  4982.     end;
  4983.  
  4984.     genReadSurfacePixel(Code, BumpTexture, _BumpAxis);
  4985.  
  4986.     asm
  4987.       jmp @@EndCode
  4988.     @@StartCode:
  4989.       sub eax,dword ptr [offset _null]{}@@BumpTempCol:
  4990.       sal eax,16
  4991.       add eax,dword ptr [offset _null]{}@@TexX:
  4992.       mov dword ptr [offset _null],eax{}@@AxisX:
  4993.     @@EndCode:
  4994.       {$I DXRender.inc}
  4995.       {  @@BumpTempCol  }
  4996.       mov eax,_BumpTempCol
  4997.       mov edx,offset @@BumpTempCol-4
  4998.       sub edx,offset @@StartCode
  4999.       mov dword ptr [ecx+edx],eax
  5000.  
  5001.       {  @@TexX  }
  5002.       mov eax,_Axis2; add eax,TDXRMachine_Axis.X
  5003.       mov edx,offset @@TexX-4
  5004.       sub edx,offset @@StartCode
  5005.       mov dword ptr [ecx+edx],eax
  5006.  
  5007.       {  @@AxisX  }
  5008.       mov eax,_BumpAxis2; add eax,TDXRMachine_Axis.X
  5009.       mov edx,offset @@AxisX-4
  5010.       sub edx,offset @@StartCode
  5011.       mov dword ptr [ecx+edx],eax
  5012.     end;
  5013.  
  5014.     {  Y  }
  5015.     asm
  5016.       jmp @@EndCode
  5017.     @@StartCode:
  5018.       mov eax,dword ptr [offset _null]{}@@TexX:
  5019.       mov edx,dword ptr [offset _null]{}@@TexY:
  5020.       sub edx,dword ptr [offset _null]{}@@iTexY:
  5021.       mov dword ptr [offset _null],eax{}@@AxisX:
  5022.       mov dword ptr [offset _null],edx{}@@AxisY:
  5023.     @@EndCode:
  5024.       {$I DXRender.inc}
  5025.       {  @@TexX  }
  5026.       mov eax,_Axis; add eax,TDXRMachine_Axis.X
  5027.       mov edx,offset @@TexX-4
  5028.       sub edx,offset @@StartCode
  5029.       mov dword ptr [ecx+edx],eax
  5030.  
  5031.       {  @@TexY  }
  5032.       mov eax,_Axis; add eax,TDXRMachine_Axis.Y
  5033.       mov edx,offset @@TexY-4
  5034.       sub edx,offset @@StartCode
  5035.       mov dword ptr [ecx+edx],eax
  5036.  
  5037.       {  @@iTexY  }
  5038.       mov eax,_iAxis; add eax,TDXRMachine_Axis.Y
  5039.       mov edx,offset @@iTexY-4
  5040.       sub edx,offset @@StartCode
  5041.       mov dword ptr [ecx+edx],eax
  5042.  
  5043.       {  @@AxisX  }
  5044.       mov eax,_BumpAxis; add eax,TDXRMachine_Axis.X
  5045.       mov edx,offset @@AxisX-4
  5046.       sub edx,offset @@StartCode
  5047.       mov dword ptr [ecx+edx],eax
  5048.  
  5049.       {  @@AxisY  }
  5050.       mov eax,_BumpAxis; add eax,TDXRMachine_Axis.Y
  5051.       mov edx,offset @@AxisY-4
  5052.       sub edx,offset @@StartCode
  5053.       mov dword ptr [ecx+edx],eax
  5054.     end;
  5055.     genReadSurfacePixel(Code, BumpTexture, _BumpTempCol);
  5056.  
  5057.     asm
  5058.       jmp @@EndCode
  5059.     @@StartCode:
  5060.       mov dword ptr [offset _null],eax{}@@BumpTempCol:
  5061.     @@EndCode:
  5062.       {$I DXRender.inc}
  5063.       {  @@BumpTempCol  }
  5064.       mov eax,_BumpTempCol
  5065.       mov edx,offset @@BumpTempCol-4
  5066.       sub edx,offset @@StartCode
  5067.       mov dword ptr [ecx+edx],eax
  5068.     end;
  5069.  
  5070.     asm
  5071.       jmp @@EndCode
  5072.     @@StartCode:
  5073.       mov edx,dword ptr [offset _null]{}@@iAxisY:
  5074.       sal edx,1
  5075.       sub dword ptr [offset _null],edx{}@@AxisY:
  5076.     @@EndCode:
  5077.       {$I DXRender.inc}
  5078.       {  @@iAxisY  }
  5079.       mov eax,_iAxis; add eax,TDXRMachine_Axis.Y
  5080.       mov edx,offset @@iAxisY-4
  5081.       sub edx,offset @@StartCode
  5082.       mov dword ptr [ecx+edx],eax
  5083.  
  5084.       {  @@AxisY  }
  5085.       mov eax,_BumpAxis; add eax,TDXRMachine_Axis.Y
  5086.       mov edx,offset @@AxisY-4
  5087.       sub edx,offset @@StartCode
  5088.       mov dword ptr [ecx+edx],eax
  5089.     end;
  5090.  
  5091.     genReadSurfacePixel(Code, BumpTexture, _BumpAxis);
  5092.  
  5093.     asm
  5094.       jmp @@EndCode
  5095.     @@StartCode:
  5096.       sub eax,dword ptr [offset _null]{}@@BumpTempCol:
  5097.       sal eax,16
  5098.       add eax,dword ptr [offset _null]{}@@TexY:
  5099.       mov dword ptr [offset _null],eax{}@@AxisY:
  5100.     @@EndCode:
  5101.       {$I DXRender.inc}
  5102.       {  @@BumpTempCol  }
  5103.       mov eax,_BumpTempCol
  5104.       mov edx,offset @@BumpTempCol-4
  5105.       sub edx,offset @@StartCode
  5106.       mov dword ptr [ecx+edx],eax
  5107.  
  5108.       {  @@TexX  }
  5109.       mov eax,_Axis2; add eax,TDXRMachine_Axis.Y
  5110.       mov edx,offset @@TexY-4
  5111.       sub edx,offset @@StartCode
  5112.       mov dword ptr [ecx+edx],eax
  5113.  
  5114.       {  @@AxisX  }
  5115.       mov eax,_BumpAxis2; add eax,TDXRMachine_Axis.Y
  5116.       mov edx,offset @@AxisY-4
  5117.       sub edx,offset @@StartCode
  5118.       mov dword ptr [ecx+edx],eax
  5119.     end;
  5120.  
  5121.     genReadTexture_Nearest(Code, Dest, Texture, _BumpAxis2^, EnableChannels);
  5122.   end;
  5123.  
  5124.   procedure genReadBumpTexture(var Code: Pointer; Dest: PDXRMachine_Color;
  5125.     const Texture, BumpTexture: TDXRMachine_Reg_Texture; EnableChannels: TDXRColorChannels);
  5126.   begin
  5127.     {if Texture.Filter in [DXR_TEXTUREFILTER_LINEAR, DXR_TEXTUREFILTER_MIPMAP_LINEAR] then
  5128.       genReadBumpTexture_BiLinear(Code, Dest, Texture, BumpTexture, EnableChannels)
  5129.     else }
  5130.       genReadBumpTexture_Nearest(Code, Dest, Texture, BumpTexture, EnableChannels);
  5131.   end;
  5132.  
  5133.   procedure genUpdateAxis(var Code: Pointer);
  5134.   var
  5135.     _Axis: Pointer;
  5136.   begin
  5137.     if not Axis.IncEnable then Exit;
  5138.  
  5139.     _Axis := @Axis.Axis;
  5140.  
  5141.     asm
  5142.       jmp @@EndCode
  5143.     @@StartCode:
  5144.       inc dword ptr [offset _null]{}@@AxisX:
  5145.     @@EndCode:
  5146.       {$I DXRender.inc}
  5147.       {  @@AxisX  }
  5148.       mov eax,_Axis; add eax,TDXRMachine_Axis.X
  5149.       mov edx,offset @@AxisX-4
  5150.       sub edx,offset @@StartCode
  5151.       mov dword ptr [ecx+edx],eax
  5152.     end;
  5153.   end;
  5154.  
  5155.   procedure genUpdateColor(var Code: Pointer);
  5156.   var
  5157.     i: Integer;
  5158.     Color: PDXRMachine_Reg_Color;
  5159.     nColor, iColor: Pointer;
  5160.   begin
  5161.     for i:=0 to ColorIndexCount-1 do
  5162.     begin
  5163.       Color := @ColorList[ColorIndex[i]];
  5164.       if Color.Gouraud then
  5165.       begin
  5166.         nColor := @Color.nColor;
  5167.         iColor := @Color.iColor;
  5168.  
  5169.         if UseMMX then
  5170.         begin
  5171.           FMMXUsed := True;
  5172.           asm
  5173.             jmp @@EndCode
  5174.           @@StartCode:
  5175.             db $0F,$6F,$05,$11,$11,$11,$11///movq mm0,qword ptr [$11111111]
  5176.                                    @@_nColor:
  5177.             db $0F,$FD,$05,$11,$11,$11,$11///paddw mm0,qword ptr [$11111111]
  5178.                                    @@_iColor:
  5179.             db $0F,$7F,$05,$11,$11,$11,$11///movq qword ptr [$11111111],mm0
  5180.                                    @@_nColor2:
  5181.           @@EndCode:
  5182.             {$I DXRender.inc}
  5183.             {  @@_nColor  }
  5184.             mov eax,nColor
  5185.             mov edx,offset @@_nColor-4
  5186.             sub edx,offset @@StartCode
  5187.             mov dword ptr [ecx+edx],eax
  5188.  
  5189.             {  @@_iColor  }
  5190.             mov eax,iColor
  5191.             mov edx,offset @@_iColor-4
  5192.             sub edx,offset @@StartCode
  5193.             mov dword ptr [ecx+edx],eax
  5194.  
  5195.             {  @@_nColor2  }
  5196.             mov eax,nColor
  5197.             mov edx,offset @@_nColor2-4
  5198.             sub edx,offset @@StartCode
  5199.             mov dword ptr [ecx+edx],eax
  5200.           end;
  5201.         end else
  5202.         begin
  5203.           asm
  5204.             jmp @@EndCode
  5205.           @@StartCode:
  5206.             mov eax,dword ptr [offset _null]{}@@nColor11:
  5207.             mov edx,dword ptr [offset _null]{}@@nColor12:
  5208.             add eax,dword ptr [offset _null]{}@@iColor1:
  5209.             add edx,dword ptr [offset _null]{}@@iColor2:
  5210.             mov dword ptr [offset _null],eax{}@@nColor21:
  5211.             mov dword ptr [offset _null],edx{}@@nColor22:
  5212.           @@EndCode:
  5213.             {$I DXRender.inc}
  5214.  
  5215.             {  @@nColor11  }
  5216.             mov eax,nColor
  5217.             mov edx,offset @@nColor11-4
  5218.             sub edx,offset @@StartCode
  5219.             mov dword ptr [ecx+edx],eax
  5220.  
  5221.             {  @@nColor12  }
  5222.             mov eax,nColor; add eax,4
  5223.             mov edx,offset @@nColor12-4
  5224.             sub edx,offset @@StartCode
  5225.             mov dword ptr [ecx+edx],eax
  5226.  
  5227.             {  @@iColor1  }
  5228.             mov eax,iColor
  5229.             mov edx,offset @@iColor1-4
  5230.             sub edx,offset @@StartCode
  5231.             mov dword ptr [ecx+edx],eax
  5232.  
  5233.             {  @@iColor2  }
  5234.             mov eax,iColor; add eax,4
  5235.             mov edx,offset @@iColor2-4
  5236.             sub edx,offset @@StartCode
  5237.             mov dword ptr [ecx+edx],eax
  5238.  
  5239.             {  @@nColor21  }
  5240.             mov eax,nColor
  5241.             mov edx,offset @@nColor21-4
  5242.             sub edx,offset @@StartCode
  5243.             mov dword ptr [ecx+edx],eax
  5244.  
  5245.             {  @@nColor22  }
  5246.             mov eax,nColor; add eax,4
  5247.             mov edx,offset @@nColor22-4
  5248.             sub edx,offset @@StartCode
  5249.             mov dword ptr [ecx+edx],eax
  5250.           end;
  5251.         end;
  5252.       end;
  5253.     end;
  5254.   end;
  5255.  
  5256.   procedure genUpdateTextureAxis(var Code: Pointer);
  5257.   var
  5258.     i: Integer;
  5259.     Texture: PDXRMachine_Reg_Texture;
  5260.     nTex, iTex: Pointer;
  5261.   begin
  5262.     for i:=0 to TextureIndexCount-1 do
  5263.     begin
  5264.       Texture := @TextureList[TextureIndex[i]];
  5265.  
  5266.       nTex := @Texture.nAxis;
  5267.       iTex := @Texture.iAxis;
  5268.  
  5269.       if UseMMX then
  5270.       begin
  5271.         FMMXUsed := True;
  5272.         asm
  5273.           jmp @@EndCode
  5274.         @@StartCode:
  5275.           db $0F,$6F,$05,$11,$11,$11,$11///movq mm0,qword ptr [$11111111]
  5276.                                  @@nTex:
  5277.           db $0F,$FE,$05,$11,$11,$11,$11///paddd mm0,qword ptr [$11111111]
  5278.                                  @@iTex:
  5279.           db $0F,$7F,$05,$11,$11,$11,$11///movq qword ptr [$11111111],mm0
  5280.                                  @@nTex2:
  5281.         @@EndCode:
  5282.           {$I DXRender.inc}
  5283.           {  @@nTex  }
  5284.           mov eax,nTex
  5285.           mov edx,offset @@nTex-4
  5286.           sub edx,offset @@StartCode
  5287.           mov dword ptr [ecx+edx],eax
  5288.  
  5289.           {  @@nTex2  }
  5290.           mov eax,nTex
  5291.           mov edx,offset @@nTex2-4
  5292.           sub edx,offset @@StartCode
  5293.           mov dword ptr [ecx+edx],eax
  5294.  
  5295.           {  @@iTex  }
  5296.           mov eax,iTex
  5297.           mov edx,offset @@iTex-4
  5298.           sub edx,offset @@StartCode
  5299.           mov dword ptr [ecx+edx],eax
  5300.         end;
  5301.       end else
  5302.       begin
  5303.         if Texture.iAxisConstant then
  5304.         begin
  5305.           if Texture.iAxis.X<>0 then
  5306.           begin
  5307.             asm
  5308.               jmp @@EndCode
  5309.             @@StartCode:
  5310.               add dword ptr [offset _Null],$11111111{}@@nTexX:
  5311.             @@EndCode:
  5312.               {$I DXRender.inc}
  5313.               {  @@nTexX  }
  5314.               mov eax,iTex; add eax,TDXRMachine_Axis.X; mov eax,dword ptr [eax]
  5315.               mov edx,offset @@nTexX-4
  5316.               sub edx,offset @@StartCode
  5317.               mov dword ptr [ecx+edx],eax
  5318.  
  5319.               mov eax,nTex; add eax,TDXRMachine_Axis.X
  5320.               mov edx,offset @@nTexX-8
  5321.               sub edx,offset @@StartCode
  5322.               mov dword ptr [ecx+edx],eax
  5323.             end;
  5324.           end;
  5325.  
  5326.           if Texture.iAxis.Y<>0 then
  5327.           begin
  5328.             asm
  5329.               jmp @@EndCode
  5330.             @@StartCode:
  5331.               add dword ptr [offset _Null],$11111111{}@@nTexY:
  5332.             @@EndCode:
  5333.               {$I DXRender.inc}
  5334.               {  @@nTexY  }
  5335.               mov eax,iTex; add eax,TDXRMachine_Axis.Y; mov eax,dword ptr [eax]
  5336.               mov edx,offset @@nTexY-4
  5337.               sub edx,offset @@StartCode
  5338.               mov dword ptr [ecx+edx],eax
  5339.                                          
  5340.               mov eax,nTex; add eax,TDXRMachine_Axis.Y
  5341.               mov edx,offset @@nTexY-8
  5342.               sub edx,offset @@StartCode
  5343.               mov dword ptr [ecx+edx],eax
  5344.             end;
  5345.           end;
  5346.         end else
  5347.         //begin
  5348.          if UseMMX then
  5349.          begin
  5350.           FMMXUsed := True;
  5351.           asm
  5352.             jmp @@EndCode
  5353.           @@StartCode:
  5354.             db $0F,$6F,$05,$11,$11,$11,$11///movq mm0,qword ptr [$11111111]
  5355.                                    @@nTex:
  5356.             db $0F,$FE,$05,$11,$11,$11,$11///paddd mm0,qword ptr [$11111111]
  5357.                                    @@iTex:
  5358.             db $0F,$7F,$05,$11,$11,$11,$11///movq qword ptr [$11111111],mm0
  5359.                                    @@nTex2:
  5360.           @@EndCode:
  5361.             {$I DXRender.inc}
  5362.             {  @@nTex  }
  5363.             mov eax,nTex
  5364.             mov edx,offset @@nTex-4
  5365.             sub edx,offset @@StartCode
  5366.             mov dword ptr [ecx+edx],eax
  5367.  
  5368.             {  @@nTex2  }
  5369.             mov eax,nTex
  5370.             mov edx,offset @@nTex2-4
  5371.             sub edx,offset @@StartCode
  5372.             mov dword ptr [ecx+edx],eax
  5373.  
  5374.             {  @@iTex  }
  5375.             mov eax,iTex
  5376.             mov edx,offset @@iTex-4
  5377.             sub edx,offset @@StartCode
  5378.             mov dword ptr [ecx+edx],eax
  5379.           end;
  5380.          end else
  5381.          begin
  5382.  
  5383.           asm
  5384.             jmp @@EndCode
  5385.           @@StartCode:
  5386.             mov eax,dword ptr [offset _Null]{}@@iTexX:
  5387.             mov edx,dword ptr [offset _Null]{}@@iTexY:
  5388.             add dword ptr [offset _Null],eax{}@@nTexX:
  5389.             add dword ptr [offset _Null],edx{}@@nTexY:
  5390.           @@EndCode:
  5391.             {$I DXRender.inc}
  5392.             {  @@iTexX  }
  5393.             mov eax,iTex; add eax,TDXRMachine_Axis.X
  5394.             mov edx,offset @@iTexX-4
  5395.             sub edx,offset @@StartCode
  5396.             mov dword ptr [ecx+edx],eax
  5397.  
  5398.             {  @@iTexY  }
  5399.             mov eax,iTex; add eax,TDXRMachine_Axis.Y
  5400.             mov edx,offset @@iTexY-4
  5401.             sub edx,offset @@StartCode
  5402.             mov dword ptr [ecx+edx],eax
  5403.  
  5404.             {  @@nTexX  }
  5405.             mov eax,nTex; add eax,TDXRMachine_Axis.X
  5406.             mov edx,offset @@nTexX-4
  5407.             sub edx,offset @@StartCode
  5408.             mov dword ptr [ecx+edx],eax
  5409.  
  5410.             {  @@nTexY  }
  5411.             mov eax,nTex; add eax,TDXRMachine_Axis.Y
  5412.             mov edx,offset @@nTexY-4
  5413.             sub edx,offset @@StartCode
  5414.             mov dword ptr [ecx+edx],eax
  5415.           end;
  5416.         end;
  5417.       end;
  5418.     end;
  5419.   end;
  5420.  
  5421.   procedure genUpdateRHW(var Code: Pointer);
  5422.   var
  5423.     nRHW, iRHW: Pointer;
  5424.   begin
  5425.     if not RHW.Enable then Exit;
  5426.  
  5427.     nRHW := @RHW.nRHW;
  5428.     iRHW := @RHW.iRHW;
  5429.  
  5430.     asm
  5431.       jmp @@EndCode
  5432.     @@StartCode:
  5433.       // 64 bit addition
  5434.       mov eax,dword ptr [offset _null]{}@@iRHW:
  5435.       mov edx,dword ptr [offset _null]{}@@iRHW2:
  5436.       add dword ptr [offset _null],eax{}@@nRHW:
  5437.       adc dword ptr [offset _null],edx{}@@nRHW2:
  5438.     @@EndCode:
  5439.       {$I DXRender.inc}
  5440.       {  @@nRHW  }
  5441.       mov eax,nRHW
  5442.       mov edx,offset @@nRHW-4
  5443.       sub edx,offset @@StartCode
  5444.       mov dword ptr [ecx+edx],eax
  5445.  
  5446.       {  @@nRHW2  }
  5447.       mov eax,nRHW; add eax,4
  5448.       mov edx,offset @@nRHW2-4
  5449.       sub edx,offset @@StartCode
  5450.       mov dword ptr [ecx+edx],eax
  5451.  
  5452.       {  @@iRHW  }
  5453.       mov eax,iRHW
  5454.       mov edx,offset @@iRHW-4
  5455.       sub edx,offset @@StartCode
  5456.       mov dword ptr [ecx+edx],eax
  5457.  
  5458.       {  @@iRHW  }
  5459.       mov eax,iRHW; add eax,4
  5460.       mov edx,offset @@iRHW2-4
  5461.       sub edx,offset @@StartCode
  5462.       mov dword ptr [ecx+edx],eax
  5463.     end;
  5464.   end;
  5465.  
  5466.   procedure genBlend(var Code: Pointer; Blend: TDXR_Blend;
  5467.     Dest, Col1, Col2: PDXRMachine_Color; EnableChannels: TDXRColorChannels;
  5468.     ConstChannels1, ConstChannels2: TDXRColorChannels);
  5469.  
  5470.     procedure Func_col1_Add_col2(var Code: Pointer; Dest, col1, col2: PWord);
  5471.     begin
  5472.       asm
  5473.         jmp @@EndCode
  5474.       @@StartCode:
  5475.         movzx eax,byte ptr [offset _null]{}@@Col1:
  5476.         movzx edx,byte ptr [offset _null]{}@@Col2:
  5477.         mov al,byte ptr [offset (_AddTable + eax + edx)]
  5478.         mov byte ptr [offset _null],al{}@@Dest:
  5479.       @@EndCode:
  5480.         {$I DXRender.inc}
  5481.         {  @@Col1  }
  5482.         mov eax,Col1; inc eax
  5483.         mov edx,offset @@Col1-4
  5484.         sub edx,offset @@StartCode
  5485.         mov dword ptr [ecx+edx],eax
  5486.  
  5487.         {  @@Col2  }
  5488.         mov eax,Col2; inc eax
  5489.         mov edx,offset @@Col2-4
  5490.         sub edx,offset @@StartCode
  5491.         mov dword ptr [ecx+edx],eax
  5492.  
  5493.         {  @@Dest  }
  5494.         mov eax,Dest; inc eax
  5495.         mov edx,offset @@Dest-4
  5496.         sub edx,offset @@StartCode
  5497.         mov dword ptr [ecx+edx],eax
  5498.       end;
  5499.     end;
  5500.  
  5501.     procedure Func_col1_Add_const2(var Code: Pointer; Dest, col1, col2: PWord);
  5502.     begin
  5503.       asm
  5504.         jmp @@EndCode
  5505.       @@StartCode:
  5506.         movzx eax,byte ptr [offset _null]{}@@Col1:
  5507.         mov al,byte ptr [$11111111 + eax]{}@@Col2:
  5508.         mov byte ptr [offset _null],al{}@@Dest:
  5509.       @@EndCode:
  5510.         {$I DXRender.inc}
  5511.         {  @@Col1  }
  5512.         mov eax,Col1; inc eax
  5513.         mov edx,offset @@Col1-4
  5514.         sub edx,offset @@StartCode
  5515.         mov dword ptr [ecx+edx],eax
  5516.  
  5517.         {  @@Col2  }
  5518.         mov eax,Col2; inc eax; movzx eax,byte ptr [eax]
  5519.         add eax,offset _AddTable
  5520.  
  5521.         mov edx,offset @@Col2-4
  5522.         sub edx,offset @@StartCode
  5523.         mov dword ptr [ecx+edx],eax
  5524.  
  5525.         {  @@Dest  }
  5526.         mov eax,Dest; inc eax
  5527.         mov edx,offset @@Dest-4
  5528.         sub edx,offset @@StartCode
  5529.         mov dword ptr [ecx+edx],eax
  5530.       end;
  5531.     end;
  5532.  
  5533.     procedure Func_col1_Sub_col2(var Code: Pointer; Dest, col1, col2: PWord);
  5534.     begin
  5535.       asm
  5536.         jmp @@EndCode
  5537.       @@StartCode:    
  5538.         movzx eax,byte ptr [offset _null]{}@@Col1:
  5539.         movzx edx,byte ptr [offset _null]{}@@Col2:
  5540.         sub eax,edx
  5541.         mov al,byte ptr [offset (_SubTable + 255 + eax)]
  5542.         mov byte ptr [offset _null],al{}@@Dest:
  5543.       @@EndCode:
  5544.         {$I DXRender.inc}
  5545.         {  @@Col1  }
  5546.         mov eax,Col1; inc eax
  5547.         mov edx,offset @@Col1-4
  5548.         sub edx,offset @@StartCode
  5549.         mov dword ptr [ecx+edx],eax
  5550.  
  5551.         {  @@Col2  }
  5552.         mov eax,Col2; inc eax
  5553.         mov edx,offset @@Col2-4
  5554.         sub edx,offset @@StartCode
  5555.         mov dword ptr [ecx+edx],eax
  5556.  
  5557.         {  @@Dest  }
  5558.         mov eax,Dest; inc eax
  5559.         mov edx,offset @@Dest-4
  5560.         sub edx,offset @@StartCode
  5561.         mov dword ptr [ecx+edx],eax
  5562.       end;
  5563.     end;
  5564.  
  5565.     procedure Func_const1_Sub_col2(var Code: Pointer; Dest, col1, col2: PWord);
  5566.     begin
  5567.       asm
  5568.         jmp @@EndCode
  5569.       @@StartCode:
  5570.         mov eax,$11111111{}@@Col1:
  5571.         movzx edx,byte ptr [offset _null]{}@@Col2:
  5572.         sub eax,edx
  5573.         mov al,byte ptr [offset (_SubTable + 255 + eax)]
  5574.         mov byte ptr [offset _null],al{}@@Dest:
  5575.       @@EndCode:
  5576.         {$I DXRender.inc}
  5577.         {  @@Col1  }
  5578.         mov eax,Col1; inc eax; movzx eax,byte ptr [eax]
  5579.         mov edx,offset @@Col1-4
  5580.         sub edx,offset @@StartCode
  5581.         mov dword ptr [ecx+edx],eax
  5582.  
  5583.         {  @@Col2  }
  5584.         mov eax,Col2; inc eax
  5585.         mov edx,offset @@Col2-4
  5586.         sub edx,offset @@StartCode
  5587.         mov dword ptr [ecx+edx],eax
  5588.  
  5589.         {  @@Dest  }
  5590.         mov eax,Dest; inc eax
  5591.         mov edx,offset @@Dest-4
  5592.         sub edx,offset @@StartCode
  5593.         mov dword ptr [ecx+edx],eax
  5594.       end;
  5595.     end;
  5596.  
  5597.     procedure Func_col1_Sub_const2(var Code: Pointer; Dest, col1, col2: PWord);
  5598.     begin
  5599.       asm
  5600.         jmp @@EndCode
  5601.       @@StartCode:
  5602.         movzx eax,byte ptr [offset _null]{}@@Col1:
  5603.         mov al,byte ptr [$11111111 + eax]{}@@Col2:
  5604.         mov byte ptr [offset _null],al{}@@Dest:
  5605.       @@EndCode:
  5606.         {$I DXRender.inc}
  5607.         {  @@Col1  }
  5608.         mov eax,Col1; inc eax
  5609.         mov edx,offset @@Col1-4
  5610.         sub edx,offset @@StartCode
  5611.         mov dword ptr [ecx+edx],eax
  5612.  
  5613.         {  @@Col2  }
  5614.         mov eax,Col2; inc eax; movzx eax,byte ptr [eax]; neg eax
  5615.         add eax,offset _SubTable+255
  5616.  
  5617.         mov edx,offset @@Col2-4
  5618.         sub edx,offset @@StartCode
  5619.         mov dword ptr [ecx+edx],eax
  5620.  
  5621.         {  @@Dest  }
  5622.         mov eax,Dest; add eax,Byte(TDXRMachine_Color.R+1)
  5623.         mov edx,offset @@Dest-4
  5624.         sub edx,offset @@StartCode
  5625.         mov dword ptr [ecx+edx],eax
  5626.       end;
  5627.     end;
  5628.  
  5629.     procedure genBlend_ZERO(var Code: Pointer; Dest: PDXRMachine_Color);
  5630.     begin
  5631.       asm
  5632.         jmp @@EndCode
  5633.       @@StartCode:
  5634.         mov dword ptr [offset _null],0{}@@Dest:
  5635.         mov dword ptr [offset _null],0{}@@Dest2:
  5636.       @@EndCode:
  5637.         {$I DXRender.inc}
  5638.         {  @@Dest  }
  5639.         mov eax,Dest
  5640.         mov edx,offset @@Dest-8
  5641.         sub edx,offset @@StartCode
  5642.         mov dword ptr [ecx+edx],eax
  5643.  
  5644.         {  @@Dest2  }
  5645.         mov eax,Dest; add eax,4
  5646.         mov edx,offset @@Dest2-8
  5647.         sub edx,offset @@StartCode
  5648.         mov dword ptr [ecx+edx],eax
  5649.       end;
  5650.     end;
  5651.  
  5652.     procedure genBlend_ONE1(var Code: Pointer; Dest, Col1: PDXRMachine_Color;
  5653.       ConstChannels1: TDXRColorChannels);
  5654.     begin
  5655.       if Dest=Col1 then Exit;
  5656.  
  5657.       if UseMMX then //False then//UseMMX then
  5658.       begin
  5659.         FMMXUsed := True;
  5660.         asm
  5661.           jmp @@EndCode
  5662.         @@StartCode:
  5663.           db $0F,$6F,$05,$11,$11,$11,$11///movq mm0,qword ptr [$11111111]
  5664.                                  @@Col:
  5665.           db $0F,$7F,$05,$11,$11,$11,$11///movq qword ptr [$11111111],mm0
  5666.                                  @@Dest:
  5667.         @@EndCode:
  5668.           {$I DXRender.inc}
  5669.           {  @@Col  }
  5670.           mov eax,Col1
  5671.           mov edx,offset @@Col-4
  5672.           sub edx,offset @@StartCode
  5673.           mov dword ptr [ecx+edx],eax
  5674.  
  5675.           {  @@Dest  }
  5676.           mov eax,Dest
  5677.           mov edx,offset @@Dest-4
  5678.           sub edx,offset @@StartCode
  5679.           mov dword ptr [ecx+edx],eax
  5680.         end;
  5681.       end else
  5682.       begin
  5683.         if ConstChannels1=[chRed, chGreen, chBlue, chAlpha] then
  5684.         begin
  5685.           asm
  5686.             jmp @@EndCode
  5687.           @@StartCode:
  5688.             mov dword ptr [offset _null],$11111111{}@@Dest:
  5689.             mov dword ptr [offset _null],$11111111{}@@Dest2:
  5690.           @@EndCode:
  5691.             {$I DXRender.inc}
  5692.             {  @@Dest  }
  5693.             mov eax,Col1
  5694.             mov eax,dword ptr [eax]
  5695.             mov edx,offset @@Dest-4
  5696.             sub edx,offset @@StartCode
  5697.             mov dword ptr [ecx+edx],eax
  5698.  
  5699.             mov eax,Dest
  5700.             mov edx,offset @@Dest-8
  5701.             sub edx,offset @@StartCode
  5702.             mov dword ptr [ecx+edx],eax
  5703.  
  5704.             {  @@Dest2  }
  5705.             mov eax,Col1; add eax,4
  5706.             mov eax,dword ptr [eax]
  5707.             mov edx,offset @@Dest2-4
  5708.             sub edx,offset @@StartCode
  5709.             mov dword ptr [ecx+edx],eax
  5710.  
  5711.             mov eax,Dest; add eax,8
  5712.             mov edx,offset @@Dest2-4
  5713.             sub edx,offset @@StartCode
  5714.             mov dword ptr [ecx+edx],eax
  5715.           end;
  5716.         end else
  5717.         begin
  5718.           asm
  5719.             jmp @@EndCode
  5720.           @@StartCode:
  5721.             mov eax,dword ptr [offset _null]{}@@Col:
  5722.             mov edx,dword ptr [offset _null]{}@@Col2:
  5723.             mov dword ptr [offset _null],eax{}@@Dest:
  5724.             mov dword ptr [offset _null],edx{}@@Dest2:
  5725.           @@EndCode:
  5726.             {$I DXRender.inc}
  5727.             {  @@Col  }
  5728.             mov eax,Col1
  5729.             mov edx,offset @@Col-4
  5730.             sub edx,offset @@StartCode
  5731.             mov dword ptr [ecx+edx],eax
  5732.  
  5733.             {  @@Col2  }
  5734.             mov eax,Col1; add eax,4
  5735.             mov edx,offset @@Col2-4
  5736.             sub edx,offset @@StartCode
  5737.             mov dword ptr [ecx+edx],eax
  5738.  
  5739.             {  @@Dest  }
  5740.             mov eax,Dest
  5741.             mov edx,offset @@Dest-4
  5742.             sub edx,offset @@StartCode
  5743.             mov dword ptr [ecx+edx],eax
  5744.  
  5745.             {  @@Dest2  }
  5746.             mov eax,Dest; add eax,4
  5747.             mov edx,offset @@Dest2-4
  5748.             sub edx,offset @@StartCode
  5749.             mov dword ptr [ecx+edx],eax
  5750.           end;
  5751.         end;
  5752.       end;
  5753.     end;
  5754.  
  5755.     procedure genBlend_ONE1_ADD_ONE2(var Code: Pointer; Dest, Col1, Col2: PDXRMachine_Color;
  5756.       ConstChannels1, ConstChannels12: TDXRColorChannels);
  5757.     begin
  5758.       if UseMMX then
  5759.       begin
  5760.         FMMXUsed := True;
  5761.         asm
  5762.           jmp @@EndCode
  5763.         @@StartCode:
  5764.           db $0F,$6F,$05,$11,$11,$11,$11///movq mm0,qword ptr [$11111111]
  5765.                                  @@Col1:
  5766.           db $0F,$6F,$0D,$11,$11,$11,$11///movq mm1,qword ptr [$11111111]
  5767.                                  @@Col2:
  5768.           db $0F,$DD,$C1      ///paddusw mm0,mm1
  5769.           db $0F,$7F,$05,$11,$11,$11,$11///movq qword ptr [$11111111],mm0
  5770.                                  @@Dest:
  5771.         @@EndCode:
  5772.           {$I DXRender.inc}
  5773.           {  @@Col1  }
  5774.           mov eax,Col1
  5775.           mov edx,offset @@Col1-4
  5776.           sub edx,offset @@StartCode
  5777.           mov dword ptr [ecx+edx],eax
  5778.  
  5779.           {  @@Col2  }
  5780.           mov eax,Col2
  5781.           mov edx,offset @@Col2-4
  5782.           sub edx,offset @@StartCode
  5783.           mov dword ptr [ecx+edx],eax
  5784.  
  5785.           {  @@Dest  }
  5786.           mov eax,Dest
  5787.           mov edx,offset @@Dest-4
  5788.           sub edx,offset @@StartCode
  5789.           mov dword ptr [ecx+edx],eax
  5790.         end;
  5791.       end else
  5792.       begin
  5793.         { Red Channel }
  5794.         if chRed in EnableChannels then
  5795.         begin
  5796.           if chRed in ConstChannels1 then
  5797.           begin
  5798.             Func_col1_Add_const2(Code, @Dest.R, @Col2.R, @Col1.R);
  5799.           end else
  5800.           if chRed in ConstChannels2 then
  5801.           begin
  5802.             Func_col1_Add_const2(Code, @Dest.R, @Col1.R, @Col2.R);
  5803.           end else
  5804.             Func_col1_Add_col2(Code, @Dest.R, @Col1.R, @Col2.R);
  5805.         end;
  5806.  
  5807.         { Green Channel }
  5808.         if chGreen in EnableChannels then
  5809.         begin
  5810.           if chRed in ConstChannels1 then
  5811.           begin
  5812.             Func_col1_Add_const2(Code, @Dest.G, @Col2.G, @Col1.G);
  5813.           end else
  5814.           if chRed in ConstChannels2 then
  5815.           begin
  5816.             Func_col1_Add_const2(Code, @Dest.G, @Col1.G, @Col2.G);
  5817.           end else
  5818.             Func_col1_Add_col2(Code, @Dest.G, @Col1.G, @Col2.G);
  5819.         end;
  5820.  
  5821.         { Blue Channel }
  5822.         if chBlue in EnableChannels then
  5823.         begin
  5824.           if chRed in ConstChannels1 then
  5825.           begin
  5826.             Func_col1_Add_const2(Code, @Dest.B, @Col2.B, @Col1.B);
  5827.           end else
  5828.           if chRed in ConstChannels2 then
  5829.           begin
  5830.             Func_col1_Add_const2(Code, @Dest.B, @Col1.B, @Col2.B);
  5831.           end else
  5832.             Func_col1_Add_col2(Code, @Dest.B, @Col1.B, @Col2.B);
  5833.         end;
  5834.  
  5835.         { Alpha Channel }
  5836.         if chAlpha in EnableChannels then
  5837.         begin
  5838.           if chRed in ConstChannels1 then
  5839.           begin
  5840.             Func_col1_Add_const2(Code, @Dest.A, @Col2.A, @Col1.A);
  5841.           end else
  5842.           if chRed in ConstChannels2 then
  5843.           begin
  5844.             Func_col1_Add_const2(Code, @Dest.A, @Col1.A, @Col2.A);
  5845.           end else
  5846.             Func_col1_Add_col2(Code, @Dest.A, @Col1.A, @Col2.A);
  5847.         end;
  5848.       end;
  5849.     end;
  5850.  
  5851.     procedure genBlend_ONE2_SUB_ONE1(var Code: Pointer; Dest, Col1, Col2: PDXRMachine_Color;
  5852.       ConstChannels1, ConstChannels12: TDXRColorChannels);
  5853.     begin
  5854.       if UseMMX then
  5855.       begin
  5856.         FMMXUsed := True;
  5857.         asm
  5858.           jmp @@EndCode
  5859.         @@StartCode:
  5860.           db $0F,$6F,$05,$11,$11,$11,$11///movq mm0,qword ptr [$11111111]
  5861.                                  @@Col1:
  5862.           db $0F,$6F,$0D,$11,$11,$11,$11///movq mm1,qword ptr [$11111111]
  5863.                                  @@Col2:
  5864.           db $0F,$D9,$C8      ///psubusw mm1,mm0
  5865.           db $0F,$7F,$0D,$11,$11,$11,$11///movq qword ptr [$11111111],mm1
  5866.                                  @@Dest:
  5867.         @@EndCode:
  5868.           {$I DXRender.inc}
  5869.           {  @@Col1  }
  5870.           mov eax,Col1
  5871.           mov edx,offset @@Col1-4
  5872.           sub edx,offset @@StartCode
  5873.           mov dword ptr [ecx+edx],eax
  5874.  
  5875.           {  @@Col2  }
  5876.           mov eax,Col2
  5877.           mov edx,offset @@Col2-4
  5878.           sub edx,offset @@StartCode
  5879.           mov dword ptr [ecx+edx],eax
  5880.  
  5881.           {  @@Dest  }
  5882.           mov eax,Dest
  5883.           mov edx,offset @@Dest-4
  5884.           sub edx,offset @@StartCode
  5885.           mov dword ptr [ecx+edx],eax
  5886.         end;
  5887.       end else
  5888.       begin
  5889.         { Red Channel }
  5890.         if chRed in EnableChannels then
  5891.         begin
  5892.           if chRed in ConstChannels1 then
  5893.           begin
  5894.             Func_col1_Sub_const2(Code, @Dest.R, @Col2.R, @Col1.R);
  5895.           end else
  5896.           if chRed in ConstChannels2 then
  5897.           begin
  5898.             Func_const1_Sub_col2(Code, @Dest.R, @Col1.R, @Col2.R);
  5899.           end else
  5900.             Func_col1_Sub_col2(Code, @Dest.R, @Col2.R, @Col1.R);
  5901.         end;
  5902.  
  5903.         { Green Channel }
  5904.         if chRed in EnableChannels then
  5905.         begin
  5906.           if chRed in ConstChannels1 then
  5907.           begin
  5908.             Func_col1_Sub_const2(Code, @Dest.G, @Col2.G, @Col1.G);
  5909.           end else
  5910.           if chRed in ConstChannels2 then
  5911.           begin
  5912.             Func_const1_Sub_col2(Code, @Dest.G, @Col1.G, @Col2.G);
  5913.           end else
  5914.             Func_col1_Sub_col2(Code, @Dest.G, @Col2.G, @Col1.G);
  5915.         end;
  5916.  
  5917.         { Blue Channel }
  5918.         if chRed in EnableChannels then
  5919.         begin
  5920.           if chRed in ConstChannels1 then
  5921.           begin
  5922.             Func_col1_Sub_const2(Code, @Dest.B, @Col2.B, @Col1.B);
  5923.           end else
  5924.           if chRed in ConstChannels2 then
  5925.           begin
  5926.             Func_const1_Sub_col2(Code, @Dest.B, @Col1.B, @Col2.B);
  5927.           end else
  5928.             Func_col1_Sub_col2(Code, @Dest.B, @Col2.B, @Col1.B);
  5929.         end;
  5930.  
  5931.         { Alpha Channel }
  5932.         if chRed in EnableChannels then
  5933.         begin
  5934.           if chRed in ConstChannels1 then
  5935.           begin
  5936.             Func_col1_Sub_const2(Code, @Dest.A, @Col2.A, @Col1.A);
  5937.           end else
  5938.           if chRed in ConstChannels2 then
  5939.           begin
  5940.             Func_const1_Sub_col2(Code, @Dest.A, @Col1.A, @Col2.A);
  5941.           end else
  5942.             Func_col1_Sub_col2(Code, @Dest.A, @Col2.A, @Col1.A);
  5943.         end;
  5944.       end;
  5945.     end;
  5946.  
  5947.     procedure genBlend_ONE1_SUB_ONE2(var Code: Pointer; Dest, Col1, Col2: PDXRMachine_Color;
  5948.       ConstChannels1, ConstChannels12: TDXRColorChannels);
  5949.     begin
  5950.       if UseMMX then
  5951.       begin
  5952.         FMMXUsed := True;
  5953.         asm
  5954.           jmp @@EndCode
  5955.         @@StartCode:
  5956.           db $0F,$6F,$05,$11,$11,$11,$11/// movq mm0,qword ptr [$11111111]
  5957.                                  @@Col1:
  5958.           db $0F,$D9,$05,$11,$11,$11,$11/// psubusw mm0,qword ptr [$11111111]
  5959.                                  @@Col2:
  5960.           db $0F,$7F,$05,$11,$11,$11,$11/// movq qword ptr [$11111111],mm0
  5961.                                  @@Dest:
  5962.         @@EndCode:
  5963.           {$I DXRender.inc}
  5964.           {  @@Col1  }
  5965.           mov eax,Col1
  5966.           mov edx,offset @@Col1-4
  5967.           sub edx,offset @@StartCode
  5968.           mov dword ptr [ecx+edx],eax
  5969.  
  5970.           {  @@Col2  }
  5971.           mov eax,Col2
  5972.           mov edx,offset @@Col2-4
  5973.           sub edx,offset @@StartCode
  5974.           mov dword ptr [ecx+edx],eax
  5975.  
  5976.           {  @@Dest  }
  5977.           mov eax,Dest
  5978.           mov edx,offset @@Dest-4
  5979.           sub edx,offset @@StartCode
  5980.           mov dword ptr [ecx+edx],eax
  5981.         end;
  5982.       end else
  5983.       begin
  5984.         { Red Channel }
  5985.         if chRed in EnableChannels then
  5986.         begin
  5987.           if chRed in ConstChannels1 then
  5988.           begin
  5989.             Func_col1_Sub_const2(Code, @Dest.R, @Col1.R, @Col2.R);
  5990.           end else
  5991.           if chRed in ConstChannels2 then
  5992.           begin
  5993.             Func_const1_Sub_col2(Code, @Dest.R, @Col2.R, @Col1.R);
  5994.           end else
  5995.             Func_col1_Sub_col2(Code, @Dest.R, @Col1.R, @Col2.R);
  5996.         end;
  5997.  
  5998.         { Green Channel }
  5999.         if chRed in EnableChannels then
  6000.         begin
  6001.           if chRed in ConstChannels1 then
  6002.           begin
  6003.             Func_col1_Sub_const2(Code, @Dest.G, @Col1.G, @Col2.G);
  6004.           end else
  6005.           if chRed in ConstChannels2 then
  6006.           begin
  6007.             Func_const1_Sub_col2(Code, @Dest.G, @Col2.G, @Col1.G);
  6008.           end else
  6009.             Func_col1_Sub_col2(Code, @Dest.G, @Col1.G, @Col2.G);
  6010.         end;
  6011.  
  6012.         { Blue Channel }
  6013.         if chRed in EnableChannels then
  6014.         begin
  6015.           if chRed in ConstChannels1 then
  6016.           begin
  6017.             Func_col1_Sub_const2(Code, @Dest.B, @Col1.B, @Col2.B);
  6018.           end else
  6019.           if chRed in ConstChannels2 then
  6020.           begin
  6021.             Func_const1_Sub_col2(Code, @Dest.B, @Col2.B, @Col1.B);
  6022.           end else
  6023.             Func_col1_Sub_col2(Code, @Dest.B, @Col1.B, @Col2.B);
  6024.         end;
  6025.  
  6026.         { Alpha Channel }
  6027.         if chRed in EnableChannels then
  6028.         begin
  6029.           if chRed in ConstChannels1 then
  6030.           begin
  6031.             Func_col1_Sub_const2(Code, @Dest.A, @Col1.A, @Col2.A);
  6032.           end else
  6033.           if chRed in ConstChannels2 then
  6034.           begin
  6035.             Func_const1_Sub_col2(Code, @Dest.A, @Col2.A, @Col1.A);
  6036.           end else
  6037.             Func_col1_Sub_col2(Code, @Dest.A, @Col1.A, @Col2.A);
  6038.         end;
  6039.       end;
  6040.     end;
  6041.  
  6042.     procedure genBlend_ONE1_MUL_ONE2(var Code: Pointer; Dest, Col1, Col2: PDXRMachine_Color;
  6043.       ConstChannels1, ConstChannels12: TDXRColorChannels);
  6044.     begin
  6045.       if UseMMX then
  6046.       begin
  6047.         FMMXUsed := True;
  6048.         asm
  6049.           jmp @@EndCode
  6050.         @@StartCode:
  6051.           db $0F,$6F,$05,$11,$11,$11,$11/// movq mm0,qword ptr [$11111111]
  6052.                                  @@Col1:
  6053.           db $0F,$6F,$0D,$11,$11,$11,$11/// movq mm1,qword ptr [$11111111]
  6054.                                  @@Col2:
  6055.           db $0F,$71,$D0,$01       /// psrlw mm0,1
  6056.           db $0F,$71,$D1,$01       /// psrlw mm1,1
  6057.           db $0F,$E5,$C1           /// pmulhw mm0,mm1
  6058.           db $0F,$71,$F0,$02       /// psllw mm0,2
  6059.           db $0F,$7F,$05,$11,$11,$11,$11/// movq qword ptr [$11111111],mm0
  6060.                                  @@Dest:
  6061.         @@EndCode:
  6062.           {$I DXRender.inc}
  6063.           {  @@Col1  }
  6064.           mov eax,Col1
  6065.           mov edx,offset @@Col1-4
  6066.           sub edx,offset @@StartCode
  6067.           mov dword ptr [ecx+edx],eax
  6068.  
  6069.           {  @@Col2  }
  6070.           mov eax,Col2
  6071.           mov edx,offset @@Col2-4
  6072.           sub edx,offset @@StartCode
  6073.           mov dword ptr [ecx+edx],eax
  6074.  
  6075.           {  @@Dest  }
  6076.           mov eax,Dest
  6077.           mov edx,offset @@Dest-4
  6078.           sub edx,offset @@StartCode
  6079.           mov dword ptr [ecx+edx],eax
  6080.         end;
  6081.       end else
  6082.       begin
  6083.         if chRed in EnableChannels then
  6084.         begin
  6085.           asm
  6086.             jmp @@EndCode
  6087.           @@StartCode:
  6088.             mov al,byte ptr [offset offset _null]{}@@Col1:
  6089.             mul byte ptr [offset offset _null]   {}@@Col2:
  6090.             mov byte ptr [offset offset _null],ah{}@@Dest:
  6091.           @@EndCode:
  6092.             {$I DXRender.inc}
  6093.             {  @@Col1  }
  6094.             mov eax,Col1; add eax,Byte(TDXRMachine_Color.R+1)
  6095.             mov edx,offset @@Col1-4
  6096.             sub edx,offset @@StartCode
  6097.             mov dword ptr [ecx+edx],eax
  6098.  
  6099.             {  @@Col2  }
  6100.             mov eax,Col2; add eax,Byte(TDXRMachine_Color.R+1)
  6101.             mov edx,offset @@Col2-4
  6102.             sub edx,offset @@StartCode
  6103.             mov dword ptr [ecx+edx],eax
  6104.  
  6105.             {  @@Dest  }
  6106.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.R+1)
  6107.             mov edx,offset @@Dest-4
  6108.             sub edx,offset @@StartCode
  6109.             mov dword ptr [ecx+edx],eax
  6110.           end;
  6111.         end;
  6112.  
  6113.         if chGreen in EnableChannels then
  6114.         begin
  6115.           asm
  6116.             jmp @@EndCode
  6117.           @@StartCode:
  6118.             mov al,byte ptr [offset offset _null]{}@@Col1:
  6119.             mul byte ptr [offset offset _null]   {}@@Col2:
  6120.             mov byte ptr [offset offset _null],ah{}@@Dest:
  6121.           @@EndCode:
  6122.             {$I DXRender.inc}
  6123.             {  @@Col1  }
  6124.             mov eax,Col1; add eax,Byte(TDXRMachine_Color.G+1)
  6125.             mov edx,offset @@Col1-4
  6126.             sub edx,offset @@StartCode
  6127.             mov dword ptr [ecx+edx],eax
  6128.  
  6129.             {  @@Col2  }
  6130.             mov eax,Col2; add eax,Byte(TDXRMachine_Color.G+1)
  6131.             mov edx,offset @@Col2-4
  6132.             sub edx,offset @@StartCode
  6133.             mov dword ptr [ecx+edx],eax
  6134.  
  6135.             {  @@Dest  }
  6136.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.G+1)
  6137.             mov edx,offset @@Dest-4
  6138.             sub edx,offset @@StartCode
  6139.             mov dword ptr [ecx+edx],eax
  6140.           end;
  6141.         end;
  6142.  
  6143.         if chBlue in EnableChannels then
  6144.         begin
  6145.           asm
  6146.             jmp @@EndCode
  6147.           @@StartCode:
  6148.             mov al,byte ptr [offset offset _null]{}@@Col1:
  6149.             mul byte ptr [offset offset _null]   {}@@Col2:
  6150.             mov byte ptr [offset offset _null],ah{}@@Dest:
  6151.           @@EndCode:
  6152.             {$I DXRender.inc}
  6153.             {  @@Col1  }
  6154.             mov eax,Col1; add eax,Byte(TDXRMachine_Color.B+1)
  6155.             mov edx,offset @@Col1-4
  6156.             sub edx,offset @@StartCode
  6157.             mov dword ptr [ecx+edx],eax
  6158.  
  6159.             {  @@Col2  }
  6160.             mov eax,Col2; add eax,Byte(TDXRMachine_Color.B+1)
  6161.             mov edx,offset @@Col2-4
  6162.             sub edx,offset @@StartCode
  6163.             mov dword ptr [ecx+edx],eax
  6164.  
  6165.             {  @@Dest  }
  6166.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.B+1)
  6167.             mov edx,offset @@Dest-4
  6168.             sub edx,offset @@StartCode
  6169.             mov dword ptr [ecx+edx],eax
  6170.           end;
  6171.         end;
  6172.  
  6173.         if chAlpha in EnableChannels then
  6174.         begin
  6175.           asm
  6176.             jmp @@EndCode
  6177.           @@StartCode:
  6178.             mov al,byte ptr [offset offset _null]{}@@Col1:
  6179.             mul byte ptr [offset offset _null]   {}@@Col2:
  6180.             mov byte ptr [offset offset _null],ah{}@@Dest:
  6181.           @@EndCode:
  6182.             {$I DXRender.inc}
  6183.             {  @@Col1  }
  6184.             mov eax,Col1; add eax,Byte(TDXRMachine_Color.A+1)
  6185.             mov edx,offset @@Col1-4
  6186.             sub edx,offset @@StartCode
  6187.             mov dword ptr [ecx+edx],eax
  6188.  
  6189.             {  @@Col2  }
  6190.             mov eax,Col2; add eax,Byte(TDXRMachine_Color.A+1)
  6191.             mov edx,offset @@Col2-4
  6192.             sub edx,offset @@StartCode
  6193.             mov dword ptr [ecx+edx],eax
  6194.  
  6195.             {  @@Dest  }
  6196.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.A+1)
  6197.             mov edx,offset @@Dest-4
  6198.             sub edx,offset @@StartCode
  6199.             mov dword ptr [ecx+edx],eax
  6200.           end;
  6201.         end;
  6202.       end;
  6203.     end;
  6204.  
  6205.     procedure genBlend_SRCALPHA1(var Code: Pointer; Dest, Col1: PDXRMachine_Color;
  6206.       ConstChannels1: TDXRColorChannels);
  6207.     begin
  6208.       asm
  6209.         jmp @@EndCode
  6210.       @@StartCode:
  6211.         movzx ebx,byte ptr [offset _null]{}@@Col1:
  6212.       @@EndCode:
  6213.         {$I DXRender.inc}
  6214.         {  @@Col1  }
  6215.         mov eax,Col1; add eax,Byte(TDXRMachine_Color.A+1)
  6216.         mov edx,offset @@Col1-4
  6217.         sub edx,offset @@StartCode
  6218.         mov dword ptr [ecx+edx],eax
  6219.       end;
  6220.  
  6221.       if [chRed, chGreen]<=EnableChannels then
  6222.       begin
  6223.         asm
  6224.           jmp @@EndCode
  6225.         @@StartCode:
  6226.           mov eax,dword ptr [offset _null]{}@@Col1:
  6227.           shr eax,8
  6228.           and eax,$00FF00FF
  6229.           imul eax,ebx
  6230.           mov dword ptr [offset _null],eax{}@@Dest:
  6231.         @@EndCode:
  6232.           {$I DXRender.inc}
  6233.           {  @@Col1  }
  6234.           mov eax,Col1
  6235.           mov edx,offset @@Col1-4
  6236.           sub edx,offset @@StartCode
  6237.           mov dword ptr [ecx+edx],eax
  6238.  
  6239.           {  @@Dest  }
  6240.           mov eax,Dest
  6241.           mov edx,offset @@Dest-4
  6242.           sub edx,offset @@StartCode
  6243.           mov dword ptr [ecx+edx],eax
  6244.         end;
  6245.       end else
  6246.       begin
  6247.         if chRed in EnableChannels then
  6248.         begin
  6249.           asm
  6250.             jmp @@EndCode
  6251.           @@StartCode:
  6252.             movzx eax,byte ptr [offset _null]{}@@Col1:
  6253.             imul eax,ebx
  6254.             mov byte ptr [offset _null],ah{}@@Dest:
  6255.           @@EndCode:
  6256.             {$I DXRender.inc}
  6257.             {  @@Col1  }
  6258.             mov eax,Col1; add eax,Byte(TDXRMachine_Color.R+1)
  6259.             mov edx,offset @@Col1-4
  6260.             sub edx,offset @@StartCode
  6261.             mov dword ptr [ecx+edx],eax
  6262.  
  6263.             {  @@Dest  }
  6264.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.R+1)
  6265.             mov edx,offset @@Dest-4
  6266.             sub edx,offset @@StartCode
  6267.             mov dword ptr [ecx+edx],eax
  6268.           end;
  6269.         end;
  6270.  
  6271.         if chGreen in EnableChannels then
  6272.         begin
  6273.           asm
  6274.             jmp @@EndCode
  6275.           @@StartCode:
  6276.             movzx eax,byte ptr [offset _null]{}@@Col1:
  6277.             imul eax,ebx
  6278.             mov byte ptr [offset _null],ah{}@@Dest:
  6279.           @@EndCode:
  6280.             {$I DXRender.inc}
  6281.             {  @@Col1  }
  6282.             mov eax,Col1; add eax,Byte(TDXRMachine_Color.G+1)
  6283.             mov edx,offset @@Col1-4
  6284.             sub edx,offset @@StartCode
  6285.             mov dword ptr [ecx+edx],eax
  6286.  
  6287.             {  @@Dest  }
  6288.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.G+1)
  6289.             mov edx,offset @@Dest-4
  6290.             sub edx,offset @@StartCode
  6291.             mov dword ptr [ecx+edx],eax
  6292.           end;
  6293.         end;
  6294.       end;
  6295.  
  6296.       if [chBlue, chAlpha]<=EnableChannels then
  6297.       begin
  6298.         asm
  6299.           jmp @@EndCode
  6300.         @@StartCode:
  6301.           mov eax,dword ptr [offset _null]{}@@Col1:
  6302.           shr eax,8
  6303.           and eax,$00FF00FF
  6304.           imul eax,ebx
  6305.           mov dword ptr [offset _null],eax{}@@Dest:
  6306.         @@EndCode:
  6307.           {$I DXRender.inc}
  6308.           {  @@Col1  }
  6309.           mov eax,Col1; add eax,4
  6310.           mov edx,offset @@Col1-4
  6311.           sub edx,offset @@StartCode
  6312.           mov dword ptr [ecx+edx],eax
  6313.  
  6314.           {  @@Dest  }
  6315.           mov eax,Dest; add eax,4
  6316.           mov edx,offset @@Dest-4
  6317.           sub edx,offset @@StartCode
  6318.           mov dword ptr [ecx+edx],eax
  6319.         end;
  6320.       end else
  6321.       begin
  6322.         if chBlue in EnableChannels then
  6323.         begin
  6324.           asm
  6325.             jmp @@EndCode
  6326.           @@StartCode:
  6327.             movzx eax,byte ptr [offset _null]{}@@Col1:
  6328.             imul eax,ebx
  6329.             mov byte ptr [offset _null],ah{}@@Dest:
  6330.           @@EndCode:
  6331.             {$I DXRender.inc}
  6332.             {  @@Col1  }
  6333.             mov eax,Col1; add eax,Byte(TDXRMachine_Color.B+1)
  6334.             mov edx,offset @@Col1-4
  6335.             sub edx,offset @@StartCode
  6336.             mov dword ptr [ecx+edx],eax
  6337.  
  6338.             {  @@Dest  }
  6339.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.B+1)
  6340.             mov edx,offset @@Dest-4
  6341.             sub edx,offset @@StartCode
  6342.             mov dword ptr [ecx+edx],eax
  6343.           end;
  6344.         end;
  6345.  
  6346.         if chAlpha in EnableChannels then
  6347.         begin
  6348.           asm
  6349.             jmp @@EndCode
  6350.           @@StartCode:
  6351.             movzx eax,byte ptr [offset _null]{}@@Col1:
  6352.             imul eax,ebx
  6353.             mov byte ptr [offset _null],ah{}@@Dest:
  6354.           @@EndCode:
  6355.             {$I DXRender.inc}
  6356.             {  @@Col1  }
  6357.             mov eax,Col1; add eax,Byte(TDXRMachine_Color.A+1)
  6358.             mov edx,offset @@Col1-4
  6359.             sub edx,offset @@StartCode
  6360.             mov dword ptr [ecx+edx],eax
  6361.  
  6362.             {  @@Dest  }
  6363.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.A+1)
  6364.             mov edx,offset @@Dest-4
  6365.             sub edx,offset @@StartCode
  6366.             mov dword ptr [ecx+edx],eax
  6367.           end;
  6368.         end;
  6369.       end;
  6370.     end;
  6371.  
  6372.     procedure genBlend_SRCALPHA1_ADD_ONE2(var Code: Pointer; Dest, Col1, Col2: PDXRMachine_Color;
  6373.       ConstChannels1, ConstChannels12: TDXRColorChannels);
  6374.     begin
  6375.       asm
  6376.         jmp @@EndCode
  6377.       @@StartCode:
  6378.         movzx ebx,byte ptr [offset _null]{}@@Col1:
  6379.       @@EndCode:
  6380.         {$I DXRender.inc}
  6381.         {  @@Col1  }
  6382.         mov eax,Col1; add eax,Byte(TDXRMachine_Color.A+1)
  6383.         mov edx,offset @@Col1-4
  6384.         sub edx,offset @@StartCode
  6385.         mov dword ptr [ecx+edx],eax
  6386.       end;
  6387.  
  6388.       if chRed in EnableChannels then
  6389.       begin
  6390.         asm
  6391.           jmp @@EndCode
  6392.         @@StartCode:
  6393.           movzx eax,byte ptr [offset _null]{}@@Col1:
  6394.           movzx edx,byte ptr [offset _null]{}@@Col2:
  6395.           imul eax,ebx
  6396.           shr eax,8
  6397.           mov al,byte ptr [offset (_AddTable + eax + edx)]
  6398.           mov byte ptr [offset _null],al{}@@Dest:
  6399.         @@EndCode:
  6400.           {$I DXRender.inc}
  6401.           {  @@Col1  }
  6402.           mov eax,Col1; add eax,Byte(TDXRMachine_Color.R+1)
  6403.           mov edx,offset @@Col1-4
  6404.           sub edx,offset @@StartCode
  6405.           mov dword ptr [ecx+edx],eax
  6406.  
  6407.           {  @@Col2  }
  6408.           mov eax,Col2; add eax,Byte(TDXRMachine_Color.R+1)
  6409.           mov edx,offset @@Col2-4
  6410.           sub edx,offset @@StartCode
  6411.           mov dword ptr [ecx+edx],eax
  6412.  
  6413.           {  @@Dest  }
  6414.           mov eax,Dest; add eax,Byte(TDXRMachine_Color.R+1)
  6415.           mov edx,offset @@Dest-4
  6416.           sub edx,offset @@StartCode
  6417.           mov dword ptr [ecx+edx],eax
  6418.         end;
  6419.       end;
  6420.  
  6421.       if chGreen in EnableChannels then
  6422.       begin
  6423.         asm
  6424.           jmp @@EndCode
  6425.         @@StartCode:
  6426.           movzx eax,byte ptr [offset _null]{}@@Col1:
  6427.           movzx edx,byte ptr [offset _null]{}@@Col2:
  6428.           imul eax,ebx
  6429.           shr eax,8
  6430.           mov al,byte ptr [offset (_AddTable + eax + edx)]
  6431.           mov byte ptr [offset _null],al{}@@Dest:
  6432.         @@EndCode:
  6433.           {$I DXRender.inc}
  6434.           {  @@Col1  }
  6435.           mov eax,Col1; add eax,Byte(TDXRMachine_Color.G+1)
  6436.           mov edx,offset @@Col1-4
  6437.           sub edx,offset @@StartCode
  6438.           mov dword ptr [ecx+edx],eax
  6439.  
  6440.           {  @@Col2  }
  6441.           mov eax,Col2; add eax,Byte(TDXRMachine_Color.G+1)
  6442.           mov edx,offset @@Col2-4
  6443.           sub edx,offset @@StartCode
  6444.           mov dword ptr [ecx+edx],eax
  6445.  
  6446.           {  @@Dest  }
  6447.           mov eax,Dest; add eax,Byte(TDXRMachine_Color.G+1)
  6448.           mov edx,offset @@Dest-4
  6449.           sub edx,offset @@StartCode
  6450.           mov dword ptr [ecx+edx],eax
  6451.         end;
  6452.       end;
  6453.  
  6454.       if chBlue in EnableChannels then
  6455.       begin
  6456.         asm
  6457.           jmp @@EndCode
  6458.         @@StartCode:
  6459.           movzx eax,byte ptr [offset _null]{}@@Col1:
  6460.           movzx edx,byte ptr [offset _null]{}@@Col2:
  6461.           imul eax,ebx
  6462.           shr eax,8
  6463.           mov al,byte ptr [offset (_AddTable + eax + edx)]
  6464.           mov byte ptr [offset _null],al{}@@Dest:
  6465.         @@EndCode:
  6466.           {$I DXRender.inc}
  6467.           {  @@Col1  }
  6468.           mov eax,Col1; add eax,Byte(TDXRMachine_Color.B+1)
  6469.           mov edx,offset @@Col1-4
  6470.           sub edx,offset @@StartCode
  6471.           mov dword ptr [ecx+edx],eax
  6472.  
  6473.           {  @@Col2  }
  6474.           mov eax,Col2; add eax,Byte(TDXRMachine_Color.B+1)
  6475.           mov edx,offset @@Col2-4
  6476.           sub edx,offset @@StartCode
  6477.           mov dword ptr [ecx+edx],eax
  6478.  
  6479.           {  @@Dest  }
  6480.           mov eax,Dest; add eax,Byte(TDXRMachine_Color.B+1)
  6481.           mov edx,offset @@Dest-4
  6482.           sub edx,offset @@StartCode
  6483.           mov dword ptr [ecx+edx],eax
  6484.         end;
  6485.       end;
  6486.  
  6487.       if chAlpha in EnableChannels then
  6488.       begin
  6489.         asm
  6490.           jmp @@EndCode
  6491.         @@StartCode:
  6492.           movzx eax,byte ptr [offset _null]{}@@Col1:
  6493.           movzx edx,byte ptr [offset _null]{}@@Col2:
  6494.           imul eax,ebx
  6495.           shr eax,8
  6496.           mov al,byte ptr [offset (_AddTable + eax + edx)]
  6497.           mov byte ptr [offset _null],al{}@@Dest:
  6498.         @@EndCode:
  6499.           {$I DXRender.inc}
  6500.           {  @@Col1  }
  6501.           mov eax,Col1; add eax,Byte(TDXRMachine_Color.A+1)
  6502.           mov edx,offset @@Col1-4
  6503.           sub edx,offset @@StartCode
  6504.           mov dword ptr [ecx+edx],eax
  6505.  
  6506.           {  @@Col2  }
  6507.           mov eax,Col2; add eax,Byte(TDXRMachine_Color.A+1)
  6508.           mov edx,offset @@Col2-4
  6509.           sub edx,offset @@StartCode
  6510.           mov dword ptr [ecx+edx],eax
  6511.  
  6512.           {  @@Dest  }
  6513.           mov eax,Dest; add eax,Byte(TDXRMachine_Color.A+1)
  6514.           mov edx,offset @@Dest-4
  6515.           sub edx,offset @@StartCode
  6516.           mov dword ptr [ecx+edx],eax
  6517.         end;
  6518.       end;
  6519.     end;
  6520.  
  6521.     procedure genBlend_ONE2_SUB_SRCALPHA1(var Code: Pointer; Dest, Col1, Col2: PDXRMachine_Color;
  6522.       ConstChannels1, ConstChannels12: TDXRColorChannels);
  6523.     begin
  6524.       asm
  6525.         jmp @@EndCode
  6526.       @@StartCode:
  6527.         movzx ebx,byte ptr [offset _null]{}@@Col1:
  6528.       @@EndCode:
  6529.         {$I DXRender.inc}
  6530.         {  @@Col1  }
  6531.         mov eax,Col1; add eax,Byte(TDXRMachine_Color.A+1)
  6532.         mov edx,offset @@Col1-4
  6533.         sub edx,offset @@StartCode
  6534.         mov dword ptr [ecx+edx],eax
  6535.       end;
  6536.  
  6537.       if chRed in EnableChannels then
  6538.       begin
  6539.         asm
  6540.           jmp @@EndCode
  6541.         @@StartCode:
  6542.           movzx eax,byte ptr [offset _null]{}@@Col1:
  6543.           movzx edx,byte ptr [offset _null]{}@@Col2:
  6544.           imul eax,ebx
  6545.           shr eax,8
  6546.           sub edx,eax
  6547.           mov al,byte ptr [offset (_SubTable + 255 + edx)]
  6548.           mov byte ptr [offset _null],al{}@@Dest:
  6549.         @@EndCode:
  6550.           {$I DXRender.inc}
  6551.           {  @@Col1  }
  6552.           mov eax,Col1; add eax,Byte(TDXRMachine_Color.R+1)
  6553.           mov edx,offset @@Col1-4
  6554.           sub edx,offset @@StartCode
  6555.           mov dword ptr [ecx+edx],eax
  6556.  
  6557.           {  @@Col2  }
  6558.           mov eax,Col2; add eax,Byte(TDXRMachine_Color.R+1)
  6559.           mov edx,offset @@Col2-4
  6560.           sub edx,offset @@StartCode
  6561.           mov dword ptr [ecx+edx],eax
  6562.  
  6563.           {  @@Dest  }
  6564.           mov eax,Dest; add eax,Byte(TDXRMachine_Color.R+1)
  6565.           mov edx,offset @@Dest-4
  6566.           sub edx,offset @@StartCode
  6567.           mov dword ptr [ecx+edx],eax
  6568.         end;
  6569.       end;
  6570.  
  6571.       if chGreen in EnableChannels then
  6572.       begin
  6573.         asm
  6574.           jmp @@EndCode
  6575.         @@StartCode:
  6576.           movzx eax,byte ptr [offset _null]{}@@Col1:
  6577.           movzx edx,byte ptr [offset _null]{}@@Col2:
  6578.           imul eax,ebx
  6579.           shr eax,8
  6580.           sub edx,eax
  6581.           mov al,byte ptr [offset (_SubTable + 255 + edx)]
  6582.           mov byte ptr [offset _null],al{}@@Dest:
  6583.         @@EndCode:
  6584.           {$I DXRender.inc}
  6585.           {  @@Col1  }
  6586.           mov eax,Col1; add eax,Byte(TDXRMachine_Color.G+1)
  6587.           mov edx,offset @@Col1-4
  6588.           sub edx,offset @@StartCode
  6589.           mov dword ptr [ecx+edx],eax
  6590.  
  6591.           {  @@Col2  }
  6592.           mov eax,Col2; add eax,Byte(TDXRMachine_Color.G+1)
  6593.           mov edx,offset @@Col2-4
  6594.           sub edx,offset @@StartCode
  6595.           mov dword ptr [ecx+edx],eax
  6596.  
  6597.           {  @@Dest  }
  6598.           mov eax,Dest; add eax,Byte(TDXRMachine_Color.G+1)
  6599.           mov edx,offset @@Dest-4
  6600.           sub edx,offset @@StartCode
  6601.           mov dword ptr [ecx+edx],eax
  6602.         end;
  6603.       end;
  6604.  
  6605.       if chBlue in EnableChannels then
  6606.       begin
  6607.         asm
  6608.           jmp @@EndCode
  6609.         @@StartCode:
  6610.           movzx eax,byte ptr [offset _null]{}@@Col1:
  6611.           movzx edx,byte ptr [offset _null]{}@@Col2:
  6612.           imul eax,ebx
  6613.           shr eax,8
  6614.           sub edx,eax
  6615.           mov al,byte ptr [offset (_SubTable + 255 + edx)]
  6616.           mov byte ptr [offset _null],al{}@@Dest:
  6617.         @@EndCode:
  6618.           {$I DXRender.inc}
  6619.           {  @@Col1  }
  6620.           mov eax,Col1; add eax,Byte(TDXRMachine_Color.B+1)
  6621.           mov edx,offset @@Col1-4
  6622.           sub edx,offset @@StartCode
  6623.           mov dword ptr [ecx+edx],eax
  6624.  
  6625.           {  @@Col2  }
  6626.           mov eax,Col2; add eax,Byte(TDXRMachine_Color.B+1)
  6627.           mov edx,offset @@Col2-4
  6628.           sub edx,offset @@StartCode
  6629.           mov dword ptr [ecx+edx],eax
  6630.  
  6631.           {  @@Dest  }
  6632.           mov eax,Dest; add eax,Byte(TDXRMachine_Color.B+1)
  6633.           mov edx,offset @@Dest-4
  6634.           sub edx,offset @@StartCode
  6635.           mov dword ptr [ecx+edx],eax
  6636.         end;
  6637.       end;
  6638.  
  6639.       if chAlpha in EnableChannels then
  6640.       begin
  6641.         asm
  6642.           jmp @@EndCode
  6643.         @@StartCode:
  6644.           movzx eax,byte ptr [offset _null]{}@@Col1:
  6645.           movzx edx,byte ptr [offset _null]{}@@Col2:
  6646.           imul eax,ebx
  6647.           shr eax,8
  6648.           sub edx,eax
  6649.           mov al,byte ptr [offset (_SubTable + 255 + edx)]
  6650.           mov byte ptr [offset _null],al{}@@Dest:
  6651.         @@EndCode:
  6652.           {$I DXRender.inc}
  6653.           {  @@Col1  }
  6654.           mov eax,Col1; add eax,Byte(TDXRMachine_Color.A+1)
  6655.           mov edx,offset @@Col1-4
  6656.           sub edx,offset @@StartCode
  6657.           mov dword ptr [ecx+edx],eax
  6658.  
  6659.           {  @@Col2  }
  6660.           mov eax,Col2; add eax,Byte(TDXRMachine_Color.A+1)
  6661.           mov edx,offset @@Col2-4
  6662.           sub edx,offset @@StartCode
  6663.           mov dword ptr [ecx+edx],eax
  6664.  
  6665.           {  @@Dest  }
  6666.           mov eax,Dest; add eax,Byte(TDXRMachine_Color.A+1)
  6667.           mov edx,offset @@Dest-4
  6668.           sub edx,offset @@StartCode
  6669.           mov dword ptr [ecx+edx],eax
  6670.         end;
  6671.       end;
  6672.     end;
  6673.  
  6674.     procedure genBlend_SRCALPHA1_ADD_INVSRCALPHA2(var Code: Pointer; Dest, Col1, Col2: PDXRMachine_Color;
  6675.       ConstChannels1, ConstChannels12: TDXRColorChannels);
  6676.     begin
  6677.       asm
  6678.         jmp @@EndCode
  6679.       @@StartCode:
  6680.         movzx ebx,byte ptr [offset _null]{}@@Col1:
  6681.         mov ebp,ebx
  6682.         xor ebp,$FF
  6683.       @@EndCode:
  6684.         {$I DXRender.inc}
  6685.         {  @@Col1  }
  6686.         mov eax,Col1; add eax,Byte(TDXRMachine_Color.A+1)
  6687.         mov edx,offset @@Col1-4
  6688.         sub edx,offset @@StartCode
  6689.         mov dword ptr [ecx+edx],eax
  6690.       end;
  6691.                        
  6692.       if [chRed, chGreen]<=EnableChannels then
  6693.       begin
  6694.         asm
  6695.           jmp @@EndCode
  6696.         @@StartCode:    
  6697.           mov eax,dword ptr [offset _null]{}@@Col1:
  6698.           mov edx,dword ptr [offset _null]{}@@Col2:
  6699.           shr eax,8
  6700.           shr edx,8
  6701.           and eax,$00FF00FF
  6702.           and edx,$00FF00FF
  6703.           imul eax,ebx
  6704.           imul edx,ebp
  6705.           add eax,edx
  6706.           mov dword ptr [offset _null],eax{}@@Dest:
  6707.         @@EndCode:
  6708.           {$I DXRender.inc}
  6709.           {  @@Col1  }
  6710.           mov eax,Col1
  6711.           mov edx,offset @@Col1-4
  6712.           sub edx,offset @@StartCode
  6713.           mov dword ptr [ecx+edx],eax
  6714.  
  6715.           {  @@Col2  }
  6716.           mov eax,Col2
  6717.           mov edx,offset @@Col2-4
  6718.           sub edx,offset @@StartCode
  6719.           mov dword ptr [ecx+edx],eax
  6720.  
  6721.           {  @@Dest  }
  6722.           mov eax,Dest
  6723.           mov edx,offset @@Dest-4
  6724.           sub edx,offset @@StartCode
  6725.           mov dword ptr [ecx+edx],eax
  6726.         end;
  6727.       end else
  6728.       begin
  6729.         if chRed in EnableChannels then
  6730.         begin
  6731.           asm
  6732.             jmp @@EndCode
  6733.           @@StartCode:
  6734.             movzx eax,byte ptr [offset _null]{}@@Col1:
  6735.             movzx edx,byte ptr [offset _null]{}@@Col2:
  6736.             sub eax,edx
  6737.             imul eax,ebx
  6738.             shr eax,8
  6739.             add eax,edx
  6740.             mov byte ptr [offset _null],al{}@@Dest:
  6741.           @@EndCode:
  6742.             {$I DXRender.inc}
  6743.             {  @@Col1  }
  6744.             mov eax,Col1; add eax,Byte(TDXRMachine_Color.R+1)
  6745.             mov edx,offset @@Col1-4
  6746.             sub edx,offset @@StartCode
  6747.             mov dword ptr [ecx+edx],eax
  6748.  
  6749.             {  @@Col2  }
  6750.             mov eax,Col2; add eax,Byte(TDXRMachine_Color.R+1)
  6751.             mov edx,offset @@Col2-4
  6752.             sub edx,offset @@StartCode
  6753.             mov dword ptr [ecx+edx],eax
  6754.  
  6755.             {  @@Dest  }
  6756.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.R+1)
  6757.             mov edx,offset @@Dest-4
  6758.             sub edx,offset @@StartCode
  6759.             mov dword ptr [ecx+edx],eax
  6760.           end;
  6761.         end;
  6762.  
  6763.         if chGreen in EnableChannels then
  6764.         begin
  6765.           asm
  6766.             jmp @@EndCode
  6767.           @@StartCode:
  6768.             movzx eax,byte ptr [offset _null]{}@@Col1:
  6769.             movzx edx,byte ptr [offset _null]{}@@Col2:
  6770.             sub eax,edx
  6771.             imul eax,ebx
  6772.             shr eax,8
  6773.             add eax,edx
  6774.             mov byte ptr [offset _null],al{}@@Dest:
  6775.           @@EndCode:
  6776.             {$I DXRender.inc}
  6777.             {  @@Col1  }
  6778.             mov eax,Col1; add eax,Byte(TDXRMachine_Color.G+1)
  6779.             mov edx,offset @@Col1-4
  6780.             sub edx,offset @@StartCode
  6781.             mov dword ptr [ecx+edx],eax
  6782.  
  6783.             {  @@Col2  }
  6784.             mov eax,Col2; add eax,Byte(TDXRMachine_Color.G+1)
  6785.             mov edx,offset @@Col2-4
  6786.             sub edx,offset @@StartCode
  6787.             mov dword ptr [ecx+edx],eax
  6788.  
  6789.             {  @@Dest  }
  6790.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.G+1)
  6791.             mov edx,offset @@Dest-4
  6792.             sub edx,offset @@StartCode
  6793.             mov dword ptr [ecx+edx],eax
  6794.           end;
  6795.         end;
  6796.       end;
  6797.  
  6798.       if [chBlue, chAlpha]<=EnableChannels then
  6799.       begin
  6800.         asm
  6801.           jmp @@EndCode
  6802.         @@StartCode:
  6803.           mov eax,dword ptr [offset _null]{}@@Col1:
  6804.           mov edx,dword ptr [offset _null]{}@@Col2:
  6805.           shr eax,8
  6806.           shr edx,8
  6807.           and eax,$00FF00FF
  6808.           and edx,$00FF00FF
  6809.           imul eax,ebx
  6810.           imul edx,ebp
  6811.           add eax,edx
  6812.           mov dword ptr [offset _null],eax{}@@Dest:
  6813.         @@EndCode:
  6814.           {$I DXRender.inc}
  6815.           {  @@Col1  }
  6816.           mov eax,Col1; add eax,4
  6817.           mov edx,offset @@Col1-4
  6818.           sub edx,offset @@StartCode
  6819.           mov dword ptr [ecx+edx],eax
  6820.  
  6821.           {  @@Col2  }
  6822.           mov eax,Col2; add eax,4
  6823.           mov edx,offset @@Col2-4
  6824.           sub edx,offset @@StartCode
  6825.           mov dword ptr [ecx+edx],eax
  6826.  
  6827.           {  @@Dest  }
  6828.           mov eax,Dest; add eax,4
  6829.           mov edx,offset @@Dest-4
  6830.           sub edx,offset @@StartCode
  6831.           mov dword ptr [ecx+edx],eax
  6832.         end;
  6833.       end else
  6834.       begin
  6835.         if chBlue in EnableChannels then
  6836.         begin
  6837.           asm
  6838.             jmp @@EndCode
  6839.           @@StartCode:
  6840.             movzx eax,byte ptr [offset _null]{}@@Col1:
  6841.             movzx edx,byte ptr [offset _null]{}@@Col2:
  6842.             sub eax,edx
  6843.             imul eax,ebx
  6844.             shr eax,8
  6845.             add eax,edx
  6846.             mov byte ptr [offset _null],al{}@@Dest:
  6847.           @@EndCode:
  6848.             {$I DXRender.inc}
  6849.             {  @@Col1  }
  6850.             mov eax,Col1; add eax,Byte(TDXRMachine_Color.B+1)
  6851.             mov edx,offset @@Col1-4
  6852.             sub edx,offset @@StartCode
  6853.             mov dword ptr [ecx+edx],eax
  6854.  
  6855.             {  @@Col2  }
  6856.             mov eax,Col2; add eax,Byte(TDXRMachine_Color.B+1)
  6857.             mov edx,offset @@Col2-4
  6858.             sub edx,offset @@StartCode
  6859.             mov dword ptr [ecx+edx],eax
  6860.  
  6861.             {  @@Dest  }
  6862.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.B+1)
  6863.             mov edx,offset @@Dest-4
  6864.             sub edx,offset @@StartCode
  6865.             mov dword ptr [ecx+edx],eax
  6866.           end;
  6867.         end;
  6868.  
  6869.         if chAlpha in EnableChannels then
  6870.         begin
  6871.           asm
  6872.             jmp @@EndCode
  6873.           @@StartCode:
  6874.             movzx eax,byte ptr [offset _null]{}@@Col1:
  6875.             movzx edx,byte ptr [offset _null]{}@@Col2:
  6876.             sub eax,edx
  6877.             imul eax,ebx
  6878.             shr eax,8
  6879.             add eax,edx
  6880.             mov byte ptr [offset _null],al{}@@Dest:
  6881.           @@EndCode:
  6882.             {$I DXRender.inc}
  6883.             {  @@Col1  }
  6884.             mov eax,Col1; add eax,Byte(TDXRMachine_Color.A+1)
  6885.             mov edx,offset @@Col1-4
  6886.             sub edx,offset @@StartCode
  6887.             mov dword ptr [ecx+edx],eax
  6888.  
  6889.             {  @@Col2  }
  6890.             mov eax,Col2; add eax,Byte(TDXRMachine_Color.A+1)
  6891.             mov edx,offset @@Col2-4
  6892.             sub edx,offset @@StartCode
  6893.             mov dword ptr [ecx+edx],eax
  6894.  
  6895.             {  @@Dest  }
  6896.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.A+1)
  6897.             mov edx,offset @@Dest-4
  6898.             sub edx,offset @@StartCode
  6899.             mov dword ptr [ecx+edx],eax
  6900.           end;
  6901.         end;
  6902.       end;
  6903.     end;
  6904.  
  6905.     procedure genBlend_INVSRCALPHA1_ADD_SRCALPHA2(var Code: Pointer; Dest, Col1, Col2: PDXRMachine_Color;
  6906.       ConstChannels1, ConstChannels12: TDXRColorChannels);
  6907.     begin
  6908.       asm
  6909.         jmp @@EndCode
  6910.       @@StartCode:
  6911.         movzx ebp,byte ptr [offset _null]{}@@Col1A:
  6912.         mov ebx,ebp
  6913.         xor ebx,$FF
  6914.       @@EndCode:
  6915.         {$I DXRender.inc}
  6916.         {  @@Col1A  }
  6917.         mov eax,Col1; add eax,Byte(TDXRMachine_Color.A+1)
  6918.         mov edx,offset @@Col1A-4
  6919.         sub edx,offset @@StartCode
  6920.         mov dword ptr [ecx+edx],eax
  6921.       end;
  6922.  
  6923.       if [chRed, chGreen]<=EnableChannels then
  6924.       begin
  6925.         asm
  6926.           jmp @@EndCode
  6927.         @@StartCode:
  6928.           mov eax,dword ptr [offset _null]{}@@Col1:
  6929.           mov edx,dword ptr [offset _null]{}@@Col2:
  6930.           shr eax,8
  6931.           shr edx,8
  6932.           and eax,$00FF00FF
  6933.           and edx,$00FF00FF
  6934.           imul eax,ebx
  6935.           imul edx,ebp
  6936.           add eax,edx
  6937.           mov dword ptr [offset _null],eax{}@@Dest:
  6938.         @@EndCode:
  6939.           {$I DXRender.inc}
  6940.           {  @@Col1  }
  6941.           mov eax,Col1
  6942.           mov edx,offset @@Col1-4
  6943.           sub edx,offset @@StartCode
  6944.           mov dword ptr [ecx+edx],eax
  6945.  
  6946.           {  @@Col2  }
  6947.           mov eax,Col2
  6948.           mov edx,offset @@Col2-4
  6949.           sub edx,offset @@StartCode
  6950.           mov dword ptr [ecx+edx],eax
  6951.  
  6952.           {  @@Dest  }
  6953.           mov eax,Dest
  6954.           mov edx,offset @@Dest-4
  6955.           sub edx,offset @@StartCode
  6956.           mov dword ptr [ecx+edx],eax
  6957.         end;
  6958.       end else
  6959.       begin
  6960.         if chRed in EnableChannels then
  6961.         begin
  6962.           asm
  6963.             jmp @@EndCode
  6964.           @@StartCode:
  6965.             movzx eax,byte ptr [offset _null]{}@@Col1:
  6966.             movzx edx,byte ptr [offset _null]{}@@Col2:
  6967.             sub eax,edx
  6968.             imul eax,ebx
  6969.             shr eax,8
  6970.             add eax,edx
  6971.             mov byte ptr [offset _null],al{}@@Dest:
  6972.           @@EndCode:
  6973.             {$I DXRender.inc}
  6974.             {  @@Col1  }
  6975.             mov eax,Col1; add eax,Byte(TDXRMachine_Color.R+1)
  6976.             mov edx,offset @@Col1-4
  6977.             sub edx,offset @@StartCode
  6978.             mov dword ptr [ecx+edx],eax
  6979.  
  6980.             {  @@Col2  }
  6981.             mov eax,Col2; add eax,Byte(TDXRMachine_Color.R+1)
  6982.             mov edx,offset @@Col2-4
  6983.             sub edx,offset @@StartCode
  6984.             mov dword ptr [ecx+edx],eax
  6985.  
  6986.             {  @@Dest  }
  6987.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.R+1)
  6988.             mov edx,offset @@Dest-4
  6989.             sub edx,offset @@StartCode
  6990.             mov dword ptr [ecx+edx],eax
  6991.           end;
  6992.         end;
  6993.  
  6994.         if chGreen in EnableChannels then
  6995.         begin
  6996.           asm
  6997.             jmp @@EndCode
  6998.           @@StartCode:
  6999.             movzx eax,byte ptr [offset _null]{}@@Col1:
  7000.             movzx edx,byte ptr [offset _null]{}@@Col2:
  7001.             sub eax,edx
  7002.             imul eax,ebx
  7003.             shr eax,8
  7004.             add eax,edx
  7005.             mov byte ptr [offset _null],al{}@@Dest:
  7006.           @@EndCode:
  7007.             {$I DXRender.inc}
  7008.             {  @@Col1  }
  7009.             mov eax,Col1; add eax,Byte(TDXRMachine_Color.G+1)
  7010.             mov edx,offset @@Col1-4
  7011.             sub edx,offset @@StartCode
  7012.             mov dword ptr [ecx+edx],eax
  7013.  
  7014.             {  @@Col2  }
  7015.             mov eax,Col2; add eax,Byte(TDXRMachine_Color.G+1)
  7016.             mov edx,offset @@Col2-4
  7017.             sub edx,offset @@StartCode
  7018.             mov dword ptr [ecx+edx],eax
  7019.  
  7020.             {  @@Dest  }
  7021.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.G+1)
  7022.             mov edx,offset @@Dest-4
  7023.             sub edx,offset @@StartCode
  7024.             mov dword ptr [ecx+edx],eax
  7025.           end;
  7026.         end;
  7027.       end;
  7028.  
  7029.       if [chBlue, chAlpha]<=EnableChannels then
  7030.       begin
  7031.         asm
  7032.           jmp @@EndCode
  7033.         @@StartCode:
  7034.           mov eax,dword ptr [offset _null]{}@@Col1:
  7035.           mov edx,dword ptr [offset _null]{}@@Col2:
  7036.           shr eax,8
  7037.           shr edx,8
  7038.           and eax,$00FF00FF
  7039.           and edx,$00FF00FF
  7040.           imul eax,ebx
  7041.           imul edx,ebp
  7042.           add eax,edx
  7043.           mov dword ptr [offset _null],eax{}@@Dest:
  7044.         @@EndCode:
  7045.           {$I DXRender.inc}
  7046.           {  @@Col1  }
  7047.           mov eax,Col1; add eax,4
  7048.           mov edx,offset @@Col1-4
  7049.           sub edx,offset @@StartCode
  7050.           mov dword ptr [ecx+edx],eax
  7051.  
  7052.           {  @@Col2  }
  7053.           mov eax,Col2; add eax,4
  7054.           mov edx,offset @@Col2-4
  7055.           sub edx,offset @@StartCode
  7056.           mov dword ptr [ecx+edx],eax
  7057.  
  7058.           {  @@Dest  }
  7059.           mov eax,Dest; add eax,4
  7060.           mov edx,offset @@Dest-4
  7061.           sub edx,offset @@StartCode
  7062.           mov dword ptr [ecx+edx],eax
  7063.         end;
  7064.       end else
  7065.       begin
  7066.         if chBlue in EnableChannels then
  7067.         begin
  7068.           asm
  7069.             jmp @@EndCode
  7070.           @@StartCode:
  7071.             movzx eax,byte ptr [offset _null]{}@@Col1:
  7072.             movzx edx,byte ptr [offset _null]{}@@Col2:
  7073.             sub eax,edx
  7074.             imul eax,ebx
  7075.             shr eax,8
  7076.             add eax,edx
  7077.             mov byte ptr [offset _null],al{}@@Dest:
  7078.           @@EndCode:
  7079.             {$I DXRender.inc}
  7080.             {  @@Col1  }
  7081.             mov eax,Col1; add eax,Byte(TDXRMachine_Color.B+1)
  7082.             mov edx,offset @@Col1-4
  7083.             sub edx,offset @@StartCode
  7084.             mov dword ptr [ecx+edx],eax
  7085.  
  7086.             {  @@Col2  }
  7087.             mov eax,Col2; add eax,Byte(TDXRMachine_Color.B+1)
  7088.             mov edx,offset @@Col2-4
  7089.             sub edx,offset @@StartCode
  7090.             mov dword ptr [ecx+edx],eax
  7091.  
  7092.             {  @@Dest  }
  7093.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.B+1)
  7094.             mov edx,offset @@Dest-4
  7095.             sub edx,offset @@StartCode
  7096.             mov dword ptr [ecx+edx],eax
  7097.           end;
  7098.         end;
  7099.  
  7100.         if chAlpha in EnableChannels then
  7101.         begin
  7102.           asm
  7103.             jmp @@EndCode
  7104.           @@StartCode:
  7105.             movzx eax,byte ptr [offset _null]{}@@Col1:
  7106.             movzx edx,byte ptr [offset _null]{}@@Col2:
  7107.             sub eax,edx
  7108.             imul eax,ebx
  7109.             shr eax,8
  7110.             add eax,edx
  7111.             mov byte ptr [offset _null],al{}@@Dest:
  7112.           @@EndCode:
  7113.             {$I DXRender.inc}
  7114.             {  @@Col1  }
  7115.             mov eax,Col1; add eax,Byte(TDXRMachine_Color.A+1)
  7116.             mov edx,offset @@Col1-4
  7117.             sub edx,offset @@StartCode
  7118.             mov dword ptr [ecx+edx],eax
  7119.  
  7120.             {  @@Col2  }
  7121.             mov eax,Col2; add eax,Byte(TDXRMachine_Color.A+1)
  7122.             mov edx,offset @@Col2-4
  7123.             sub edx,offset @@StartCode
  7124.             mov dword ptr [ecx+edx],eax
  7125.  
  7126.             {  @@Dest  }
  7127.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.A+1)
  7128.             mov edx,offset @@Dest-4
  7129.             sub edx,offset @@StartCode
  7130.             mov dword ptr [ecx+edx],eax
  7131.           end;
  7132.         end;
  7133.       end;
  7134.     end;
  7135.  
  7136.     procedure genBlend_DECALALPHA(var Code: Pointer; Dest, Col1, Col2: PDXRMachine_Color;
  7137.       ConstChannels1, ConstChannels12: TDXRColorChannels);
  7138.     begin
  7139.       if ([chRed, chGreen, chBlue]<=EnableChannels) and (Dest<>Col1) then
  7140.       begin
  7141.         if UseMMX then
  7142.         begin
  7143.           FMMXUsed := True;
  7144.           asm
  7145.             jmp @@EndCode
  7146.           @@StartCode:
  7147.             db $0F,$6F,$05,$11,$11,$11,$11///movq mm0,qword ptr [$11111111]
  7148.                                    @@Col1:
  7149.             db $0F,$7F,$05,$11,$11,$11,$11///movq qword ptr [$11111111],mm0
  7150.                                    @@Dest:
  7151.           @@EndCode:
  7152.             {$I DXRender.inc}
  7153.             {  @@Col1  }
  7154.             mov eax,Col1
  7155.             mov edx,offset @@Col1-4
  7156.             sub edx,offset @@StartCode
  7157.             mov dword ptr [ecx+edx],eax
  7158.  
  7159.             {  @@Dest  }
  7160.             mov eax,Dest
  7161.             mov edx,offset @@Dest-4
  7162.             sub edx,offset @@StartCode
  7163.             mov dword ptr [ecx+edx],eax
  7164.           end;
  7165.         end else
  7166.         begin
  7167.           asm
  7168.             jmp @@EndCode
  7169.           @@StartCode:
  7170.             mov eax,dword ptr [offset _null]{}@@Col1:
  7171.             mov edx,dword ptr [offset _null]{}@@Col1_2:
  7172.             mov dword ptr [offset _null],eax{}@@Dest:
  7173.             mov dword ptr [offset _null],edx{}@@Dest2:
  7174.           @@EndCode:
  7175.             {$I DXRender.inc}
  7176.             {  @@Col1  }
  7177.             mov eax,Col1
  7178.             mov edx,offset @@Col1-4
  7179.             sub edx,offset @@StartCode
  7180.             mov dword ptr [ecx+edx],eax
  7181.  
  7182.             {  @@Col1_2  }
  7183.             mov eax,Col1; add eax,4
  7184.             mov edx,offset @@Col1_2-4
  7185.             sub edx,offset @@StartCode
  7186.             mov dword ptr [ecx+edx],eax
  7187.  
  7188.             {  @@Dest  }
  7189.             mov eax,Dest
  7190.             mov edx,offset @@Dest-4
  7191.             sub edx,offset @@StartCode
  7192.             mov dword ptr [ecx+edx],eax
  7193.  
  7194.             {  @@Dest2  }
  7195.             mov eax,Dest; add eax,4
  7196.             mov edx,offset @@Dest2-4
  7197.             sub edx,offset @@StartCode
  7198.             mov dword ptr [ecx+edx],eax
  7199.           end;
  7200.         end;
  7201.       end;
  7202.  
  7203.       if chAlpha in EnableChannels then
  7204.       begin
  7205.         asm
  7206.           jmp @@EndCode
  7207.         @@StartCode:
  7208.           mov al,byte ptr [offset _null]{}@@Col2:
  7209.           mov byte ptr [offset _null],al{}@@Dest:
  7210.         @@EndCode:
  7211.           {$I DXRender.inc}
  7212.           {  @@Col2  }
  7213.           mov eax,Col2; add eax,Byte(TDXRMachine_Color.A+1)
  7214.           mov edx,offset @@Col2-4
  7215.           sub edx,offset @@StartCode
  7216.           mov dword ptr [ecx+edx],eax
  7217.  
  7218.           {  @@Dest  }
  7219.           mov eax,Dest; add eax,Byte(TDXRMachine_Color.A+1)
  7220.           mov edx,offset @@Dest-4
  7221.           sub edx,offset @@StartCode
  7222.           mov dword ptr [ecx+edx],eax
  7223.         end;
  7224.       end;
  7225.     end;
  7226.  
  7227.     procedure genBlend_MODULATE(var Code: Pointer; Dest, Col1, Col2: PDXRMachine_Color;
  7228.       ConstChannels1, ConstChannels12: TDXRColorChannels);
  7229.     begin
  7230.       if chRed in EnableChannels then
  7231.       begin
  7232.         asm
  7233.           jmp @@EndCode
  7234.         @@StartCode:
  7235.           mov al,byte ptr [offset offset _null]{}@@Col1:
  7236.           mul byte ptr [offset offset _null]   {}@@Col2:
  7237.           mov byte ptr [offset offset _null],ah{}@@Dest:
  7238.         @@EndCode:
  7239.           {$I DXRender.inc}
  7240.           {  @@Col1  }
  7241.           mov eax,Col1; add eax,Byte(TDXRMachine_Color.R+1)
  7242.           mov edx,offset @@Col1-4
  7243.           sub edx,offset @@StartCode
  7244.           mov dword ptr [ecx+edx],eax
  7245.  
  7246.           {  @@Col2  }
  7247.           mov eax,Col2; add eax,Byte(TDXRMachine_Color.R+1)
  7248.           mov edx,offset @@Col2-4
  7249.           sub edx,offset @@StartCode
  7250.           mov dword ptr [ecx+edx],eax
  7251.  
  7252.           {  @@Dest  }
  7253.           mov eax,Dest; add eax,Byte(TDXRMachine_Color.R+1)
  7254.           mov edx,offset @@Dest-4
  7255.           sub edx,offset @@StartCode
  7256.           mov dword ptr [ecx+edx],eax
  7257.         end;
  7258.       end;
  7259.  
  7260.       if chGreen in EnableChannels then
  7261.       begin
  7262.         asm
  7263.           jmp @@EndCode
  7264.         @@StartCode:
  7265.           mov al,byte ptr [offset offset _null]{}@@Col1:
  7266.           mul byte ptr [offset offset _null]   {}@@Col2:
  7267.           mov byte ptr [offset offset _null],ah{}@@Dest:
  7268.         @@EndCode:
  7269.           {$I DXRender.inc}
  7270.           {  @@Col1  }
  7271.           mov eax,Col1; add eax,Byte(TDXRMachine_Color.G+1)
  7272.           mov edx,offset @@Col1-4
  7273.           sub edx,offset @@StartCode
  7274.           mov dword ptr [ecx+edx],eax
  7275.  
  7276.           {  @@Col2  }
  7277.           mov eax,Col2; add eax,Byte(TDXRMachine_Color.G+1)
  7278.           mov edx,offset @@Col2-4
  7279.           sub edx,offset @@StartCode
  7280.           mov dword ptr [ecx+edx],eax
  7281.  
  7282.           {  @@Dest  }
  7283.           mov eax,Dest; add eax,Byte(TDXRMachine_Color.G+1)
  7284.           mov edx,offset @@Dest-4
  7285.           sub edx,offset @@StartCode
  7286.           mov dword ptr [ecx+edx],eax
  7287.         end;
  7288.       end;
  7289.  
  7290.       if chBlue in EnableChannels then
  7291.       begin
  7292.         asm
  7293.           jmp @@EndCode
  7294.         @@StartCode:
  7295.           mov al,byte ptr [offset offset _null]{}@@Col1:
  7296.           mul byte ptr [offset offset _null]   {}@@Col2:
  7297.           mov byte ptr [offset offset _null],ah{}@@Dest:
  7298.         @@EndCode:
  7299.           {$I DXRender.inc}
  7300.           {  @@Col1  }
  7301.           mov eax,Col1; add eax,Byte(TDXRMachine_Color.B+1)
  7302.           mov edx,offset @@Col1-4
  7303.           sub edx,offset @@StartCode
  7304.           mov dword ptr [ecx+edx],eax
  7305.  
  7306.           {  @@Col2  }
  7307.           mov eax,Col2; add eax,Byte(TDXRMachine_Color.B+1)
  7308.           mov edx,offset @@Col2-4
  7309.           sub edx,offset @@StartCode
  7310.           mov dword ptr [ecx+edx],eax
  7311.  
  7312.           {  @@Dest  }
  7313.           mov eax,Dest; add eax,Byte(TDXRMachine_Color.B+1)
  7314.           mov edx,offset @@Dest-4
  7315.           sub edx,offset @@StartCode
  7316.           mov dword ptr [ecx+edx],eax
  7317.         end;
  7318.       end;
  7319.  
  7320.       if (chAlpha in EnableChannels) or (Dest<>Col1) then
  7321.       begin
  7322.         asm
  7323.           jmp @@EndCode
  7324.         @@StartCode:
  7325.           mov al,byte ptr [offset _null]{}@@Col1:
  7326.           mov byte ptr [offset _null],al{}@@Dest:
  7327.         @@EndCode:
  7328.           {$I DXRender.inc}
  7329.           {  @@Col1  }
  7330.           mov eax,Col1; add eax,Byte(TDXRMachine_Color.A+1)
  7331.           mov edx,offset @@Col1-4
  7332.           sub edx,offset @@StartCode
  7333.           mov dword ptr [ecx+edx],eax
  7334.  
  7335.           {  @@Dest  }
  7336.           mov eax,Dest; add eax,Byte(TDXRMachine_Color.A+1)
  7337.           mov edx,offset @@Dest-4
  7338.           sub edx,offset @@StartCode
  7339.           mov dword ptr [ecx+edx],eax
  7340.         end;
  7341.       end;
  7342.     end;
  7343.  
  7344.     procedure genBlend_MODULATEALPHA(var Code: Pointer; Dest, Col1, Col2: PDXRMachine_Color;
  7345.       ConstChannels1, ConstChannels12: TDXRColorChannels);
  7346.     begin
  7347.       if UseMMX then
  7348.       begin
  7349.         FMMXUsed := True;
  7350.         asm
  7351.           jmp @@EndCode
  7352.         @@StartCode:
  7353.           db $0F,$6F,$05,$11,$11,$11,$11///movq mm0,qword ptr [$11111111]
  7354.                                  @@Col1:
  7355.           db $0F,$6F,$0D,$11,$11,$11,$11///movq mm1,qword ptr [$11111111]
  7356.                                  @@Col2:
  7357.           db $0F,$E5,$C1      ///pmulhw mm0,mm1
  7358.           db $0F,$7F,$05,$11,$11,$11,$11///movq qword ptr [$11111111],mm0
  7359.                                  @@Dest:
  7360.         @@EndCode:
  7361.           {$I DXRender.inc}
  7362.           {  @@Col1  }
  7363.           mov eax,Col1
  7364.           mov edx,offset @@Col1-4
  7365.           sub edx,offset @@StartCode
  7366.           mov dword ptr [ecx+edx],eax
  7367.  
  7368.           {  @@Col2  }
  7369.           mov eax,Col2
  7370.           mov edx,offset @@Col2-4
  7371.           sub edx,offset @@StartCode
  7372.           mov dword ptr [ecx+edx],eax
  7373.  
  7374.           {  @@Dest  }
  7375.           mov eax,offset Dest
  7376.           mov edx,offset @@Dest-4
  7377.           sub edx,offset @@StartCode
  7378.           mov dword ptr [ecx+edx],eax
  7379.         end;
  7380.       end else
  7381.       begin
  7382.         if chRed in EnableChannels then
  7383.         begin
  7384.           asm
  7385.             jmp @@EndCode
  7386.           @@StartCode:
  7387.             mov al,byte ptr [offset offset _null]{}@@Col1:
  7388.             mul byte ptr [offset offset _null]   {}@@Col2:
  7389.             mov byte ptr [offset offset _null],ah{}@@Dest:
  7390.           @@EndCode:
  7391.             {$I DXRender.inc}
  7392.             {  @@Col1  }
  7393.             mov eax,Col1; add eax,Byte(TDXRMachine_Color.R+1)
  7394.             mov edx,offset @@Col1-4
  7395.             sub edx,offset @@StartCode
  7396.             mov dword ptr [ecx+edx],eax
  7397.  
  7398.             {  @@Col2  }
  7399.             mov eax,Col2; add eax,Byte(TDXRMachine_Color.R+1)
  7400.             mov edx,offset @@Col2-4
  7401.             sub edx,offset @@StartCode
  7402.             mov dword ptr [ecx+edx],eax
  7403.  
  7404.             {  @@Dest  }
  7405.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.R+1)
  7406.             mov edx,offset @@Dest-4
  7407.             sub edx,offset @@StartCode
  7408.             mov dword ptr [ecx+edx],eax
  7409.           end;
  7410.         end;
  7411.  
  7412.         if chGreen in EnableChannels then
  7413.         begin
  7414.           asm
  7415.             jmp @@EndCode
  7416.           @@StartCode:
  7417.             mov al,byte ptr [offset offset _null]{}@@Col1:
  7418.             mul byte ptr [offset offset _null]   {}@@Col2:
  7419.             mov byte ptr [offset offset _null],ah{}@@Dest:
  7420.           @@EndCode:
  7421.             {$I DXRender.inc}
  7422.             {  @@Col1  }
  7423.             mov eax,Col1; add eax,Byte(TDXRMachine_Color.G+1)
  7424.             mov edx,offset @@Col1-4
  7425.             sub edx,offset @@StartCode
  7426.             mov dword ptr [ecx+edx],eax
  7427.  
  7428.             {  @@Col2  }
  7429.             mov eax,Col2; add eax,Byte(TDXRMachine_Color.G+1)
  7430.             mov edx,offset @@Col2-4
  7431.             sub edx,offset @@StartCode
  7432.             mov dword ptr [ecx+edx],eax
  7433.  
  7434.             {  @@Dest  }
  7435.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.G+1)
  7436.             mov edx,offset @@Dest-4
  7437.             sub edx,offset @@StartCode
  7438.             mov dword ptr [ecx+edx],eax
  7439.           end;
  7440.         end;
  7441.  
  7442.         if chBlue in EnableChannels then
  7443.         begin
  7444.           asm
  7445.             jmp @@EndCode
  7446.           @@StartCode:
  7447.             mov al,byte ptr [offset offset _null]{}@@Col1:
  7448.             mul byte ptr [offset offset _null]   {}@@Col2:
  7449.             mov byte ptr [offset offset _null],ah{}@@Dest:
  7450.           @@EndCode:
  7451.             {$I DXRender.inc}
  7452.             {  @@Col1  }
  7453.             mov eax,Col1; add eax,Byte(TDXRMachine_Color.B+1)
  7454.             mov edx,offset @@Col1-4
  7455.             sub edx,offset @@StartCode
  7456.             mov dword ptr [ecx+edx],eax
  7457.  
  7458.             {  @@Col2  }
  7459.             mov eax,Col2; add eax,Byte(TDXRMachine_Color.B+1)
  7460.             mov edx,offset @@Col2-4
  7461.             sub edx,offset @@StartCode
  7462.             mov dword ptr [ecx+edx],eax
  7463.  
  7464.             {  @@Dest  }
  7465.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.B+1)
  7466.             mov edx,offset @@Dest-4
  7467.             sub edx,offset @@StartCode
  7468.             mov dword ptr [ecx+edx],eax
  7469.           end;
  7470.         end;
  7471.  
  7472.         if chAlpha in EnableChannels then
  7473.         begin
  7474.           asm
  7475.             jmp @@EndCode
  7476.           @@StartCode:
  7477.             mov al,byte ptr [offset offset _null]{}@@Col1:
  7478.             mul byte ptr [offset offset _null]   {}@@Col2:
  7479.             mov byte ptr [offset offset _null],ah{}@@Dest:
  7480.           @@EndCode:
  7481.             {$I DXRender.inc}
  7482.             {  @@Col1  }
  7483.             mov eax,Col1; add eax,Byte(TDXRMachine_Color.A+1)
  7484.             mov edx,offset @@Col1-4
  7485.             sub edx,offset @@StartCode
  7486.             mov dword ptr [ecx+edx],eax
  7487.  
  7488.             {  @@Col2  }
  7489.             mov eax,Col2; add eax,Byte(TDXRMachine_Color.A+1)
  7490.             mov edx,offset @@Col2-4
  7491.             sub edx,offset @@StartCode
  7492.             mov dword ptr [ecx+edx],eax
  7493.  
  7494.             {  @@Dest  }
  7495.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.A+1)
  7496.             mov edx,offset @@Dest-4
  7497.             sub edx,offset @@StartCode
  7498.             mov dword ptr [ecx+edx],eax
  7499.           end;
  7500.         end;
  7501.       end;
  7502.     end;
  7503.  
  7504.     procedure genBlend_ADD(var Code: Pointer; Dest, Col1, Col2: PDXRMachine_Color;
  7505.       ConstChannels1, ConstChannels12: TDXRColorChannels);
  7506.     begin
  7507.       if UseMMX then
  7508.       begin
  7509.         FMMXUsed := True;
  7510.         asm
  7511.           jmp @@EndCode
  7512.         @@StartCode:
  7513.           db $0F,$6F,$05,$11,$11,$11,$11///movq mm0,qword ptr [$11111111]
  7514.                                  @@Col1:
  7515.           db $0F,$6F,$0D,$11,$11,$11,$11///movq mm1,qword ptr [$11111111]
  7516.                                  @@Col2:
  7517.           db $0F,$DD,$C1      ///paddusw mm0,mm1
  7518.           db $0F,$7F,$05,$11,$11,$11,$11///movq qword ptr [$11111111],mm0
  7519.                                  @@Dest:
  7520.         @@EndCode:
  7521.           {$I DXRender.inc}
  7522.           {  @@Col1  }
  7523.           mov eax,Col1
  7524.           mov edx,offset @@Col1-4
  7525.           sub edx,offset @@StartCode
  7526.           mov dword ptr [ecx+edx],eax
  7527.  
  7528.           {  @@Col2  }
  7529.           mov eax,Col2
  7530.           mov edx,offset @@Col2-4
  7531.           sub edx,offset @@StartCode
  7532.           mov dword ptr [ecx+edx],eax
  7533.  
  7534.           {  @@Dest  }
  7535.           mov eax,Dest
  7536.           mov edx,offset @@Dest-4
  7537.           sub edx,offset @@StartCode
  7538.           mov dword ptr [ecx+edx],eax
  7539.         end;
  7540.  
  7541.         {  Alpha Channel  }
  7542.         if chAlpha in EnableChannels then
  7543.         begin
  7544.           asm
  7545.             jmp @@EndCode
  7546.           @@StartCode:
  7547.             mov al,byte ptr [offset _null]{}@@Col2:
  7548.             mov byte ptr [offset _null],al{}@@Dest:
  7549.           @@EndCode:
  7550.             {$I DXRender.inc}
  7551.             {  @@Col2  }
  7552.             mov eax,Col2; add eax,Byte(TDXRMachine_Color.A+1)
  7553.             mov edx,offset @@Col2-4
  7554.             sub edx,offset @@StartCode
  7555.             mov dword ptr [ecx+edx],eax
  7556.  
  7557.             {  @@Dest  }
  7558.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.A+1)
  7559.             mov edx,offset @@Dest-4
  7560.             sub edx,offset @@StartCode
  7561.             mov dword ptr [ecx+edx],eax
  7562.           end;
  7563.         end;
  7564.       end else
  7565.       begin
  7566.         { Red Channel }
  7567.         if chRed in EnableChannels then
  7568.         begin
  7569.           if chRed in ConstChannels1 then
  7570.           begin
  7571.             Func_col1_Add_const2(Code, @Dest.R, @Col2.R, @Col1.R);
  7572.           end else
  7573.           if chRed in ConstChannels2 then
  7574.           begin
  7575.             Func_col1_Add_const2(Code, @Dest.R, @Col1.R, @Col2.R);
  7576.           end else
  7577.             Func_col1_Add_col2(Code, @Dest.R, @Col1.R, @Col2.R);
  7578.         end;
  7579.  
  7580.         { Green Channel }
  7581.         if chGreen in EnableChannels then
  7582.         begin
  7583.           if chRed in ConstChannels1 then
  7584.           begin
  7585.             Func_col1_Add_const2(Code, @Dest.G, @Col2.G, @Col1.G);
  7586.           end else
  7587.           if chRed in ConstChannels2 then
  7588.           begin
  7589.             Func_col1_Add_const2(Code, @Dest.G, @Col1.G, @Col2.G);
  7590.           end else
  7591.             Func_col1_Add_col2(Code, @Dest.G, @Col1.G, @Col2.G);
  7592.         end;
  7593.  
  7594.         { Blue Channel }
  7595.         if chBlue in EnableChannels then
  7596.         begin
  7597.           if chRed in ConstChannels1 then
  7598.           begin
  7599.             Func_col1_Add_const2(Code, @Dest.B, @Col2.B, @Col1.B);
  7600.           end else
  7601.           if chRed in ConstChannels2 then
  7602.           begin
  7603.             Func_col1_Add_const2(Code, @Dest.B, @Col1.B, @Col2.B);
  7604.           end else
  7605.             Func_col1_Add_col2(Code, @Dest.B, @Col1.B, @Col2.B);
  7606.         end;
  7607.  
  7608.         {  Alpha Channel  }
  7609.         if (chAlpha in EnableChannels) and (Col2<>Dest) then
  7610.         begin
  7611.           asm
  7612.             jmp @@EndCode
  7613.           @@StartCode:
  7614.             mov al,byte ptr [offset _null]{}@@Col2:
  7615.             mov byte ptr [offset _null],al{}@@Dest:
  7616.           @@EndCode:
  7617.             {$I DXRender.inc}
  7618.             {  @@Col2  }
  7619.             mov eax,Col2; add eax,Byte(TDXRMachine_Color.A+1)
  7620.             mov edx,offset @@Col2-4
  7621.             sub edx,offset @@StartCode
  7622.             mov dword ptr [ecx+edx],eax
  7623.  
  7624.             {  @@Dest  }
  7625.             mov eax,Dest; add eax,Byte(TDXRMachine_Color.A+1)
  7626.             mov edx,offset @@Dest-4
  7627.             sub edx,offset @@StartCode
  7628.             mov dword ptr [ecx+edx],eax
  7629.           end;
  7630.         end;
  7631.       end;
  7632.     end;
  7633.  
  7634.   begin
  7635.     if EnableChannels=[] then Exit;
  7636.                              
  7637.     case Blend of
  7638.       DXR_BLEND_ZERO                      : genBlend_ZERO(Code, Dest);
  7639.       DXR_BLEND_ONE1                      : genBlend_ONE1(Code, Dest, Col1, ConstChannels1);
  7640.       DXR_BLEND_ONE2                      : genBlend_ONE1(Code, Dest, Col2, ConstChannels2);
  7641.       DXR_BLEND_ONE1_ADD_ONE2             : genBlend_ONE1_ADD_ONE2(Code, Dest, Col1, Col2, ConstChannels1, ConstChannels2);
  7642.       DXR_BLEND_ONE1_SUB_ONE2             : genBlend_ONE1_SUB_ONE2(Code, Dest, Col1, Col2, ConstChannels1, ConstChannels2);
  7643.       DXR_BLEND_ONE2_SUB_ONE1             : genBlend_ONE2_SUB_ONE1(Code, Dest, Col1, Col2, ConstChannels1, ConstChannels2);
  7644.       DXR_BLEND_ONE1_MUL_ONE2             : genBlend_ONE1_MUL_ONE2(Code, Dest, Col1, Col2, ConstChannels1, ConstChannels2);
  7645.       DXR_BLEND_SRCALPHA1                 : genBlend_SRCALPHA1(Code, Dest, Col1, ConstChannels1);
  7646.       DXR_BLEND_SRCALPHA1_ADD_ONE2        : genBlend_SRCALPHA1_ADD_ONE2(Code, Dest, Col1, Col2, ConstChannels1, ConstChannels2);
  7647.       DXR_BLEND_ONE2_SUB_SRCALPHA1        : genBlend_ONE2_SUB_SRCALPHA1(Code, Dest, Col1, Col2, ConstChannels1, ConstChannels2);
  7648.       DXR_BLEND_SRCALPHA1_ADD_INVSRCALPHA2: genBlend_SRCALPHA1_ADD_INVSRCALPHA2(Code, Dest, Col1, Col2, ConstChannels1, ConstChannels2);
  7649.       DXR_BLEND_INVSRCALPHA1_ADD_SRCALPHA2: genBlend_INVSRCALPHA1_ADD_SRCALPHA2(Code, Dest, Col1, Col2, ConstChannels1, ConstChannels2);
  7650.       DXR_BLEND_DECAL                     : genBlend_ONE1(Code, Dest, Col1, ConstChannels1);
  7651.       DXR_BLEND_DECALALPHA                : genBlend_DECALALPHA(Code, Dest, Col1, Col2, ConstChannels1, ConstChannels2);
  7652.       DXR_BLEND_MODULATE                  : genBlend_MODULATE(Code, Dest, Col1, Col2, ConstChannels1, ConstChannels2);
  7653.       DXR_BLEND_MODULATEALPHA             : genBlend_MODULATEALPHA(Code, Dest, Col1, Col2, ConstChannels1, ConstChannels2);
  7654.       DXR_BLEND_ADD                       : genBlend_ADD(Code, Dest, Col1, Col2, ConstChannels1, ConstChannels2);
  7655.     end;                                                                                                      
  7656.   end;
  7657.  
  7658. var
  7659.   StackPoint: Integer;
  7660.  
  7661.   function NewWorkColor: PDXRMachine_Color;
  7662.   begin
  7663.     Result := @FStack[StackPoint]; Inc(StackPoint);
  7664.   end;
  7665.  
  7666.   function GenerateCode2(var Code: Pointer; Tree: PDXRMachine_Tree): PDXRMachine_Color;
  7667.   var
  7668.     Col1, Col2: PDXRMachine_Color;
  7669.     ConstChannels1, ConstChannels2: TDXRColorChannels;
  7670.     ch: TDXRColorChannels;
  7671.   begin
  7672.     Result := NewWorkColor;
  7673.     case Tree.Typ of
  7674.       DXR_TREETYPE_LOADBLACK:
  7675.           begin
  7676.             genBlend(Code, DXR_BLEND_ZERO, Result, nil, nil, Tree.Channels, [], []);
  7677.           end;
  7678.       DXR_TREETYPE_LOADCOLOR:
  7679.           begin
  7680.             genBlend(Code, DXR_BLEND_ONE1, Result, @ColorList[Tree.Color].nColor, nil, Tree.Channels, [], []);
  7681.           end;
  7682.       DXR_TREETYPE_LOADCONSTCOLOR:
  7683.           begin
  7684.             genBlend(Code, DXR_BLEND_ONE1, Result, @Tree.ConstColor, nil, Tree.Channels,
  7685.               [chRed, chGreen, chBlue, chAlpha], []);
  7686.           end;
  7687.       DXR_TREETYPE_LOADTEXTURE:
  7688.           begin
  7689.             genReadTexture(Code, Result, TextureList[Tree.Texture], Tree.Channels);
  7690.           end;
  7691.       DXR_TREETYPE_LOADBUMPTEXTURE:
  7692.           begin
  7693.             genReadBumpTexture(Code, Result, TextureList[Tree.Texture], TextureList[Tree.BumpTexture], Tree.Channels);
  7694.           end;
  7695.       DXR_TREETYPE_LOADDESTPIXEL:
  7696.           begin
  7697.             genReadDestPixel(Code);
  7698.             genDecodeColor(Code, Dest^, Result, Tree.Channels, _BlackColor);
  7699.           end;
  7700.       DXR_TREETYPE_BLEND:
  7701.           begin
  7702.             // Blend color
  7703.             Col1 := nil;
  7704.             Col2 := nil;
  7705.  
  7706.             ConstChannels1 := [];
  7707.             ConstChannels2 := [];
  7708.  
  7709.             if (Tree.BlendTree1<>nil) and (Tree.BlendTree1.Typ=DXR_TREETYPE_LOADBLACK) then
  7710.             begin
  7711.               Col1 := @_BlackColor;
  7712.             end else
  7713.             if (Tree.BlendTree1<>nil) and (Tree.BlendTree1.Typ=DXR_TREETYPE_LOADCOLOR) then
  7714.             begin
  7715.               Col1 := @ColorList[Tree.BlendTree1.Color].nColor;
  7716.             end else
  7717.             if (Tree.BlendTree1<>nil) and (Tree.BlendTree1.Typ=DXR_TREETYPE_LOADCONSTCOLOR) then
  7718.             begin
  7719.               Col1 := @Tree.BlendTree1.ConstColor;
  7720.               ConstChannels1 := [chRed, chGreen, chBlue, chAlpha];
  7721.             end else
  7722.             if (Tree.BlendTree1<>nil) and (Tree.BlendTree1.Typ=DXR_TREETYPE_LOADTEXTURE) then
  7723.             begin
  7724.               ch := TextureList[Tree.BlendTree1.Texture].EnableChannels;
  7725.  
  7726.               if (chRed in Tree.BlendTree1.Channels) and (not (chRed in ch)) then
  7727.               begin
  7728.                 ConstChannels1 := ConstChannels1 + [chRed];
  7729.                 Tree.BlendTree1.Channels := Tree.BlendTree1.Channels - [chRed];
  7730.               end;
  7731.  
  7732.               if (chGreen in Tree.BlendTree1.Channels) and (not (chGreen in ch)) then
  7733.               begin
  7734.                 ConstChannels1 := ConstChannels1 + [chGreen];
  7735.                 Tree.BlendTree1.Channels := Tree.BlendTree1.Channels - [chGreen];
  7736.               end;
  7737.  
  7738.               if (chBlue in Tree.BlendTree1.Channels) and (not (chBlue in ch)) then
  7739.               begin
  7740.                 ConstChannels1 := ConstChannels1 + [chBlue];
  7741.                 Tree.BlendTree1.Channels := Tree.BlendTree1.Channels - [chBlue];
  7742.               end;
  7743.  
  7744.               if (chAlpha in Tree.BlendTree1.Channels) and (not (chAlpha in ch)) then
  7745.               begin
  7746.                 ConstChannels1 := ConstChannels1 + [chAlpha];
  7747.                 Tree.BlendTree1.Channels := Tree.BlendTree1.Channels - [chAlpha];
  7748.               end;
  7749.  
  7750.               Col1 := GenerateCode2(Code, Tree.BlendTree1);
  7751.  
  7752.               if chRed in ConstChannels1 then
  7753.                 Col1.R := TextureList[Tree.BlendTree1.Texture].DefaultColor.R;
  7754.  
  7755.               if chGreen in ConstChannels1 then
  7756.                 Col1.G := TextureList[Tree.BlendTree1.Texture].DefaultColor.G;
  7757.  
  7758.               if chBlue in ConstChannels1 then
  7759.                 Col1.B := TextureList[Tree.BlendTree1.Texture].DefaultColor.B;
  7760.                
  7761.               if chAlpha in ConstChannels1 then
  7762.                 Col1.A := TextureList[Tree.BlendTree1.Texture].DefaultColor.A;
  7763.             end else
  7764.             if Tree.BlendTree1<>nil then
  7765.             begin
  7766.               Col1 := GenerateCode2(Code, Tree.BlendTree1);
  7767.             end;
  7768.  
  7769.             if (Tree.BlendTree2<>nil) and (Tree.BlendTree2.Typ=DXR_TREETYPE_LOADBLACK) then
  7770.             begin
  7771.               Col2 := @_BlackColor;
  7772.             end else
  7773.             if (Tree.BlendTree2<>nil) and (Tree.BlendTree2.Typ=DXR_TREETYPE_LOADCOLOR) then
  7774.             begin
  7775.               Col2 := @ColorList[Tree.BlendTree2.Color].nColor;
  7776.             end else
  7777.             if (Tree.BlendTree2<>nil) and (Tree.BlendTree2.Typ=DXR_TREETYPE_LOADCONSTCOLOR) then
  7778.             begin
  7779.               Col2 := @Tree.BlendTree2.ConstColor;
  7780.               ConstChannels2 := [chRed, chGreen, chBlue, chAlpha];
  7781.             end else
  7782.             if (Tree.BlendTree2<>nil) and (Tree.BlendTree2.Typ=DXR_TREETYPE_LOADTEXTURE) then
  7783.             begin
  7784.               ch := TextureList[Tree.BlendTree2.Texture].EnableChannels;
  7785.              
  7786.               if (chRed in Tree.BlendTree2.Channels) and (not (chRed in ch)) then
  7787.               begin
  7788.                 ConstChannels2 := ConstChannels2 + [chRed];
  7789.                 Tree.BlendTree2.Channels := Tree.BlendTree2.Channels - [chRed];
  7790.               end;
  7791.  
  7792.               if (chGreen in Tree.BlendTree2.Channels) and (not (chGreen in ch)) then
  7793.               begin
  7794.                 ConstChannels2 := ConstChannels2 + [chGreen];
  7795.                 Tree.BlendTree2.Channels := Tree.BlendTree2.Channels - [chGreen];
  7796.               end;
  7797.  
  7798.               if (chBlue in Tree.BlendTree2.Channels) and (not (chBlue in ch)) then
  7799.               begin
  7800.                 ConstChannels2 := ConstChannels2 + [chBlue];
  7801.                 Tree.BlendTree2.Channels := Tree.BlendTree2.Channels - [chBlue];
  7802.               end;
  7803.  
  7804.               if (chAlpha in Tree.BlendTree2.Channels) and (not (chAlpha in ch)) then
  7805.               begin
  7806.                 ConstChannels2 := ConstChannels2 + [chAlpha];
  7807.                 Tree.BlendTree2.Channels := Tree.BlendTree2.Channels - [chAlpha];
  7808.               end;
  7809.  
  7810.               Col2 := GenerateCode2(Code, Tree.BlendTree2);
  7811.  
  7812.               if chRed in ConstChannels2 then
  7813.                 Col2.R := TextureList[Tree.BlendTree2.Texture].DefaultColor.R;
  7814.  
  7815.               if chGreen in ConstChannels2 then
  7816.                 Col2.G := TextureList[Tree.BlendTree2.Texture].DefaultColor.G;
  7817.  
  7818.               if chBlue in ConstChannels2 then
  7819.                 Col2.B := TextureList[Tree.BlendTree2.Texture].DefaultColor.B;
  7820.  
  7821.               if chAlpha in ConstChannels2 then
  7822.                 Col2.A := TextureList[Tree.BlendTree2.Texture].DefaultColor.A;
  7823.             end else
  7824.             if Tree.BlendTree2<>nil then
  7825.             begin
  7826.               Col2 := GenerateCode2(Code, Tree.BlendTree2);
  7827.             end;
  7828.  
  7829.             genBlend(Code, Tree.Blend, Result, Col1, Col2, Tree.Channels,
  7830.               ConstChannels1, ConstChannels2);
  7831.           end;
  7832.     end;
  7833.   end;
  7834.  
  7835. var
  7836.   ExitAddress, MainCode: Pointer;
  7837.   Col: PDXRMachine_Color;
  7838. begin
  7839.   if (Tree.Typ=DXR_TREETYPE_LOADCOLOR) and (not ColorList[Tree.Color].Gouraud) and
  7840.     (not ZBuffer.Enable) and (not Dither.Enable) and (Dest.BitCount in [16, 32]) then
  7841.   begin
  7842.     FCall := Code;
  7843.     genInitDestAddress(Code);
  7844.     genEncodeColor(Code, Dest^, @ColorList[Tree.Color].nColor, Tree.Channels);
  7845.  
  7846.     case Dest.BitCount of
  7847.       16: begin
  7848.             asm
  7849.               jmp @@EndCode
  7850.             @@StartCode:
  7851.               mov edx,eax
  7852.               rol eax,16
  7853.               mov ax,dx
  7854.  
  7855.               {  DWORD arrangement  }
  7856.               mov edx,edi
  7857.               and edx,3
  7858.               shr edx,1
  7859.               jz @@dwordarray_skip
  7860.  
  7861.             @@dwordarray_loop:
  7862.               mov word ptr [edi],ax
  7863.               add edi,2
  7864.               dec ecx
  7865.               jz @@Exit
  7866.               dec edx
  7867.               jmp @@dwordarray_loop
  7868.             @@dwordarray_skip:
  7869.  
  7870.               {  DWORD  }
  7871.               mov edx,ecx
  7872.               shr edx,1
  7873.               jz @@dword_skip
  7874.             @@dword_loop:
  7875.               mov dword ptr [edi],eax
  7876.               add edi,4
  7877.               dec edx
  7878.               jnz @@dword_loop
  7879.  
  7880.               and ecx,1
  7881.               jz @@Exit
  7882.             @@dword_skip:
  7883.  
  7884.               {  WORD  }
  7885.               mov word ptr [edi],ax
  7886.             @@Exit:
  7887.               ret
  7888.             @@EndCode:
  7889.               {$I DXRender.inc}
  7890.             end;
  7891.           end;
  7892.       32: begin
  7893.             asm
  7894.               jmp @@EndCode
  7895.             @@StartCode:
  7896.               {  DWORD  }
  7897.               dec ecx
  7898.             @@loop:
  7899.               mov dword ptr [edi+ecx*4],eax
  7900.               dec ecx
  7901.               jnl @@loop
  7902.               ret
  7903.             @@EndCode:
  7904.               {$I DXRender.inc}
  7905.             end;
  7906.           end;
  7907.     end;
  7908.  
  7909.     Exit;
  7910.   end;
  7911.  
  7912.   {  -----------  Exit  -----------  }
  7913.   ExitAddress := Code;
  7914.  
  7915.   asm
  7916.     jmp @@EndCode
  7917.   @@StartCode:
  7918.     ret
  7919.   @@EndCode:
  7920.     {$I DXRender.inc}
  7921.   end;
  7922.  
  7923.   {  -----------  Loop  -----------  }
  7924.   SkipAddress := Code;
  7925.  
  7926.   genUpdateAxis(Code);
  7927.   genUpdateColor(Code);
  7928.   genUpdateTextureAxis(Code);
  7929.   genUpdateRHW(Code);
  7930.   genUpdateDestAddress(Code);
  7931.   genUpdateZBufferAddress(Code);
  7932.  
  7933.   asm
  7934.     jmp @@EndCode
  7935.   @@StartCode:
  7936.     dec ecx
  7937.   @@EndCode:
  7938.     {$I DXRender.inc}
  7939.   end;
  7940.   genCmpFunc(Code, DXR_CMPFUNC_LESSEQUAL, ExitAddress);
  7941.  
  7942.   {  -----------  Main  -----------  }
  7943.   MainCode := Code;
  7944.  
  7945.   genZBufferTest(Code);
  7946.  
  7947.   if Tree.Typ=DXR_TREETYPE_LOADCOLOR then
  7948.   begin
  7949.     genEncodeColor2(Code, Dest^, @ColorList[Tree.Color].nColor, Tree.Channels);
  7950.     genWriteDestPixel(Code);
  7951.   end else
  7952.   if (Tree.Typ=DXR_TREETYPE_LOADTEXTURE) and (not Dither.Enable) and
  7953.     (TextureList[Tree.Texture].Filter in [DXR_TEXTUREFILTER_NEAREST, DXR_TEXTUREFILTER_MIPMAP_NEAREST]) and
  7954.     (dxrCompareSurface(Dest^, TextureList[Tree.Texture].Surface^)) then
  7955.   begin
  7956.     genReadSurfacePixel(Code, TextureList[Tree.Texture], @TextureList[Tree.Texture].nAxis);
  7957.     genColorKey(Code, TextureList[Tree.Texture]);
  7958.     genWriteDestPixel(Code);
  7959.   end else
  7960.   begin
  7961.     StackPoint := 0; Col := GenerateCode2(Code, Tree);
  7962.     genEncodeColor2(Code, Dest^, Col, Tree.Channels);
  7963.     genWriteDestPixel(Code);
  7964.   end;
  7965.  
  7966.   genCmpFunc(Code, DXR_CMPFUNC_ALWAYS, SkipAddress);
  7967.  
  7968.   {  -----------  Initialize  -----------  }
  7969.   FCall := Code;
  7970.  
  7971.   genInitDestAddress(Code);
  7972.   genInitZBuffer(Code);
  7973.  
  7974.   genCmpFunc(Code, DXR_CMPFUNC_ALWAYS, MainCode);
  7975. end;
  7976.  
  7977. procedure TDXRMachine.Run(Count: Integer);
  7978. var
  7979.   P: Pointer;
  7980. begin
  7981.   if Count<=0 then Exit;
  7982.   if FCall=nil then Exit;
  7983.  
  7984.   P := FCall;
  7985.  
  7986.   asm
  7987.     push edi
  7988.     push esi
  7989.     push ebx
  7990.     push ebp
  7991.     push eax
  7992.     push edx
  7993.     mov ecx,Count
  7994.     mov eax,P
  7995.     call eax
  7996.     pop edx
  7997.     pop eax
  7998.     pop ebp
  7999.     pop ebx
  8000.     pop esi
  8001.     pop edi
  8002.   end;
  8003.  
  8004.   if FMMXUsed then
  8005.   begin
  8006.     asm
  8007.       db $0F,$77                    ///emms
  8008.     end;
  8009.   end;
  8010. end;
  8011.  
  8012. var
  8013.   FDXRMachine: TDXRMachine;
  8014.  
  8015. function DXRMachine: TDXRMachine;
  8016. begin
  8017.   if FDXRMachine=nil then
  8018.     FDXRMachine := TDXRMachine.Create;
  8019.   Result := FDXRMachine;
  8020. end;
  8021.  
  8022. procedure dxrDefRenderStates(var States: TDXR_RenderStates);
  8023. var
  8024.   i: Integer;
  8025. begin
  8026.   FillChar(States, SizeOf(States), 0);
  8027.  
  8028.   with States do
  8029.   begin
  8030.     DitherEnable := False;
  8031.     SpecularEnable := True;
  8032.     CullMode := DXR_CULL_CCW;
  8033.     Shade := DXR_SHADEMODE_GOURAUD;
  8034.     TexBlend := DXR_BLEND_MODULATE;
  8035.     Blend := DXR_BLEND_ONE1;
  8036.     TextureFilter := DXR_TEXTUREFILTER_NEAREST;
  8037.     ZBuffer := nil;
  8038.     ZFunc := DXR_CMPFUNC_LESSEQUAL;
  8039.     ZWriteEnable := True;
  8040.     EnableDrawLine := 0;
  8041.   end;
  8042.  
  8043.   for i:=0 to DXR_MAXTEXTURE-1 do
  8044.     with States.TextureList[i] do
  8045.     begin
  8046.       LayerBlend := DXR_TEXTURELAYERBLEND_TEXTURE;
  8047.       Blend := DXR_BLEND_ONE1;
  8048.       Surface := nil;
  8049.       ColorKeyEnable := False;
  8050.       ColorKey := 0;
  8051.       TextureAddress := DXR_TEXTUREADDRESS_TILE;
  8052.       BumpTexture := -1;
  8053.     end;
  8054. end;
  8055.  
  8056. {  Draw primitive  }
  8057.  
  8058. type
  8059.   PArrayDXR_Vertex = ^TArrayDXR_Vertex;
  8060.   TArrayDXR_Vertex = array[0..0] of TDXR_Vertex;
  8061.  
  8062.   PArrayPDXR_Vertex = ^TArrayPDXR_Vertex;
  8063.   TArrayPDXR_Vertex = array[0..0] of PDXR_Vertex;
  8064.  
  8065.   TDXR_Triangle = array[0..2] of PDXR_Vertex;
  8066.  
  8067.   PArrayDWORD = ^TArrayDWORD;
  8068.   TArrayDWORD = array[0..2] of DWORD;
  8069.  
  8070. procedure dxrDrawTriangle(const Dest: TDXR_Surface; const States: TDXR_RenderStates; const Tri: TDXR_Triangle);
  8071.  
  8072.   function InitGenerator_MakeTree_LoadTexture(Texture: Integer): PDXRMachine_Tree;
  8073.   begin
  8074.     if States.TextureList[Texture].BumpTexture>=0 then
  8075.       Result := DXRMachine.CreateTree_LoadBumpTexture(Texture, States.TextureList[Texture].BumpTexture)
  8076.     else
  8077.       Result := DXRMachine.CreateTree_LoadTexture(Texture);
  8078.   end;
  8079.  
  8080.   function InitGenerator_MakeTree: PDXRMachine_Tree;
  8081.   var
  8082.     i: Integer;
  8083.     Layer: PDXR_TextureLayer;
  8084.   begin
  8085.     if States.TextureEnable then
  8086.     begin
  8087.       {  Load texel  }
  8088.       Result := DXRMachine.CreateTree2(DXR_TREETYPE_LOADBLACK);
  8089.  
  8090.       if States.TextureEnable then
  8091.         for i:=Low(States.TextureList) to High(States.TextureList) do
  8092.         begin
  8093.           Layer := @States.TextureList[i];
  8094.           if (Layer.Surface<>nil) and (Layer.LayerBlend=DXR_TEXTURELAYERBLEND_TEXTURE) then
  8095.           begin
  8096.             Result := DXRMachine.CreateTree_Blend(Layer.Blend, InitGenerator_MakeTree_LoadTexture(i), Result);
  8097.           end;
  8098.         end;
  8099.  
  8100.       {  Lighting  }
  8101.       Result := DXRMachine.CreateTree_Blend(States.TexBlend, Result, DXRMachine.CreateTree_LoadColor(0));
  8102.  
  8103.       {  Blend after lighting is given  }
  8104.       for i:=Low(States.TextureList) to High(States.TextureList) do
  8105.       begin
  8106.         Layer := @States.TextureList[i];
  8107.         if (Layer.Surface<>nil) and (Layer.LayerBlend=DXR_TEXTURELAYERBLEND_LAST) then
  8108.         begin
  8109.           Result := DXRMachine.CreateTree_Blend(Layer.Blend, InitGenerator_MakeTree_LoadTexture(i), Result);
  8110.         end;
  8111.       end;
  8112.     end else
  8113.     begin
  8114.       Result := DXRMachine.CreateTree_LoadColor(0);
  8115.     end;
  8116.  
  8117.     {  Blend with Dest pixel   }
  8118.     Result := DXRMachine.CreateTree_Blend(States.Blend, Result, DXRMachine.CreateTree2(DXR_TREETYPE_LOADDESTPIXEL));
  8119.  
  8120.     {  Specular generation  }
  8121.     if States.SpecularEnable then
  8122.     begin
  8123.       Result := DXRMachine.CreateTree_Blend(DXR_BLEND_ONE1_ADD_ONE2, Result, DXRMachine.CreateTree_LoadColor(1));
  8124.     end;
  8125.   end;
  8126.  
  8127.   procedure InitGenerator;
  8128.  
  8129.     function Hypot(X, Y: Extended): Extended;
  8130.     begin
  8131.       Result := Sqrt(X*X + Y*Y);
  8132.     end;
  8133.  
  8134.   var
  8135.     i: Integer;
  8136.     Layer: PDXR_TextureLayer;
  8137.     Mipmap1, Mipmap2, Mipmap3: Integer;
  8138.     TmpSurface2: PDXR_Surface;
  8139.   begin
  8140.     DXRMachine.Initialize;
  8141.  
  8142.     {  Parameter setting  }
  8143.     DXRMachine.Dest := @Dest;
  8144.     DXRMachine.ZBuffer.Enable := States.ZBuffer<>nil;
  8145.     DXRMachine.ZBuffer.Surface := States.ZBuffer;
  8146.     DXRMachine.ZBuffer.CmpFunc := States.ZFunc;
  8147.     DXRMachine.ZBuffer.WriteEnable := States.ZWriteEnable;
  8148.     DXRMachine.Dither.Enable := States.DitherEnable;
  8149.  
  8150.     DXRMachine.ColorList[0].Gouraud := States.Shade=DXR_SHADEMODE_GOURAUD;
  8151.     DXRMachine.ColorList[1].Gouraud := States.Shade=DXR_SHADEMODE_GOURAUD;
  8152.  
  8153.     if States.TextureEnable then
  8154.       for i:=Low(States.TextureList) to High(States.TextureList) do
  8155.       begin
  8156.         Layer := @States.TextureList[i];
  8157.  
  8158.         if States.TextureList[i].Surface<>nil then
  8159.         begin
  8160.           with DXRMachine.TextureList[i] do
  8161.           begin
  8162.             ColorKeyEnable := Layer.ColorKeyEnable;
  8163.             ColorKey := Layer.ColorKey;
  8164.             Surface := Layer.Surface;
  8165.             Filter := States.TextureFilter;
  8166.             TextureAddress := Layer.TextureAddress;
  8167.  
  8168.             if (Filter in [DXR_TEXTUREFILTER_MIPMAP_NEAREST, DXR_TEXTUREFILTER_MIPMAP_LINEAR]) and
  8169.               (Surface.MipmapChain<>nil) then
  8170.             begin
  8171.               {  Mipmap  }
  8172.               Mipmap1 := MaxInt;
  8173.               Mipmap3 := Trunc(Abs(Hypot(Tri[2].sx-Tri[1].sx, Tri[2].sy-Tri[1].sy))*
  8174.                 Abs(Hypot(Tri[1].sx-Tri[0].sx, Tri[1].sy-Tri[0].sy))*
  8175.                 Abs(Hypot(Tri[2].sx-Tri[0].sx, Tri[2].sy-Tri[0].sy))/9);
  8176.  
  8177.               TmpSurface2 := Surface;
  8178.  
  8179.               while TmpSurface2<>nil do
  8180.               begin
  8181.                 Mipmap2 := TmpSurface2.Width2*TmpSurface2.Height2;
  8182.  
  8183.                 if (Abs(Mipmap3-Mipmap2)<Abs(Mipmap3-Mipmap1)) then
  8184.                 begin
  8185.                   Surface := TmpSurface2;
  8186.                   Mipmap1 := Mipmap2;
  8187.                 end;
  8188.  
  8189.                 TmpSurface2 := TmpSurface2.MipmapChain;
  8190.               end;
  8191.             end;
  8192.           end;
  8193.         end;
  8194.       end;
  8195.  
  8196.     {  Tree making  }
  8197.     DXRMachine.Compile(InitGenerator_MakeTree);
  8198.   end;
  8199.  
  8200. type
  8201.   TCol64Array = array[0..1] of TDXRMachine_Color;
  8202.   T2DAxis64Array = array[0..DXR_MAXTEXTURE-1] of TDXRMachine_Axis;
  8203.  
  8204. const
  8205.   Int32Value = 65536.0*65536.0;
  8206.  
  8207. var
  8208.   TexXFloat, TexYFloat: array[0..DXR_MAXTEXTURE-1] of DWORD;
  8209.  
  8210.   function Comp2DWORD(c: Comp): DWORD;
  8211.   begin
  8212.     Result := PDWORD(@c)^;
  8213.   end;
  8214.  
  8215.   function FloatToIntFloat(d: Extended): Comp;
  8216.   begin
  8217.     Result := d*Int32Value;
  8218.   end;
  8219.  
  8220.   function FloatToColorFloat(d: Extended): Word;
  8221.   begin
  8222.     Result := Trunc(d*255);
  8223.   end;
  8224.  
  8225.   function FloatToTextureFloatX(i: Integer; d: Extended): DWORD;
  8226.   begin
  8227.     Result := Comp2DWORD(d*TexXFloat[i]);
  8228.   end;
  8229.  
  8230.   function FloatToTextureFloatY(i: Integer; d: Double): DWORD;
  8231.   begin
  8232.     Result := Comp2DWORD(d*TexYFloat[i]);
  8233.   end;
  8234.  
  8235.   function FloatToRHWFloat(d: Extended): Comp;
  8236.   begin
  8237.     Result := d*Int32Value;
  8238.   end;
  8239.  
  8240.   procedure drawline(x1, x2, y: Integer;
  8241.     const x_ntex1, x_ntex2: T2DAxis64Array;
  8242.     const x_nc1, x_nc2: TCol64Array;
  8243.     const x_nRHW1, x_nRHW2: Comp);
  8244.   var
  8245.     i, xcount, xcount2, ofs: Integer;
  8246.   begin
  8247.     xcount := x2-x1;
  8248.     xcount2 := xcount;
  8249.  
  8250.     {  Clipping  }
  8251.     ofs := 0;
  8252.  
  8253.     if x1<0 then
  8254.     begin
  8255.       i := -x1;
  8256.       Inc(ofs, i);
  8257.       Inc(x1, i);
  8258.       Dec(xcount2, i);
  8259.     end;
  8260.  
  8261.     if x1+xcount2>=Integer(Dest.Width) then
  8262.     begin
  8263.       i := (x1+xcount2)-Integer(Dest.Width);
  8264.       Dec(xcount2, i);
  8265.     end;
  8266.  
  8267.     if xcount2<=0 then Exit;
  8268.  
  8269.     DXRMachine.Axis.Axis.X := x1;
  8270.     DXRMachine.Axis.Axis.Y := y;
  8271.  
  8272.     for i:=0 to DXRMachine.TextureIndexCount-1 do
  8273.       with DXRMachine.TextureList[DXRMachine.TextureIndex[i]] do
  8274.       begin
  8275.         nAxis := x_ntex1[i];
  8276.         iAxis.X := Integer(x_ntex2[i].X-x_ntex1[i].X) div xcount;
  8277.         iAxis.Y := Integer(x_ntex2[i].Y-x_ntex1[i].Y) div xcount;
  8278.  
  8279.         if TextureAddress=DXR_TEXTUREADDRESS_DONOTCLIP then
  8280.         begin
  8281.           if (DWORD(nAxis.X) shr 16>DXRMachine.TextureList[DXRMachine.TextureIndex[i]].Surface.Width) or
  8282.             (DWORD(nAxis.Y) shr 16>DXRMachine.TextureList[DXRMachine.TextureIndex[i]].Surface.Height) then Exit;
  8283.  
  8284.           if ((DWORD(nAxis.X+iAxis.X*(xcount)-1)) shr 16>DXRMachine.TextureList[DXRMachine.TextureIndex[i]].Surface.Width) or
  8285.             ((DWORD(nAxis.Y+iAxis.Y*(xcount)-1)) shr 16>DXRMachine.TextureList[DXRMachine.TextureIndex[i]].Surface.Height) then Exit;
  8286.         end;
  8287.  
  8288.         if ofs<>0 then
  8289.         begin
  8290.           nAxis.X := nAxis.X + iAxis.X*ofs;
  8291.           nAxis.Y := nAxis.Y + iAxis.Y*ofs;
  8292.         end;
  8293.       end;
  8294.  
  8295.     for i:=0 to DXRMachine.ColorIndexCount-1 do
  8296.       with DXRMachine.ColorList[DXRMachine.ColorIndex[i]] do
  8297.       begin
  8298.         if Gouraud then
  8299.         begin
  8300.           nColor := x_nc1[i];
  8301.  
  8302.           iColor.R := Integer(x_nc2[i].R-x_nc1[i].R) div xcount;
  8303.           iColor.G := Integer(x_nc2[i].G-x_nc1[i].G) div xcount;
  8304.           iColor.B := Integer(x_nc2[i].B-x_nc1[i].B) div xcount;
  8305.           iColor.A := Integer(x_nc2[i].A-x_nc1[i].A) div xcount;
  8306.  
  8307.           if ofs<>0 then
  8308.           begin
  8309.             nColor.R := nColor.R + iColor.R*ofs;
  8310.             nColor.G := nColor.G + iColor.G*ofs;
  8311.             nColor.B := nColor.B + iColor.B*ofs;
  8312.             nColor.A := nColor.A + iColor.A*ofs;
  8313.           end;
  8314.         end;
  8315.       end;
  8316.  
  8317.     with DXRMachine.RHW do
  8318.     begin
  8319.       if Enable then
  8320.       begin
  8321.         nRHW := x_nRHW1;
  8322.         iRHW := (x_nRHW2-x_nRHW1) / xcount;
  8323.         if ofs<>0 then
  8324.           nRHW := nRHW + iRHW*ofs;
  8325.       end;
  8326.     end;
  8327.  
  8328.     DXRMachine.Run(xcount2);
  8329.   end;
  8330.  
  8331.   procedure draw(p1, pt1, p2, pt2: PDXR_Vertex; starty, ycount, y1, y2, ofs1, ofs2: Integer);
  8332.   var
  8333.     i, j, y: Integer;
  8334.     c1, c2, c2_1, c2_2: TDXR_Color;
  8335.     y_nx1, y_nx2, y_ix1, y_ix2: Comp;
  8336.     y_ntex1, y_ntex2, y_itex1, y_itex2: T2DAxis64Array;
  8337.     y_nc1, y_nc2, y_ic1, y_ic2: TCol64Array;
  8338.     y_nRHW1, y_nRHW2, y_iRHW1, y_iRHW2: Comp;
  8339.   begin
  8340.     if ycount<=0 then Exit;
  8341.     if y1=0 then Exit;
  8342.     if y2=0 then Exit;
  8343.  
  8344.     {  Clipping  }
  8345.     if starty<0 then
  8346.     begin
  8347.       i := -starty;
  8348.  
  8349.       Inc(ofs1, i);
  8350.       Inc(ofs2, i);
  8351.  
  8352.       Inc(starty, i);
  8353.       Dec(ycount, i);
  8354.     end;
  8355.  
  8356.     if starty+ycount>=Integer(Dest.Height) then
  8357.     begin
  8358.       i := (starty+ycount)-Integer(Dest.Height);
  8359.       Dec(ycount, i);
  8360.     end;
  8361.  
  8362.     if ycount<=0 then Exit;
  8363.  
  8364.     y_nx1 := FloatToIntFloat(Trunc(p1.sx));
  8365.     y_nx2 := FloatToIntFloat(Trunc(p2.sx));
  8366.     y_ix1 := FloatToIntFloat((Trunc(pt1.sx)-Trunc(p1.sx))/y1);
  8367.     y_ix2 := FloatToIntFloat((Trunc(pt2.sx)-Trunc(p2.sx))/y2);
  8368.  
  8369.     if ofs1<>0 then
  8370.       y_nx1 := y_nx1 + y_ix1*ofs1;
  8371.  
  8372.     if ofs2<>0 then
  8373.       y_nx2 := y_nx2 + y_ix2*ofs2;
  8374.  
  8375.     for i:=0 to DXRMachine.TextureIndexCount-1 do
  8376.     begin
  8377.       j := DXRMachine.TextureIndex[i];
  8378.  
  8379.       y_itex1[i].X := FloatToTextureFloatX(i, (pt1.tu[j]-p1.tu[j])/y1);
  8380.       y_itex1[i].Y := FloatToTextureFloatY(i, (pt1.tv[j]-p1.tv[j])/y1);
  8381.       y_itex2[i].X := FloatToTextureFloatX(i, (pt2.tu[j]-p2.tu[j])/y2);
  8382.       y_itex2[i].Y := FloatToTextureFloatY(i, (pt2.tv[j]-p2.tv[j])/y2);
  8383.  
  8384.       y_ntex1[i].X := FloatToTextureFloatX(i, p1.tu[j]);
  8385.       y_ntex1[i].Y := FloatToTextureFloatY(i, p1.tv[j]);
  8386.       y_ntex2[i].X := FloatToTextureFloatX(i, p2.tu[j]);
  8387.       y_ntex2[i].Y := FloatToTextureFloatY(i, p2.tv[j]);
  8388.  
  8389.       if ofs1<>0 then
  8390.       begin
  8391.         y_ntex1[i].X := y_ntex1[i].X + y_itex1[i].X*ofs1;
  8392.         y_ntex1[i].Y := y_ntex1[i].Y + y_itex1[i].Y*ofs1;
  8393.       end;
  8394.  
  8395.       if ofs2<>0 then
  8396.       begin
  8397.         y_ntex2[i].X := y_ntex2[i].X + y_itex2[i].X*ofs2;
  8398.         y_ntex2[i].Y := y_ntex2[i].Y + y_itex2[i].Y*ofs2;
  8399.       end;
  8400.     end;
  8401.  
  8402.     for i:=0 to DXRMachine.ColorIndexCount-1 do
  8403.       if DXRMachine.ColorList[i].Gouraud then
  8404.       begin
  8405.         if DXRMachine.ColorIndex[i]=0 then
  8406.         begin
  8407.           c1 := p1.color;
  8408.           c2 := p2.color;
  8409.           c2_1 := pt1.color;
  8410.           c2_2 := pt2.color;
  8411.         end else
  8412.         begin
  8413.           c1 := p1.specular;
  8414.           c2 := p2.specular;
  8415.           c2_1 := pt1.specular;
  8416.           c2_2 := pt2.specular;
  8417.         end;
  8418.  
  8419.         y_nc1[i].R := FloatToColorFloat(RGBA_GETRED(c1));
  8420.         y_nc1[i].G := FloatToColorFloat(RGBA_GETGREEN(c1));
  8421.         y_nc1[i].B := FloatToColorFloat(RGBA_GETBLUE(c1));
  8422.         y_nc1[i].A := FloatToColorFloat(RGBA_GETALPHA(c1));
  8423.         y_nc2[i].R := FloatToColorFloat(RGBA_GETRED(c2));
  8424.         y_nc2[i].G := FloatToColorFloat(RGBA_GETGREEN(c2));
  8425.         y_nc2[i].B := FloatToColorFloat(RGBA_GETBLUE(c2));
  8426.         y_nc2[i].A := FloatToColorFloat(RGBA_GETALPHA(c2));
  8427.  
  8428.         y_ic1[i].R := FloatToColorFloat((RGBA_GETRED(c2_1)-RGBA_GETRED(c1))/y1);
  8429.         y_ic1[i].G := FloatToColorFloat((RGBA_GETGREEN(c2_1)-RGBA_GETGREEN(c1))/y1);
  8430.         y_ic1[i].B := FloatToColorFloat((RGBA_GETBLUE(c2_1)-RGBA_GETBLUE(c1))/y1);
  8431.         y_ic1[i].A := FloatToColorFloat((RGBA_GETALPHA(c2_1)-RGBA_GETALPHA(c1))/y1);
  8432.         y_ic2[i].R := FloatToColorFloat((RGBA_GETRED(c2_2)-RGBA_GETRED(c2))/y2);
  8433.         y_ic2[i].G := FloatToColorFloat((RGBA_GETGREEN(c2_2)-RGBA_GETGREEN(c2))/y2);
  8434.         y_ic2[i].B := FloatToColorFloat((RGBA_GETBLUE(c2_2)-RGBA_GETBLUE(c2))/y2);
  8435.         y_ic2[i].A := FloatToColorFloat((RGBA_GETALPHA(c2_2)-RGBA_GETALPHA(c2))/y2);
  8436.  
  8437.         if ofs1<>0 then
  8438.         begin
  8439.           y_nc1[i].R := y_nc1[i].R + y_ic1[i].R*ofs1;
  8440.           y_nc1[i].G := y_nc1[i].G + y_ic1[i].G*ofs1;
  8441.           y_nc1[i].B := y_nc1[i].B + y_ic1[i].B*ofs1;
  8442.           y_nc1[i].A := y_nc1[i].A + y_ic1[i].A*ofs1;
  8443.         end;
  8444.  
  8445.         if ofs2<>0 then
  8446.         begin
  8447.           y_nc2[i].R := y_nc2[i].R + y_ic2[i].R*ofs2;
  8448.           y_nc2[i].G := y_nc2[i].G + y_ic2[i].G*ofs2;
  8449.           y_nc2[i].B := y_nc2[i].B + y_ic2[i].B*ofs2;
  8450.           y_nc2[i].A := y_nc2[i].A + y_ic2[i].A*ofs2;
  8451.         end;
  8452.       end;
  8453.  
  8454.     if DXRMachine.RHW.Enable then
  8455.     begin
  8456.       y_nRHW1 := FloatToRHWFloat(p1.rhw);
  8457.       y_nRHW2 := FloatToRHWFloat(p2.rhw);
  8458.       y_iRHW1 := FloatToRHWFloat((pt1.rhw-p1.rhw)/y1);
  8459.       y_iRHW2 := FloatToRHWFloat((pt2.rhw-p2.rhw)/y2);
  8460.  
  8461.       if ofs1<>0 then
  8462.       begin
  8463.         y_nRHW1 := y_nRHW1 + y_iRHW1*ofs1;
  8464.       end;
  8465.  
  8466.       if ofs2<>0 then
  8467.       begin
  8468.         y_nRHW2 := y_nRHW2 + y_iRHW2*ofs2;
  8469.       end;
  8470.     end else
  8471.     begin
  8472.       y_nRHW1 := 0;
  8473.       y_nRHW2 := 0;
  8474.       y_iRHW1 := 0;
  8475.       y_iRHW2 := 0;
  8476.     end;
  8477.  
  8478.     for y:=starty to starty+ycount-1 do
  8479.     begin
  8480.       if (States.EnableDrawLine=0) or ((States.EnableDrawLine-1)=y mod 2) then
  8481.         if PInteger(Integer(@y_nx1)+4)^<PInteger(Integer(@y_nx2)+4)^ then
  8482.         begin
  8483.           drawline(
  8484.             PInteger(Integer(@y_nx1)+4)^, PInteger(Integer(@y_nx2)+4)^, y,
  8485.             y_ntex1, y_ntex2,
  8486.             y_nc1, y_nc2,
  8487.             y_nRHW1, y_nRHW2
  8488.           );
  8489.         end else if PInteger(Integer(@y_nx1)+4)^>PInteger(Integer(@y_nx2)+4)^ then
  8490.         begin
  8491.           drawline(
  8492.             PInteger(Integer(@y_nx2)+4)^, PInteger(Integer(@y_nx1)+4)^, y,
  8493.             y_ntex2, y_ntex1,
  8494.             y_nc2, y_nc1,
  8495.             y_nRHW2, y_nRHW1
  8496.           );
  8497.         end;
  8498.  
  8499.       y_nx1 := y_nx1 + y_ix1;
  8500.       y_nx2 := y_nx2 + y_ix2;
  8501.  
  8502.       for i:=0 to DXRMachine.TextureIndexCount-1 do
  8503.         with DXRMachine.TextureList[DXRMachine.TextureIndex[i]] do
  8504.         begin
  8505.           y_ntex1[i].X := y_ntex1[i].X + y_itex1[i].X;
  8506.           y_ntex1[i].Y := y_ntex1[i].Y + y_itex1[i].Y;
  8507.           y_ntex2[i].X := y_ntex2[i].X + y_itex2[i].X;
  8508.           y_ntex2[i].Y := y_ntex2[i].Y + y_itex2[i].Y;
  8509.         end;
  8510.  
  8511.       for i:=0 to DXRMachine.ColorIndexCount-1 do
  8512.         with DXRMachine.ColorList[DXRMachine.ColorIndex[i]] do
  8513.         begin
  8514.           if Gouraud then
  8515.           begin
  8516.             y_nc1[i].R := y_nc1[i].R + y_ic1[i].R;
  8517.             y_nc1[i].G := y_nc1[i].G + y_ic1[i].G;
  8518.             y_nc1[i].B := y_nc1[i].B + y_ic1[i].B;
  8519.             y_nc1[i].A := y_nc1[i].A + y_ic1[i].A;
  8520.             y_nc2[i].R := y_nc2[i].R + y_ic2[i].R;
  8521.             y_nc2[i].G := y_nc2[i].G + y_ic2[i].G;
  8522.             y_nc2[i].B := y_nc2[i].B + y_ic2[i].B;
  8523.             y_nc2[i].A := y_nc2[i].A + y_ic2[i].A;
  8524.           end;
  8525.         end;
  8526.  
  8527.       if DXRMachine.RHW.Enable then
  8528.       begin
  8529.         y_nRHW1 := y_nRHW1 + y_iRHW1;
  8530.         y_nRHW2 := y_nRHW2 + y_iRHW2;
  8531.       end;
  8532.     end;
  8533.   end;
  8534.  
  8535. var
  8536.   p: array[0..2] of PDXR_Vertex;
  8537.   tmp: Pointer;
  8538.   y1, y2, y3, i: Integer;
  8539. begin
  8540.   {  Cull  }
  8541.   case States.CullMode of
  8542.     DXR_CULL_NONE:
  8543.         begin
  8544.         end;
  8545.     DXR_CULL_CW:
  8546.         begin
  8547.           if (Tri[1].sx-Tri[0].sx)*(Tri[2].sy-Tri[0].sy)-(Tri[1].sy-Tri[0].sy)*(Tri[2].sx-Tri[0].sx)>0 then Exit;
  8548.         end;
  8549.     DXR_CULL_CCW:
  8550.         begin
  8551.           if (Tri[1].sx-Tri[0].sx)*(Tri[2].sy-Tri[0].sy)-(Tri[1].sy-Tri[0].sy)*(Tri[2].sx-Tri[0].sx)<0 then Exit;
  8552.         end;
  8553.   end;
  8554.  
  8555.   Inc(RenderPrimitiveCount);
  8556.  
  8557.   { p[0]=Top vertex of Y axis }
  8558.   { p[1]=Center vertex of Y axis }
  8559.   { p[2]=Bottom vertex of Y axis }
  8560.   p[0]:=Tri[0]; p[1]:=Tri[1]; p[2]:=Tri[2];
  8561.   if p[0].sy>p[1].sy then begin tmp:=p[0]; p[0]:=p[1]; p[1]:=tmp end;
  8562.   if p[0].sy>p[2].sy then begin tmp:=p[0]; p[0]:=p[2]; p[2]:=tmp end;
  8563.   if p[1].sy>p[2].sy then begin tmp:=p[1]; p[1]:=p[2]; p[2]:=tmp end;
  8564.  
  8565.   if (p[2].sy<=p[0].sy) then Exit;
  8566.   if (p[2].sy<=0) or (p[0].sy>=Dest.Height) then Exit;
  8567.   if (p[0].sx<0) and (p[1].sx<0) and (p[2].sx<0) then Exit;
  8568.   if (p[0].sx>=Dest.Width) and (p[1].sx>=Dest.Width) and (p[2].sx>=Dest.Width) then Exit;
  8569.  
  8570.   {  Generate code  }
  8571.   if States.TextureFilter in [DXR_TEXTUREFILTER_MIPMAP_NEAREST, DXR_TEXTUREFILTER_MIPMAP_LINEAR] then
  8572.     DXRMachine.Compiled := False;
  8573.  
  8574.   if not DXRMachine.Compiled then
  8575.     InitGenerator;
  8576.  
  8577.   y1 := Trunc(p[1].sy)-Trunc(p[0].sy);
  8578.   y2 := Trunc(p[2].sy)-Trunc(p[1].sy);
  8579.   y3 := Trunc(p[2].sy)-Trunc(p[0].sy);
  8580.  
  8581.   for i:=0 to DXRMachine.TextureIndexCount-1 do
  8582.     with DXRMachine.TextureList[DXRMachine.TextureIndex[i]] do
  8583.     begin
  8584.       case TextureAddress of
  8585.         DXR_TEXTUREADDRESS_TILE:
  8586.             begin
  8587.               TexXFloat[i] := Surface.Width2 * TextureAxisFloat;
  8588.               TexYFloat[i] := Surface.Height2 * TextureAxisFloat;
  8589.             end;
  8590.         DXR_TEXTUREADDRESS_DONOTCLIP:
  8591.             begin
  8592.               TexXFloat[i] := (Surface.Width-1) * TextureAxisFloat;
  8593.               TexYFloat[i] := (Surface.Height-1) * TextureAxisFloat;
  8594.             end;
  8595.       end;
  8596.     end;
  8597.  
  8598.   with DXRMachine.ColorList[0] do
  8599.     if Enable and (not Gouraud) then
  8600.     begin
  8601.       nColor.R := RGBA_GETRED(Tri[0].color)*ColorFloat;
  8602.       nColor.G := RGBA_GETGREEN(Tri[0].color)*ColorFloat;
  8603.       nColor.B := RGBA_GETBLUE(Tri[0].color)*ColorFloat;
  8604.       nColor.A := RGBA_GETALPHA(Tri[0].color)*ColorFloat;
  8605.     end;
  8606.  
  8607.   with DXRMachine.ColorList[1] do
  8608.     if Enable and (not Gouraud) then
  8609.     begin
  8610.       nColor.R := RGBA_GETRED(Tri[0].specular)*ColorFloat;
  8611.       nColor.G := RGBA_GETGREEN(Tri[0].specular)*ColorFloat;
  8612.       nColor.B := RGBA_GETBLUE(Tri[0].specular)*ColorFloat;
  8613.       nColor.A := RGBA_GETALPHA(Tri[0].specular)*ColorFloat;
  8614.     end;
  8615.  
  8616.   { p[0] - p[1] }
  8617.   draw(p[0], p[1], p[0], p[2], Trunc(p[0].sy), y1, y1, y3, 0, 0);
  8618.  
  8619.   { p[1] - p[2] }
  8620.   draw(p[1], p[2], p[0], p[2], Trunc(p[1].sy), y2, y2, y3, 0, y1);
  8621. end;
  8622.  
  8623. procedure dxrDrawPrimitive(const Dest: TDXR_Surface; const States: TDXR_RenderStates; PrimitiveType: TDXR_PrimitiveType;
  8624.   VertexList: PDXR_Vertex; VertexCount: DWORD);
  8625. var
  8626.   i: Integer;
  8627.   Tri: TDXR_Triangle;
  8628. begin
  8629.   if not (PrimitiveType in [DXR_PRIMITIVETYPE_TRIANGLELIST, DXR_PRIMITIVETYPE_TRIANGLESTRIP]) then Exit;
  8630.  
  8631.   DXRMachine.Compiled := False;
  8632.  
  8633.   case PrimitiveType of
  8634.     DXR_PRIMITIVETYPE_TRIANGLELIST:
  8635.         begin
  8636.           for i:=0 to VertexCount div 3-1 do
  8637.           begin
  8638.             Tri[0] := @PArrayDXR_Vertex(VertexList)[i*3];
  8639.             Tri[1] := @PArrayDXR_Vertex(VertexList)[i*3+1];
  8640.             Tri[2] := @PArrayDXR_Vertex(VertexList)[i*3+2];
  8641.             dxrDrawTriangle(Dest, States, Tri);
  8642.           end;
  8643.         end;
  8644.     DXR_PRIMITIVETYPE_TRIANGLESTRIP:
  8645.         begin
  8646.           for i:=2 to VertexCount-1 do
  8647.           begin
  8648.             Tri[0] := @PArrayDXR_Vertex(VertexList)[i-2];
  8649.             Tri[1] := @PArrayDXR_Vertex(VertexList)[i-1];
  8650.             Tri[2] := @PArrayDXR_Vertex(VertexList)[i];
  8651.             dxrDrawTriangle(Dest, States, Tri);
  8652.           end;
  8653.         end;
  8654.   end;
  8655. end;
  8656.  
  8657. procedure dxrDrawPointeredPrimitive(const Dest: TDXR_Surface; const States: TDXR_RenderStates; PrimitiveType: TDXR_PrimitiveType;
  8658.   VertexList: PPDXR_Vertex; VertexCount: DWORD);
  8659. var
  8660.   i: Integer;
  8661.   Tri: TDXR_Triangle;
  8662. begin
  8663.   if not (PrimitiveType in [DXR_PRIMITIVETYPE_TRIANGLELIST, DXR_PRIMITIVETYPE_TRIANGLESTRIP]) then Exit;
  8664.  
  8665.   DXRMachine.Compiled := False;
  8666.  
  8667.   case PrimitiveType of
  8668.     DXR_PRIMITIVETYPE_TRIANGLELIST:
  8669.         begin
  8670.           for i:=0 to VertexCount div 3-1 do
  8671.           begin
  8672.             Tri[0] := PArrayPDXR_Vertex(VertexList)[i*3];
  8673.             Tri[1] := PArrayPDXR_Vertex(VertexList)[i*3+1];
  8674.             Tri[2] := PArrayPDXR_Vertex(VertexList)[i*3+2];
  8675.             dxrDrawTriangle(Dest, States, Tri);
  8676.           end;
  8677.         end;
  8678.     DXR_PRIMITIVETYPE_TRIANGLESTRIP:
  8679.         begin
  8680.           for i:=2 to VertexCount-1 do
  8681.           begin
  8682.             Tri[0] := PArrayPDXR_Vertex(VertexList)[i-2];
  8683.             Tri[1] := PArrayPDXR_Vertex(VertexList)[i-1];
  8684.             Tri[2] := PArrayPDXR_Vertex(VertexList)[i];
  8685.             dxrDrawTriangle(Dest, States, Tri);
  8686.           end;
  8687.         end;
  8688.   end;
  8689. end;
  8690.  
  8691. procedure dxrDrawIndexedPrimitive(const Dest: TDXR_Surface; const States: TDXR_RenderStates; PrimitiveType: TDXR_PrimitiveType;
  8692.   VertexList: PDXR_Vertex; VertexCount: DWORD; IndexList: PDWORD; IndexCount: DWORD);
  8693. var
  8694.   i: Integer;
  8695.   Tri: TDXR_Triangle;
  8696. begin
  8697.   if not (PrimitiveType in [DXR_PRIMITIVETYPE_TRIANGLELIST, DXR_PRIMITIVETYPE_TRIANGLESTRIP]) then Exit;
  8698.  
  8699.   DXRMachine.Compiled := False;
  8700.  
  8701.   case PrimitiveType of
  8702.     DXR_PRIMITIVETYPE_TRIANGLELIST:
  8703.         begin
  8704.           for i:=0 to IndexCount div 3-1 do
  8705.           begin
  8706.             Tri[0] := @PArrayDXR_Vertex(VertexList)[PArrayDWORD(IndexList)[i*3]];
  8707.             Tri[1] := @PArrayDXR_Vertex(VertexList)[PArrayDWORD(IndexList)[i*3+1]];
  8708.             Tri[2] := @PArrayDXR_Vertex(VertexList)[PArrayDWORD(IndexList)[i*3+2]];
  8709.             dxrDrawTriangle(Dest, States, Tri);
  8710.           end;
  8711.         end;
  8712.     DXR_PRIMITIVETYPE_TRIANGLESTRIP:
  8713.         begin
  8714.           for i:=2 to IndexCount-1 do
  8715.           begin
  8716.             Tri[0] := @PArrayDXR_Vertex(VertexList)[PArrayDWORD(IndexList)[i-2]];
  8717.             Tri[1] := @PArrayDXR_Vertex(VertexList)[PArrayDWORD(IndexList)[i-1]];
  8718.             Tri[2] := @PArrayDXR_Vertex(VertexList)[PArrayDWORD(IndexList)[i]];
  8719.             dxrDrawTriangle(Dest, States, Tri);
  8720.           end;
  8721.         end;
  8722.   end;
  8723. end;
  8724.  
  8725. function MulDiv64(a, b, c: Integer): Integer; assembler;
  8726. asm
  8727.   mov eax, a
  8728.   imul b
  8729.   idiv c
  8730. end;
  8731.  
  8732. function Max(B1, B2: Integer): Integer; {$IFDEF VER9UP}inline;{$ENDIF}
  8733. begin
  8734.   if B1>=B2 then Result := B1 else Result := B2;
  8735. end;
  8736.  
  8737. function Min(B1, B2: Integer): Integer; {$IFDEF VER9UP}inline;{$ENDIF}
  8738. begin
  8739.   if B1<=B2 then Result := B1 else Result := B2;
  8740. end;
  8741.  
  8742. function BltClipX(const Dest, Src: TDXR_Surface;
  8743.   var StartX, EndX, StartSrcX: Integer): Boolean; {$IFDEF VER9UP}inline;{$ENDIF}
  8744. begin
  8745.   if StartX<0 then
  8746.   begin
  8747.     StartSrcX := StartSrcX-StartX;
  8748.     StartX := 0;
  8749.   end;
  8750.  
  8751.   EndX := Min(EndX, Dest.Width);
  8752.  
  8753.   Result := (EndX>0) and (EndX-StartX>0);
  8754. end;
  8755.  
  8756. function BltClipY(const Dest, Src: TDXR_Surface;
  8757.   var StartY, EndY, StartSrcY: Integer): Boolean; {$IFDEF VER9UP}inline;{$ENDIF}
  8758. begin
  8759.   if StartY<0 then
  8760.   begin
  8761.     StartSrcY := StartSrcY-StartY;
  8762.     StartY := 0;
  8763.   end;
  8764.  
  8765.   EndY := Min(EndY, Dest.Height);
  8766.  
  8767.   Result := (EndY>0) and (EndY-StartY>0);
  8768. end;
  8769.  
  8770. function BltClip(const Dest, Src: TDXR_Surface;
  8771.   var StartX, StartY, EndX, EndY, StartSrcX, StartSrcY: Integer): Boolean; {$IFDEF VER9UP}inline;{$ENDIF}
  8772. begin
  8773.   Result := BltClipX(Dest, Src, StartX, EndX, StartSrcX) and
  8774.     BltClipY(Dest, Src, StartY, EndY, StartSrcY);
  8775. end;
  8776.  
  8777. function FillClip(const Dest: TDXR_Surface;
  8778.   var StartX, StartY, EndX, EndY: Integer): Boolean; {$IFDEF VER9UP}inline;{$ENDIF}
  8779. begin
  8780.   StartX := Max(StartX, 0);
  8781.   StartY := Max(StartY, 0);
  8782.   EndX := Min(EndX, Dest.Width);
  8783.   EndY := Min(EndY, Dest.Height);
  8784.  
  8785.   Result := (StartX<EndX) and (StartY<EndY);
  8786. end;
  8787.  
  8788. var
  8789.   CosinTable: array[0..255] of Double;
  8790.  
  8791. procedure InitCosinTable; {$IFDEF VER9UP}inline;{$ENDIF}
  8792. var
  8793.   i: Integer;
  8794. begin
  8795.   for i:=Low(CosinTable) to High(CosinTable) do
  8796.     CosinTable[i] := Cos((i/256)*2*PI);
  8797. end;
  8798.  
  8799. function Cos256(i: Integer): Double; {$IFDEF VER9UP}inline;{$ENDIF}
  8800. begin
  8801.   Result := CosinTable[i and 255];
  8802. end;
  8803.  
  8804. function Sin256(i: Integer): Double; {$IFDEF VER9UP}inline;{$ENDIF}
  8805. begin
  8806.   Result := CosinTable[(i+192) and 255];
  8807. end;
  8808.  
  8809. function RotationClip(const Dest, Src: TDXR_Surface;
  8810.   X, Y, Width, Height: Integer; CenterX, CenterY: Double; Angle: Integer;
  8811.   var StartX, StartY, EndX, EndY: Integer): Boolean;
  8812.  
  8813.   function RotatePoint(ax, ay: Integer): TPoint;
  8814.   var
  8815.     c, s: Double;
  8816.   begin
  8817.     ax := Trunc(ax - Width*CenterX);
  8818.     ay := Trunc(ay - Height*CenterY);
  8819.     c := Cos256(Angle);
  8820.     s := Sin256(Angle);
  8821.     Result.X := X+Trunc(ax * c - ay * s);
  8822.     Result.Y := Y+Trunc(ax * s + ay * c);
  8823.   end;
  8824.                      
  8825. var
  8826.   i: Integer;
  8827.   Points: array[0..3] of TPoint;
  8828. begin                      
  8829.   Points[0] := RotatePoint(0, 0);
  8830.   Points[1] := RotatePoint(Width, 0);
  8831.   Points[2] := RotatePoint(0, Height);
  8832.   Points[3] := RotatePoint(Width, Height);
  8833.  
  8834.   StartX := Points[0].X;
  8835.   StartY := Points[0].Y;
  8836.   EndX := StartX;
  8837.   EndY := StartY;
  8838.  
  8839.   for i:=1 to 3 do
  8840.     with Points[i] do
  8841.     begin
  8842.       StartX := Min(StartX, X);
  8843.       StartY := Min(StartY, Y);
  8844.       EndX := Max(EndX, X);
  8845.       EndY := Max(EndY, Y);
  8846.     end;
  8847.  
  8848.   StartX := Max(StartX, 0);
  8849.   StartY := Max(StartY, 0);
  8850.   EndX := Min(EndX, Dest.Width);
  8851.   EndY := Min(EndY, Dest.Height);
  8852.  
  8853.   Result := (StartX<=Integer(Dest.Width)) and (EndX>0) and (EndX-StartX>0) and
  8854.     (StartY<=Integer(Dest.Height)) and (EndY>0) and (EndY-StartY>0);
  8855. end;
  8856.  
  8857. procedure CopyXLineInitialize(const Dest, Src: TDXR_Surface;
  8858.   const Blend: TDXR_Blend; Alpha: Integer;
  8859.   IncX, IncY: Integer;
  8860.   ColorKeyEnable: Boolean; ColorKey: DWORD);
  8861. var
  8862.   Tree: PDXRMachine_Tree;
  8863. begin
  8864.   DXRMachine.Initialize;
  8865.  
  8866.   {  Parameter setting  }
  8867.   DXRMachine.Dest := @Dest;
  8868.   DXRMachine.TextureList[0].ColorKeyEnable := ColorKeyEnable;
  8869.   DXRMachine.TextureList[0].ColorKey := ColorKey;
  8870.   DXRMachine.TextureList[0].Surface := @Src;
  8871.   DXRMachine.TextureList[0].TextureAddress := DXR_TEXTUREADDRESS_DONOTCLIP;
  8872.   DXRMachine.TextureList[0].iAxis.X := IncX;
  8873.   DXRMachine.TextureList[0].iAxis.Y := IncY;
  8874.   DXRMachine.TextureList[0].iAxisConstant := True;
  8875.   DXRMachine.TextureList[0].DefaultColor.R := Alpha*ColorFloat;
  8876.   DXRMachine.TextureList[0].DefaultColor.G := Alpha*ColorFloat;
  8877.   DXRMachine.TextureList[0].DefaultColor.B := Alpha*ColorFloat;
  8878.   DXRMachine.TextureList[0].DefaultColor.A := Alpha*ColorFloat;
  8879.  
  8880.   {  Tree making  }
  8881.   Tree := DXRMachine.CreateTree_Blend(Blend, DXRMachine.CreateTree_LoadTexture(0), DXRMachine.CreateTree2(DXR_TREETYPE_LOADDESTPIXEL));
  8882.  
  8883.   DXRMachine.Compile(Tree);
  8884. end;
  8885.  
  8886. procedure dxrCopyRectBlend(const Dest, Src: TDXR_Surface;
  8887.   const DestRect, SrcRect: TRect; Blend: TDXR_Blend; Alpha: Integer;
  8888.   ColorKeyEnable: Boolean; ColorKey: DWORD);
  8889. var
  8890.   StartX, StartY, EndX, EndY, StartSrcX, StartSrcY: Integer;
  8891.   dy, sx, sy: Integer;
  8892.   IncX, IncY: Integer;
  8893. begin
  8894.   {  Clipping  }
  8895.   if (DestRect.Left>=DestRect.Right) or (DestRect.Top>=DestRect.Bottom) then Exit;
  8896.  
  8897.   if (SrcRect.Left<0) or (SrcRect.Top<0) or
  8898.     (SrcRect.Right>Integer(Src.Width)) or (SrcRect.Bottom>Integer(Src.Height)) or
  8899.     (SrcRect.Left>=SrcRect.Right) or (SrcRect.Top>=SrcRect.Bottom) then Exit;
  8900.  
  8901.   StartX := DestRect.Left;
  8902.   StartY := DestRect.Top;
  8903.   EndX := DestRect.Right;
  8904.   EndY := DestRect.Bottom;
  8905.   StartSrcX := 0;
  8906.   StartSrcY := 0;
  8907.   if not BltClip(Dest, Src, StartX, StartY, EndX, EndY, StartSrcX, StartSrcY) then Exit;
  8908.  
  8909.   IncX := MulDiv64(SrcRect.Right-SrcRect.Left, TextureAxisFloat, DestRect.Right-DestRect.Left);
  8910.   IncY := MulDiv64(SrcRect.Bottom-SrcRect.Top, TextureAxisFloat, DestRect.Bottom-DestRect.Top);
  8911.                                                        
  8912.   sx := StartSrcX * IncX + SrcRect.Left*TextureAxisFloat;
  8913.   sy := StartSrcY * IncY + SrcRect.Top*TextureAxisFloat;
  8914.  
  8915.   if (sx<0) or (sy<0) or ((sx+(EndX-StartX)*IncX) shr 16>Integer(Src.Width)) or
  8916.     ((sy+(EndY-StartY)*IncY) shr 16>Integer(Src.Height)) then Exit;
  8917.  
  8918.   {  Compile  }
  8919.   CopyXLineInitialize(Dest, Src, Blend, Alpha, IncX, 0, ColorKeyEnable, ColorKey);
  8920.  
  8921.   {  Run  }
  8922.   for dy:=StartY to EndY-1 do
  8923.   begin
  8924.     DXRMachine.Axis.Axis.X := StartX;
  8925.     DXRMachine.Axis.Axis.Y := dy;
  8926.     DXRMachine.TextureList[0].nAxis.X := sx;
  8927.     DXRMachine.TextureList[0].nAxis.Y := sy;
  8928.     DXRMachine.Run(EndX-StartX);
  8929.     Inc(sy, IncY);
  8930.   end;
  8931. end;
  8932.  
  8933. procedure dxrFillRectColorBlend(const Dest: TDXR_Surface;
  8934.   const DestRect: TRect; Blend: TDXR_Blend; Col: COLORREF);
  8935. var
  8936.   dy, StartX, StartY, EndX, EndY: Integer;
  8937.   Tree: PDXRMachine_Tree;
  8938. begin
  8939.   {  Clipping  }
  8940.   if (DestRect.Left>=DestRect.Right) or (DestRect.Top>=DestRect.Bottom) then Exit;
  8941.  
  8942.   StartX := DestRect.Left;
  8943.   StartY := DestRect.Top;
  8944.   EndX := DestRect.Right;
  8945.   EndY := DestRect.Bottom;
  8946.   if not FillClip(Dest, StartX, StartY, EndX, EndY) then Exit;
  8947.  
  8948.   {  Compile  }
  8949.   DXRMachine.Initialize;
  8950.   DXRMachine.Dest := @Dest;
  8951.   Tree := DXRMachine.CreateTree_Blend(Blend,
  8952.     DXRMachine.CreateTree_LoadConstColor(Byte(Col), Byte(Col shr 8), Byte(Col shr 16), Byte(Col shr 24)),
  8953.     DXRMachine.CreateTree2(DXR_TREETYPE_LOADDESTPIXEL));
  8954.   DXRMachine.Compile(Tree);    
  8955.    
  8956.   {  Run  }
  8957.   for dy:=StartY to EndY-1 do
  8958.   begin
  8959.     DXRMachine.Axis.Axis.X := StartX;
  8960.     DXRMachine.Axis.Axis.Y := dy;
  8961.     DXRMachine.Run(EndX-StartX);
  8962.   end;
  8963. end;
  8964.  
  8965. procedure dxrDrawWaveXBlend(const Dest, Src: TDXR_Surface;
  8966.   X, Y, Width, Height: Integer; const SrcRect: TRect; amp, Len, ph: Integer;
  8967.   Blend: TDXR_Blend; Alpha: Integer;
  8968.   ColorKeyEnable: Boolean; ColorKey: DWORD);
  8969. var
  8970.   StartX, StartY, EndX, EndY, StartSrcX, StartSrcY: Integer;
  8971.   sx, sy: Integer;
  8972.   dy, IncX, IncY, i, IncPh: Integer;
  8973. begin
  8974.   {  Clipping  }
  8975.   if (Width=0) or (Height=0) then Exit;
  8976.  
  8977.   if (SrcRect.Left<0) or (SrcRect.Top<0) or
  8978.     (SrcRect.Right>Integer(Src.Width)) or (SrcRect.Bottom>Integer(Src.Height)) or
  8979.     (SrcRect.Left>=SrcRect.Right) or (SrcRect.Top>=SrcRect.Bottom) then Exit;
  8980.  
  8981.   StartY := Y;
  8982.   EndY := Y+Height;
  8983.   StartSrcY := 0;
  8984.   if not BltClipY(Dest, Src, StartY, EndY, StartSrcY) then Exit;
  8985.  
  8986.   IncX := MulDiv64(SrcRect.Right-SrcRect.Left, TextureAxisFloat, Width);
  8987.   IncY := MulDiv64(SrcRect.Bottom-SrcRect.Top, TextureAxisFloat, Height);
  8988.  
  8989.   if Len=0 then
  8990.   begin
  8991.     IncPh := 0;
  8992.   end else
  8993.     IncPh := MulDiv64(256, 65536, Len);
  8994.   i := ph*65536+StartSrcY*IncPh;
  8995.              
  8996.   sy := StartSrcY * IncY + SrcRect.Top*TextureAxisFloat;
  8997.  
  8998.   if ((sy+(EndY-StartY)*IncY) shr 16>Integer(Src.Height)) then Exit;
  8999.  
  9000.   {  Compile  }
  9001.   CopyXLineInitialize(Dest, Src, Blend, Alpha, IncX, 0, ColorKeyEnable, ColorKey);
  9002.  
  9003.   {  Run  }
  9004.   for dy:=StartY to EndY-1 do
  9005.   begin
  9006.     {  X clipping  }
  9007.     StartX := X+Round(Sin256(i div 65536)*amp);
  9008.     EndX := StartX+Width;
  9009.     StartSrcX := 0;
  9010.  
  9011.     if BltClipX(Dest, Src, StartX, EndX, StartSrcX) then
  9012.     begin
  9013.       sx := StartSrcX * IncX + SrcRect.Left*TextureAxisFloat;
  9014.       if (sx<0) or (sy<0) or ((sx+(EndX-StartX)*IncX) shr 16>Integer(Src.Width)) then Exit;
  9015.       DXRMachine.Axis.Axis.X := StartX;
  9016.       DXRMachine.Axis.Axis.Y := dy;
  9017.       DXRMachine.TextureList[0].nAxis.X := sx;
  9018.       DXRMachine.TextureList[0].nAxis.Y := sy;
  9019.       DXRMachine.Run(EndX-StartX);
  9020.     end;
  9021.  
  9022.     Inc(i, IncPh);
  9023.     Inc(sy, IncY);
  9024.   end;
  9025. end;
  9026.  
  9027. procedure dxrDrawRotateBlend(const Dest, Src: TDXR_Surface;
  9028.   X, Y, Width, Height: Integer; const SrcRect: TRect; CenterX, CenterY: Double;
  9029.   Angle: Integer; Blend: TDXR_Blend; Alpha: Integer;
  9030.   ColorKeyEnable: Boolean; ColorKey: DWORD);
  9031. var
  9032.   StartX, EndX, StartY, EndY: Integer;
  9033.   dy, sx, sy: Integer;
  9034.   c, s, xIncX, xIncY, yIncX, yIncY: Integer;
  9035.   pSkip, pCount: Integer;
  9036.   gStartX, gStartY: Integer;
  9037. begin
  9038.   {  Clipping  }
  9039.   if (Width=0) or (Height=0) then Exit;
  9040.  
  9041.   if (SrcRect.Left<0) or (SrcRect.Top<0) or
  9042.     (SrcRect.Right>Integer(Src.Width)) or (SrcRect.Bottom>Integer(Src.Height)) or
  9043.     (SrcRect.Left>=SrcRect.Right) or (SrcRect.Top>=SrcRect.Bottom) then Exit;
  9044.  
  9045.   if not RotationClip(Dest, Src, X, Y, Width, Height, CenterX, CenterY, Angle,
  9046.     StartX, StartY, EndX, EndY) then Exit;
  9047.  
  9048.   c := Trunc(Cos256(-Angle)*TextureAxisFloat);
  9049.   s := Trunc(Sin256(-Angle)*TextureAxisFloat);
  9050.  
  9051.   xIncX := MulDiv64(SrcRect.Right-SrcRect.Left, c, Width);
  9052.   xIncY := MulDiv64(SrcRect.Bottom-SrcRect.Top, s, Height);
  9053.  
  9054.   yIncX := MulDiv64(SrcRect.Right-SrcRect.Left, s, Width);
  9055.   yIncY := MulDiv64(SrcRect.Bottom-SrcRect.Top, c, Height);
  9056.  
  9057.   sx := (-X+StartX) * xIncX + (Y-StartY) * yIncX + Trunc((SrcRect.Right-SrcRect.Left)*CenterX*TextureAxisFloat) + SrcRect.Left*TextureAxisFloat;
  9058.   sy := (-X+StartX) * xIncY - (Y-StartY) * yIncY + Trunc((SrcRect.Bottom-SrcRect.Top)*CenterY*TextureAxisFloat) + SrcRect.Top*TextureAxisFloat;
  9059.  
  9060.   {  Compile  }
  9061.   CopyXLineInitialize(Dest, Src, Blend, Alpha, xIncX, xIncY, ColorKeyEnable, ColorKey);
  9062.  
  9063.   {  Run  }
  9064.   for dy := StartY to EndY-1 do
  9065.   begin
  9066.     gStartX := sx;
  9067.     gStartY := sy;
  9068.  
  9069.     {  X clipping  }
  9070.     pSkip := 0;
  9071.     if xIncX>0 then
  9072.     begin
  9073.       if gStartX<SrcRect.Left*TextureAxisFloat then
  9074.         pSkip := (SrcRect.Left*TextureAxisFloat-gStartX+xIncX-1) div xIncX;
  9075.     end else if xIncX<0 then
  9076.     begin
  9077.       if gStartX>=SrcRect.Right*TextureAxisFloat then
  9078.         pSkip := (SrcRect.Right*TextureAxisFloat-gStartX+xIncX) div xIncX;
  9079.     end;
  9080.  
  9081.     if xIncY>0 then
  9082.     begin
  9083.       if gStartY<SrcRect.Top*TextureAxisFloat then
  9084.         pSkip := Max((SrcRect.Top*TextureAxisFloat-gStartY+xIncY-1) div xIncY, pSkip);
  9085.     end else if xIncY<0 then
  9086.     begin
  9087.       if gStartY>=SrcRect.Bottom*TextureAxisFloat then
  9088.         pSkip := Max((SrcRect.Bottom*TextureAxisFloat-gStartY+xIncY) div xIncY, pSkip);
  9089.     end;
  9090.  
  9091.     gStartX := gStartX + pSkip*xIncX;
  9092.     gStartY := gStartY + pSkip*xIncY;
  9093.  
  9094.     {  X clipping  }
  9095.     if xIncX>=0 then
  9096.     begin
  9097.       pCount := (SrcRect.Right*TextureAxisFloat-gStartX) div Max(xIncX, 1);
  9098.     end else
  9099.     begin
  9100.       pCount := (gStartX-SrcRect.Left*TextureAxisFloat) div (-xIncX);
  9101.     end;
  9102.  
  9103.     if xIncY>=0 then
  9104.     begin
  9105.       pCount := Min((SrcRect.Bottom*TextureAxisFloat-gStartY) div Max(xIncY, 1), pCount);
  9106.     end else
  9107.     begin
  9108.       pCount := Min((gStartY-SrcRect.Top*TextureAxisFloat) div (-xIncY), pCount);
  9109.     end;
  9110.  
  9111.     pCount := Min(Integer(Dest.Width)-(StartX+pSkip), pCount);
  9112.  
  9113.     {  Run  }
  9114.     DXRMachine.Axis.Axis.X := StartX + pSkip;
  9115.     DXRMachine.Axis.Axis.Y := dy;
  9116.     DXRMachine.TextureList[0].nAxis.X := gStartX;
  9117.     DXRMachine.TextureList[0].nAxis.Y := gStartY;
  9118.     DXRMachine.Run(pCount);
  9119.  
  9120.     sx := sx - yIncX;
  9121.     sy := sy + yIncY;
  9122.   end;
  9123. end;
  9124.  
  9125. //var TextureSurface, DestSurface: TDXR_Surface; RenderStates: TDXR_RenderStates;
  9126. //
  9127. //dxrDefRenderStates(RenderStates);
  9128. //if dxrDDSurfaceLock(Surf.ISurface, DestSurface then begin
  9129. //  dxrDDSurfaceLock(TextureSurface as IDirectDrawSurface, TextureSurface);
  9130. //  RenderStates.TextureList<0>.Surface:=@TextureSurface;
  9131. //  dxrDrawPrimitive(DestSurface, RenderStates, DXR_PRIMITIVETYPE_TRIANGLELIST, @VertexList, 36);
  9132. //  dxrDDSurfaceUnlock(SurfaceTexture as IDirectDrawSurface, TextureSurface);
  9133. //  dxrDDSurfaceUnlock(Surf.ISurface, DestSurface);
  9134. //end;
  9135.  
  9136. initialization
  9137.   ReadCPUID;
  9138.   Init;
  9139.   InitCosinTable;
  9140.  
  9141.   dxrSetOption(DXR_OPTION_MMXENABLE, 1);
  9142. finalization
  9143.   FDXRMachine.Free;
  9144. end.