TMAP_Z.ASM 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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_z.asm $
  13. ; $Revision: 1.4 $
  14. ; $Author: mike $
  15. ; $Date: 1994/11/30 00:57:06 $
  16. ;
  17. ; Assembly routines to do a flat-shaded z-buffer tmap.
  18. ;
  19. ; $Log: tmap_z.asm $
  20. ; Revision 1.4 1994/11/30 00:57:06 mike
  21. ; optimization.
  22. ;
  23. ; Revision 1.3 1994/11/12 16:41:14 mike
  24. ; jae -> ja.
  25. ;
  26. ; Revision 1.2 1994/07/08 17:43:14 john
  27. ; Added flat-shaded-zbuffered polygon.
  28. ;
  29. ; Revision 1.1 1994/07/08 10:58:18 john
  30. ; Initial revision
  31. ;
  32. ;
  33. .386
  34. public asm_tmap_scanline_flat_z_
  35. public _tmap_flat_color_z
  36. public _tmap_z_buffer
  37. include tmap_inc.asm
  38. _DATA SEGMENT DWORD PUBLIC USE32 'DATA'
  39. extrn _fx_y:dword
  40. extrn _fx_xleft:dword
  41. extrn _fx_xright:dword
  42. extrn _fx_z:dword
  43. extrn _fx_dz_dx:dword
  44. ;** extrn _pixptr:dword
  45. _tmap_flat_color_z db ?
  46. _tmap_z_buffer dd 0
  47. _loop_count dd 0
  48. _DATA ENDS
  49. DGROUP GROUP _DATA
  50. _TEXT SEGMENT PARA PUBLIC USE32 'CODE'
  51. ASSUME DS:_DATA
  52. ASSUME CS:_TEXT
  53. ; --------------------------------------------------------------------------------------------------
  54. ; Enter:
  55. ; _xleft fixed point left x coordinate
  56. ; _xright fixed point right x coordinate
  57. ; _y fixed point y coordinate
  58. ;**; _pixptr address of source pixel map
  59. ; for (x = (int) xleft; x <= (int) xright; x++) {
  60. ; _setcolor(read_pixel_from_tmap(srcb,((int) (u/z)) & 63,((int) (v/z)) & 63));
  61. ; _setpixel(x,y);
  62. ;
  63. ; z += dz_dx;
  64. ; }
  65. asm_tmap_scanline_flat_z_:
  66. pusha
  67. ; Setup for loop: _loop_count iterations = (int) xright - (int) xleft
  68. ;**; esi source pixel pointer = pixptr
  69. ; edi initial row pointer = y*320+x
  70. ; set esi = pointer to start of texture map data
  71. ;** mov esi,_pixptr
  72. ; set edi = address of first pixel to modify
  73. mov edi,_fx_y
  74. shr edi,16
  75. cmp edi,_window_bottom
  76. ja _none_to_do
  77. imul edi,_bytes_per_row
  78. mov eax,_fx_xleft
  79. sar eax,16
  80. jns eax_ok
  81. sub eax,eax
  82. eax_ok:
  83. add edi,eax
  84. mov esi,edi
  85. shl esi, 2
  86. add esi, _tmap_z_buffer
  87. add edi,write_buffer
  88. ; set _loop_count = # of iterations
  89. mov eax,_fx_xright
  90. sar eax,16
  91. cmp eax,_window_right
  92. jb eax_ok1
  93. mov eax,_window_right
  94. eax_ok1: cmp eax,_window_left
  95. ja eax_ok2
  96. mov eax,_window_left
  97. eax_ok2:
  98. mov ebx,_fx_xleft
  99. sar ebx,16
  100. sub eax,ebx
  101. js _none_to_do
  102. cmp eax,_window_width
  103. jbe _ok_to_do
  104. mov eax,_window_width
  105. _ok_to_do:
  106. mov _loop_count, eax
  107. mov cl,_tmap_flat_color_z
  108. mov edx, _fx_z
  109. mov ebp, _fx_dz_dx
  110. mov ebx, 4
  111. _size = (_end1 - _start1)/num_iters
  112. mov eax,num_iters-1
  113. sub eax,_loop_count
  114. jns j_eax_ok1
  115. inc eax ; sort of a hack, but we can get -1 here and want to be graceful
  116. jns j_eax_ok1 ; if we jump, we had -1, which is kind of ok, if not, we int 3
  117. int 3 ; oops, going to jump behind _start1, very bad...
  118. sub eax,eax ; ok to continue
  119. j_eax_ok1: imul eax,eax,dword ptr _size
  120. add eax,offset _start1
  121. jmp eax
  122. align 4
  123. _start1:
  124. rept num_iters
  125. local l1
  126. cmp edx, [esi]
  127. jge l1
  128. mov [esi], edx
  129. mov [edi], cl
  130. l1: add esi, ebx
  131. add edx, ebp
  132. inc edi
  133. endm
  134. _end1:
  135. _none_to_do: popa
  136. ret
  137. _TEXT ends
  138. end