]> icculus.org git repositories - btb/d2x.git/blob - texmap/tmap_flt.asm
use the orientation parameter of g3_draw_bitmap
[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 ;
13 ; Flat shader derived from texture mapper (kind of slow)
14 ;
15 ;
16
17 [BITS 32]
18
19 global  _asm_tmap_scanline_flat
20 global  asm_tmap_scanline_flat
21
22 [SECTION .data]
23
24 %include        "tmap_inc.asm"
25
26 [SECTION .text]
27
28 ; --------------------------------------------------------------------------------------------------
29 ; Enter:
30 ;       _xleft  fixed point left x coordinate
31 ;       _xright fixed point right x coordinate
32 ;       _y      fixed point y coordinate
33 ;**;    _pixptr address of source pixel map
34
35 ;   for (x = (int) xleft; x <= (int) xright; x++) {
36 ;      _setcolor(read_pixel_from_tmap(srcb,((int) (u/z)) & 63,((int) (v/z)) & 63));
37 ;      _setpixel(x,y);
38 ;
39 ;      z += dz_dx;
40 ;   }
41
42 align 4
43 _asm_tmap_scanline_flat:
44 asm_tmap_scanline_flat:
45         pusha
46
47 ; Setup for loop:       _loop_count  iterations = (int) xright - (int) xleft
48 ;**;    esi     source pixel pointer = pixptr
49 ;       edi     initial row pointer = y*320+x
50
51 ; set esi = pointer to start of texture map data
52 ;**     mov     esi,_pixptr
53
54 ; set edi = address of first pixel to modify
55         mov     edi,[_fx_y]
56         cmp     edi,[_window_bottom]
57         ja      near _none_to_do
58
59         imul    edi,[_bytes_per_row]
60         mov     eax,[_fx_xleft]
61         test    eax, eax
62         jns     eax_ok
63         sub     eax,eax
64 eax_ok:
65         add     edi,eax
66         add     edi,[_write_buffer]
67
68 ; set _loop_count = # of iterations
69         mov     eax,[_fx_xright]
70
71         cmp     eax,[_window_right]
72         jl      eax_ok1
73         mov     eax,[_window_right]
74 eax_ok1:        cmp     eax,[_window_left]
75         jg      eax_ok2
76         mov     eax,[_window_left]
77 eax_ok2:
78
79         mov     ebx,[_fx_xleft]
80         sub     eax,ebx
81         js      _none_to_do
82         cmp     eax,[_window_width]
83         jbe     _ok_to_do
84         mov     eax,[_window_width]
85         dec     eax
86 _ok_to_do:
87         mov     ecx,eax
88
89 ; edi = destination pixel pointer
90         cmp     dword [_tmap_flat_cthru_table], 0
91         jne     do_flat_cthru
92
93         mov     al,[_tmap_flat_color]
94
95 ; word align
96         inc     ecx
97         test    edi,1
98         je      edi_even
99         mov     [edi],al
100         inc     edi
101         dec     ecx
102         je      _none_to_do
103 edi_even:       shr     ecx,1
104         je      _no_full_words
105         mov     ah,al
106         rep     stosw
107 _no_full_words: adc     ecx,ecx ; if cy set, then write one more pixel (ecx == 0)
108         rep     stosb   ; write 0 or 1 pixel
109
110 _none_to_do:    popa
111         ret
112
113 do_flat_cthru:
114         mov     esi, [_tmap_flat_cthru_table]
115         xor     eax, eax
116         cmp     ecx, 0
117         je      _none_to_do
118         ; edi = dest, esi = table, ecx = count
119
120 flat_cthru_loop:
121         mov     al, [edi]    ; get already drawn pixel
122         mov     al, [eax+esi]   ; xlat thru cthru table
123         mov     [edi],al     ; write it
124         inc     edi
125         dec     ecx
126         jnz     flat_cthru_loop
127         popa
128         ret
129