]> icculus.org git repositories - btb/d2x.git/blob - 2d/scalea.asm
draw all gauges properly when using the cockpit in d2x-gl, including the energy bars...
[btb/d2x.git] / 2d / scalea.asm
1 ; $ Id: $
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 ; Asm inner loop for scaler.
15
16
17
18
19
20 [BITS 32]
21
22 [SECTION .data]
23
24         align   4
25         
26
27         global _scale_trans_color
28         global _scale_error_term
29         global _scale_initial_pixel_count
30         global _scale_adj_up
31         global _scale_adj_down
32         global _scale_final_pixel_count
33         global _scale_ydelta_minus_1
34         global _scale_whole_step
35         global _scale_source_ptr
36         global _scale_dest_ptr
37
38                 
39         _scale_trans_color              db      0
40         _scale_error_term               dd      0
41         _scale_initial_pixel_count      dd      0
42         _scale_adj_up                   dd      0
43         _scale_adj_down                 dd      0
44         _scale_final_pixel_count        dd      0
45         _scale_ydelta_minus_1           dd      0
46         _scale_whole_step               dd      0
47         _scale_source_ptr               dd      0
48         _scale_dest_ptr                 dd      0
49         _scale_cc_jump_spot             dd      0
50         _scale_slice_length_1           dd      0
51         _scale_slice_length_2           dd      0
52
53 [SECTION .text]
54
55 global _rls_stretch_scanline_asm
56
57 _rls_stretch_scanline_asm:
58                 cld
59                 pusha
60                 mov     esi, [_scale_source_ptr]
61                 mov     edi, [_scale_dest_ptr]
62                 mov     edx, [_scale_ydelta_minus_1]
63                 mov     ebx, [_scale_whole_step]
64                 mov     ah,  [_scale_trans_color]
65                 mov     ebp, [_scale_error_term]
66
67                 mov     ecx, [_scale_initial_pixel_count]
68                 lodsb
69                 cmp     al, ah
70                 je      first_pixel_transparent
71                 rep     stosb
72                 jmp     next_pixel
73
74 first_pixel_transparent:
75                 add     edi, ecx
76                 jmp     next_pixel
77
78 skip_this_pixel:        add     edi, ecx
79                         dec     edx
80                         jz      done
81
82 next_pixel:             lodsb                           ; get next source pixel
83                         mov     ecx, ebx                                        
84                         add     ebp, [_scale_adj_up]
85                         jle     no_inc_error_term
86                         inc     ecx
87                         sub     ebp, [_scale_adj_down]
88 no_inc_error_term:                                              
89                         cmp     al, ah
90                         je      skip_this_pixel
91                         rep     stosb                   ; write source pixel to n locations
92                         dec     edx
93                         jnz     next_pixel
94
95 done:                   lodsb
96                         cmp     al, ah
97                         je      exit_sub
98                         mov     ecx, [_scale_final_pixel_count]
99                         rep     stosb
100
101 exit_sub:
102                         popa
103                         ret
104
105 global _scale_do_cc_scanline
106 global _rls_do_cc_setup_asm
107
108 _scale_do_cc_scanline:
109         cld
110         pusha
111         mov     esi, [_scale_source_ptr]
112         mov     edi, [_scale_dest_ptr]
113         mov     ah,  [_scale_trans_color]
114         mov     ebx, [_scale_slice_length_1]
115         mov     edx, [_scale_slice_length_2]
116
117         mov     ecx, [_scale_initial_pixel_count]
118
119         ; Do the first texture pixel
120         mov     ecx, [_scale_initial_pixel_count]
121         lodsb
122         cmp     al, ah
123         je      @1
124         rep     stosb
125 @1:     add     edi, ecx
126
127         mov     ecx, [_scale_cc_jump_spot]
128         jmp     ecx
129
130         ; This is the compiled code to do the middle pixels...
131 scale_cc_start:         mov     al, [esi]
132 scale_cc_changer:       db      08bh, 0cbh ;mov     ecx, ebx        ;<==== CODE CHANGES TO EBX OR EDX !!!!!!
133                         inc     esi
134                         cmp     al, ah
135                         je      @2
136                         rep     stosb
137                 @2:     add     edi, ecx
138 scale_cc_end:
139
140 %macro repproc 0
141                         mov     al, [esi]
142                         db      08bh, 0cbh ;mov     ecx, ebx        ;<==== CODE CHANGES TO EBX OR EDX !!!!!!
143                         inc     esi
144                         cmp     al, ah
145                         je      %%skip
146                         rep     stosb
147 %%skip:                 add     edi, ecx
148 %endmacro
149
150 %rep 319
151 repproc
152 %endrep
153 last_cc_instruction:
154
155         mov     ecx, [_scale_final_pixel_count]
156         lodsb
157         cmp     al, ah
158         je      last_one_transparent
159         rep     stosb
160 last_one_transparent:
161
162         popa
163         ret
164
165 _rls_do_cc_setup_asm:
166
167                 pusha
168
169                 mov     ebx, [_scale_whole_step]
170                 mov     [_scale_slice_length_1], ebx
171                 inc     ebx
172                 mov     [_scale_slice_length_2], ebx
173
174                 mov     ebp, [_scale_error_term]
175                 mov     edx, [_scale_ydelta_minus_1]
176
177                 mov     ebx,  scale_cc_end
178                 sub     ebx,  scale_cc_start      ; ebx = distance to next changer inst.
179
180                 mov     eax, [_scale_ydelta_minus_1]
181
182                 
183                 imul    eax, ebx                ; eax = sizeof 1 iteration * numiterations.
184                                                 
185                 mov     edi,  last_cc_instruction
186                 sub     edi, eax                ; edi = address of first iteration that we need
187                                                 ;       to jump to
188                 mov     [_scale_cc_jump_spot], edi
189
190                 mov     ecx,  scale_cc_changer
191                 sub     ecx,  scale_cc_start      ; ecx = distance from start to to next changer inst.
192                 
193                 add     edi, ecx
194
195 next_pixel1:            add     ebp, [_scale_adj_up]
196                         jle     no_inc_error_term1
197                         ; Modify code in scale_do_cc_scanline_ to write 'edx' pixels
198                 mov     al, byte [edi]
199                 cmp     al, 08bh
200                 jne     BigError
201                         mov     word[edi], 0CA8Bh  ; 0x8BCA = mov ecx, edx
202                         add     edi, ebx                
203                         sub     ebp, [_scale_adj_down]
204                         dec     edx
205                         jnz     next_pixel1
206                         jmp     done1
207
208 no_inc_error_term1:     ; Modify code in scale_do_cc_scanline_ to write 'ebx' pixels
209                 mov     al, byte [edi]
210                 cmp     al, 08bh
211                 jne     BigError
212                         mov     word [edi], 0CB8Bh  ; 0x8BCB = mov ecx, ebx
213                         add     edi, ebx                
214                         dec     edx
215                         jnz     next_pixel1
216
217 done1:          popa
218                 ret
219
220 BigError:       int 3   ; Stop, buddy!!
221                 popa
222                 ret