home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / DELPHIX.ZIP / Source / DXRender.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-06  |  277.2 KB  |  8,787 lines

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