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