]> icculus.org git repositories - btb/d2x.git/blob - texmap/tmap_flt.asm
added cvsignore
[btb/d2x.git] / texmap / tmap_flt.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_flt.asm,v $
13 ; $Revision: 1.1.1.1 $
14 ; $Author: bradleyb $
15 ; $Date: 2001-01-19 03:30:16 $
16 ;
17 ; Flat shader derived from texture mapper (kind of slow)
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.10  1995/02/20  18:22:53  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.9  1995/02/20  17:08:51  john
29 ; Added code so that you can build the tmapper with no assembly!
30 ;
31 ; Revision 1.8  1994/12/02  23:29:21  mike
32 ; change jb/ja to jl/jg.
33 ;
34 ; Revision 1.7  1994/11/12  16:39:35  mike
35 ; jae to ja.
36 ;
37 ; Revision 1.6  1994/08/09  11:27:53  john
38 ; Added cthru mode.
39 ;
40 ; Revision 1.5  1994/07/08  17:43:11  john
41 ; Added flat-shaded-zbuffered polygon.
42 ;
43 ; Revision 1.4  1994/04/08  16:25:43  mike
44 ; optimize inner loop of flat shader.
45 ;
46 ; Revision 1.3  1994/03/31  08:34:20  mike
47 ; Optimized (well, speeded-up) inner loop for tmap-based flat shader.
48 ;
49 ; Revision 1.2  1993/11/22  10:24:57  mike
50 ; *** empty log message ***
51 ;
52 ; Revision 1.1  1993/09/08  17:29:46  mike
53 ; Initial revision
54 ;
55 ;
56 ;
57
58 [BITS 32]
59
60 global  _asm_tmap_scanline_flat
61 global  asm_tmap_scanline_flat
62
63 [SECTION .data]
64
65 %include        "tmap_inc.asm"
66
67 [SECTION .text]
68
69 ; --------------------------------------------------------------------------------------------------
70 ; Enter:
71 ;       _xleft  fixed point left x coordinate
72 ;       _xright fixed point right x coordinate
73 ;       _y      fixed point y coordinate
74 ;**;    _pixptr address of source pixel map
75
76 ;   for (x = (int) xleft; x <= (int) xright; x++) {
77 ;      _setcolor(read_pixel_from_tmap(srcb,((int) (u/z)) & 63,((int) (v/z)) & 63));
78 ;      _setpixel(x,y);
79 ;
80 ;      z += dz_dx;
81 ;   }
82
83 align 4
84 _asm_tmap_scanline_flat:
85 asm_tmap_scanline_flat:
86         pusha
87
88 ; Setup for loop:       _loop_count  iterations = (int) xright - (int) xleft
89 ;**;    esi     source pixel pointer = pixptr
90 ;       edi     initial row pointer = y*320+x
91
92 ; set esi = pointer to start of texture map data
93 ;**     mov     esi,_pixptr
94
95 ; set edi = address of first pixel to modify
96         mov     edi,[_fx_y]
97         cmp     edi,[_window_bottom]
98         ja      near _none_to_do
99
100         imul    edi,[_bytes_per_row]
101         mov     eax,[_fx_xleft]
102         test    eax, eax
103         jns     eax_ok
104         sub     eax,eax
105 eax_ok:
106         add     edi,eax
107         add     edi,[_write_buffer]
108
109 ; set _loop_count = # of iterations
110         mov     eax,[_fx_xright]
111
112         cmp     eax,[_window_right]
113         jl      eax_ok1
114         mov     eax,[_window_right]
115 eax_ok1:        cmp     eax,[_window_left]
116         jg      eax_ok2
117         mov     eax,[_window_left]
118 eax_ok2:
119
120         mov     ebx,[_fx_xleft]
121         sub     eax,ebx
122         js      _none_to_do
123         cmp     eax,[_window_width]
124         jbe     _ok_to_do
125         mov     eax,[_window_width]
126         dec     eax
127 _ok_to_do:
128         mov     ecx,eax
129
130 ; edi = destination pixel pointer
131         cmp     dword [_tmap_flat_cthru_table], 0
132         jne     do_flat_cthru
133
134         mov     al,[_tmap_flat_color]
135
136 ; word align
137         inc     ecx
138         test    edi,1
139         je      edi_even
140         mov     [edi],al
141         inc     edi
142         dec     ecx
143         je      _none_to_do
144 edi_even:       shr     ecx,1
145         je      _no_full_words
146         mov     ah,al
147         rep     stosw
148 _no_full_words: adc     ecx,ecx ; if cy set, then write one more pixel (ecx == 0)
149         rep     stosb   ; write 0 or 1 pixel
150
151 _none_to_do:    popa
152         ret
153
154 do_flat_cthru:
155         mov     esi, [_tmap_flat_cthru_table]
156         xor     eax, eax
157         cmp     ecx, 0
158         je      _none_to_do
159         ; edi = dest, esi = table, ecx = count
160
161 flat_cthru_loop:
162         mov     al, [edi]    ; get already drawn pixel
163         mov     al, [eax+esi]   ; xlat thru cthru table
164         mov     [edi],al     ; write it
165         inc     edi
166         dec     ecx
167         jnz     flat_cthru_loop
168         popa
169         ret
170