]> icculus.org git repositories - theoddone33/hheretic.git/blob - base/linear.asm
Optimized blit functions.
[theoddone33/hheretic.git] / base / linear.asm
1         .386
2         .MODEL  small
3         INCLUDE defs.inc
4
5
6 ;============================================================================
7 ;
8 ; unwound vertical scaling code
9 ;
10 ; eax   light table pointer, 0 lowbyte overwritten
11 ; ebx   all 0, low byte overwritten
12 ; ecx   fractional step value
13 ; edx   fractional scale value
14 ; esi   start of source pixels
15 ; edi   bottom pixel in screenbuffer to blit into
16 ;
17 ; ebx should be set to 0 0 0 dh to feed the pipeline
18 ;
19 ; The graphics wrap vertically at 128 pixels
20 ;============================================================================
21
22 .DATA
23
24 EXTRN   _centery:DWORD
25
26 SCALEDEFINE     MACRO   number
27         dd      vscale&number
28 ENDM
29
30         ALIGN   4
31 scalecalls      LABEL
32 LINE    =       0
33 REPT    SCREENHEIGHT+1
34         SCALEDEFINE     %LINE
35 LINE    =       LINE+1
36 ENDM
37
38
39 ;=================================
40
41
42 .CODE
43
44 ;================
45 ;
46 ; R_DrawColumn
47 ;
48 ;================
49
50 PROC   R_DrawColumn_
51 PUBLIC   R_DrawColumn_
52         PUSHR
53
54         mov             ebp,[_dc_yh]
55         mov             ebx,ebp
56         mov     edi,[_ylookup+ebx*4]
57         mov             ebx,[_dc_x]
58         add     edi,[_columnofs + ebx*4]
59
60         mov             eax,[_dc_yl]
61         sub     ebp,eax                    ; ebp = pixel count
62         or              ebp,ebp
63         js              done
64
65         mov     ecx,[_dc_iscale]
66
67         sub             eax,[_centery]
68         imul    ecx
69         mov             edx,[_dc_texturemid]
70         add             edx,eax
71         shl             edx,9                                                   ; 7 significant bits, 25 frac
72
73         shl             ecx,9                                                   ; 7 significant bits, 25 frac
74         mov     esi,[_dc_source]
75
76         mov     eax,[_dc_colormap]
77
78         xor     ebx,ebx
79         shld    ebx,edx,7                                               ; get address of first location
80         call    [scalecalls+4+ebp*4]
81
82 done:
83         POPR
84         ret
85
86 ;============ HIGH DETAIL ============
87
88 SCALELABEL      MACRO   number
89 vscale&number:
90 ENDM
91
92 LINE    =       SCREENHEIGHT
93 REPT SCREENHEIGHT-1
94         SCALELABEL      %LINE
95         mov     al,[esi+ebx]                    ; get source pixel
96         add     edx,ecx                         ; calculate next location
97         mov     al,[eax]                        ; translate the color
98 ;       xor             ebx,ebx
99 ;       shld    ebx,edx,7                      ; get address of next location
100         mov             ebx,edx
101         shr             ebx,25
102         mov     [edi-(LINE-1)*SCREENWIDTH],al   ; draw a pixel to the buffer
103 LINE    =       LINE-1
104 ENDM
105 vscale1:
106         mov     al,[esi+ebx]
107         mov     al,[eax]
108         mov     [edi],al
109 vscale0:
110         ret
111
112 ENDP
113
114
115
116 ;============================================================================
117 ;
118 ; unwound horizontal texture mapping code
119 ;
120 ; eax   lighttable
121 ; ebx   scratch register
122 ; ecx   position 6.10 bits x, 6.10 bits y
123 ; edx   step 6.10 bits x, 6.10 bits y
124 ; esi   start of block
125 ; edi   dest
126 ; ebp   fff to mask bx
127 ;
128 ; ebp should by preset from ebx / ecx before calling
129 ;============================================================================
130
131 OP_SHLD =       0fh
132
133
134 .DATA
135
136
137 MAPDEFINE     MACRO   number
138         dd      hmap&number
139 ENDM
140
141         ALIGN   4
142 mapcalls      LABEL
143 LINE    =       0
144 REPT    SCREENWIDTH+1
145         MAPDEFINE     %LINE
146 LINE    =       LINE+1
147 ENDM
148
149
150 callpoint       dd  0
151 returnpoint     dd      0
152
153
154 .CODE
155
156 ;================
157 ;
158 ; R_DrawSpan
159 ;
160 ; Horizontal texture mapping
161 ;
162 ;================
163
164
165 PROC   R_DrawSpan_
166 PUBLIC  R_DrawSpan_
167         PUSHR
168
169 IFE SKIPPRIMITIVES
170
171         mov     eax,[_ds_x1]
172         mov     ebx,[_ds_x2]
173         mov     eax,[mapcalls+eax*4]
174         mov     [callpoint],eax       ; spot to jump into unwound
175         mov     eax,[mapcalls+4+ebx*4]
176         mov     [returnpoint],eax     ; spot to patch a ret at
177         mov     BYTE PTR [eax], OP_RET
178
179 ;
180 ; build composite position
181 ;
182         mov     ecx,[_ds_xfrac]
183         shl     ecx,10
184         and     ecx,0ffff0000h
185         mov     eax,[_ds_yfrac]
186         shr     eax,6
187         and     eax,0ffffh
188         or      ecx,eax
189
190 ;
191 ; build composite step
192 ;
193         mov     edx,[_ds_xstep]
194         shl     edx,10
195         and     edx,0ffff0000h
196         mov     eax,[_ds_ystep]
197         shr     eax,6
198         and     eax,0ffffh
199         or      edx,eax
200
201         mov     esi,[_ds_source]
202
203         mov     edi,[_ds_y]
204         mov     edi,[_ylookup+edi*4]
205         add edi,[_columnofs]
206
207         mov     eax,[_ds_colormap]
208
209 ;
210 ; feed the pipeline and jump in
211 ;
212         mov             ebp,0fffh               ; used to mask off slop high bits from position
213         shld    ebx,ecx,22                              ; shift y units in
214         shld    ebx,ecx,6                               ; shift x units in
215         and             ebx,ebp                                 ; mask off slop bits
216         call    [callpoint]
217
218         mov     ebx,[returnpoint]
219         mov     BYTE PTR [ebx],OP_MOVAL         ; remove the ret patched in
220
221 ENDIF
222         POPR
223         ret
224
225
226 ;============= HIGH DETAIL ============
227
228 .CODE
229
230 MAPLABEL      MACRO   number
231 hmap&number:
232 ENDM
233
234 LINE    =      0
235 PCOL    =       0
236 REPT SCREENWIDTH/4
237 PLANE   =       0
238 REPT    4
239         MAPLABEL      %LINE
240 LINE    =       LINE + 1
241
242         mov     al,[esi+ebx]            ; get source pixel
243         shld    ebx,ecx,22                              ; shift y units in
244         shld    ebx,ecx,6                               ; shift x units in
245         mov     al,[eax]                ; translate color
246         and             ebx,ebp                                 ; mask off slop bits
247         add             ecx,edx                                 ; position += step
248         mov     [edi+PLANE+PCOL*4],al       ; write pixel
249 PLANE   =       PLANE + 1
250 ENDM
251 PCOL    =       PCOL + 1
252 ENDM
253 hmap320:
254         ret
255
256 ENDP
257
258 END