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