]> icculus.org git repositories - btb/d2x.git/blob - texmap/tmapfade.asm
Use PhysicsFS for making the hoard ham.
[btb/d2x.git] / texmap / tmapfade.asm
1 ; $Id: tmapfade.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 ; .
15 ;
16 ;
17 [BITS 32]
18 global  _asm_tmap_scanline_shaded
19 global  asm_tmap_scanline_shaded
20
21 [SECTION .data]
22
23 %include        "tmap_inc.asm"
24 _loop_count             dd      0
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 align 4
42
43 _asm_tmap_scanline_shaded:
44 asm_tmap_scanline_shaded:
45 ;        push fs
46         pusha
47
48 ;        mov     fs, [_gr_fade_table_selector] ; DPH: No selectors in windows
49
50 ; Setup for loop:       _loop_count  iterations = (int) xright - (int) xleft
51 ;       edi     initial row pointer = y*320+x
52
53 ; set edi = address of first pixel to modify
54         mov     edi,[_fx_y]
55  cmp edi,_window_bottom
56  jae near _none_to_do
57
58         imul    edi,[_bytes_per_row]
59         mov     eax,[_fx_xleft]
60         test    eax,eax
61         jns     eax_ok
62         sub     eax,eax
63 eax_ok:
64         add     edi,eax
65         add     edi,[_write_buffer]
66
67 ; set _loop_count = # of iterations
68         mov     eax,[_fx_xright]
69
70         cmp     eax,[_window_right]
71         jl      eax_ok1
72         mov     eax,[_window_right]
73 eax_ok1:        cmp     eax,[_window_left]
74         jg      eax_ok2
75         mov     eax,[_window_left]
76 eax_ok2:
77         mov     ebx,[_fx_xleft]
78         sub     eax,ebx
79         js      near _none_to_do
80         cmp     eax,[_window_width]
81         jbe     _ok_to_do
82         mov     eax,[_window_width]
83 _ok_to_do:
84         mov     [_loop_count], eax
85
86         mov     ecx, 0
87         mov     ch,[_tmap_flat_shade_value]
88         and     ch, 31
89
90 ;_size = (_end1 - _start1)/num_iters
91         mov     eax,num_iters-1
92         sub     eax,[_loop_count]
93         jns     j_eax_ok1
94         inc     eax     ; sort of a hack, but we can get -1 here and want to be graceful
95         jns     j_eax_ok1       ; if we jump, we had -1, which is kind of ok, if not, we int 3
96         int     3       ; oops, going to jump behind _start1, very bad...
97         sub     eax,eax ; ok to continue
98 j_eax_ok1:      imul    eax,eax,(_end1 - _start1)/num_iters
99         add     eax, _start1        ;originally offset _start1
100         jmp     eax
101
102         align   4
103 _start1:
104
105 %rep num_iters
106         mov     cl, [edi]               ; get pixel
107         mov     al, [_gr_fade_table + ecx]            ; darken pixel
108         mov     [edi], al               ; write pixel
109         inc     edi                     ; goto next pixel
110 %endrep
111 _end1:
112
113 _none_to_do:    popa
114 ;                pop     fs
115         ret
116