Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 372afde46e
Fetching contributors…

Cannot retrieve contributors at this time

file 1234 lines (1057 sloc) 30.058 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 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234
 .386P
 .model FLAT
;
; d_draw16.s
; x86 assembly-language horizontal 8-bpp span-drawing code, with 16-pixel
; subdivision.
;

include qasm.inc
include d_if.inc

if id386

;----------------------------------------------------------------------
; 8-bpp horizontal span drawing code for polygons, with no transparency and
; 16-pixel subdivision.
;
; Assumes there is at least one span in pspans, and that every span
; contains at least one pixel
;----------------------------------------------------------------------

_DATA SEGMENT

_DATA ENDS
_TEXT SEGMENT

; out-of-line, rarely-needed clamping code

LClampHigh0:
 mov esi,ds:dword ptr[_bbextents]
 jmp LClampReentry0
LClampHighOrLow0:
 jg LClampHigh0
 xor esi,esi
 jmp LClampReentry0

LClampHigh1:
 mov edx,ds:dword ptr[_bbextentt]
 jmp LClampReentry1
LClampHighOrLow1:
 jg LClampHigh1
 xor edx,edx
 jmp LClampReentry1

LClampLow2:
 mov ebp,4096
 jmp LClampReentry2
LClampHigh2:
 mov ebp,ds:dword ptr[_bbextents]
 jmp LClampReentry2

LClampLow3:
 mov ecx,4096
 jmp LClampReentry3
LClampHigh3:
 mov ecx,ds:dword ptr[_bbextentt]
 jmp LClampReentry3

LClampLow4:
 mov eax,4096
 jmp LClampReentry4
LClampHigh4:
 mov eax,ds:dword ptr[_bbextents]
 jmp LClampReentry4

LClampLow5:
 mov ebx,4096
 jmp LClampReentry5
LClampHigh5:
 mov ebx,ds:dword ptr[_bbextentt]
 jmp LClampReentry5


pspans equ 4+16

 align 4
 public _D_DrawSpans16
_D_DrawSpans16:
 push ebp ; preserve caller's stack frame
 push edi
 push esi ; preserve register variables
 push ebx

;
; set up scaled-by-16 steps, for 16-long segments; also set up cacheblock
; and span list pointers
;
; TODO: any overlap from rearranging?
 fld ds:dword ptr[_d_sdivzstepu]
 fmul ds:dword ptr[fp_16]
 mov edx,ds:dword ptr[_cacheblock]
 fld ds:dword ptr[_d_tdivzstepu]
 fmul ds:dword ptr[fp_16]
 mov ebx,ds:dword ptr[pspans+esp] ; point to the first span descriptor
 fld ds:dword ptr[_d_zistepu]
 fmul ds:dword ptr[fp_16]
 mov ds:dword ptr[pbase],edx ; pbase = cacheblock
 fstp ds:dword ptr[zi16stepu]
 fstp ds:dword ptr[tdivz16stepu]
 fstp ds:dword ptr[sdivz16stepu]

LSpanLoop:
;
; set up the initial s/z, t/z, and 1/z on the FP stack, and generate the
; initial s and t values
;
; FIXME: pipeline FILD?
 fild ds:dword ptr[espan_t_v+ebx]
 fild ds:dword ptr[espan_t_u+ebx]

 fld st(1) ; dv | du | dv
 fmul ds:dword ptr[_d_sdivzstepv] ; dv*d_sdivzstepv | du | dv
 fld st(1) ; du | dv*d_sdivzstepv | du | dv
 fmul ds:dword ptr[_d_sdivzstepu] ; du*d_sdivzstepu | dv*d_sdivzstepv | du | dv
 fld st(2) ; du | du*d_sdivzstepu | dv*d_sdivzstepv | du | dv
 fmul ds:dword ptr[_d_tdivzstepu] ; du*d_tdivzstepu | du*d_sdivzstepu |
; dv*d_sdivzstepv | du | dv
 fxch st(1) ; du*d_sdivzstepu | du*d_tdivzstepu |
; dv*d_sdivzstepv | du | dv
 faddp st(2),st(0) ; du*d_tdivzstepu |
; du*d_sdivzstepu + dv*d_sdivzstepv | du | dv
 fxch st(1) ; du*d_sdivzstepu + dv*d_sdivzstepv |
; du*d_tdivzstepu | du | dv
 fld st(3) ; dv | du*d_sdivzstepu + dv*d_sdivzstepv |
; du*d_tdivzstepu | du | dv
 fmul ds:dword ptr[_d_tdivzstepv] ; dv*d_tdivzstepv |
; du*d_sdivzstepu + dv*d_sdivzstepv |
; du*d_tdivzstepu | du | dv
 fxch st(1) ; du*d_sdivzstepu + dv*d_sdivzstepv |
; dv*d_tdivzstepv | du*d_tdivzstepu | du | dv
 fadd ds:dword ptr[_d_sdivzorigin] ; sdivz = d_sdivzorigin + dv*d_sdivzstepv +
; du*d_sdivzstepu; stays in %st(2) at end
 fxch st(4) ; dv | dv*d_tdivzstepv | du*d_tdivzstepu | du |
; s/z
 fmul ds:dword ptr[_d_zistepv] ; dv*d_zistepv | dv*d_tdivzstepv |
; du*d_tdivzstepu | du | s/z
 fxch st(1) ; dv*d_tdivzstepv | dv*d_zistepv |
; du*d_tdivzstepu | du | s/z
 faddp st(2),st(0) ; dv*d_zistepv |
; dv*d_tdivzstepv + du*d_tdivzstepu | du | s/z
 fxch st(2) ; du | dv*d_tdivzstepv + du*d_tdivzstepu |
; dv*d_zistepv | s/z
 fmul ds:dword ptr[_d_zistepu] ; du*d_zistepu |
; dv*d_tdivzstepv + du*d_tdivzstepu |
; dv*d_zistepv | s/z
 fxch st(1) ; dv*d_tdivzstepv + du*d_tdivzstepu |
; du*d_zistepu | dv*d_zistepv | s/z
 fadd ds:dword ptr[_d_tdivzorigin] ; tdivz = d_tdivzorigin + dv*d_tdivzstepv +
; du*d_tdivzstepu; stays in %st(1) at end
 fxch st(2) ; dv*d_zistepv | du*d_zistepu | t/z | s/z
 faddp st(1),st(0) ; dv*d_zistepv + du*d_zistepu | t/z | s/z

 fld ds:dword ptr[fp_64k] ; fp_64k | dv*d_zistepv + du*d_zistepu | t/z | s/z
 fxch st(1) ; dv*d_zistepv + du*d_zistepu | fp_64k | t/z | s/z
 fadd ds:dword ptr[_d_ziorigin] ; zi = d_ziorigin + dv*d_zistepv +
; du*d_zistepu; stays in %st(0) at end
; 1/z | fp_64k | t/z | s/z
;
; calculate and clamp s & t
;
 fdiv st(1),st(0) ; 1/z | z*64k | t/z | s/z

;
; point %edi to the first pixel in the span
;
 mov ecx,ds:dword ptr[_d_viewbuffer]
 mov eax,ds:dword ptr[espan_t_v+ebx]
 mov ds:dword ptr[pspantemp],ebx ; preserve spans pointer

 mov edx,ds:dword ptr[_tadjust]
 mov esi,ds:dword ptr[_sadjust]
 mov edi,ds:dword ptr[_d_scantable+eax*4] ; v * screenwidth
 add edi,ecx
 mov ecx,ds:dword ptr[espan_t_u+ebx]
 add edi,ecx ; pdest = &pdestspan[scans->u];
 mov ecx,ds:dword ptr[espan_t_count+ebx]

;
; now start the FDIV for the end of the span
;
 cmp ecx,16
 ja LSetupNotLast1

 dec ecx
 jz LCleanup1 ; if only one pixel, no need to start an FDIV
 mov ds:dword ptr[spancountminus1],ecx

; finish up the s and t calcs
 fxch st(1) ; z*64k | 1/z | t/z | s/z

 fld st(0) ; z*64k | z*64k | 1/z | t/z | s/z
 fmul st(0),st(4) ; s | z*64k | 1/z | t/z | s/z
 fxch st(1) ; z*64k | s | 1/z | t/z | s/z
 fmul st(0),st(3) ; t | s | 1/z | t/z | s/z
 fxch st(1) ; s | t | 1/z | t/z | s/z
 fistp ds:dword ptr[s] ; 1/z | t | t/z | s/z
 fistp ds:dword ptr[t] ; 1/z | t/z | s/z

 fild ds:dword ptr[spancountminus1]

 fld ds:dword ptr[_d_tdivzstepu] ; C(d_tdivzstepu) | spancountminus1
 fld ds:dword ptr[_d_zistepu] ; C(d_zistepu) | C(d_tdivzstepu) | spancountminus1
 fmul st(0),st(2) ; C(d_zistepu)*scm1 | C(d_tdivzstepu) | scm1
 fxch st(1) ; C(d_tdivzstepu) | C(d_zistepu)*scm1 | scm1
 fmul st(0),st(2) ; C(d_tdivzstepu)*scm1 | C(d_zistepu)*scm1 | scm1
 fxch st(2) ; scm1 | C(d_zistepu)*scm1 | C(d_tdivzstepu)*scm1
 fmul ds:dword ptr[_d_sdivzstepu] ; C(d_sdivzstepu)*scm1 | C(d_zistepu)*scm1 |
; C(d_tdivzstepu)*scm1
 fxch st(1) ; C(d_zistepu)*scm1 | C(d_sdivzstepu)*scm1 |
; C(d_tdivzstepu)*scm1
 faddp st(3),st(0) ; C(d_sdivzstepu)*scm1 | C(d_tdivzstepu)*scm1
 fxch st(1) ; C(d_tdivzstepu)*scm1 | C(d_sdivzstepu)*scm1
 faddp st(3),st(0) ; C(d_sdivzstepu)*scm1
 faddp st(3),st(0)

 fld ds:dword ptr[fp_64k]
 fdiv st(0),st(1) ; this is what we've gone to all this trouble to
; overlap
 jmp LFDIVInFlight1

LCleanup1:
; finish up the s and t calcs
 fxch st(1) ; z*64k | 1/z | t/z | s/z

 fld st(0) ; z*64k | z*64k | 1/z | t/z | s/z
 fmul st(0),st(4) ; s | z*64k | 1/z | t/z | s/z
 fxch st(1) ; z*64k | s | 1/z | t/z | s/z
 fmul st(0),st(3) ; t | s | 1/z | t/z | s/z
 fxch st(1) ; s | t | 1/z | t/z | s/z
 fistp ds:dword ptr[s] ; 1/z | t | t/z | s/z
 fistp ds:dword ptr[t] ; 1/z | t/z | s/z
 jmp LFDIVInFlight1

 align 4
LSetupNotLast1:
; finish up the s and t calcs
 fxch st(1) ; z*64k | 1/z | t/z | s/z

 fld st(0) ; z*64k | z*64k | 1/z | t/z | s/z
 fmul st(0),st(4) ; s | z*64k | 1/z | t/z | s/z
 fxch st(1) ; z*64k | s | 1/z | t/z | s/z
 fmul st(0),st(3) ; t | s | 1/z | t/z | s/z
 fxch st(1) ; s | t | 1/z | t/z | s/z
 fistp ds:dword ptr[s] ; 1/z | t | t/z | s/z
 fistp ds:dword ptr[t] ; 1/z | t/z | s/z

 fadd ds:dword ptr[zi16stepu]
 fxch st(2)
 fadd ds:dword ptr[sdivz16stepu]
 fxch st(2)
 fld ds:dword ptr[tdivz16stepu]
 faddp st(2),st(0)
 fld ds:dword ptr[fp_64k]
 fdiv st(0),st(1) ; z = 1/1/z
; this is what we've gone to all this trouble to
; overlap
LFDIVInFlight1:

 add esi,ds:dword ptr[s]
 add edx,ds:dword ptr[t]
 mov ebx,ds:dword ptr[_bbextents]
 mov ebp,ds:dword ptr[_bbextentt]
 cmp esi,ebx
 ja LClampHighOrLow0
LClampReentry0:
 mov ds:dword ptr[s],esi
 mov ebx,ds:dword ptr[pbase]
 shl esi,16
 cmp edx,ebp
 mov ds:dword ptr[sfracf],esi
 ja LClampHighOrLow1
LClampReentry1:
 mov ds:dword ptr[t],edx
 mov esi,ds:dword ptr[s] ; sfrac = scans->sfrac;
 shl edx,16
 mov eax,ds:dword ptr[t] ; tfrac = scans->tfrac;
 sar esi,16
 mov ds:dword ptr[tfracf],edx

;
; calculate the texture starting address
;
 sar eax,16
 mov edx,ds:dword ptr[_cachewidth]
 imul eax,edx ; (tfrac >> 16) * cachewidth
 add esi,ebx
 add esi,eax ; psource = pbase + (sfrac >> 16) +
; ((tfrac >> 16) * cachewidth);
;
; determine whether last span or not
;
 cmp ecx,16
 jna LLastSegment

;
; not the last segment; do full 16-wide segment
;
LNotLastSegment:

;
; advance s/z, t/z, and 1/z, and calculate s & t at end of span and steps to
; get there
;

; pick up after the FDIV that was left in flight previously

 fld st(0) ; duplicate it
 fmul st(0),st(4) ; s = s/z * z
 fxch st(1)
 fmul st(0),st(3) ; t = t/z * z
 fxch st(1)
 fistp ds:dword ptr[snext]
 fistp ds:dword ptr[tnext]
 mov eax,ds:dword ptr[snext]
 mov edx,ds:dword ptr[tnext]

 mov bl,ds:byte ptr[esi] ; get first source texel
 sub ecx,16 ; count off this segments' pixels
 mov ebp,ds:dword ptr[_sadjust]
 mov ds:dword ptr[counttemp],ecx ; remember count of remaining pixels

 mov ecx,ds:dword ptr[_tadjust]
 mov ds:byte ptr[edi],bl ; store first dest pixel

 add ebp,eax
 add ecx,edx

 mov eax,ds:dword ptr[_bbextents]
 mov edx,ds:dword ptr[_bbextentt]

 cmp ebp,4096
 jl LClampLow2
 cmp ebp,eax
 ja LClampHigh2
LClampReentry2:

 cmp ecx,4096
 jl LClampLow3
 cmp ecx,edx
 ja LClampHigh3
LClampReentry3:

 mov ds:dword ptr[snext],ebp
 mov ds:dword ptr[tnext],ecx

 sub ebp,ds:dword ptr[s]
 sub ecx,ds:dword ptr[t]

;
; set up advancetable
;
 mov eax,ecx
 mov edx,ebp
 sar eax,20 ; tstep >>= 16;
 jz LZero
 sar edx,20 ; sstep >>= 16;
 mov ebx,ds:dword ptr[_cachewidth]
 imul eax,ebx
 jmp LSetUp1

LZero:
 sar edx,20 ; sstep >>= 16;
 mov ebx,ds:dword ptr[_cachewidth]

LSetUp1:

 add eax,edx ; add in sstep
; (tstep >> 16) * cachewidth + (sstep >> 16);
 mov edx,ds:dword ptr[tfracf]
 mov ds:dword ptr[advancetable+4],eax ; advance base in t
 add eax,ebx ; ((tstep >> 16) + 1) * cachewidth +
; (sstep >> 16);
 shl ebp,12 ; left-justify sstep fractional part
 mov ebx,ds:dword ptr[sfracf]
 shl ecx,12 ; left-justify tstep fractional part
 mov ds:dword ptr[advancetable],eax ; advance extra in t

 mov ds:dword ptr[tstep],ecx
 add edx,ecx ; advance tfrac fractional part by tstep frac

 sbb ecx,ecx ; turn tstep carry into -1 (0 if none)
 add ebx,ebp ; advance sfrac fractional part by sstep frac
 adc esi,ds:dword ptr[advancetable+4+ecx*4] ; point to next source texel

 add edx,ds:dword ptr[tstep]
 sbb ecx,ecx
 mov al,ds:byte ptr[esi]
 add ebx,ebp
 mov ds:byte ptr[1+edi],al
 adc esi,ds:dword ptr[advancetable+4+ecx*4]

 add edx,ds:dword ptr[tstep]
 sbb ecx,ecx
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]

 add edx,ds:dword ptr[tstep]
 sbb ecx,ecx
 mov ds:byte ptr[2+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]

 add edx,ds:dword ptr[tstep]
 sbb ecx,ecx
 mov ds:byte ptr[3+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]

 add edx,ds:dword ptr[tstep]
 sbb ecx,ecx
 mov ds:byte ptr[4+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]

 add edx,ds:dword ptr[tstep]
 sbb ecx,ecx
 mov ds:byte ptr[5+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]

 add edx,ds:dword ptr[tstep]
 sbb ecx,ecx
 mov ds:byte ptr[6+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]

 add edx,ds:dword ptr[tstep]
 sbb ecx,ecx
 mov ds:byte ptr[7+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]


;
; start FDIV for end of next segment in flight, so it can overlap
;
 mov ecx,ds:dword ptr[counttemp]
 cmp ecx,16 ; more than one segment after this?
 ja LSetupNotLast2 ; yes

 dec ecx
 jz LFDIVInFlight2 ; if only one pixel, no need to start an FDIV
 mov ds:dword ptr[spancountminus1],ecx
 fild ds:dword ptr[spancountminus1]

 fld ds:dword ptr[_d_zistepu] ; C(d_zistepu) | spancountminus1
 fmul st(0),st(1) ; C(d_zistepu)*scm1 | scm1
 fld ds:dword ptr[_d_tdivzstepu] ; C(d_tdivzstepu) | C(d_zistepu)*scm1 | scm1
 fmul st(0),st(2) ; C(d_tdivzstepu)*scm1 | C(d_zistepu)*scm1 | scm1
 fxch st(1) ; C(d_zistepu)*scm1 | C(d_tdivzstepu)*scm1 | scm1
 faddp st(3),st(0) ; C(d_tdivzstepu)*scm1 | scm1
 fxch st(1) ; scm1 | C(d_tdivzstepu)*scm1
 fmul ds:dword ptr[_d_sdivzstepu] ; C(d_sdivzstepu)*scm1 | C(d_tdivzstepu)*scm1
 fxch st(1) ; C(d_tdivzstepu)*scm1 | C(d_sdivzstepu)*scm1
 faddp st(3),st(0) ; C(d_sdivzstepu)*scm1
 fld ds:dword ptr[fp_64k] ; 64k | C(d_sdivzstepu)*scm1
 fxch st(1) ; C(d_sdivzstepu)*scm1 | 64k
 faddp st(4),st(0) ; 64k

 fdiv st(0),st(1) ; this is what we've gone to all this trouble to
; overlap
 jmp LFDIVInFlight2

 align 4
LSetupNotLast2:
 fadd ds:dword ptr[zi16stepu]
 fxch st(2)
 fadd ds:dword ptr[sdivz16stepu]
 fxch st(2)
 fld ds:dword ptr[tdivz16stepu]
 faddp st(2),st(0)
 fld ds:dword ptr[fp_64k]
 fdiv st(0),st(1) ; z = 1/1/z
; this is what we've gone to all this trouble to
; overlap
LFDIVInFlight2:
 mov ds:dword ptr[counttemp],ecx

 add edx,ds:dword ptr[tstep]
 sbb ecx,ecx
 mov ds:byte ptr[8+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]

 add edx,ds:dword ptr[tstep]
 sbb ecx,ecx
 mov ds:byte ptr[9+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]

 add edx,ds:dword ptr[tstep]
 sbb ecx,ecx
 mov ds:byte ptr[10+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]

 add edx,ds:dword ptr[tstep]
 sbb ecx,ecx
 mov ds:byte ptr[11+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]

 add edx,ds:dword ptr[tstep]
 sbb ecx,ecx
 mov ds:byte ptr[12+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]

 add edx,ds:dword ptr[tstep]
 sbb ecx,ecx
 mov ds:byte ptr[13+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]

 add edx,ds:dword ptr[tstep]
 sbb ecx,ecx
 mov ds:byte ptr[14+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]

 add edi,16
 mov ds:dword ptr[tfracf],edx
 mov edx,ds:dword ptr[snext]
 mov ds:dword ptr[sfracf],ebx
 mov ebx,ds:dword ptr[tnext]
 mov ds:dword ptr[s],edx
 mov ds:dword ptr[t],ebx

 mov ecx,ds:dword ptr[counttemp] ; retrieve count

;
; determine whether last span or not
;
 cmp ecx,16 ; are there multiple segments remaining?
 mov ds:byte ptr[-1+edi],al
 ja LNotLastSegment ; yes

;
; last segment of scan
;
LLastSegment:

;
; advance s/z, t/z, and 1/z, and calculate s & t at end of span and steps to
; get there. The number of pixels left is variable, and we want to land on the
; last pixel, not step one past it, so we can't run into arithmetic problems
;
 test ecx,ecx
 jz LNoSteps ; just draw the last pixel and we're done

; pick up after the FDIV that was left in flight previously


 fld st(0) ; duplicate it
 fmul st(0),st(4) ; s = s/z * z
 fxch st(1)
 fmul st(0),st(3) ; t = t/z * z
 fxch st(1)
 fistp ds:dword ptr[snext]
 fistp ds:dword ptr[tnext]

 mov al,ds:byte ptr[esi] ; load first texel in segment
 mov ebx,ds:dword ptr[_tadjust]
 mov ds:byte ptr[edi],al ; store first pixel in segment
 mov eax,ds:dword ptr[_sadjust]

 add eax,ds:dword ptr[snext]
 add ebx,ds:dword ptr[tnext]

 mov ebp,ds:dword ptr[_bbextents]
 mov edx,ds:dword ptr[_bbextentt]

 cmp eax,4096
 jl LClampLow4
 cmp eax,ebp
 ja LClampHigh4
LClampReentry4:
 mov ds:dword ptr[snext],eax

 cmp ebx,4096
 jl LClampLow5
 cmp ebx,edx
 ja LClampHigh5
LClampReentry5:

 cmp ecx,1 ; don't bother
 je LOnlyOneStep ; if two pixels in segment, there's only one step,
; of the segment length
 sub eax,ds:dword ptr[s]
 sub ebx,ds:dword ptr[t]

 add eax,eax ; convert to 15.17 format so multiply by 1.31
 add ebx,ebx ; reciprocal yields 16.48

 imul ds:dword ptr[reciprocal_table_16-8+ecx*4] ; sstep = (snext - s) /
; (spancount-1)
 mov ebp,edx

 mov eax,ebx
 imul ds:dword ptr[reciprocal_table_16-8+ecx*4] ; tstep = (tnext - t) /
; (spancount-1)
LSetEntryvec:
;
; set up advancetable
;
 mov ebx,ds:dword ptr[entryvec_table_16+ecx*4]
 mov eax,edx
 mov ds:dword ptr[jumptemp],ebx ; entry point into code for RET later
 mov ecx,ebp
 sar edx,16 ; tstep >>= 16;
 mov ebx,ds:dword ptr[_cachewidth]
 sar ecx,16 ; sstep >>= 16;
 imul edx,ebx

 add edx,ecx ; add in sstep
; (tstep >> 16) * cachewidth + (sstep >> 16);
 mov ecx,ds:dword ptr[tfracf]
 mov ds:dword ptr[advancetable+4],edx ; advance base in t
 add edx,ebx ; ((tstep >> 16) + 1) * cachewidth +
; (sstep >> 16);
 shl ebp,16 ; left-justify sstep fractional part
 mov ebx,ds:dword ptr[sfracf]
 shl eax,16 ; left-justify tstep fractional part
 mov ds:dword ptr[advancetable],edx ; advance extra in t

 mov ds:dword ptr[tstep],eax
 mov edx,ecx
 add edx,eax
 sbb ecx,ecx
 add ebx,ebp
 adc esi,ds:dword ptr[advancetable+4+ecx*4]

 jmp dword ptr[jumptemp] ; jump to the number-of-pixels handler

;----------------------------------------

LNoSteps:
 mov al,ds:byte ptr[esi] ; load first texel in segment
 sub edi,15 ; adjust for hardwired offset
 jmp LEndSpan


LOnlyOneStep:
 sub eax,ds:dword ptr[s]
 sub ebx,ds:dword ptr[t]
 mov ebp,eax
 mov edx,ebx
 jmp LSetEntryvec

;----------------------------------------

 public Entry2_16, Entry3_16, Entry4_16, Entry5_16
 public Entry6_16, Entry7_16, Entry8_16, Entry9_16
 public Entry10_16, Entry11_16, Entry12_16, Entry13_16
 public Entry14_16, Entry15_16, Entry16_16

Entry2_16:
 sub edi,14 ; adjust for hardwired offsets
 mov al,ds:byte ptr[esi]
 jmp LEntry2_16

;----------------------------------------

Entry3_16:
 sub edi,13 ; adjust for hardwired offsets
 add edx,eax
 mov al,ds:byte ptr[esi]
 sbb ecx,ecx
 add ebx,ebp
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
 jmp LEntry3_16

;----------------------------------------

Entry4_16:
 sub edi,12 ; adjust for hardwired offsets
 add edx,eax
 mov al,ds:byte ptr[esi]
 sbb ecx,ecx
 add ebx,ebp
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
 add edx,ds:dword ptr[tstep]
 jmp LEntry4_16

;----------------------------------------

Entry5_16:
 sub edi,11 ; adjust for hardwired offsets
 add edx,eax
 mov al,ds:byte ptr[esi]
 sbb ecx,ecx
 add ebx,ebp
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
 add edx,ds:dword ptr[tstep]
 jmp LEntry5_16

;----------------------------------------

Entry6_16:
 sub edi,10 ; adjust for hardwired offsets
 add edx,eax
 mov al,ds:byte ptr[esi]
 sbb ecx,ecx
 add ebx,ebp
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
 add edx,ds:dword ptr[tstep]
 jmp LEntry6_16

;----------------------------------------

Entry7_16:
 sub edi,9 ; adjust for hardwired offsets
 add edx,eax
 mov al,ds:byte ptr[esi]
 sbb ecx,ecx
 add ebx,ebp
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
 add edx,ds:dword ptr[tstep]
 jmp LEntry7_16

;----------------------------------------

Entry8_16:
 sub edi,8 ; adjust for hardwired offsets
 add edx,eax
 mov al,ds:byte ptr[esi]
 sbb ecx,ecx
 add ebx,ebp
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
 add edx,ds:dword ptr[tstep]
 jmp LEntry8_16

;----------------------------------------

Entry9_16:
 sub edi,7 ; adjust for hardwired offsets
 add edx,eax
 mov al,ds:byte ptr[esi]
 sbb ecx,ecx
 add ebx,ebp
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
 add edx,ds:dword ptr[tstep]
 jmp LEntry9_16

;----------------------------------------

Entry10_16:
 sub edi,6 ; adjust for hardwired offsets
 add edx,eax
 mov al,ds:byte ptr[esi]
 sbb ecx,ecx
 add ebx,ebp
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
 add edx,ds:dword ptr[tstep]
 jmp LEntry10_16

;----------------------------------------

Entry11_16:
 sub edi,5 ; adjust for hardwired offsets
 add edx,eax
 mov al,ds:byte ptr[esi]
 sbb ecx,ecx
 add ebx,ebp
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
 add edx,ds:dword ptr[tstep]
 jmp LEntry11_16

;----------------------------------------

Entry12_16:
 sub edi,4 ; adjust for hardwired offsets
 add edx,eax
 mov al,ds:byte ptr[esi]
 sbb ecx,ecx
 add ebx,ebp
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
 add edx,ds:dword ptr[tstep]
 jmp LEntry12_16

;----------------------------------------

Entry13_16:
 sub edi,3 ; adjust for hardwired offsets
 add edx,eax
 mov al,ds:byte ptr[esi]
 sbb ecx,ecx
 add ebx,ebp
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
 add edx,ds:dword ptr[tstep]
 jmp LEntry13_16

;----------------------------------------

Entry14_16:
 sub edi,2 ; adjust for hardwired offsets
 add edx,eax
 mov al,ds:byte ptr[esi]
 sbb ecx,ecx
 add ebx,ebp
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
 add edx,ds:dword ptr[tstep]
 jmp LEntry14_16

;----------------------------------------

Entry15_16:
 dec edi ; adjust for hardwired offsets
 add edx,eax
 mov al,ds:byte ptr[esi]
 sbb ecx,ecx
 add ebx,ebp
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
 add edx,ds:dword ptr[tstep]
 jmp LEntry15_16

;----------------------------------------

Entry16_16:
 add edx,eax
 mov al,ds:byte ptr[esi]
 sbb ecx,ecx
 add ebx,ebp
 adc esi,ds:dword ptr[advancetable+4+ecx*4]

 add edx,ds:dword ptr[tstep]
 sbb ecx,ecx
 mov ds:byte ptr[1+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
 add edx,ds:dword ptr[tstep]
LEntry15_16:
 sbb ecx,ecx
 mov ds:byte ptr[2+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
 add edx,ds:dword ptr[tstep]
LEntry14_16:
 sbb ecx,ecx
 mov ds:byte ptr[3+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
 add edx,ds:dword ptr[tstep]
LEntry13_16:
 sbb ecx,ecx
 mov ds:byte ptr[4+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
 add edx,ds:dword ptr[tstep]
LEntry12_16:
 sbb ecx,ecx
 mov ds:byte ptr[5+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
 add edx,ds:dword ptr[tstep]
LEntry11_16:
 sbb ecx,ecx
 mov ds:byte ptr[6+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
 add edx,ds:dword ptr[tstep]
LEntry10_16:
 sbb ecx,ecx
 mov ds:byte ptr[7+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
 add edx,ds:dword ptr[tstep]
LEntry9_16:
 sbb ecx,ecx
 mov ds:byte ptr[8+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
 add edx,ds:dword ptr[tstep]
LEntry8_16:
 sbb ecx,ecx
 mov ds:byte ptr[9+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
 add edx,ds:dword ptr[tstep]
LEntry7_16:
 sbb ecx,ecx
 mov ds:byte ptr[10+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
 add edx,ds:dword ptr[tstep]
LEntry6_16:
 sbb ecx,ecx
 mov ds:byte ptr[11+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
 add edx,ds:dword ptr[tstep]
LEntry5_16:
 sbb ecx,ecx
 mov ds:byte ptr[12+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
 add edx,ds:dword ptr[tstep]
LEntry4_16:
 sbb ecx,ecx
 mov ds:byte ptr[13+edi],al
 add ebx,ebp
 mov al,ds:byte ptr[esi]
 adc esi,ds:dword ptr[advancetable+4+ecx*4]
LEntry3_16:
 mov ds:byte ptr[14+edi],al
 mov al,ds:byte ptr[esi]
LEntry2_16:

LEndSpan:

;
; clear s/z, t/z, 1/z from FP stack
;
 fstp st(0)
 fstp st(0)
 fstp st(0)

 mov ebx,ds:dword ptr[pspantemp] ; restore spans pointer
 mov ebx,ds:dword ptr[espan_t_pnext+ebx] ; point to next span
 test ebx,ebx ; any more spans?
 mov ds:byte ptr[15+edi],al
 jnz LSpanLoop ; more spans

 pop ebx ; restore register variables
 pop esi
 pop edi
 pop ebp ; restore the caller's stack frame
 ret


;----------------------------------------------------------------------
; 8-bpp horizontal span z drawing codefor polygons, with no transparency.
;
; Assumes there is at least one span in pzspans, and that every span
; contains at least one pixel
;----------------------------------------------------------------------



; z-clamp on a non-negative gradient span
LClamp:
 mov edx,040000000h
 xor ebx,ebx
 fstp st(0)
 jmp LZDraw

; z-clamp on a negative gradient span
LClampNeg:
 mov edx,040000000h
 xor ebx,ebx
 fstp st(0)
 jmp LZDrawNeg


pzspans equ 4+16

 public _D_DrawZSpans
_D_DrawZSpans:
 push ebp ; preserve caller's stack frame
 push edi
 push esi ; preserve register variables
 push ebx

 fld ds:dword ptr[_d_zistepu]
 mov eax,ds:dword ptr[_d_zistepu]
 mov esi,ds:dword ptr[pzspans+esp]
 test eax,eax
 jz LFNegSpan

 fmul ds:dword ptr[Float2ToThe31nd]
 fistp ds:dword ptr[izistep] ; note: we are relying on FP exceptions being turned
; off here to avoid range problems
 mov ebx,ds:dword ptr[izistep] ; remains loaded for all spans

LFSpanLoop:
; set up the initial 1/z value
 fild ds:dword ptr[espan_t_v+esi]
 fild ds:dword ptr[espan_t_u+esi]
 mov ecx,ds:dword ptr[espan_t_v+esi]
 mov edi,ds:dword ptr[_d_pzbuffer]
 fmul ds:dword ptr[_d_zistepu]
 fxch st(1)
 fmul ds:dword ptr[_d_zistepv]
 fxch st(1)
 fadd ds:dword ptr[_d_ziorigin]
 imul ecx,ds:dword ptr[_d_zrowbytes]
 faddp st(1),st(0)

; clamp if z is nearer than 2 (1/z > 0.5)
 fcom ds:dword ptr[float_point5]
 add edi,ecx
 mov edx,ds:dword ptr[espan_t_u+esi]
 add edx,edx ; word count
 mov ecx,ds:dword ptr[espan_t_count+esi]
 add edi,edx ; pdest = &pdestspan[scans->u];
 push esi ; preserve spans pointer
 fnstsw ax
 test ah,045h
 jz LClamp

 fmul ds:dword ptr[Float2ToThe31nd]
 fistp ds:dword ptr[izi] ; note: we are relying on FP exceptions being turned
; off here to avoid problems when the span is closer
; than 1/(2**31)
 mov edx,ds:dword ptr[izi]

; at this point:
; %ebx = izistep
; %ecx = count
; %edx = izi
; %edi = pdest

LZDraw:

; do a single pixel up front, if necessary to dword align the destination
 test edi,2
 jz LFMiddle
 mov eax,edx
 add edx,ebx
 shr eax,16
 dec ecx
 mov ds:word ptr[edi],ax
 add edi,2

; do middle a pair of aligned dwords at a time
LFMiddle:
 push ecx
 shr ecx,1 ; count / 2
 jz LFLast ; no aligned dwords to do
 shr ecx,1 ; (count / 2) / 2
 jnc LFMiddleLoop ; even number of aligned dwords to do

 mov eax,edx
 add edx,ebx
 shr eax,16
 mov esi,edx
 add edx,ebx
 and esi,0FFFF0000h
 or eax,esi
 mov ds:dword ptr[edi],eax
 add edi,4
 and ecx,ecx
 jz LFLast

LFMiddleLoop:
 mov eax,edx
 add edx,ebx
 shr eax,16
 mov esi,edx
 add edx,ebx
 and esi,0FFFF0000h
 or eax,esi
 mov ebp,edx
 mov ds:dword ptr[edi],eax
 add edx,ebx
 shr ebp,16
 mov esi,edx
 add edx,ebx
 and esi,0FFFF0000h
 or ebp,esi
 mov ds:dword ptr[4+edi],ebp ; FIXME: eliminate register contention
 add edi,8

 dec ecx
 jnz LFMiddleLoop

LFLast:
 pop ecx ; retrieve count
 pop esi ; retrieve span pointer

; do the last, unaligned pixel, if there is one
 and ecx,1 ; is there an odd pixel left to do?
 jz LFSpanDone ; no
 shr edx,16
 mov ds:word ptr[edi],dx ; do the final pixel's z

LFSpanDone:
 mov esi,ds:dword ptr[espan_t_pnext+esi]
 test esi,esi
 jnz LFSpanLoop

 jmp LFDone

LFNegSpan:
 fmul ds:dword ptr[FloatMinus2ToThe31nd]
 fistp ds:dword ptr[izistep] ; note: we are relying on FP exceptions being turned
; off here to avoid range problems
 mov ebx,ds:dword ptr[izistep] ; remains loaded for all spans

LFNegSpanLoop:
; set up the initial 1/z value
 fild ds:dword ptr[espan_t_v+esi]
 fild ds:dword ptr[espan_t_u+esi]
 mov ecx,ds:dword ptr[espan_t_v+esi]
 mov edi,ds:dword ptr[_d_pzbuffer]
 fmul ds:dword ptr[_d_zistepu]
 fxch st(1)
 fmul ds:dword ptr[_d_zistepv]
 fxch st(1)
 fadd ds:dword ptr[_d_ziorigin]
 imul ecx,ds:dword ptr[_d_zrowbytes]
 faddp st(1),st(0)

; clamp if z is nearer than 2 (1/z > 0.5)
 fcom ds:dword ptr[float_point5]
 add edi,ecx
 mov edx,ds:dword ptr[espan_t_u+esi]
 add edx,edx ; word count
 mov ecx,ds:dword ptr[espan_t_count+esi]
 add edi,edx ; pdest = &pdestspan[scans->u];
 push esi ; preserve spans pointer
 fnstsw ax
 test ah,045h
 jz LClampNeg

 fmul ds:dword ptr[Float2ToThe31nd]
 fistp ds:dword ptr[izi] ; note: we are relying on FP exceptions being turned
; off here to avoid problems when the span is closer
; than 1/(2**31)
 mov edx,ds:dword ptr[izi]

; at this point:
; %ebx = izistep
; %ecx = count
; %edx = izi
; %edi = pdest

LZDrawNeg:

; do a single pixel up front, if necessary to dword align the destination
 test edi,2
 jz LFNegMiddle
 mov eax,edx
 sub edx,ebx
 shr eax,16
 dec ecx
 mov ds:word ptr[edi],ax
 add edi,2

; do middle a pair of aligned dwords at a time
LFNegMiddle:
 push ecx
 shr ecx,1 ; count / 2
 jz LFNegLast ; no aligned dwords to do
 shr ecx,1 ; (count / 2) / 2
 jnc LFNegMiddleLoop ; even number of aligned dwords to do

 mov eax,edx
 sub edx,ebx
 shr eax,16
 mov esi,edx
 sub edx,ebx
 and esi,0FFFF0000h
 or eax,esi
 mov ds:dword ptr[edi],eax
 add edi,4
 and ecx,ecx
 jz LFNegLast

LFNegMiddleLoop:
 mov eax,edx
 sub edx,ebx
 shr eax,16
 mov esi,edx
 sub edx,ebx
 and esi,0FFFF0000h
 or eax,esi
 mov ebp,edx
 mov ds:dword ptr[edi],eax
 sub edx,ebx
 shr ebp,16
 mov esi,edx
 sub edx,ebx
 and esi,0FFFF0000h
 or ebp,esi
 mov ds:dword ptr[4+edi],ebp ; FIXME: eliminate register contention
 add edi,8

 dec ecx
 jnz LFNegMiddleLoop

LFNegLast:
 pop ecx ; retrieve count
 pop esi ; retrieve span pointer

; do the last, unaligned pixel, if there is one
 and ecx,1 ; is there an odd pixel left to do?
 jz LFNegSpanDone ; no
 shr edx,16
 mov ds:word ptr[edi],dx ; do the final pixel's z

LFNegSpanDone:
 mov esi,ds:dword ptr[espan_t_pnext+esi]
 test esi,esi
 jnz LFNegSpanLoop

LFDone:
 pop ebx ; restore register variables
 pop esi
 pop edi
 pop ebp ; restore the caller's stack frame
 ret



_TEXT ENDS
endif ;id386
 END
Something went wrong with that request. Please try again.