]> icculus.org git repositories - btb/d2x.git/blob - texmap/tmap_flt.asm
formatting
[btb/d2x.git] / texmap / tmap_flt.asm
1 ; $Id: tmap_flt.asm,v 1.2 2003-02-18 20:15:48 btb Exp $
2 ;THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 ;SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 ;END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ;ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 ;IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 ;SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 ;FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 ;CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 ;AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 ;COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 ;
13 ;
14 ; Flat shader derived from texture mapper (kind of slow)
15 ;
16 ; Old Log:
17 ; Revision 1.10  1995/02/20  18:22:53  john
18 ; Put all the externs in the assembly modules into tmap_inc.asm.
19 ; Also, moved all the C versions of the inner loops into a new module,
20 ; scanline.c.
21 ;
22 ; Revision 1.9  1995/02/20  17:08:51  john
23 ; Added code so that you can build the tmapper with no assembly!
24 ;
25 ; Revision 1.8  1994/12/02  23:29:21  mike
26 ; change jb/ja to jl/jg.
27 ;
28 ; Revision 1.7  1994/11/12  16:39:35  mike
29 ; jae to ja.
30 ;
31 ; Revision 1.6  1994/08/09  11:27:53  john
32 ; Added cthru mode.
33 ;
34 ; Revision 1.5  1994/07/08  17:43:11  john
35 ; Added flat-shaded-zbuffered polygon.
36 ;
37 ; Revision 1.4  1994/04/08  16:25:43  mike
38 ; optimize inner loop of flat shader.
39 ;
40 ; Revision 1.3  1994/03/31  08:34:20  mike
41 ; Optimized (well, speeded-up) inner loop for tmap-based flat shader.
42 ;
43 ; Revision 1.2  1993/11/22  10:24:57  mike
44 ; *** empty log message ***
45 ;
46 ; Revision 1.1  1993/09/08  17:29:46  mike
47 ; Initial revision
48 ;
49 ;
50 ;
51
52 [BITS 32]
53
54 global  _asm_tmap_scanline_flat
55 global  asm_tmap_scanline_flat
56
57 [SECTION .data]
58
59 %include        "tmap_inc.asm"
60
61 [SECTION .text]
62
63 ; --------------------------------------------------------------------------------------------------
64 ; Enter:
65 ;       _xleft  fixed point left x coordinate
66 ;       _xright fixed point right x coordinate
67 ;       _y      fixed point y coordinate
68 ;**;    _pixptr address of source pixel map
69
70 ;   for (x = (int) xleft; x <= (int) xright; x++) {
71 ;      _setcolor(read_pixel_from_tmap(srcb,((int) (u/z)) & 63,((int) (v/z)) & 63));
72 ;      _setpixel(x,y);
73 ;
74 ;      z += dz_dx;
75 ;   }
76
77 align 4
78 _asm_tmap_scanline_flat:
79 asm_tmap_scanline_flat:
80         pusha
81
82 ; Setup for loop:       _loop_count  iterations = (int) xright - (int) xleft
83 ;**;    esi     source pixel pointer = pixptr
84 ;       edi     initial row pointer = y*320+x
85
86 ; set esi = pointer to start of texture map data
87 ;**     mov     esi,_pixptr
88
89 ; set edi = address of first pixel to modify
90         mov     edi,[_fx_y]
91         cmp     edi,[_window_bottom]
92         ja      near _none_to_do
93
94         imul    edi,[_bytes_per_row]
95         mov     eax,[_fx_xleft]
96         test    eax, eax
97         jns     eax_ok
98         sub     eax,eax
99 eax_ok:
100         add     edi,eax
101         add     edi,[_write_buffer]
102
103 ; set _loop_count = # of iterations
104         mov     eax,[_fx_xright]
105
106         cmp     eax,[_window_right]
107         jl      eax_ok1
108         mov     eax,[_window_right]
109 eax_ok1:        cmp     eax,[_window_left]
110         jg      eax_ok2
111         mov     eax,[_window_left]
112 eax_ok2:
113
114         mov     ebx,[_fx_xleft]
115         sub     eax,ebx
116         js      _none_to_do
117         cmp     eax,[_window_width]
118         jbe     _ok_to_do
119         mov     eax,[_window_width]
120         dec     eax
121 _ok_to_do:
122         mov     ecx,eax
123
124 ; edi = destination pixel pointer
125         cmp     dword [_tmap_flat_cthru_table], 0
126         jne     do_flat_cthru
127
128         mov     al,[_tmap_flat_color]
129
130 ; word align
131         inc     ecx
132         test    edi,1
133         je      edi_even
134         mov     [edi],al
135         inc     edi
136         dec     ecx
137         je      _none_to_do
138 edi_even:       shr     ecx,1
139         je      _no_full_words
140         mov     ah,al
141         rep     stosw
142 _no_full_words: adc     ecx,ecx ; if cy set, then write one more pixel (ecx == 0)
143         rep     stosb   ; write 0 or 1 pixel
144
145 _none_to_do:    popa
146         ret
147
148 do_flat_cthru:
149         mov     esi, [_tmap_flat_cthru_table]
150         xor     eax, eax
151         cmp     ecx, 0
152         je      _none_to_do
153         ; edi = dest, esi = table, ecx = count
154
155 flat_cthru_loop:
156         mov     al, [edi]    ; get already drawn pixel
157         mov     al, [eax+esi]   ; xlat thru cthru table
158         mov     [edi],al     ; write it
159         inc     edi
160         dec     ecx
161         jnz     flat_cthru_loop
162         popa
163         ret
164