Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
9837 turbocat 1
bits 32
2
 
3
section .text
4
 
5
%define which	[ebp+36]	; int which
6
%define line	[ebp+40]	; int line
7
%define where	[ebp+44]	; unsigned char *where
8
 
9
%define vram	[ebp+24]	; unsigned char *vram
10
%define reg	[ebp+28]	; unsigned char reg[0x20]
11
%define highpal [ebp+32]	; unsigned int *highpal
12
 
13
;%define cache_align times ($$-$) & 3 nop	; Align to 4-byte boundary
14
;%define cache_align times ($$-$) & 7 nop	; Align to 8-byte boundary
15
%define cache_align times ($$-$) & 31 nop	; Align to 32-byte boundary
16
 
17
global asm_tiles_init
18
global drawtile1_solid
19
global drawtile1
20
global drawtile2_solid
21
global drawtile2
22
global drawtile3_solid
23
global drawtile3
24
global drawtile4_solid
25
global drawtile4
26
 
27
; Neat utility macro
28
%macro triple_xor 2
29
	xor %1, %2	; Triple XOR for a neat register exchange  ;)
30
	xor %2, %1
31
	xor %1, %2
32
%endmacro
33
 
34
%macro blit_pixel1 1-*		; 8bpp blitting, solid
35
	mov eax, ebx
36
	and eax, %1
37
    %if %0 > 1
38
        shr eax, byte %2
39
    %endif
40
	or eax, [esi]
41
	mov byte [edi], al
42
	inc edi
43
%endmacro
44
 
45
%macro blit_pixel1_trans 1-*	; 8bpp blitting, transparent
46
	mov eax, ebx
47
	and eax, %1
48
	jz %%trans
49
    %if %0 > 1
50
        shr eax, byte %2
51
    %endif
52
	or eax, [esi]
53
	mov byte [edi], al
54
    %%trans:
55
	inc edi
56
%endmacro
57
 
58
%macro blit_pixel2 1-*		; 16bpp blitting, solid
59
	mov eax, ebx
60
	and eax, %1
61
    %if %0 > 1
62
        shr eax, byte %2
63
    %endif
64
	lea edx, [esi+eax*4]
65
	mov eax, [edx]
66
	mov word [edi], ax
67
	add edi, byte 2
68
%endmacro
69
 
70
%macro blit_pixel2_trans 1-*	; 16bpp blitting, transparent
71
	mov eax, ebx
72
	and eax, %1
73
	jz %%trans
74
    %if %0 > 1
75
        shr eax, byte %2
76
    %endif
77
	lea edx, [esi+eax*4]
78
	mov eax, [edx]
79
	mov word [edi], ax
80
    %%trans:
81
	add edi, byte 2
82
%endmacro
83
 
84
%macro blit_pixel3 1-*		; 24bpp blitting, solid
85
	mov eax, ebx
86
	and eax, %1
87
    %if %0 > 1
88
        shr eax, byte %2
89
    %endif
90
	lea edx, [esi+eax*4+1]
91
	mov ax, word [edx]
92
	mov word [edi], ax
93
	add edi, 2
94
	dec edx
95
	mov al, byte [edx]
96
	mov byte [edi], al
97
	inc edi
98
%endmacro
99
 
100
%macro blit_pixel3_trans 1-*	; 24bpp blitting, transparent
101
	mov eax, ebx
102
	and eax, %1
103
	jz %%trans
104
    %if %0 > 1
105
        shr eax, byte %2
106
    %endif
107
	lea edx, [esi+eax*4+1]
108
	mov ax, word [edx]
109
	mov word [edi], ax
110
	add edi, 2
111
	dec edx
112
	mov al, byte [edx]
113
	mov byte [edi], al
114
	inc edi
115
	jmp %%next
116
    %%trans:
117
	add edi, byte 3
118
    %%next:
119
%endmacro
120
 
121
%macro blit_pixel4 1-*		; 32bpp blitting, solid
122
	mov eax, ebx
123
	and eax, %1
124
    %if %0 > 1
125
        shr eax, byte %2
126
    %endif
127
	lea edx, [esi+eax*4]
128
	mov eax, [edx]
129
	mov [edi], eax
130
	add edi, byte 4
131
%endmacro
132
 
133
%macro blit_pixel4_trans 1-*	; 32bpp blitting, transparent
134
	mov eax, ebx
135
	and eax, %1
136
	jz %%trans
137
    %if %0 > 1
138
        shr eax, byte %2
139
    %endif
140
	lea edx, [esi+eax*4]
141
	mov eax, [edx]
142
	mov [edi], eax
143
    %%trans:
144
	add edi, byte 4
145
%endmacro
146
 
147
; ----------------------------------------
148
; int _asm_tiles_init
149
;   (unsigned char *vram, unsigned char *reg, unsigned char *highpal)
150
; ----------------------------------------
151
 
152
	cache_align
153
 
154
asm_tiles_init:
155
 
156
	push eax
157
	push ebx
158
	push edx
159
	push esp
160
	push ebp
161
	mov ebp, esp
162
 
163
	mov eax, vram
164
	mov ebx, reg
165
	mov edx, highpal
166
	mov [__vram], eax
167
	mov [__reg], ebx
168
	mov [__highpal], edx
169
 
170
	pop ebp
171
	pop esp
172
	pop edx
173
	pop ebx
174
	pop eax
175
 
176
	ret
177
 
178
	cache_align
179
 
180
; ----------------------------------------
181
; int _drawtile1_solid
182
;   (int which, int line, unsigned char *where)
183
; ----------------------------------------
184
 
185
	cache_align
186
 
187
drawtile1_solid:
188
 
189
	pushad
190
	mov ebp, esp
191
 
192
.setup:
193
 
194
.get_pal:
195
 
196
	mov ebx, which
197
	mov esi, [__highpal]
198
	mov eax, ebx
199
	shr eax, byte 7
200
	and eax, 0xc0
201
	add esi, eax
202
	mov edi, [__reg]
203
	push esi
204
 
205
.check_y_flip:
206
 
207
	mov eax, ebx
208
	xor ecx, ecx
209
	mov edx, line
210
	test eax, 0x1000
211
 
212
	jz .check_interlace
213
 
214
.y_flipped:
215
 
216
	xor edx, byte 7
217
 
218
	cache_align
219
 
220
.check_interlace:
221
 
222
	mov esi, [__reg]
223
	mov cl, [esi+12]
224
	mov esi, [__vram]
225
	and eax, 0x7ff
226
	test cl, byte 0x2
227
 
228
	jz .no_interlace
229
 
230
.interlace:
231
 
232
	lea edx, [edx*8]
233
	shl eax, 6
234
	jmp .check_x_flip
235
 
236
	cache_align
237
 
238
.no_interlace:
239
 
240
	lea edx, [edx*4]
241
	shl eax, 5
242
 
243
	cache_align
244
 
245
.check_x_flip:
246
 
247
	add eax, edx
248
	mov edi, where
249
	lea esi, [esi+eax]
250
	mov ebx, [esi]
251
	pop esi
252
	mov eax, which
253
	test eax, 0x800
254
 
255
	jz near .x_not_flipped
256
 
257
.x_flipped:
258
 
259
	blit_pixel1 0x0f000000, 24	; pixel 8
260
	blit_pixel1 0xf0000000, 28	; ..... 7
261
	blit_pixel1 0x000f0000, 16	; ..... 6
262
	blit_pixel1 0x00f00000, 20	; ..... 5
263
	blit_pixel1 0x00000f00, 8	; ..... 4
264
	blit_pixel1 0x0000f000, 12	; ..... 3
265
	blit_pixel1 0x0000000f		; ..... 2
266
	blit_pixel1 0x000000f0, 4	; ..... 1
267
 
268
	jmp .cleanup
269
 
270
	cache_align
271
 
272
.x_not_flipped:
273
 
274
	blit_pixel1 0x000000f0, 4	; pixel 1
275
	blit_pixel1 0x0000000f		; ..... 2
276
	blit_pixel1 0x0000f000, 12	; ..... 3
277
	blit_pixel1 0x00000f00, 8	; ..... 4
278
	blit_pixel1 0x00f00000, 20	; ..... 5
279
	blit_pixel1 0x000f0000, 16	; ..... 6
280
	blit_pixel1 0xf0000000, 28	; ..... 7
281
	blit_pixel1 0x0f000000, 24	; ..... 8
282
 
283
	cache_align
284
 
285
.cleanup:
286
 
287
	popad
288
 
289
	ret
290
 
291
	cache_align
292
 
293
; ----------------------------------------
294
 
295
drawtile1:
296
 
297
	pushad
298
	mov ebp, esp
299
 
300
.setup:
301
 
302
.get_pal:
303
 
304
	mov ebx, which
305
	mov esi, [__highpal]
306
	mov eax, ebx
307
	shr eax, byte 7
308
	and eax, 0xc0
309
	add esi, eax
310
	push esi
311
 
312
.check_y_flip:
313
 
314
	mov eax, ebx
315
	xor ecx, ecx
316
	mov edx, line
317
	test eax, 0x1000
318
 
319
	jz .check_interlace
320
 
321
.y_flipped:
322
 
323
	xor edx, byte 7
324
 
325
	cache_align
326
 
327
.check_interlace:
328
 
329
	mov esi, [__reg]
330
	mov cl, [esi+12]
331
	mov esi, [__vram]
332
	and eax, 0x7ff
333
	test cl, byte 0x2
334
 
335
	jz .no_interlace
336
 
337
.interlace:
338
 
339
	lea edx, [edx*8]
340
	shl eax, 6
341
	jmp .check_x_flip
342
 
343
	cache_align
344
 
345
.no_interlace:
346
 
347
	lea edx, [edx*4]
348
	shl eax, 5
349
 
350
	cache_align
351
 
352
.check_x_flip:
353
 
354
	add eax, edx
355
	mov edi, where
356
	lea esi, [esi+eax]
357
	mov ebx, [esi]
358
	pop esi
359
	test ebx, ebx
360
 
361
	jz near .cleanup		; Don't waste time if the tile is blank!
362
 
363
	mov eax, which
364
	test eax, 0x800
365
 
366
	jz near .x_not_flipped
367
 
368
.x_flipped:
369
 
370
	blit_pixel1_trans 0x0f000000, 24	; pixel 8
371
	blit_pixel1_trans 0xf0000000, 28	; ..... 7
372
	blit_pixel1_trans 0x000f0000, 16	; ..... 6
373
	blit_pixel1_trans 0x00f00000, 20	; ..... 5
374
	blit_pixel1_trans 0x00000f00, 8		; ..... 4
375
	blit_pixel1_trans 0x0000f000, 12	; ..... 3
376
	blit_pixel1_trans 0x0000000f		; ..... 2
377
	blit_pixel1_trans 0x000000f0, 4		; ..... 1
378
 
379
	jmp .cleanup
380
 
381
	cache_align
382
 
383
.x_not_flipped:
384
 
385
	blit_pixel1_trans 0x000000f0, 4		; pixel 1
386
	blit_pixel1_trans 0x0000000f		; ..... 2
387
	blit_pixel1_trans 0x0000f000, 12	; ..... 3
388
	blit_pixel1_trans 0x00000f00, 8		; ..... 4
389
	blit_pixel1_trans 0x00f00000, 20	; ..... 5
390
	blit_pixel1_trans 0x000f0000, 16	; ..... 6
391
	blit_pixel1_trans 0xf0000000, 28	; ..... 7
392
	blit_pixel1_trans 0x0f000000, 24	; ..... 8
393
 
394
	cache_align
395
 
396
.cleanup:
397
 
398
	popad
399
 
400
	ret
401
 
402
	cache_align
403
 
404
; ----------------------------------------
405
 
406
	cache_align
407
 
408
drawtile2_solid:
409
 
410
	pushad
411
	mov ebp, esp
412
 
413
.setup:
414
 
415
.get_pal:
416
 
417
	mov ebx, which
418
	mov esi, [__highpal]
419
	mov ecx, esi
420
	mov eax, ebx
421
	shr eax, byte 7
422
	and eax, 0xc0
423
	add esi, eax
424
; -
425
	mov edi, [__reg]
426
	mov edx, [edi + 7]
427
	push dword [esi]
428
	and edx, 0x3f
429
	mov eax, [ecx + edx*4]
430
	mov [esi], eax
431
; -
432
	push esi
433
 
434
.check_y_flip:
435
 
436
	mov eax, ebx
437
	xor ecx, ecx
438
	mov edx, line
439
	test eax, 0x1000
440
 
441
	jz .check_interlace
442
 
443
.y_flipped:
444
 
445
	xor edx, byte 7
446
 
447
	cache_align
448
 
449
.check_interlace:
450
 
451
	mov esi, [__reg]
452
	mov cl, [esi+12]
453
	mov esi, [__vram]
454
	and eax, 0x7ff
455
	test cl, byte 0x2
456
 
457
	jz .no_interlace
458
 
459
.interlace:
460
 
461
	lea edx, [edx*8]
462
	shl eax, 6
463
	jmp .check_x_flip
464
 
465
	cache_align
466
 
467
.no_interlace:
468
 
469
	lea edx, [edx*4]
470
	shl eax, 5
471
 
472
	cache_align
473
 
474
.check_x_flip:
475
 
476
	add eax, edx
477
	mov edi, where
478
	lea esi, [esi+eax]
479
	mov ebx, [esi]
480
	pop esi
481
	mov eax, which
482
	test eax, 0x800
483
 
484
	jz near .x_not_flipped
485
 
486
.x_flipped:
487
 
488
	blit_pixel2 0x0f000000, 24	; pixel 8
489
	blit_pixel2 0xf0000000, 28	; ..... 7
490
	blit_pixel2 0x000f0000, 16	; ..... 6
491
	blit_pixel2 0x00f00000, 20	; ..... 5
492
	blit_pixel2 0x00000f00, 8	; ..... 4
493
	blit_pixel2 0x0000f000, 12	; ..... 3
494
	blit_pixel2 0x0000000f		; ..... 2
495
	blit_pixel2 0x000000f0, 4	; ..... 1
496
 
497
	jmp .cleanup
498
 
499
	cache_align
500
 
501
.x_not_flipped:
502
 
503
	blit_pixel2 0x000000f0, 4	; pixel 1
504
	blit_pixel2 0x0000000f		; ..... 2
505
	blit_pixel2 0x0000f000, 12	; ..... 3
506
	blit_pixel2 0x00000f00, 8	; ..... 4
507
	blit_pixel2 0x00f00000, 20	; ..... 5
508
	blit_pixel2 0x000f0000, 16	; ..... 6
509
	blit_pixel2 0xf0000000, 28	; ..... 7
510
	blit_pixel2 0x0f000000, 24	; ..... 8
511
 
512
	cache_align
513
 
514
.cleanup:
515
	pop dword [esi]
516
	popad
517
	ret
518
 
519
	cache_align
520
 
521
; ----------------------------------------
522
 
523
	cache_align
524
 
525
drawtile2:
526
 
527
	pushad
528
	mov ebp, esp
529
 
530
.get_pal:
531
 
532
	mov ebx, which
533
	mov esi, [__highpal]
534
	mov eax, ebx
535
	shr eax, 7
536
	and eax, 0xc0
537
	add esi, eax
538
	push esi
539
 
540
.check_y_flip:
541
 
542
	mov eax, ebx
543
	xor ecx, ecx
544
	mov edx, line
545
	test eax, 0x1000
546
 
547
	jz .check_interlace
548
 
549
.y_flipped:
550
 
551
	xor edx, byte 7
552
 
553
	cache_align
554
 
555
.check_interlace:
556
 
557
	mov esi, [__reg]
558
	mov cl, [esi+12]
559
	mov esi, [__vram]
560
	and eax, 0x7ff
561
	test cl, byte 0x2
562
 
563
	jz .no_interlace
564
 
565
.interlace:
566
 
567
	lea edx, [edx*8]
568
	shl eax, 6
569
 
570
	jmp .check_x_flip
571
 
572
	cache_align
573
 
574
.no_interlace:
575
	lea edx, [edx*4]
576
	shl eax, 5
577
 
578
	cache_align
579
 
580
.check_x_flip:
581
 
582
	add eax, edx
583
	mov edi, where
584
	lea esi, [esi+eax]
585
	mov ebx, [esi]
586
	pop esi
587
	test ebx, ebx
588
 
589
	jz near .cleanup		; Don't waste time if the tile is blank!
590
 
591
	mov eax, which
592
	test eax, 0x800
593
 
594
	jz near .x_not_flipped
595
 
596
.x_flipped:
597
 
598
	blit_pixel2_trans 0x0f000000, 24	; pixel 8
599
	blit_pixel2_trans 0xf0000000, 28	; ..... 7
600
	blit_pixel2_trans 0x000f0000, 16	; ..... 6
601
	blit_pixel2_trans 0x00f00000, 20	; ..... 5
602
	blit_pixel2_trans 0x00000f00, 8		; ..... 4
603
	blit_pixel2_trans 0x0000f000, 12	; ..... 3
604
	blit_pixel2_trans 0x0000000f		; ..... 2
605
	blit_pixel2_trans 0x000000f0, 4		; ..... 1
606
 
607
	jmp .cleanup
608
 
609
	cache_align
610
 
611
.x_not_flipped:
612
 
613
	blit_pixel2_trans 0x000000f0, 4		; pixel 1
614
	blit_pixel2_trans 0x0000000f		; ..... 2
615
	blit_pixel2_trans 0x0000f000, 12	; ..... 3
616
	blit_pixel2_trans 0x00000f00, 8		; ..... 4
617
	blit_pixel2_trans 0x00f00000, 20	; ..... 5
618
	blit_pixel2_trans 0x000f0000, 16	; ..... 6
619
	blit_pixel2_trans 0xf0000000, 28	; ..... 7
620
	blit_pixel2_trans 0x0f000000, 24	; ..... 8
621
 
622
	cache_align
623
 
624
.cleanup:
625
	popad
626
	ret
627
 
628
	cache_align
629
 
630
; ----------------------------------------
631
 
632
drawtile3_solid:
633
 
634
	pushad
635
	mov ebp, esp
636
 
637
.setup:
638
 
639
.get_pal:
640
 
641
	mov ebx, which
642
	mov esi, [__highpal]
643
	mov ecx, esi
644
	mov eax, ebx
645
	shr eax, byte 7
646
	and eax, 0xc0
647
	add esi, eax
648
; -
649
	mov edi, [__reg]
650
	mov edx, [edi + 7]
651
	push dword [esi]
652
	and edx, 0x3f
653
	mov eax, [ecx + edx*4]
654
	mov [esi], eax
655
; -
656
	push esi
657
 
658
.check_y_flip:
659
 
660
	mov eax, ebx
661
	xor ecx, ecx
662
	mov edx, line
663
	test eax, 0x1000
664
 
665
	jz .check_interlace
666
 
667
.y_flipped:
668
 
669
	xor edx, byte 7
670
 
671
	cache_align
672
 
673
.check_interlace:
674
 
675
	mov esi, [__reg]
676
	mov cl, [esi+12]
677
	mov esi, [__vram]
678
	and eax, 0x7ff
679
	test cl, byte 0x2
680
 
681
	jz .no_interlace
682
 
683
.interlace:
684
 
685
	lea edx, [edx*8]
686
	shl eax, 6
687
	jmp .check_x_flip
688
 
689
	cache_align
690
 
691
.no_interlace:
692
 
693
	lea edx, [edx*4]
694
	shl eax, 5
695
 
696
	cache_align
697
 
698
.check_x_flip:
699
 
700
	add eax, edx
701
	mov edi, where
702
	lea esi, [esi+eax]
703
	mov ebx, [esi]
704
	pop esi
705
	mov eax, which
706
	test eax, 0x800
707
 
708
	jz near .x_not_flipped
709
 
710
.x_flipped:
711
 
712
	blit_pixel3 0x0f000000, 24	; pixel 8
713
	blit_pixel3 0xf0000000, 28	; ..... 7
714
	blit_pixel3 0x000f0000, 16	; ..... 6
715
	blit_pixel3 0x00f00000, 20	; ..... 5
716
	blit_pixel3 0x00000f00, 8	; ..... 4
717
	blit_pixel3 0x0000f000, 12	; ..... 3
718
	blit_pixel3 0x0000000f		; ..... 2
719
	blit_pixel3 0x000000f0, 4	; ..... 1
720
 
721
	jmp .cleanup
722
 
723
	cache_align
724
 
725
.x_not_flipped:
726
 
727
	blit_pixel3 0x000000f0, 4	; pixel 1
728
	blit_pixel3 0x0000000f		; ..... 2
729
	blit_pixel3 0x0000f000, 12	; ..... 3
730
	blit_pixel3 0x00000f00, 8	; ..... 4
731
	blit_pixel3 0x00f00000, 20	; ..... 5
732
	blit_pixel3 0x000f0000, 16	; ..... 6
733
	blit_pixel3 0xf0000000, 28	; ..... 7
734
	blit_pixel3 0x0f000000, 24	; ..... 8
735
 
736
	cache_align
737
 
738
.cleanup:
739
 
740
	pop dword [esi]
741
	popad
742
	ret
743
 
744
	cache_align
745
 
746
; ----------------------------------------
747
 
748
drawtile3:
749
 
750
	pushad
751
	mov ebp, esp
752
 
753
.setup:
754
 
755
.get_pal:
756
 
757
	mov ebx, which
758
	mov esi, [__highpal]
759
	mov eax, ebx
760
	shr eax, byte 7
761
	and eax, 0xc0
762
	add esi, eax
763
	push esi
764
 
765
.check_y_flip:
766
 
767
	mov eax, ebx
768
	xor ecx, ecx
769
	mov edx, line
770
	test eax, 0x1000
771
 
772
	jz .check_interlace
773
 
774
.y_flipped:
775
 
776
	xor edx, byte 7
777
 
778
	cache_align
779
 
780
.check_interlace:
781
 
782
	mov esi, [__reg]
783
	mov cl, [esi+12]
784
	mov esi, [__vram]
785
	and eax, 0x7ff
786
	test cl, byte 0x2
787
 
788
	jz .no_interlace
789
 
790
.interlace:
791
 
792
	lea edx, [edx*8]
793
	shl eax, 6
794
	jmp .check_x_flip
795
 
796
	cache_align
797
 
798
.no_interlace:
799
 
800
	lea edx, [edx*4]
801
	shl eax, 5
802
 
803
	cache_align
804
 
805
.check_x_flip:
806
 
807
	add eax, edx
808
	mov edi, where
809
	lea esi, [esi+eax]
810
	mov ebx, [esi]
811
	pop esi
812
	test ebx, ebx
813
 
814
	jz near .cleanup		; Don't waste time if the tile is blank!
815
 
816
	mov eax, which
817
	test eax, 0x800
818
 
819
	jz near .x_not_flipped
820
 
821
.x_flipped:
822
 
823
	blit_pixel3_trans 0x0f000000, 24	; pixel 8
824
	blit_pixel3_trans 0xf0000000, 28	; ..... 7
825
	blit_pixel3_trans 0x000f0000, 16	; ..... 6
826
	blit_pixel3_trans 0x00f00000, 20	; ..... 5
827
	blit_pixel3_trans 0x00000f00, 8		; ..... 4
828
	blit_pixel3_trans 0x0000f000, 12	; ..... 3
829
	blit_pixel3_trans 0x0000000f		; ..... 2
830
	blit_pixel3_trans 0x000000f0, 4		; ..... 1
831
 
832
	jmp .cleanup
833
 
834
	cache_align
835
 
836
.x_not_flipped:
837
 
838
	blit_pixel3_trans 0x000000f0, 4		; pixel 1
839
	blit_pixel3_trans 0x0000000f		; ..... 2
840
	blit_pixel3_trans 0x0000f000, 12	; ..... 3
841
	blit_pixel3_trans 0x00000f00, 8		; ..... 4
842
	blit_pixel3_trans 0x00f00000, 20	; ..... 5
843
	blit_pixel3_trans 0x000f0000, 16	; ..... 6
844
	blit_pixel3_trans 0xf0000000, 28	; ..... 7
845
	blit_pixel3_trans 0x0f000000, 24	; ..... 8
846
 
847
	cache_align
848
 
849
.cleanup:
850
 
851
	popad
852
 
853
	ret
854
 
855
	cache_align
856
 
857
; ----------------------------------------
858
 
859
drawtile4_solid:
860
 
861
	pushad
862
	mov ebp, esp
863
 
864
.setup:
865
 
866
.get_pal:
867
 
868
	mov ebx, which
869
	mov esi, [__highpal]
870
	mov ecx, esi
871
	mov eax, ebx
872
	shr eax, byte 7
873
	and eax, 0xc0
874
	add esi, eax
875
; -
876
	mov edi, [__reg]
877
	mov edx, [edi + 7]
878
	push dword [esi]
879
	and edx, 0x3f
880
	mov eax, [ecx + edx*4]
881
	mov [esi], eax
882
; -
883
	push esi
884
 
885
.check_y_flip:
886
 
887
	mov eax, ebx
888
	xor ecx, ecx
889
	mov edx, line
890
	test eax, 0x1000
891
 
892
	jz .check_interlace
893
 
894
.y_flipped:
895
 
896
	xor edx, byte 7
897
 
898
	cache_align
899
 
900
.check_interlace:
901
 
902
	mov esi, [__reg]
903
	mov cl, [esi+12]
904
	mov esi, [__vram]
905
	and eax, 0x7ff
906
	test cl, byte 0x2
907
 
908
	jz .no_interlace
909
 
910
.interlace:
911
 
912
	lea edx, [edx*8]
913
	shl eax, 6
914
	jmp .check_x_flip
915
 
916
	cache_align
917
 
918
.no_interlace:
919
 
920
	lea edx, [edx*4]
921
	shl eax, 5
922
 
923
	cache_align
924
 
925
.check_x_flip:
926
 
927
	add eax, edx
928
	mov edi, where
929
	lea esi, [esi+eax]
930
	mov ebx, [esi]
931
	pop esi
932
	mov eax, which
933
	test eax, 0x800
934
 
935
	jz near .x_not_flipped
936
 
937
.x_flipped:
938
 
939
	blit_pixel4 0x0f000000, 24	; pixel 8
940
	blit_pixel4 0xf0000000, 28	; ..... 7
941
	blit_pixel4 0x000f0000, 16	; ..... 6
942
	blit_pixel4 0x00f00000, 20	; ..... 5
943
	blit_pixel4 0x00000f00, 8	; ..... 4
944
	blit_pixel4 0x0000f000, 12	; ..... 3
945
	blit_pixel4 0x0000000f		; ..... 2
946
	blit_pixel4 0x000000f0, 4	; ..... 1
947
 
948
	jmp .cleanup
949
 
950
	cache_align
951
 
952
.x_not_flipped:
953
 
954
	blit_pixel4 0x000000f0, 4	; pixel 1
955
	blit_pixel4 0x0000000f		; ..... 2
956
	blit_pixel4 0x0000f000, 12	; ..... 3
957
	blit_pixel4 0x00000f00, 8	; ..... 4
958
	blit_pixel4 0x00f00000, 20	; ..... 5
959
	blit_pixel4 0x000f0000, 16	; ..... 6
960
	blit_pixel4 0xf0000000, 28	; ..... 7
961
	blit_pixel4 0x0f000000, 24	; ..... 8
962
 
963
	cache_align
964
 
965
.cleanup:
966
 
967
	pop dword [esi]
968
	popad
969
	ret
970
 
971
	cache_align
972
 
973
; ----------------------------------------
974
 
975
drawtile4:
976
 
977
	pushad
978
	mov ebp, esp
979
 
980
.setup:
981
 
982
.get_pal:
983
 
984
	mov ebx, which
985
	mov esi, [__highpal]
986
	mov eax, ebx
987
	shr eax, byte 7
988
	and eax, 0xc0
989
	add esi, eax
990
	push esi
991
 
992
.check_y_flip:
993
 
994
	mov eax, ebx
995
	xor ecx, ecx
996
	mov edx, line
997
	test eax, 0x1000
998
 
999
	jz .check_interlace
1000
 
1001
.y_flipped:
1002
 
1003
	xor edx, byte 7
1004
 
1005
	cache_align
1006
 
1007
.check_interlace:
1008
 
1009
	mov esi, [__reg]
1010
	mov cl, [esi+12]
1011
	mov esi, [__vram]
1012
	and eax, 0x7ff
1013
	test cl, byte 0x2
1014
 
1015
	jz .no_interlace
1016
 
1017
.interlace:
1018
 
1019
	lea edx, [edx*8]
1020
	shl eax, 6
1021
	jmp .check_x_flip
1022
 
1023
	cache_align
1024
 
1025
.no_interlace:
1026
 
1027
	lea edx, [edx*4]
1028
	shl eax, 5
1029
 
1030
	cache_align
1031
 
1032
.check_x_flip:
1033
 
1034
	add eax, edx
1035
	mov edi, where
1036
	lea esi, [esi+eax]
1037
	mov ebx, [esi]
1038
	pop esi
1039
	test ebx, ebx
1040
 
1041
	jz near .cleanup		; Don't waste time if the tile is blank!
1042
 
1043
	mov eax, which
1044
	test eax, 0x800
1045
 
1046
	jz near .x_not_flipped
1047
 
1048
.x_flipped:
1049
 
1050
	blit_pixel4_trans 0x0f000000, 24	; pixel 8
1051
	blit_pixel4_trans 0xf0000000, 28	; ..... 7
1052
	blit_pixel4_trans 0x000f0000, 16	; ..... 6
1053
	blit_pixel4_trans 0x00f00000, 20	; ..... 5
1054
	blit_pixel4_trans 0x00000f00, 8		; ..... 4
1055
	blit_pixel4_trans 0x0000f000, 12	; ..... 3
1056
	blit_pixel4_trans 0x0000000f		; ..... 2
1057
	blit_pixel4_trans 0x000000f0, 4		; ..... 1
1058
 
1059
	jmp .cleanup
1060
 
1061
	cache_align
1062
 
1063
.x_not_flipped:
1064
 
1065
	blit_pixel4_trans 0x000000f0, 4		; pixel 1
1066
	blit_pixel4_trans 0x0000000f		; ..... 2
1067
	blit_pixel4_trans 0x0000f000, 12	; ..... 3
1068
	blit_pixel4_trans 0x00000f00, 8		; ..... 4
1069
	blit_pixel4_trans 0x00f00000, 20	; ..... 5
1070
	blit_pixel4_trans 0x000f0000, 16	; ..... 6
1071
	blit_pixel4_trans 0xf0000000, 28	; ..... 7
1072
	blit_pixel4_trans 0x0f000000, 24	; ..... 8
1073
 
1074
	cache_align
1075
 
1076
.cleanup:
1077
 
1078
	popad
1079
 
1080
	ret
1081
 
1082
	cache_align
1083
 
1084
section .data
1085
 
1086
	__vram		dd 0
1087
	__reg		dd 0
1088
	__highpal	dd 0
1089
 
1090
; ----------------------------------------
1091
 
1092
%ifdef NASM_STACK_NOEXEC
1093
section .note.GNU-stack noalloc noexec nowrite progbits
1094
%endif