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