home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / texmap / tmap_skv.asm < prev    next >
Assembly Source File  |  1998-06-08  |  9KB  |  334 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_skv.asm $
  13. ; $Revision: 1.5 $
  14. ; $Author: mike $
  15. ; $Date: 1994/11/30 00:57:03 $
  16. ; Vertical scanner for sky bitmap rendering.
  17. ; $Log: tmap_skv.asm $
  18. ; Revision 1.5  1994/11/30  00:57:03  mike
  19. ; optimization.
  20. ; Revision 1.4  1994/11/12  16:41:13  mike
  21. ; jae -> ja.
  22. ; Revision 1.3  1994/05/24  11:03:12  mike
  23. ; Make work for any sized (power of 2) bitmap.
  24. ; Revision 1.2  1994/01/31  15:42:14  mike
  25. ; Vertical scanning sky texture mapper (in inner loop).
  26. ; Revision 1.1  1994/01/30  14:10:55  mike
  27. ; Initial revision
  28.  
  29.  
  30.  
  31. DEBUG_ON    =    1
  32.  
  33.     .386
  34.  
  35.     option    oldstructs
  36.  
  37.     .nolist
  38.     include    psmacros.inc
  39.     .list
  40.  
  41.  
  42.     public    asm_tmap_scanline_lin_sky_v_, asm_tmap_scanline_lin_v_
  43.  
  44.     include    tmap_inc.asm
  45.  
  46. sky_width_log_2    equ    10
  47. sky_height_log_2    equ    7
  48.  
  49. width_log_2    equ    6
  50. height_log_2    equ    6
  51.  
  52. _DATA    SEGMENT DWORD PUBLIC USE32 'DATA'
  53.  
  54.     extd    _fx_u
  55.     extd    _fx_v
  56.     extd    _fx_du_dx
  57.     extd    _fx_dv_dx
  58.     extd    _fx_y
  59.     extd    _fx_xleft
  60.     extd    _fx_xright
  61.  
  62.     extd    _pixptr
  63.  
  64.     extd    _x
  65.     extd    _loop_count
  66.  
  67. _DATA    ENDS
  68.  
  69. DGROUP    GROUP    _DATA
  70.  
  71. _TEXT   SEGMENT PARA PUBLIC USE32 'CODE'
  72.  
  73.     ASSUME    DS:_DATA
  74.     ASSUME    CS:_TEXT
  75.  
  76. ; --------------------------------------------------------------------------------------------------
  77. ; Enter:
  78. ;    _xleft    fixed point left x coordinate
  79. ;    _xright    fixed point right x coordinate
  80. ;    _y    fixed point y coordinate
  81. ;    _pixptr    address of source pixel map
  82. ;    _u    fixed point initial u coordinate
  83. ;    _v    fixed point initial v coordinate
  84. ;    _du_dx    fixed point du/dx
  85. ;    _dv_dx    fixed point dv/dx
  86.  
  87. ;   for (x = (int) xleft; x <= (int) xright; x++) {
  88. ;      _setcolor(read_pixel_from_tmap(srcb,((int) (u/z)) & 63,((int) (v/z)) & 63));
  89. ;      _setpixel(x,y);
  90. ;
  91. ;      u += du_dx;
  92. ;      v += dv_dx;
  93. ;      z += dz_dx;
  94. ;   }
  95.  
  96.     align    4
  97. asm_tmap_scanline_lin_sky_v_:
  98.     pusha
  99.  
  100. ; Setup for loop:    _loop_count  iterations = (int) xright - (int) xleft
  101. ;    esi    source pixel pointer = pixptr
  102. ;    edi    initial row pointer = y*320+x
  103.  
  104. ; set esi = pointer to start of texture map data
  105.     mov    esi,_pixptr
  106.  
  107. ; set edi = address of first pixel to modify
  108.     mov    edi,_fx_xleft
  109.     sar    edi,16
  110.     jns    edi_ok
  111.     sub    edi,edi
  112. edi_ok:
  113.     cmp    edi,_window_bottom
  114.     ja    _none_to_do
  115.     imul    edi,_bytes_per_row
  116.  
  117.     add    edi,_fx_y
  118.     add    edi,write_buffer
  119.  
  120. ; set _loop_count = # of iterations
  121.     mov    eax,_fx_xright
  122.     sar    eax,16
  123.     mov    ebx,_fx_xleft
  124.     sar    ebx,16
  125.     sub    eax,ebx
  126.     js    _none_to_do
  127.     cmp    eax,_window_height
  128.     jbe    _ok_to_do
  129.     mov    eax,_window_height
  130. _ok_to_do:
  131.     mov    _loop_count,eax
  132.  
  133. ;    edi    destination pixel pointer
  134.  
  135.  
  136.     mov    ebx,_fx_u
  137.     mov    ecx,_fx_du_dx
  138.     mov    edx,_fx_dv_dx
  139.     mov    ebp,_fx_v
  140.  
  141.     shl    ebx,16-sky_width_log_2
  142.     shl    ebp,16-sky_height_log_2
  143.     shl    edx,16-sky_height_log_2
  144.     shl    ecx,16-sky_width_log_2
  145.  
  146. ; eax    work
  147. ; ebx    u
  148. ; ecx    du_dx
  149. ; edx    dv_dx
  150. ; ebp    v
  151. ; esi    read address
  152. ; edi    write address
  153.  
  154. _size = (_end1 - _start1)/num_iters
  155.     mov    eax,num_iters-1
  156.     sub    eax,_loop_count
  157.     jns    j_eax_ok1
  158.     inc    eax    ; sort of a hack, but we can get -1 here and want to be graceful
  159.     jns    j_eax_ok1    ; if we jump, we had -1, which is kind of ok, if not, we int 3
  160.     int    3    ; oops, going to jump behind _start1, very bad...
  161.     sub    eax,eax    ; ok to continue
  162. j_eax_ok1:    imul    eax,eax,dword ptr _size
  163.     add    eax,offset _start1
  164.     jmp    eax
  165.  
  166.     align    4
  167. _start1:
  168.  
  169. ; "OPTIMIZATIONS" maybe not worth making
  170. ;    Getting rid of the esi from the mov al,[esi+eax] instruction.
  171. ;       This would require moving into eax at the top of the loop, rather than doing the sub eax,eax.
  172. ;       You would have to align your bitmaps so that the two shlds would create the proper base address.
  173. ;       In other words, your bitmap data would have to begin at 4096x (for 64x64 bitmaps).
  174. ;       I did timings without converting the sub to a mov eax,esi and setting esi to the proper value.
  175. ;       There was a speedup of about 1% to 1.5% without converting the sub to a mov.
  176. ;    Getting rid of the edi by doing a mov nnnn[edi],al instead of mov [edi],al.
  177. ;       The problem with this is you would have a dword offset for nnnn.  My timings indicate it is slower.  (I think.)
  178. ;    Combining u,v and du,dv into single longwords.
  179. ;       The problem with this is you then must do a 16 bit operation to extract them, and you don't have enough
  180. ;       instructions to separate a destination operand from being used by the next instruction.  It shaves out one
  181. ;       register instruction (an add reg,reg), but adds a 16 bit operation, and the setup is more complicated.
  182. ; usage:
  183. ;    eax    work
  184. ;    ebx    u coordinate
  185. ;    ecx    delta u
  186. ;    edx    delta v
  187. ;    ebp    v coordinate
  188. ;    esi    pointer to source bitmap
  189. ;    edi    write address
  190.  rept num_iters
  191.     mov    eax,ebp    ; clear for 
  192.     add    ebp,edx    ; update v coordinate
  193.     shr    eax,32-sky_height_log_2    ; shift in v coordinate
  194.     shld    eax,ebx,sky_width_log_2    ; shift in u coordinate while shifting up v coordinate
  195.     add    ebx,ecx    ; update u coordinate
  196.     mov    al,[esi+eax]    ; get pixel from source bitmap
  197.     mov    [edi],al
  198.     add    edi,_bytes_per_row
  199.  
  200.  endm
  201.  
  202. _end1:
  203.  
  204. _none_to_do:    popa
  205.  
  206.     ret
  207.  
  208. ; --------------------------------------------------------------------------------------------------------------------------------
  209.     align    4
  210. asm_tmap_scanline_lin_v_:
  211.     pusha
  212.  
  213. ; Setup for loop:    _loop_count  iterations = (int) xright - (int) xleft
  214. ;    esi    source pixel pointer = pixptr
  215. ;    edi    initial row pointer = y*320+x
  216.  
  217. ; set esi = pointer to start of texture map data
  218.     mov    esi,_pixptr
  219.  
  220. ; set edi = address of first pixel to modify
  221.     mov    edi,_fx_xleft
  222.     sar    edi,16
  223.     jns    edi_ok_a
  224.     sub    edi,edi
  225. edi_ok_a:
  226.     cmp    edi,_window_bottom
  227.     ja    _none_to_do_a
  228.     imul    edi,_bytes_per_row
  229.  
  230.     add    edi,_fx_y
  231.     add    edi,write_buffer
  232.  
  233. ; set _loop_count = # of iterations
  234.     mov    eax,_fx_xright
  235.     sar    eax,16
  236.     mov    ebx,_fx_xleft
  237.     sar    ebx,16
  238.     sub    eax,ebx
  239.     js    _none_to_do_a
  240.     cmp    eax,_window_height
  241.     jbe    _ok_to_do_a
  242.     mov    eax,_window_height
  243. _ok_to_do_a:
  244.     mov    _loop_count,eax
  245.  
  246. ;    edi    destination pixel pointer
  247.  
  248.  
  249.     mov    ebx,_fx_u
  250.     mov    ecx,_fx_du_dx
  251.     mov    edx,_fx_dv_dx
  252.     mov    ebp,_fx_v
  253.  
  254.     shl    ebx,16-width_log_2
  255.     shl    ebp,16-height_log_2
  256.     shl    edx,16-height_log_2
  257.     shl    ecx,16-width_log_2
  258.  
  259. ; eax    work
  260. ; ebx    u
  261. ; ecx    du_dx
  262. ; edx    dv_dx
  263. ; ebp    v
  264. ; esi    read address
  265. ; edi    write address
  266.  
  267. _size_a = (_end1_a - _start1_a)/num_iters
  268.     mov    eax,num_iters-1
  269.     sub    eax,_loop_count
  270.     jns    j_eax_ok1_a
  271.     inc    eax    ; sort of a hack, but we can get -1 here and want to be graceful
  272.     jns    j_eax_ok1_a    ; if we jump, we had -1, which is kind of ok, if not, we int 3
  273.     int    3    ; oops, going to jump behind _start1, very bad...
  274.     sub    eax,eax    ; ok to continue
  275. j_eax_ok1_a:    imul    eax,eax,dword ptr _size_a
  276.     add    eax,offset _start1_a
  277.     jmp    eax
  278.  
  279.     align    4
  280. _start1_a:
  281.  
  282. ; "OPTIMIZATIONS" maybe not worth making
  283. ;    Getting rid of the esi from the mov al,[esi+eax] instruction.
  284. ;       This would require moving into eax at the top of the loop, rather than doing the sub eax,eax.
  285. ;       You would have to align your bitmaps so that the two shlds would create the proper base address.
  286. ;       In other words, your bitmap data would have to begin at 4096x (for 64x64 bitmaps).
  287. ;       I did timings without converting the sub to a mov eax,esi and setting esi to the proper value.
  288. ;       There was a speedup of about 1% to 1.5% without converting the sub to a mov.
  289. ;    Getting rid of the edi by doing a mov nnnn[edi],al instead of mov [edi],al.
  290. ;       The problem with this is you would have a dword offset for nnnn.  My timings indicate it is slower.  (I think.)
  291. ;    Combining u,v and du,dv into single longwords.
  292. ;       The problem with this is you then must do a 16 bit operation to extract them, and you don't have enough
  293. ;       instructions to separate a destination operand from being used by the next instruction.  It shaves out one
  294. ;       register instruction (an add reg,reg), but adds a 16 bit operation, and the setup is more complicated.
  295. ; usage:
  296. ;    eax    work
  297. ;    ebx    u coordinate
  298. ;    ecx    delta u
  299. ;    edx    delta v
  300. ;    ebp    v coordinate
  301. ;    esi    pointer to source bitmap
  302. ;    edi    write address
  303.  rept num_iters
  304.     mov    eax,ebp    ; clear for 
  305.     add    ebp,edx    ; update v coordinate
  306.     shr    eax,32-height_log_2    ; shift in v coordinate
  307.     shld    eax,ebx,width_log_2    ; shift in u coordinate while shifting up v coordinate
  308.     add    ebx,ecx    ; update u coordinate
  309.     mov    al,[esi+eax]    ; get pixel from source bitmap
  310.     mov    [edi],al
  311.     add    edi,_bytes_per_row
  312.  
  313.  endm
  314.  
  315. _end1_a:
  316.  
  317. _none_to_do_a:    popa
  318.  
  319.     ret
  320.  
  321.  
  322.  
  323. _TEXT    ends
  324.  
  325.     end
  326.