[go: up one dir, main page]

Menu

[r15]: / engine / darken_a.asm  Maximize  Restore  History

Download this file

367 lines (274 with data), 6.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
;
; Assembler versions of the darkness routines
;
[BITS 32]
[SECTION .text]
; Declare public symbols
GLOBAL _darken_x86_32mmx
GLOBAL darken_x86_32mmx
GLOBAL _darken_x86_32smmx
GLOBAL darken_x86_32smmx
GLOBAL _darken_x86_16
GLOBAL darken_x86_16
GLOBAL _darken_x86_16s
GLOBAL darken_x86_16s
GLOBAL _darken_x86_8
GLOBAL darken_x86_8
GLOBAL _darken_x86_8s
GLOBAL darken_x86_8s
GLOBAL _darken_x86_blit8
GLOBAL darken_x86_blit8
GLOBAL _darken_x86_blit16
GLOBAL darken_x86_blit16
GLOBAL _darken_x86_blit32
GLOBAL darken_x86_blit32
; MMX darkness code
_darken_x86_32mmx:
darken_x86_32mmx:
push ebp
mov ebp,esp
pushad
emms
mov edi,[ebp+8] ;Dest
mov esi,[ebp+12] ;Source
mov ecx,[ebp+16] ;Len
darkloop32:
mov al,[esi] ; get the source pixel
; shl al,3 ; Expand to 8 bits
mov edx,[edi] ; get the dest pixel
; Replicate source level throughout EAX
mov ah,al
shl eax,8
mov al,ah
shl eax,8
mov al,ah
; Do the thing
movd mm0,edx
movd mm1,eax
psubusb mm0,mm1
movd eax,mm0
mov [edi],eax ; Write output
; Next pixel
add edi,4
inc esi ; inc byte source
loop darkloop32
emms
popad
pop ebp
ret
; Single colour (not using a darkmap)
_darken_x86_32smmx:
darken_x86_32smmx:
push ebp
mov ebp,esp
pushad
emms
mov edi,[ebp+8] ;Dest
mov esi,[ebp+12] ;Source colour (not address)
mov ecx,[ebp+16] ;Len
darkloop32s:
mov eax,esi ; get the source pixel
mov edx,[edi] ; get the dest pixel
; Replicate source level throughout EAX
mov ah,al
shl eax,8
mov al,ah
shl eax,8
mov al,ah
; Do the thing
movd mm0,edx
movd mm1,eax
psubusb mm0,mm1
movd eax,mm0
; We use colour separation in the roof projector, and 0 is transparent
; So we need to make it non-zero unless it is supposed to be transparent
test eax,0xffffffff ; Is it zero?
jnz dark32noclip
test edx,0xffffffff ; If it's meant to be 0, don't adjust it
jz dark32noclip
or eax,0x01000000
dark32noclip:
mov [edi],eax ; Write output
; Next pixel
add edi,4
loop darkloop32s
emms
popad
pop ebp
ret
; 16bpp darkness code
_darken_x86_16:
darken_x86_16:
push ebp
mov ebp,esp
pushad
mov edi,[ebp+8] ;Dest
mov esi,[ebp+12] ;Source
mov ecx,[ebp+16] ;Len
mov ebx,[ebp+20] ;LUT address
xor edx,edx ; Clear high bits
darkloop16:
mov al,[esi] ; get the source pixel
mov dx,[edi] ; get the dest pixel
; Consult lookuptable to get correct lighting value
; shl 13 instead of shl 16 converts light level to 5-bit, effective shr 3
; ax = I32_clut[(ax*65536)+dx]
and eax,0x000000f8 ; ax = (ax)
shl eax,13 ; ax = (ax * 65536)
add eax,edx ; ax = (ax * 65536)+dx
shl eax,1 ; align to 16 bit array
add eax,ebx ; I32_clut[(ax * 65536)+dx]
mov ax,[eax] ; ax = I32_clut[(ax * 65536)+dx]
mov [edi],ax ; Write output
inc edi ; inc word output
inc edi
inc esi ; inc byte source
loop darkloop16
popad
pop ebp
ret
; Single colour (not using a darkmap)
_darken_x86_16s:
darken_x86_16s:
push ebp
mov ebp,esp
pushad
mov edi,[ebp+8] ;Dest
mov esi,[ebp+12] ;Source colour (not address)
mov ecx,[ebp+16] ;Len
mov ebx,[ebp+20] ;LUT address
xor edx,edx ; Clear high bits
darkloop16s:
mov eax,esi ; get the source pixel
mov dx,[edi] ; get the dest pixel
; Consult lookuptable to get correct lighting value
; shl 13 instead of shl 16 converts light level to 5-bit, effective shr 3
; ax = I32_clut[(ax*65536)+dx]
and eax,0x000000f8 ; ax = (ax)
shl eax,13 ; ax = (ax * 65536)
add eax,edx ; ax = (ax * 65536)+dx
shl eax,1 ; align to 16 bit array
add eax,ebx ; I32_clut[(ax * 65536)+dx]
mov ax,[eax] ; ax = I32_clut[(ax * 65536)+dx]
mov [edi],ax ; Write output
inc edi ; inc word output
inc edi
loop darkloop16s
popad
pop ebp
ret
; 8bpp darkness code
_darken_x86_8:
darken_x86_8:
push ebp
mov ebp,esp
pushad
mov edi,[ebp+8] ;Dest
mov esi,[ebp+12] ;Source
mov ecx,[ebp+16] ;Len
mov ebx,[ebp+20] ;LUT address
xor edx,edx ; Clear high bits
darkloop8:
mov ah,[esi] ; get the source pixel
mov al,[edi] ; get the dest pixel
; Consult lookuptable to get correct lighting value
and eax,0x0000ffff ; Clear to 64k space
add eax,ebx ; Add LUT base
mov al,[eax] ; Get colour from table
mov [edi],al ; Write output
inc edi ; inc byte output
inc esi ; inc byte source
loop darkloop8
popad
pop ebp
ret
_darken_x86_8s:
darken_x86_8s:
push ebp
mov ebp,esp
pushad
mov edi,[ebp+8] ;Dest
mov esi,[ebp+12] ;Source colour (not address)
mov ecx,[ebp+16] ;Len
mov ebx,[ebp+20] ;LUT address
xor edx,edx ; Clear high bits
shl esi,8 ; move to AH position
; Single colour (not using a darkmap)
darkloop8s:
mov eax,esi ; get the source pixel (This is already in AH position)
mov al,[edi] ; get the dest pixel
; Consult lookuptable to get correct lighting value
and eax,0x0000ffff ; Clear to 64k space
add eax,ebx ; Add LUT base
mov al,[eax] ; Get colour from table
mov [edi],al ; Write output
inc edi ; inc byte output
loop darkloop8s
popad
pop ebp
ret
; Bitmap Combining
; 8bpp
_darken_x86_blit8:
darken_x86_blit8:
push ebp
mov ebp,esp
pushad
mov edi,[ebp+8] ;Dest
mov esi,[ebp+12] ;Source
mov ecx,[ebp+16] ;Len
blitloop8:
lodsb
test al,0xff
jz blitskip8
mov [edi],al
blitskip8:
inc edi
loop blitloop8
popad
pop ebp
ret
; 16bpp
_darken_x86_blit16:
darken_x86_blit16:
push ebp
mov ebp,esp
pushad
mov edi,[ebp+8] ;Dest
mov esi,[ebp+12] ;Source
mov ecx,[ebp+16] ;Len
blitloop16:
lodsw
test ax,0xffff
jz blitskip16
mov [edi],ax
blitskip16:
inc edi
inc edi
loop blitloop16
popad
pop ebp
ret
; 32bpp
_darken_x86_blit32:
darken_x86_blit32:
push ebp
mov ebp,esp
pushad
mov edi,[ebp+8] ;Dest
mov esi,[ebp+12] ;Source
mov ecx,[ebp+16] ;Len
blitloop32:
lodsd
test eax,0xffffffff
jz blitskip32
mov [edi],eax
blitskip32:
inc edi
inc edi
inc edi
inc edi
loop blitloop32
popad
pop ebp
ret