Subversion Repositories Kolibri OS

Rev

Rev 9172 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8210 maxcodehac 1
;
2
; x86 format converters for HERMES
3
; Copyright (c) 1998 Glenn Fielder (gaffer@gaffer.org)
4
; This source code is licensed under the GNU LGPL
5
;
6
; Please refer to the file COPYING.LIB contained in the distribution for
7
; licensing conditions
8
;
9
; Routines adjusted for Hermes by Christian Nentwich (brn@eleet.mcb.at)
10
; Used with permission.
11
;
12
 
13
BITS 32
14
 
9172 turbocat 15
%include "common.inc"
8210 maxcodehac 16
 
9172 turbocat 17
SDL_FUNC _ConvertX86p16_16BGR565
18
SDL_FUNC _ConvertX86p16_16RGB555
19
SDL_FUNC _ConvertX86p16_16BGR555
20
SDL_FUNC _ConvertX86p16_8RGB332
21
 
9202 turbocat 22
SDL_FUNC ConvertX86p16_16BGR565
23
SDL_FUNC ConvertX86p16_16RGB555
24
SDL_FUNC ConvertX86p16_16BGR555
25
SDL_FUNC ConvertX86p16_8RGB332
26
 
27
 
8210 maxcodehac 28
EXTERN _ConvertX86
9202 turbocat 29
EXTERN ConvertX86
8210 maxcodehac 30
 
31
SECTION .text
32
 
9202 turbocat 33
ConvertX86p16_16BGR565:
8210 maxcodehac 34
_ConvertX86p16_16BGR565:
35
 
36
    ; check short
37
    cmp ecx,BYTE 16
38
    ja .L3
39
 
40
 
9172 turbocat 41
.L1: ; short loop
8210 maxcodehac 42
    mov al,[esi]
43
    mov ah,[esi+1]
44
    mov ebx,eax
45
    mov edx,eax
46
    shr eax,11
47
    and eax,BYTE 11111b
48
    and ebx,11111100000b
49
    shl edx,11
50
    add eax,ebx
51
    add eax,edx
52
    mov [edi],al
53
    mov [edi+1],ah
54
    add esi,BYTE 2
55
    add edi,BYTE 2
56
    dec ecx
57
    jnz .L1
9172 turbocat 58
.L2:
59
    retn
8210 maxcodehac 60
 
9172 turbocat 61
.L3: ; head
8210 maxcodehac 62
    mov eax,edi
63
    and eax,BYTE 11b
64
    jz .L4
65
    mov al,[esi]
66
    mov ah,[esi+1]
67
    mov ebx,eax
68
    mov edx,eax
69
    shr eax,11
70
    and eax,BYTE 11111b
71
    and ebx,11111100000b
72
    shl edx,11
73
    add eax,ebx
74
    add eax,edx
75
    mov [edi],al
76
    mov [edi+1],ah
77
    add esi,BYTE 2
78
    add edi,BYTE 2
79
    dec ecx
80
 
9172 turbocat 81
.L4: ; save count
8210 maxcodehac 82
    push ecx
83
 
84
    ; unroll twice
85
    shr ecx,1
86
 
87
    ; point arrays to end
88
    lea esi,[esi+ecx*4]
89
    lea edi,[edi+ecx*4]
90
 
91
    ; negative counter
92
    neg ecx
93
    jmp SHORT .L6
94
 
9172 turbocat 95
.L5:    mov [edi+ecx*4-4],eax
96
.L6:    mov eax,[esi+ecx*4]
8210 maxcodehac 97
 
98
        mov ebx,[esi+ecx*4]
99
        and eax,07E007E0h
100
 
101
        mov edx,[esi+ecx*4]
102
        and ebx,0F800F800h
103
 
104
        shr ebx,11
105
        and edx,001F001Fh
106
 
107
        shl edx,11
108
        add eax,ebx
109
 
110
        add eax,edx
111
        inc ecx
112
 
113
        jnz .L5
114
 
115
    mov [edi+ecx*4-4],eax
116
 
117
    ; tail
118
    pop ecx
119
    and ecx,BYTE 1
120
    jz .L7
121
    mov al,[esi]
122
    mov ah,[esi+1]
123
    mov ebx,eax
124
    mov edx,eax
125
    shr eax,11
126
    and eax,BYTE 11111b
127
    and ebx,11111100000b
128
    shl edx,11
129
    add eax,ebx
130
    add eax,edx
131
    mov [edi],al
132
    mov [edi+1],ah
133
    add esi,BYTE 2
134
    add edi,BYTE 2
135
 
9172 turbocat 136
.L7:
137
    retn
8210 maxcodehac 138
 
9202 turbocat 139
ConvertX86p16_16RGB555:
8210 maxcodehac 140
_ConvertX86p16_16RGB555:
141
 
142
    ; check short
143
    cmp ecx,BYTE 32
144
    ja .L3
145
 
146
 
9172 turbocat 147
.L1: ; short loop
8210 maxcodehac 148
    mov al,[esi]
149
    mov ah,[esi+1]
150
    mov ebx,eax
151
    shr ebx,1
152
    and ebx,     0111111111100000b
153
    and eax,BYTE 0000000000011111b
154
    add eax,ebx
155
    mov [edi],al
156
    mov [edi+1],ah
157
    add esi,BYTE 2
158
    add edi,BYTE 2
159
    dec ecx
160
    jnz .L1
9172 turbocat 161
.L2:
162
    retn
8210 maxcodehac 163
 
9172 turbocat 164
.L3: ; head
8210 maxcodehac 165
    mov eax,edi
166
    and eax,BYTE 11b
167
    jz .L4
168
    mov al,[esi]
169
    mov ah,[esi+1]
170
    mov ebx,eax
171
    shr ebx,1
172
    and ebx,     0111111111100000b
173
    and eax,BYTE 0000000000011111b
174
    add eax,ebx
175
    mov [edi],al
176
    mov [edi+1],ah
177
    add esi,BYTE 2
178
    add edi,BYTE 2
179
    dec ecx
180
 
9172 turbocat 181
.L4: ; save ebp
8210 maxcodehac 182
    push ebp
183
 
184
    ; save count
185
    push ecx
186
 
187
    ; unroll four times
188
    shr ecx,2
189
 
190
    ; point arrays to end
191
    lea esi,[esi+ecx*8]
192
    lea edi,[edi+ecx*8]
193
 
194
    ; negative counter
195
    xor ebp,ebp
196
    sub ebp,ecx
197
 
9172 turbocat 198
.L5:    mov eax,[esi+ebp*8]        ; agi?
8210 maxcodehac 199
        mov ecx,[esi+ebp*8+4]
200
 
201
        mov ebx,eax
202
        mov edx,ecx
203
 
204
        and eax,0FFC0FFC0h
205
        and ecx,0FFC0FFC0h
206
 
207
        shr eax,1
208
        and ebx,001F001Fh
209
 
210
        shr ecx,1
211
        and edx,001F001Fh
212
 
213
        add eax,ebx
214
        add ecx,edx
215
 
216
        mov [edi+ebp*8],eax
217
        mov [edi+ebp*8+4],ecx
218
 
219
        inc ebp
220
        jnz .L5
221
 
222
    ; tail
223
    pop ecx
9172 turbocat 224
.L6: and ecx,BYTE 11b
8210 maxcodehac 225
    jz .L7
226
    mov al,[esi]
227
    mov ah,[esi+1]
228
    mov ebx,eax
229
    shr ebx,1
230
    and ebx,     0111111111100000b
231
    and eax,BYTE 0000000000011111b
232
    add eax,ebx
233
    mov [edi],al
234
    mov [edi+1],ah
235
    add esi,BYTE 2
236
    add edi,BYTE 2
237
    dec ecx
238
    jmp SHORT .L6
239
 
9172 turbocat 240
.L7: pop ebp
241
    retn
8210 maxcodehac 242
 
9202 turbocat 243
ConvertX86p16_16BGR555:
8210 maxcodehac 244
_ConvertX86p16_16BGR555:
245
 
246
    ; check short
247
    cmp ecx,BYTE 16
248
    ja .L3
249
 
250
 
9172 turbocat 251
.L1: ; short loop
8210 maxcodehac 252
    mov al,[esi]
253
    mov ah,[esi+1]
254
    mov ebx,eax
255
    mov edx,eax
256
    shr eax,11
257
    and eax,BYTE 11111b
258
    shr ebx,1
259
    and ebx,1111100000b
260
    shl edx,10
261
    and edx,0111110000000000b
262
    add eax,ebx
263
    add eax,edx
264
    mov [edi],al
265
    mov [edi+1],ah
266
    add esi,BYTE 2
267
    add edi,BYTE 2
268
    dec ecx
269
    jnz .L1
9172 turbocat 270
.L2:
271
    retn
8210 maxcodehac 272
 
9172 turbocat 273
.L3: ; head
8210 maxcodehac 274
    mov eax,edi
275
    and eax,BYTE 11b
276
    jz .L4
277
    mov al,[esi]
278
    mov ah,[esi+1]
279
    mov ebx,eax
280
    mov edx,eax
281
    shr eax,11
282
    and eax,BYTE 11111b
283
    shr ebx,1
284
    and ebx,1111100000b
285
    shl edx,10
286
    and edx,0111110000000000b
287
    add eax,ebx
288
    add eax,edx
289
    mov [edi],al
290
    mov [edi+1],ah
291
    add esi,BYTE 2
292
    add edi,BYTE 2
293
    dec ecx
294
 
9172 turbocat 295
.L4: ; save count
8210 maxcodehac 296
    push ecx
297
 
298
    ; unroll twice
299
    shr ecx,1
300
 
301
    ; point arrays to end
302
    lea esi,[esi+ecx*4]
303
    lea edi,[edi+ecx*4]
304
 
305
    ; negative counter
306
    neg ecx
307
    jmp SHORT .L6
308
 
9172 turbocat 309
.L5:     mov [edi+ecx*4-4],eax
310
.L6:     mov eax,[esi+ecx*4]
8210 maxcodehac 311
 
312
        shr eax,1
313
        mov ebx,[esi+ecx*4]
314
 
315
        and eax,03E003E0h
316
        mov edx,[esi+ecx*4]
317
 
318
        and ebx,0F800F800h
319
 
320
        shr ebx,11
321
        and edx,001F001Fh
322
 
323
        shl edx,10
324
        add eax,ebx
325
 
326
        add eax,edx
327
        inc ecx
328
 
329
        jnz .L5
330
 
331
    mov [edi+ecx*4-4],eax
332
 
333
    ; tail
334
    pop ecx
335
    and ecx,BYTE 1
336
    jz .L7
337
    mov al,[esi]
338
    mov ah,[esi+1]
339
    mov ebx,eax
340
    mov edx,eax
341
    shr eax,11
342
    and eax,BYTE 11111b
343
    shr ebx,1
344
    and ebx,1111100000b
345
    shl edx,10
346
    and edx,0111110000000000b
347
    add eax,ebx
348
    add eax,edx
349
    mov [edi],al
350
    mov [edi+1],ah
351
    add esi,BYTE 2
352
    add edi,BYTE 2
353
 
9172 turbocat 354
.L7:
355
    retn
8210 maxcodehac 356
 
357
 
358
 
359
 
360
 
9202 turbocat 361
ConvertX86p16_8RGB332:
8210 maxcodehac 362
_ConvertX86p16_8RGB332:
363
 
364
    ; check short
365
    cmp ecx,BYTE 16
366
    ja .L3
367
 
368
 
9172 turbocat 369
.L1: ; short loop
8210 maxcodehac 370
    mov al,[esi+0]
371
    mov ah,[esi+1]
372
    mov ebx,eax
373
    mov edx,eax
374
    and eax,BYTE 11000b         ; blue
375
    shr eax,3
376
    and ebx,11100000000b        ; green
377
    shr ebx,6
378
    and edx,1110000000000000b   ; red
379
    shr edx,8
380
    add eax,ebx
381
    add eax,edx
382
    mov [edi],al
383
    add esi,BYTE 2
384
    inc edi
385
    dec ecx
386
    jnz .L1
9172 turbocat 387
.L2:
388
    retn
8210 maxcodehac 389
 
9172 turbocat 390
.L3: mov eax,edi
8210 maxcodehac 391
    and eax,BYTE 11b
392
    jz .L4
393
    mov al,[esi+0]
394
    mov ah,[esi+1]
395
    mov ebx,eax
396
    mov edx,eax
397
    and eax,BYTE 11000b         ; blue
398
    shr eax,3
399
    and ebx,11100000000b        ; green
400
    shr ebx,6
401
    and edx,1110000000000000b   ; red
402
    shr edx,8
403
    add eax,ebx
404
    add eax,edx
405
    mov [edi],al
406
    add esi,BYTE 2
407
    inc edi
408
    dec ecx
409
    jmp SHORT .L3
410
 
9172 turbocat 411
.L4: ; save ebp
8210 maxcodehac 412
    push ebp
413
 
414
    ; save count
415
    push ecx
416
 
417
    ; unroll 4 times
418
    shr ecx,2
419
 
420
    ; prestep
421
    mov dl,[esi+0]
422
    mov bl,[esi+1]
423
    mov dh,[esi+2]
424
 
9172 turbocat 425
.L5:     shl edx,16
8210 maxcodehac 426
        mov bh,[esi+3]
427
 
428
        shl ebx,16
429
        mov dl,[esi+4]
430
 
431
        mov dh,[esi+6]
432
        mov bl,[esi+5]
433
 
434
        and edx,00011000000110000001100000011000b
435
        mov bh,[esi+7]
436
 
437
        ror edx,16+3
438
        mov eax,ebx                                     ; setup eax for reds
439
 
440
        and ebx,00000111000001110000011100000111b
441
        and eax,11100000111000001110000011100000b       ; reds
442
 
443
        ror ebx,16-2
444
        add esi,BYTE 8
445
 
446
        ror eax,16
447
        add edi,BYTE 4
448
 
449
        add eax,ebx
450
        mov bl,[esi+1]                                  ; greens
451
 
452
        add eax,edx
453
        mov dl,[esi+0]                                  ; blues
454
 
455
        mov [edi-4],eax
456
        mov dh,[esi+2]
457
 
458
        dec ecx
459
        jnz .L5
460
 
461
    ; check tail
462
    pop ecx
463
    and ecx,BYTE 11b
464
    jz .L7
465
 
9172 turbocat 466
.L6: ; tail
8210 maxcodehac 467
    mov al,[esi+0]
468
    mov ah,[esi+1]
469
    mov ebx,eax
470
    mov edx,eax
471
    and eax,BYTE 11000b         ; blue
472
    shr eax,3
473
    and ebx,11100000000b        ; green
474
    shr ebx,6
475
    and edx,1110000000000000b   ; red
476
    shr edx,8
477
    add eax,ebx
478
    add eax,edx
479
    mov [edi],al
480
    add esi,BYTE 2
481
    inc edi
482
    dec ecx
483
    jnz .L6
484
 
9172 turbocat 485
.L7: pop ebp
486
    retn
8210 maxcodehac 487
 
9172 turbocat 488
%ifidn __OUTPUT_FORMAT__,elf32
489
section .note.GNU-stack noalloc noexec nowrite progbits
490
%endif