]> icculus.org git repositories - btb/d2x.git/blob - texmap/tmapfade.asm
copied files from d1x
[btb/d2x.git] / texmap / tmapfade.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/tmapfade.asm,v $
13 ; $Revision: 1.1.1.1 $
14 ; $Author: bradleyb $
15 ; $Date: 2001-01-19 03:30:16 $
16 ;
17 ; .
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.6  1995/02/20  18:23:01  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.5  1995/02/20  17:09:15  john
29 ; Added code so that you can build the tmapper with no assembly!
30 ;
31 ; Revision 1.4  1994/12/02  23:29:36  mike
32 ; change jb/ja to jl/jg.
33 ;
34 ; Revision 1.3  1994/11/30  00:57:36  mike
35 ; *** empty log message ***
36 ;
37 ; Revision 1.2  1994/10/06  18:38:49  john
38 ; Added the ability to fade a scanline by calling gr_upoly_tmap
39 ; with Gr_scanline_darkening_level with a value < MAX_FADE_LEVELS.
40 ;
41 ; Revision 1.1  1994/10/06  18:04:42  john
42 ; Initial revision
43 ;
44 ;
45 [BITS 32]
46 global  _asm_tmap_scanline_shaded
47 global  asm_tmap_scanline_shaded
48
49 [SECTION .data]
50
51 %include        "tmap_inc.asm"
52 _loop_count             dd      0
53
54 [SECTION .text]
55
56 ; --------------------------------------------------------------------------------------------------
57 ; Enter:
58 ;       _xleft  fixed point left x coordinate
59 ;       _xright fixed point right x coordinate
60 ;       _y      fixed point y coordinate
61 ;**;    _pixptr address of source pixel map
62
63 ;   for (x = (int) xleft; x <= (int) xright; x++) {
64 ;      _setcolor(read_pixel_from_tmap(srcb,((int) (u/z)) & 63,((int) (v/z)) & 63));
65 ;      _setpixel(x,y);
66 ;
67 ;      z += dz_dx;
68 ;   }
69 align 4
70
71 _asm_tmap_scanline_shaded:
72 asm_tmap_scanline_shaded:
73 ;        push fs
74         pusha
75
76 ;        mov     fs, [_gr_fade_table_selector] ; DPH: No selectors in windows
77
78 ; Setup for loop:       _loop_count  iterations = (int) xright - (int) xleft
79 ;       edi     initial row pointer = y*320+x
80
81 ; set edi = address of first pixel to modify
82         mov     edi,[_fx_y]
83  cmp edi,_window_bottom
84  jae near _none_to_do
85
86         imul    edi,[_bytes_per_row]
87         mov     eax,[_fx_xleft]
88         test    eax,eax
89         jns     eax_ok
90         sub     eax,eax
91 eax_ok:
92         add     edi,eax
93         add     edi,[_write_buffer]
94
95 ; set _loop_count = # of iterations
96         mov     eax,[_fx_xright]
97
98         cmp     eax,[_window_right]
99         jl      eax_ok1
100         mov     eax,[_window_right]
101 eax_ok1:        cmp     eax,[_window_left]
102         jg      eax_ok2
103         mov     eax,[_window_left]
104 eax_ok2:
105         mov     ebx,[_fx_xleft]
106         sub     eax,ebx
107         js      near _none_to_do
108         cmp     eax,[_window_width]
109         jbe     _ok_to_do
110         mov     eax,[_window_width]
111 _ok_to_do:
112         mov     [_loop_count], eax
113
114         mov     ecx, 0
115         mov     ch,[_tmap_flat_shade_value]
116         and     ch, 31
117
118 ;_size = (_end1 - _start1)/num_iters
119         mov     eax,num_iters-1
120         sub     eax,[_loop_count]
121         jns     j_eax_ok1
122         inc     eax     ; sort of a hack, but we can get -1 here and want to be graceful
123         jns     j_eax_ok1       ; if we jump, we had -1, which is kind of ok, if not, we int 3
124         int     3       ; oops, going to jump behind _start1, very bad...
125         sub     eax,eax ; ok to continue
126 j_eax_ok1:      imul    eax,eax,(_end1 - _start1)/num_iters
127         add     eax, _start1        ;originally offset _start1
128         jmp     eax
129
130         align   4
131 _start1:
132
133 %rep num_iters
134         mov     cl, [edi]               ; get pixel
135         mov     al, [_gr_fade_table + ecx]            ; darken pixel
136         mov     [edi], al               ; write pixel
137         inc     edi                     ; goto next pixel
138 %endrep
139 _end1:
140
141 _none_to_do:    popa
142 ;                pop     fs
143         ret
144