home *** CD-ROM | disk | FTP | other *** search
/ Excalibur 51 / Excalibur_51_cd.bin / wing / fast32.as_ / fast32.as
Text File  |  1994-08-13  |  7KB  |  292 lines

  1.     page ,132
  2.     TITLE FAST32.ASM
  3. ;---------------------------------------------------------------------------;
  4. ;  FAST.ASM
  5. ;
  6. ;  32 bit asm routines for doing a "sprite" bitblt
  7. ;
  8. ;      TransCopyDIBBits - copy DIB bits with a transparent color
  9. ;      CopyDIBBits      - copy DIB bits without a transparent color
  10. ;
  11. ;   (C) Copyright 1994 Microsoft Corp.  All rights reserved.
  12. ;
  13. ;   You have a royalty-free right to use, modify, reproduce and
  14. ;   distribute the Sample Files (and/or any modified version) in
  15. ;   any way you find useful, provided that you agree that
  16. ;   Microsoft has no warranty obligations or liability for any
  17. ;   Sample Application Files which are modified.
  18. ;
  19. ;---------------------------------------------------------------------------;
  20.  
  21. ;
  22. ; 32 bit code segment version of FAST16.ASM
  23. ;
  24. ; NOTE! cmacro32.inc needs MASM 5.1 compatibility
  25. ; Run MASM 6 specifying option: /Zm   (provides MASM 5.1 compatibility)
  26. ;
  27.     .xlist
  28.     include cmacro32.inc
  29.     .list
  30.  
  31. ;
  32. ; NOTE!!!! because we are generating USE32 code this must NOT
  33. ; be located in a code segment with USE16 code, so we put it into
  34. ; it's own little segment....
  35. ;
  36.  
  37. ifndef SEGNAME
  38.     SEGNAME equ <FAST_TEXT32>
  39. endif
  40.  
  41. createSeg %SEGNAME, CodeSeg, dword, use32, CODE
  42.  
  43. sBegin Data
  44. sEnd Data
  45.  
  46. sBegin CodeSeg
  47.         assumes cs,CodeSeg
  48.         assumes ds,nothing
  49.         assumes es,nothing
  50.  
  51. ;-------------------------------------------------------
  52. ;
  53. ; TransCopyDIBBits
  54. ;
  55. ; Copy a block with transparency
  56. ;
  57. ;-------------------------------------------------------
  58.  
  59. cProc TransCopyDIBBits,<FAR, PASCAL, PUBLIC>,<>
  60.         ParmW   DestSelector    ; dest 48bit pointer
  61.         ParmD   DestOffset
  62.         ParmD   pSource         ; source pointer
  63.         ParmD   dwWidth         ; width pixels
  64.         ParmD   dwHeight        ; height pixels
  65.         ParmD   dwScanD         ; width bytes dest
  66.         ParmD   dwScanS         ; width bytes source
  67.         ParmB   bTranClr        ; transparent color
  68. cBegin
  69.         push ds
  70.         push esi
  71.         push edi
  72.  
  73.         mov ecx, dwWidth
  74.         or ecx,ecx
  75.         jz tcdb_nomore     ; test for silly case
  76.  
  77.         mov edx, dwHeight       ; EDX is line counter
  78.         mov ah, bTranClr        ; AL has transparency color
  79.  
  80.         xor esi, esi
  81.         lds si, pSource         ; DS:[ESI] point to source
  82.  
  83.         mov es, DestSelector    ; es:[edi] point to dest
  84.         mov edi, DestOffset
  85.  
  86.         sub dwScanD,ecx         ; bias these
  87.         sub dwScanS,ecx
  88.  
  89.         mov ebx,ecx             ; save this for later
  90.  
  91.         align 4
  92.  
  93. tcdb_morelines:
  94.         mov ecx, ebx            ; ECX is pixel counter
  95.         shr ecx,2
  96.         jz  short tcdb_nextscan
  97.  
  98. ;
  99. ; The idea here is to not branch very often so we unroll the loop by four
  100. ; and try to not branch when a whole run of pixels is either transparent
  101. ; or not transparent.
  102. ;
  103. ; There are two loops. One loop is for a run of pixels equal to the
  104. ; transparent color, the other is for runs of pixels we need to store.
  105. ;
  106. ; When we detect a "bad" pixel we jump to the same position in the
  107. ; other loop.
  108. ;
  109. ; Here is the loop we will stay in as long as we encounter a "transparent"
  110. ; pixel in the source.
  111. ;
  112.  
  113.         align 4
  114.  
  115. tcdb_same:
  116.         mov al, ds:[esi]
  117.         cmp al, ah
  118.         jne short tcdb_diff0
  119.  
  120. tcdb_same0:
  121.         mov al, ds:[esi+1]
  122.         cmp al, ah
  123.         jne short tcdb_diff1
  124.  
  125. tcdb_same1:
  126.         mov al, ds:[esi+2]
  127.         cmp al, ah
  128.         jne short tcdb_diff2
  129.  
  130. tcdb_same2:
  131.         mov al, ds:[esi+3]
  132.         cmp al, ah
  133.         jne short tcdb_diff3
  134.  
  135. tcdb_same3:
  136.         add edi,4
  137.         add esi,4
  138.         dec ecx
  139.         jnz short tcdb_same
  140.         jz  short tcdb_nextscan
  141.  
  142. ;
  143. ; Here is the loop we will stay in as long as 
  144. ; we encounter a "non transparent" pixel in the source.
  145. ;
  146.  
  147.         align 4
  148.  
  149. tcdb_diff:
  150.         mov al, ds:[esi]
  151.         cmp al, ah
  152.         je short tcdb_same0
  153.  
  154. tcdb_diff0:
  155.         mov es:[edi],al
  156.         mov al, ds:[esi+1]
  157.         cmp al, ah
  158.         je short tcdb_same1
  159.  
  160. tcdb_diff1:
  161.         mov es:[edi+1],al
  162.         mov al, ds:[esi+2]
  163.         cmp al, ah
  164.         je short tcdb_same2
  165.  
  166. tcdb_diff2:
  167.         mov es:[edi+2],al
  168.         mov al, ds:[esi+3]
  169.         cmp al, ah
  170.         je short tcdb_same3
  171.  
  172. tcdb_diff3:
  173.         mov es:[edi+3],al
  174.  
  175.         add edi,4
  176.         add esi,4
  177.         dec ecx
  178.         jnz short tcdb_diff
  179.         jz  short tcdb_nextscan
  180.  
  181. ;
  182. ; We are at the end of a scan, check for odd leftover pixels to do
  183. ; and go to the next scan.
  184. ;
  185.  
  186.         align 4
  187.  
  188. tcdb_nextscan:
  189.         mov ecx,ebx
  190.         and ecx,11b
  191.         jnz short tcdb_oddstuff
  192.         ; move on to the start of the next line
  193.  
  194. tcdb_nextscan1:
  195.         add esi, dwScanS
  196.         add edi, dwScanD
  197.  
  198.         dec edx                 ; line counter
  199.         jnz short tcdb_morelines
  200.         jz  short tcdb_nomore
  201.  
  202. ;
  203. ; If the width is not a multiple of 4 we will come here to clean up
  204. ; the last few pixels
  205. ;
  206.  
  207. tcdb_oddstuff:
  208.         inc ecx
  209. tcdb_oddloop:
  210.         dec ecx
  211.         jz  short tcdb_nextscan1
  212.         mov al, ds:[esi]
  213.         inc esi
  214.         inc edi
  215.         cmp al, ah
  216.         je  short tcdb_oddloop
  217.         mov es:[edi-1],al
  218.         jmp short tcdb_oddloop
  219.  
  220. tcdb_nomore:
  221.         pop edi
  222.         pop esi
  223.         pop ds
  224. cEnd
  225.  
  226. ;-----------------------------------------------------------------------------;
  227. ;
  228. ; CopyDIBBits
  229. ;
  230. ; Copy a block without transparency
  231. ;
  232. ;-----------------------------------------------------------------------------;
  233.  
  234. cProc CopyDIBBits,<FAR, PASCAL, PUBLIC>,<>
  235.         ParmD   pDest           ; dest pointer
  236.         ParmD   pSource         ; source pointer
  237.         ParmD   dwWidth         ; width pixels
  238.         ParmD   dwHeight        ; height pixels
  239.         ParmD   dwScanD         ; width bytes dest
  240.         ParmD   dwScanS         ; width bytes source
  241. cBegin
  242.         push ds
  243.         push esi
  244.         push edi
  245.  
  246.         mov ecx, dwWidth
  247.         or ecx,ecx
  248.         jz cdb_nomore     ; test for silly case
  249.  
  250.         mov edx, dwHeight       ; EDX is line counter
  251.         or edx,edx
  252.         jz cdb_nomore     ; test for silly case
  253.  
  254.         xor esi, esi
  255.         lds si, pSource         ; DS:[ESI] point to source
  256.  
  257.         xor edi, edi
  258.         les di, pDest           ; ES:[EDI] point to dest
  259.  
  260.         sub dwScanD,ecx         ; bias these
  261.         sub dwScanS,ecx
  262.  
  263.         mov ebx,ecx
  264.         shr ebx,2
  265.  
  266.         mov eax,ecx
  267.         and eax,11b
  268.  
  269.         align 4
  270.  
  271. cdb_loop:
  272.         mov ecx, ebx
  273.         rep movs dword ptr es:[edi], dword ptr ds:[esi]
  274.         mov ecx,eax
  275.         rep movs byte ptr es:[edi], byte ptr ds:[esi]
  276.  
  277.         add esi, dwScanS
  278.         add edi, dwScanD
  279.         dec edx                 ; line counter
  280.         jnz short cdb_loop
  281.  
  282. cdb_nomore:
  283.         pop edi
  284.         pop esi
  285.         pop ds
  286. cEnd
  287.  
  288.  
  289.  
  290. sEnd CodeSeg
  291. end
  292.