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