home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / grafik / xlib / xvbitmap.asm < prev    next >
Encoding:
Assembly Source File  |  1992-11-12  |  21.7 KB  |  677 lines

  1. ;-----------------------------------------------------------------------
  2. ; MODULE XVBITMAP
  3. ;
  4. ; Video Bitmap functions - Video Ram <-> Video Ram
  5. ;
  6. ; Compile with Tasm.
  7. ; C callable.
  8. ;
  9. ;
  10. ; ****** XLIB - Mode X graphics library                ****************
  11. ; ******                                               ****************
  12. ; ****** Written By Themie Gouthas                     ****************
  13. ;
  14. ; egg@dstos3.dsto.gov.au
  15. ; teg@bart.dsto.gov.au
  16. ;-----------------------------------------------------------------------
  17. COMMENT $
  18.  
  19. The XVBITMAP module implements yet another type of bitmap to complement
  20. planar and compiled bitmaps, VRAM based bitmaps. If a 4 cylinder car is
  21. analagous to planar bitmaps, that is thrifty on memory consumption but low
  22. performance and and a V8 is analagous to Compiled bitmaps, memory guzzlers
  23. that really fly, then VRAM based bitmaps are the 6 cylinder modest performers
  24. with acceptable memory consumption.
  25.  
  26. To summarise their selling points, VBM's are moderately fast with fair memory
  27. consumption, and unlike compiled bitmaps, can be clipped. The disadvantages
  28. are that they are limited by the amount of free video ram and have a complex
  29. structure.
  30.  
  31. The VRAM bitmap format is rather complex consisting of components stored in
  32. video ram and components in system ram working together. This complexity
  33. necessitates the existence of a creation function "x_make_vbm" which takes
  34. an input linear bitmap and generates the equivalent VBM (VRAM Bit Map).
  35.  
  36. VBM structure:
  37.  
  38.       WORD  0   Size          Total size of this VBM structure in bytes
  39.       WORD  1   ImageWidth    Width in bytes of the image (for all alignments)
  40.       WORD  2   ImageHeight   Height in scan lines of the image
  41.  
  42.       WORD  3 Alignment 0  ImagePtr   Offset in VidRAM of this aligned image
  43.    +--WORD  4              MaskPtr    Offset (within this structure's DS) of
  44.    |   .                   alignment masks
  45.    |   .
  46.    |   .
  47.    |  WORD  9 Alignment 3  ImagePtr   Offset in VidRAM of this aligned image
  48.   +|--WORD 10              MaskPtr    Offset (within this structure's DS) of
  49.   ||                              alignment masks
  50.   ||
  51.   |+->BYTE 21 (WORD 11)                -------+-- Image masks for alignment 0
  52.   |   .                                       |
  53.   |   .                                       |
  54.   |   BYTE  21 + ImageWidth*ImageHeight  -----+
  55.   |
  56.   |   .
  57.   |   . (similaly for alignments 1 - 2 )
  58.   |   .
  59.   |
  60.   +-->BYTE  21 + 3*ImageWidth*ImageHeight + 1-+-- Image masks for alignment 3
  61.       .                                       |
  62.       .                                       |
  63.       BYTE  21 + 4*(ImageWidth*ImageHeight) --+
  64.  
  65.       .
  66.       .
  67.       << Similarly for alignments 2 and 3 >>
  68.       .
  69.       .
  70.       BYTE 21 + 4*(ImageWidth*ImageHeight)
  71.   -------------
  72.  
  73.   (And dont forget the corresponding data in video ram)
  74.  
  75. $
  76.  
  77.  
  78. include xlib.inc
  79. include xvbitmap.inc
  80.  
  81. VBM_info_struc struc
  82.   Size        dw ?
  83.   ImageWidth  dw ?
  84.   ImageHeight dw ?
  85. ;  AlignData   dw ?
  86. VBM_info_struc ends
  87.  
  88. AlignData equ 6
  89.  
  90. VBM_alignment_struc struc
  91.   ImagePtr    dw ?
  92.   MaskPtr     dw ?
  93. VBM_alignment_struc ends
  94.  
  95.  
  96.     .code
  97.  
  98.  
  99. ;----------------------------------------------------------------------
  100. ; x_store_vbm_image
  101. ;
  102. ;  Store the linear bitmap in video RAM using the specified alignment and
  103. ;  start address. Returns number video ram bytes used.
  104. ;
  105. ;  THIS FUNCTION IS FOR USE BY x_make_masked_vbm
  106. ;
  107. ; Prototype:
  108. ;
  109. ;  x_store_vbm_image(unsigned int vramoffs, unsigned int Align,
  110. ;         char far *lbm);
  111. ;
  112. ;
  113. ; Written by Themie Gouthas
  114. ;----------------------------------------------------------------------
  115. _x_store_vbm_image  proc
  116.     ARG VramOffs:word,Align:word,LBitmap:dword
  117.     LOCAL BMWidth:byte=LocalStk
  118.     push  bp
  119.         mov   bp,sp
  120.     sub   sp,LocalStk                 ; Create space for local variables
  121.         push  si
  122.         push  di
  123.     push  ds
  124.     cld
  125.  
  126.     mov   ax,SCREEN_SEG               ; Point ES to screen segment
  127.     mov   es,ax
  128.     mov   di,[VramOffs]               ; Point ES:DI to VRAM dest start
  129.     mov   bx,[Align]                  ; Set BL to first pixel plane align
  130.         and   bl,03h
  131.  
  132.     lds   si,[LBitmap]                ; DS:SI -> source linear Bitmap
  133.         lodsw                             ; Al = B.M. width (bytes) AH = B.M.
  134.     mov   bh,ah                       ; Save source bitmap dimensions
  135.     mov   [BMWidth],al                ;
  136.  
  137.     mov   dx,SC_INDEX                 ; Initialize Map Mask for plane
  138.     mov   al,MAP_MASK                 ; selection
  139.         out   dx,al
  140.     inc   dx
  141.     xor   ch,ch                       ; clear CH
  142. @@RowLoop:
  143.     mov   cl,bl                       ; Set initial plane for current
  144.     mov   ah,11h                      ; allignment
  145.     shl   ah,cl
  146.  
  147.     mov   cl,[BMWidth]                ; Initialize column counter
  148. @@ColLoop:
  149.     mov   al,ah
  150.         out   dx,al                       ; set vga write plane
  151.     lodsb                             ; load next LBM pixel
  152.     mov   es:[di],al                  ; store it in Video Ram
  153.     shl   ah,1                        ; rotate plane mask
  154.     jnb   @@NoAddrIncr                ; Time to increment dest address ?
  155.     inc   di                          ; Yes: increment addr and reset
  156.     mov   ah,11h                      ;  plane mask to plane 0
  157. @@NoAddrIncr:
  158.     loop  @@ColLoop                   ; Loop to next pixel column
  159.     cmp   ah,11h
  160. ;    je    @@skip
  161.     inc   di                ; Increment dest addr
  162. ;@@skip:
  163.     dec   bh                          ; Decrement row counter
  164.     jnz   @@RowLoop                   ; Jump if more rows to go
  165.     mov   ax,di                       ; calculate video RAM consumed and
  166.     sub   ax,[VramOffs]               ;   return value
  167.  
  168.         pop   ds                          ; restore data segment
  169.     pop   di                          ; restore registers
  170.         pop   si
  171.         mov   sp,bp                       ; dealloc local variables
  172.     pop   bp
  173.         ret
  174. _x_store_vbm_image  endp
  175.  
  176.  
  177. _x_put_masked_vbm  proc
  178.     ARG X:word,Y:word,ScrnOffs:word,SrcVBM:dword
  179.     LOCAL VBMWidth:word,VBMHeight:word,NextLineIncr:word=LocalStk
  180.     push  bp
  181.         mov   bp,sp
  182.     sub   sp,LocalStk                 ; Create space for local variables
  183.         push  si
  184.         push  di
  185.     push  ds
  186.     cld
  187.  
  188.     mov   ax,SCREEN_SEG               ; Point es to VGA segment
  189.         mov   es,ax
  190.         mov   ax,[Y]                      ; Calculate dest screen row
  191.     mov   cx,[_ScrnLogicalByteWidth]  ;  by mult. dest Y coord by Screen
  192.     mul   cx                          ;  width then adding screen offset
  193.  
  194.     mov   di,[ScrnOffs]               ;  store result in DI
  195.         add   di,ax
  196.     mov   si,[X]                      ; Load X coord into CX and make a
  197.     mov   bx,si                       ;  copy in DX
  198.     shr   bx,2                        ; Find starting byte in dest row
  199.     add   di,bx                       ;  add to DI giving screen offset of
  200.                                           ;  first pixel's byte
  201.  
  202.     and   si,3                        ; get pixel alignment in si
  203.  
  204.     lds   bx,[SrcVBM]                 ; DS:BX -> VBM data structure
  205.     shl   si,2                        ; si = offset of data  for curr
  206.                       ; alignment
  207.  
  208.     mov ax,word ptr [bx+ImageHeight]  ; Get image height
  209.     mov   [VBMHeight],ax
  210.     mov ax,word ptr [bx+ImageWidth]   ; Get image width
  211.     mov   [VBMWidth],ax
  212.  
  213.     sub   cx,ax                       ; NextLineIncr = bytes to the begin.
  214.     mov   [NextLineIncr],cx           ;  of bitmaps next row on screen
  215.     mov   dx,[bx+MaskPtr+AlignData+si]  ; DS:SI -> mask data
  216.     mov   bx,[bx+ImagePtr+AlignData+si] ; ES:BX -> source video bitmap
  217.     mov   si,dx
  218.  
  219.     mov   dx,GC_INDEX                 ; Set bit mask for all bits from
  220.     mov   ax,BIT_MASK                 ; VGA latches and none from CPU
  221.     out   dx,ax
  222.  
  223.     mov   dx,SC_INDEX                 ; Point SC register to map mask
  224.     mov   al,MAP_MASK                 ; in preperation for masking data
  225.     out   dx,al
  226.     inc   dx                          ; Point dx to SC data register
  227.     mov   ah,byte ptr [VBMHeight]     ; AH = Scanline loop counter
  228.  
  229. @@RowLoop:
  230.     mov   cx,[VBMWidth]               ; Width in bytes across
  231.  
  232. @@ColumnLoop:
  233.     lodsb
  234.     out   dx,al
  235.     mov   al,es:[bx]                  ; load latches from source bitmap
  236.     stosb                             ; store latches to dest. bitmap
  237.     inc   bx
  238.     loop  @@ColumnLoop
  239.  
  240.     add   di,[NextLineIncr]           ; point to start of next dest row
  241.     dec   ah                          ; decrement scan line counter
  242.     jnz   @@RowLoop                   ; jump if more scanlines left
  243.  
  244.     mov   dx,GC_INDEX+1               ; Restore bitmask to the default -
  245.     mov   al,0ffh                     ;  all data from cpu
  246.     out   dx,al
  247.  
  248.         pop   ds                          ; restore data segment
  249.         pop   di                          ; restore registers
  250.         pop   si
  251.         mov   sp,bp                       ; dealloc local variables
  252.         pop   bp
  253.         ret
  254. _x_put_masked_vbm  endp
  255.  
  256.  
  257. _x_put_masked_vbm_clipx  proc
  258. ARG X:word,Y:word,ScrnOffs:word,SrcVBM:dword
  259. LOCAL DataInc,LeftSkip,VBMWidth,VBMHeight,NextLineIncr:word=LocalStk
  260.     push  bp
  261.         mov   bp,sp
  262.     sub   sp,LocalStk             ; Create space for local variables
  263.         push  si
  264.         push  di
  265.     push  ds
  266.     cld
  267.  
  268.     mov   di,[X]                  ; load X coord int DI and make a
  269.     mov   si,di                   ;  copy in SI
  270.     shr   di,2                    ; Find Byte offset of X coord
  271.  
  272.     and   si,3                    ; Calculate pixels plane alignment
  273.     shl   si,2                    ; Prepare to lookup mask & data
  274.     les   bx,[SrcVBM]             ; ES:BX -> begining of VBM data
  275.  
  276.     mov   cx,es:[bx+ImageWidth]   ; Get image width and save in CX
  277.  
  278.  
  279.  
  280.     ;;;;; CLIP PROCESSING FOR LEFT CLIP BORDER ;;;;;;;;;;;;;;;;;;;
  281.  
  282.     mov   dx,[_LeftClip]
  283.     sub   dx,di
  284.     jle   @@NotLeftClip
  285.     cmp   dx,cx
  286.     jnl   @@NotVisible
  287.     add   di,dx
  288.     mov   [LeftSkip],dx
  289.     mov   [DataInc],dx
  290.     sub   cx,dx
  291.     jmp   short @@HorizClipDone
  292.  
  293.         ;;;; EXIT FOR COMPLETELY OBSCURED V.B.M's ;;;;;;;;;;;;;;;;;;;;;;
  294.  
  295. @@NotVisible:
  296.     pop   ds                          ; restore data segment
  297.     pop   di                          ; restore registers
  298.     pop   si
  299.     mov   sp,bp                       ; dealloc local variables
  300.     pop   bp
  301.     ret
  302.  
  303.     ;;;;; CLIP PROCESSING FOR RIGHT CLIP BORDER ;;;;;;;;;;;;;;;;;;;
  304.  
  305. @@NotLeftClip:
  306.     mov   dx,[_RightClip]
  307.     sub   dx,di
  308.     js    @@NotVisible
  309.     mov   [LeftSkip],0
  310.         mov   [DataInc],0
  311.     cmp   dx,cx
  312.     jg    @@HorizClipDone
  313.     inc   dx
  314.     sub   cx,dx
  315.     mov   [DataInc],cx
  316.     mov   cx,dx
  317.  
  318. @@HorizClipDone:
  319.  
  320.  
  321.     add   di,[ScrnOffs]           ; Add the current page offset
  322.     mov   [VBMWidth],cx
  323.         mov   ax,es:[bx+ImageHeight]  ; Get image height and save in AX
  324.     mov   [VBMHeight],ax
  325.  
  326.  
  327.     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  328.  
  329.     mov   ax,[Y]                      ; Calculate dest screen row
  330.     mov   cx,[_ScrnLogicalByteWidth]  ;  by mult. dest Y coord by Screen
  331.     mul   cx                          ;  width then adding screen offset
  332.     add   di,ax                       ; Add Dest Screen Row to di
  333.     sub   cx,[VBMWidth]
  334.     mov   [NextLineIncr],cx
  335.  
  336.     mov   ax,es                       ; copy ES to DS
  337.     mov   ds,ax
  338.         mov   ax,SCREEN_SEG               ; Point es to VGA segment
  339.     mov   es,ax
  340.  
  341.     mov   ax,[bx+MaskPtr+AlignData+si]  ; DS:SI -> mask data
  342.     mov   bx,[bx+ImagePtr+AlignData+si] ; ES:BX -> source video bitmap
  343.     mov   si,ax
  344.  
  345.     mov   ax,[LeftSkip]               ; Skip data/mask bytes in
  346.     add   bx,ax                       ; each row that have been clipped
  347.     add   si,ax                       ; by the L.H.S border
  348.  
  349.  
  350.     mov   dx,GC_INDEX                 ; Set bit mask for all bits from
  351.     mov   ax,BIT_MASK                 ; VGA latches and none from CPU
  352.     out   dx,ax
  353.     mov   dx,SC_INDEX                 ; Point SC register to map mask
  354.     mov   al,MAP_MASK                 ; in preperation for masking data
  355.     out   dx,al
  356.     inc   dx                          ; Point dx to SC data register
  357.     mov   ah,byte ptr [VBMHeight]     ; AH = Scanline loop counter
  358.  
  359. @@RowLoop:
  360.     mov   cx,[VBMWidth]               ; Width in bytes across
  361.  
  362. @@ColumnLoop:
  363.     lodsb
  364.     out   dx,al
  365.     mov   al,es:[bx]                  ; load latches from source bitmap
  366.     stosb                             ; store latches to dest. bitmap
  367.     inc   bx
  368.     loop  @@ColumnLoop
  369.     add   bx,[DataInc]
  370.     add   si,[DataInc]
  371.     add   di,[NextLineIncr]           ; point to start of next dest row
  372.     dec   byte ptr ah                 ; decrement scan line counter
  373.     jnz   @@RowLoop                   ; jump if more scanlines left
  374.  
  375.     mov   dx,GC_INDEX+1               ; Restore bitmask to the default -
  376.     mov   al,0ffh                     ;  all data from cpu
  377.     out   dx,al
  378.  
  379.     pop   ds                          ; restore data segment
  380.         pop   di                          ; restore registers
  381.         pop   si
  382.         mov   sp,bp                       ; dealloc local variables
  383.         pop   bp
  384.         ret
  385. _x_put_masked_vbm_clipx  endp
  386.  
  387.  
  388. _x_put_masked_vbm_clipy  proc
  389. ARG X:word,Y:word,ScrnOffs:word,SrcVBM:dword
  390. LOCAL VBMWidth,VBMHeight,TopRow,NextLineIncr:word=LocalStk
  391.     push  bp
  392.         mov   bp,sp
  393.     sub   sp,LocalStk                 ; Create space for local variables
  394.         push  si
  395.         push  di
  396.     push  ds
  397.     cld
  398.  
  399.     mov   di,[X]                  ; load X coord int DI and make a
  400.     mov   si,di                   ;  copy in SI
  401.     
  402.  
  403.     and   si,3                    ; Calculate pixels plane alignment
  404.     shl   si,2                    ; Prepare to lookup mask & data
  405.     les   bx,[SrcVBM]             ; ES:BX -> begining of VBM data
  406.  
  407.  
  408.     mov   ax,es:[bx+ImageHeight]  ; Get image height and save in AX
  409.  
  410.  
  411.  
  412.     ;;;;; CLIP PROCESSING FOR TOP CLIP BORDER ;;;;;;;;;;;;;;;;;;;;;
  413.  
  414.     mov   dx,[_TopClip]           ; Compare u.l. Y coord with Top
  415.     sub   dx,[Y]                  ; clipping border
  416.     jle   @@NotTopClip            ; jump if VBM not clipped from above
  417.     cmp   dx,ax
  418.     jnl   @@NotVisible            ; jump if VBM is completely obscured
  419.     mov   [TopRow],dx
  420.     sub   ax,dx
  421.     add   [Y],dx
  422.     jmp   short @@VertClipDone
  423.  
  424.     ;;;; EXIT FOR COMPLETELY OBSCURED V.B.M's ;;;;;;;;;;;;;;;;;;;;;;
  425.  
  426. @@NotVisible:
  427.     pop   ds                          ; restore data segment
  428.     pop   di                          ; restore registers
  429.     pop   si
  430.     mov   sp,bp                       ; dealloc local variables
  431.     pop   bp
  432.     ret
  433.  
  434.     ;;;;; CLIP PROCESSING FOR BOTTOM CLIP BORDER ;;;;;;;;;;;;;;;;;;;
  435.  
  436. @@NotTopClip:
  437.     mov   dx,[_BottomClip]
  438.     sub   dx,[Y]
  439.     js    @@NotVisible
  440.         mov   [TopRow],0
  441.     cmp   dx,ax
  442.     jg    @@VertClipDone
  443.     inc   dx
  444.     mov   ax,dx
  445.  
  446. @@VertClipDone:
  447.  
  448.  
  449.         shr   di,2                    ; Find Byte offset of X coord
  450.     add   di,[ScrnOffs]           ; Add the current page offset
  451.         mov   cx,es:[bx+ImageWidth]   ; Get image width and save in CX
  452.     mov   [VBMWidth],cx
  453.         mov   [VBMHeight],ax
  454.  
  455.     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  456.  
  457.     mov   ax,[Y]                      ; Calculate dest screen row
  458.     mov   cx,[_ScrnLogicalByteWidth]  ;  by mult. dest Y coord by Screen
  459.     mul   cx                          ;  width then adding screen offset
  460.     add   di,ax                       ; Add Dest Screen Row to di
  461.     sub   cx,[VBMWidth]
  462.     mov   [NextLineIncr],cx
  463.  
  464.     mov   ax,es                       ; copy ES to DS
  465.     mov   ds,ax
  466.         mov   ax,SCREEN_SEG               ; Point es to VGA segment
  467.     mov   es,ax
  468.  
  469.     mov   ax,[bx+MaskPtr+AlignData+si]  ; DS:SI -> mask data
  470.     mov   bx,[bx+ImagePtr+AlignData+si] ; ES:BX -> source video bitmap
  471.     mov   si,ax
  472.  
  473.  
  474.  
  475.     mov   ax,[VBMWidth]               ; Increment DS:BX and DS:SI to
  476.     mul   [TopRow]                    ;  skip image/mask data that has
  477.     add   bx,ax                       ;  been clipped by the top border
  478.     add   si,ax
  479.  
  480.  
  481.     mov   dx,GC_INDEX                 ; Set bit mask for all bits from
  482.     mov   ax,BIT_MASK                 ; VGA latches and none from CPU
  483.     out   dx,ax
  484.     mov   dx,SC_INDEX                 ; Point SC register to map mask
  485.     mov   al,MAP_MASK                 ; in preperation for masking data
  486.     out   dx,al
  487.     inc   dx                          ; Point dx to SC data register
  488.     mov   ah,byte ptr [VBMHeight]     ; AH = Scanline loop counter
  489.  
  490. @@RowLoop:
  491.     mov   cx,[VBMWidth]               ; Width in bytes across
  492.  
  493. @@ColumnLoop:
  494.     lodsb
  495.     out   dx,al
  496.     mov   al,es:[bx]                  ; load latches from source bitmap
  497.     stosb                             ; store latches to dest. bitmap
  498.     inc   bx
  499.     loop  @@ColumnLoop
  500.     add   di,[NextLineIncr]           ; point to start of next dest row
  501.     dec   byte ptr ah                 ; decrement scan line counter
  502.     jnz   @@RowLoop                   ; jump if more scanlines left
  503.  
  504.     mov   dx,GC_INDEX+1               ; Restore bitmask to the default -
  505.     mov   al,0ffh                     ;  all data from cpu
  506.     out   dx,al
  507.  
  508.     pop   ds                          ; restore data segment
  509.         pop   di                          ; restore registers
  510.         pop   si
  511.         mov   sp,bp                       ; dealloc local variables
  512.         pop   bp
  513.         ret
  514. _x_put_masked_vbm_clipy  endp
  515.  
  516. _x_put_masked_vbm_clipxy  proc
  517. ARG X:word,Y:word,ScrnOffs:word,SrcVBM:dword
  518. LOCAL DataInc,LeftSkip,VBMWidth,VBMHeight,TopRow,NextLineIncr:word=LocalStk
  519.     push  bp
  520.         mov   bp,sp
  521.     sub   sp,LocalStk                 ; Create space for local variables
  522.         push  si
  523.         push  di
  524.     push  ds
  525.     cld
  526.  
  527.     mov   di,[X]                  ; load X coord int DI and make a
  528.     mov   si,di                   ;  copy in SI
  529.     shr   di,2                    ; Find Byte offset of X coord
  530.  
  531.     and   si,3                    ; Calculate pixels plane alignment
  532.     shl   si,2                    ; Prepare to lookup mask & data
  533.     les   bx,[SrcVBM]             ; ES:BX -> begining of VBM data
  534.  
  535.     mov   cx,es:[bx+ImageWidth]   ; Get image width and save in CX
  536.     mov   ax,es:[bx+ImageHeight]  ; Get image height and save in AX
  537.  
  538.  
  539.  
  540.     ;;;;; CLIP PROCESSING FOR TOP CLIP BORDER ;;;;;;;;;;;;;;;;;;;;;
  541.  
  542.     mov   dx,[_TopClip]           ; Compare u.l. Y coord with Top
  543.     sub   dx,[Y]                  ; clipping border
  544.     jle   @@NotTopClip            ; jump if VBM not clipped from above
  545.     cmp   dx,ax
  546.     jnl   @@NotVisible            ; jump if VBM is completely obscured
  547.     mov   [TopRow],dx
  548.     sub   ax,dx
  549.     add   [Y],dx
  550.     jmp   short @@VertClipDone
  551.  
  552.     ;;;; EXIT FOR COMPLETELY OBSCURED V.B.M's ;;;;;;;;;;;;;;;;;;;;;;
  553.  
  554. @@NotVisible:
  555.     pop   ds                          ; restore data segment
  556.     pop   di                          ; restore registers
  557.     pop   si
  558.     mov   sp,bp                       ; dealloc local variables
  559.     pop   bp
  560.     ret
  561.  
  562.     ;;;;; CLIP PROCESSING FOR BOTTOM CLIP BORDER ;;;;;;;;;;;;;;;;;;;
  563.  
  564. @@NotTopClip:
  565.     mov   dx,[_BottomClip]
  566.     sub   dx,[Y]
  567.     js    @@NotVisible
  568.         mov   [TopRow],0
  569.     cmp   dx,ax
  570.     jg    @@VertClipDone
  571.     inc   dx
  572.     mov   ax,dx
  573.  
  574. @@VertClipDone:
  575.  
  576.     ;;;;; CLIP PROCESSING FOR LEFT CLIP BORDER ;;;;;;;;;;;;;;;;;;;
  577.  
  578.     mov   dx,[_LeftClip]
  579.     sub   dx,di
  580.     jle   @@NotLeftClip
  581.     cmp   dx,cx
  582.     jnl   @@NotVisible
  583.     add   di,dx
  584.     mov   [LeftSkip],dx
  585.     mov   [DataInc],dx
  586.     sub   cx,dx
  587.     jmp   short @@HorizClipDone
  588.  
  589.     ;;;;; CLIP PROCESSING FOR RIGHT CLIP BORDER ;;;;;;;;;;;;;;;;;;;
  590.  
  591. @@NotLeftClip:
  592.     mov   dx,[_RightClip]
  593.     sub   dx,di
  594.     js    @@NotVisible
  595.     mov   [LeftSkip],0
  596.         mov   [DataInc],0
  597.     cmp   dx,cx
  598.     jg    @@HorizClipDone
  599.     inc   dx
  600.     sub   cx,dx
  601.     mov   [DataInc],cx
  602.     mov   cx,dx
  603.  
  604. @@HorizClipDone:
  605.  
  606.         add   di,[ScrnOffs]           ; Add the current page offset
  607.     mov   [VBMWidth],cx
  608.         mov   [VBMHeight],ax
  609.     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  610.  
  611.     mov   ax,[Y]                      ; Calculate dest screen row
  612.     mov   cx,[_ScrnLogicalByteWidth]  ;  by mult. dest Y coord by Screen
  613.     mul   cx                          ;  width then adding screen offset
  614.     add   di,ax                       ; Add Dest Screen Row to di
  615.     sub   cx,[VBMWidth]
  616.     mov   [NextLineIncr],cx
  617.  
  618.     mov   ax,es                       ; copy ES to DS
  619.     mov   ds,ax
  620.         mov   ax,SCREEN_SEG               ; Point es to VGA segment
  621.     mov   es,ax
  622.  
  623.     mov   ax,[bx+MaskPtr+AlignData+si]  ; DS:SI -> mask data
  624.     mov   bx,[bx+ImagePtr+AlignData+si] ; ES:BX -> source video bitmap
  625.     mov   si,ax
  626.  
  627.  
  628.  
  629.     mov   ax,[VBMWidth]               ; Increment DS:BX and DS:SI to
  630.     add   ax,[DataInc]                ;  skip image/mask data that has
  631.     mul   [TopRow]                    ;  been clipped by the top border
  632.     add   ax,[LeftSkip]               ; Skip also data/mask bytes in
  633.     add   bx,ax                       ; each row that have been clipped
  634.     add   si,ax                       ; by the L.H.S border
  635.  
  636.  
  637.     mov   dx,GC_INDEX                 ; Set bit mask for all bits from
  638.     mov   ax,BIT_MASK                 ; VGA latches and none from CPU
  639.     out   dx,ax
  640.     mov   dx,SC_INDEX                 ; Point SC register to map mask
  641.     mov   al,MAP_MASK                 ; in preperation for masking data
  642.     out   dx,al
  643.     inc   dx                          ; Point dx to SC data register
  644.     mov   ah,byte ptr [VBMHeight]     ; AH = Scanline loop counter
  645.  
  646. @@RowLoop:
  647.     mov   cx,[VBMWidth]               ; Width in bytes across
  648.  
  649. @@ColumnLoop:
  650.     lodsb
  651.     out   dx,al
  652.     mov   al,es:[bx]                  ; load latches from source bitmap
  653.     stosb                             ; store latches to dest. bitmap
  654.     inc   bx
  655.     loop  @@ColumnLoop
  656.     add   bx,[DataInc]
  657.     add   si,[DataInc]
  658.     add   di,[NextLineIncr]           ; point to start of next dest row
  659.     dec   byte ptr ah                 ; decrement scan line counter
  660.     jnz   @@RowLoop                   ; jump if more scanlines left
  661.  
  662.     mov   dx,GC_INDEX+1               ; Restore bitmask to the default -
  663.     mov   al,0ffh                     ;  all data from cpu
  664.     out   dx,al
  665.  
  666.     pop   ds                          ; restore data segment
  667.         pop   di                          ; restore registers
  668.         pop   si
  669.         mov   sp,bp                       ; dealloc local variables
  670.         pop   bp
  671.         ret
  672. _x_put_masked_vbm_clipxy  endp
  673.  
  674.  
  675.     end
  676.  
  677.