Advertisement
Guest User

Untitled

a guest
Feb 9th, 2012
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.         .686P
  3.         .XMM
  4.         .model  flat, stdcall
  5.         option  casemap:none
  6.  
  7. ;//===============================================================================================
  8. ;// Setup
  9. ;//===============================================================================================
  10.  
  11. XRES        equ 1024
  12. YRES        equ 1024
  13.  
  14. DC_ITERATIONS   equ 20
  15.  
  16. LOCALVAR_SPACE  equ 24
  17.  
  18. ;//===============================================================================================
  19. ;// Includes and externs
  20. ;//===============================================================================================
  21.  
  22.         include windows.inc
  23.         include kernel32.inc
  24.                
  25. ;//     extrn   _imp__ExitProcess@4:PROC
  26. ;//     extrn   _imp__DestroyWindow@4:PROC
  27.         extrn   _imp__GetAsyncKeyState@4:PROC
  28.         extrn   _imp__CreateWindowExA@48:PROC
  29.         extrn   Direct3DCreate9@4:PROC
  30. ;//     extrn   D3DXVec2Hermite@24:PROC
  31.  
  32. ;//===============================================================================================
  33. ;// Teh marco definitns
  34. ;//===============================================================================================
  35.  
  36. dcEnd       macro   a
  37.         db  000h
  38.         endm
  39.  
  40. dcRotate        macro   a
  41.         db  020h or ( a and 01fh )
  42.         endm
  43.  
  44. dcIncrease      macro   z
  45.         db  040h or ( a and 01fh )
  46.         endm
  47.  
  48. dcReduce        macro   z
  49.         db  060h or ( a and 01fh )
  50.         endm
  51.  
  52. dcDisplace      macro   x, y
  53.         db  080h or ( x / 4 )
  54.         db  ( ( x and 003h ) * 64 ) or y
  55.         endm
  56.  
  57. dcVertex        macro   x, y
  58.         db  0a0h or ( x / 4 )
  59.         db  ( ( x and 003h ) * 64 ) or y
  60.         endm
  61.  
  62. dcTangent       macro   x, y
  63.         db  0b0h or ( x / 4 )
  64.         db  ( ( x and 003h ) * 64 ) or y
  65.         endm
  66.  
  67. dcARGB      macro   a, r, g, b
  68.         db  0c0h or ( a * 16 ) or r
  69.         db  ( g * 16 ) or b
  70.         endm
  71.  
  72. dcRender        macro
  73.         db  0e0h
  74.         endm
  75.  
  76. dcClearStack    macro
  77.         db  0e1h
  78.         endm
  79.  
  80. dcOutline       macro
  81.         db  0e2h
  82.         endm
  83.  
  84. ;//===============================================================================================
  85. ;// Data
  86. ;//===============================================================================================
  87.  
  88.         public  __fltused
  89.  
  90. _BSS        segment
  91.  
  92. vertexStack dd  10000 * 5 dup ( ? )        
  93. faces       dd  1024 dup ( ? )
  94.  
  95. _BSS        ends
  96.  
  97. _DATA       segment
  98.  
  99. vv:
  100.  
  101. d3dDevice       dd  ?
  102. __fltused       dd  ?
  103.  
  104. currentVertex   dd  ?
  105. renderVertex    dd  ?
  106.  
  107. s0x     dd  ?
  108. s0y     dd  ?
  109. s0z     dd  ?
  110. s0argb      dd  ?
  111. s1x     dd  ?
  112. s1y     dd  ?
  113. s1z     dd  ?
  114. currentCol:
  115. currentColI:
  116. s1argb      dd  ?
  117.  
  118. v0Pre       dd  ?
  119. v0x     dd  ?
  120. v0y     dd  ?
  121. t0x     dd  ?
  122. t0y     dd  ?
  123. currentColID:
  124. v1Pre       dd  ?
  125. v1x     dd  ?
  126. v1y     dd  ?
  127. t1x     dd  ?
  128. t1y     dd  ?
  129.  
  130. scaleProduct    dd  0
  131.  
  132. scaleMatrix dd  0, 0, 0, 0
  133.         dd  0, 0, 0, 0
  134.         dd  0, 0
  135.        
  136.         ;//dd   03f800000h, 0
  137.         ;//dd   0, 0, 0, 03f800000h
  138.  
  139. translateMatrix dd  03f800000h, 0, 0, 0
  140.         dd  0, 03f800000h, 0, 0
  141.         dd  0, 0, 03f800000h, 0
  142.         dd  0, 0, 0, 03f800000h
  143.  
  144. rotateMatrix    dd  0, 0, 0, 0
  145.         dd  0, 0, 0, 0
  146.         dd  0, 0
  147.        
  148.         ;//dd   03f800000h, 0
  149.         ;//dd   0, 0, 0, 03f800000h
  150.  
  151. identityMatrix  dd  03f800000h, 0, 0, 0
  152.         dd  0, 03f800000h, 0, 0
  153.         dd  0, 0, 03f800000h, 0
  154.         dd  0, 0, 0
  155.        
  156.         ;//dd   03f800000h
  157.  
  158. quadVerts       dd  03f800000h              ;// 1
  159.         dd  0bf800000h              ;// -1
  160.         dd  000000000h              ;// 0
  161.         dd  03f800000h              ;// 1
  162.         dd  000000000h              ;// 0
  163.         dd  0bf800000h              ;// -1
  164.         dd  0bf800000h              ;// -1
  165.         dd  000000000h              ;// 0
  166.         dd  000000000h              ;// 0
  167.         dd  000000000h              ;// 0
  168.         dd  03f800000h              ;// 1
  169.         dd  03f800000h              ;// 1
  170.         dd  000000000h              ;// 0
  171.         dd  03f800000h              ;// 1
  172.         dd  03f800000h              ;// 1
  173.         dd  0bf800000h              ;// -1
  174.         dd  03f800000h              ;// 1
  175.         dd  000000000h              ;// 0
  176.         dd  000000000h              ;// 0
  177.         dd  03f800000h              ;// 1
  178.  
  179. devParams       dd  XRES
  180.         dd  YRES
  181.         dd  15h
  182.         dd  0
  183.         dd  0
  184.         dd  0
  185.         dd  1
  186.         dd  0
  187.         dd  1
  188.         dd  0
  189.         dd  0
  190.         dd  0
  191.         dd  0
  192.         dd  1
  193.  
  194. ;// DC data
  195.  
  196. dcData:
  197.  
  198.         dcVertex    0, 0
  199.         dcARGB  0, 15, 15, 15
  200.        
  201.         dcVertex    57, 20
  202.         dcARGB  1, 15, 15, 15
  203.         dcTangent   32, 43
  204.        
  205.         dcVertex    32, 30
  206.         dcARGB  1, 3, 5, 15
  207.         dcTangent   0, 63
  208.  
  209.         dcVertex    0, 0
  210.         dcARGB  0, 15, 0, 15
  211.  
  212.         dcOutline
  213.  
  214.         rept    8
  215.         dcRotate    8
  216.         dcOutline
  217.         endm
  218.  
  219.         dcRender
  220.         dcEnd
  221.  
  222. ;// DC data must be followed by at least 3 readable bytes (read but ignored)
  223.  
  224. ;// Window
  225.  
  226. textStatic      db  "static", 0
  227.  
  228. ;// x86 sucks
  229.  
  230. fpuSave     db  128 dup ( ? )
  231.  
  232. _DATA       ends
  233.  
  234. _TEXT       segment
  235.  
  236. ;//===============================================================================================
  237. ;// Entry point
  238. ;//===============================================================================================
  239.  
  240. Start:
  241.  
  242.         mov ebp, offset vv
  243.  
  244. ;// Create D3D object
  245.  
  246.         push    32
  247.         call    Direct3DCreate9@4
  248.         push    eax                 ;// Save device
  249.  
  250. ;// Create window
  251.  
  252.         push    0
  253.         push    0
  254.         push    0
  255.         push    0
  256.         push    YRES
  257.         push    XRES
  258.         push    0
  259.         push    0
  260.         push    090000000h
  261.         push    0
  262.         push    offset textStatic
  263.         push    0
  264.         call    dword ptr _imp__CreateWindowExA@48
  265.  
  266. ;// Create D3D device
  267.  
  268.         pop esi                 ;// D3D object
  269.  
  270.         push    ebp                 ;// &d3dDevice
  271.         push    offset devParams
  272.         push    00000040h                   ;// D3DCREATE_HARDWARE_VERTEXPROCESSING
  273.         push    eax                 ;// window
  274.         push    1                   ;// D3DDEVTYPE_HAL
  275.         push    0                   ;// D3DADAPTER_DEFAULT = 0
  276.  
  277.         mov dword ptr devParams + 28, eax           ;// window
  278.        
  279.         push    esi
  280.         mov     eax, [ esi ]       
  281.         call    dword ptr [ eax + 64 ]          ;// CreateDevice
  282.  
  283. ;// Set some states
  284.  
  285.         mov esi, dword ptr [ ebp + ( d3dDevice - vv ) ]
  286.  
  287.         push    2                   ;// D3DTEXF_LINEAR
  288.         push    5                   ;// D3DSAMP_MAGFILTER
  289.         push    0
  290.         push    esi
  291.         mov     eax, [ esi ]       
  292.         call    dword ptr [ eax + 276 ]         ;// SetSamplerState
  293.  
  294.         push    2                   ;// D3DTEXF_LINEAR
  295.         push    6                   ;// D3DSAMP_MINFILTER
  296.         push    0
  297.         push    esi
  298.         mov     eax, [ esi ]       
  299.         call    dword ptr [ eax + 276 ]         ;// SetSamplerState
  300.        
  301. ;// Generate textures
  302.    
  303.         mov eax, offset dcData
  304.         mov edx, 1024
  305.         call    renderDC
  306.  
  307.         mov dword ptr [ faces ], ebx
  308.  
  309. ;// Teh main loop
  310.  
  311. waitLoop:
  312.         call    renderFrame
  313.  
  314.         push    27                  ;// VK_ESCAPE
  315.         call    dword ptr _imp__GetAsyncKeyState@4
  316.         test    eax, eax
  317.         je  short waitLoop
  318.  
  319. ;// Release D3D device
  320.        
  321. ;//     mov esi, DWORD PTR [ ebp + ( d3d - vv )  ]
  322. ;//     push    esi
  323. ;//     mov     eax, [ esi ]
  324. ;//     call    dword ptr [ eax + 8 ]               ;// Release
  325.  
  326. ;//     jmp dword ptr _imp__ExitProcess@4
  327.         ret
  328.  
  329. ;//===============================================================================================
  330. ;// Render an frame
  331. ;//===============================================================================================
  332.  
  333. ;// At entry - ebp = vv, eax = 0
  334.  
  335. renderFrame:
  336.    
  337.         mov esi, dword ptr [ ebp + ( d3dDevice - vv ) ]
  338.        
  339.         push    esi
  340.         mov eax, [ esi ]
  341.         call    dword ptr [ eax + 164 ]         ;// BeginScene     
  342.  
  343.         push    0                   ;// For Present
  344.         push    0
  345.         push    0
  346.         push    0
  347.        
  348. ;// Clear frame
  349.  
  350.         push    0
  351.         push    03f800000h
  352.         push    0                   ;// Background col
  353.         push    1                   ;// D3DCLEAR_TARGET
  354.         push    0
  355.         push    0
  356.         push    esi
  357.         mov eax, [ esi ]   
  358.         call    dword ptr [ eax + 172 ]         ;// Clear
  359.  
  360. ;//     mov ebx, offset dcData
  361. ;//     mov edx, 200
  362. ;//     call    dcLocalConstraints
  363.  
  364. ;// Set texture
  365.  
  366.         push    dword ptr [ faces ]
  367.         push    0
  368.         push    esi
  369.         mov eax, dword ptr [ esi ]
  370.         call    dword ptr [ eax + 260 ]         ;// SetTexture
  371.        
  372. ;// Set some states
  373.  
  374.         push    5                   ;// D3DBLEND_SRCALPHA
  375.         push    19                  ;// D3DRS_SRCBLEND
  376.         push    esi
  377.         mov eax, dword ptr [ esi ]
  378.         call    dword ptr [ eax + 228 ]         ;// SetRenderState
  379.  
  380.         push    6                   ;// D3DBLEND_INVSRCALPHA
  381.         push    20                  ;// D3DRS_DESTBLEND
  382.         push    esi
  383.         mov eax, dword ptr [ esi ]
  384.         call    dword ptr [ eax + 228 ]         ;// SetRenderState
  385.  
  386. ;// Draw quad
  387.  
  388.         push    258                 ;// D3DFVF_XYZ | D3DFVF_TEX1
  389.         push    esi
  390.         mov eax, dword ptr [ esi ]
  391.         call    dword ptr [ eax + 356 ]         ;// SetFVF
  392.  
  393.         lea eax, dword ptr [ ebp + ( quadVerts - vv ) ]
  394.         push    20                  ;// Vertex size
  395.         push    eax                 ;// Vertices
  396.         push    2                   ;// No. primitives
  397.         push    5                   ;// D3DPT_TRIANGLESTRIP
  398.         push    esi
  399.         mov eax, dword ptr [ esi ]
  400.         call    dword ptr [ eax + 332 ]         ;// DrawPrimitiveUP
  401.  
  402.  
  403. ;// End scene
  404.  
  405.         push    esi
  406.         mov eax, [ esi ]
  407.         call    dword ptr [ eax + 168 ]         ;// EndScene       
  408.    
  409.         push    esi
  410.         mov eax, [ esi ]
  411.         call    dword ptr [ eax + 68 ]          ;// Present    
  412.    
  413.         ret
  414.  
  415. ;//===============================================================================================
  416. ;// Generate DC texture
  417. ;//
  418. ;// ebp - vv
  419. ;// edx - size
  420. ;// eax - texture code
  421. ;//
  422. ;// Returns texture  in ebx, end of code in eax, texture surface in ecx
  423. ;//===============================================================================================
  424.  
  425. sizeCopy        equ -4
  426. codeCopy        equ -8
  427. currentTexture  equ -12
  428. currentSurface  equ -16
  429. oldSurface      equ -20
  430. lesserSurface   equ -24
  431.  
  432. renderDC:
  433.  
  434.         push    edx                 ;// size
  435.         push    eax                 ;// code, size
  436.  
  437. ;// Create texture
  438.  
  439.         push    eax                 ;// ?, code, size
  440.         mov eax, esp
  441.        
  442.         push    0
  443.         push    eax                 ;// &ctex
  444.         push    0                   ;// D3DPOOL_DEFAULT
  445.         push    21                  ;// D3DFMT_A8R8G8B8
  446.         push    1                   ;// D3DUSAGE_RENDERTARGET = 1
  447.         push    1                   ;// levels = 1
  448.         push    edx                 ;// width
  449.         push    edx                 ;// height
  450.        
  451.         mov esi, dword ptr [ ebp + ( d3dDevice - vv ) ]
  452.         push    esi
  453.         mov eax, [ esi ]
  454.         call    dword ptr [ eax + 92 ]          ;// CreateTexture
  455.  
  456. ;// Save current rendertarget
  457.  
  458.         push    eax                 ;// ?, ctex, code, size
  459.         mov eax, esp
  460.  
  461.         push    eax                 ;// &osurf
  462.         push    0
  463.         push    esi
  464.         mov eax, [ esi ]
  465.         call    dword ptr [ eax + 152 ]         ;// GetRenderTarget
  466.  
  467. ;// Get texture surface
  468.  
  469.         mov esi, [ esp + 4 ]                ;// ctex
  470.  
  471.         push    eax                 ;// ?, osurf, ctex, code, size
  472.         mov eax, esp
  473.  
  474.         push    eax                 ;// &csurf
  475.         push    0
  476.         push    esi
  477.         mov eax, [ esi ]
  478.         call    dword ptr [ eax + 72 ]          ;// GetSurfaceLevel
  479.                                
  480.                                 ;// csurf, osurf, ctex, code, size
  481. ;// Set rendertarget to new texture surface
  482.  
  483.         push    dword ptr [ esp ]               ;// csurf
  484.         push    0          
  485.  
  486.         mov esi, dword ptr [ ebp + ( d3dDevice - vv ) ]
  487.         push    esi
  488.         mov eax, [ esi ]
  489.         call    dword ptr [ eax + 148 ]         ;// SetRenderTarget
  490.  
  491. ;// Recursively refine quarter-size copy
  492.  
  493.         push    0                   ;// (lsurf), csurf, osurf, ctex, code, size
  494.  
  495.         mov edx, [ esp + 20 ]
  496.         shr     edx, 1                  ;// size / 2
  497.         je  short skipRecurse
  498.        
  499.         mov eax, [ esp + 16 ]               ;// code
  500.         call    renderDC
  501.  
  502. ;// renderDC returns texture, get texture surface. If not recursing, lsurf = 0
  503.  
  504.         mov [ esp ], ecx
  505.  
  506. skipRecurse:
  507.  
  508. ;// Solve iteratively for current grid level
  509.  
  510.         mov eax, DC_ITERATIONS
  511. gridLoop:       push    eax
  512.  
  513. ;// Scale lsurf to csurf
  514.  
  515.         cmp dword ptr [ esp + 4 ], 0
  516.         je  skipScale1
  517.  
  518.         push    2                   ;// D3DTEXF_LINEAR
  519.         push    0
  520.         push    dword ptr [ esp + 16 ]          ;// csurf
  521.         push    0
  522.         push    dword ptr [ esp + 20 ]          ;// lsurf
  523.        
  524.         mov esi, dword ptr [ ebp + ( d3dDevice - vv ) ]
  525.         push    esi
  526.         mov eax, [ esi ]
  527.         call    dword ptr [ eax + 136 ]         ;// StretchRect
  528.  
  529. skipScale1:
  530.  
  531. ;// Apply constraints
  532.  
  533.         mov esi, dword ptr [ ebp + ( d3dDevice - vv ) ]
  534.         push    esi
  535.         mov eax, [ esi ]
  536.         call    dword ptr [ eax + 164 ]         ;// BeginScene
  537.        
  538.         mov ebx, [ esp + 20 ]               ;// code
  539.         mov edx, [ esp + 24 ]               ;// size
  540.         call    dcLocalConstraints
  541.  
  542.         mov esi, dword ptr [ ebp + ( d3dDevice - vv ) ]
  543.         push    esi
  544.         mov eax, [ esi ]
  545.         call    dword ptr [ eax + 168 ]         ;// EndScene           
  546.  
  547. ;// Scale csurf to lsurf
  548.  
  549.         cmp dword ptr [ esp + 4 ], 0
  550.         je  skipScale2
  551.  
  552.         push    2                   ;// D3DTEXF_LINEAR
  553.         push    0
  554.         push    dword ptr [ esp + 12 ]          ;// lsurf
  555.         push    0
  556.         push    dword ptr [ esp + 24 ]          ;// csurf
  557.  
  558.         mov esi, dword ptr [ ebp + ( d3dDevice - vv ) ]
  559.         push    esi
  560.         mov eax, [ esi ]
  561.         call    dword ptr [ eax + 136 ]         ;// StretchRect
  562.    
  563. skipScale2:
  564.  
  565. ;// Loop
  566.  
  567.         pop eax
  568.         dec al
  569.         jnz     gridLoop
  570.  
  571. ;// Restore rendertarget                        ;// lsurf, csurf, osurf, ctex, code, size  
  572.  
  573.         push    dword ptr [ esp + 8 ]               ;// osurf
  574.         push    0
  575.        
  576.         mov esi, dword ptr [ ebp + ( d3dDevice - vv ) ]
  577.         push    esi
  578.         mov eax, [ esi ]
  579.         call    dword ptr [ eax + 148 ]         ;// SetRenderTarget
  580.  
  581. ;// Return
  582.  
  583.         mov eax, ebx                    ;// end of code
  584.         pop ecx
  585.         pop ecx                 ;// csurf
  586.         pop ebx                
  587.         pop ebx                 ;// ctex
  588.  
  589.         pop edi
  590.         pop edi
  591.         ret
  592.  
  593. ;//===============================================================================================
  594. ;// Apply DC local constraints
  595. ;//
  596. ;// ebx - texture code
  597. ;// edx - texture size
  598. ;// Target texture must be rendertarget
  599. ;//
  600. ;// Returns end of texture code in ebx
  601. ;//===============================================================================================
  602.  
  603. endCodeLoop:
  604.  
  605.         mov esi, dword ptr [ ebp + ( d3dDevice - vv ) ]
  606.  
  607.         lea eax, dword ptr [ ebp + ( identityMatrix - vv ) ]
  608.         push    eax                 ;// Source matrix
  609.         push    256                 ;// World matrix
  610.         push    esi
  611.         mov eax, [ esi ]
  612.         call    dword ptr [ eax + 176 ]         ;// SetTransform
  613.  
  614.         pop eax
  615.         pop eax
  616.         ret
  617.  
  618. dcLocalConstraints: push    edx
  619.  
  620.         mov esi, dword ptr [ ebp + ( d3dDevice - vv ) ]
  621.  
  622.         push    2                   ;// D3DBLEND_ONE
  623.         push    19                  ;// D3DRS_SRCBLEND
  624.         push    esi
  625.         mov eax, [ esi ]
  626.         call    dword ptr [ eax + 228 ]         ;// SetRenderState
  627.  
  628.         push    1                   ;// D3DBLEND_ZERO
  629.         push    20                  ;// D3DRS_DESTBLEND
  630.         push    esi
  631.         mov eax, [ esi ]
  632.         call    dword ptr [ eax + 228 ]         ;// SetRenderState
  633.  
  634.         push    1
  635.         push    27                  ;// D3DRS_ALPHABLENDENABLE
  636.         push    esi
  637.         mov eax, [ esi ]
  638.         call    dword ptr [ eax + 228 ]         ;// SetRenderState
  639.  
  640.         push    0
  641.         push    137                 ;// D3DRS_LIGHTING
  642.         push    esi
  643.         mov eax, [ esi ]
  644.         call    dword ptr [ eax + 228 ]         ;// SetRenderState
  645.    
  646. ;// Initialise stack and colour
  647.  
  648.         mov dword ptr [ ebp + ( currentVertex - vv ) ], offset vertexStack
  649.         mov dword ptr [ ebp + ( currentCol - vv ) ], 0
  650.  
  651. ;// Keep track of how much we're scaling
  652.  
  653.         mov dword ptr [ ebp + ( scaleProduct - vv ) ], 03f800000h   ;// 1.0f
  654.  
  655. ;// Process code       
  656.  
  657. codeLoop:
  658.         push    codeLoop
  659.  
  660.         finit
  661.  
  662.         mov eax, dword ptr [ ebx ]
  663.         inc     ebx
  664.        
  665.         mov cl, ah
  666.         mov ch, al
  667.        
  668.         sub al, 20h
  669.         jc  endCodeLoop
  670.         sub al, 20h
  671.         jc  opcodeRotate
  672.         sub al, 20h
  673.         jc  opcodeIncrease
  674.         sub al, 20h
  675.         jc  opcodeReduce
  676.         sub     al, 20h
  677.         jc  opcodeDisplace
  678.         sub al, 10h
  679.         jc  opcodeVertex
  680.         sub al, 10h
  681.         jc  opcodeTangent
  682.         sub al, 20h
  683.         jc  opcodeARGB
  684.        
  685. opcodeCommand:
  686.  
  687.         and     al,0fh
  688.         je  commandRender
  689.         dec al
  690.         je  commandClearStack
  691.  
  692. ;//-----------------------------------------------------------------------------------------------
  693. ;// Outline command
  694.  
  695. commandOutline:
  696.  
  697.         push    5
  698.         fild    dword ptr [ esp ]
  699.         pop eax
  700.  
  701.         jmp thickLoop
  702.    
  703. ;//-----------------------------------------------------------------------------------------------
  704. ;// Render command
  705.  
  706. commandRender:
  707.  
  708.         push    2
  709.         fild    dword ptr [ esp ]
  710.         pop eax
  711.  
  712. thickLoop:
  713.  
  714. ;// Beginning of vertex stack
  715.  
  716.         mov esi, offset vertexStack
  717.  
  718. ;// Get initial colour
  719.  
  720.         mov ecx, [ esi ]
  721.         imul    ecx, 17
  722.         mov dword ptr [ ebp + ( currentColI - vv ) ], ecx
  723.  
  724. ;// Get inital x, y, dx, dy
  725.  
  726.         lea edi, dword ptr [ ebp + ( v1Pre - vv ) ]
  727.  
  728.         movsd
  729.         movsd
  730.         movsd
  731.         movsd
  732.         movsd
  733.  
  734.         mov dword ptr [ ebp + ( renderVertex - vv ) ], esi
  735.  
  736. ;// Begin processing segments
  737.  
  738. vertexLoop:
  739.        
  740. ;// Endpoint to beginning
  741.  
  742.         lea esi, dword ptr [ ebp + ( v1Pre - vv ) ]
  743.         lea edi, dword ptr [ ebp + ( v0Pre - vv ) ]
  744.  
  745.         movsd
  746.         movsd
  747.         movsd
  748.         movsd
  749.         movsd
  750.        
  751. ;// Read new vertex and colour delta
  752.  
  753.         mov esi, dword ptr [ ebp + ( renderVertex - vv ) ]
  754.        
  755.         movsd
  756.         movsd
  757.         movsd
  758.         movsd
  759.         movsd
  760.  
  761.         mov dword ptr [ ebp + ( renderVertex - vv ) ], esi
  762.  
  763. ;// Begin subdivision
  764.  
  765.         push    3d70f0eeh                   ;// 1/17
  766.         fld dword ptr [ esp ]
  767.         fldz                        ;// 0
  768.         pop eax
  769.  
  770. subdivideLoop:
  771.  
  772. ;// Save FPU state because DX doesn't, GRR
  773.  
  774.         ;//push eax                 ;// t for hermite spline
  775.         ;//fst  dword ptr [ esp ]
  776.  
  777.         fsave   dword ptr [ ebp + ( fpuSave - vv ) ]
  778.         frstor  dword ptr [ ebp + ( fpuSave - vv ) ]
  779.  
  780. ;// s1 -> s0
  781.  
  782.         lea esi, dword ptr [ ebp + ( s1x - vv ) ]
  783.         lea edi, dword ptr [ ebp + ( s0x - vv ) ]
  784.  
  785.         movsd
  786.         movsd
  787.         movsd
  788.         movsd
  789.        
  790. ;// Hermite interpolation
  791. ;// edi -> s1x
  792.  
  793.         fld1
  794.         fsubp   st(3), st
  795.  
  796.         fld st(0)                   ;// s   --
  797.         fld st(0)                   ;// s   s   --
  798.         fmul    st(0), st(1)                ;// s^2 s   --
  799.         fld st(1)                   ;// s   s^2 s   --
  800.         fmul    st(0), st(1)                ;// s^3 s^2 s   --
  801.  
  802.         fld dword ptr [ edi + ( v0x - s1x ) ]
  803.         fadd    dword ptr [ edi + ( v0x - s1x ) ]
  804.         fadd    dword ptr [ edi + ( t0x - s1x ) ]
  805.         fadd    dword ptr [ edi + ( t1x - s1x ) ]
  806.         fsub    dword ptr [ edi + ( v1x - s1x ) ]
  807.         fsub    dword ptr [ edi + ( v1x - s1x ) ]
  808.         fmulp   st(1), st
  809.        
  810.         fld dword ptr [ edi + ( v1x - s1x ) ]
  811.         fadd    dword ptr [ edi + ( v1x - s1x ) ]
  812.         fadd    dword ptr [ edi + ( v1x - s1x ) ]
  813.         fsub    dword ptr [ edi + ( v0x - s1x ) ]
  814.         fsub    dword ptr [ edi + ( v0x - s1x ) ]
  815.         fsub    dword ptr [ edi + ( v0x - s1x ) ]
  816.         fsub    dword ptr [ edi + ( t0x - s1x ) ]
  817.         fsub    dword ptr [ edi + ( t0x - s1x ) ]
  818.         fsub    dword ptr [ edi + ( t1x - s1x ) ]
  819.         fmulp   st(2), st
  820.  
  821.         fld dword ptr [ edi + ( t0x - s1x ) ]
  822.         fmulp   st(3), st
  823.  
  824.         fld dword ptr [ edi + ( v0x - s1x ) ]
  825.  
  826.         faddp   st(1), st
  827.         faddp   st(1), st
  828.         faddp   st(1), st
  829.         fstp    dword ptr [ edi + ( s1x - s1x ) ]
  830.  
  831.         add edi, 4
  832.  
  833.         fld st(0)                   ;// s   --
  834.         fld st(0)                   ;// s   s   --
  835.         fmul    st(0), st(1)                ;// s^2 s   --
  836.         fld st(1)                   ;// s   s^2 s   --
  837.         fmul    st(0), st(1)                ;// s^3 s^2 s   --
  838.  
  839.         fld dword ptr [ edi + ( v0x - s1x ) ]
  840.         fadd    dword ptr [ edi + ( v0x - s1x ) ]
  841.         fadd    dword ptr [ edi + ( t0x - s1x ) ]
  842.         fadd    dword ptr [ edi + ( t1x - s1x ) ]
  843.         fsub    dword ptr [ edi + ( v1x - s1x ) ]
  844.         fsub    dword ptr [ edi + ( v1x - s1x ) ]
  845.         fmulp   st(1), st
  846.        
  847.         fld dword ptr [ edi + ( v1x - s1x ) ]
  848.         fadd    dword ptr [ edi + ( v1x - s1x ) ]
  849.         fadd    dword ptr [ edi + ( v1x - s1x ) ]
  850.         fsub    dword ptr [ edi + ( v0x - s1x ) ]
  851.         fsub    dword ptr [ edi + ( v0x - s1x ) ]
  852.         fsub    dword ptr [ edi + ( v0x - s1x ) ]
  853.         fsub    dword ptr [ edi + ( t0x - s1x ) ]
  854.         fsub    dword ptr [ edi + ( t0x - s1x ) ]
  855.         fsub    dword ptr [ edi + ( t1x - s1x ) ]
  856.         fmulp   st(2), st
  857.  
  858.         fld dword ptr [ edi + ( t0x - s1x ) ]
  859.         fmulp   st(3), st
  860.  
  861.         fld dword ptr [ edi + ( v0x - s1x ) ]
  862.  
  863.         faddp   st(1), st
  864.         faddp   st(1), st
  865.         faddp   st(1), st
  866.         fstp    dword ptr [ edi + ( s1x - s1x ) ]
  867.  
  868. ;// Clear alpha if outlining
  869.  
  870.         fld1
  871.         fucomi  st(0), st(3)
  872.         jnc noClearAlpha
  873.  
  874.         mov byte ptr [ ebp + ( s1argb - vv + 3 ) ], 0
  875.         mov byte ptr [ ebp + ( currentColID - vv + 3 ) ], 0
  876.  
  877. noClearAlpha:
  878.  
  879.         faddp   st(3), st
  880.  
  881. ;// First run through loop ends here
  882.  
  883.         fucomi  st(0), st(1)
  884.         jc  endSubdivideLoop
  885.    
  886. ;// Save unexpanded s1
  887.  
  888.         push    dword ptr [ edi - 4 ]
  889.         push    dword ptr [ edi ]
  890.         push    edi
  891.  
  892. ;// Expand
  893.  
  894.         fld dword ptr [ edi ]               ;// y1  --
  895.         fld dword ptr [ edi - 4 ]               ;// x1  y1  --
  896.         fld dword ptr [ edi - 16 ]          ;// y0  x1  y1  --
  897.  
  898.         fsubp   st(2), st                   ;// x1  dy  --
  899.  
  900.         fld dword ptr [ edi - 20 ]          ;// x0  x1  dy  --
  901.        
  902.         fsubp   st(1), st                   ;// dx  dy  --
  903.  
  904.         fld st(1)                   ;// dy  dx  dy  --
  905.         fmul    st(0), st(2)                ;// dy*dy   dx  dy  --
  906.         fld st(1)                   ;// dx  dy*dy   dx  dy  --
  907.         fmul    st(0), st(2)                ;// dx*dx   dy*dy   dx  dy  --
  908.  
  909.         faddp   st(1), st                   ;// len dx  dy  --
  910.         fsqrt
  911.  
  912.         fimul   dword ptr [ esp + 16 ]
  913.         fdiv    st(0), st(5)                ;// scale
  914.         fmul    dword ptr [ ebp + ( scaleProduct - vv ) ]
  915.  
  916.                                 ;// slen    dx  dy  --
  917.         fld st(0)                   ;// slen    slen    dx  dy  --
  918.         fdivp   st(2), st                   ;// slen    ndx dy  --
  919.         fdivp   st(2), st                   ;// ndx ndy --
  920.  
  921.         fld st(1)
  922.         fld st(1)                   ;// dx  dy  dx  dy  --
  923.         fsubp   st(3), st                   ;// dy  dx  dy-dx   --
  924.         faddp   st(1), st                   ;// dx+dy   dy-dx   --
  925.  
  926.         fld dword ptr [ edi ]
  927.         fadd    st(0), st(2)
  928.         fstp    dword ptr [ edi ]
  929.        
  930.         sub edi, 4
  931.  
  932.         fld dword ptr [ edi ]
  933.         fadd    st(0), st(1)
  934.         fstp    dword ptr [ edi ]
  935.        
  936.         sub edi, 12
  937.  
  938.         fld dword ptr [ edi ]
  939.         fsub    st(0), st(1)
  940.         fstp    dword ptr [ edi ]
  941.  
  942.         sub edi, 4
  943.  
  944.         fld dword ptr [ edi ]
  945.         fadd    st(0), st(2)
  946.         fstp    dword ptr [ edi ]
  947.  
  948. ;// Render
  949.  
  950.         mov esi, dword ptr [ ebp + ( d3dDevice - vv ) ]
  951.        
  952.         push    66                  ;// D3DFVF_XYZ | D3DFVF_DIFFUSE
  953.  
  954.         push    esi
  955.         mov eax, [ esi ]
  956.         call    dword ptr [ eax + 356 ]         ;// SetFVF
  957.  
  958.         push    16                  ;// Vertex size
  959.         lea eax, dword ptr [ ebp + ( s0x - vv ) ]       ;// s0
  960.         push    eax
  961.         push    1                   ;// No. primitives
  962.         push    2                   ;// D3DPT_LINELIST
  963.        
  964.         push    esi
  965.         mov eax, [ esi ]
  966.         call    dword ptr [ eax + 332 ]         ;// DrawPrimitiveUP
  967.  
  968. ;// Restore FPU state
  969.  
  970.         frstor  dword ptr [ ebp + ( fpuSave - vv ) ]
  971.  
  972. ;// Restore unexpanded s1
  973.  
  974.         pop edi
  975.         pop dword ptr [ edi ]
  976.         pop dword ptr [ edi - 4 ]
  977.  
  978. ;// Interpolate colour
  979.    
  980.         lea esi, dword ptr [ ebp + ( currentColID - vv ) ]
  981.  
  982.         mov al, [ esi ]
  983.         add [ esi + ( currentColI - currentColID ) ], al
  984.         inc esi
  985.         mov al, [ esi ]
  986.         add [ esi + ( currentColI - currentColID ) ], al
  987.         inc esi
  988.         mov al, [ esi ]
  989.         add [ esi + ( currentColI - currentColID ) ], al
  990.         inc esi
  991.         mov al, [ esi ]
  992.         add [ esi + ( currentColI - currentColID ) ], al
  993.         inc esi
  994.        
  995.        
  996. ;// End subdivision loop
  997.  
  998. endSubdivideLoop:
  999.        
  1000.         fadd    st(0), st(1)
  1001.         fld1
  1002.         fucomip st(0), st(1)
  1003.         jnc subdivideLoop
  1004.  
  1005. ;// End vertex loop
  1006.  
  1007.         fucomip st(0), st(1)
  1008.         fucomip st(0), st(1)
  1009.  
  1010.         mov eax, dword ptr [ ebp + ( renderVertex - vv ) ]
  1011.         cmp eax, dword ptr [ ebp + ( currentVertex - vv ) ]
  1012.         jne vertexLoop
  1013.  
  1014.         fldlg2 
  1015.         fsubp   st(1), st
  1016.         fldz   
  1017.         fucomip st(0), st(1)
  1018.         jc  thickLoop
  1019.  
  1020.         ret
  1021.  
  1022. ;//-----------------------------------------------------------------------------------------------
  1023. ;// Clear stack command
  1024.  
  1025. commandClearStack:
  1026.        
  1027.         mov dword ptr [ ebp + ( currentVertex - vv ) ], offset vertexStack
  1028.         mov dword ptr [ ebp + ( currentCol - vv ) ], 0
  1029.  
  1030.         ret
  1031.  
  1032. ;//-----------------------------------------------------------------------------------------------
  1033. ;// Vertex or tangent command
  1034.  
  1035. opcodeTangent:
  1036.         inc ebx
  1037.  
  1038.         mov eax, ecx
  1039.         shr eax, 6
  1040.         and eax, 03fh
  1041.         and ecx, 03fh
  1042.  
  1043.         sub eax, 32
  1044.         sub ecx, 32
  1045.  
  1046.         push    ecx
  1047.         fild    dword ptr [ esp ]
  1048.         push    20
  1049.         fidiv   dword ptr [ esp ]      
  1050.  
  1051.         push    eax
  1052.         fild    dword ptr [ esp ]
  1053.         push    20
  1054.         fidiv   dword ptr [ esp ]
  1055.        
  1056.         pop eax
  1057.         pop eax
  1058.         pop eax
  1059.         pop eax
  1060.  
  1061.         mov esi, dword ptr [ ebp + ( currentVertex - vv ) ]
  1062.         sub esi, 8
  1063.  
  1064.         fstp    dword ptr [ esi ]
  1065.         add esi, 4
  1066.         fstp    dword ptr [ esi ]
  1067.         add esi, 4
  1068.                
  1069.         ret
  1070.        
  1071. opcodeVertex:
  1072.         inc ebx
  1073.  
  1074.         mov eax, ecx
  1075.         shr eax, 6
  1076.         and eax, 03fh
  1077.         and ecx, 03fh
  1078.  
  1079.         push    ecx
  1080.         fild    dword ptr [ esp ]
  1081.         push    63
  1082.         fidiv   dword ptr [ esp ]      
  1083.  
  1084.         push    eax
  1085.         fild    dword ptr [ esp ]
  1086.         push    63
  1087.         fidiv   dword ptr [ esp ]
  1088.        
  1089.         pop eax
  1090.         pop eax
  1091.         pop eax
  1092.         pop eax
  1093.  
  1094.         mov esi, dword ptr [ ebp + ( currentVertex - vv ) ]
  1095.         mov dword ptr [ esi ], 0
  1096.         add esi, 4
  1097.         fstp    dword ptr [ esi ]
  1098.         add esi, 4
  1099.         fstp    dword ptr [ esi ]
  1100.         add esi, 4
  1101.         mov dword ptr [ esi ], 0
  1102.         add esi, 4
  1103.         mov dword ptr [ esi ], 0
  1104.         add esi, 4
  1105.         mov dword ptr [ ebp + ( currentVertex - vv ) ], esi
  1106.  
  1107.         ret
  1108.  
  1109. ;//-----------------------------------------------------------------------------------------------
  1110. ;// Displace command
  1111.  
  1112. opcodeDisplace: inc ebx
  1113.  
  1114.         mov eax, ecx
  1115.         shr eax, 6
  1116.         and eax, 03fh
  1117.         and ecx, 03fh
  1118.  
  1119.         sub eax, 32
  1120.         sub ecx, 32
  1121.  
  1122.         push    ecx
  1123.         fild    dword ptr [ esp ]
  1124.         push    63
  1125.         fidiv   dword ptr [ esp ]      
  1126.  
  1127.         push    eax
  1128.         fild    dword ptr [ esp ]
  1129.         push    63
  1130.         fidiv   dword ptr [ esp ]
  1131.        
  1132.         pop eax
  1133.         pop eax
  1134.         pop eax
  1135.         pop eax
  1136.  
  1137.         lea esi, dword ptr [ ebp + ( translateMatrix - vv ) ]
  1138.  
  1139.         fstp    dword ptr [ esi + ( 12 * 4 ) ]
  1140.         fstp    dword ptr [ esi + ( 13 * 4 ) ]
  1141.        
  1142.         push    esi                 ;// Source matrix
  1143.         push    256                 ;// World matrix
  1144.  
  1145.         mov esi, dword ptr [ ebp + ( d3dDevice - vv ) ]
  1146.         push    esi
  1147.         mov eax, [ esi ]
  1148.         call    dword ptr [ eax + 184 ]         ;// MultiplyTransform
  1149.  
  1150.         ret
  1151.  
  1152. ;//-----------------------------------------------------------------------------------------------
  1153. ;// Reduce command
  1154.  
  1155. opcodeReduce:
  1156.  
  1157.         and eax, 1fh
  1158.         push    eax
  1159.         fild    dword ptr [ esp ]
  1160.         push    31
  1161.         fidiv   dword ptr [ esp ]
  1162.         fld1
  1163.         fsubrp  st(1), st
  1164.  
  1165.         pop eax
  1166.         pop eax
  1167.  
  1168.         lea esi, dword ptr [ ebp + ( scaleProduct - vv ) ]
  1169.  
  1170.         fld st(0)
  1171.         fmul    dword ptr [ esi ]
  1172.         fstp    dword ptr [ esi ]
  1173.         add esi, 4
  1174.  
  1175.         fst dword ptr [ esi + ( 0 * 4 ) ]
  1176.         fstp    dword ptr [ esi + ( 5 * 4 ) ]
  1177.        
  1178.         push    esi                 ;// Source matrix
  1179.         push    256                 ;// World matrix
  1180.  
  1181.         mov esi, dword ptr [ ebp + ( d3dDevice - vv ) ]
  1182.         push    esi
  1183.         mov eax, [ esi ]
  1184.         call    dword ptr [ eax + 184 ]         ;// MultiplyTransform
  1185.  
  1186.         ret
  1187.  
  1188. ;//-----------------------------------------------------------------------------------------------
  1189. ;// Increase command
  1190.  
  1191. opcodeIncrease:
  1192.  
  1193.         and eax, 1fh
  1194.         push    eax
  1195.         fild    dword ptr [ esp ]
  1196.         push    31
  1197.         fidiv   dword ptr [ esp ]
  1198.         fld1
  1199.         fadd    st(0), st(1)
  1200.  
  1201.         pop eax
  1202.         pop eax
  1203.  
  1204.         lea esi, dword ptr [ ebp + ( scaleProduct - vv ) ]
  1205.  
  1206.         fld st(0)
  1207.         fmul    dword ptr [ esi ]
  1208.         fstp    dword ptr [ esi ]
  1209.         add esi, 4
  1210.  
  1211.         fst dword ptr [ esi + ( 0 * 4 ) ]
  1212.         fstp    dword ptr [ esi + ( 5 * 4 ) ]
  1213.  
  1214.         push    esi                 ;// Source matrix
  1215.         push    256                 ;// World matrix
  1216.  
  1217.         mov esi, dword ptr [ ebp + ( d3dDevice - vv ) ]
  1218.         push    esi
  1219.         mov eax, [ esi ]
  1220.         call    dword ptr [ eax + 184 ]         ;// MultiplyTransform
  1221.  
  1222.         ret
  1223.  
  1224. ;//-----------------------------------------------------------------------------------------------
  1225. ;// Rotate command
  1226.  
  1227. opcodeRotate:
  1228.        
  1229.         push    edx
  1230.  
  1231.         and eax, 1fh
  1232.         push    eax
  1233.         fild    dword ptr [ esp ]
  1234.         push    3dc90fdbh
  1235.         fld dword ptr [ esp ]
  1236.         fmul    st(0), st(1)
  1237.         fsincos
  1238.  
  1239.         pop eax
  1240.         pop eax
  1241.  
  1242.         lea esi, dword ptr [ ebp + ( rotateMatrix - vv ) ]
  1243.  
  1244.         fst dword ptr [ esi + ( 0 * 4 ) ]
  1245.         fstp    dword ptr [ esi + ( 5 * 4 ) ]
  1246.         fst dword ptr [ esi + ( 1 * 4 ) ]
  1247.         fchs   
  1248.         fstp    dword ptr [ esi + ( 4 * 4 ) ]
  1249.  
  1250.         push    esi                 ;// Source matrix
  1251.         push    256                 ;// World matrix
  1252.  
  1253.         mov esi, dword ptr [ ebp + ( d3dDevice - vv ) ]
  1254.         push    esi
  1255.         mov eax, [ esi ]
  1256.         call    dword ptr [ eax + 184 ]         ;// MultiplyTransform
  1257.  
  1258.         pop edx
  1259.  
  1260.         ret
  1261.  
  1262. ;//-----------------------------------------------------------------------------------------------
  1263. ;// ARGB command
  1264. ;//t1 = agrb << 12;// t2 = argb | t1;// t2 = t2 << 4;// t2 = t2 & 0xf0f0f0f0;//
  1265.        
  1266. opcodeARGB: inc ebx
  1267.  
  1268.         lea esi, dword ptr [ ebp + ( currentCol - vv ) ]
  1269.  
  1270.         mov al, cl
  1271.         and al, 0fh
  1272.         sub al, byte ptr [ esi ]
  1273.         add byte ptr [ esi ], al
  1274.         inc esi
  1275.         ror eax, 8
  1276.  
  1277.         shr ecx, 4
  1278.  
  1279.         mov al, cl
  1280.         and al, 0fh
  1281.         sub al, byte ptr [ esi ]
  1282.         add byte ptr [ esi ], al
  1283.         inc esi
  1284.         ror eax, 8
  1285.  
  1286.         shr ecx, 4
  1287.  
  1288.         mov al, cl
  1289.         and al, 0fh
  1290.         sub al, byte ptr [ esi ]
  1291.         add byte ptr [ esi ], al
  1292.         inc esi
  1293.         ror eax, 8
  1294.  
  1295.         shr ecx, 4
  1296.  
  1297.         mov al, cl
  1298.         and al, 1
  1299.         neg al
  1300.         and al, 0fh
  1301.         sub al, byte ptr [ esi ]
  1302.         add byte ptr [ esi ], al
  1303.         inc esi
  1304.         ror eax, 8
  1305.  
  1306.         mov esi, dword ptr [ ebp + ( currentVertex - vv ) ]
  1307.         mov dword ptr [ esi - 20 ], eax
  1308.    
  1309.         ret
  1310.  
  1311. End Start
  1312.  
  1313. _TEXT       ends
  1314.  
  1315. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement