home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / texmap / tmap_kl.asm < prev    next >
Assembly Source File  |  1998-06-08  |  7KB  |  308 lines

  1. ;THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  2. ;SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  3. ;END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  4. ;ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  5. ;IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  6. ;SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  7. ;FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  8. ;CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  9. ;AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  10. ;COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  11. ;
  12. ; $Source: f:/miner/source/texmap/rcs/tmap_kl.asm $
  13. ; $Revision: 1.3 $
  14. ; $Author: mike $
  15. ; $Date: 1994/11/30 00:56:50 $
  16. ;
  17. ; Linear, lighted texture mapper inner loop with a constant lighting value.
  18. ;
  19. ; $Log: tmap_kl.asm $
  20. ; Revision 1.3  1994/11/30  00:56:50  mike
  21. ; optimization.
  22. ; Revision 1.2  1994/11/12  16:39:38  mike
  23. ; jae to ja.
  24. ; Revision 1.1  1994/05/10  09:37:52  mike
  25. ; Initial revision
  26. ; Revision 1.1  1993/09/08  17:29:52  mike
  27. ; Initial revision
  28. ;
  29. ;
  30.  
  31.     .386
  32.  
  33.     public    asm_tmap_scanline_lin_lighted_k_
  34.  
  35.     include    tmap_inc.asm
  36.  
  37. _DATA    SEGMENT DWORD PUBLIC USE32 'DATA'
  38.  
  39.     extrn    _fx_l:dword
  40. ;**    extrn    _fx_dl_dx:dword
  41.     extrn    _dither_intensity_lighting:dword
  42.  
  43.     extrn    _fx_u:dword
  44.     extrn    _fx_v:dword
  45.     extrn    _fx_du_dx:dword
  46.     extrn    _fx_dv_dx:dword
  47.     extrn    _fx_y:dword
  48.     extrn    _fx_xleft:dword
  49.     extrn    _fx_xright:dword
  50.  
  51.     extrn    _pixptr:dword
  52.  
  53.     extrn    _x:dword
  54.     extrn    _loop_count:dword
  55.  
  56.     extern    _pixel_data_selector:word, _gr_fade_table_selector:word
  57.  
  58. _DATA    ENDS
  59.  
  60. DGROUP    GROUP    _DATA
  61.  
  62. _TEXT   SEGMENT PARA PUBLIC USE32 'CODE'
  63.  
  64.     ASSUME    DS:_DATA
  65.     ASSUME    CS:_TEXT
  66.  
  67. ; --------------------------------------------------------------------------------------------------
  68. ; Enter:
  69. ;    _xleft    fixed point left x coordinate
  70. ;    _xright    fixed point right x coordinate
  71. ;    _y    fixed point y coordinate
  72. ;    _pixptr    address of source pixel map
  73. ;    _u    fixed point initial u coordinate
  74. ;    _v    fixed point initial v coordinate
  75. ;    _du_dx    fixed point du/dx
  76. ;    _dv_dx    fixed point dv/dx
  77.  
  78. ;   for (x = (int) xleft; x <= (int) xright; x++) {
  79. ;      _setcolor(read_pixel_from_tmap(srcb,((int) (u/z)) & 63,((int) (v/z)) & 63));
  80. ;      _setpixel(x,y);
  81. ;
  82. ;      u += du_dx;
  83. ;      v += dv_dx;
  84. ;      z += dz_dx;
  85. ;   }
  86.  
  87.     align    4
  88. asm_tmap_scanline_lin_lighted_k_:
  89.     push    es
  90.     push    fs
  91.     pusha
  92.  
  93.     mov    es,_pixel_data_selector    ; selector[0*2]
  94.     mov    fs,_gr_fade_table_selector    ; selector[1*2]    ; fs = bmd_fade_table
  95.  
  96. ; Setup for loop:    _loop_count  iterations = (int) xright - (int) xleft
  97. ;   esi    source pixel pointer = pixptr
  98. ;   edi    initial row pointer = y*320+x
  99.  
  100. ; set esi = pointer to start of texture map data
  101.     mov    esi,_pixptr
  102.  
  103. ; set edi = address of first pixel to modify
  104.     mov    edi,_fx_y    ; this is actually an int
  105.     cmp    edi,_window_bottom
  106.     ja    _none_to_do
  107.  
  108.     imul    edi,_bytes_per_row
  109.     mov    ebx,_fx_xleft
  110.     sar    ebx,16
  111.     jns    ebx_ok
  112.     sub    ebx,ebx
  113. ebx_ok:
  114.     add    edi,ebx
  115.     add    edi,write_buffer
  116.  
  117. ; set _loop_count = # of iterations
  118.     mov    eax,_fx_xright
  119.     sar    eax,16
  120.     cmp    eax,_window_right
  121.     jl    eax_ok1
  122.     mov    eax,_window_right
  123. eax_ok1:    cmp    eax,_window_left
  124.     jg    eax_ok2
  125.     mov    eax,_window_left
  126. eax_ok2:
  127.  
  128.     sub    eax,ebx
  129.     js    _none_to_do
  130.     cmp    eax,_window_width
  131.     jbe    _ok_to_do
  132.     mov    eax,_window_width
  133. _ok_to_do:
  134.     mov    _loop_count,eax
  135.  
  136. ;    edi    destination pixel pointer
  137.  
  138.  
  139.     mov    ecx,offset _lighting_tables
  140.     mov    eax,_fx_u    ; get 32 bit u coordinate
  141.     shr    eax,6    ; get 6:10 int:frac u coordinate into low word
  142.     mov    ebp,_fx_v    ; get 32 bit v coordinate
  143.     shl    ebp,10    ; put 6:10 int:frac into high word
  144.     mov    bp,ax    ; put u coordinate in low word
  145.  
  146.     mov    eax,_fx_du_dx    ; get 32 bit delta u
  147.     shr    eax,6    ; get 6:10 int:frac delta u into low word
  148.     mov    edx,_fx_dv_dx    ; get 32 bit delta v
  149.     shl    edx,10    ; put 6:10 int:frac into high word
  150.     mov    dx,ax    ; put delta u in low word
  151.  
  152. ;; esi, ecx should be free
  153. loop_test = 1    ; set to 1 to run as loop for better profiling
  154.  if loop_test
  155.     mov    ebx,_fx_l
  156.     shr    ebx,8
  157.  
  158.     mov    ecx,_loop_count
  159.     inc    ecx
  160.     shr    ecx,1
  161.     je    one_more_pix
  162.     pushf
  163.  
  164.     align    4
  165. loop1:
  166.     mov    eax,ebp    ; get u, v
  167.     shr    eax,26    ; shift out all but int(v)
  168.     shld    ax,bp,6    ; shift in u, shifting up v
  169.  
  170.     mov    bl,es:[eax]    ; get pixel from source bitmap
  171.  
  172.     mov    al,fs:[ebx]    ; xlat pixel through lighting tables
  173.  
  174.     add    ebp,edx    ; u += du, v += dv
  175.     mov    [edi],al    ; write pixel...
  176.     inc    edi    ; ...and advance
  177.  
  178. ; --- ---
  179.  
  180.     mov    eax,ebp    ; get u, v
  181.     shr    eax,26    ; shift out all but int(v)
  182.     shld    ax,bp,6    ; shift in u, shifting up v
  183.  
  184.     mov    bl,es:[eax]    ; get pixel from source bitmap
  185.  
  186.     add    ebp,edx    ; u += du, v += dv
  187.  
  188.     mov    al,fs:[ebx]    ; xlat pixel through lighting tables
  189.     mov    [edi],al    ; write pixel...
  190.     inc    edi    ; ...and advance
  191.  
  192.     dec    ecx    ; _loop_count
  193.     jne    loop1
  194.  
  195.     popf
  196.     jnc    all_done
  197.  
  198. one_more_pix:    mov    eax,ebp    ; get u, v
  199.     shr    eax,26    ; shift out all but int(v)
  200.     shld    ax,bp,6    ; shift in u, shifting up v
  201.  
  202.     mov    bl,es:[eax]    ; get pixel from source bitmap
  203.     mov    al,fs:[ebx]    ; xlat pixel through lighting tables
  204.     mov    [edi],al    ; write pixel...
  205.  
  206. all_done:    popa
  207.     pop    fs
  208.     pop    es
  209.     ret
  210.  
  211.  
  212.  endif
  213.  
  214. ; usage:
  215. ;    eax    work
  216. ;    ebx    lighting value
  217. ;    ecx    _lighting_tables
  218. ;    edx    du, dv 6:10:6:10
  219. ;    ebp    u, v coordinates 6:10:6:10
  220. ;    esi    pointer to source bitmap
  221. ;    edi    write address
  222.  
  223. _size = (_end1 - _start1)/num_iters
  224.     mov    ebx,_fx_l
  225.     shr    ebx,8
  226.     mov    eax,num_iters
  227.     sub    eax,_loop_count
  228.     imul    eax,eax,dword ptr _size
  229.     add    eax,offset _start1
  230.     jmp    eax
  231.  
  232.     align    4
  233. _start1:
  234.  
  235. ; usage:
  236. ;    eax    work
  237. ;    ebx    lighting value
  238. ;    ecx    _lighting_tables
  239. ;    edx    du, dv 6:10:6:10
  240. ;    ebp    u, v coordinates 6:10:6:10
  241. ;    esi    pointer to source bitmap
  242. ;    edi    write address
  243.  
  244. ; do all but the last pixel in the unwound loop, last pixel done separately because less work is needed
  245.   rept num_iters
  246.  if 1
  247.  
  248.     mov    eax,ebp    ; get u, v
  249.     shr    eax,26    ; shift out all but int(v)
  250.     shld    ax,bp,6    ; shift in u, shifting up v
  251.  
  252.     add    ebp,edx    ; u += du, v += dv
  253.  
  254.     mov    bl,[esi+eax]    ; get pixel from source bitmap
  255.     mov    al,[ecx+ebx]    ; xlat pixel through lighting tables
  256.     mov    [edi],al    ; write pixel...
  257.     inc    edi    ; ...and advance
  258.  
  259.  
  260.   else
  261.  
  262. ; version which assumes segment overrides are in place (which they are obviously not)
  263.     mov    eax,ebp    ; get u, v
  264.     shr    eax,26    ; shift out all but int(v)
  265.     shld    ax,bp,6    ; shift in u, shifting up v
  266.  
  267.     add    ebp,edx    ; u += du, v += dv
  268.  
  269.     mov    bl,[eax]    ; get pixel from source bitmap
  270.     mov    al,[ebx]    ; xlat pixel through lighting tables
  271.     mov    [edi],al    ; write pixel...
  272.     inc    edi    ; ...and advance
  273.  endif
  274.   endm
  275.  
  276. _end1:
  277.  
  278. ; now do the leftover pixel
  279.     mov    eax,ebp
  280.     shr    eax,26    ; shift in v coordinate
  281.     shld    ax,bp,6    ; shift in u coordinate while shifting up v coordinate
  282.     mov    bl,[esi+eax]    ; get pixel from source bitmap
  283.     mov    al,_lighting_tables[ebx]    ; xlat pixel through lighting tables
  284.     mov    [edi],al    ; write pixel...
  285.  
  286. _none_to_do:    popa
  287.     pop    fs
  288.     pop    es
  289.     ret
  290.  
  291. ; -- Code to get rgb 5 bits integer, 5 bits fraction value into 5 bits integer (for each gun)
  292. ; suitable for inverse color lookup
  293. ;**__test:
  294. ;** int 3
  295. ;**;                  rrrrrfffffrrrrrfffffxxbbbbbfffff
  296. ;**    mov    eax,11111001001010101110101101110111b
  297. ;**    and    eax,11111000001111100000001111100000b
  298. ;**    shld    ebx,eax,15
  299. ;**    or    bx,ax
  300.  
  301. _TEXT    ends
  302.  
  303.     end
  304.