]> icculus.org git repositories - btb/d2x.git/blob - texmap/tmap_lin.asm
remove superfluous files
[btb/d2x.git] / texmap / tmap_lin.asm
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: /cvs/cvsroot/d2x/texmap/tmap_lin.asm,v $
13 ; $Revision: 1.1.1.1 $
14 ; $Author: bradleyb $
15 ; $Date: 2001-01-19 03:30:16 $
16 ;
17 ; Linearly interpolating texture mapper inner loop
18 ;
19 ; $Log: not supported by cvs2svn $
20 ; Revision 1.1.1.1  1999/06/14 22:13:53  donut
21 ; Import of d1x 1.37 source.
22 ;
23 ; Revision 1.3  1995/02/20  18:22:57  john
24 ; Put all the externs in the assembly modules into tmap_inc.asm.
25 ; Also, moved all the C versions of the inner loops into a new module, 
26 ; scanline.c.
27
28 ; Revision 1.2  1995/02/20  17:09:10  john
29 ; Added code so that you can build the tmapper with no assembly!
30
31 ; Revision 1.1  1994/11/30  12:24:04  mike
32 ; Initial revision
33
34 ; Revision 1.6  1994/11/12  16:39:40  mike
35 ; jae to ja.
36
37 ; Revision 1.5  1994/02/10  21:24:43  matt
38 ; Got rid of debug_on set
39
40 ; Revision 1.4  1994/01/31  15:39:53  mike
41 ; Write additional inner loop for transparency.
42
43 ; Revision 1.3  1994/01/26  11:50:04  john
44 ; Added transparency to linear unlighted texture mapper.
45
46 ; Revision 1.2  1993/11/22  10:24:36  mike
47 ; *** empty log message ***
48
49 ; Revision 1.1  1993/09/08  17:29:50  mike
50 ; Initial revision
51
52 ;
53 ;
54
55 [BITS 32]
56
57 global  _asm_tmap_scanline_lin
58 global  asm_tmap_scanline_lin
59
60 [SECTION .data]
61
62 %include        "tmap_inc.asm"
63
64 _loop_count     dd      0
65
66 [SECTION .text]
67
68 ; --------------------------------------------------------------------------------------------------
69 ; Enter:
70 ;       _xleft  fixed point left x coordinate
71 ;       _xright fixed point right x coordinate
72 ;       _y      fixed point y coordinate
73 ;       _pixptr address of source pixel map
74 ;       _u      fixed point initial u coordinate
75 ;       _v      fixed point initial v coordinate
76 ;       _du_dx  fixed point du/dx
77 ;       _dv_dx  fixed point dv/dx
78
79 ;   for (x = (int) xleft; x <= (int) xright; x++) {
80 ;      _setcolor(read_pixel_from_tmap(srcb,((int) (u/z)) & 63,((int) (v/z)) & 63));
81 ;      _setpixel(x,y);
82 ;
83 ;      u += du_dx;
84 ;      v += dv_dx;
85 ;      z += dz_dx;
86 ;   }
87
88         align   4
89 _asm_tmap_scanline_lin:
90 asm_tmap_scanline_lin:
91         pusha
92
93 ; Setup for loop:       _loop_count  iterations = (int) xright - (int) xleft
94 ;       esi     source pixel pointer = pixptr
95 ;       edi     initial row pointer = y*320+x
96
97 ; set esi = pointer to start of texture map data
98         mov     esi,[_pixptr]
99
100 ; set edi = address of first pixel to modify
101         mov     edi,[_fx_y]
102         cmp     edi,[_window_bottom]
103         ja      near _none_to_do
104
105         imul    edi,[_bytes_per_row]
106         mov     eax,[_fx_xleft]
107         test    eax, eax
108         jns     eax_ok
109         sub     eax,eax
110 eax_ok:
111         add     edi,eax
112         add     edi,[_write_buffer]
113
114 ; set _loop_count = # of iterations
115         mov     eax,[_fx_xright]
116         cmp     eax,[_window_right]
117         jb      eax_ok1
118         mov     eax,[_window_right]
119 eax_ok1:        cmp     eax,[_window_left]
120         ja      eax_ok2
121         mov     eax,[_window_left]
122 eax_ok2:
123
124         mov     ebx,[_fx_xleft]
125         sub     eax,ebx
126         js      near _none_to_do
127         cmp     eax,[_window_width]
128         jbe     _ok_to_do
129         mov     eax,[_window_width]
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,10
142         shl     ebp,10
143         shl     edx,10
144         shl     ecx,10
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         test    dword [_Transparency_on],-1
155         jne     near transparent_texture
156
157 %define _size   (_end1 - _start1)/num_iters
158         mov     eax,num_iters-1
159         sub     eax,[_loop_count]
160         jns     j_eax_ok1
161         inc     eax     ; sort of a hack, but we can get -1 here and want to be graceful
162         jns     j_eax_ok1       ; if we jump, we had -1, which is kind of ok, if not, we int 3
163         int     3       ; oops, going to jump behind _start1, very bad...
164         sub     eax,eax ; ok to continue
165 j_eax_ok1:      imul    eax,eax,_size
166         add     eax,_start1
167         jmp     eax
168
169         align   4
170 _start1:
171
172 ; "OPTIMIZATIONS" maybe not worth making
173 ;    Getting rid of the esi from the mov al,[esi+eax] instruction.
174 ;       This would require moving into eax at the top of the loop, rather than doing the sub eax,eax.
175 ;       You would have to align your bitmaps so that the two shlds would create the proper base address.
176 ;       In other words, your bitmap data would have to begin at 4096x (for 64x64 bitmaps).
177 ;       I did timings without converting the sub to a mov eax,esi and setting esi to the proper value.
178 ;       There was a speedup of about 1% to 1.5% without converting the sub to a mov.
179 ;    Getting rid of the edi by doing a mov nnnn[edi],al instead of mov [edi],al.
180 ;       The problem with this is you would have a dword offset for nnnn.  My timings indicate it is slower.  (I think.)
181 ;    Combining u,v and du,dv into single longwords.
182 ;       The problem with this is you then must do a 16 bit operation to extract them, and you don't have enough
183 ;       instructions to separate a destination operand from being used by the next instruction.  It shaves out one
184 ;       register instruction (an add reg,reg), but adds a 16 bit operation, and the setup is more complicated.
185 ; usage:
186 ;       eax     work
187 ;       ebx     u coordinate
188 ;       ecx     delta u
189 ;       edx     delta v
190 ;       ebp     v coordinate
191 ;       esi     pointer to source bitmap
192 ;       edi     write address
193 %rep num_iters
194         mov     eax,ebp ; clear for 
195         add     ebp,edx ; update v coordinate
196         shr     eax,26  ; shift in v coordinate
197         shld    eax,ebx,6       ; shift in u coordinate while shifting up v coordinate
198         add     ebx,ecx ; update u coordinate
199         mov     al,[esi+eax]    ; get pixel from source bitmap
200         mov     [edi],al
201         inc     edi             ; XPARENT ADDED BY JOHN
202
203 ; inner loop if bitmaps are 256x256
204 ; your register usage is bogus, and you must clear ecx
205 ; fix your setup
206 ; this is only about 10% faster in the inner loop
207 ; this method would adapt to writing two pixels at a time better than
208 ; the 64x64 method because you wouldn't run out of registers
209 ; Note that this method assumes that both dv_dx and du_dx are in edx.
210 ; edx = vi|vf|ui|uf
211 ; where each field is 8 bits, vi = integer v coordinate, vf = fractional v coordinate, etc.
212 ;** add ebx,edx
213 ;** mov cl,bh
214 ;** shld cx,bx,8
215 ;** mov al,[esi+ecx]
216 ;** mov [edi],al
217 ;** inc edi
218 %endrep
219
220 _end1:
221
222 _none_to_do:    popa
223
224         ret
225
226 ; ----------------------------------------------------------------------------------------
227 ; if texture map has transparency, use this code.
228 transparent_texture:
229         test    dword [_loop_count],-1
230         je      _t_none_to_do
231 loop_transparent:
232         mov     eax,ebp ; clear for 
233         add     ebp,edx ; update v coordinate
234         shr     eax,26  ; shift in v coordinate
235         shld    eax,ebx,6       ; shift in u coordinate while shifting up v coordinate
236         add     ebx,ecx ; update u coordinate
237         mov     al,[esi+eax]    ; get pixel from source bitmap
238         cmp     al,255
239         je      transp
240         mov     [edi],al
241 transp: inc     edi             ; XPARENT ADDED BY JOHN
242
243         dec     dword [_loop_count]
244         jne     loop_transparent
245
246 _t_none_to_do:  popa
247         ret
248
249
250 ; This is the inner loop to write two pixels at a time
251 ; This is about 2.5% faster overall (on Mike's 66 MHz 80486 DX2, VLB)
252 ; You must write code to even align edi and do half as many iterations, and write
253 ; the beginning and ending extra pixels, if necessary.
254 ;       sub     eax,eax ; clear for 
255 ;       shld    eax,ebp,6       ; shift in v coordinate
256 ;       add     ebp,_fx_dv_dx   ; update v coordinate
257 ;       shld    eax,ebx,6       ; shift in u coordinate while shifting up v coordinate
258 ;       add     ebx,ecx ; update u coordinate
259 ;       mov     dl,[esi+eax]    ; get pixel from source bitmap
260 ;
261 ;       sub     eax,eax ; clear for 
262 ;       shld    eax,ebp,6       ; shift in v coordinate
263 ;       add     ebp,_fx_dv_dx   ; update v coordinate
264 ;       shld    eax,ebx,6       ; shift in u coordinate while shifting up v coordinate
265 ;       add     ebx,ecx ; update u coordinate
266 ;       mov     dh,[esi+eax]    ; get pixel from source bitmap
267 ;
268 ;       mov     [edi],dx
269 ;       add     edi,2
270