home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / texmap / tmap_16g.asm < prev    next >
Assembly Source File  |  1998-06-08  |  5KB  |  215 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_16g.asm $
  13. ; $Revision: 1.4 $
  14. ; $Author: mike $
  15. ; $Date: 1994/11/30 00:56:37 $
  16. ;
  17. ; inner loop of rgb lighted linear texture mapper for 16 bits/pixel
  18. ;
  19. ; $Log: tmap_16g.asm $
  20. ; Revision 1.4  1994/11/30  00:56:37  mike
  21. ; optimization.
  22. ; Revision 1.3  1994/11/12  16:39:23  mike
  23. ; jae to ja.
  24. ; Revision 1.2  1993/11/22  10:24:28  mike
  25. ; *** empty log message ***
  26. ; Revision 1.1  1993/09/08  17:29:17  mike
  27. ; Initial revision
  28. ;
  29. ;
  30.  
  31.  
  32.     .386
  33.  
  34.     option    oldstructs
  35.  
  36.     .nolist
  37.     include    psmacros.inc
  38.     .list
  39.  
  40.     public    asm_tmap_scanline_lin_rgb_16g_
  41.  
  42.     include    tmap_inc.asm
  43.  
  44. _DATA    SEGMENT DWORD PUBLIC USE32 'DATA'
  45.  
  46.     extd    _fx_u
  47.     extd    _fx_v
  48.     extd    _fx_du_dx
  49.     extd    _fx_dv_dx
  50.     extd    _fx_y
  51.     extd    _fx_xleft
  52.     extd    _fx_xright
  53.  
  54.     extd    _pixptr
  55.  
  56.     extd    _x
  57.     extd    _loop_count
  58.  
  59.     extd    _fx_rgb,_fx_drgb_dx
  60.  
  61.     extd    _fx_r,_fx_g,_fx_b,_fx_dr_dx,_fx_dg_dx,_fx_db_dx
  62.  
  63.     align    4
  64.  
  65. _DATA    ENDS
  66.  
  67. DGROUP    GROUP    _DATA
  68.  
  69. _TEXT   SEGMENT PARA PUBLIC USE32 'CODE'
  70.  
  71.     ASSUME    DS:_DATA
  72.     ASSUME    CS:_TEXT
  73.  
  74. ; --------------------------------------------------------------------------------------------------
  75. ; Enter:
  76. ;    _xleft    fixed point left x coordinate
  77. ;    _xright    fixed point right x coordinate
  78. ;    _y    fixed point y coordinate
  79. ;    _pixptr    address of source pixel map
  80. ;    _u    fixed point initial u coordinate
  81. ;    _v    fixed point initial v coordinate
  82. ;    _du_dx    fixed point du/dx
  83. ;    _dv_dx    fixed point dv/dx
  84.  
  85. ;   for (x = (int) xleft; x <= (int) xright; x++) {
  86. ;      _setcolor(read_pixel_from_tmap(srcb,((int) (u/z)) & 63,((int) (v/z)) & 63));
  87. ;      _setpixel(x,y);
  88. ;
  89. ;      u += du_dx;
  90. ;      v += dv_dx;
  91. ;      z += dz_dx;
  92. ;   }
  93.  
  94.     align    4
  95. asm_tmap_scanline_lin_rgb_16g_:
  96.     pusha
  97.  
  98. ; Setup for loop:    _loop_count  iterations = (int) xright - (int) xleft
  99. ;    esi    source pixel pointer = pixptr
  100. ;    edi    initial row pointer = y*320+x
  101.  
  102. ; set esi = pointer to start of texture map data
  103.     mov    esi,_pixptr
  104.  
  105. ; set edi = address of first pixel to modify
  106.     mov    edi,_fx_y
  107.     cmp    edi,_window_bottom
  108.     ja    _none_to_do
  109.  
  110.     sub    edi,_window_top
  111.     imul    edi,_bytes_per_row
  112.     mov    eax,_fx_xleft
  113.     sar    eax,16
  114.     jns    eax_ok
  115.     sub    eax,eax
  116. eax_ok:
  117.     sub    eax,_window_left
  118.     add    edi,eax
  119.     add    edi,eax
  120.     add    edi,write_buffer
  121.  
  122. ; set _loop_count = # of iterations
  123.     mov    eax,_fx_xright
  124.     sar    eax,16
  125.     cmp    eax,_window_right
  126.     jb    eax_ok1
  127.     mov    eax,_window_right
  128. eax_ok1:    cmp    eax,_window_left
  129.     ja    eax_ok2
  130.     mov    eax,_window_left
  131. eax_ok2:
  132.  
  133.     mov    ebx,_fx_xleft
  134.     sar    ebx,16
  135.     sub    eax,ebx
  136.     js    _none_to_do
  137.     cmp    eax,_window_width
  138.     jbe    _ok_to_do
  139.     mov    eax,_window_width
  140. _ok_to_do:
  141.     mov    _loop_count,eax
  142.  
  143. ;    edi    destination pixel pointer
  144.  
  145. ; shift up all light values and deltas so that the highest 5 bits are the integer portion
  146.     shl    _fx_r,11
  147.     shl    _fx_g,11
  148.     shl    _fx_b,11
  149.  
  150.     shl    _fx_dr_dx,11
  151.     shl    _fx_dg_dx,11
  152.     shl    _fx_db_dx,11
  153.  
  154. ; ---------------------------------------------------------------------------------------------------------------------
  155.     mov    eax,_fx_g
  156.     mov    edx,_fx_b
  157.     mov    ebx,_fx_r
  158.     mov    ebp,_fx_dr_dx
  159.     mov    esi,_fx_dg_dx
  160.  
  161. ; register usage:
  162. ;  eax    _fx_g
  163. ;  ebx    _fx_r
  164. ;  ecx    work
  165. ;  edx    _fx_b
  166. ;  ebp    _fx_dr_dx
  167. ;  esi    _fx_dg_dx
  168. ;  edi    write address
  169.  
  170. ; do the regular texture mapper linear interpolation to get the pixel from the source bitmap
  171. _loop1:
  172.     mov    ecx,ebx    ; light value in high 5 bits
  173.     shr    ecx,27    ; shift out all but light value
  174.     shld    ecx,eax,5
  175.     shld    ecx,edx,5
  176.  
  177. ; now %ecx = r|g|b, each 5 bits, bit #15 clear, write the pixel
  178.     mov    [edi],cx
  179.     add    edi,2
  180.  
  181. ; now add the deltas
  182.     add    ebx,ebp
  183.     add    eax,esi
  184.     add    edx,_fx_db_dx
  185.  
  186.     dec    _loop_count
  187.     jns    _loop1
  188.  
  189. ; ---------------------------------------------------------------------------------------------------------------------
  190.  
  191. _none_to_do:    popa
  192.  
  193.     ret
  194.  
  195. ; -- Code to get rgb 5 bits integer, 5 bits fraction value into 5 bits integer (for each gun)
  196. ; suitable for inverse color lookup
  197. ;**__test:
  198. ;** int 3
  199. ;**;                  rrrrrfffffrrrrrfffffxxbbbbbfffff
  200. ;**    mov    eax,11111001001010101110101101110111b
  201. ;**    and    eax,11111000001111100000001111100000b
  202. ;**    shld    ebx,eax,15
  203. ;**    or    bx,ax
  204.  
  205. _TEXT    ends
  206.  
  207.     end
  208.  
  209.  
  210.  
  211.