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