home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Codigo / hh / rsource.exe / Hexen Source / LINEAR.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-07-27  |  6.4 KB  |  350 lines

  1.     .386
  2.     .MODEL  small
  3.     INCLUDE defs.inc
  4.  
  5.  
  6. ;============================================================================
  7. ;
  8. ; unwound vertical scaling code
  9. ;
  10. ; eax   light table pointer, 0 lowbyte overwritten
  11. ; ebx   all 0, low byte overwritten
  12. ; ecx   fractional step value
  13. ; edx   fractional scale value
  14. ; esi   start of source pixels
  15. ; edi   bottom pixel in screenbuffer to blit into
  16. ;
  17. ; ebx should be set to 0 0 0 dh to feed the pipeline
  18. ;
  19. ; The graphics wrap vertically at 128 pixels
  20. ;============================================================================
  21.  
  22. .DATA
  23.  
  24. EXTRN    _centery:DWORD
  25.  
  26. SCALEDEFINE     MACRO   number
  27.     dd      vscale&number
  28. ENDM
  29.  
  30.     ALIGN   4
  31. scalecalls      LABEL
  32. LINE    =       0
  33. REPT    SCREENHEIGHT+1
  34.     SCALEDEFINE     %LINE
  35. LINE    =       LINE+1
  36. ENDM
  37.  
  38. FUZZSCALEDEFINE     MACRO   number
  39.     dd      fuzzvscale&number
  40. ENDM
  41.  
  42.     ALIGN   4
  43. fuzzscalecalls      LABEL
  44. LINE    =       0
  45. REPT    SCREENHEIGHT+1
  46.     FUZZSCALEDEFINE     %LINE
  47. LINE    =       LINE+1
  48. ENDM
  49.  
  50. calladdr    dd    ?
  51.  
  52. ;=================================
  53.  
  54.  
  55. .CODE
  56.  
  57. ;================
  58. ;
  59. ; R_DrawColumn
  60. ;
  61. ;================
  62.  
  63. PROC   R_DrawColumn_
  64. PUBLIC   R_DrawColumn_
  65.     PUSHR
  66.  
  67.     mov        ebp,[_dc_yh]
  68.     mov        ebx,ebp
  69.     mov     edi,[_ylookup+ebx*4]
  70.     mov        ebx,[_dc_x]
  71.     add     edi,[_columnofs + ebx*4]
  72.  
  73.     mov        eax,[_dc_yl]
  74.     sub     ebp,eax                    ; ebp = pixel count
  75.     or        ebp,ebp
  76.     js        done
  77.  
  78.     mov     ecx,[_dc_iscale]
  79.  
  80.     sub        eax,[_centery]
  81.     imul    ecx
  82.     mov        edx,[_dc_texturemid]
  83.     add        edx,eax
  84.     shl        edx,9                            ; 7 significant bits, 25 frac
  85.  
  86.     shl        ecx,9                            ; 7 significant bits, 25 frac
  87.     mov     esi,[_dc_source]
  88.  
  89.     mov     eax,[_dc_colormap]
  90.  
  91.     xor     ebx,ebx
  92.     shld    ebx,edx,7                        ; get address of first location
  93.     call    [scalecalls+4+ebp*4]
  94.  
  95. done:
  96.     POPR
  97.     ret
  98.  
  99. ;============ HIGH DETAIL ============
  100.  
  101. SCALELABEL      MACRO   number
  102. vscale&number:
  103. ENDM
  104.  
  105. LINE    =       SCREENHEIGHT
  106. REPT SCREENHEIGHT-1
  107.     SCALELABEL      %LINE
  108.     mov     al,[esi+ebx]                    ; get source pixel
  109.     add     edx,ecx                         ; calculate next location
  110.     mov     al,[eax]                        ; translate the color
  111. ;    xor             ebx,ebx
  112. ;    shld    ebx,edx,7                      ; get address of next location
  113.     mov        ebx,edx
  114.     shr        ebx,25
  115.     mov     [edi-(LINE-1)*SCREENWIDTH],al   ; draw a pixel to the buffer
  116. LINE    =       LINE-1
  117. ENDM
  118. vscale1:
  119.     mov     al,[esi+ebx]
  120.     mov     al,[eax]
  121.     mov     [edi],al
  122. vscale0:
  123.     ret
  124.  
  125. ENDP
  126.  
  127.  
  128. ;================
  129. ;
  130. ; R_DrawFuzz
  131. ;
  132. ;================
  133.  
  134. PROC   R_DrawFuzzColumn_
  135. PUBLIC   R_DrawFuzzColumn_
  136.     PUSHR
  137.  
  138.     mov    ebp,[_dc_yh]
  139.     mov    ebx,ebp
  140.     mov     edi,[_ylookup+ebx*4]
  141.     mov    ebx,[_dc_x]
  142.     add     edi,[_columnofs + ebx*4]
  143.  
  144.     mov    eax,[_dc_yl]
  145.     sub     ebp,eax                    ; ebp = pixel count
  146.     or    ebp,ebp
  147.     js    fuzzdone
  148.  
  149.     mov     ecx,[_dc_iscale]
  150.  
  151.     sub    eax,[_centery]
  152.     imul    ecx
  153.     mov    edx,[_dc_texturemid]
  154.     add    edx,eax
  155.     shl    edx,9  ; 7 significant bits, 25 frac
  156.  
  157.     shl    ecx,9  ; 7 significant bits, 25 frac
  158.     mov     esi,[_dc_source]
  159.     mov     eax,[_dc_colormap]
  160.     xor     ebx,ebx
  161.     shld    ebx,edx,7    ;get address of first location
  162.  
  163.     mov    ebp, [fuzzscalecalls+4+ebp*4]
  164.     mov    calladdr, ebp
  165.     mov    ebp, ecx
  166.     xor    ecx, ecx
  167.  
  168.     call     [calladdr]
  169.  
  170. fuzzdone:
  171.     POPR
  172.     ret
  173.  
  174.  
  175. FUZZSCALELABEL      MACRO   number
  176. fuzzvscale&number:
  177. ENDM
  178.  
  179. LINE    =       SCREENHEIGHT
  180. REPT SCREENHEIGHT-1
  181.     FUZZSCALELABEL      %LINE
  182.     mov     al, byte ptr [esi+ebx]    ; get source pixel
  183.     add     edx, ebp                         ; calculate next location
  184.  
  185.     mov    cl, byte ptr [edi-(LINE-1)*SCREENWIDTH]
  186.     mov     ch, [eax]
  187.     add    ecx, [_tinttable]
  188.     mov    ebx, edx
  189.     shr    ebx, 25
  190.     mov    al, [ecx]
  191.     mov     [edi-(LINE-1)*SCREENWIDTH],al   ; draw a pixel to the buffer
  192.     xor    ecx, ecx
  193. LINE    =       LINE-1
  194. ENDM
  195. fuzzvscale1:
  196.     mov     al,[esi+ebx]
  197.     mov    cl, byte ptr [edi-(LINE-1)*SCREENWIDTH]
  198.     mov     ch, [eax]
  199.     add    ecx, [_tinttable]
  200.     mov    al, [ecx]
  201.     mov     [edi],al
  202. fuzzvscale0:
  203.     ret
  204.  
  205. ENDP
  206.  
  207. ;============================================================================
  208. ;
  209. ; unwound horizontal texture mapping code
  210. ;
  211. ; eax   lighttable
  212. ; ebx   scratch register
  213. ; ecx   position 6.10 bits x, 6.10 bits y
  214. ; edx   step 6.10 bits x, 6.10 bits y
  215. ; esi   start of block
  216. ; edi   dest
  217. ; ebp   fff to mask bx
  218. ;
  219. ; ebp should by preset from ebx / ecx before calling
  220. ;============================================================================
  221.  
  222. OP_SHLD    =    0fh
  223.  
  224.  
  225. .DATA
  226.  
  227.  
  228. MAPDEFINE     MACRO   number
  229.     dd      hmap&number
  230. ENDM
  231.  
  232.     ALIGN   4
  233. mapcalls      LABEL
  234. LINE    =       0
  235. REPT    SCREENWIDTH+1
  236.     MAPDEFINE     %LINE
  237. LINE    =       LINE+1
  238. ENDM
  239.  
  240.  
  241. callpoint    dd  0
  242. returnpoint    dd    0
  243.  
  244.  
  245. .CODE
  246.  
  247. ;================
  248. ;
  249. ; R_DrawSpan
  250. ;
  251. ; Horizontal texture mapping
  252. ;
  253. ;================
  254.  
  255.  
  256. PROC   R_DrawSpan_
  257. PUBLIC    R_DrawSpan_
  258.     PUSHR
  259.  
  260. IFE SKIPPRIMITIVES
  261.  
  262.     mov    eax,[_ds_x1]
  263.     mov    ebx,[_ds_x2]
  264.     mov    eax,[mapcalls+eax*4]
  265.     mov    [callpoint],eax       ; spot to jump into unwound
  266.     mov    eax,[mapcalls+4+ebx*4]
  267.     mov    [returnpoint],eax     ; spot to patch a ret at
  268.     mov    BYTE PTR [eax], OP_RET
  269.  
  270. ;
  271. ; build composite position
  272. ;
  273.     mov    ecx,[_ds_xfrac]
  274.     shl    ecx,10
  275.     and    ecx,0ffff0000h
  276.     mov    eax,[_ds_yfrac]
  277.     shr    eax,6
  278.     and    eax,0ffffh
  279.     or    ecx,eax
  280.  
  281. ;
  282. ; build composite step
  283. ;
  284.     mov    edx,[_ds_xstep]
  285.     shl    edx,10
  286.     and    edx,0ffff0000h
  287.     mov    eax,[_ds_ystep]
  288.     shr    eax,6
  289.     and    eax,0ffffh
  290.     or    edx,eax
  291.  
  292.     mov    esi,[_ds_source]
  293.  
  294.     mov    edi,[_ds_y]
  295.     mov    edi,[_ylookup+edi*4]
  296.     add edi,[_columnofs]
  297.  
  298.     mov    eax,[_ds_colormap]
  299.  
  300. ;
  301. ; feed the pipeline and jump in
  302. ;
  303.     mov        ebp,0fffh        ; used to mask off slop high bits from position
  304.     shld    ebx,ecx,22                ; shift y units in
  305.     shld    ebx,ecx,6                ; shift x units in
  306.     and        ebx,ebp                    ; mask off slop bits
  307.     call    [callpoint]
  308.  
  309.     mov    ebx,[returnpoint]
  310.     mov    BYTE PTR [ebx],OP_MOVAL        ; remove the ret patched in
  311.  
  312. ENDIF
  313.     POPR
  314.     ret
  315.  
  316.  
  317. ;============= HIGH DETAIL ============
  318.  
  319. .CODE
  320.  
  321. MAPLABEL      MACRO   number
  322. hmap&number:
  323. ENDM
  324.  
  325. LINE    =      0
  326. PCOL    =    0
  327. REPT SCREENWIDTH/4
  328. PLANE    =    0
  329. REPT    4
  330.     MAPLABEL      %LINE
  331. LINE    =    LINE + 1
  332.  
  333.     mov     al,[esi+ebx]            ; get source pixel
  334.     shld    ebx,ecx,22                ; shift y units in
  335.     shld    ebx,ecx,6                ; shift x units in
  336.     mov     al,[eax]                ; translate color
  337.     and    ebx,ebp                    ; mask off slop bits
  338.     add    ecx,edx                    ; position += step
  339.     mov     [edi+PLANE+PCOL*4],al       ; write pixel
  340. PLANE    =    PLANE + 1
  341. ENDM
  342. PCOL    =    PCOL + 1
  343. ENDM
  344. hmap320:
  345.     ret
  346.  
  347. ENDP
  348.  
  349. END
  350.