home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / texmap / tmap_sky.asm < prev    next >
Assembly Source File  |  1998-06-08  |  6KB  |  227 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_sky.asm $
  13. ; $Revision: 1.5 $
  14. ; $Author: mike $
  15. ; $Date: 1994/11/30 00:57:04 $
  16. ; Sky texture mapper.
  17. ; $Log: tmap_sky.asm $
  18. ; Revision 1.5  1994/11/30  00:57:04  mike
  19. ; optimization.
  20. ; Revision 1.4  1994/11/12  16:41:14  mike
  21. ; jae -> ja.
  22. ; Revision 1.3  1994/03/25  17:08:48  matt
  23. ; Attempt to make this code work on wide windows, but I don't think
  24. ; it did.
  25. ; Revision 1.2  1994/01/18  10:49:54  mike
  26. ; Modified linear texture mapper for sky plotting.
  27. ; Revision 1.1  1994/01/14  15:07:03  mike
  28. ; Initial revision
  29.  
  30. DEBUG_ON    =    1
  31.  
  32.     .386
  33.  
  34.     option    oldstructs
  35.  
  36.     .nolist
  37.     include    psmacros.inc
  38.     .list
  39.  
  40.  
  41.     public    asm_tmap_scanline_lin_sky_
  42.  
  43.     include    tmap_inc.asm
  44.  
  45. width_log_2    equ    10
  46. height_log_2    equ    7
  47.  
  48. big_num_iters equ num_iters*2
  49.  
  50.  
  51. _DATA    SEGMENT DWORD PUBLIC USE32 'DATA'
  52.  
  53.     extd    _fx_u
  54.     extd    _fx_v
  55.     extd    _fx_du_dx
  56.     extd    _fx_dv_dx
  57.     extd    _fx_y
  58.     extd    _fx_xleft
  59.     extd    _fx_xright
  60.  
  61.     extd    _pixptr
  62.  
  63.     extd    _x
  64.     extd    _loop_count
  65.  
  66. _DATA    ENDS
  67.  
  68. DGROUP    GROUP    _DATA
  69.  
  70. _TEXT   SEGMENT PARA PUBLIC USE32 'CODE'
  71.  
  72.     ASSUME    DS:_DATA
  73.     ASSUME    CS:_TEXT
  74.  
  75. ; --------------------------------------------------------------------------------------------------
  76. ; Enter:
  77. ;    _xleft    fixed point left x coordinate
  78. ;    _xright    fixed point right x coordinate
  79. ;    _y    fixed point y coordinate
  80. ;    _pixptr    address of source pixel map
  81. ;    _u    fixed point initial u coordinate
  82. ;    _v    fixed point initial v coordinate
  83. ;    _du_dx    fixed point du/dx
  84. ;    _dv_dx    fixed point dv/dx
  85.  
  86. ;   for (x = (int) xleft; x <= (int) xright; x++) {
  87. ;      _setcolor(read_pixel_from_tmap(srcb,((int) (u/z)) & 63,((int) (v/z)) & 63));
  88. ;      _setpixel(x,y);
  89. ;
  90. ;      u += du_dx;
  91. ;      v += dv_dx;
  92. ;      z += dz_dx;
  93. ;   }
  94.  
  95.     align    4
  96. asm_tmap_scanline_lin_sky_:
  97.     pusha
  98.  
  99. ; Setup for loop:    _loop_count  iterations = (int) xright - (int) xleft
  100. ;    esi    source pixel pointer = pixptr
  101. ;    edi    initial row pointer = y*320+x
  102.  
  103. ; set esi = pointer to start of texture map data
  104.     mov    esi,_pixptr
  105.  
  106. ; set edi = address of first pixel to modify
  107.     mov    edi,_fx_y
  108.     cmp    edi,_window_bottom
  109.     ja    _none_to_do
  110.  
  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.     add    edi,eax
  118.     add    edi,write_buffer
  119.  
  120. ; set _loop_count = # of iterations
  121.     mov    eax,_fx_xright
  122.     sar    eax,16
  123.     cmp    eax,_window_right
  124.     jb    eax_ok1
  125.     mov    eax,_window_right
  126. eax_ok1:    cmp    eax,_window_left
  127.     ja    eax_ok2
  128.     mov    eax,_window_left
  129. eax_ok2:
  130.  
  131.     mov    ebx,_fx_xleft
  132.     sar    ebx,16
  133.     sub    eax,ebx
  134.     js    _none_to_do
  135.     cmp    eax,_window_width
  136.     jbe    _ok_to_do
  137.     mov    eax,_window_width
  138. _ok_to_do:
  139.     mov    _loop_count,eax
  140.  
  141. ;    edi    destination pixel pointer
  142.  
  143.  
  144.     mov    ebx,_fx_u
  145.     mov    ecx,_fx_du_dx
  146.     mov    edx,_fx_dv_dx
  147.     mov    ebp,_fx_v
  148.  
  149.     shl    ebx,16-width_log_2
  150.     shl    ebp,16-height_log_2
  151.     shl    edx,16-height_log_2
  152.     shl    ecx,16-width_log_2
  153.  
  154. ; eax    work
  155. ; ebx    u
  156. ; ecx    du_dx
  157. ; edx    dv_dx
  158. ; ebp    v
  159. ; esi    read address
  160. ; edi    write address
  161.  
  162. _size = (_end1 - _start1)/big_num_iters
  163.     mov    eax,big_num_iters-1
  164.     sub    eax,_loop_count
  165.     jns    j_eax_ok1
  166.     inc    eax    ; sort of a hack, but we can get -1 here and want to be graceful
  167.     jns    j_eax_ok1    ; if we jump, we had -1, which is kind of ok, if not, we int 3
  168.     int    3    ; oops, going to jump behind _start1, very bad...
  169.     sub    eax,eax    ; ok to continue
  170. j_eax_ok1:    imul    eax,eax,dword ptr _size
  171.     add    eax,offset _start1
  172.     jmp    eax
  173.  
  174.     align    4
  175. _start1:
  176.  
  177. ; "OPTIMIZATIONS" maybe not worth making
  178. ;    Getting rid of the esi from the mov al,[esi+eax] instruction.
  179. ;       This would require moving into eax at the top of the loop, rather than doing the sub eax,eax.
  180. ;       You would have to align your bitmaps so that the two shlds would create the proper base address.
  181. ;       In other words, your bitmap data would have to begin at 4096x (for 64x64 bitmaps).
  182. ;       I did timings without converting the sub to a mov eax,esi and setting esi to the proper value.
  183. ;       There was a speedup of about 1% to 1.5% without converting the sub to a mov.
  184. ;    Getting rid of the edi by doing a mov nnnn[edi],al instead of mov [edi],al.
  185. ;       The problem with this is you would have a dword offset for nnnn.  My timings indicate it is slower.  (I think.)
  186. ;    Combining u,v and du,dv into single longwords.
  187. ;       The problem with this is you then must do a 16 bit operation to extract them, and you don't have enough
  188. ;       instructions to separate a destination operand from being used by the next instruction.  It shaves out one
  189. ;       register instruction (an add reg,reg), but adds a 16 bit operation, and the setup is more complicated.
  190. ; usage:
  191. ;    eax    work
  192. ;    ebx    u coordinate
  193. ;    ecx    delta u
  194. ;    edx    delta v
  195. ;    ebp    v coordinate
  196. ;    esi    pointer to source bitmap
  197. ;    edi    write address
  198.  rept big_num_iters
  199.     mov    eax,ebp    ; clear for 
  200.     add    ebp,edx    ; update v coordinate
  201.     shr    eax,32-height_log_2    ; shift in v coordinate
  202.     shld    eax,ebx,width_log_2    ; shift in u coordinate while shifting up v coordinate
  203.     add    ebx,ecx    ; update u coordinate
  204.     mov    al,[esi+eax]    ; get pixel from source bitmap
  205.     mov    [edi],al
  206.     inc    edi
  207.  
  208.  endm
  209.  
  210. _end1:
  211.  
  212. _none_to_do:    popa
  213.  
  214.     ret
  215.  
  216. _TEXT    ends
  217.  
  218.     end
  219.